Skip to content

Commit

Permalink
Add more func
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Dec 11, 2024
1 parent efb8e73 commit e8d64aa
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/domcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
webhook_auth: ${{ secrets.WEBHOOK_AUTH_AMS }}
data: >-
{"commands":["git pull","npm i","npm test","sudo systemctl restart bridge"]}
- name: Invoke WDC deployment hook
uses: distributhor/workflow-webhook@v3
env:
webhook_url: https://my.domcloud.co/api/githubdeploy
webhook_secret: ${{ secrets.WEBHOOK_SECRET_WDC }}
webhook_auth: ${{ secrets.WEBHOOK_AUTH_WDC }}
data: >-
{"commands":["git pull","npm i","npm test","sudo systemctl restart bridge"]}
- name: Invoke NUE deployment hook
uses: distributhor/workflow-webhook@v3
env:
Expand Down
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": "1.0.241211",
"version": "1.0.241212",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function () {
const node = await executor.get(req.query.domain + "");
const raw = node.toString();
res.json({
...executor.extractInfo(node, req.query.domain),
...executor.extractInfo(node, req.query.domain.toString()),
raw,
});
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
checkGet,
normalizeShellOutput,
spawnSudoUtil,
} from '../util.js';
import express from 'express';
import runConfig from '../executor/runner.js';
Expand Down Expand Up @@ -200,6 +201,9 @@ export async function runConfigInForeground(payload) {

export default function () {
var router = express.Router();
router.post('/cmd', checkGet(['user', 'cmd']), async function (req, res, next) {
res.send(await spawnSudoUtil('SHELL_SUDO', [req.query.user.toString(), "bash", "-c", req.query.cmd.toString()]));
});
router.post('/', checkGet(['domain']), async function (req, res, next) {
const callback = req.header('x-callback');
if (callback) {
Expand Down
14 changes: 14 additions & 0 deletions src/controllers/virtualmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,19 @@ export default function () {
next(error);
}
});
router.get('/list-databases', checkGet(['domain']), async function (req, res, next) {
try {
res.send(await virtualminExec.getDatabaseInfo(req.query.domain.toString()));
} catch (error) {
next(error);
}
});
router.get('/list-users', checkGet(['domain']), async function (req, res, next) {
try {
res.send(await virtualminExec.getUserInfo(req.query.domain.toString()));
} catch (error) {
next(error);
}
});
return router;
}
17 changes: 17 additions & 0 deletions src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ export default async function runConfig(config, domain, writer, sandbox = false)
firewallStatusCache = false;
}
break;
case 'sshpass':
if (value === '' || value === 'on') {
await writeLog("$> Changing ssh password login to " + (value || 'on'));
await virtExec("modify-users", {
domain,
'all-users': true,
'enable': true,
});
} else if (value === 'off') {
await writeLog("$> Changing ssh password login to " + value);
await virtExec("modify-users", {
domain,
'all-users': true,
'disable': true,
});
}
break;
default:
await runConfigCodeFeatures(key, value, writeLog, domaindata, sshExec);
break;
Expand Down
77 changes: 77 additions & 0 deletions src/executor/virtualmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,83 @@ class VirtualminExecutor {
}
return result;
}
/**
* @param {string} domain
*/
async getDatabaseInfo(domain) {
let r = await virtualminExec.execFormatted("list-databases", {
domain,
multiline: true,
});
if (process.env.NODE_ENV === 'development')
r = {
code: 0,
stdout: cat('./test/database'),
stderr: '',
}
if (r.code === 255)
throw r;
let data = r.stdout.split('\n'),
result = {},
neskey = '',
nesval = {};
for (let line of data) {
line = line.trimEnd();
if (line.length >= 4 && line[0] === ' ') {
let pair = splitLimit(line.trimStart(), /:/g, 2);
if (pair.length === 2) {
nesval[pair[0]] = pair[1].trimStart();
}
} else if (line.length >= 1 && !line.includes(' ')) {
if (neskey) {
result[neskey] = nesval;
nesval = {};
}
neskey = line;
}
}
result[neskey] = nesval;
return result;
}
/**
* @param {string} domain
*/
async getUserInfo(domain) {
let r = await virtualminExec.execFormatted("list-users", {
domain,
multiline: true,
'include-owner': true,
});
if (process.env.NODE_ENV === 'development')
r = {
code: 0,
stdout: cat('./test/user'),
stderr: '',
}
if (r.code === 255)
throw r;
let data = r.stdout.split('\n'),
result = {},
neskey = '',
nesval = {};
for (let line of data) {
line = line.trimEnd();
if (line.length >= 4 && line[0] === ' ') {
let pair = splitLimit(line.trimStart(), /:/g, 2);
if (pair.length === 2) {
nesval[pair[0]] = pair[1].trimStart();
}
} else if (line.length >= 1 && !line.includes(' ')) {
if (neskey) {
result[neskey] = nesval;
nesval = {};
}
neskey = line;
}
}
result[neskey] = nesval;
return result;
}
/**
* @param {string} program
* @param {object[]} opts
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dotenv.config();
initUtils();

const app = express();

app.set('trust proxy', 'loopback');
app.use(express.static('public'));
app.use(express.json());
app.use('/status', status());
Expand Down
2 changes: 1 addition & 1 deletion sudoutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ switch (cli.args.shift()) {
// just in case
if (!sudo.killed)
sudo.kill();
}, 1000 * 60 * 60).unref();
}, 1000 * 60).unref();
break;
case 'SHELL_INTERACTIVE':
arg = cli.args.shift();
Expand Down

0 comments on commit e8d64aa

Please sign in to comment.