From b5b105fb0a9b209a9657b882b111b0dea3311cc5 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 15 Dec 2024 11:53:11 +0700 Subject: [PATCH] Add drop and change pass db --- package-lock.json | 4 ++-- package.json | 2 +- src/executor/runner.js | 42 +++++++++++++++++++++------------------ src/executor/runnersub.js | 40 ++++++++++++++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 40cdaa1..98b6d07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domcloud-bridge", - "version": "1.0.241212", + "version": "1.0.241215", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domcloud-bridge", - "version": "1.0.241212", + "version": "1.0.241215", "license": "MIT", "dependencies": { "cli": "^1.0.1", diff --git a/package.json b/package.json index 24ace8e..1220e2a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/executor/runner.js b/src/executor/runner.js index c69371a..b34e41b 100644 --- a/src/executor/runner.js +++ b/src/executor/runner.js @@ -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; @@ -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) { diff --git a/src/executor/runnersub.js b/src/executor/runnersub.js index 1fdcd88..18f8143 100644 --- a/src/executor/runnersub.js +++ b/src/executor/runnersub.js @@ -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; @@ -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"`); }