coolify/apps/ui/src/lib/components/Services/Wordpress.svelte

229 lines
7 KiB
Svelte
Raw Normal View History

2022-02-10 14:47:44 +00:00
<script lang="ts">
2022-04-05 13:56:25 +00:00
import { post } from '$lib/api';
import { page } from '$app/stores';
2022-07-06 09:02:36 +00:00
import { status } from '$lib/store';
2022-02-10 14:47:44 +00:00
import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';
2022-04-05 13:56:25 +00:00
import Setting from '$lib/components/Setting.svelte';
import { browser } from '$app/env';
2022-04-02 22:18:48 +00:00
import { t } from '$lib/translations';
2022-07-06 09:02:36 +00:00
import { errorNotification, getDomain } from '$lib/common';
2022-02-10 14:47:44 +00:00
2022-07-06 09:02:36 +00:00
export let service: any;
export let readOnly: any;
export let settings: any;
2022-04-05 13:56:25 +00:00
const { id } = $page.params;
const { ipv4, ipv6 } = settings;
2022-04-05 13:56:25 +00:00
let ftpUrl = generateUrl(service.wordpress.ftpPublicPort);
let ftpUser = service.wordpress.ftpUser;
let ftpPassword = service.wordpress.ftpPassword;
let ftpLoading = false;
2022-05-10 08:12:13 +00:00
let ownMysql = service.wordpress.ownMysql;
2022-04-05 13:56:25 +00:00
2022-07-06 09:02:36 +00:00
function generateUrl(publicPort: any) {
2022-04-05 13:56:25 +00:00
return browser
2022-09-19 10:05:47 +00:00
? `sftp://${settings?.fqdn ? getDomain(settings.fqdn) : ipv4 || ipv6}:${publicPort}`
2022-04-05 13:56:25 +00:00
: 'Loading...';
}
2022-07-06 09:02:36 +00:00
async function changeSettings(name: any) {
2022-04-05 15:15:06 +00:00
if (ftpLoading) return;
2022-07-06 09:02:36 +00:00
if ($status.service.isRunning) {
2022-04-05 15:15:06 +00:00
ftpLoading = true;
let ftpEnabled = service.wordpress.ftpEnabled;
2022-04-05 13:56:25 +00:00
2022-04-05 15:15:06 +00:00
if (name === 'ftpEnabled') {
ftpEnabled = !ftpEnabled;
}
try {
const {
publicPort,
ftpUser: user,
ftpPassword: password
2022-07-06 09:02:36 +00:00
} = await post(`/services/${id}/wordpress/ftp`, {
2022-04-05 15:15:06 +00:00
ftpEnabled
});
ftpUrl = generateUrl(publicPort);
ftpUser = user;
ftpPassword = password;
service.wordpress.ftpEnabled = ftpEnabled;
2022-07-06 09:02:36 +00:00
} catch (error) {
2022-04-05 15:15:06 +00:00
return errorNotification(error);
} finally {
ftpLoading = false;
}
2022-05-10 08:12:13 +00:00
} else {
try {
if (name === 'ownMysql') {
ownMysql = !ownMysql;
}
2022-07-06 09:02:36 +00:00
await post(`/services/${id}/wordpress/settings`, {
2022-05-10 08:12:13 +00:00
ownMysql
});
service.wordpress.ownMysql = ownMysql;
} catch (error) {
2022-05-10 08:12:13 +00:00
return errorNotification(error);
}
2022-04-05 13:56:25 +00:00
}
}
2022-02-10 14:47:44 +00:00
</script>
2022-10-14 13:48:37 +00:00
<div class="flex flex-row border-b border-coolgray-500 my-6 space-x-2">
<div class="title font-bold pb-3">WordPress</div>
2022-02-10 14:47:44 +00:00
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="extraConfig">{$t('forms.extra_config')}</label>
<textarea
2022-09-19 10:05:47 +00:00
class="w-full"
2022-04-17 17:17:12 +00:00
bind:value={service.wordpress.extraConfig}
2022-07-22 12:01:07 +00:00
disabled={$status.service.isRunning || $status.service.initialLoading}
2022-07-06 09:02:36 +00:00
readonly={$status.service.isRunning}
class:resize-none={$status.service.isRunning}
2022-04-17 18:22:21 +00:00
rows="5"
name="extraConfig"
id="extraConfig"
2022-07-22 12:01:07 +00:00
placeholder={!$status.service.isRunning && !$status.service.initialLoading
2022-04-02 22:18:48 +00:00
? `${$t('forms.eg')}:
2022-02-10 14:47:44 +00:00
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);`
2022-04-17 17:17:12 +00:00
: 'N/A'}
/>
2022-02-10 14:47:44 +00:00
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-04-05 13:56:25 +00:00
<Setting
2022-09-02 06:43:02 +00:00
id="ftpEnabled"
2022-04-05 13:56:25 +00:00
bind:setting={service.wordpress.ftpEnabled}
loading={ftpLoading}
2022-07-06 09:02:36 +00:00
disabled={!$status.service.isRunning}
2022-04-05 13:56:25 +00:00
on:click={() => changeSettings('ftpEnabled')}
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."
/>
</div>
{#if service.wordpress.ftpEnabled}
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="ftpUrl">sFTP Connection URI</label>
2022-04-05 13:56:25 +00:00
<CopyPasswordField id="ftpUrl" readonly disabled name="ftpUrl" value={ftpUrl} />
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="ftpUser">User</label>
2022-04-05 13:56:25 +00:00
<CopyPasswordField id="ftpUser" readonly disabled name="ftpUser" value={ftpUser} />
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="ftpPassword">Password</label>
2022-07-22 12:01:07 +00:00
<CopyPasswordField
id="ftpPassword"
isPasswordField
readonly
disabled
name="ftpPassword"
value={ftpPassword}
/>
2022-04-05 13:56:25 +00:00
</div>
{/if}
2022-10-14 13:48:37 +00:00
<div class="flex flex-row border-b border-coolgray-500 my-6 space-x-2">
<div class="title font-bold pb-3">MySQL</div>
2022-02-10 14:47:44 +00:00
</div>
2022-09-19 10:05:47 +00:00
<div class="space-y-2">
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<Setting
id="ownMysql"
dataTooltip={$t('forms.must_be_stopped_to_modify')}
bind:setting={service.wordpress.ownMysql}
2022-07-06 09:02:36 +00:00
disabled={$status.service.isRunning}
2022-09-19 10:05:47 +00:00
on:click={() => !$status.service.isRunning && changeSettings('ownMysql')}
title="Use your own MySQL server"
description="Enables the use of your own MySQL server. If you don't have one, you can use the one provided by Coolify."
2022-05-10 08:12:13 +00:00
/>
</div>
2022-09-19 10:05:47 +00:00
{#if service.wordpress.ownMysql}
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlHost">Host</label>
<input
class="w-full"
name="mysqlHost"
id="mysqlHost"
required
readonly={$status.service.isRunning}
disabled={$status.service.isRunning}
bind:value={service.wordpress.mysqlHost}
placeholder="{$t('forms.eg')}: db.coolify.io"
/>
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlPort">Port</label>
<input
class="w-full"
name="mysqlPort"
id="mysqlPort"
required
readonly={$status.service.isRunning}
disabled={$status.service.isRunning}
bind:value={service.wordpress.mysqlPort}
placeholder="{$t('forms.eg')}: 3306"
/>
</div>
{/if}
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlDatabase">{$t('index.database')}</label>
2022-05-10 08:12:13 +00:00
<input
2022-09-19 10:05:47 +00:00
class="w-full"
name="mysqlDatabase"
id="mysqlDatabase"
2022-05-10 08:12:13 +00:00
required
2022-09-19 10:05:47 +00:00
readonly={readOnly && !service.wordpress.ownMysql}
disabled={readOnly && !service.wordpress.ownMysql}
bind:value={service.wordpress.mysqlDatabase}
placeholder="{$t('forms.eg')}: wordpress_db"
2022-05-10 08:12:13 +00:00
/>
</div>
2022-09-19 10:05:47 +00:00
{#if !service.wordpress.ownMysql}
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlRootUser">{$t('forms.root_user')}</label>
<input
class="w-full"
name="mysqlRootUser"
id="mysqlRootUser"
placeholder="MySQL {$t('forms.root_user')}"
value={service.wordpress.mysqlRootUser}
readonly={$status.service.isRunning || !service.wordpress.ownMysql}
disabled={$status.service.isRunning || !service.wordpress.ownMysql}
/>
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlRootUserPassword">{$t('forms.roots_password')}</label>
<CopyPasswordField
id="mysqlRootUserPassword"
isPasswordField
readonly={$status.service.isRunning || !service.wordpress.ownMysql}
disabled={$status.service.isRunning || !service.wordpress.ownMysql}
name="mysqlRootUserPassword"
value={service.wordpress.mysqlRootUserPassword}
/>
</div>
{/if}
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlUser">{$t('forms.user')}</label>
2022-05-10 08:12:13 +00:00
<input
2022-09-19 10:05:47 +00:00
class="w-full"
name="mysqlUser"
id="mysqlUser"
bind:value={service.wordpress.mysqlUser}
2022-07-06 09:02:36 +00:00
readonly={$status.service.isRunning || !service.wordpress.ownMysql}
disabled={$status.service.isRunning || !service.wordpress.ownMysql}
2022-05-10 08:12:13 +00:00
/>
</div>
2022-10-14 13:48:37 +00:00
<div class="grid grid-cols-2 items-center px-4">
2022-09-19 10:05:47 +00:00
<label for="mysqlPassword">{$t('forms.password')}</label>
2022-05-10 08:12:13 +00:00
<CopyPasswordField
2022-09-19 10:05:47 +00:00
id="mysqlPassword"
2022-05-10 08:12:13 +00:00
isPasswordField
2022-07-06 09:02:36 +00:00
readonly={$status.service.isRunning || !service.wordpress.ownMysql}
disabled={$status.service.isRunning || !service.wordpress.ownMysql}
2022-09-19 10:05:47 +00:00
name="mysqlPassword"
bind:value={service.wordpress.mysqlPassword}
2022-05-10 08:12:13 +00:00
/>
</div>
2022-02-10 14:47:44 +00:00
</div>