mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-09 11:55:52 +08:00
feat: PHP 网站增加配置上传限制功能 (#1133)
This commit is contained in:
parent
f65f0d86aa
commit
aa3e8783ae
8 changed files with 112 additions and 4 deletions
|
|
@ -142,6 +142,7 @@ type WebsitePHPConfigUpdate struct {
|
||||||
Params map[string]string `json:"params"`
|
Params map[string]string `json:"params"`
|
||||||
Scope string `json:"scope" validate:"required"`
|
Scope string `json:"scope" validate:"required"`
|
||||||
DisableFunctions []string `json:"disableFunctions"`
|
DisableFunctions []string `json:"disableFunctions"`
|
||||||
|
UploadMaxSize string `json:"uploadMaxSize"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebsitePHPFileUpdate struct {
|
type WebsitePHPFileUpdate struct {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ type WebsiteLog struct {
|
||||||
type PHPConfig struct {
|
type PHPConfig struct {
|
||||||
Params map[string]string `json:"params"`
|
Params map[string]string `json:"params"`
|
||||||
DisableFunctions []string `json:"disableFunctions"`
|
DisableFunctions []string `json:"disableFunctions"`
|
||||||
|
UploadMaxSize string `json:"uploadMaxSize"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NginxRewriteRes struct {
|
type NginxRewriteRes struct {
|
||||||
|
|
|
||||||
|
|
@ -1026,6 +1026,10 @@ func (w WebsiteService) GetPHPConfig(id uint) (*response.PHPConfig, error) {
|
||||||
res.DisableFunctions = disableFunctions
|
res.DisableFunctions = disableFunctions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uploadMaxSize := phpConfig.Key("upload_max_filesize").Value()
|
||||||
|
if uploadMaxSize != "" {
|
||||||
|
res.UploadMaxSize = uploadMaxSize
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1089,9 +1093,14 @@ func (w WebsiteService) UpdatePHPConfig(req request.WebsitePHPConfigUpdate) (err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.Scope == "uploadSize" {
|
if req.Scope == "upload_max_filesize" {
|
||||||
postMaxSize := phpConfig.Key("post_max_size")
|
postMaxSize := phpConfig.Key("post_max_size")
|
||||||
postMaxSize.SetValue("")
|
postMaxSize.SetValue(req.UploadMaxSize)
|
||||||
|
uploadMaxFileSize := phpConfig.Key("upload_max_filesize")
|
||||||
|
uploadMaxFileSize.SetValue(req.UploadMaxSize)
|
||||||
|
if err = cfg.SaveTo(phpConfigPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appInstallReq := request.AppInstalledOperate{
|
appInstallReq := request.AppInstalledOperate{
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,7 @@ export namespace Website {
|
||||||
export interface PHPConfig {
|
export interface PHPConfig {
|
||||||
params: any;
|
params: any;
|
||||||
disableFunctions: string[];
|
disableFunctions: string[];
|
||||||
|
uploadMaxSize: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PHPConfigUpdate {
|
export interface PHPConfigUpdate {
|
||||||
|
|
@ -277,6 +278,7 @@ export namespace Website {
|
||||||
params?: any;
|
params?: any;
|
||||||
disableFunctions?: string[];
|
disableFunctions?: string[];
|
||||||
scope: string;
|
scope: string;
|
||||||
|
uploadMaxSize?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PHPUpdate {
|
export interface PHPUpdate {
|
||||||
|
|
|
||||||
|
|
@ -1390,6 +1390,7 @@ const message = {
|
||||||
second: 'Second',
|
second: 'Second',
|
||||||
disableFunction: 'Disable function',
|
disableFunction: 'Disable function',
|
||||||
disableFunctionHelper: 'Enter the function to be disabled, such as exec, please use multiple, split',
|
disableFunctionHelper: 'Enter the function to be disabled, such as exec, please use multiple, split',
|
||||||
|
uploadMaxSize: 'Upload limit',
|
||||||
},
|
},
|
||||||
nginx: {
|
nginx: {
|
||||||
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',
|
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',
|
||||||
|
|
|
||||||
|
|
@ -1371,6 +1371,7 @@ const message = {
|
||||||
second: '秒',
|
second: '秒',
|
||||||
disableFunction: '禁用函数',
|
disableFunction: '禁用函数',
|
||||||
disableFunctionHelper: '输入要禁用的函数,例如exec,多个请用,分割',
|
disableFunctionHelper: '输入要禁用的函数,例如exec,多个请用,分割',
|
||||||
|
uploadMaxSize: '上传限制',
|
||||||
},
|
},
|
||||||
nginx: {
|
nginx: {
|
||||||
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',
|
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<el-tabs tab-position="left" v-model="index">
|
<el-tabs tab-position="left" v-model="index">
|
||||||
<el-tab-pane :label="$t('website.updateConfig')" name="0">
|
<el-tab-pane :label="$t('website.updateConfig')" name="0">
|
||||||
<Config :id="id"></Config>
|
<Config :id="id" v-if="index == '0'"></Config>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane :label="$t('php.disableFunction')" name="1">
|
<el-tab-pane :label="$t('php.disableFunction')" name="1">
|
||||||
<Function :id="id"></Function>
|
<Function :id="id" v-if="index == '1'"></Function>
|
||||||
|
</el-tab-pane>
|
||||||
|
<el-tab-pane :label="$t('php.uploadMaxSize')" name="2">
|
||||||
|
<Upload :id="id" v-if="index == '2'"></Upload>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -15,6 +18,7 @@ import { GetWebsite } from '@/api/modules/website';
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
import Config from './config/index.vue';
|
import Config from './config/index.vue';
|
||||||
import Function from './function/index.vue';
|
import Function from './function/index.vue';
|
||||||
|
import Upload from './upload/index.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
id: {
|
id: {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
<template>
|
||||||
|
<div v-loading="loading">
|
||||||
|
<el-row>
|
||||||
|
<el-col :xs="20" :sm="12" :md="10" :lg="10" :xl="8" :offset="1">
|
||||||
|
<el-form :model="form" :rules="rules" ref="phpFormRef">
|
||||||
|
<el-form-item>
|
||||||
|
<el-input clearable v-model.number="form.uploadSize" maxlength="15">
|
||||||
|
<template #append>M</template>
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<el-button type="primary" @click="openCreate(phpFormRef)">
|
||||||
|
{{ $t('commons.button.save') }}
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<ConfirmDialog ref="confirmDialogRef" @confirm="submit"></ConfirmDialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { GetPHPConfig, UpdatePHPConfig } from '@/api/modules/website';
|
||||||
|
import { checkNumberRange } from '@/global/form-rules';
|
||||||
|
import { computed, onMounted, reactive } from 'vue';
|
||||||
|
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { FormInstance } from 'element-plus';
|
||||||
|
import i18n from '@/lang';
|
||||||
|
import { MsgSuccess } from '@/utils/message';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
id: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const websiteID = computed(() => {
|
||||||
|
return props.id;
|
||||||
|
});
|
||||||
|
const rules = reactive({
|
||||||
|
uploadSize: [checkNumberRange(0, 999999999)],
|
||||||
|
});
|
||||||
|
const phpFormRef = ref();
|
||||||
|
const confirmDialogRef = ref();
|
||||||
|
const loading = ref(false);
|
||||||
|
const form = ref({
|
||||||
|
uploadSize: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const search = () => {
|
||||||
|
loading.value = true;
|
||||||
|
GetPHPConfig(websiteID.value)
|
||||||
|
.then((res) => {
|
||||||
|
form.value.uploadSize = parseFloat(res.data.uploadMaxSize.replace(/[^\d.]/g, ''));
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCreate = async (formEl: FormInstance | undefined) => {
|
||||||
|
if (!formEl) return;
|
||||||
|
formEl.validate(async (valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
let params = {
|
||||||
|
header: i18n.global.t('database.confChange'),
|
||||||
|
operationInfo: i18n.global.t('database.restartNowHelper'),
|
||||||
|
submitInputInfo: i18n.global.t('database.restartNow'),
|
||||||
|
};
|
||||||
|
confirmDialogRef.value!.acceptParams(params);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const submit = () => {
|
||||||
|
loading.value = true;
|
||||||
|
const uploadMaxSize = form.value.uploadSize + 'M';
|
||||||
|
UpdatePHPConfig({ scope: 'upload_max_filesize', id: websiteID.value, uploadMaxSize: uploadMaxSize })
|
||||||
|
.then(() => {
|
||||||
|
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
|
||||||
|
search();
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
search();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
Add table
Reference in a new issue