Support custom PHP server values (#218)
* Add the logic for custom php paths * Add the i18n strings * Fix some visual thingspull/222/head
parent
323cae4c50
commit
ad63ca0c8b
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||||
import sslProfiles from '../../util/ssl_profiles';
|
import sslProfiles from '../../util/ssl_profiles';
|
||||||
import websiteConf from './website.conf';
|
import websiteConf from './website.conf';
|
||||||
import shareQuery from '../../util/share_query';
|
import shareQuery from '../../util/share_query';
|
||||||
|
import phpPath from '../../util/php_path';
|
||||||
|
|
||||||
export default (domains, global) => {
|
export default (domains, global) => {
|
||||||
const config = {};
|
const config = {};
|
||||||
|
@ -53,8 +54,8 @@ export default (domains, global) => {
|
||||||
if (global.php.phpBackupServer.computed)
|
if (global.php.phpBackupServer.computed)
|
||||||
config.http.push(['upstream php', {
|
config.http.push(['upstream php', {
|
||||||
server: [
|
server: [
|
||||||
`${global.php.phpServer.computed[0] === '/' ? 'unix:' : ''}${global.php.phpServer.computed}`,
|
phpPath(global),
|
||||||
`${global.php.phpBackupServer.computed[0] === '/' ? 'unix:' : ''}${global.php.phpBackupServer.computed} backup`,
|
`${phpPath(global, true)} backup`,
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
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.
|
THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import phpPath from '../../util/php_path';
|
||||||
|
|
||||||
export default (domains, global) => {
|
export default (domains, global) => {
|
||||||
const legacyRouting = domains.some(d => d.routing.legacyPhpRouting.computed);
|
const legacyRouting = domains.some(d => d.routing.legacyPhpRouting.computed);
|
||||||
const config = {};
|
const config = {};
|
||||||
|
@ -42,8 +44,7 @@ export default (domains, global) => {
|
||||||
|
|
||||||
config['# fastcgi settings'] = '';
|
config['# fastcgi settings'] = '';
|
||||||
config.fastcgi_pass = domains.some(d => d.php.php.computed) && global.php.phpBackupServer.computed !== ''
|
config.fastcgi_pass = domains.some(d => d.php.php.computed) && global.php.phpBackupServer.computed !== ''
|
||||||
? 'php'
|
? 'php' : phpPath(global);
|
||||||
: ((global.php.phpServer.computed[0] === '/' ? 'unix:' : '') + global.php.phpServer.computed);
|
|
||||||
config.fastcgi_index = 'index.php';
|
config.fastcgi_index = 'index.php';
|
||||||
config.fastcgi_buffers = '8 16k';
|
config.fastcgi_buffers = '8 16k';
|
||||||
config.fastcgi_buffer_size = '32k';
|
config.fastcgi_buffer_size = '32k';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -40,5 +40,6 @@ export default {
|
||||||
php74Socket: '7.4 socket',
|
php74Socket: '7.4 socket',
|
||||||
php80Socket: '8.0 socket',
|
php80Socket: '8.0 socket',
|
||||||
phpSocket: 'PHP socket',
|
phpSocket: 'PHP socket',
|
||||||
|
custom: 'Custom',
|
||||||
disabled: 'Disabled',
|
disabled: 'Disabled',
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,5 +40,6 @@ export default {
|
||||||
php74Socket: 'Socket 7.4',
|
php74Socket: 'Socket 7.4',
|
||||||
php80Socket: 'Socket 8.0',
|
php80Socket: 'Socket 8.0',
|
||||||
phpSocket: 'Socket PHP',
|
phpSocket: 'Socket PHP',
|
||||||
|
custom: 'Custom', // TODO: translate
|
||||||
disabled: 'Désactivé',
|
disabled: 'Désactivé',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -40,5 +40,6 @@ export default {
|
||||||
php74Socket: 'Socket 7.4',
|
php74Socket: 'Socket 7.4',
|
||||||
php80Socket: 'Socket 8.0',
|
php80Socket: 'Socket 8.0',
|
||||||
phpSocket: 'Socket PHP',
|
phpSocket: 'Socket PHP',
|
||||||
|
custom: 'Custom', // TODO: translate
|
||||||
disabled: 'Desabilitado',
|
disabled: 'Desabilitado',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -40,5 +40,6 @@ export default {
|
||||||
php74Socket: '7.4 socket',
|
php74Socket: '7.4 socket',
|
||||||
php80Socket: '8.0 socket',
|
php80Socket: '8.0 socket',
|
||||||
phpSocket: 'PHP socket',
|
phpSocket: 'PHP socket',
|
||||||
|
custom: 'Custom', // TODO: translate
|
||||||
disabled: '禁用',
|
disabled: '禁用',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -40,5 +40,6 @@ export default {
|
||||||
php74Socket: '7.4 socket',
|
php74Socket: '7.4 socket',
|
||||||
php80Socket: '8.0 socket',
|
php80Socket: '8.0 socket',
|
||||||
phpSocket: 'PHP socket',
|
phpSocket: 'PHP socket',
|
||||||
|
custom: 'Custom', // TODO: translate
|
||||||
disabled: '禁用',
|
disabled: '禁用',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
Copyright 2020 DigitalOcean
|
Copyright 2021 DigitalOcean
|
||||||
|
|
||||||
This code is licensed under the MIT License.
|
This code is licensed under the MIT License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
@ -42,8 +42,8 @@ THE SOFTWARE.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal is-aligned-top">
|
||||||
<div class="field-label">
|
<div class="field-label has-margin-top">
|
||||||
<label class="label">{{ $t('templates.globalSections.php.phpServer') }}</label>
|
<label class="label">{{ $t('templates.globalSections.php.phpServer') }}</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-body">
|
<div class="field-body">
|
||||||
|
@ -55,12 +55,18 @@ THE SOFTWARE.
|
||||||
:reduce="s => s.value"
|
:reduce="s => s.value"
|
||||||
></VueSelect>
|
></VueSelect>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal is-aligned-top">
|
||||||
<div class="field-label">
|
<div class="field-label has-margin-top">
|
||||||
<label class="label">{{ $t('templates.globalSections.php.phpBackupServer') }}</label>
|
<label class="label">{{ $t('templates.globalSections.php.phpBackupServer') }}</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-body">
|
<div class="field-body">
|
||||||
|
@ -73,6 +79,12 @@ THE SOFTWARE.
|
||||||
:reduce="s => s.value"
|
:reduce="s => s.value"
|
||||||
></VueSelect>
|
></VueSelect>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -98,7 +110,9 @@ THE SOFTWARE.
|
||||||
'/var/run/php/php7.4-fpm.sock': 'templates.globalSections.php.php74Socket',
|
'/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/php8.0-fpm.sock': 'templates.globalSections.php.php80Socket',
|
||||||
'/var/run/php/php-fpm.sock': 'templates.globalSections.php.phpSocket',
|
'/var/run/php/php-fpm.sock': 'templates.globalSections.php.phpSocket',
|
||||||
|
'custom': 'templates.globalSections.php.custom',
|
||||||
};
|
};
|
||||||
|
const hiddenValues = ['', 'custom'];
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
phpServer: {
|
phpServer: {
|
||||||
|
@ -106,11 +120,19 @@ THE SOFTWARE.
|
||||||
options: serverOptions,
|
options: serverOptions,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
phpServerCustom: {
|
||||||
|
default: 'unix:/var/run/php/php-fpm.sock',
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
phpBackupServer: {
|
phpBackupServer: {
|
||||||
default: '',
|
default: '',
|
||||||
options: { '': 'templates.globalSections.php.disabled', ...serverOptions },
|
options: { '': 'templates.globalSections.php.disabled', ...serverOptions },
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
phpBackupServerCustom: {
|
||||||
|
default: 'unix:/var/run/php/php-fpm.sock',
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -128,31 +150,47 @@ THE SOFTWARE.
|
||||||
...computedFromDefaults(defaults, 'php'), // Getters & setters for the delegated data
|
...computedFromDefaults(defaults, 'php'), // Getters & setters for the delegated data
|
||||||
phpServerOptions() {
|
phpServerOptions() {
|
||||||
return Object.entries(this.$props.data.phpServer.options)
|
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() {
|
phpBackupServerOptions() {
|
||||||
return Object.entries(this.$props.data.phpBackupServer.options)
|
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: {
|
watch: {
|
||||||
// Check server selection is valid
|
// Check server selection is valid
|
||||||
'$props.data.phpServer': {
|
'$props.data.phpServer': {
|
||||||
handler(data) {
|
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))
|
if (!Object.keys(data.options).includes(data.computed))
|
||||||
data.computed = data.default;
|
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,
|
deep: true,
|
||||||
},
|
},
|
||||||
// Check backup server selection is valid
|
// Check backup server selection is valid
|
||||||
'$props.data.phpBackupServer': {
|
'$props.data.phpBackupServer': {
|
||||||
handler(data) {
|
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))
|
if (!Object.keys(data.options).includes(data.computed))
|
||||||
data.computed = data.default;
|
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,
|
deep: true,
|
||||||
},
|
},
|
||||||
|
@ -175,11 +213,23 @@ THE SOFTWARE.
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
// Ensure 'Disabled' gets translated in VueSelect on language switch
|
// Ensure 'Custom'/'Disabled' get translated in VueSelect on language switch
|
||||||
'$i18n.locale'() {
|
'$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);
|
.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,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue