18 Commits

Author SHA1 Message Date
c86546af82 Version bump to v0.2.1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-06 11:41:14 -05:00
6c046dde81 Added license view and edit functions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-06 11:40:45 -05:00
4167130f0c Started work on adding license tracking
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-06 01:37:56 -05:00
b98fbddd9e Version bump to v0.2.0
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-05 16:16:11 -04:00
0818f57131 Added ability to use redis datastores for session data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-05 16:14:37 -04:00
4a43aaabb6 Fixed linter errors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 21:30:31 -04:00
a297829ffc Version bump v0.1.5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-04 21:24:45 -04:00
4da2877a89 Added a way to configure using a remote database
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-04 21:24:22 -04:00
2e309b29f1 Updated package-lock for v0.1.4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-04 20:31:06 -04:00
0cea6eb4ca Version bump to v0.1.4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 18:25:29 -04:00
d1268fe708 Fixed system config in /etc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 18:23:29 -04:00
ff92316e1e Updated the systemd unit file to load the proper config file
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 18:17:29 -04:00
629a7df3c4 Version bump to v0.1.3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 18:08:08 -04:00
30e23caf7f Added config options to define what host address and port to listen on
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-04 18:07:44 -04:00
9afe8c5391 Version bump v0.1.2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-04 17:59:25 -04:00
e958080702 Fixed some linter issues
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-04 17:54:43 -04:00
6455f3ff10 Changed to Grunt.js for task running
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-04 17:53:42 -04:00
1536c0721d Added preliminary code for the express-flasher flash message integration - will uncomment code tomorrow when package can be published
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-04 17:30:17 -04:00
22 changed files with 1953 additions and 6046 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ public/js/
# Local data storage
data/
# Local config
config/local.json

View File

@ -3,6 +3,7 @@ pipeline:
image: node:18
commands:
- npm install
- npm run grunt
lint:
image: node:18

View File

@ -4,6 +4,51 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: [{
expand: true,
cwd: 'assets/styles',
src: ['**/*.scss'],
dest: 'public/css',
ext: '.css'
}]
}
},
uglify: {
options: {
mangle: false
},
compile: {
files: {
'public/js/nechryael.min.js': ['assets/js/**/*.js']
}
}
},
watch: {
css: {
files: ['assets/styles/**/*.scss'],
tasks: ['sass'],
options: {
atBegin: true,
spawn: false
}
},
js: {
files: ['assets/js/**/*.js'],
tasks: ['uglify'],
options: {
atBegin: true,
spawn: false
}
}
},
deb_package: {
options: {
maintainer: 'Gregory Ballantine <gballantine@bitgoblin.tech>',
@ -39,7 +84,7 @@ module.exports = function(grunt) {
},
{
cwd: './build/etc/',
src: 'production.json',
src: 'default.json',
dest: '/etc/overseer/'
},
{
@ -75,10 +120,14 @@ module.exports = function(grunt) {
}
});
// Load the plugin that provides the "uglify" task.
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-deb');
// Default task(s).
// CLI tasks.
grunt.registerTask('default', ['sass', 'uglify']);
grunt.registerTask('package', ['deb_package']);
};

3
assets/js/nechryael.js Normal file
View File

@ -0,0 +1,3 @@
$(document).ready(function() {
console.log('Document is ready!');
});

View File

