mirror of https://github.com/ouqiang/gocron
parent
3474636e23
commit
4daf0a15ba
|
@ -14,7 +14,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const AppVersion = "1.2.2"
|
const AppVersion = "1.3"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var serverAddr string
|
var serverAddr string
|
||||||
|
|
|
@ -171,6 +171,7 @@ func RegisterMiddleware(m *macaron.Macaron) {
|
||||||
if app.Installed {
|
if app.Installed {
|
||||||
ipAuth(ctx)
|
ipAuth(ctx)
|
||||||
userAuth(ctx, sess)
|
userAuth(ctx, sess)
|
||||||
|
urlAuth(ctx, sess)
|
||||||
setShareData(ctx, sess)
|
setShareData(ctx, sess)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -224,6 +225,33 @@ func userAuth(ctx *macaron.Context, sess session.Store) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URL权限验证
|
||||||
|
func urlAuth(ctx *macaron.Context, sess session.Store) {
|
||||||
|
if user.IsAdmin(sess) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 普通用户允许访问的URL地址
|
||||||
|
allowPaths := []string{
|
||||||
|
"",
|
||||||
|
"/task",
|
||||||
|
"/task/log",
|
||||||
|
"/host",
|
||||||
|
"/user/login",
|
||||||
|
"/user/logout",
|
||||||
|
"/user/editMyPassword",
|
||||||
|
}
|
||||||
|
uri := strings.TrimSpace(ctx.Req.URL.Path)
|
||||||
|
uri = strings.TrimRight(uri, "/")
|
||||||
|
for _, path := range allowPaths {
|
||||||
|
if path == uri {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Status(403)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** 设置共享数据 **/
|
/** 设置共享数据 **/
|
||||||
func setShareData(ctx *macaron.Context, sess session.Store) {
|
func setShareData(ctx *macaron.Context, sess session.Store) {
|
||||||
ctx.Data["URI"] = ctx.Req.URL.Path
|
ctx.Data["URI"] = ctx.Req.URL.Path
|
||||||
|
@ -239,6 +267,7 @@ func setShareData(ctx *macaron.Context, sess session.Store) {
|
||||||
}
|
}
|
||||||
ctx.Data["LoginUsername"] = user.Username(sess)
|
ctx.Data["LoginUsername"] = user.Username(sess)
|
||||||
ctx.Data["LoginUid"] = user.Uid(sess)
|
ctx.Data["LoginUid"] = user.Uid(sess)
|
||||||
|
ctx.Data["IsAdmin"] = user.IsAdmin(sess)
|
||||||
ctx.Data["AppName"] = app.Setting.AppName
|
ctx.Data["AppName"] = app.Setting.AppName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,9 @@
|
||||||
<div class="right menu">
|
<div class="right menu">
|
||||||
<a class="item {{{if or (eq .Controller "task") (eq .Controller "delaytask")}}}active{{{end}}}" href="/task"><i class="tasks icon"></i>任务</a>
|
<a class="item {{{if or (eq .Controller "task") (eq .Controller "delaytask")}}}active{{{end}}}" href="/task"><i class="tasks icon"></i>任务</a>
|
||||||
<a class="item {{{if eq .Controller "host"}}}active{{{end}}}" href="/host"><i class="linux icon"></i>任务节点</a>
|
<a class="item {{{if eq .Controller "host"}}}active{{{end}}}" href="/host"><i class="linux icon"></i>任务节点</a>
|
||||||
|
{{{if .IsAdmin}}}
|
||||||
<a class="item {{{if eq .Controller "user"}}}active{{{end}}}" href="/user"><i class="user icon"></i>用户管理</a>
|
<a class="item {{{if eq .Controller "user"}}}active{{{end}}}" href="/user"><i class="user icon"></i>用户管理</a>
|
||||||
{{{if gt .LoginUid 0}}}
|
<a class="item {{{if eq .Controller "manage"}}}active{{{end}}}" href="/manage/slack/edit"><i class="settings icon"></i>系统管理</a>
|
||||||
<a class="item {{{if eq .Controller "manage"}}}active{{{end}}}" href="/manage/slack/edit"><i class="settings icon"></i>管理</a>
|
|
||||||
{{{end}}}
|
{{{end}}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
{{{ template "host/menu" . }}}
|
{{{ template "host/menu" . }}}
|
||||||
|
|
||||||
<div class="twelve wide column">
|
<div class="twelve wide column">
|
||||||
<div class="pageHeader">
|
{{{if .IsAdmin}}}
|
||||||
|
<div class="pageHeader">
|
||||||
<div class="segment">
|
<div class="segment">
|
||||||
<h3 class="ui dividing header">
|
<h3 class="ui dividing header">
|
||||||
<a href="/host/create">
|
<a href="/host/create">
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{{end}}}
|
||||||
<form class="ui form">
|
<form class="ui form">
|
||||||
<div class="three fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
@ -49,11 +51,15 @@
|
||||||
<td>{{{.Port}}}</td>
|
<td>{{{.Port}}}</td>
|
||||||
<td>{{{.Remark}}}</td>
|
<td>{{{.Remark}}}</td>
|
||||||
<td class="operation">
|
<td class="operation">
|
||||||
|
{{{if $.IsAdmin}}}
|
||||||
<a class="ui purple button" href="/host/edit/{{{.Id}}}">编辑</a>
|
<a class="ui purple button" href="/host/edit/{{{.Id}}}">编辑</a>
|
||||||
<button class="ui positive button" onclick="util.removeConfirm('/host/remove/{{{.Id}}}')">删除</button><br>
|
<button class="ui positive button" onclick="util.removeConfirm('/host/remove/{{{.Id}}}')">删除</button><br>
|
||||||
|
{{{end}}}
|
||||||
<div style="margin-top: 5px;">
|
<div style="margin-top: 5px;">
|
||||||
<a class="ui twitter button" href="/task?host_id={{{.Id}}}">查看任务</a>
|
<a class="ui twitter button" href="/task?host_id={{{.Id}}}">查看任务</a>
|
||||||
|
{{{if $.IsAdmin}}}
|
||||||
<button class="ui blue button" @click="ping({{{.Id}}})">连接测试</button>
|
<button class="ui blue button" @click="ping({{{.Id}}})">连接测试</button>
|
||||||
|
{{{end}}}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
{{{template "task/menu" .}}}
|
{{{template "task/menu" .}}}
|
||||||
<div class="twelve wide column">
|
<div class="twelve wide column">
|
||||||
<div class="pageHeader">
|
{{{if .IsAdmin}}}
|
||||||
|
<div class="pageHeader">
|
||||||
<div class="segment">
|
<div class="segment">
|
||||||
<h3 class="ui dividing header">
|
<h3 class="ui dividing header">
|
||||||
<a href="/task/create">
|
<a href="/task/create">
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{{end}}}
|
||||||
<form class="ui form">
|
<form class="ui form">
|
||||||
<div class="six fields search">
|
<div class="six fields search">
|
||||||
<div class="one wide field">
|
<div class="one wide field">
|
||||||
|
@ -54,21 +56,25 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="field">
|
{{{if .IsAdmin}}}
|
||||||
<select id="batch-operation">
|
<div class="field">
|
||||||
<option value="0">批量操作</option>
|
<select id="batch-operation">
|
||||||
<option value="1">激活</option>
|
<option value="0">批量操作</option>
|
||||||
<option value="2">停止</option>
|
<option value="1">激活</option>
|
||||||
<option value="3">删除</option>
|
<option value="2">停止</option>
|
||||||
</select>
|
<option value="3">删除</option>
|
||||||
</div>
|
</select>
|
||||||
|
</div>
|
||||||
|
{{{end}}}
|
||||||
<br>
|
<br>
|
||||||
<table class="ui celled table task-list">
|
<table class="ui celled table task-list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
{{{if .IsAdmin}}}
|
||||||
<input type="checkbox" onclick="checkAll(this)" style="width:25px;height: 25px;">
|
<th>
|
||||||
</th>
|
<input type="checkbox" onclick="checkAll(this)" style="width:25px;height: 25px;">
|
||||||
|
</th>
|
||||||
|
{{{end}}}
|
||||||
<th>任务ID</th>
|
<th>任务ID</th>
|
||||||
<th>任务名称</th>
|
<th>任务名称</th>
|
||||||
<th>任务类型</th>
|
<th>任务类型</th>
|
||||||
|
@ -86,12 +92,14 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{{range $i, $v := .Tasks}}}
|
{{{range $i, $v := .Tasks}}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
{{{if $.IsAdmin}}}
|
||||||
<input type="checkbox"
|
<td>
|
||||||
class="sub-check"
|
<input type="checkbox"
|
||||||
data-id="{{{.Id}}}"
|
class="sub-check"
|
||||||
style="width:25px;height: 25px;">
|
data-id="{{{.Id}}}"
|
||||||
</td>
|
style="width:25px;height: 25px;">
|
||||||
|
</td>
|
||||||
|
{{{end}}}
|
||||||
<td>{{{.Id}}}</td>
|
<td>{{{.Id}}}</td>
|
||||||
<td>{{{.Name}}}</td>
|
<td>{{{.Name}}}</td>
|
||||||
<td>{{{if eq .Level 1}}}主任务{{{else}}}子任务{{{end}}}</td>
|
<td>{{{if eq .Level 1}}}主任务{{{else}}}子任务{{{end}}}</td>
|
||||||
|
@ -113,7 +121,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="ui buttons operation">
|
<div class="ui buttons operation">
|
||||||
|
{{{if $.IsAdmin}}}
|
||||||
<a href="/task/edit/{{{.Id}}}" ><i class="edit big icon" title="编辑"></i></a>
|
<a href="/task/edit/{{{.Id}}}" ><i class="edit big icon" title="编辑"></i></a>
|
||||||
{{{if eq .Level 1}}}
|
{{{if eq .Level 1}}}
|
||||||
{{{if eq .Status 1}}}
|
{{{if eq .Status 1}}}
|
||||||
|
@ -124,6 +132,8 @@
|
||||||
{{{end}}}
|
{{{end}}}
|
||||||
<a href="javascript:void(0);" @click="remove({{{.Id}}})"><i class="remove big icon" title="删除"></i></a>
|
<a href="javascript:void(0);" @click="remove({{{.Id}}})"><i class="remove big icon" title="删除"></i></a>
|
||||||
<a href="javascript:void(0);" @click="run({{{.Id}}})"><i class="rocket big icon" title="手动执行"></i></a>
|
<a href="javascript:void(0);" @click="run({{{.Id}}})"><i class="rocket big icon" title="手动执行"></i></a>
|
||||||
|
{{{end}}}
|
||||||
|
|
||||||
<a href="/task/log?task_id={{{.Id}}}"><i class="bar chart icon big" title="查看日志"></i></a>
|
<a href="/task/log?task_id={{{.Id}}}"><i class="bar chart icon big" title="查看日志"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
{{{ template "task/menu" . }}}
|
{{{ template "task/menu" . }}}
|
||||||
|
|
||||||
<div class="twelve wide column">
|
<div class="twelve wide column">
|
||||||
|
{{{if .IsAdmin}}}
|
||||||
<div class="pageHeader">
|
<div class="pageHeader">
|
||||||
<div class="segment">
|
<div class="segment">
|
||||||
<h3 class="ui dividing header">
|
<h3 class="ui dividing header">
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{{end}}}
|
||||||
<form class="ui form">
|
<form class="ui form">
|
||||||
<div class="six fields search">
|
<div class="six fields search">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
Loading…
Reference in New Issue