mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-13 18:15:31 +08:00
fix: 优化未启用安全入口跳转逻辑 (#1210)
This commit is contained in:
parent
cbdf1ad7b7
commit
bb48964cca
10 changed files with 64 additions and 31 deletions
|
@ -103,7 +103,12 @@ func (b *BaseApi) Captcha(c *gin.Context) {
|
||||||
// @Router /auth/issafety [get]
|
// @Router /auth/issafety [get]
|
||||||
func (b *BaseApi) CheckIsSafety(c *gin.Context) {
|
func (b *BaseApi) CheckIsSafety(c *gin.Context) {
|
||||||
code := c.DefaultQuery("code", "")
|
code := c.DefaultQuery("code", "")
|
||||||
helper.SuccessWithData(c, authService.CheckIsSafety(code))
|
status, err := authService.CheckIsSafety(code)
|
||||||
|
if err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithData(c, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Tags Auth
|
// @Tags Auth
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
type AuthService struct{}
|
type AuthService struct{}
|
||||||
|
|
||||||
type IAuthService interface {
|
type IAuthService interface {
|
||||||
CheckIsSafety(code string) bool
|
CheckIsSafety(code string) (string, error)
|
||||||
VerifyCode(code string) (bool, error)
|
VerifyCode(code string) (bool, error)
|
||||||
Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error)
|
Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error)
|
||||||
LogOut(c *gin.Context) error
|
LogOut(c *gin.Context) error
|
||||||
|
@ -143,13 +143,16 @@ func (u *AuthService) VerifyCode(code string) (bool, error) {
|
||||||
return setting.Value == code, nil
|
return setting.Value == code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *AuthService) CheckIsSafety(code string) bool {
|
func (u *AuthService) CheckIsSafety(code string) (string, error) {
|
||||||
status, err := settingRepo.Get(settingRepo.WithByKey("SecurityEntrance"))
|
status, err := settingRepo.Get(settingRepo.WithByKey("SecurityEntrance"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return "", err
|
||||||
}
|
}
|
||||||
if len(status.Value) == 0 {
|
if len(status.Value) == 0 {
|
||||||
return true
|
return "disable", nil
|
||||||
}
|
}
|
||||||
return status.Value == code
|
if status.Value == code {
|
||||||
|
return "pass", nil
|
||||||
|
}
|
||||||
|
return "unpass", nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const logOutApi = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const checkIsSafety = (code: string) => {
|
export const checkIsSafety = (code: string) => {
|
||||||
return http.get<boolean>(`/auth/issafety?code=${code}`);
|
return http.get<string>(`/auth/issafety?code=${code}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const checkIsDemo = () => {
|
export const checkIsDemo = () => {
|
||||||
|
|
|
@ -65,6 +65,7 @@ const loadDataFromDB = async () => {
|
||||||
document.title = res.data.panelName;
|
document.title = res.data.panelName;
|
||||||
i18n.locale.value = res.data.language;
|
i18n.locale.value = res.data.language;
|
||||||
i18n.warnHtmlMessage = false;
|
i18n.warnHtmlMessage = false;
|
||||||
|
globalStore.entrance = res.data.securityEntrance;
|
||||||
globalStore.updateLanguage(res.data.language);
|
globalStore.updateLanguage(res.data.language);
|
||||||
globalStore.setThemeConfig({ ...themeConfig.value, theme: res.data.theme });
|
globalStore.setThemeConfig({ ...themeConfig.value, theme: res.data.theme });
|
||||||
globalStore.setThemeConfig({ ...themeConfig.value, panelName: res.data.panelName });
|
globalStore.setThemeConfig({ ...themeConfig.value, panelName: res.data.panelName });
|
||||||
|
|
|
@ -29,15 +29,6 @@ router.beforeEach((to, from, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!to.matched.some((record) => record.meta.requiresAuth)) return next();
|
if (!to.matched.some((record) => record.meta.requiresAuth)) return next();
|
||||||
if (!globalStore.isLogin) {
|
|
||||||
next({
|
|
||||||
name: 'entrance',
|
|
||||||
params: { code: globalStore.entrance },
|
|
||||||
});
|
|
||||||
NProgress.done();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="login-backgroud" v-if="isSafety && !isErr">
|
<div class="login-backgroud" v-if="isSafety && !isErr && !isNotFound">
|
||||||
<div class="login-wrapper">
|
<div class="login-wrapper">
|
||||||
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
|
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
|
||||||
<div class="login-title">
|
<div class="login-title">
|
||||||
|
@ -15,15 +15,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!isSafety && !isErr">
|
<div v-if="!isSafety && !isErr && !isNotFound">
|
||||||
<UnSafe />
|
<UnSafe />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isErr && mySafetyCode.code === 'err-ip'">
|
<div v-if="isErr && mySafetyCode.code === 'err-ip' && !isNotFound">
|
||||||
<ErrIP />
|
<ErrIP />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isErr && mySafetyCode.code === 'err-domain'">
|
<div v-if="isErr && mySafetyCode.code === 'err-domain' && !isNotFound">
|
||||||
<ErrDomain />
|
<ErrDomain />
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="isNotFound">
|
||||||
|
<ErrFound />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -32,6 +35,7 @@ import { checkIsSafety } from '@/api/modules/auth';
|
||||||
import LoginForm from '../components/login-form.vue';
|
import LoginForm from '../components/login-form.vue';
|
||||||
import UnSafe from '@/components/error-message/unsafe.vue';
|
import UnSafe from '@/components/error-message/unsafe.vue';
|
||||||
import ErrIP from '@/components/error-message/err_ip.vue';
|
import ErrIP from '@/components/error-message/err_ip.vue';
|
||||||
|
import ErrFound from '@/components/error-message/404.vue';
|
||||||
import ErrDomain from '@/components/error-message/err_domain.vue';
|
import ErrDomain from '@/components/error-message/err_domain.vue';
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { GlobalStore } from '@/store';
|
import { GlobalStore } from '@/store';
|
||||||
|
@ -40,6 +44,7 @@ const globalStore = GlobalStore();
|
||||||
const isSafety = ref(true);
|
const isSafety = ref(true);
|
||||||
const screenWidth = ref(null);
|
const screenWidth = ref(null);
|
||||||
const isErr = ref();
|
const isErr = ref();
|
||||||
|
const isNotFound = ref();
|
||||||
|
|
||||||
const mySafetyCode = defineProps({
|
const mySafetyCode = defineProps({
|
||||||
code: {
|
code: {
|
||||||
|
@ -50,15 +55,24 @@ const mySafetyCode = defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
const getStatus = async () => {
|
const getStatus = async () => {
|
||||||
if (mySafetyCode.code === 'err-ip' || mySafetyCode.code === 'err-domain') {
|
isErr.value = true;
|
||||||
isErr.value = true;
|
|
||||||
}
|
|
||||||
const res = await checkIsSafety(mySafetyCode.code);
|
const res = await checkIsSafety(mySafetyCode.code);
|
||||||
if (mySafetyCode.code === 'err-ip' || mySafetyCode.code === 'err-domain') {
|
isErr.value = false;
|
||||||
isErr.value = false;
|
globalStore.entrance = '';
|
||||||
|
if (res.data === 'disable') {
|
||||||
|
if (mySafetyCode.code === '') {
|
||||||
|
isNotFound.value = false;
|
||||||
|
} else {
|
||||||
|
isNotFound.value = true;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
isSafety.value = res.data;
|
isNotFound.value = false;
|
||||||
if (isSafety.value) {
|
if (res.data !== 'pass') {
|
||||||
|
isSafety.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.data === 'pass') {
|
||||||
globalStore.entrance = mySafetyCode.code;
|
globalStore.entrance = mySafetyCode.code;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ const screenWidth = ref(null);
|
||||||
|
|
||||||
const getStatus = async () => {
|
const getStatus = async () => {
|
||||||
const res = await checkIsSafety(globalStore.entrance);
|
const res = await checkIsSafety(globalStore.entrance);
|
||||||
if (!res.data) {
|
if (res.data === 'unpass') {
|
||||||
router.replace({ name: 'entrance' });
|
router.replace({ name: 'entrance' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -171,6 +171,8 @@ import { updateSetting, getSettingInfo, getSystemAvailable, updateSSL, loadSSLIn
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import { Setting } from '@/api/interface/setting';
|
import { Setting } from '@/api/interface/setting';
|
||||||
|
import { GlobalStore } from '@/store';
|
||||||
|
const globalStore = GlobalStore();
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const entranceRef = ref();
|
const entranceRef = ref();
|
||||||
|
@ -280,8 +282,14 @@ const handleSSL = async () => {
|
||||||
await updateSSL({ ssl: 'disable', domain: '', sslType: '', key: '', cert: '', sslID: 0 });
|
await updateSSL({ ssl: 'disable', domain: '', sslType: '', key: '', cert: '', sslID: 0 });
|
||||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
let href = window.location.href;
|
let href = window.location.href;
|
||||||
|
globalStore.isLogin = false;
|
||||||
let address = href.split('://')[1];
|
let address = href.split('://')[1];
|
||||||
window.open(`http://${address}/`, '_self');
|
if (globalStore.entrance) {
|
||||||
|
address = address.replaceAll('settings/safe', globalStore.entrance);
|
||||||
|
} else {
|
||||||
|
address = address.replaceAll('settings/safe', 'login');
|
||||||
|
}
|
||||||
|
window.location.href = `http://${address}`;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
form.ssl = 'enable';
|
form.ssl = 'enable';
|
||||||
|
|
|
@ -72,7 +72,14 @@ const onSavePort = async (formEl: FormInstance | undefined) => {
|
||||||
globalStore.isLogin = false;
|
globalStore.isLogin = false;
|
||||||
let href = window.location.href;
|
let href = window.location.href;
|
||||||
let ip = href.split('//')[1].split(':')[0];
|
let ip = href.split('//')[1].split(':')[0];
|
||||||
window.open(`${href.split('//')[0]}//${ip}:${form.serverPort}/${globalStore.entrance}`, '_self');
|
if (globalStore.entrance) {
|
||||||
|
window.open(
|
||||||
|
`${href.split('//')[0]}//${ip}:${form.serverPort}/${globalStore.entrance}`,
|
||||||
|
'_self',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
window.open(`${href.split('//')[0]}//${ip}:${form.serverPort}/login`, '_self');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
|
|
@ -212,7 +212,11 @@ const onSaveSSL = async (formEl: FormInstance | undefined) => {
|
||||||
let href = window.location.href;
|
let href = window.location.href;
|
||||||
globalStore.isLogin = false;
|
globalStore.isLogin = false;
|
||||||
let address = href.split('://')[1];
|
let address = href.split('://')[1];
|
||||||
address = address.replaceAll('settings/safe', globalStore.entrance);
|
if (globalStore.entrance) {
|
||||||
|
address = address.replaceAll('settings/safe', globalStore.entrance);
|
||||||
|
} else {
|
||||||
|
address = address.replaceAll('settings/safe', 'login');
|
||||||
|
}
|
||||||
window.open(`https://${address}`, '_self');
|
window.open(`https://${address}`, '_self');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue