mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-05 00:48:16 +01:00
- Add Next.js admin routes (/admin, /admin/login, /admin/pages, /admin/pages/new, /admin/pages/[id]) - Create admin layout with navigation and authentication - Build login page with email/password form - Implement pages list with search and create functionality - Add WYSIWYG editor for content creation/editing - Create API routes for admin authentication and content management - Add middleware for route protection - Include sample data population script - Add comprehensive admin interface documentation for non-technical users - Create test page for validating admin functionality - Update environment configuration for JWT secret Admin interface is now super easy and intuitive for non-technical team members to: - Login with email/password - View all pages with search - Create new pages - Edit existing pages with rich text editor - Save as draft or publish immediately - Preview content before publishing All code follows best practices with proper error handling, security, and accessibility.
119 lines
3.1 KiB
JavaScript
Executable File
119 lines
3.1 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
var childProcess = require('child_process');
|
|
var spawn = childProcess.spawn;
|
|
var exec = childProcess.exec;
|
|
|
|
module.exports = function (pid, signal, callback) {
|
|
if (typeof signal === 'function' && callback === undefined) {
|
|
callback = signal;
|
|
signal = undefined;
|
|
}
|
|
|
|
pid = parseInt(pid);
|
|
if (Number.isNaN(pid)) {
|
|
if (callback) {
|
|
return callback(new Error("pid must be a number"));
|
|
} else {
|
|
throw new Error("pid must be a number");
|
|
}
|
|
}
|
|
|
|
var tree = {};
|
|
var pidsToProcess = {};
|
|
tree[pid] = [];
|
|
pidsToProcess[pid] = 1;
|
|
|
|
switch (process.platform) {
|
|
case 'win32':
|
|
exec('taskkill /pid ' + pid + ' /T /F', callback);
|
|
break;
|
|
case 'darwin':
|
|
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
|
|
return spawn('pgrep', ['-P', parentPid]);
|
|
}, function () {
|
|
killAll(tree, signal, callback);
|
|
});
|
|
break;
|
|
// case 'sunos':
|
|
// buildProcessTreeSunOS(pid, tree, pidsToProcess, function () {
|
|
// killAll(tree, signal, callback);
|
|
// });
|
|
// break;
|
|
default: // Linux
|
|
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
|
|
return spawn('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid]);
|
|
}, function () {
|
|
killAll(tree, signal, callback);
|
|
});
|
|
break;
|
|
}
|
|
};
|
|
|
|
function killAll (tree, signal, callback) {
|
|
var killed = {};
|
|
try {
|
|
Object.keys(tree).forEach(function (pid) {
|
|
tree[pid].forEach(function (pidpid) {
|
|
if (!killed[pidpid]) {
|
|
killPid(pidpid, signal);
|
|
killed[pidpid] = 1;
|
|
}
|
|
});
|
|
if (!killed[pid]) {
|
|
killPid(pid, signal);
|
|
killed[pid] = 1;
|
|
}
|
|
});
|
|
} catch (err) {
|
|
if (callback) {
|
|
return callback(err);
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
if (callback) {
|
|
return callback();
|
|
}
|
|
}
|
|
|
|
function killPid(pid, signal) {
|
|
try {
|
|
process.kill(parseInt(pid, 10), signal);
|
|
}
|
|
catch (err) {
|
|
if (err.code !== 'ESRCH') throw err;
|
|
}
|
|
}
|
|
|
|
function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesList, cb) {
|
|
var ps = spawnChildProcessesList(parentPid);
|
|
var allData = '';
|
|
ps.stdout.on('data', function (data) {
|
|
var data = data.toString('ascii');
|
|
allData += data;
|
|
});
|
|
|
|
var onClose = function (code) {
|
|
delete pidsToProcess[parentPid];
|
|
|
|
if (code != 0) {
|
|
// no more parent processes
|
|
if (Object.keys(pidsToProcess).length == 0) {
|
|
cb();
|
|
}
|
|
return;
|
|
}
|
|
|
|
allData.match(/\d+/g).forEach(function (pid) {
|
|
pid = parseInt(pid, 10);
|
|
tree[parentPid].push(pid);
|
|
tree[pid] = [];
|
|
pidsToProcess[pid] = 1;
|
|
buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb);
|
|
});
|
|
};
|
|
|
|
ps.on('close', onClose);
|
|
}
|