Import path fix
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
|
|
||||||
const conf = require('@simpleworkjs/conf');
|
const conf = require('@simpleworkjs/conf');
|
||||||
const Table = require('../utils/redis_model');
|
const Table = require('.');
|
||||||
const ModelPs = require('../utils/model_pubsub');
|
const ModelPs = require('../utils/model_pubsub');
|
||||||
|
|
||||||
const tldExtract = require('tld-extract').parse_host;
|
const tldExtract = require('tld-extract').parse_host;
|
||||||
|
|||||||
@@ -230,20 +230,24 @@ class Host extends Table{
|
|||||||
|
|
||||||
async checkWildcardForRenew(){
|
async checkWildcardForRenew(){
|
||||||
try{
|
try{
|
||||||
|
console.log(`Checking ${this.host}`);
|
||||||
if(this.is_wildcard && Date.now() > this.wildcard_expires - (30 * 24 * 60 * 60 * 1000)){
|
if(this.is_wildcard && Date.now() > this.wildcard_expires - (30 * 24 * 60 * 60 * 1000)){
|
||||||
this.createWildcardCert();
|
this.createWildcardCert();
|
||||||
}
|
}
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
console.error('checkWildcardForRenew instance', this.host, error)
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async checkWildcardForRenew(){
|
static async checkWildcardForRenew(){
|
||||||
try{
|
try{
|
||||||
|
console.log('checkWildcardForRenew here', this)
|
||||||
for(let host of await this.listDetail()){
|
for(let host of await this.listDetail()){
|
||||||
host.createWildcardCert();
|
host.createWildcardCert();
|
||||||
}
|
}
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
console.error('checkWildcardForRenew', error)
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
const conf = require('@simpleworkjs/conf');
|
||||||
|
const {setUpTable} = require('model-redis');
|
||||||
|
|
||||||
|
const Table = setUpTable(conf.redis);
|
||||||
|
|
||||||
const Table = require('../utils/redis_model');
|
|
||||||
module.exports = Table;
|
module.exports = Table;
|
||||||
|
|
||||||
require('./dns_provider');
|
require('./dns_provider');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Table = require('../utils/redis_model');
|
const Table = require('.');
|
||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ frontEndModules.forEach(dep => {
|
|||||||
// local folder.
|
// local folder.
|
||||||
router.use('/static', express.static(path.join(__dirname, '../public')))
|
router.use('/static', express.static(path.join(__dirname, '../public')))
|
||||||
|
|
||||||
router.get('/', async function(req, res, next) {
|
router.get('/', (req, res) => {
|
||||||
res.render('hosts', {...values});
|
res.redirect(301, '/hosts');
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/hosts', async function(req, res, next) {
|
router.get('/hosts', async function(req, res, next) {
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ const {Host} = require('../models/host');
|
|||||||
|
|
||||||
// Initial wildcard cert check 30 seconds after app starts
|
// Initial wildcard cert check 30 seconds after app starts
|
||||||
// Delay allows the system to fully initialize before checking certs
|
// Delay allows the system to fully initialize before checking certs
|
||||||
setTimeout(Host.checkWildcardForRenew, 30000);
|
setTimeout(Host.checkWildcardForRenew.bind(Host), 30000);
|
||||||
|
|
||||||
// Check wildcard certs once every 24 hours
|
// Check wildcard certs once every 24 hours
|
||||||
// Ensures certificates are renewed well before expiration
|
// Ensures certificates are renewed well before expiration
|
||||||
setInterval(Host.checkWildcardForRenew, 86400000);
|
setInterval(Host.checkWildcardForRenew.bind(Host), 86400000);
|
||||||
|
|
||||||
console.log('Host scheduler service initialized');
|
console.log('Host scheduler service initialized');
|
||||||
console.log('- Wildcard cert check: 30s after start, then every 24h');
|
console.log('- Wildcard cert check: 30s after start, then every 24h');
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const process_type = {
|
|
||||||
number: function(key, value){
|
|
||||||
if(key.min && value < key.min) return `is to small, min ${key.min}.`
|
|
||||||
if(key.max && value > key.max) return `is to large, max ${key.max}.`
|
|
||||||
},
|
|
||||||
string: function(key, value){
|
|
||||||
if(key.min && value.length < key.min) return `is too short, min ${key.min}.`
|
|
||||||
if(key.max && value.length > key.max) return `is too short, max ${key.max}.`
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
function returnOrCall(value){
|
|
||||||
return typeof(value) === 'function' ? value() : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processKeys(map, data, partial){
|
|
||||||
let errors = [];
|
|
||||||
let out = {};
|
|
||||||
|
|
||||||
for(let key of Object.keys(map)){
|
|
||||||
|
|
||||||
// Do not require "isRequired" fields for partial validation, useful for
|
|
||||||
// updates.
|
|
||||||
if(!map[key].always && partial && !data.hasOwnProperty(key)) continue;
|
|
||||||
|
|
||||||
// Make sure required keys are present
|
|
||||||
if(!partial && map[key].isRequired && !data.hasOwnProperty(key)){
|
|
||||||
errors.push({key, message:`${key} is required.`});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove undefined keys unless they have a default option or are a
|
|
||||||
// relation
|
|
||||||
if(data[key] === undefined){
|
|
||||||
if(!map[key].default){
|
|
||||||
if(map[key].model && !map[key].type) continue;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the type of the key
|
|
||||||
if(data.hasOwnProperty(key) && map[key].type && typeof(data[key]) !== map[key].type){
|
|
||||||
errors.push({key, message:`${key} is not ${map[key].type} type.`});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the key to the process object to be returned and set any default
|
|
||||||
// if the key is blank
|
|
||||||
out[key] = data.hasOwnProperty(key) && data[key] !== undefined ? data[key] : returnOrCall(map[key].default);
|
|
||||||
|
|
||||||
// Check for type specific validations, ie: string length
|
|
||||||
if(data.hasOwnProperty(key) && process_type[map[key].type]){
|
|
||||||
let typeError = process_type[map[key].type](map[key], data[key]);
|
|
||||||
if(typeError){
|
|
||||||
errors.push({key, message:`${key} ${typeError}`});
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for errors, throw validation error if any
|
|
||||||
if(errors.length !== 0){
|
|
||||||
throw ObjectValidateError(errors);
|
|
||||||
return {__errors__: errors};
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseFromString(map, data){
|
|
||||||
// Use the key maps data type to return string values to native
|
|
||||||
let types = {
|
|
||||||
boolean: function(value){ return value === 'false' ? false : true },
|
|
||||||
number: Number,
|
|
||||||
string: String,
|
|
||||||
object: JSON.parse
|
|
||||||
};
|
|
||||||
|
|
||||||
for(let key of Object.keys(data)){
|
|
||||||
if(map[key] && map[key].type && data[key]){
|
|
||||||
data[key] = types[map[key].type](data[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseToString(data){
|
|
||||||
let types = {
|
|
||||||
object: JSON.stringify
|
|
||||||
}
|
|
||||||
|
|
||||||
return (types[typeof(data)] || String)(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ObjectValidateError(keys, message){
|
|
||||||
let error = new Error('ObjectValidateError')
|
|
||||||
error.name = "ObjectValidateError"
|
|
||||||
error.message = message || `Invalid Keys: ${message}`
|
|
||||||
error.keys = (keys || {});
|
|
||||||
error.status = 422;
|
|
||||||
|
|
||||||
return error
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectValidateError.prototype = Error.prototype;
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {processKeys, parseFromString, ObjectValidateError, parseToString};
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const {setUpTable} = require('model-redis');
|
|
||||||
const conf = require('@simpleworkjs/conf');
|
|
||||||
|
|
||||||
const Table = setUpTable({
|
|
||||||
prefix: conf.redis.prefix
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Table;
|
|
||||||
Reference in New Issue
Block a user