Skip to content

Commit 088fa74

Browse files
authored
Merge pull request #1 from yehux/dev
重新开始
2 parents 0a09037 + acaaa4b commit 088fa74

File tree

550 files changed

+146206
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

550 files changed

+146206
-2
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js linguist-language=Go
2+
*.css linguist-language=Go
3+
*.html linguist-language=Go

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
.idea
15+
vendor
16+
.DS_Store
17+
*/.DS_Store
18+
*/.idea/%
19+
*/vendor/%

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 野虎团队
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,93 @@
1-
# Coot
2-
玩转 IFTTT 体验极客生活,互联网自动化神器
1+
![help](./images/coot.png)
2+
3+
# 介绍
4+
5+
**Coot** 是一款 **IFTTT** 自动化神器,基于 **Golang** 开发让你体验不同的极客生活。
6+
7+
- **快速安装** 基于 **Golang** + **SqlLite** 开发,用户可在 **Linux****Mac** 上快速部署
8+
- **两种语言** 支持 **Python** + **Shell** 两种语言 让用户更多的选择
9+
- **插件库** 基于 **Github** 实现云插件库,用户无需编写代码直接使用
10+
11+
# 地址
12+
13+
- 官网:https://coot.io
14+
- Github:https://github.com/yehuio/Coot
15+
- 下载地址:https://github.com/yehuio/Coot/releases
16+
- 插件库地址:https://github.com/yehuio/Coot-Plugs
17+
18+
# 部署说明
19+
20+
> 下载软件到 **Linux** or **Mac**下解压
21+
22+
输入
23+
24+
```
25+
./coot help
26+
```
27+
28+
![help](./images/help.png)
29+
30+
运行
31+
32+
```
33+
./coot run
34+
35+
or
36+
37+
./coot run 0.0.0.0:9000
38+
```
39+
40+
![run](./images/run.png)
41+
42+
# 使用截图
43+
44+
![task](./images/task.png)
45+
![plug](./images/plug.png)
46+
47+
48+
# 注意事项
49+
50+
- 邮箱 **SMTP** 配置后需要开启方可使用
51+
- 创建任务需要开启邮箱通知填写接收邮箱(可写多个)
52+
- 编写脚本 输出结果 0&&测试 ,没有0&& 不会进行通知
53+
- 服务重启后,所有任务都会变成停止状态
54+
- 目前无登录功能,对互联网开放请自设置安全限制
55+
56+
# Todo
57+
58+
- [x] 任务中心
59+
- [x] 任务添加
60+
- [x] 任务删除
61+
- [x] 任务执行
62+
- [x] 任务暂停
63+
- [x] 支持 Shell+Python
64+
- [x] 支持 秒
65+
- [x] 支持 分钟
66+
- [x] 支持 小时
67+
- [x] 支持每天指定时间
68+
- [x] 支持每月指定时间
69+
- [x] 插件仓库
70+
- [x] 插件列表
71+
- [x] 插件使用
72+
- [x] 消息通知
73+
- [x] 仪表盘统计
74+
- [x] 日记记录
75+
- [x] 启动命令行
76+
- [x] 自定义 ip 端口
77+
- [x] 任务详情
78+
- [x] 任务修改
79+
- [x] 支持更多的通知方式
80+
- [x] 是否启用登录
81+
- [ ] 平台统计
82+
- [ ] 手机版本优化
83+
84+
# 关于
85+
86+
- 出品:野虎团队
87+
- URL:https://yehu.io
88+
89+
# 反馈群:
90+
91+
加微信拉人,请备注 **野虎**
92+
93+
![wechat](./images/wechat.jpg)

core/dbUtil/dbUtil.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package dbUtil
2+
3+
import (
4+
"database/sql"
5+
_ "github.com/mattn/go-sqlite3"
6+
"Coot/error"
7+
)
8+
9+
// 连接数据库
10+
func conn() *sql.DB {
11+
db, err := sql.Open("sqlite3", "./db/coot.db")
12+
error.Check(err, "连接数据库失败")
13+
return db
14+
}
15+
16+
// 插入数据
17+
func Insert(sql string, args ...interface{}) int64 {
18+
/*
19+
参数说明:
20+
21+
sql insert 语句
22+
args insert value 参数
23+
24+
使用案例:
25+
26+
sql := `
27+
INSERT INTO coot_tasks (
28+
task_name,
29+
task_explain,
30+
task_id,
31+
task_time_type,
32+
task_time,
33+
last_exec_time,
34+
is_plug_script,
35+
script_type,
36+
script_path,
37+
alert_type,
38+
create_time
39+
)
40+
VALUES
41+
(?,?,?,?,?,?,?,?,?,?,?);
42+
`
43+
dbUtil.Insert(sql, "插入任务测试", "测试说明", "", 1, "2", "", "1", "shell", "/scripts/myscript/test.sh", "1", "2019-07-10 16:12")
44+
*/
45+
db := conn()
46+
stmt, _ := db.Prepare(sql)
47+
48+
res, err := stmt.Exec(args...)
49+
error.Check(err, "插入数据失败")
50+
51+
defer stmt.Close()
52+
53+
id, err := res.LastInsertId()
54+
error.Check(err, "获取插入ID失败")
55+
56+
defer db.Close()
57+
58+
// 返回 自增长 ID
59+
return id
60+
}
61+
62+
// 更新数据
63+
func Update(sql string, args ...interface{}) int64 {
64+
/*
65+
参数说明:
66+
67+
sql update 语句
68+
args update 参数
69+
70+
使用案例:
71+
72+
sql := `
73+
UPDATE coot_tasks
74+
SET task_name = ?
75+
WHERE
76+
id = ?;
77+
`
78+
dbUtil.Update(sql, "任务更新测试", 1)
79+
*/
80+
db := conn()
81+
stmt, _ := db.Prepare(sql)
82+
83+
res, err := stmt.Exec(args...)
84+
85+
error.Check(err, "更新数据失败")
86+
defer stmt.Close()
87+
88+
affect, err := res.RowsAffected()
89+
error.Check(err, "获取影响行数失败")
90+
91+
defer db.Close()
92+
93+
return affect
94+
}
95+
96+
// 查询数据
97+
func Query(sql string, args ...interface{}) []map[string]interface{} {
98+
/*
99+
参数说明:
100+
101+
sql select 语句
102+
args select 参数
103+
104+
使用案例:
105+
106+
sql := `select * from coot_tasks where id=?;`
107+
result := dbUtil.Query(sql, 1)
108+
*/
109+
db := conn()
110+
111+
rows, err := db.Query(sql, args ...)
112+
error.Check(err, "查询数据失败")
113+
114+
defer rows.Close()
115+
116+
columns, err := rows.Columns()
117+
error.Check(err, "查询表名失败")
118+
119+
count := len(columns)
120+
121+
tableData := make([]map[string]interface{}, 0)
122+
values := make([]interface{}, count)
123+
valuePtrs := make([]interface{}, count)
124+
125+
for rows.Next() {
126+
for i := 0; i < count; i++ {
127+
valuePtrs[i] = &values[i]
128+
}
129+
rows.Scan(valuePtrs...)
130+
entry := make(map[string]interface{})
131+
for i, col := range columns {
132+
var v interface{}
133+
val := values[i]
134+
b, ok := val.([]byte)
135+
if ok {
136+
v = string(b)
137+
} else {
138+
v = val
139+
}
140+
entry[col] = v
141+
}
142+
tableData = append(tableData, entry)
143+
}
144+
145+
defer db.Close()
146+
147+
return tableData
148+
}
149+
150+
// 删除数据
151+
func Delete(sql string, args ...interface{}) int64 {
152+
/*
153+
参数说明:
154+
155+
sql delete 语句
156+
args delete 参数
157+
158+
使用案例:
159+
160+
sql := `delete from coot_tasks where id=?;`
161+
dbUtil.Delete(sql, 2)
162+
*/
163+
db := conn()
164+
165+
stmt, _ := db.Prepare(sql)
166+
167+
res, err := stmt.Exec(args...)
168+
error.Check(err, "删除数据失败")
169+
defer stmt.Close()
170+
171+
affect, err := res.RowsAffected()
172+
error.Check(err, "获取影响行数失败")
173+
174+
defer db.Close()
175+
176+
return affect
177+
}

core/exec/exec.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package exec
2+
3+
import (
4+
"bytes"
5+
"os/exec"
6+
)
7+
8+
func Execute(shell string) (string, error) {
9+
cmd := exec.Command("/bin/bash", "-c", shell)
10+
var out bytes.Buffer
11+
12+
cmd.Stdout = &out
13+
err := cmd.Run()
14+
if err != nil {
15+
return "", err
16+
}
17+
return out.String(), nil
18+
}

0 commit comments

Comments
 (0)