mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 20:49:03 +08:00
feat: 增加 demo 环境处理
This commit is contained in:
parent
554a238fd3
commit
0e11b18cd6
@ -13,4 +13,5 @@ type System struct {
|
||||
BaseDir string `mapstructure:"base_dir"`
|
||||
Mode string `mapstructure:"mode"`
|
||||
RepoUrl string `mapstructure:"repo_url"`
|
||||
IsDemo bool `mapstructure:"is_demo"`
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ var (
|
||||
ErrTypePasswordExpired = "ErrPasswordExpired"
|
||||
ErrTypeNotSafety = "ErrNotSafety"
|
||||
ErrNameIsExist = "ErrNameIsExist"
|
||||
ErrDemoEnvironment = "ErrDemoEnvironment"
|
||||
)
|
||||
|
||||
// app
|
||||
|
@ -15,6 +15,7 @@ ErrRepoNotValid: "Remote repository verification failed!"
|
||||
|
||||
#common
|
||||
ErrNameIsExist: "Name is already exist"
|
||||
ErrDemoEnvironment: "Demo server, prohibit this operation!"
|
||||
|
||||
#app
|
||||
ErrPortInUsed: "{{ .detail }} port already in use"
|
||||
|
@ -15,6 +15,7 @@ ErrRepoNotValid: "远程仓库校验失败!"
|
||||
|
||||
#common
|
||||
ErrNameIsExist: "名称已存在"
|
||||
ErrDemoEnvironment: "演示服务器,禁止此操作!"
|
||||
|
||||
#app
|
||||
ErrPortInUsed: "{{ .detail }} 端口已被占用!"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
@ -45,6 +46,10 @@ func Routers() *gin.Engine {
|
||||
// Router.Use(middleware.CSRF())
|
||||
// Router.Use(middleware.LoadCsrfToken())
|
||||
|
||||
if global.CONF.System.IsDemo {
|
||||
Router.Use(middleware.DemoHandle())
|
||||
}
|
||||
|
||||
setWebStatic(Router)
|
||||
|
||||
Router.Use(i18n.GinI18nLocalize())
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
func Init() {
|
||||
baseDir := "/opt"
|
||||
mode := "dev"
|
||||
mode := ""
|
||||
fileOp := files.NewFileOp()
|
||||
v := viper.NewWithOptions()
|
||||
v.SetConfigType("yaml")
|
||||
@ -68,6 +68,7 @@ func Init() {
|
||||
|
||||
global.CONF = serverConfig
|
||||
global.CONF.BaseDir = baseDir
|
||||
global.CONF.System.IsDemo = v.GetBool("system.is_demo")
|
||||
global.CONF.System.DataDir = global.CONF.BaseDir + "/1panel"
|
||||
global.CONF.System.Cache = global.CONF.System.DataDir + "/cache"
|
||||
global.CONF.System.Backup = global.CONF.System.DataDir + "/backup"
|
||||
|
40
backend/middleware/demo_handle.go
Normal file
40
backend/middleware/demo_handle.go
Normal file
@ -0,0 +1,40 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var whiteUrlList = map[string]struct{}{
|
||||
"/api/v1/auth/login": {},
|
||||
"/api/v1/websites/config": {},
|
||||
"/api/v1/websites/waf/config": {},
|
||||
"/api/v1/files/loadfile": {},
|
||||
"/api/v1/files/size": {},
|
||||
"/api/v1/logs/operation": {},
|
||||
"/api/v1/logs/login": {},
|
||||
"/api/v1/auth/logout": {},
|
||||
}
|
||||
|
||||
func DemoHandle() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if strings.Contains(c.Request.URL.Path, "search") || c.Request.Method == http.MethodGet {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
if _, ok := whiteUrlList[c.Request.URL.Path]; ok {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusInternalServerError, dto.Response{
|
||||
Code: http.StatusInternalServerError,
|
||||
Message: buserr.New(constant.ErrDemoEnvironment).Error(),
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) {
|
||||
appRouter.GET("/installed/loadport/:key", baseApi.LoadPort)
|
||||
appRouter.GET("/installed/loadpassword/:key", baseApi.LoadPassword)
|
||||
appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck)
|
||||
appRouter.POST("/installed", baseApi.SearchAppInstalled)
|
||||
appRouter.POST("/installed/search", baseApi.SearchAppInstalled)
|
||||
appRouter.POST("/installed/op", baseApi.OperateInstalled)
|
||||
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
|
||||
appRouter.POST("/installed/backups", baseApi.SearchInstalledBackup)
|
||||
|
@ -3,6 +3,7 @@ system:
|
||||
base_dir: /opt
|
||||
mode: dev
|
||||
repo_url: https://1panel.oss-cn-hangzhou.aliyuncs.com/package
|
||||
is_demo: false
|
||||
|
||||
log:
|
||||
level: debug
|
||||
|
@ -2,27 +2,22 @@ import i18n from '@/lang';
|
||||
import router from '@/routers';
|
||||
import { MsgError } from '@/utils/message';
|
||||
|
||||
/**
|
||||
* @description: 校验网络请求状态码
|
||||
* @param {Number} status
|
||||
* @return void
|
||||
*/
|
||||
export const checkStatus = (status: number): void => {
|
||||
export const checkStatus = (status: number, msg: string): void => {
|
||||
switch (status) {
|
||||
case 400:
|
||||
MsgError(i18n.global.t('commons.res.paramError'));
|
||||
MsgError(msg ? msg : i18n.global.t('commons.res.paramError'));
|
||||
break;
|
||||
case 404:
|
||||
MsgError(i18n.global.t('commons.res.notFound'));
|
||||
MsgError(msg ? msg : i18n.global.t('commons.res.notFound'));
|
||||
break;
|
||||
case 403:
|
||||
router.replace({ path: '/' });
|
||||
MsgError(i18n.global.t('commons.res.forbidden'));
|
||||
MsgError(msg ? msg : i18n.global.t('commons.res.forbidden'));
|
||||
break;
|
||||
case 500:
|
||||
MsgError(i18n.global.t('commons.res.serverError'));
|
||||
MsgError(msg ? msg : i18n.global.t('commons.res.serverError'));
|
||||
break;
|
||||
default:
|
||||
MsgError(i18n.global.t('commons.res.commonError'));
|
||||
MsgError(msg ? msg : i18n.global.t('commons.res.commonError'));
|
||||
}
|
||||
};
|
||||
|
@ -79,7 +79,7 @@ class RequestHttp {
|
||||
async (error: AxiosError) => {
|
||||
const { response } = error;
|
||||
if (error.message.indexOf('timeout') !== -1) MsgError('请求超时!请您稍后重试');
|
||||
if (response) checkStatus(response.status);
|
||||
if (response) checkStatus(response.status, response.data['message']);
|
||||
if (!window.navigator.onLine) router.replace({ path: '/500' });
|
||||
return Promise.reject(error);
|
||||
},
|
||||
|
@ -31,7 +31,7 @@ export const ChangePort = (params: App.ChangePort) => {
|
||||
};
|
||||
|
||||
export const SearchAppInstalled = (search: App.AppInstallSearch) => {
|
||||
return http.post<ResPage<App.AppInstalled>>('apps/installed', search);
|
||||
return http.post<ResPage<App.AppInstalled>>('apps/installed/search', search);
|
||||
};
|
||||
|
||||
export const GetAppPort = (key: string) => {
|
||||
@ -51,7 +51,7 @@ export const AppInstalledDeleteCheck = (appInstallId: number) => {
|
||||
};
|
||||
|
||||
export const GetAppInstalled = (search: App.AppInstalledSearch) => {
|
||||
return http.post<App.AppInstalled[]>('apps/installed', search);
|
||||
return http.post<App.AppInstalled[]>('apps/installed/search', search);
|
||||
};
|
||||
|
||||
export const InstalledOp = (op: App.AppInstalledOp) => {
|
||||
|
@ -155,6 +155,9 @@ const submit = async (formEl: FormInstance | undefined) => {
|
||||
search(req);
|
||||
})
|
||||
.finally(() => {
|
||||
if (req.operate === 'add') {
|
||||
enable.value = false;
|
||||
}
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
|
@ -102,8 +102,12 @@ const get = async () => {
|
||||
const updateEnable = async (enable: boolean) => {
|
||||
enableUpdate.value.enable = enable;
|
||||
loading.value = true;
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
loading.value = false;
|
||||
try {
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
} catch (error) {
|
||||
form.enable = !enable;
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async (formEl: FormInstance | undefined) => {
|
||||
|
@ -87,9 +87,10 @@ const get = async () => {
|
||||
};
|
||||
|
||||
const remove = (index: number) => {
|
||||
data.value.splice(index, 1);
|
||||
const copyList = data.value.concat();
|
||||
copyList.splice(index, 1);
|
||||
const extArray = [];
|
||||
data.value.forEach((d) => {
|
||||
copyList.forEach((d) => {
|
||||
extArray.push(d.file);
|
||||
});
|
||||
submit(extArray);
|
||||
@ -123,8 +124,12 @@ const submit = async (extArray: string[]) => {
|
||||
const updateEnable = async (enable: boolean) => {
|
||||
enableUpdate.value.enable = enable;
|
||||
loading.value = true;
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
loading.value = false;
|
||||
try {
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
} catch (error) {
|
||||
enableUpdate.value.enable = !enable;
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -102,9 +102,10 @@ const get = async () => {
|
||||
};
|
||||
|
||||
const removeIp = (index: number) => {
|
||||
data.value.splice(index, 1);
|
||||
const copyList = data.value.concat();
|
||||
copyList.splice(index, 1);
|
||||
let ipArray = [];
|
||||
data.value.forEach((d) => {
|
||||
copyList.forEach((d) => {
|
||||
ipArray.push(d.ip);
|
||||
});
|
||||
submit(ipArray);
|
||||
@ -146,8 +147,12 @@ const submit = async (ipList: string[]) => {
|
||||
const updateEnable = async (enable: boolean) => {
|
||||
enableUpdate.value.enable = enable;
|
||||
loading.value = true;
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
loading.value = false;
|
||||
try {
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
} catch (error) {
|
||||
enableUpdate.value.enable = !enable;
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -143,8 +143,12 @@ const openCreate = () => {
|
||||
const updateEnable = async (enable: boolean) => {
|
||||
enableUpdate.value.enable = enable;
|
||||
loading.value = true;
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
loading.value = false;
|
||||
try {
|
||||
await UpdateWafEnable(enableUpdate.value);
|
||||
} catch (error) {
|
||||
enableUpdate.value.enable = !enable;
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async (addArray: string[]) => {
|
||||
|
@ -333,21 +333,25 @@ const submit = async (formEl: FormInstance | undefined) => {
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
PreCheck({}).then((res) => {
|
||||
if (res.data) {
|
||||
PreCheck({})
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
loading.value = false;
|
||||
preCheckRef.value.acceptParams({ items: res.data });
|
||||
} else {
|
||||
CreateWebsite(website.value)
|
||||
.then(() => {
|
||||
MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
|
||||
handleClose();
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
preCheckRef.value.acceptParams({ items: res.data });
|
||||
} else {
|
||||
CreateWebsite(website.value)
|
||||
.then(() => {
|
||||
MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
|
||||
handleClose();
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user