Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Path = require('path');
const ChildProcess = require('child_process');
const Fs = require('fs');
const conf = require('simple-configure');
let gitCommands = [];
let workTree = conf.get('wikipath');
if (workTree) {
Fs.realpath(workTree, (err, absWorkTree) => {
if (err) { throw new Error('Repository path does not exist: ' + workTree); }
workTree = absWorkTree;
const gitDir = Path.join(workTree, '.git');
Fs.stat(gitDir, (err1) => {
if (err1) { throw new Error('Repository path is not initialized: ' + workTree); }
gitCommands = ['--git-dir=' + gitDir, '--work-tree=' + workTree];
// run a smoke test of git and the repo:
ChildProcess.exec('git log -1 --oneline ', {cwd: workTree}, (err2) => {
if (err2) {
if (/fatal: your current branch 'master' does not have any commits yet/.test(err2.message)) {
throw new Error('Please add an initial commit to the repository: ' + workTree);
}
throw new Error(err2.message + ' in ' + workTree);
function addPrettyAndUrlTo(object) {
object.pretty = true; // makes the generated html nicer, in case someone looks at the mail body
object.url = conf.get('publicUrlPrefix');
}
module.exports = function redirectIfNotSoCraTesAdmin(req, res, next) {
const originalUrl = req.originalUrl;
const user = req.user;
if (securedBySoCraTesAdminURLRegex && securedBySoCraTesAdminURLRegex.test(originalUrl)) {
if (!res.locals.accessrights.isSoCraTesAdmin()) {
logger.info('Someone tried to access SoCraTes-Admin protected page ' + originalUrl + ' ' + (user ? ' - User was: ' + user.authenticationId : ''));
return res.redirect('/mustBeSoCraTesAdmin?page=' + encodeURIComponent(conf.get('publicUrlPrefix') + originalUrl));
}
}
next();
};
module.exports = function redirectIfNotSuperuser(req, res, next) {
const originalUrl = req.originalUrl;
const user = req.user;
if (securedBySuperuserURLRegex.test(originalUrl)) {
if (!res.locals.accessrights.isSuperuser()) {
logger.info('Someone tried to access superuser protected page ' + originalUrl + ' ' + (user ? ' - User was: ' + user.authenticationId : ''));
return res.redirect('/mustBeSuperuser?page=' + encodeURIComponent(conf.get('publicUrlPrefix') + originalUrl));
}
}
next();
};
const beans = require('simple-configure').get('beans');
const misc = beans.get('misc');
const dashboardService = beans.get('dashboardService');
const app = misc.expressAppIn(__dirname);
app.get('/', (req, res, next) => {
dashboardService.dataForDashboard(req.user.member.nickname(), (err, result) => {
if (err) { return next(err); }
res.render('index', result);
});
});
module.exports = app;
'use strict';
const beans = require('simple-configure').get('beans');
const misc = beans.get('misc');
const subscriberstore = beans.get('subscriberstore');
const app = misc.expressAppIn(__dirname);
app.get('/count', (req, res) => {
subscriberstore.allSubscribers((err, subscribers) => {
if (err || !subscribers) { return res.end(''); }
res.end(subscribers.length.toString());
});
});
module.exports = app;
const conf = require('simple-configure');
const beans = conf.get('beans');
const Group = beans.get('group');
module.exports = {
bodyToGroup: function (body) {
const override = {
contactTheOrganizers: body.contactTheOrganizers ? body.contactTheOrganizers === 'on' : false
};
const mapped = Object.assign({}, body, override);
return new Group(mapped);
}
};
'use strict';
var store = require('simple-configure').get('beans').get('announcementstore');
var _ = require('lodash');
module.exports = function latestNews(req, res, next) {
store.allAnnouncementsUntilToday(function (err, news) {
if (err) {return next(err); }
var maxNewsInSidebar = 5;
res.locals.latestNews = _.take(news, maxNewsInSidebar);
res.locals.displayMoreNews = news.length > maxNewsInSidebar;
next();
});
};
'use strict';
const Git = require('simple-configure').get('beans').get('gitmech');
module.exports = function subdirs(req, res, next) {
Git.lsdirs((err, gitdirs) => {
res.locals.wikisubdirs = gitdirs;
next(err);
});
};
static isSuperuser(id) {
const superusers = conf.get('superuser');
return superusers && superusers.indexOf(id) > -1;
}