-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add openBaseDir for php website config #8866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,8 @@ type IWebsiteService interface { | |
| GetWebsiteResource(websiteID uint) ([]response.Resource, error) | ||
| ListDatabases() ([]response.Database, error) | ||
| ChangeDatabase(req request.ChangeDatabase) error | ||
|
|
||
| OperateCrossSiteAccess(req request.CrossSiteAccessOp) error | ||
| } | ||
|
|
||
| func NewIWebsiteService() IWebsiteService { | ||
|
|
@@ -428,7 +430,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) | |
| return err | ||
| } | ||
| if runtime.Type == constant.RuntimePHP && runtime.Resource == constant.ResourceAppstore { | ||
| createPHPConfig(website) | ||
| createOpenBasedirConfig(website) | ||
| } | ||
| } | ||
| tx, ctx := helper.GetTxAndContext() | ||
|
|
@@ -573,6 +575,9 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) { | |
| } | ||
| res.RuntimeType = runtime.Type | ||
| res.RuntimeName = runtime.Name | ||
| if runtime.Type == constant.RuntimePHP { | ||
| res.OpenBaseDir = files.NewFileOp().Stat(path.Join(GetSitePath(website, SiteIndexDir), ".user.ini")) | ||
| } | ||
| } | ||
| return res, nil | ||
| } | ||
|
|
@@ -3278,3 +3283,18 @@ func (w WebsiteService) ChangeDatabase(req request.ChangeDatabase) error { | |
| website.DbType = req.DatabaseType | ||
| return websiteRepo.Save(context.Background(), &website) | ||
| } | ||
|
|
||
| func (w WebsiteService) OperateCrossSiteAccess(req request.CrossSiteAccessOp) error { | ||
| website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if req.Operation == constant.StatusEnable { | ||
| createOpenBasedirConfig(&website) | ||
| } | ||
| if req.Operation == constant.StatusDisable { | ||
| fileOp := files.NewFileOp() | ||
| return fileOp.DeleteFile(path.Join(GetSitePath(website, SiteIndexDir), ".user.ini")) | ||
| } | ||
| return nil | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code modifications seem mostly correct, but there are a few areas that could benefit from further refinement: Code Differences
Optimization Suggestions
Potential Issues Identified
Overall, the modifications enhance flexibility and functionality by adding a capability to manage cross-site access settings directly via service requests without altering underlying resource configurations manually. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,28 +2,39 @@ | |
| <div v-loading="loading"> | ||
| <el-row> | ||
| <el-col :xs="20" :sm="12" :md="10" :lg="10" :xl="8"> | ||
| <el-form label-position="right" label-width="80px"> | ||
| <el-form label-position="right" label-width="120px"> | ||
| <el-form-item> | ||
| <div v-if="website.type === 'static'"> | ||
| <el-text type="info">{{ $t('website.staticChangePHPHelper') }}</el-text> | ||
| </div> | ||
| <el-text type="info" v-if="website.type === 'static'"> | ||
| {{ $t('website.staticChangePHPHelper') }} | ||
| </el-text> | ||
| </el-form-item> | ||
|
|
||
| <el-form-item :label="$t('website.changeVersion')"> | ||
| <el-select v-model="versionReq.runtimeID" class="w-full"> | ||
| <el-option :key="-1" :label="$t('website.static')" :value="0"></el-option> | ||
| <el-option | ||
| v-for="(item, index) in versions" | ||
| :key="index" | ||
| :label="item.label" | ||
| :value="item.value" | ||
| ></el-option> | ||
| </el-select> | ||
| <el-row :gutter="20"> | ||
| <el-col :span="20"> | ||
| <el-select v-model="versionReq.runtimeID" class="p-w-200"> | ||
| <el-option :key="-1" :label="$t('website.static')" :value="0"></el-option> | ||
| <el-option | ||
| v-for="(item, index) in versions" | ||
| :key="index" | ||
| :label="item.label" | ||
| :value="item.value" | ||
| ></el-option> | ||
| </el-select> | ||
| </el-col> | ||
| <el-col :span="4"> | ||
| <el-button | ||
| type="primary" | ||
| @click="submit()" | ||
| :disabled="versionReq.runtimeID === oldRuntimeID" | ||
| > | ||
| {{ $t('commons.button.save') }} | ||
| </el-button> | ||
| </el-col> | ||
| </el-row> | ||
| </el-form-item> | ||
| <el-form-item> | ||
| <el-button type="primary" @click="submit()" :disabled="versionReq.runtimeID === oldRuntimeID"> | ||
| {{ $t('commons.button.save') }} | ||
| </el-button> | ||
| <el-form-item :label="$t('website.openBaseDir')"> | ||
| <el-switch v-model="openBaseDir" @change="operateCrossSite"></el-switch> | ||
| <span class="input-help">{{ $t('website.openBaseDirHelper') }}</span> | ||
| </el-form-item> | ||
| </el-form> | ||
| </el-col> | ||
|
|
@@ -36,7 +47,7 @@ import { SearchRuntimes } from '@/api/modules/runtime'; | |
| import { onMounted, reactive, ref } from 'vue'; | ||
| import { Runtime } from '@/api/interface/runtime'; | ||
| import { Website } from '@/api/interface/website'; | ||
| import { changePHPVersion, getWebsite } from '@/api/modules/website'; | ||
| import { changePHPVersion, getWebsite, operateCrossSiteAccess } from '@/api/modules/website'; | ||
| import i18n from '@/lang'; | ||
| import { MsgSuccess } from '@/utils/message'; | ||
| const props = defineProps({ | ||
|
|
@@ -56,7 +67,9 @@ const loading = ref(false); | |
| const oldRuntimeID = ref(0); | ||
| const website = ref({ | ||
| type: '', | ||
| openBaseDir: false, | ||
| }); | ||
| const openBaseDir = ref(false); | ||
|
|
||
| const getRuntimes = async () => { | ||
| try { | ||
|
|
@@ -95,6 +108,18 @@ const getWebsiteDetail = async () => { | |
| versionReq.runtimeID = res.data.runtimeID; | ||
| oldRuntimeID.value = res.data.runtimeID; | ||
| website.value = res.data; | ||
| openBaseDir.value = res.data.openBaseDir || false; | ||
| }; | ||
|
|
||
| const operateCrossSite = async () => { | ||
| try { | ||
| await operateCrossSiteAccess({ | ||
| websiteID: props.id, | ||
| operation: openBaseDir.value ? 'Enable' : 'Disable', | ||
| }); | ||
| MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); | ||
| getWebsiteDetail(); | ||
| } catch (error) {} | ||
| }; | ||
|
|
||
| onMounted(() => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code you sent has several minor adjustments.
These changes address minor coding issues and improve readability while not introducing major bugs. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippets are syntactically correct, free of syntax errors, but contain some room for improvement and optimizations.
Potential Irregularities and Issues:
Empty Response Body: The
helper.Success(c)call within bothClearProxyCacheandOperateCrossSiteAccessmethods does not include a response message to the client. This might be fine if you always expect successful responses with an empty body, however, it's usually good practice to include messages or specific payloads.Error Handling Clarity:
ClearProxyCachemethod, there is no return statement after returning from the error handling. Consider adding one to ensure that control returns out of the function immediately if an error occurs.helper.InternalServer(c, err)), which can lead to duplicated code and maintenance overhead. If possible, consider extracting this common functionality into a separate helper method likehandleGenericErrors.Performance Optimization Suggestions:
API Security Concerns:
Code Readability Enhancement:
Parameter Validation:
gin.BasicAuth()for authentication or custom validation libraries such asvalidator.v9. This helps maintain the integrity of the API inputs.Here’s how you could refactor the code based on these suggestions:
This refactoring addresses some of the mentioned issues while maintaining readability and security.