@ -86,7 +86,8 @@ input[type="submit"].button-primary{
}
}
#item-header{
#item-header,
#license-header{
margin-bottom: 25px;
h1,
@ -96,7 +97,9 @@ input[type="submit"].button-primary{
}
.item-added-date,
.item-updated-date{
.item-updated-date,
.license-added-date,
.license-updated-date{
margin-bottom: 5px;
color: #666;
font-size: 1.6rem;

View File

@ -1,4 +1,8 @@
{
"server": {
"address": "0.0.0.0",
"port": 3000
},
"database": {
"driver": "sqlite",
"connection_string": "/opt/overseer/data/overseer.db"

View File

@ -4,6 +4,7 @@ Description=Overseer inventory tracking app
[Service]
User=overseer
Group=overseer
Environment="NODE_CONFIG_DIR=/etc/overseer"
ExecStart=/usr/bin/overseer
SuccessExitStatus=143

View File

@ -1,6 +1,15 @@
{
"server": {
"address": "0.0.0.0",
"port": 3000
},
"database": {
"driver": "sqlite",
"connection_string": "data/overseer.db"
},
"redis": {
"host": "192.168.1.10",
"port": 6379,
"number": "0"
}
}

View File

@ -1,17 +0,0 @@
const gulp = require('gulp');
const { watch } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
// compile
function styles(cb) {
return gulp.src('./assets/styles/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./public/css'));
cb();
}
// by default, watch files
exports.default = function() {
// compile sass stylesheets
watch('assets/styles/**/*.scss', styles);
};

View File

@ -1,8 +1,11 @@
const express = require('express');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
// const flash = require('express-flasher');
// instantiate new express.js app
const app = express();
const port = 3000;
const config = require('config');
// initialize database connection
(async () => {
@ -12,6 +15,23 @@ const port = 3000;
});
})();
// initialize Redis store for session data
const redisClient = require('./src/redis');
// initialize express.js session w/ Redis datastore
app.use(session({
store: new RedisStore({
client: redisClient,
}), // use Redis datastore
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
// setup flash messaging
// app.use(flash.flash());
// app.use(flash.flashRead());
// set up body POST parameters
app.use(express.json());
app.use(express.urlencoded({
@ -27,6 +47,7 @@ app.use(express.static('public'));
// load route handlers
const homeRoutes = require('./src/routes/home');
const itemRoutes = require('./src/routes/item');
const licenseRoutes = require('./src/routes/license');
// register route handlers
app.get('/', homeRoutes.getIndex);
@ -35,8 +56,13 @@ app.post('/item/add', itemRoutes.postAdd);
app.get('/item/:id', itemRoutes.getItem);
app.get('/item/:id/edit', itemRoutes.getItemEdit);
app.post('/item/:id/edit', itemRoutes.postItemEdit);
app.get('/license/add', licenseRoutes.getAdd);
app.post('/license/add', licenseRoutes.postAdd);
app.get('/license/:id', licenseRoutes.getLicense);
app.get('/license/:id/edit', licenseRoutes.getEdit);
app.post('/license/:id/edit', licenseRoutes.postEdit);
// start app
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
app.listen(config.get('server.port'), config.get('server.address'), () => {
console.log(`Overseer is listening on port ${config.get('server.port')}.`);
});

7444
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
{
"name": "overseer",
"version": "0.1.1",
"version": "0.2.1",
"description": "Self-hosted inventory tracker",
"main": "index.js",
"scripts": {
"start": "node index.js",
"grunt": "grunt",
"gulp": "gulp",
"nodemon": "nodemon index.js",
"lint": "eslint index.js src/**/*.js",
"test": "echo \"Error: no test specified\" && exit 1"
@ -21,7 +20,10 @@
],
"author": "Gregory Ballanine <gballantine@bitgoblin.tech>",
"uploaders": [
{ "name": "Gregory Ballantine", "email": "gballantine@bitgoblin.tech" }
{
"name": "Gregory Ballantine",
"email": "gballantine@bitgoblin.tech"
}
],
"license": "BSD-2-Clause",
"devDependencies": {
@ -29,15 +31,23 @@
"eslint-config-google": "^0.14.0",
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-sass": "^2.0.0",
"grunt-contrib-uglify": "^5.2.2",
"grunt-contrib-watch": "^1.1.0",
"grunt-deb": "^0.2.5",
"gulp": "^4.0.2",
"gulp-sass": "^5.1.0",
"nodemon": "^2.0.20",
"sass": "^1.55.0"
},
"dependencies": {
"config": "^3.3.8",
"connect-redis": "^6.1.3",
"express": "^4.18.2",
"express-session": "^1.17.3",
"mariadb": "^3.0.2",
"mysql2": "^2.3.3",
"pg": "^8.8.0",
"pg-hstore": "^2.3.4",
"redis": "^4.4.0",
"sequelize": "^6.25.3",
"sqlite3": "^5.1.2",
"twig": "^1.15.4"

View File

@ -1,10 +1,7 @@
const dbConfig = require('config').get('database');
const Sequelize = require('sequelize');
const sequelize = new Sequelize({
dialect: dbConfig.get('driver'),
storage: dbConfig.get('connection_string'),
});
const sequelize = initDatabase();
const db = {};
@ -12,5 +9,32 @@ db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.items = require('./item.js')(sequelize, Sequelize);
db.licenses = require('./license.js')(sequelize, Sequelize);
module.exports = db;
/**
* Initializes a sequelize database connection.
*
* @return {object} - sequelize connection
*/
function initDatabase() {
let sequelize = null;
if (dbConfig.get('driver') == 'sqlite') {
sequelize = new Sequelize({
dialect: dbConfig.get('driver'),
storage: dbConfig.get('connection_string'),
});
} else {
const dbName = dbConfig.get('name');
const dbUsername = dbConfig.get('username');
const dbPassword = dbConfig.get('password');
sequelize = new Sequelize(dbName, dbUsername, dbPassword, {
dialect: dbConfig.get('driver'),
host: dbConfig.get('address'),
});
}
return sequelize;
}

27
src/models/license.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = (sequelize, Sequelize) => {
const License = sequelize.define('license', {
name: {
type: Sequelize.STRING,
},
key: {
type: Sequelize.STRING,
},
manufacturer: {
type: Sequelize.STRING,
},
purchasedFrom: {
type: Sequelize.STRING,
},
purchasedAt: {
type: Sequelize.DATE,
},
});
return License;
};

31
src/redis.js Normal file
View File

@ -0,0 +1,31 @@
const redisConfig = require('config').get('redis');
exports.default = function() {
let redisUrl = 'redis://';
// add the redis username if defined
if (typeof redisConfig.get('username') !== 'undefined') {
redisUrl += redisConfig.get('username');
}
// add the user password if defined
if (typeof redisConfig.get('password') !== 'undefined') {
redisUrl += ':' + redisConfig.get('password') + '@';
}
// add redis host URL
redisUrl += redisConfig.get('host');
// add redis host port
redisUrl += ':' + redisConfig.get('port');
// add redis database number if defined
if (typeof redisConfig.get('number') !== 'undefined') {
redisUrl += redisConfig.get('number');
}
const { createClient } = require("redis");
let redisClient = createClient({
url: redisUrl,
legacyMode: true,
});
redisClient.connect().catch(console.error);
return redisClient;
};

View File

@ -1,8 +1,10 @@
const db = require('../models');
const Item = db.items;
const License = db.licenses;
// GET - /
exports.getIndex = async function(req, res) {
// fetch inventory items from database
const items = await Item.findAll({
limit: 10,
order: [
@ -10,7 +12,18 @@ exports.getIndex = async function(req, res) {
],
});
// fetch licenses from database
const licenses = await License.findAll({
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
// req.flash('info', 'This is a test flash message.');
res.render('index.twig', {
inventory: items,
licenses: licenses,
});
};

74
src/routes/license.js Normal file
View File

@ -0,0 +1,74 @@
const db = require('../models');
const License = db.licenses;
// GET - /license/add
exports.getAdd = async function(req, res) {
res.render('license/add.twig');
};
// POST - /license/add
exports.postAdd = async function(req, res) {
const license = await License.create({
name: req.body.license_name,
key: req.body.license_key,
manufacturer: req.body.license_manufacturer,
purchasedFrom: req.body.license_purchase_from,
purchasedAt: req.body.license_purchase_date,
});
console.log(`Saved license ${license.name} to the database.`);
res.redirect('/');
};
// GET - /license/{id}
exports.getLicense = async function(req, res) {
const license = await License.findAll({
where: {
id: req.params.id,
},
});
res.render('license/view.twig', {
license: license[0],
});
};
// GET - /license/{id}/edit
exports.getEdit = async function(req, res) {
const license = await License.findAll({
where: {
id: req.params.id,
},
});
res.render('license/edit.twig', {
license: license[0],
});
};
// POST - /license/{id}/edit
exports.postEdit = async function(req, res) {
// fetch license from DB
const licenseSearch = await License.findAll({
where: {
id: req.params.id,
},
});
// retrieve the license record from the array for ease of use
const license = licenseSearch[0];
// update license attributes
license.name = req.body.license_name;
license.key = req.body.license_key;
license.manufacturer = req.body.license_manufacturer;
license.purchasedFrom = req.body.license_purchase_from;
license.purchasedAt = req.body.license_purchase_date;
// save attribute changes
await license.save();
// redirect user to license page
res.redirect('/license/' + license.id);
};

View File

@ -28,32 +28,51 @@
<hr>
<section class="row">
<div class="columns twelve">
<h3>Recently updated records:</h3>
<div class="columns six">
<h3>Recently updated hardware:</h3>
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Type</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for item in inventory %}
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="columns six">
<h3>Recently updated licenses:</h3>
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for license in licenses %}
<tr>
<td><a href="/license/{{ license.id }}">{{ license.name }}</a></td>
<td>{{ license.manufacturer }}</td>
<td>{{ license.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
<section class="row">
<table class="columns twelve">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Type</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for item in inventory %}
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>
{% endblock %}

View File

@ -9,7 +9,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/css/gargoyle.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="/js/drake.js"></script>
<script src="/js/nechryael.min.js"></script>
</head>
<body>
<!-- global navigation -->
@ -20,10 +20,17 @@
<li class="nav-link"><a href="/">Home</a></li>
<li class="nav-link"><a href="/item/search">Search</a></li>
<li class="nav-link"><a href="/item/add">Add Item</a></li>
<li class="nav-link"><a href="/license/add">Add License</a></li>
</ul>
</div>
</nav>
{% if flash != null %}
<div class="flash-message {{ flash.type }}">
<p>{{ flash.msg }}</p>
</div>
{% endif %}
<!-- main content -->
<div id="main-content" class="container fluid">
{% block content %}{% endblock %}

53
views/license/add.twig Normal file
View File

@ -0,0 +1,53 @@
{% extends 'layout.twig' %}
{% block title %}Add New License{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Add new license</h1>
</div>
</header>
<section class="row">
<div class="columns twelve">
<form action="/license/add" method="POST">
<div class="row">
<div class="columns twelve">
<label for="license_name">License name:</label>
<input class="u-full-width" type="text" placeholder="My new license" id="license_name" name="license_name" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_key">License Key:</label>
<input class="u-full-width" type="text" placeholder="ABCD-EFGH-1234-5678" id="license_key" name="license_key" required>
</div>
<div class="six columns">
<label for="license_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="license_manufacturer" name="license_manufacturer">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="license_purchase_from" name="license_purchase_from">
</div>
<div class="six columns">
<label for="license_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="license_purchase_date" name="license_purchase_date">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</section>
{% endblock %}

53
views/license/edit.twig Normal file
View File

@ -0,0 +1,53 @@
{% extends 'layout.twig' %}
{% block title %}Edit License{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Editing "{{ license.name }}"</h1>
</div>
</header>
<section class="row">
<div class="columns twelve">
<form action="/license/{{ license.id }}/edit" method="POST">
<div class="row">
<div class="columns twelve">
<label for="license_name">License name:</label>
<input class="u-full-width" type="text" placeholder="My new license" id="license_name" name="license_name" value="{{ license.name }}" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_key">License key:</label>
<input class="u-full-width" type="text" placeholder="ABCD-EFGH-1234-5678" id="license_key" name="license_key" value="{{ license.key }}" required>
</div>
<div class="six columns">
<label for="license_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="license_manufacturer" name="license_manufacturer" value="{{ license.manufacturer }}">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="license_purchase_from" name="license_purchase_from" value="{{ license.purchasedFrom }}">
</div>
<div class="six columns">
<label for="license_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="license_purchase_date" name="license_purchase_date" value="{{ license.purchasedAt }}">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</section>
{% endblock %}

43
views/license/view.twig Normal file
View File

@ -0,0 +1,43 @@
{% extends 'layout.twig' %}
{% block title %}{{ license.name }}{% endblock %}
{% block content %}
<!-- page header -->
<header id="license-header" class="row">
<div class="columns twelve">
<span>
<h1>{{ license.name }}</h1>
<p><a href="/license/{{ license.id }}/edit"><i class="fa-solid fa-pen-to-square"></i> Edit</a></p>
</span>
<h4 class="license-added-date">license added at: {{ license.createdAt }}</h4>
<h4 class="license-updated-date">Last updated at: {{ license.updatedAt }}</h4>
</div>
</header>
<!-- license information -->
<section class="row">
<table class="columns twelve">
<thead>
<tr>
<th>Product name</th>
<th>License Key</th>
<th>Manufacturer</th>
<th>Seller</th>
<th>Purchase date</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ license.name }}</td>
<td>{{ license.key ? license.key : 'N/a' }}</td>
<td>{{ license.manufacturer ? license.manufacturer : 'N/a' }}</td>
<td>{{ license.purchasedFrom ? license.purchasedFrom : 'N/a' }}</td>
<td>{{ license.purchasedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
</tbody>
</table>
</section>
{% endblock %}