-
Notifications
You must be signed in to change notification settings - Fork 12
/
xray_projects.go
71 lines (62 loc) · 1.84 KB
/
xray_projects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"errors"
"github.com/jinzhu/gorm"
)
// Project - 被动扫描项目
type Project struct {
gorm.Model
Name string `gorm:"type:varchar(100);unique_index" json:"name"`
Domain string `json:"domain"` // xxx,xxx,xxx
Config string `json:"config"` // config_{name}.yaml
Plugins string `json:"plugins"`
Reverse string `json:"reverse"` // ???
Listen int `json:"listen"` // Listen Port
ProcessID int `json:"process_id"`
// Worked bool
}
func updateProjectPidAndListenPort(id uint, pid, port int) (out Project, err error) {
if conn.First(&out, Project{Model: gorm.Model{ID: id}}).RecordNotFound() {
return out, errors.New("record is not found")
}
if err := conn.Model(&out).Updates(map[string]interface{}{
"process_id": pid, "listen": port,
}).Error; err != nil {
return out, err
}
return out, nil
}
func newProject(p Project) (out Project, err error) {
if !conn.First(&out, Project{Name: p.Name}).RecordNotFound() {
return out, errors.New("record is exists")
}
if err = conn.Create(&p).Error; err != nil {
return p, err
}
return p, nil
}
func findProjects(limit, offset int) (outs []*Project, err error) {
if conn.Limit(limit).Offset(offset).Order("id desc").Find(&outs).RecordNotFound() {
return outs, errors.New("record not found")
}
return outs, nil
}
func getProjectsCount() (count int) {
var err error
if err = conn.Model(&Project{}).Count(&count).Error; err != nil {
return -1
}
return count
}
func findProjectByID(id uint) (out Project, err error) {
if conn.First(&out, Project{Model: gorm.Model{ID: id}}).RecordNotFound() {
return out, errors.New("record not found")
}
return out, nil
}
func findProjectByName(name string) (out Project, err error) {
if conn.First(&out, Project{Name: name}).RecordNotFound() {
return out, errors.New("record not found")
}
return out, nil
}