mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-04 21:09:31 +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"`
|
BaseDir string `mapstructure:"base_dir"`
|
||||||
Mode string `mapstructure:"mode"`
|
Mode string `mapstructure:"mode"`
|
||||||
RepoUrl string `mapstructure:"repo_url"`
|
RepoUrl string `mapstructure:"repo_url"`
|
||||||
|
IsDemo bool `mapstructure:"is_demo"`
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ var (
|
|||||||
ErrTypePasswordExpired = "ErrPasswordExpired"
|
ErrTypePasswordExpired = "ErrPasswordExpired"
|
||||||
ErrTypeNotSafety = "ErrNotSafety"
|
ErrTypeNotSafety = "ErrNotSafety"
|
||||||
ErrNameIsExist = "ErrNameIsExist"
|
ErrNameIsExist = "ErrNameIsExist"
|
||||||
|
ErrDemoEnvironment = "ErrDemoEnvironment"
|
||||||
)
|
)
|
||||||
|
|
||||||
// app
|
// app
|
||||||
|
@ -15,6 +15,7 @@ ErrRepoNotValid: "Remote repository verification failed!"
|
|||||||
|
|
||||||
#common
|
#common
|
||||||
ErrNameIsExist: "Name is already exist"
|
ErrNameIsExist: "Name is already exist"
|
||||||
|
ErrDemoEnvironment: "Demo server, prohibit this operation!"
|
||||||
|
|
||||||
#app
|
#app
|
||||||
ErrPortInUsed: "{{ .detail }} port already in use"
|
ErrPortInUsed: "{{ .detail }} port already in use"
|
||||||
|
@ -15,6 +15,7 @@ ErrRepoNotValid: "远程仓库校验失败!"
|
|||||||
|
|
||||||
#common
|
#common
|
||||||
ErrNameIsExist: "名称已存在"
|
ErrNameIsExist: "名称已存在"
|
||||||
|
ErrDemoEnvironment: "演示服务器,禁止此操作!"
|
||||||
|
|
||||||
#app
|
#app
|
||||||
ErrPortInUsed: "{{ .detail }} 端口已被占用!"
|
ErrPortInUsed: "{{ .detail }} 端口已被占用!"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -45,6 +46,10 @@ func Routers() *gin.Engine {
|
|||||||
// Router.Use(middleware.CSRF())
|
// Router.Use(middleware.CSRF())
|
||||||
// Router.Use(middleware.LoadCsrfToken())
|
// Router.Use(middleware.LoadCsrfToken())
|
||||||
|
|
||||||
|
if global.CONF.System.IsDemo {
|
||||||
|
Router.Use(middleware.DemoHandle())
|
||||||
|
}
|
||||||
|
|
||||||
setWebStatic(Router)
|
setWebStatic(Router)
|
||||||
|
|
||||||
Router.Use(i18n.GinI18nLocalize())
|
Router.Use(i18n.GinI18nLocalize())
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
baseDir := "/opt"
|
baseDir := "/opt"
|
||||||
mode := "dev"
|
mode := ""
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
v := viper.NewWithOptions()
|
v := viper.NewWithOptions()
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
@ -68,6 +68,7 @@ func Init() {
|
|||||||
|
|
||||||
global.CONF = serverConfig
|
global.CONF = serverConfig
|
||||||
global.CONF.BaseDir = baseDir
|
global.CONF.BaseDir = baseDir
|
||||||
|
global.CONF.System.IsDemo = v.GetBool("system.is_demo")
|
||||||
global.CONF.System.DataDir = global.CONF.BaseDir + "/1panel"
|
global.CONF.System.DataDir = global.CONF.BaseDir + "/1panel"
|
||||||
global.CONF.System.Cache = global.CONF.System.DataDir + "/cache"
|
global.CONF.System.Cache = global.CONF.System.DataDir + "/cache"
|
||||||
global.CONF.System.Backup = global.CONF.System.DataDir + "/backup"
|
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/loadport/:key", baseApi.LoadPort)
|
||||||
appRouter.GET("/installed/loadpassword/:key", baseApi.LoadPassword)
|
appRouter.GET("/installed/loadpassword/:key", baseApi.LoadPassword)
|
||||||
appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck)
|
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/op", baseApi.OperateInstalled)
|
||||||
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
|
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
|
||||||
appRouter.POST("/installed/backups", baseApi.SearchInstalledBackup)
|
appRouter.POST("/installed/backups", baseApi.SearchInstalledBackup)
|
||||||
|
@ -3,6 +3,7 @@ system:
|
|||||||
base_dir: /opt
|
base_dir: /opt
|
||||||
mode: dev
|
mode: dev
|
||||||
repo_url: https://1panel.oss-cn-hangzhou.aliyuncs.com/package
|
repo_url: https://1panel.oss-cn-hangzhou.aliyuncs.com/package
|
||||||
|
is_demo: false
|
||||||
|
|
||||||
log:
|
log:
|
||||||
level: debug
|
level: debug
|
||||||
|
@ -2,27 +2,22 @@ import i18n from '@/lang';
|
|||||||
import router from '@/routers';
|
import router from '@/routers';
|
||||||
import { MsgError } from '@/utils/message';
|
import { MsgError } from '@/utils/message';
|
||||||
|
|
||||||
/**
|
export const checkStatus = (status: number, msg: string): void => {
|
||||||
* @description: 校验网络请求状态码
|
|
||||||
* @param {Number} status
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
export const checkStatus = (status: number): void => {
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 400:
|
case 400:
|
||||||
MsgError(i18n.global.t('commons.res.paramError'));
|
MsgError(msg ? msg : i18n.global.t('commons.res.paramError'));
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
MsgError(i18n.global.t('commons.res.notFound'));
|
MsgError(msg ? msg : i18n.global.t('commons.res.notFound'));
|
||||||
break;
|
break;
|
||||||
case 403:
|
case 403:
|
||||||
router.replace({ path: '/' });
|
router.replace({ path: '/' });
|
||||||
MsgError(i18n.global.t('commons.res.forbidden'));
|
MsgError(msg ? msg : i18n.global.t('commons.res.forbidden'));
|
||||||
break;
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
MsgError(i18n.global.t('commons.res.serverError'));
|
MsgError(msg ? msg : i18n.global.t('commons.res.serverError'));
|
||||||
break;
|
break;
|
||||||
default:
|
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) => {
|
async (error: AxiosError) => {
|
||||||
const { response } = error;
|
const { response } = error;
|
||||||
if (error.message.indexOf('timeout') !== -1) MsgError('请求超时!请您稍后重试');
|
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' });
|
if (!window.navigator.onLine) router.replace({ path: '/500' });
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
},
|
},
|
||||||
|
@ -31,7 +31,7 @@ export const ChangePort = (params: App.ChangePort) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SearchAppInstalled = (search: App.AppInstallSearch) => {
|
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) => {
|
export const GetAppPort = (key: string) => {
|
||||||
@ -51,7 +51,7 @@ export const AppInstalledDeleteCheck = (appInstallId: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const GetAppInstalled = (search: App.AppInstalledSearch) => {
|
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) => {
|
export const InstalledOp = (op: App.AppInstalledOp) => {
|
||||||
|
@ -155,6 +155,9 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||||||
search(req);
|
search(req);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
if (req.operate === 'add') {
|
||||||
|
enable.value = false;
|
||||||
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -102,8 +102,12 @@ const get = async () => {
|
|||||||
const updateEnable = async (enable: boolean) => {
|
const updateEnable = async (enable: boolean) => {
|
||||||
enableUpdate.value.enable = enable;
|
enableUpdate.value.enable = enable;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
try {
|
||||||
await UpdateWafEnable(enableUpdate.value);
|
await UpdateWafEnable(enableUpdate.value);
|
||||||
|
} catch (error) {
|
||||||
|
form.enable = !enable;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = async (formEl: FormInstance | undefined) => {
|
const submit = async (formEl: FormInstance | undefined) => {
|
||||||
|
@ -87,9 +87,10 @@ const get = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const remove = (index: number) => {
|
const remove = (index: number) => {
|
||||||
data.value.splice(index, 1);
|
const copyList = data.value.concat();
|
||||||
|
copyList.splice(index, 1);
|
||||||
const extArray = [];
|
const extArray = [];
|
||||||
data.value.forEach((d) => {
|
copyList.forEach((d) => {
|
||||||
extArray.push(d.file);
|
extArray.push(d.file);
|
||||||
});
|
});
|
||||||
submit(extArray);
|
submit(extArray);
|
||||||
@ -123,8 +124,12 @@ const submit = async (extArray: string[]) => {
|
|||||||
const updateEnable = async (enable: boolean) => {
|
const updateEnable = async (enable: boolean) => {
|
||||||
enableUpdate.value.enable = enable;
|
enableUpdate.value.enable = enable;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
try {
|
||||||
await UpdateWafEnable(enableUpdate.value);
|
await UpdateWafEnable(enableUpdate.value);
|
||||||
|
} catch (error) {
|
||||||
|
enableUpdate.value.enable = !enable;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -102,9 +102,10 @@ const get = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const removeIp = (index: number) => {
|
const removeIp = (index: number) => {
|
||||||
data.value.splice(index, 1);
|
const copyList = data.value.concat();
|
||||||
|
copyList.splice(index, 1);
|
||||||
let ipArray = [];
|
let ipArray = [];
|
||||||
data.value.forEach((d) => {
|
copyList.forEach((d) => {
|
||||||
ipArray.push(d.ip);
|
ipArray.push(d.ip);
|
||||||
});
|
});
|
||||||
submit(ipArray);
|
submit(ipArray);
|
||||||
@ -146,8 +147,12 @@ const submit = async (ipList: string[]) => {
|
|||||||
const updateEnable = async (enable: boolean) => {
|
const updateEnable = async (enable: boolean) => {
|
||||||
enableUpdate.value.enable = enable;
|
enableUpdate.value.enable = enable;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
try {
|
||||||
await UpdateWafEnable(enableUpdate.value);
|
await UpdateWafEnable(enableUpdate.value);
|
||||||
|
} catch (error) {
|
||||||
|
enableUpdate.value.enable = !enable;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -143,8 +143,12 @@ const openCreate = () => {
|
|||||||
const updateEnable = async (enable: boolean) => {
|
const updateEnable = async (enable: boolean) => {
|
||||||
enableUpdate.value.enable = enable;
|
enableUpdate.value.enable = enable;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
try {
|
||||||
await UpdateWafEnable(enableUpdate.value);
|
await UpdateWafEnable(enableUpdate.value);
|
||||||
|
} catch (error) {
|
||||||
|
enableUpdate.value.enable = !enable;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = async (addArray: string[]) => {
|
const submit = async (addArray: string[]) => {
|
||||||
|
@ -333,7 +333,8 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
PreCheck({}).then((res) => {
|
PreCheck({})
|
||||||
|
.then((res) => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
preCheckRef.value.acceptParams({ items: res.data });
|
preCheckRef.value.acceptParams({ items: res.data });
|
||||||
@ -347,6 +348,9 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user