From 6606f64a4b2ca4c30b9d5e3faf9e55ea34c568e9 Mon Sep 17 00:00:00 2001 From: ouqiang Date: Mon, 7 May 2018 21:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=87=8D=E6=9E=84#=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 3 +- Dockerfile-release | 2 - README.md | 8 +- internal/models/setting.go | 57 ++++++- internal/routers/routers.go | 20 ++- makefile | 4 + web/vue/src/App.vue | 21 ++- web/vue/src/components/common/navMenu.vue | 31 +++- web/vue/src/main.js | 4 - web/vue/src/pages/host/list.vue | 10 +- web/vue/src/pages/install/index.vue | 154 +++++++++++++++++- .../src/pages/system/notification/email.vue | 83 ++++++++++ .../src/pages/system/notification/slack.vue | 54 ++++++ web/vue/src/pages/system/notification/tab.vue | 30 ++++ .../src/pages/system/notification/webhook.vue | 46 ++++++ web/vue/src/pages/task/edit.vue | 82 ++++++++++ web/vue/src/pages/task/list.vue | 10 +- web/vue/src/pages/taskLog/list.vue | 15 +- web/vue/src/pages/user/editPassword.vue | 1 - web/vue/src/pages/user/list.vue | 10 +- 20 files changed, 596 insertions(+), 49 deletions(-) create mode 100644 web/vue/src/pages/system/notification/email.vue create mode 100644 web/vue/src/pages/system/notification/slack.vue create mode 100644 web/vue/src/pages/system/notification/tab.vue create mode 100644 web/vue/src/pages/system/notification/webhook.vue create mode 100644 web/vue/src/pages/task/edit.vue diff --git a/.dockerignore b/.dockerignore index 191381e..1a902cc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -.git \ No newline at end of file +.git +nodu_modules \ No newline at end of file diff --git a/Dockerfile-release b/Dockerfile-release index a4b8a9c..a6aebec 100644 --- a/Dockerfile-release +++ b/Dockerfile-release @@ -1,7 +1,5 @@ FROM alpine:latest -MAINTAINER ouqiang - WORKDIR /usr/local/gocron COPY . . diff --git a/README.md b/README.md index 2e3b30e..c1cff0f 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,12 @@ 4. 浏览器访问 http://localhost:5920 ### 源码安装 -1. `go`语言版本1.9+ +1. 安装Go 1.9+, Node.js, Yarn 2. `go get -d github.com/ouqiang/gocron` -3. 编译 `make` -4. 启动 +3. 安装依赖 `make install-vue` +4. 前端打包 `make build-vue` +5. 编译Go代码 `make` +6. 启动 * gocron `./bin/gocron web` * gocron-node `./bin/gocron-node` diff --git a/internal/models/setting.go b/internal/models/setting.go index 8fd1f75..c1f591a 100644 --- a/internal/models/setting.go +++ b/internal/models/setting.go @@ -11,11 +11,34 @@ type Setting struct { Value string `xorm:"varchar(4096) notnull default '' "` } +const slackTemplate = ` +任务ID: {{.TaskId}}\n +任务名称: {{.TaskName}}\n +状态: \n {{.Status}} \n +执行结果: {{.Result}} +` +const emailTemplate = ` +任务ID: {{.TaskId}}
+任务名称: {{.TaskName}}
+状态: \n {{.Status}}
+执行结果: {{.Result}} +` +const webhookTemplate = ` +{ + "task_id": "{{.TaskId}}", + "task_name": "{{.TaskName}}", + "status": "{{.Status}}", + "result": "{{.Result}}" +} +` + const SlackCode = "slack" const SlackUrlKey = "url" +const SlackTemplateKey = "template" const SlackChannelKey = "channel" const MailCode = "mail" +const MailTemplateKey = "template" const MailServerKey = "server" const MailUserKey = "user" @@ -23,11 +46,25 @@ const MailUserKey = "user" func (setting *Setting) InitBasicField() { setting.Code = SlackCode setting.Key = SlackUrlKey + setting.Value = "" Db.Insert(setting) - setting.Id = 0 + + setting.Code = SlackCode + setting.Key = SlackTemplateKey + setting.Value = slackTemplate + Db.Insert(setting) + setting.Id = 0 + setting.Code = MailCode setting.Key = MailServerKey + setting.Value = "" + Db.Insert(setting) + setting.Id = 0 + + setting.Code = MailCode + setting.Key = MailTemplateKey + setting.Value = emailTemplate Db.Insert(setting) } @@ -36,6 +73,7 @@ func (setting *Setting) InitBasicField() { type Slack struct { Url string `json:"url"` Channels []Channel `json:"channels"` + Template string `json:"template"` } type Channel struct { @@ -46,7 +84,7 @@ type Channel struct { func (setting *Setting) Slack() (Slack, error) { list := make([]Setting, 0) err := Db.Where("code = ?", SlackCode).Find(&list) - slack := Slack{Url: "", Channels: make([]Channel, 0)} + slack := Slack{} if err != nil { return slack, err } @@ -58,14 +96,16 @@ func (setting *Setting) Slack() (Slack, error) { func (setting *Setting) formatSlack(list []Setting, slack *Slack) { for _, v := range list { - if v.Key == SlackUrlKey { + switch v.Key { + case SlackUrlKey: slack.Url = v.Value - continue + case SlackTemplateKey: + slack.Template = v.Value + default: + slack.Channels = append(slack.Channels, Channel{ + v.Id, v.Value, + }) } - - slack.Channels = append(slack.Channels, Channel{ - v.Id, v.Value, - }) } } @@ -111,6 +151,7 @@ type Mail struct { User string `json:"user"` Password string `json:"password"` MailUsers []MailUser `json:"mail_users"` + Template string `json:"template"` } type MailUser struct { diff --git a/internal/routers/routers.go b/internal/routers/routers.go index a66fc13..351bafc 100644 --- a/internal/routers/routers.go +++ b/internal/routers/routers.go @@ -130,8 +130,8 @@ func RegisterMiddleware(m *macaron.Macaron) { m.Use(toolbox.Toolboxer(m)) } m.Use(macaron.Renderer()) - m.Use(ipAuth) m.Use(checkAppInstall) + m.Use(ipAuth) m.Use(userAuth) m.Use(urlAuth) } @@ -140,10 +140,10 @@ func RegisterMiddleware(m *macaron.Macaron) { /** 检测应用是否已安装 **/ func checkAppInstall(ctx *macaron.Context) { - if ctx.Req.URL.Path == "/install" { + if app.Installed { return } - if app.Installed { + if ctx.Req.URL.Path == "/install/store" { return } jsonResp := utils.JsonResponse{} @@ -154,6 +154,9 @@ func checkAppInstall(ctx *macaron.Context) { // IP验证, 通过反向代理访问gocron,需设置Header X-Real-IP才能获取到客户端真实IP func ipAuth(ctx *macaron.Context) { + if !app.Installed { + return + } allowIpsStr := app.Setting.AllowIps if allowIpsStr == "" { return @@ -173,6 +176,9 @@ func ipAuth(ctx *macaron.Context) { // 用户认证 func userAuth(ctx *macaron.Context) { + if !app.Installed { + return + } user.RestoreToken(ctx) if user.IsLogin(ctx) { return @@ -181,7 +187,7 @@ func userAuth(ctx *macaron.Context) { if strings.HasPrefix(uri, "/v1") { return } - excludePaths := []string{"", "/install", "/user/login"} + excludePaths := []string{"", "/user/login"} for _, path := range excludePaths { if uri == path { return @@ -195,6 +201,9 @@ func userAuth(ctx *macaron.Context) { // URL权限验证 func urlAuth(ctx *macaron.Context) { + if !app.Installed { + return + } if user.IsAdmin(ctx) { return } @@ -225,6 +234,9 @@ func urlAuth(ctx *macaron.Context) { /** API接口签名验证 **/ func apiAuth(ctx *macaron.Context) { + if !app.Installed { + return + } if !app.Setting.ApiSignEnable { return } diff --git a/makefile b/makefile index d073651..37bcaa4 100644 --- a/makefile +++ b/makefile @@ -46,6 +46,10 @@ build-vue: cd web/vue && yarn run build cp -r web/vue/dist/ web/public/ +.PHONY: install-vue +install-vue: + cp web/vue && yarn install + .PHONY: clean clean: rm bin/gocron diff --git a/web/vue/src/App.vue b/web/vue/src/App.vue index f97270b..d2903b3 100644 --- a/web/vue/src/App.vue +++ b/web/vue/src/App.vue @@ -5,7 +5,7 @@ -
+
@@ -35,9 +35,26 @@ export default { } diff --git a/web/vue/src/components/common/navMenu.vue b/web/vue/src/components/common/navMenu.vue index 94cceac..615be81 100644 --- a/web/vue/src/components/common/navMenu.vue +++ b/web/vue/src/components/common/navMenu.vue @@ -7,15 +7,28 @@ text-color="#fff" active-text-color="#ffd04b" router> - 任务管理 - 任务节点 - 用户管理 - 系统管理 - - - 修改密码 - 退出 - + + + 任务管理 + + + 任务节点 + + + 用户管理 + + + 系统管理 + + + + + + 修改密码 + 退出 + + +
diff --git a/web/vue/src/main.js b/web/vue/src/main.js index aa818ab..02b8152 100644 --- a/web/vue/src/main.js +++ b/web/vue/src/main.js @@ -10,10 +10,6 @@ import store from './store/index' Vue.config.productionTip = false Vue.use(ElementUI) -Vue.prototype.$refresh = function () { - router.go(0) -} - Vue.prototype.$appConfirm = function (callback) { this.$confirm('确定执行此操作?', '提示', { confirmButtonText: '确定', diff --git a/web/vue/src/pages/host/list.vue b/web/vue/src/pages/host/list.vue index 960852e..269edb8 100644 --- a/web/vue/src/pages/host/list.vue +++ b/web/vue/src/pages/host/list.vue @@ -14,8 +14,14 @@ - 新增 - 刷新

+ + + 新增 + + + 刷新 + + -
- 安装页面 -
+ + + +

数据库配置

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

管理员账号配置

+ + + + + + + + + + + + + + + + + + + + + + + + + + 安装 + +
+
+
diff --git a/web/vue/src/pages/system/notification/email.vue b/web/vue/src/pages/system/notification/email.vue new file mode 100644 index 0000000..ec8bef4 --- /dev/null +++ b/web/vue/src/pages/system/notification/email.vue @@ -0,0 +1,83 @@ + + + diff --git a/web/vue/src/pages/system/notification/slack.vue b/web/vue/src/pages/system/notification/slack.vue new file mode 100644 index 0000000..b913719 --- /dev/null +++ b/web/vue/src/pages/system/notification/slack.vue @@ -0,0 +1,54 @@ + + + diff --git a/web/vue/src/pages/system/notification/tab.vue b/web/vue/src/pages/system/notification/tab.vue new file mode 100644 index 0000000..40d63a5 --- /dev/null +++ b/web/vue/src/pages/system/notification/tab.vue @@ -0,0 +1,30 @@ + + + diff --git a/web/vue/src/pages/system/notification/webhook.vue b/web/vue/src/pages/system/notification/webhook.vue new file mode 100644 index 0000000..7d70eae --- /dev/null +++ b/web/vue/src/pages/system/notification/webhook.vue @@ -0,0 +1,46 @@ + + + diff --git a/web/vue/src/pages/task/edit.vue b/web/vue/src/pages/task/edit.vue new file mode 100644 index 0000000..053bf21 --- /dev/null +++ b/web/vue/src/pages/task/edit.vue @@ -0,0 +1,82 @@ + + + diff --git a/web/vue/src/pages/task/list.vue b/web/vue/src/pages/task/list.vue index 5bd9809..9c6742a 100644 --- a/web/vue/src/pages/task/list.vue +++ b/web/vue/src/pages/task/list.vue @@ -53,8 +53,14 @@ - 新增 - 刷新

+ + + 新增 + + + 刷新 + + 搜索 -

- 清空日志 - 刷新

-

+ + + 清空日志 + + + 刷新 + + + label="任务名称" + width="180"> { this.$router.push('/user') }) diff --git a/web/vue/src/pages/user/list.vue b/web/vue/src/pages/user/list.vue index 7e7c99d..a9d50d7 100644 --- a/web/vue/src/pages/user/list.vue +++ b/web/vue/src/pages/user/list.vue @@ -1,8 +1,14 @@