mirror of https://github.com/ouqiang/gocron
parent
3474636e23
commit
4daf0a15ba
|
@ -14,7 +14,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const AppVersion = "1.2.2"
|
||||
const AppVersion = "1.3"
|
||||
|
||||
func main() {
|
||||
var serverAddr string
|
||||
|
|
|
@ -171,6 +171,7 @@ func RegisterMiddleware(m *macaron.Macaron) {
|
|||
if app.Installed {
|
||||
ipAuth(ctx)
|
||||
userAuth(ctx, sess)
|
||||
urlAuth(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) {
|
||||
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["LoginUid"] = user.Uid(sess)
|
||||
ctx.Data["IsAdmin"] = user.IsAdmin(sess)
|
||||
ctx.Data["AppName"] = app.Setting.AppName
|
||||
}
|
||||
|
||||
|
|
|
@ -62,9 +62,9 @@
|
|||
<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 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>
|
||||
{{{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}}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
{{{ template "host/menu" . }}}
|
||||
|
||||
<div class="twelve wide column">
|
||||
{{{if .IsAdmin}}}
|
||||
<div class="pageHeader">
|
||||
<div class="segment">
|
||||
<h3 class="ui dividing header">
|
||||
|
@ -16,6 +17,7 @@
|
|||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
{{{end}}}
|
||||
<form class="ui form">
|
||||
<div class="three fields">
|
||||
<div class="field">
|
||||
|
@ -49,11 +51,15 @@
|
|||
<td>{{{.Port}}}</td>
|
||||
<td>{{{.Remark}}}</td>
|
||||
<td class="operation">
|
||||
{{{if $.IsAdmin}}}
|
||||
<a class="ui purple button" href="/host/edit/{{{.Id}}}">编辑</a>
|
||||
<button class="ui positive button" onclick="util.removeConfirm('/host/remove/{{{.Id}}}')">删除</button><br>
|
||||
{{{end}}}
|
||||
<div style="margin-top: 5px;">
|
||||
<a class="ui twitter button" href="/task?host_id={{{.Id}}}">查看任务</a>
|
||||
{{{if $.IsAdmin}}}
|
||||
<button class="ui blue button" @click="ping({{{.Id}}})">连接测试</button>
|
||||
{{{end}}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<div class="ui grid">
|
||||
{{{template "task/menu" .}}}
|
||||
<div class="twelve wide column">
|
||||
{{{if .IsAdmin}}}
|
||||
<div class="pageHeader">
|
||||
<div class="segment">
|
||||
<h3 class="ui dividing header">
|
||||
|
@ -14,6 +15,7 @@
|
|||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
{{{end}}}
|
||||
<form class="ui form">
|
||||
<div class="six fields search">
|
||||
<div class="one wide field">
|
||||
|
@ -54,6 +56,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{{if .IsAdmin}}}
|
||||
<div class="field">
|
||||
<select id="batch-operation">
|
||||
<option value="0">批量操作</option>
|
||||
|
@ -62,13 +65,16 @@
|
|||
<option value="3">删除</option>
|
||||
</select>
|
||||
</div>
|
||||
{{{end}}}
|
||||
<br>
|
||||
<table class="ui celled table task-list">
|
||||
<thead>
|
||||
<tr>
|
||||
{{{if .IsAdmin}}}
|
||||
<th>
|
||||
<input type="checkbox" onclick="checkAll(this)" style="width:25px;height: 25px;">
|
||||
</th>
|
||||
{{{end}}}
|
||||
<th>任务ID</th>
|
||||
<th>任务名称</th>
|
||||
<th>任务类型</th>
|
||||
|
@ -86,12 +92,14 @@
|
|||
<tbody>
|
||||
{{{range $i, $v := .Tasks}}}
|
||||
<tr>
|
||||
{{{if $.IsAdmin}}}
|
||||
<td>
|
||||
<input type="checkbox"
|
||||
class="sub-check"
|
||||
data-id="{{{.Id}}}"
|
||||
style="width:25px;height: 25px;">
|
||||
</td>
|
||||
{{{end}}}
|
||||
<td>{{{.Id}}}</td>
|
||||
<td>{{{.Name}}}</td>
|
||||
<td>{{{if eq .Level 1}}}主任务{{{else}}}子任务{{{end}}}</td>
|
||||
|
@ -113,7 +121,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<div class="ui buttons operation">
|
||||
|
||||
{{{if $.IsAdmin}}}
|
||||
<a href="/task/edit/{{{.Id}}}" ><i class="edit big icon" title="编辑"></i></a>
|
||||
{{{if eq .Level 1}}}
|
||||
{{{if eq .Status 1}}}
|
||||
|
@ -124,6 +132,8 @@
|
|||
{{{end}}}
|
||||
<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>
|
||||
{{{end}}}
|
||||
|
||||
<a href="/task/log?task_id={{{.Id}}}"><i class="bar chart icon big" title="查看日志"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
{{{ template "task/menu" . }}}
|
||||
|
||||
<div class="twelve wide column">
|
||||
{{{if .IsAdmin}}}
|
||||
<div class="pageHeader">
|
||||
<div class="segment">
|
||||
<h3 class="ui dividing header">
|
||||
|
@ -22,6 +23,7 @@
|
|||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
{{{end}}}
|
||||
<form class="ui form">
|
||||
<div class="six fields search">
|
||||
<div class="field">
|
||||
|
|
Loading…
Reference in New Issue