mirror of https://github.com/ouqiang/gocron
安装系统页面,不显示导航栏
parent
d3d7350fc7
commit
ebb5139a7b
|
@ -1,10 +1,12 @@
|
|||
[![Build Status](https://travis-ci.org/ouqiang/gocron.png)](https://travis-ci.org/ouqiang/gocron)
|
||||
# gocron - 定时任务web管理系统
|
||||
|
||||
# 项目简介
|
||||
使用Go语言开发的定时任务集中调度和管理系统, 用于替代Linux-crontab
|
||||
|
||||
## 功能特性
|
||||
* 定时任务统一调度和管理
|
||||
* 支持任务CURD
|
||||
* crontab时间表达式,支持秒级任务定义
|
||||
* crontab时间表达式,可精确到每秒
|
||||
* 任务执行失败重试设置
|
||||
* 任务超时设置
|
||||
* 任务执行方式
|
||||
|
|
|
@ -101,6 +101,7 @@ func writeConfig(form InstallForm) error {
|
|||
"db.prefix": form.DbTablePrefix,
|
||||
"db.charset": "utf8",
|
||||
"allow_ips" : "",
|
||||
"app.name": "定时任务管理系统", // 应用名称
|
||||
}
|
||||
|
||||
return setting.Write(dbConfig, app.AppConfig)
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"github.com/ouqiang/gocron/routers/user"
|
||||
"github.com/go-macaron/gzip"
|
||||
"github.com/ouqiang/gocron/routers/manage"
|
||||
"github.com/go-macaron/csrf"
|
||||
"github.com/ouqiang/gocron/routers/loginlog"
|
||||
)
|
||||
|
||||
|
@ -139,12 +138,15 @@ func RegisterMiddleware(m *macaron.Macaron) {
|
|||
Provider: "file",
|
||||
ProviderConfig: app.DataDir + "/sessions",
|
||||
}))
|
||||
m.Use(csrf.Csrfer())
|
||||
m.Use(toolbox.Toolboxer(m))
|
||||
checkAppInstall(m)
|
||||
ipAuth(m)
|
||||
userAuth(m)
|
||||
setShareData(m)
|
||||
m.Use(func(ctx *macaron.Context, sess session.Store){
|
||||
if app.Installed {
|
||||
ipAuth(ctx)
|
||||
userAuth(ctx, sess)
|
||||
setShareData(ctx, sess)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 系统未安装,重定向到安装页面
|
||||
|
@ -161,57 +163,54 @@ func checkAppInstall(m *macaron.Macaron) {
|
|||
}
|
||||
|
||||
// IP验证, 通过反向代理访问gocron,需设置Header X-Real-IP才能获取到客户端真实IP
|
||||
func ipAuth(m *macaron.Macaron) {
|
||||
m.Use(func(ctx *macaron.Context) {
|
||||
allowIpsStr := app.Setting.Key("allow_ips").String()
|
||||
if allowIpsStr == "" {
|
||||
return
|
||||
}
|
||||
clientIp := ctx.RemoteAddr()
|
||||
if !utils.InStringSlice(allowIps, clientIp) {
|
||||
ctx.Status(403)
|
||||
}
|
||||
})
|
||||
func ipAuth(ctx *macaron.Context) {
|
||||
allowIpsStr := app.Setting.Key("allow_ips").String()
|
||||
if allowIpsStr == "" {
|
||||
return
|
||||
}
|
||||
clientIp := ctx.RemoteAddr()
|
||||
allowIps := strings.Split(allowIpsStr, ",")
|
||||
if !utils.InStringSlice(allowIps, clientIp) {
|
||||
logger.Warnf("非法IP访问-%s", clientIp)
|
||||
ctx.Status(403)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户认证
|
||||
func userAuth(m *macaron.Macaron) {
|
||||
m.Use(func(ctx *macaron.Context, sess session.Store) {
|
||||
if user.IsLogin(sess) {
|
||||
return
|
||||
func userAuth(ctx *macaron.Context, sess session.Store) {
|
||||
if user.IsLogin(sess) {
|
||||
return
|
||||
}
|
||||
uri := ctx.Req.URL.Path
|
||||
found := false
|
||||
excludePaths := []string{"/install", "/user/login", "/api"}
|
||||
for _, path := range excludePaths {
|
||||
if strings.HasPrefix(uri, path) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
uri := ctx.Req.URL.Path
|
||||
found := false
|
||||
excludePaths := []string{"/install", "/user/login", "/api"}
|
||||
for _, path := range excludePaths {
|
||||
if strings.HasPrefix(uri, path) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ctx.Redirect("/user/login")
|
||||
}
|
||||
})
|
||||
}
|
||||
if !found {
|
||||
ctx.Redirect("/user/login")
|
||||
}
|
||||
}
|
||||
|
||||
// 设置共享数据
|
||||
func setShareData(m *macaron.Macaron) {
|
||||
m.Use(func(ctx *macaron.Context, sess session.Store) {
|
||||
ctx.Data["URI"] = ctx.Req.URL.Path
|
||||
urlPath := strings.TrimPrefix(ctx.Req.URL.Path, "/")
|
||||
paths := strings.Split(urlPath, "/")
|
||||
ctx.Data["Controller"] = ""
|
||||
ctx.Data["Action"] = ""
|
||||
if len(paths) > 0 {
|
||||
ctx.Data["Controller"] = paths[0]
|
||||
}
|
||||
if len(paths) > 1 {
|
||||
ctx.Data["Action"] = paths[1]
|
||||
}
|
||||
ctx.Data["LoginUsername"] = user.Username(sess)
|
||||
ctx.Data["LoginUid"] = user.Uid(sess)
|
||||
})
|
||||
func setShareData(ctx *macaron.Context, sess session.Store) {
|
||||
ctx.Data["URI"] = ctx.Req.URL.Path
|
||||
urlPath := strings.TrimPrefix(ctx.Req.URL.Path, "/")
|
||||
paths := strings.Split(urlPath, "/")
|
||||
ctx.Data["Controller"] = ""
|
||||
ctx.Data["Action"] = ""
|
||||
if len(paths) > 0 {
|
||||
ctx.Data["Controller"] = paths[0]
|
||||
}
|
||||
if len(paths) > 1 {
|
||||
ctx.Data["Action"] = paths[1]
|
||||
}
|
||||
ctx.Data["LoginUsername"] = user.Username(sess)
|
||||
ctx.Data["LoginUid"] = user.Uid(sess)
|
||||
ctx.Data["AppName"] = app.Setting.Key("app.name").String()
|
||||
}
|
||||
|
||||
func isAjaxRequest(ctx *macaron.Context) bool {
|
||||
|
|
|
@ -29,11 +29,12 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
{{{if not .DisableNav}}}
|
||||
<!--header begin-->
|
||||
<header>
|
||||
<div class="bigcontainer">
|
||||
<div id="logo">
|
||||
定时任务管理平台
|
||||
{{{.AppName}}}
|
||||
</div>
|
||||
<div class="user">
|
||||
<div class="ui inline labeled icon top right pointing dropdown">
|
||||
|
@ -68,4 +69,5 @@
|
|||
<a class="item" href="https://github.com/ouqiang/gocron/wiki" target="_blank"><i class="file text icon"></i>查看文档</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{{end}}}
|
|
@ -2,17 +2,7 @@
|
|||
|
||||
<div class="ui grid">
|
||||
{{{ template "install/menu" . }}}
|
||||
<div class="twelve wide column">
|
||||
<div class="pageHeader">
|
||||
<div class="segment">
|
||||
<h3 class="ui dividing header">
|
||||
<i class="large add icon"></i>
|
||||
<div class="content">
|
||||
安装gocron
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ten wide column">
|
||||
<form class="ui form">
|
||||
<div class="ui blue center aligned segment">
|
||||
<p>数据库配置</p>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div class="verticalMenu">
|
||||
<div class="ui vertical pointing menu fluid">
|
||||
<a class="active teal item" href="/install">
|
||||
<i class="linux icon"></i> 安装
|
||||
<i class="chevron right icon"></i> 安装
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue