feat: Finalize on-demand sftp for wp
This commit is contained in:
parent
8e9e6607e5
commit
fe9d0503fb
@ -0,0 +1,29 @@
|
|||||||
|
-- RedefineTables
|
||||||
|
PRAGMA foreign_keys=OFF;
|
||||||
|
CREATE TABLE "new_Wordpress" (
|
||||||
|
"id" TEXT NOT NULL PRIMARY KEY,
|
||||||
|
"extraConfig" TEXT,
|
||||||
|
"tablePrefix" TEXT,
|
||||||
|
"mysqlUser" TEXT NOT NULL,
|
||||||
|
"mysqlPassword" TEXT NOT NULL,
|
||||||
|
"mysqlRootUser" TEXT NOT NULL,
|
||||||
|
"mysqlRootUserPassword" TEXT NOT NULL,
|
||||||
|
"mysqlDatabase" TEXT,
|
||||||
|
"mysqlPublicPort" INTEGER,
|
||||||
|
"ftpEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"ftpUser" TEXT,
|
||||||
|
"ftpPassword" TEXT,
|
||||||
|
"ftpPublicPort" INTEGER,
|
||||||
|
"ftpHostKey" TEXT,
|
||||||
|
"ftpHostKeyPrivate" TEXT,
|
||||||
|
"serviceId" TEXT NOT NULL,
|
||||||
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" DATETIME NOT NULL,
|
||||||
|
CONSTRAINT "Wordpress_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "Service" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
INSERT INTO "new_Wordpress" ("createdAt", "extraConfig", "id", "mysqlDatabase", "mysqlPassword", "mysqlPublicPort", "mysqlRootUser", "mysqlRootUserPassword", "mysqlUser", "serviceId", "tablePrefix", "updatedAt") SELECT "createdAt", "extraConfig", "id", "mysqlDatabase", "mysqlPassword", "mysqlPublicPort", "mysqlRootUser", "mysqlRootUserPassword", "mysqlUser", "serviceId", "tablePrefix", "updatedAt" FROM "Wordpress";
|
||||||
|
DROP TABLE "Wordpress";
|
||||||
|
ALTER TABLE "new_Wordpress" RENAME TO "Wordpress";
|
||||||
|
CREATE UNIQUE INDEX "Wordpress_serviceId_key" ON "Wordpress"("serviceId");
|
||||||
|
PRAGMA foreign_key_check;
|
||||||
|
PRAGMA foreign_keys=ON;
|
@ -26,28 +26,31 @@
|
|||||||
: 'Loading...';
|
: 'Loading...';
|
||||||
}
|
}
|
||||||
async function changeSettings(name) {
|
async function changeSettings(name) {
|
||||||
ftpLoading = true;
|
if (ftpLoading) return;
|
||||||
let ftpEnabled = service.wordpress.ftpEnabled;
|
if (isRunning) {
|
||||||
|
ftpLoading = true;
|
||||||
|
let ftpEnabled = service.wordpress.ftpEnabled;
|
||||||
|
|
||||||
if (name === 'ftpEnabled') {
|
if (name === 'ftpEnabled') {
|
||||||
ftpEnabled = !ftpEnabled;
|
ftpEnabled = !ftpEnabled;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
publicPort,
|
publicPort,
|
||||||
ftpUser: user,
|
ftpUser: user,
|
||||||
ftpPassword: password
|
ftpPassword: password
|
||||||
} = await post(`/services/${id}/wordpress/settings.json`, {
|
} = await post(`/services/${id}/wordpress/settings.json`, {
|
||||||
ftpEnabled
|
ftpEnabled
|
||||||
});
|
});
|
||||||
ftpUrl = generateUrl(publicPort);
|
ftpUrl = generateUrl(publicPort);
|
||||||
ftpUser = user;
|
ftpUser = user;
|
||||||
ftpPassword = password;
|
ftpPassword = password;
|
||||||
service.wordpress.ftpEnabled = ftpEnabled;
|
service.wordpress.ftpEnabled = ftpEnabled;
|
||||||
} catch ({ error }) {
|
} catch ({ error }) {
|
||||||
return errorNotification(error);
|
return errorNotification(error);
|
||||||
} finally {
|
} finally {
|
||||||
ftpLoading = false;
|
ftpLoading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -78,6 +81,7 @@ define('SUBDOMAIN_INSTALL', false);`
|
|||||||
<Setting
|
<Setting
|
||||||
bind:setting={service.wordpress.ftpEnabled}
|
bind:setting={service.wordpress.ftpEnabled}
|
||||||
loading={ftpLoading}
|
loading={ftpLoading}
|
||||||
|
disabled={!isRunning}
|
||||||
on:click={() => changeSettings('ftpEnabled')}
|
on:click={() => changeSettings('ftpEnabled')}
|
||||||
title="Enable sFTP connection to WordPress data"
|
title="Enable sFTP connection to WordPress data"
|
||||||
description="Enables an on-demand sFTP connection to the WordPress data directory. This is useful if you want to use sFTP to upload files."
|
description="Enables an on-demand sFTP connection to the WordPress data directory. This is useful if you want to use sFTP to upload files."
|
||||||
|
@ -40,34 +40,34 @@ export const post: RequestHandler = async (event) => {
|
|||||||
ftpHostKeyPrivate
|
ftpHostKeyPrivate
|
||||||
} = data;
|
} = data;
|
||||||
if (user) ftpUser = user;
|
if (user) ftpUser = user;
|
||||||
try {
|
|
||||||
await fs.stat(hostkeyDir);
|
|
||||||
} catch (error) {
|
|
||||||
await asyncExecShell(`mkdir -p ${hostkeyDir}`);
|
|
||||||
}
|
|
||||||
if (!ftpHostKey) {
|
|
||||||
await asyncExecShell(
|
|
||||||
`ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" -q -f /tmp/${id} < /dev/null`
|
|
||||||
);
|
|
||||||
const { stdout: ftpHostKey } = await asyncExecShell(`cat ${hostkeyDir}/${id}.ed25519`);
|
|
||||||
await db.prisma.wordpress.update({
|
|
||||||
where: { serviceId: id },
|
|
||||||
data: { ftpHostKey: encrypt(ftpHostKey.replace('\n', '')) }
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await asyncExecShell(`echo ${decrypt(ftpHostKey)} > ${hostkeyDir}/${id}.ed25519`);
|
|
||||||
}
|
|
||||||
if (!ftpHostKeyPrivate) {
|
|
||||||
await asyncExecShell(`ssh-keygen -t rsa -b 4096 -N "" -f /tmp/${id}.rsa < /dev/null`);
|
|
||||||
const { stdout: ftpHostKeyPrivate } = await asyncExecShell(`cat /tmp/${id}.rsa`);
|
|
||||||
await db.prisma.wordpress.update({
|
|
||||||
where: { serviceId: id },
|
|
||||||
data: { ftpHostKeyPrivate: encrypt(ftpHostKeyPrivate.replace('\n', '')) }
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await asyncExecShell(`echo ${decrypt(ftpHostKeyPrivate)} > ${hostkeyDir}/${id}.rsa`);
|
|
||||||
}
|
|
||||||
if (destinationDockerId) {
|
if (destinationDockerId) {
|
||||||
|
try {
|
||||||
|
await fs.stat(hostkeyDir);
|
||||||
|
} catch (error) {
|
||||||
|
await asyncExecShell(`mkdir -p ${hostkeyDir}`);
|
||||||
|
}
|
||||||
|
if (!ftpHostKey) {
|
||||||
|
await asyncExecShell(
|
||||||
|
`ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" -q -f ${hostkeyDir}/${id}.ed25519`
|
||||||
|
);
|
||||||
|
const { stdout: ftpHostKey } = await asyncExecShell(`cat ${hostkeyDir}/${id}.ed25519`);
|
||||||
|
await db.prisma.wordpress.update({
|
||||||
|
where: { serviceId: id },
|
||||||
|
data: { ftpHostKey: encrypt(ftpHostKey) }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await asyncExecShell(`echo "${decrypt(ftpHostKey)}" > ${hostkeyDir}/${id}.ed25519`);
|
||||||
|
}
|
||||||
|
if (!ftpHostKeyPrivate) {
|
||||||
|
await asyncExecShell(`ssh-keygen -t rsa -b 4096 -N "" -f ${hostkeyDir}/${id}.rsa`);
|
||||||
|
const { stdout: ftpHostKeyPrivate } = await asyncExecShell(`cat ${hostkeyDir}/${id}.rsa`);
|
||||||
|
await db.prisma.wordpress.update({
|
||||||
|
where: { serviceId: id },
|
||||||
|
data: { ftpHostKeyPrivate: encrypt(ftpHostKeyPrivate) }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await asyncExecShell(`echo "${decrypt(ftpHostKeyPrivate)}" > ${hostkeyDir}/${id}.rsa`);
|
||||||
|
}
|
||||||
const { network, engine } = destinationDocker;
|
const { network, engine } = destinationDocker;
|
||||||
const host = getEngine(engine);
|
const host = getEngine(engine);
|
||||||
if (ftpEnabled) {
|
if (ftpEnabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user