1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

feat: PHP 网站增加配置上传限制功能 (#1133)

This commit is contained in:
zhengkunwang223 2023-05-24 18:38:50 +08:00 committed by GitHub
parent f65f0d86aa
commit aa3e8783ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 4 deletions

View File

@ -142,6 +142,7 @@ type WebsitePHPConfigUpdate struct {
Params map[string]string `json:"params"`
Scope string `json:"scope" validate:"required"`
DisableFunctions []string `json:"disableFunctions"`
UploadMaxSize string `json:"uploadMaxSize"`
}
type WebsitePHPFileUpdate struct {

View File

@ -47,6 +47,7 @@ type WebsiteLog struct {
type PHPConfig struct {
Params map[string]string `json:"params"`
DisableFunctions []string `json:"disableFunctions"`
UploadMaxSize string `json:"uploadMaxSize"`
}
type NginxRewriteRes struct {

View File

@ -1026,6 +1026,10 @@ func (w WebsiteService) GetPHPConfig(id uint) (*response.PHPConfig, error) {
res.DisableFunctions = disableFunctions
}
}
uploadMaxSize := phpConfig.Key("upload_max_filesize").Value()
if uploadMaxSize != "" {
res.UploadMaxSize = uploadMaxSize
}
return res, nil
}
@ -1089,9 +1093,14 @@ func (w WebsiteService) UpdatePHPConfig(req request.WebsitePHPConfigUpdate) (err
return err
}
}
if req.Scope == "uploadSize" {
if req.Scope == "upload_max_filesize" {
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{

View File

@ -270,6 +270,7 @@ export namespace Website {
export interface PHPConfig {
params: any;
disableFunctions: string[];
uploadMaxSize: string;
}
export interface PHPConfigUpdate {
@ -277,6 +278,7 @@ export namespace Website {
params?: any;
disableFunctions?: string[];
scope: string;
uploadMaxSize?: string;
}
export interface PHPUpdate {

View File

@ -1390,6 +1390,7 @@ const message = {
second: 'Second',
disableFunction: 'Disable function',
disableFunctionHelper: 'Enter the function to be disabled, such as exec, please use multiple, split',
uploadMaxSize: 'Upload limit',
},
nginx: {
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',

View File

@ -1371,6 +1371,7 @@ const message = {
second: '秒',
disableFunction: '禁用函数',
disableFunctionHelper: '输入要禁用的函数例如exec多个请用,分割',
uploadMaxSize: '上传限制',
},
nginx: {
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',

View File

@ -1,10 +1,13 @@
<template>
<el-tabs tab-position="left" v-model="index">
<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 :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-tabs>
</template>
@ -15,6 +18,7 @@ import { GetWebsite } from '@/api/modules/website';
import { computed, onMounted, ref } from 'vue';
import Config from './config/index.vue';
import Function from './function/index.vue';
import Upload from './upload/index.vue';
const props = defineProps({
id: {

View File

@ -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>