mirror of
https://gitee.com/gokins/gokins.git
synced 2024-11-29 17:57:50 +08:00
commit
c7ed2705d2
10
README.md
10
README.md
@ -27,11 +27,21 @@ Gokins是一个由Go语言和Vue编写的款轻量级、能够持续集成和持
|
||||
* **安全**
|
||||
|
||||
绝不收集任何用户、服务器信息,是一个独立安全的服务
|
||||
|
||||
## Demo
|
||||
|
||||
[demo-示例展示-点击这里](http://gokins.cn:8030).
|
||||
|
||||
> 1. 本示例仅提供展示作用(登录密码:123456)
|
||||
> 2. 此示例每天凌晨会有gokins定时器 __重新编译__
|
||||
> 3. 如果进不去,就是被其他人玩坏了,请等待重新编译(第二天早点来)
|
||||
> 4. 示例提供git,gcc,golang,java8,maven环境
|
||||
|
||||
## Quick Start
|
||||
|
||||
It is super easy to get started with your first project.
|
||||
|
||||
|
||||
#### Step 1: 下载
|
||||
|
||||
[latest stable release](https://github.com/mgr9525/gokins/releases).
|
||||
|
54
comm/dbfl.go
54
comm/dbfl.go
@ -13,7 +13,7 @@ const sqls = `
|
||||
Target Server Version : 3030001
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 23/10/2020 20:25:46
|
||||
Date: 30/10/2020 11:08:09
|
||||
*/
|
||||
|
||||
PRAGMA foreign_keys = false;
|
||||
@ -29,12 +29,6 @@ CREATE TABLE "sys_param" (
|
||||
"times" datetime
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_param
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_user
|
||||
-- ----------------------------
|
||||
@ -53,13 +47,6 @@ CREATE TABLE "sys_user" (
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_user
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO "sys_user" VALUES (1, 'admin', 'root', NULL, '超级管理员', NULL, '2020-07-08 07:25:53', NULL, NULL, NULL);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_model
|
||||
-- ----------------------------
|
||||
@ -73,16 +60,9 @@ CREATE TABLE "t_model" (
|
||||
"del" integer DEFAULT 0,
|
||||
"envs" text,
|
||||
"wrkdir" text,
|
||||
"clrdir" integer DEFAULT 0,
|
||||
"timer_switch" integer
|
||||
"clrdir" integer DEFAULT 0
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_model
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_model_run
|
||||
-- ----------------------------
|
||||
@ -99,12 +79,6 @@ CREATE TABLE "t_model_run" (
|
||||
"tgtyps" text
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_model_run
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_output
|
||||
-- ----------------------------
|
||||
@ -117,12 +91,6 @@ CREATE TABLE "t_output" (
|
||||
"times" datetime
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_output
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_plugin
|
||||
-- ----------------------------
|
||||
@ -140,12 +108,6 @@ CREATE TABLE "t_plugin" (
|
||||
"exend" integer DEFAULT 0
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_plugin
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_plugin_run
|
||||
-- ----------------------------
|
||||
@ -161,12 +123,6 @@ CREATE TABLE "t_plugin_run" (
|
||||
"excode" integer
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_plugin_run
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_trigger
|
||||
-- ----------------------------
|
||||
@ -190,12 +146,6 @@ CREATE TABLE "t_trigger" (
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_trigger
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Auto increment value for sys_param
|
||||
-- ----------------------------
|
||||
|
11
comm/vars.go
11
comm/vars.go
@ -6,11 +6,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Dir string
|
||||
Path string
|
||||
Host string
|
||||
Gin *gin.Engine
|
||||
Db *xorm.Engine
|
||||
Dir string
|
||||
Path string
|
||||
Host string
|
||||
NoUppass bool
|
||||
Gin *gin.Engine
|
||||
Db *xorm.Engine
|
||||
|
||||
RunTaskLen int = 5
|
||||
)
|
||||
|
File diff suppressed because one or more lines are too long
BIN
doc/sys.db
BIN
doc/sys.db
Binary file not shown.
54
doc/sys.sql
54
doc/sys.sql
@ -10,7 +10,7 @@
|
||||
Target Server Version : 3030001
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 23/10/2020 20:25:46
|
||||
Date: 30/10/2020 11:08:09
|
||||
*/
|
||||
|
||||
PRAGMA foreign_keys = false;
|
||||
@ -26,12 +26,6 @@ CREATE TABLE "sys_param" (
|
||||
"times" datetime
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_param
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_user
|
||||
-- ----------------------------
|
||||
@ -50,13 +44,6 @@ CREATE TABLE "sys_user" (
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_user
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO "sys_user" VALUES (1, 'admin', 'root', NULL, '超级管理员', NULL, '2020-07-08 07:25:53', NULL, NULL, NULL);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_model
|
||||
-- ----------------------------
|
||||
@ -70,16 +57,9 @@ CREATE TABLE "t_model" (
|
||||
"del" integer DEFAULT 0,
|
||||
"envs" text,
|
||||
"wrkdir" text,
|
||||
"clrdir" integer DEFAULT 0,
|
||||
"timer_switch" integer
|
||||
"clrdir" integer DEFAULT 0
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_model
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_model_run
|
||||
-- ----------------------------
|
||||
@ -96,12 +76,6 @@ CREATE TABLE "t_model_run" (
|
||||
"tgtyps" text
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_model_run
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_output
|
||||
-- ----------------------------
|
||||
@ -114,12 +88,6 @@ CREATE TABLE "t_output" (
|
||||
"times" datetime
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_output
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_plugin
|
||||
-- ----------------------------
|
||||
@ -137,12 +105,6 @@ CREATE TABLE "t_plugin" (
|
||||
"exend" integer DEFAULT 0
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_plugin
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_plugin_run
|
||||
-- ----------------------------
|
||||
@ -158,12 +120,6 @@ CREATE TABLE "t_plugin_run" (
|
||||
"excode" integer
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_plugin_run
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_trigger
|
||||
-- ----------------------------
|
||||
@ -187,12 +143,6 @@ CREATE TABLE "t_trigger" (
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_trigger
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Auto increment value for sys_param
|
||||
-- ----------------------------
|
||||
|
1
main.go
1
main.go
@ -38,6 +38,7 @@ func init() {
|
||||
println("dir:" + dir)
|
||||
flag.StringVar(&comm.Dir, "d", dir, "数据目录")
|
||||
flag.StringVar(&comm.Host, "bind", ":8030", "绑定地址")
|
||||
flag.BoolVar(&comm.NoUppass, "nps", false, "是否禁止修改密码")
|
||||
flag.IntVar(&comm.RunTaskLen, "rln", 5, "同时执行的流水线数量")
|
||||
flag.StringVar(&clearPass, "clp", "", "清除某个用户密码(请先关闭服务在执行)")
|
||||
flag.StringVar(&mvData, "mvdata", "", "转移某个库数据到本地(目前不转移运行日志记录)")
|
||||
|
24
mgr/run.go
24
mgr/run.go
@ -51,18 +51,18 @@ func (c *RunTask) run() {
|
||||
if c.Md.Clrdir == 1 {
|
||||
err := rmDirFiles(c.Md.Wrkdir)
|
||||
if err != nil {
|
||||
c.end(2, "运行目录创建失败:"+err.Error())
|
||||
c.end(2, "工作目录创建失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if c.Md.Clrdir != 1 {
|
||||
c.end(2, "运行目录不存在")
|
||||
/*if c.Md.Clrdir != 1 {
|
||||
c.end(2, "工作目录不存在")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
err := os.MkdirAll(c.Md.Wrkdir, 0755)
|
||||
if err != nil {
|
||||
c.end(2, "运行目录创建失败:"+err.Error())
|
||||
c.end(2, "工作目录创建失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -159,32 +159,34 @@ func (c *RunTask) runs(pgn *model.TPlugin) (rns *model.TPluginRun, rterr error)
|
||||
if regPATH.MatchString(s) {
|
||||
noPath = false
|
||||
envs[i] = strings.ReplaceAll(s, "$PATH", os.Getenv("PATH"))
|
||||
envs[i] = strings.ReplaceAll(s, "${PATH}", os.Getenv("PATH"))
|
||||
}
|
||||
}
|
||||
if noPath {
|
||||
envs = append(envs, "PATH="+os.Getenv("PATH"))
|
||||
}
|
||||
envs = append(envs, "WORKDIR="+c.Md.Wrkdir)
|
||||
cmd.Env = envs
|
||||
}
|
||||
if c.Md.Wrkdir != "" {
|
||||
cmd.Dir = c.Md.Wrkdir
|
||||
} else if comm.Dir != "" {
|
||||
cmd.Dir = comm.Dir
|
||||
}
|
||||
err = cmd.Run()
|
||||
rn.State = 4
|
||||
if err != nil {
|
||||
println("cmd.run err:" + err.Error())
|
||||
rn.State = 2
|
||||
return rn, err
|
||||
// rn.State = 2
|
||||
// return rn, err
|
||||
}
|
||||
fmt.Println(fmt.Sprintf("cmdRun(%s)dir:%s", pgn.Title, cmd.Dir))
|
||||
if cmd.ProcessState != nil {
|
||||
rn.Excode = cmd.ProcessState.ExitCode()
|
||||
}
|
||||
if rn.Excode != 0 {
|
||||
if pgn.Exend == 1 && (err != nil || rn.Excode != 0) {
|
||||
rn.State = 2
|
||||
if pgn.Exend == 1 {
|
||||
return rn, fmt.Errorf("程序执行错误:%d", rn.Excode)
|
||||
}
|
||||
return rn, fmt.Errorf("程序执行错误(exit:%d):%+v", rn.Excode, err)
|
||||
}
|
||||
return rn, nil
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ function main(){
|
||||
`,
|
||||
}
|
||||
HookjsMap["github"] = &Hookjs{
|
||||
Uis: map[string]string{"secretkey": "string", "branch": "string"},
|
||||
Desc: "secretkey:签名秘钥,branch:push对象分支",
|
||||
Defs: `{"secretkey":"pwd","branch":"master"}`,
|
||||
Uis: map[string]string{"password": "string", "branch": "string"},
|
||||
Desc: "password:签名秘钥,branch:push对象分支",
|
||||
Defs: `{"password":"pwd","branch":"master"}`,
|
||||
js: `
|
||||
|
||||
function main(){
|
||||
|
@ -10,6 +10,6 @@ import (
|
||||
func CommInfo(c *gin.Context) {
|
||||
root := dbService.FindUser("admin")
|
||||
info := ruisUtil.NewMap()
|
||||
info.Set("need_install", root.Pass == "")
|
||||
info.Set("need_install", root == nil || root.Pass == "")
|
||||
c.JSON(200, info)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"gokins/comm"
|
||||
"gokins/core"
|
||||
"gokins/model"
|
||||
"gokins/service/dbService"
|
||||
"gokins/service/utilService"
|
||||
"time"
|
||||
@ -27,6 +28,13 @@ func LoginInfo(c *gin.Context) {
|
||||
c.JSON(200, rets)
|
||||
}
|
||||
|
||||
type lgTimes struct {
|
||||
times int
|
||||
lgtm time.Time
|
||||
}
|
||||
|
||||
var mplgtms = make(map[string]*lgTimes)
|
||||
|
||||
func Login(c *gin.Context, req *ruisUtil.Map) {
|
||||
name := req.GetString("name")
|
||||
pass := req.GetString("pass")
|
||||
@ -39,10 +47,30 @@ func Login(c *gin.Context, req *ruisUtil.Map) {
|
||||
c.String(511, "未找到用户!")
|
||||
return
|
||||
}
|
||||
|
||||
isin := false
|
||||
tms, ok := mplgtms[usr.Xid]
|
||||
if ok && time.Since(tms.lgtm).Minutes() <= 10 {
|
||||
isin = true
|
||||
if tms.times >= 2 {
|
||||
c.String(521, "失败次数太多,十分钟后再试!")
|
||||
return
|
||||
}
|
||||
}
|
||||
if usr.Pass != ruisUtil.Md5String(pass) {
|
||||
if isin {
|
||||
tms.times++
|
||||
//tms.lgtm = time.Now()
|
||||
} else {
|
||||
mplgtms[usr.Xid] = &lgTimes{
|
||||
times: 0,
|
||||
lgtm: time.Now(),
|
||||
}
|
||||
}
|
||||
c.String(512, "密码错误!")
|
||||
return
|
||||
}
|
||||
delete(mplgtms, usr.Xid)
|
||||
|
||||
tks, err := core.CreateToken(&jwt.MapClaims{
|
||||
"xid": usr.Xid,
|
||||
@ -60,17 +88,27 @@ func Install(c *gin.Context, req *ruisUtil.Map) {
|
||||
c.String(500, "param err!")
|
||||
return
|
||||
}
|
||||
isup := true
|
||||
usr := dbService.FindUser("admin")
|
||||
if usr == nil {
|
||||
c.String(511, "未找到用户!")
|
||||
return
|
||||
isup = false
|
||||
usr = &model.SysUser{}
|
||||
usr.Xid = "admin"
|
||||
usr.Name = "root"
|
||||
usr.Nick = "超级管理员"
|
||||
usr.Times = time.Now()
|
||||
}
|
||||
if usr.Pass != "" {
|
||||
c.String(512, "what??!")
|
||||
return
|
||||
}
|
||||
usr.Pass = ruisUtil.Md5String(pass)
|
||||
_, err := comm.Db.Cols("pass").Where("id=?", usr.Id).Update(usr)
|
||||
var err error
|
||||
if isup {
|
||||
_, err = comm.Db.Cols("pass").Where("id=?", usr.Id).Update(usr)
|
||||
} else {
|
||||
_, err = comm.Db.Insert(usr)
|
||||
}
|
||||
if err != nil {
|
||||
c.String(511, "服务错误!")
|
||||
return
|
||||
@ -88,6 +126,10 @@ func Install(c *gin.Context, req *ruisUtil.Map) {
|
||||
}
|
||||
|
||||
func Uppass(c *gin.Context, req *ruisUtil.Map) {
|
||||
if comm.NoUppass {
|
||||
c.String(511, "管理员禁止修改密码!")
|
||||
return
|
||||
}
|
||||
pass := req.GetString("pass")
|
||||
newpass := req.GetString("newpass")
|
||||
if pass == "" || newpass == "" {
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-dialog title="流水线编辑" :visible.sync="formVisible" :close-on-click-modal="false">
|
||||
<el-dialog title="流水线编辑" :visible.sync="formVisible" :close-on-click-modal="false" width="800px">
|
||||
<el-col :span="24" style="margin-bottom: 20px;">
|
||||
<el-form :model="formData" label-width="80px" :rules="formRules" ref="formd">
|
||||
<el-form-item label="项目名称" prop="Title">
|
||||
@ -8,11 +8,11 @@
|
||||
<el-form-item label="描述">
|
||||
<el-input type="textarea" v-model="formData.Desc" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="运行目录">
|
||||
<el-form-item label="工作目录">
|
||||
<el-input v-model="formData.Wrkdir" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="目录问题">
|
||||
<el-switch v-model="formData.clrdir" active-text="创建并清空运行目录"></el-switch>
|
||||
<el-form-item label="目录">
|
||||
<el-switch v-model="formData.clrdir" active-text="清空工作目录"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item label="环境变量">
|
||||
<el-input type="textarea" v-model="formData.Envs" auto-complete="off" :rows="8" placeholder="每行一个变量,格式:name=xxxx"></el-input>
|
||||
@ -53,7 +53,7 @@
|
||||
Desc: '',
|
||||
Envs:'',
|
||||
Wrkdir:'',
|
||||
clrdir:false
|
||||
clrdir:false,
|
||||
}
|
||||
if(e)
|
||||
this.formData={
|
||||
@ -62,7 +62,7 @@
|
||||
Desc: e.Desc,
|
||||
Envs:e.Envs,
|
||||
Wrkdir:e.Wrkdir,
|
||||
clrdir:e.Clrdir==1
|
||||
clrdir:e.Clrdir==1,
|
||||
}
|
||||
},/*handleSelect:function(id){
|
||||
this.tmpltCont='';
|
||||
|
Loading…
Reference in New Issue
Block a user