Support custom PHP server values (#218)

* Add the logic for custom php paths

* Add the i18n strings

* Fix some visual things
pull/222/head
Matt (IPv4) Cowley 2021-02-04 19:29:32 +00:00 committed by GitHub
parent 323cae4c50
commit ad63ca0c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 112 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -27,6 +27,7 @@ THE SOFTWARE.
import sslProfiles from '../../util/ssl_profiles';
import websiteConf from './website.conf';
import shareQuery from '../../util/share_query';
import phpPath from '../../util/php_path';
export default (domains, global) => {
const config = {};
@ -53,8 +54,8 @@ export default (domains, global) => {
if (global.php.phpBackupServer.computed)
config.http.push(['upstream php', {
server: [
`${global.php.phpServer.computed[0] === '/' ? 'unix:' : ''}${global.php.phpServer.computed}`,
`${global.php.phpBackupServer.computed[0] === '/' ? 'unix:' : ''}${global.php.phpBackupServer.computed} backup`,
phpPath(global),
`${phpPath(global, true)} backup`,
],
}]);

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import phpPath from '../../util/php_path';
export default (domains, global) => {
const legacyRouting = domains.some(d => d.routing.legacyPhpRouting.computed);
const config = {};
@ -42,8 +44,7 @@ export default (domains, global) => {
config['# fastcgi settings'] = '';
config.fastcgi_pass = domains.some(d => d.php.php.computed) && global.php.phpBackupServer.computed !== ''
? 'php'
: ((global.php.phpServer.computed[0] === '/' ? 'unix:' : '') + global.php.phpServer.computed);
? 'php' : phpPath(global);
config.fastcgi_index = 'index.php';
config.fastcgi_buffers = '8 16k';
config.fastcgi_buffer_size = '32k';

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -40,5 +40,6 @@ export default {
php74Socket: '7.4 socket',
php80Socket: '8.0 socket',
phpSocket: 'PHP socket',
custom: 'Custom',
disabled: 'Disabled',
};

View File

@ -40,5 +40,6 @@ export default {
php74Socket: 'Socket 7.4',
php80Socket: 'Socket 8.0',
phpSocket: 'Socket PHP',
custom: 'Custom', // TODO: translate
disabled: 'Désactivé',
};

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -40,5 +40,6 @@ export default {
php74Socket: 'Socket 7.4',
php80Socket: 'Socket 8.0',
phpSocket: 'Socket PHP',
custom: 'Custom', // TODO: translate
disabled: 'Desabilitado',
};

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -40,5 +40,6 @@ export default {
php74Socket: '7.4 socket',
php80Socket: '8.0 socket',
phpSocket: 'PHP socket',
custom: 'Custom', // TODO: translate
disabled: '禁用',
};

View File

@ -1,5 +1,5 @@
/*
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -40,5 +40,6 @@ export default {
php74Socket: '7.4 socket',
php80Socket: '8.0 socket',
phpSocket: 'PHP socket',
custom: 'Custom', // TODO: translate
disabled: '禁用',
};

View File

@ -1,5 +1,5 @@
<!--
Copyright 2020 DigitalOcean
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
@ -42,8 +42,8 @@ THE SOFTWARE.
</div>
<template v-else>
<div class="field is-horizontal">
<div class="field-label">
<div class="field is-horizontal is-aligned-top">
<div class="field-label has-margin-top">
<label class="label">{{ $t('templates.globalSections.php.phpServer') }}</label>
</div>
<div class="field-body">
@ -55,12 +55,18 @@ THE SOFTWARE.
:reduce="s => s.value"
></VueSelect>
</div>
<div v-if="phpServerCustomEnabled"
:class="`control${phpServerCustomChanged ? ' is-changed' : ''}`"
>
<input v-model="phpServerCustom" class="input" type="text" :placeholder="$props.data.phpServerCustom.default" />
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<div class="field is-horizontal is-aligned-top">
<div class="field-label has-margin-top">
<label class="label">{{ $t('templates.globalSections.php.phpBackupServer') }}</label>
</div>
<div class="field-body">
@ -73,6 +79,12 @@ THE SOFTWARE.
:reduce="s => s.value"
></VueSelect>
</div>
<div v-if="phpBackupServerCustomEnabled"
:class="`control${phpBackupServerCustomChanged ? ' is-changed' : ''}`"
>
<input v-model="phpBackupServerCustom" class="input" type="text" :placeholder="$props.data.phpBackupServerCustom.default" />
</div>
</div>
</div>
</div>
@ -98,7 +110,9 @@ THE SOFTWARE.
'/var/run/php/php7.4-fpm.sock': 'templates.globalSections.php.php74Socket',
'/var/run/php/php8.0-fpm.sock': 'templates.globalSections.php.php80Socket',
'/var/run/php/php-fpm.sock': 'templates.globalSections.php.phpSocket',
'custom': 'templates.globalSections.php.custom',
};
const hiddenValues = ['', 'custom'];
const defaults = {
phpServer: {
@ -106,11 +120,19 @@ THE SOFTWARE.
options: serverOptions,
enabled: true,
},
phpServerCustom: {
default: 'unix:/var/run/php/php-fpm.sock',
enabled: false,
},
phpBackupServer: {
default: '',
options: { '': 'templates.globalSections.php.disabled', ...serverOptions },
enabled: true,
},
phpBackupServerCustom: {
default: 'unix:/var/run/php/php-fpm.sock',
enabled: false,
},
};
export default {
@ -128,31 +150,47 @@ THE SOFTWARE.
...computedFromDefaults(defaults, 'php'), // Getters & setters for the delegated data
phpServerOptions() {
return Object.entries(this.$props.data.phpServer.options)
.map(([key, value]) => ({ label: `${this.$t(value)}${key ? `: ${key}` : ''}`, value: key }));
.map(([key, value]) => this.formattedOption(key, value));
},
phpBackupServerOptions() {
return Object.entries(this.$props.data.phpBackupServer.options)
.map(([key, value]) => ({ label: `${this.$t(value)}${key ? `: ${key}` : ''}`, value: key }));
.map(([key, value]) => this.formattedOption(key, value));
},
},
watch: {
// Check server selection is valid
'$props.data.phpServer': {
handler(data) {
// This might cause recursion, but seems not to
if (data.enabled)
if (data.enabled) {
// This might cause recursion, but seems not to
if (!Object.keys(data.options).includes(data.computed))
data.computed = data.default;
// Show the custom box
this.$props.data.phpServerCustom.enabled = data.computed === 'custom';
return;
}
// Hide custom if disabled
this.$props.data.phpServerCustom.enabled = false;
},
deep: true,
},
// Check backup server selection is valid
'$props.data.phpBackupServer': {
handler(data) {
// This might cause recursion, but seems not to
if (data.enabled)
if (data.enabled) {
// This might cause recursion, but seems not to
if (!Object.keys(data.options).includes(data.computed))
data.computed = data.default;
// Show the custom box
this.$props.data.phpBackupServerCustom.enabled = data.computed === 'custom';
return;
}
// Hide custom if disabled
this.$props.data.phpBackupServerCustom.enabled = false;
},
deep: true,
},
@ -175,11 +213,23 @@ THE SOFTWARE.
},
deep: true,
},
// Ensure 'Disabled' gets translated in VueSelect on language switch
// Ensure 'Custom'/'Disabled' get translated in VueSelect on language switch
'$i18n.locale'() {
const updated = this.phpBackupServerOptions
const updated = this.phpServerOptions
.find(x => x.value === this.$refs.phpServerOptions.$data._value.value);
if (updated) this.$refs.phpServerOptions.$data._value = updated;
const updatedBackup = this.phpBackupServerOptions
.find(x => x.value === this.$refs.phpBackupServerSelect.$data._value.value);
if (updated) this.$refs.phpBackupServerSelect.$data._value = updated;
if (updatedBackup) this.$refs.phpBackupServerSelect.$data._value = updatedBackup;
},
},
methods: {
formattedOption(key, value) {
return {
label: `${this.$t(value)}${hiddenValues.includes(key) ? '' : `: ${key}`}`,
value: key,
};
},
},
};

View File

@ -0,0 +1,31 @@
/*
Copyright 2021 DigitalOcean
This code is licensed under the MIT License.
You may obtain a copy of the License at
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
export default (global, backup = false) => {
const key = `php${backup ? 'Backup' : ''}Server`;
if (global.php[key].computed === 'custom') return global.php[`${key}Custom`].computed;
return (global.php[key].computed[0] === '/' ? 'unix:' : '') + global.php[key].computed;
};