Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
currentScheme += '.';
}
}
// Set the current working directory to the location of the config file,
// so that paths in the config file are relative to itself.
process.chdir(path.dirname(configPath));
$$serverState.saveState('lastConfig', $$config);
}
console.log('Server starting up.');
// Load the shared state plugin file.
global.$$plugin = null;
if ($$config.plugin && fs.existsSync($$config.plugin)) {
var plugin = require(path.resolve($$config.plugin)).Plugin;
global.$$plugin = new plugin();
}
// A container for all the network transports, generally accessed via $$network.transports.
global.$$network = new Network({
config: $$config.network
});
// The manager of the application process, controlling restarts and heartbeats.
global.$$persistence = new Persistence({
config: $$config.persistence
});
// The logging manager.
global.$$logging = new Logging({
cache.db.select(task.dbKey, opts, function (err, entry) {
if (err) {
koop.log.error('Error selecting rows from the DB', task.dbKey, opts, err)
throw err
}
if (fs.existsSync(filePart)) fs.unlinkSync(filePart)
fs.writeFile(filePart, JSON.stringify(entry[0]), function () {
// TODO why build this here?
// we could open a file handle and push each layer into the file via io
var vrtPartial = ''
vrtPartial += filePart
vrtPartial += ''
fs.appendFileSync(task.files.rootVrtFile, vrtPartial)
// tick up the number of complete pages
self.completed++
job.progress(null, null, pageLen)
cb()
})
})
}, 4)
// ----------
sparseConfig.timezone = process.env.SYSTEM_TZ;
// some systems report EDT while not having EDT zoneinfo
if ('EDT' === sparseConfig.timezone) {
sparseConfig.timezone = 'EST';
}
// Session Secret
crypto.randomBytes(48, function(ex, buf) {
sparseConfig.server.sessionSecret = buf.toString('hex');
});
var logPath = path.resolve(__dirname + '/../') + '/logs';
if (!fs.existsSync(logPath)) {
fs.mkdirSync(logPath, 0755);
}
// JWT Signing Key
if (!sparseConfig.jwtKey) {
crypto.randomBytes(48, function(ex, buf) {
sparseConfig.jwtKey = buf.toString('hex');
});
}
// override data dir
if (process.env.NODE_DATA_DIR) {
sparseConfig.modules.cdn.config.data_dir = path.resolve(process.env.NODE_DATA_DIR);
}
BaseModel.prototype.initialize.apply(this);
global.logger = new winston.Logger({
exitOnError: $$persistence.get('exitOnError')
});
// Set up console logger.
if (this.get('console').enabled) {
this.get('console').handleExceptions = !$$persistence.get('exitOnError');
logger.add(winston.transports.Console, this.get('console'));
}
// Set up file logger.
if (this.get('file').enabled) {
// Create the log file folder.
var dir = path.dirname(this.get('file').filename);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
this.get('file').timestamp = function() {
return moment().format('YYYY-MM-DD HH:mm:ss');
};
this.get('file').handleExceptions = !$$persistence.get('exitOnError');
logger.add(require('winston-daily-rotate-file'), this.get('file'));
}
// Set up email.
if (this.get('mail').enabled) {
var subject = this.get('mail').subject;
if (subject) {
subject = subject.replace('{hostname}', os.hostname());
return new Promise((resolve, reject) => {
const trimmedPaths = existingTemplateFiles.map(fullPath =>
fullPath.replace(templatesPath + "/", "").replace(/\.js|\.jsx/gi, "")
);
const templateJsonString = JSON.stringify(trimmedPaths);
const filepath = path.resolve(`./wordsby/data/templates.json`);
const dir = path.resolve("./wordsby/data");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
// Save templates array to the public folder. to be consumed by WP for template switching and preview urls
fs.writeFile(filepath, new Buffer.from(templateJsonString, "utf8"), err => {
if (err) reject(err);
resolve();
});
});
};
cache.getCount(job.data.table, job.data.options, function (err, count) {
if (err) {
koop.log.error('Error getting count from the DB', err)
throw err
}
// if we can handle the data in one page
if (count <= job.data.options.limit) {
singlePage(job, done)
// if we already have a VRT on disk
} else if (fs.existsSync(job.data.paths.rootVrtFile) && !job.data.options.ignore_cache) {
createFromVRT(job, done)
// we need to start from scratch
} else {
multiPage(job, count, done)
}
})
})
fs.readFile('report/template.html', 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/htmlbody/g, html).replace(/cssparent/g, "../../../../report");
var reportFile = 'generated/reports/' + image + '.html';
var parentDir = reportFile.substring(0, reportFile.lastIndexOf("/"));
if (!fs.existsSync(parentDir)) {
fs.mkdirSync(parentDir, 0777, true);
}
fs.writeFile(reportFile, result, 'utf8', function(err) {
if (err) {
return console.log(err);
} else {
callback(coverageSummary);
}
});
});
};
fs.readFile('report/template.html', 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/htmlbody/g, html);
var reportFile = 'generated/reports/' + image + '.html';
var parentDir = reportFile.substring(0, reportFile.lastIndexOf("/"));
if (!fs.existsSync(parentDir)) {
fs.mkdirSync(parentDir, 0777, true);
fs.linkSync('report/css', parentDir + '/css');
fs.linkSync('report/fonts', parentDir + '/fonts');
fs.linkSync('report/js', parentDir + '/js');
}
fs.writeFile(reportFile, result, 'utf8', function(err) {
if (err) {
return console.log(err);
} else {
callback(coverageSummary);
}
});
});
};
var bootstrap = require(__dirname + '/../src/bootstrap');
_createAccount(bootstrap.app.dao, function() {
process.exit(0);
});
});
});
dao.on('error', function(err) {
console.log('MongoDB unconnectable via : ' + sparseConfig.dbMongo.connect);
console.log(err);
auxServers();
});
});
}
if (!fs.existsSync(targetConfig)) {
domainSelect();
} else {
//process.HEADLESS = true;
var bootstrap = require(__dirname + '/../src/bootstrap');
bootstrap.app.dao.on('ready', function() {
bootstrap.app.dao.registerModel(require('../src/models/migration').Migration);
bootstrap.app.dao.runMigrations(pkg.version, targetConfig, function(err, result) {
if (err) {
console.error(err);
} else {
console.log(result);
}
function deleteFolderRecursive(path, preventDeletion) {
var canRemove = true;
if (fs.existsSync(path)) {
var files = fs.readdirSync(path);
files.forEach(function(file,index) {
var curPath = path + "/" + file;
for (var i=0; i