mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
增加是否开启登录功能的开关
This commit is contained in:
parent
01379e3df0
commit
fd42a7a2f7
@ -27,6 +27,7 @@ var amqpAddr string
|
||||
var amqpQueueName string
|
||||
var amqpJsonFormat bool
|
||||
var saveDays int
|
||||
var enableLogin bool
|
||||
var username string
|
||||
var password string
|
||||
|
||||
@ -51,10 +52,16 @@ func UpdateConfigByEnv() {
|
||||
amqpQueueName = Getenv("GLC_AMQP_QUEUE_NAME", "glc-log-queue") // rabbitMq队列名
|
||||
amqpJsonFormat = GetenvBool("GLC_AMQP_JSON_FORMAT", true) // rabbitMq消息文本是否为json格式,默认true
|
||||
saveDays = GetenvInt("GLC_SAVE_DAYS", 180) // 日志分仓时的保留天数(0~180),0表示不自动删除,默认180天
|
||||
enableLogin = GetenvBool("GLC_ENABLE_LOGIN", false) // 是否开启用户密码登录,默认“false”
|
||||
username = Getenv("GLC_USERNAME", "glc") // 登录用户名,默认“glc”
|
||||
password = Getenv("GLC_PASSWORD", "glogcenter") // 登录密码,默认“glogcenter”
|
||||
}
|
||||
|
||||
// 取配置: 是否开启用户密码登录,可通过环境变量“GLC_ENABLE_LOGIN”设定,默认“false”
|
||||
func IsEnableLogin() bool {
|
||||
return enableLogin
|
||||
}
|
||||
|
||||
// 取配置: 登录用户名,可通过环境变量“GLC_USERNAME”设定,默认“glc”
|
||||
func GetUsername() string {
|
||||
return username
|
||||
|
||||
@ -34,15 +34,13 @@ func Run() {
|
||||
gweb.RegisterController(method.GET, "/**/*.png", html.StaticFileController)
|
||||
|
||||
// 控制器
|
||||
gweb.RegisterController(method.POST, contextPath+"/search", controller.LogSearchController) // 查询日志 Deprecated
|
||||
gweb.RegisterController(method.POST, contextPath+"/add", controller.LogAddController) // 添加日志 Deprecated
|
||||
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/log/add", controller.JsonLogAddController) // 添加日志
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/log/search", controller.LogSearchController) // 查询日志
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/names", controller.StorageNamesController) // 查询日志仓名称列表
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/list", controller.StorageListController) // 查询日志仓信息列表
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/delete", controller.StorageDeleteController) // 删除日志仓
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/user/login", controller.LoginController) // Login
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/log/add", controller.JsonLogAddController) // 添加日志
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/log/search", controller.LogSearchController) // 查询日志
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/names", controller.StorageNamesController) // 查询日志仓名称列表
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/list", controller.StorageListController) // 查询日志仓信息列表
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/store/delete", controller.StorageDeleteController) // 删除日志仓
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/user/enableLogin", controller.IsEnableLoginController) // 查询是否开启用户密码登录功能
|
||||
gweb.RegisterController(method.POST, contextPath+"/v1/user/login", controller.LoginController) // Login
|
||||
|
||||
// 默认引擎空转一下,触发未建索引继续建
|
||||
go ldb.NewDefaultEngine().AddTextLog("", "", "")
|
||||
|
||||
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"glc/cmn"
|
||||
"glc/conf"
|
||||
"glc/gweb"
|
||||
"glc/ldb"
|
||||
)
|
||||
@ -9,7 +10,7 @@ import (
|
||||
// 日志检索(表单提交方式)
|
||||
func LogSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
|
||||
if req.GetFormParameter("token") != GetSessionid() {
|
||||
if conf.IsEnableLogin() && req.GetFormParameter("token") != GetSessionid() {
|
||||
return gweb.Error403() // 登录检查
|
||||
}
|
||||
|
||||
|
||||
@ -12,14 +12,16 @@ import (
|
||||
var sessionid string
|
||||
|
||||
func init() {
|
||||
sessionid = createSessionid()
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Hour) // 一小时更新一次
|
||||
for {
|
||||
<-ticker.C
|
||||
sessionid = createSessionid()
|
||||
}
|
||||
}()
|
||||
if conf.IsEnableLogin() {
|
||||
sessionid = createSessionid()
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Hour) // 一小时更新一次
|
||||
for {
|
||||
<-ticker.C
|
||||
sessionid = createSessionid()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func LoginController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
@ -32,6 +34,10 @@ func LoginController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
return gweb.Result(sessionid)
|
||||
}
|
||||
|
||||
func IsEnableLoginController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
return gweb.Result(conf.IsEnableLogin())
|
||||
}
|
||||
|
||||
func createSessionid() string {
|
||||
ymd := cmn.GetYyyymmdd(0)
|
||||
by1 := md5.Sum(cmn.StringToBytes(conf.GetUsername() + ymd))
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
|
||||
// 查询日志仓名称列表
|
||||
func StorageNamesController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
if req.GetFormParameter("token") != GetSessionid() {
|
||||
if conf.IsEnableLogin() && req.GetFormParameter("token") != GetSessionid() {
|
||||
return gweb.Error403() // 登录检查
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ func StorageNamesController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
|
||||
// 查询日志仓信息列表
|
||||
func StorageListController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
if req.GetFormParameter("token") != GetSessionid() {
|
||||
if conf.IsEnableLogin() && req.GetFormParameter("token") != GetSessionid() {
|
||||
return gweb.Error403() // 登录检查
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ func StorageListController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
|
||||
// 删除指定日志仓
|
||||
func StorageDeleteController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
if req.GetFormParameter("token") != GetSessionid() {
|
||||
if conf.IsEnableLogin() && req.GetFormParameter("token") != GetSessionid() {
|
||||
return gweb.Error403() // 登录检查
|
||||
}
|
||||
|
||||
|
||||
@ -15,22 +15,21 @@
|
||||
|
||||
</div>
|
||||
|
||||
<el-link v-if="isLogin" @click="logout">
|
||||
<el-link v-if="enableLogin && isLogin" @click="logout">
|
||||
<el-icon :size="26"><expand/></el-icon>
|
||||
</el-link>
|
||||
|
||||
</el-header>
|
||||
|
||||
<el-aside v-if="isLogin" class="menubar x-menubar" style="width:48px">
|
||||
<el-aside v-if="!enableLogin || isLogin" class="menubar x-menubar" style="width:48px">
|
||||
<Menu :isCollapsed="true"></Menu>
|
||||
</el-aside>
|
||||
|
||||
<el-main v-if="isLogin" class="main x-main" >
|
||||
<el-main v-if="!enableLogin || isLogin" class="main x-main" >
|
||||
<router-view></router-view>
|
||||
</el-main>
|
||||
|
||||
<Login v-if="!isLogin"></Login>
|
||||
|
||||
<Login v-if="enableLogin && !isLogin"></Login>
|
||||
|
||||
</el-container>
|
||||
</el-container>
|
||||
@ -40,6 +39,7 @@
|
||||
import Menu from './components/Menu.vue'
|
||||
import { Expand, Fold } from '@element-plus/icons-vue'
|
||||
import Login from './views/login.vue'
|
||||
import api from './api'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -47,12 +47,24 @@ export default {
|
||||
Expand,
|
||||
Menu,
|
||||
Login
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isLogin: !!sessionStorage.getItem('glctoken')
|
||||
enableLogin: true,
|
||||
isLogin: false,
|
||||
}
|
||||
},
|
||||
created() {
|
||||
api.enableLogin().then(rs => {
|
||||
let res = rs.data
|
||||
if (res.success) {
|
||||
this.enableLogin = res.result;
|
||||
if (res.result) {
|
||||
this.isLogin = !!sessionStorage.getItem('glctoken');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
clickLogo() {
|
||||
location.href = "https://github.com/gotoeasy/glogcenter"
|
||||
|
||||
@ -50,4 +50,8 @@ export default {
|
||||
formData.append("password", pass);
|
||||
return post(`${BASE_URL}/glc/v1/user/login`, formData)
|
||||
},
|
||||
enableLogin() {
|
||||
let formData = new FormData();
|
||||
return post(`${BASE_URL}/glc/v1/user/enableLogin`, formData)
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user