Skip to content

Commit 3d84a55

Browse files
authored
fix: Dealing with API interface issues (#7295)
1 parent b88438a commit 3d84a55

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

backend/middleware/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func SessionAuth() gin.HandlerFunc {
6565

6666
func isValid1PanelToken(panelToken string, panelTimestamp string) bool {
6767
system1PanelToken := global.CONF.System.ApiKey
68-
if GenerateMD5("1panel"+panelToken+panelTimestamp) == GenerateMD5("1panel"+system1PanelToken+panelTimestamp) {
68+
if panelToken == GenerateMD5("1panel"+system1PanelToken+panelTimestamp) {
6969
return true
7070
}
7171
return false

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,8 @@ const message = {
14101410
apiInterfaceHelper: 'Allow third-party applications to access the API.',
14111411
apiInterfaceAlert1: `Don't enable it in production environments because it may increase server security risks.`,
14121412
apiInterfaceAlert2: `Don't use third-party applications to call the API to prevent potential security threats.`,
1413-
apiInterfaceAlert3: 'API document:',
1414-
apiInterfaceAlert4: 'Usage document:',
1413+
apiInterfaceAlert3: 'API Docs',
1414+
apiInterfaceAlert4: 'Usage Docs',
14151415
apiKey: 'Interface key',
14161416
apiKeyHelper: 'API key is used for third-party applications to access the API.',
14171417
ipWhiteList: 'IP whitelist',

frontend/src/lang/modules/tw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,8 @@ const message = {
13311331
apiInterfaceHelper: '提供面板支持 API 接口訪問',
13321332
apiInterfaceAlert1: '請不要在生產環境開啟,這可能新增服務器安全風險',
13331333
apiInterfaceAlert2: '請不要使用協力廠商應用調用面板 API,以防止潜在的安全威脅。',
1334-
apiInterfaceAlert3: 'API 接口檔案',
1335-
apiInterfaceAlert4: '使用檔案',
1334+
apiInterfaceAlert3: 'API 接口檔案',
1335+
apiInterfaceAlert4: '使用檔案',
13361336
apiKey: '接口密钥',
13371337
apiKeyHelper: '接口密钥用於外部應用訪問 API 接口',
13381338
ipWhiteList: 'IP白名單',

frontend/src/lang/modules/zh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,8 @@ const message = {
13331333
apiInterfaceHelper: '提供面板支持 API 接口访问',
13341334
apiInterfaceAlert1: '请不要在生产环境开启,这可能增加服务器安全风险',
13351335
apiInterfaceAlert2: '请不要使用第三方应用调用面板 API,以防止潜在的安全威胁。',
1336-
apiInterfaceAlert3: 'API 接口文档:',
1337-
apiInterfaceAlert4: '使用文档:',
1336+
apiInterfaceAlert3: 'API 接口文档',
1337+
apiInterfaceAlert4: '使用文档',
13381338
apiKey: '接口密钥',
13391339
apiKeyHelper: '接口密钥用于外部应用访问 API 接口',
13401340
ipWhiteList: 'IP 白名单',

frontend/src/views/setting/panel/api-interface/index.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
<el-text type="danger">{{ $t('setting.apiInterfaceAlert2') }}</el-text>
2222
</li>
2323
<li>
24-
{{ $t('setting.apiInterfaceAlert3') }}
25-
<el-link :href="apiURL" type="success" target="_blank" class="mb-0.5 ml-0.5">
26-
{{ apiURL }}
24+
<el-link :href="apiURL" type="warning" target="_blank" class="mb-0.5 ml-0.5">
25+
{{ $t('setting.apiInterfaceAlert3') }}
2726
</el-link>
2827
</li>
2928
<li>
30-
{{ $t('setting.apiInterfaceAlert4') }}
31-
<el-link :href="panelURL" type="success" target="_blank" class="mb-0.5 ml-0.5">
32-
{{ panelURL }}
29+
<el-link :href="panelURL" type="warning" target="_blank" class="mb-0.5 ml-0.5">
30+
{{ $t('setting.apiInterfaceAlert4') }}
3331
</el-link>
3432
</li>
3533
</ul>
@@ -73,7 +71,7 @@
7371
<template #footer>
7472
<span class="dialog-footer">
7573
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
76-
<el-button :disabled="loading" type="primary" @click="onBind(formRef)">
74+
<el-button :disabled="loading" type="primary" @click="onSave(formRef)">
7775
{{ $t('commons.button.confirm') }}
7876
</el-button>
7977
</span>
@@ -97,7 +95,7 @@ const formRef = ref();
9795
const apiURL = `${window.location.protocol}//${window.location.hostname}${
9896
window.location.port ? `:${window.location.port}` : ''
9997
}/1panel/swagger/index.html`;
100-
const panelURL = `https://1panel.cn/docs`;
98+
const panelURL = `https://1panel.cn/docs/dev_manual/api_manual/`;
10199
102100
const form = reactive({
103101
apiKey: '',
@@ -171,7 +169,7 @@ const resetApiKey = async () => {
171169
});
172170
};
173171
174-
const onBind = async (formEl: FormInstance | undefined) => {
172+
const onSave = async (formEl: FormInstance | undefined) => {
175173
if (!formEl) return;
176174
formEl.validate(async (valid) => {
177175
if (!valid) return;

frontend/src/views/setting/panel/index.vue

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
<script lang="ts" setup>
197197
import { ref, reactive, onMounted, computed } from 'vue';
198198
import { ElForm, ElMessageBox } from 'element-plus';
199-
import { getSettingInfo, updateSetting, getSystemAvailable } from '@/api/modules/setting';
199+
import { getSettingInfo, updateSetting, getSystemAvailable, updateApiConfig } from '@/api/modules/setting';
200200
import { GlobalStore } from '@/store';
201201
import { useI18n } from 'vue-i18n';
202202
import { useTheme } from '@/hooks/use-theme';
@@ -391,19 +391,11 @@ const onChangeProxy = () => {
391391
392392
const onChangeApiInterfaceStatus = async () => {
393393
if (form.apiInterfaceStatus === 'enable') {
394-
loading.value = true;
395-
await updateSetting({ key: 'ApiInterfaceStatus', value: form.apiInterfaceStatus })
396-
.then(() => {
397-
loading.value = false;
398-
apiInterfaceRef.value.acceptParams({
399-
apiInterfaceStatus: form.apiInterfaceStatus,
400-
apiKey: form.apiKey,
401-
ipWhiteList: form.ipWhiteList,
402-
});
403-
})
404-
.catch(() => {
405-
loading.value = false;
406-
});
394+
apiInterfaceRef.value.acceptParams({
395+
apiInterfaceStatus: form.apiInterfaceStatus,
396+
apiKey: form.apiKey,
397+
ipWhiteList: form.ipWhiteList,
398+
});
407399
return;
408400
}
409401
ElMessageBox.confirm(i18n.t('setting.apiInterfaceClose'), i18n.t('setting.apiInterface'), {
@@ -413,7 +405,12 @@ const onChangeApiInterfaceStatus = async () => {
413405
.then(async () => {
414406
loading.value = true;
415407
form.apiInterfaceStatus = 'disable';
416-
await updateSetting({ key: 'ApiInterfaceStatus', value: 'disable' })
408+
let param = {
409+
apiKey: form.apiKey,
410+
ipWhiteList: form.ipWhiteList,
411+
apiInterfaceStatus: form.apiInterfaceStatus,
412+
};
413+
await updateApiConfig(param)
417414
.then(() => {
418415
loading.value = false;
419416
search();

0 commit comments

Comments
 (0)