Skip to content

Commit

Permalink
nginx ordering n Podman API
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Jan 2, 2024
1 parent 35d53fe commit f5753f4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 54 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domcloud-bridge",
"version": "0.37.0",
"version": "0.37.1",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/named.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
checkAuth,
checkGet,
checkPost,
} from '../util.js';
Expand All @@ -9,22 +8,22 @@ import {
} from '../executor/named.js';
export default function () {
var router = express.Router();
router.post('/resync', checkAuth, checkGet(['zone']), async function (req, res, next) {
router.post('/resync', checkGet(['zone']), async function (req, res, next) {
try {
await executor.resync(req.query.zone.toString());
res.json("OK");
} catch (error) {
next(error);
}
});
router.get('/show', checkAuth, checkGet(['zone']), async function (req, res, next) {
router.get('/show', checkGet(['zone']), async function (req, res, next) {
try {
res.json(await executor.show(req.query.zone.toString()));
} catch (error) {
next(error);
}
});
router.post('/modify', checkAuth, checkGet(['zone']), async function (req, res, next) {
router.post('/modify', checkGet(['zone']), async function (req, res, next) {
try {
res.json(await executor.set(req.query.zone.toString(), req.body));
} catch (error) {
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/nginx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
checkAuth,
checkGet,
checkPost,
} from '../util.js';
Expand All @@ -9,7 +8,7 @@ import {
} from '../executor/nginx.js';
export default function () {
var router = express.Router();
router.get('/', checkAuth, checkGet(['domain']), async function (req, res, next) {
router.get('/', checkGet(['domain']), async function (req, res, next) {
try {
const node = await executor.get(req.query.domain + "");
const raw = node.toString();
Expand All @@ -21,15 +20,15 @@ export default function () {
next(error);
}
});
router.post('/', checkAuth, checkGet(['domain']), async function (req, res, next) {
router.post('/', checkGet(['domain']), async function (req, res, next) {
try {
res.contentType('text/plain');
return res.send(await executor.set("" + req.query.domain, req.body || {}));
} catch (error) {
next(error);
}
});
router.post('/ssl', checkAuth, checkGet(['domain']), checkPost(['ssl']), async function (req, res, next) {
router.post('/ssl', checkGet(['domain']), checkPost(['ssl']), async function (req, res, next) {
try {
res.contentType('text/plain');
return res.send(await executor.setSsl("" + req.query.domain, req.body.ssl, req.body.http + ""));
Expand Down
34 changes: 34 additions & 0 deletions src/controllers/podman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import express from 'express';
import {
podmanExec as executor
} from '../executor/podman.js';
import {
checkGet,
checkPost
} from '../util.js';

export default function () {
var router = express.Router();
router.get('/show', checkGet(['user']), async function (req, res, next) {
try {
res.json([executor.checkPodmanEnabled(req.query.user.toString())]);
} catch (error) {
next(error);
}
});
router.post('/add', checkPost(['user']), async function (req, res, next) {
try {
res.json(await executor.enablePodman(req.body.user.toString()));
} catch (error) {
next(error);
}
});
router.post('/del', checkPost(['user']), async function (req, res, next) {
try {
res.json(await executor.disablePodman(req.body.user.toString()));
} catch (error) {
next(error);
}
});
return router;
}
3 changes: 1 addition & 2 deletions src/controllers/runner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
checkAuth,
checkGet,
normalizeShellOutput,
} from '../util.js';
Expand Down Expand Up @@ -148,7 +147,7 @@ export async function runConfigInBackgroundSingleton(payload) {

export default function () {
var router = express.Router();
router.post('/', checkAuth, checkGet(['domain']), async function (req, res, next) {
router.post('/', checkGet(['domain']), async function (req, res, next) {
runConfigInBackgroundSingleton({
body: req.body,
domain: req.query.domain + "",
Expand Down
1 change: 0 additions & 1 deletion src/controllers/screend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import express from 'express';
import {
checkGet,
checkPost,
spawnSudoUtil
} from '../util.js';
import { screendExecutor } from '../executor/screend.js';

Expand Down
10 changes: 5 additions & 5 deletions src/controllers/virtualmin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express';
import { virtualminExec } from '../executor/virtualmin.js';
import { checkAuth, checkGet } from '../util.js';
import { checkGet } from '../util.js';

export default function () {
var router = express.Router();
router.get('/create-link', checkAuth, checkGet(['user']), async function (req, res, next) {
router.get('/create-link', checkGet(['user']), async function (req, res, next) {
try {
res.send((await virtualminExec.execFormatted('create-login-link', {
user: req.query.user.toString(),
Expand All @@ -13,22 +13,22 @@ export default function () {
next(error);
}
});
router.get('/list-domains', checkAuth, checkGet(['domain']), async function (req, res, next) {
router.get('/list-domains', checkGet(['domain']), async function (req, res, next) {
try {
res.send(await virtualminExec.getDomainInfo(req.query.domain.toString().split(','), false));
} catch (error) {
next(error);
}
});
router.get('/list-all-domains', checkAuth, async function (req, res, next) {
router.get('/list-all-domains', async function (req, res, next) {
try {
let proc = await virtualminExec.execFormatted('list-domains', { 'name-only': true, 'toplevel': true });
res.send(proc.stdout.trim().split('\n'));
} catch (error) {
next(error);
}
});
router.get('/list-bandwidth', checkAuth, checkGet(['domain']), async function (req, res, next) {
router.get('/list-bandwidth', checkGet(['domain']), async function (req, res, next) {
try {
res.send(await virtualminExec.getBandwidthInfo(req.query.domain.toString().split(',')));
} catch (error) {
Expand Down
68 changes: 34 additions & 34 deletions src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
break;
}
}

if (stillroot) {
subdomaindata = domaindata
} else {
Expand All @@ -779,11 +780,42 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
return;
}
}

if (config.source || config.commands) {
await sshExec(`shopt -s dotglob`, false);
await sshExec(`export DOMAIN='${subdomain}'`, false);
await sshExec(`mkdir -p ${subdomaindata['Home directory']}/public_html && cd "$_"`);
}

if (config.nginx && config.nginx.root) {
// moved to config.features
config.features = (config.features || []).concat([{
root: config.nginx.root
}]);
delete config.nginx.root;
} else if (config.root) {
// moved to config.features
config.features = (config.features || []).concat([{
root: config.root
}]);
delete config.root;
}

if (Array.isArray(config.features)) {
await writeLog("$> Applying features");
for (const feature of config.features) {
if (typeof feature === 'string' && feature.match(/^ssl/)) {
continue;
}
await featureRunner(feature);
}
}

if (config.nginx) {
await writeLog("$> Applying nginx config on " + subdomain);
await writeLog(await nginxExec.set(subdomain, config.nginx));
}

if (config.source) {
if (typeof config.source === 'string') {
config.source = {
Expand Down Expand Up @@ -864,6 +896,7 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
await iptablesExec.setAddUser(domaindata['Username']);
}
}

if (config.commands) {
if (config.envs) {
let entries = Object.entries(config.envs);
Expand All @@ -886,43 +919,10 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
}
}


if (config.nginx && config.nginx.root) {
// moved to config.features
config.features = (config.features || []).concat([{
root: config.nginx.root
}]);
delete config.nginx.root;
} else if (config.root) {
// moved to config.features
config.features = (config.features || []).concat([{
root: config.root
}]);
delete config.root;
}

if (Array.isArray(config.features)) {
await writeLog("$> Applying features");
for (const feature of config.features) {
if (typeof feature === 'string' && feature.match(/^ssl/)) {
continue;
}
await featureRunner(feature);
}
}


if (process.env.MODE !== 'dev') {
if (config.nginx) {
await writeLog("$> Applying nginx config on " + subdomain);
await writeLog(await nginxExec.set(subdomain, config.nginx));
}

if (Array.isArray(config.features)) {
for (const feature of config.features) {
if (typeof feature === 'string' && feature.match(/^ssl/)) {
await featureRunner(feature);
}
await featureRunner(feature);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import status from './controllers/status.js';
import iptables from './controllers/iptables.js';
import screend from './controllers/screend.js';
import {
checkAuth,
initUtils
} from './util.js';
import runner from './controllers/runner.js';
import virtualmin from './controllers/virtualmin.js';
import podman from './controllers/podman.js';

dotenv.config();
initUtils();
Expand All @@ -18,11 +20,13 @@ const app = express();

app.use(express.static('public'));
app.use(express.json());
app.use('/named', named());
app.use('/status', status());
app.use(checkAuth);
app.use('/named', named());
app.use('/nginx', nginx());
app.use('/iptables', iptables());
app.use('/screend', screend());
app.use('/podman', podman());
app.use('/runner', runner());
app.use('/virtualmin', virtualmin());
app.use(function (err, req, res, next) {
Expand Down

0 comments on commit f5753f4

Please sign in to comment.