forked from 0xDkd/auxpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
128 lines (119 loc) · 3.86 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"auxpi/auxpiAll"
"auxpi/bootstrap"
"auxpi/controllers"
"auxpi/models"
_ "auxpi/routers"
"auxpi/utils"
"flag"
"fmt"
"os"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
func main() {
args := os.Args
p := "\033[32m"
s := "\033[0m"
if len(args) <= 1 {
err := logs.SetLogger(logs.AdapterFile, `{"filename":"auxpi.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
if err != nil {
beego.Alert(err)
}
beego.BConfig.ServerName = "Auxpi-Server-2.0"
//不可修改静态服务器,请不要修改,否则将影响后台图片显示
beego.SetStaticPath("/backup", bootstrap.SiteConfig.SiteUploadWay.LocalStore.StorageLocation)
//自定义静态服务器
beego.SetStaticPath(bootstrap.SiteConfig.SiteUploadWay.LocalStore.Link, bootstrap.SiteConfig.SiteUploadWay.LocalStore.StorageLocation)
//SessionID 重写
beego.BConfig.WebConfig.Session.SessionName = "PHPSESSION"
//ERROR 自定义
beego.ErrorController(&controllers.ErrorController{})
beego.Run()
} else {
switch args[1] {
case "init":
if _, err := os.Stat("conf/install.lock"); err == nil {
fmt.Println(p + "[INFO]:AUXPI have already initialization complete.\r\n[INFO]:Please run \"./auxpi run\" to start " + s)
return
}
//初始化格式
formatData()
//日志文件
msg := p + `[SUCCESS]:Init completed ! ` + "\r" + `[INFO]:Please edit "conf/siteConfig" to make auxpi can connect to database` + s
fmt.Println(msg)
case "run":
err := logs.SetLogger(logs.AdapterFile, `{"filename":"auxpi.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
if err != nil {
beego.Alert(err)
}
beego.BConfig.ServerName = "Auxpi-Server-2.0"
//不可修改静态服务器,请不要修改,否则将影响后台图片显示
beego.SetStaticPath("/backup", bootstrap.SiteConfig.SiteUploadWay.LocalStore.StorageLocation)
//自定义静态服务器
beego.SetStaticPath(bootstrap.SiteConfig.SiteUploadWay.LocalStore.Link, bootstrap.SiteConfig.SiteUploadWay.LocalStore.StorageLocation)
//SessionID 重写
beego.BConfig.WebConfig.Session.SessionName = "PHPSESSION"
//ERROR 自定义
beego.ErrorController(&controllers.ErrorController{})
beego.Run()
case "migrate":
var errs = make([]error, 8, 10)
errs[0] = models.MigrateImages()
errs[1] = models.MigrateSyncImage()
errs[2] = models.MigrateStores()
errs[3] = models.MigrateUsers()
errs[4] = models.MigrateRole()
errs[5] = models.MigratePermissions()
errs[6] = models.MigrateOptions()
errs[7] = models.MigrateLogs()
models.CreateAdminRole()
for _, err := range errs {
if err != nil {
fmt.Println("[ERROR]:" + auxpi.ErrorToString(err))
return
}
}
fmt.Println(p + "[SUCCESS]: Database migrate Done" + s)
}
}
}
func formatData() {
bootstrap.FormatSoftLink(&bootstrap.SiteConfig.SiteUploadWay.LocalStore.Link)
bootstrap.FormatStoreLocation(&bootstrap.SiteConfig.SiteUploadWay.LocalStore.StorageLocation)
//强制重载配置,防止用户填入的数据不规范
bootstrap.ReGenerate()
}
func logo() {
b, err := bootstrap.Asset("views/logo/index.tpl")
if err != nil {
return
}
p := "\033[34m"
s := "\033[0m"
fmt.Println(p + string(b) + s)
}
func init() {
logo()
var (
mod string
user string
pass string
email string
)
flag.StringVar(&user, "name", "auxpi-admin", "Admin UserName")
flag.StringVar(&pass, "pass", "admin-pass", "Admin PassWord")
flag.StringVar(&email, "email", "[email protected]", "Admin Email")
flag.StringVar(&mod,"mod","","Choose Module")
flag.Parse()
t := utils.GetSha256CodeWithSalt("auxpiauxpi")
if mod == "admin" {
if u, _ := models.GetUserInfoByID(1); u.ID > 0 {
fmt.Println("\033[31m[ERROR]:Admin Is Existed\033[0m")
return
}
models.RegisterAdmin(user, utils.GetSha256CodeWithSalt(pass), t, email)
fmt.Println("\033[32m[SUCCESS]:Create Admin SUCCESS\033[0m")
}
}