Skip to content

Commit

Permalink
Add drop and change pass db
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Dec 15, 2024
1 parent 02862b2 commit b5b105f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 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": "1.0.241212",
"version": "1.0.241215",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
42 changes: 23 additions & 19 deletions src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,27 @@ export default async function runConfig(config, domain, writer, sandbox = false)
domain,
});
if (value.pass) {
await writeLog("$> virtualmin modify-database-pass mysql");
if (domaindata['Features']?.includes('mysql')) {
await virtExec("modify-database-pass", {
domain,
pass: value.pass,
type: 'mysql',
});
if (domaindata['Password for mysql'] == domaindata['Password']) {
if (domaindata['Features']?.includes('mysql')) {
await writeLog("$> virtualmin modify-database-pass mysql");
await virtExec("modify-database-pass", {
domain,
pass: value.pass,
type: 'mysql',
});
domaindata['Password for mysql'] = value.pass;
}
}
if (domaindata['Features']?.includes('postgres')) {
await writeLog("$> virtualmin modify-database-pass postgres");
await virtExec("modify-database-pass", {
domain,
pass: value.pass,
type: 'postgres',
});
if (domaindata['Password for postgres'] == domaindata['Password']) {
if (domaindata['Features']?.includes('postgres')) {
await writeLog("$> virtualmin modify-database-pass postgres");
await virtExec("modify-database-pass", {
domain,
pass: value.pass,
type: 'postgres',
});
domaindata['Password for postgres'] = value.pass;
}
}
}
break;
Expand Down Expand Up @@ -358,17 +364,15 @@ export default async function runConfig(config, domain, writer, sandbox = false)
if (cb) cb('', 124);
}, maxExecutionTime).unref();

const pw = domaindata['Password for mysql'] || domaindata['Password or postgres'] || domaindata['Password'];

await sshExec('unset HISTFILE TERM', false); // https://stackoverflow.com/a/9039154/3908409
await sshExec(`export CI=true CONTINUOUS_INTEGRATION=true LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 `, false);
await sshExec(`export PIP_PROGRESS_BAR=off BUILDKIT_PROGRESS=plain`, false);
await sshExec(` USERNAME='${domaindata['Username']}' PASSWORD='${pw}'`, false);
await sshExec(` USERNAME='${domaindata['Username']}' PASSWORD='${domaindata['Password']}'`, false);
if (domaindata['Password for mysql']) {
await sshExec(` MY_PASSWORD='${domaindata['Password for mysql']}'`, false);
await sshExec(` MYPASSWD='${domaindata['Password for mysql']}'`, false);
}
if (domaindata['Password or postgres']) {
await sshExec(` PG_PASSWORD='${domaindata['Password or postgres']}'`, false);
await sshExec(` PGPASSWD='${domaindata['Password or postgres']}'`, false);
}
const firewallOn = await firewallStatus();
if (config.subdomain) {
Expand Down
40 changes: 39 additions & 1 deletion src/executor/runnersub.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,26 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
name: dbname,
type: 'mysql',
});
} else if (!value) {
} else if (value.startsWith("drop ")) {
let dropdb = value.substr("drop ".length).trim();
dbname = getDbName(domaindata['Username'], domainprefix == "db" ? dropdb : domainprefix + '_' + dropdb);
await virtExec("delete-database", {
domain: subdomain,
name: dbname,
type: 'mysql',
});
} else if (value.startsWith("modify-pass ")) {
let pass = value.substr("modify-pass ".length).trim();
if (pass) {
await virtExec("modify-database-pass", {
domain: subdomain,
pass,
type: 'mysql',
});
subdomaindata['Password for mysql'] = pass;
await sshExec(` MY_PASSWORD='${pass}'`, false);
}
} else if (!value) {
await writeLog(`$> MySQL is already initialized. To create another database, use "mysql create dbname"`);
}
break;
Expand Down Expand Up @@ -134,6 +153,25 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
type: 'postgres',
}
);
} else if (value.startsWith("drop ")) {
let dropdb = value.substr("drop ".length).trim();
dbname = getDbName(domaindata['Username'], domainprefix == "db" ? dropdb : domainprefix + '_' + dropdb);
await virtExec("delete-database", {
domain: subdomain,
name: dbname,
type: 'postgres',
});
} else if (value.startsWith("modify-pass ")) {
let pass = value.substr("modify-pass ".length).trim();
if (pass) {
await virtExec("modify-database-pass", {
domain: subdomain,
pass,
type: 'postgres',
});
subdomaindata['Password for postgres'] = pass;
await sshExec(` PG_PASSWORD='${pass}'`, false);
}
} else if (!value) {
await writeLog(`$> PostgreSQL is already initialized. To create another database, use "postgresql create dbname"`);
}
Expand Down

0 comments on commit b5b105f

Please sign in to comment.