-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
144 lines (114 loc) · 2.87 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"log"
"os"
rice "github.com/GeertJohan/go.rice"
"github.com/bitcav/nitr/cmd"
db "github.com/bitcav/nitr/database"
"github.com/bitcav/nitr/handlers"
"github.com/bitcav/nitr/utils"
"github.com/kardianos/service"
"github.com/gofiber/embed"
"github.com/gofiber/fiber"
"github.com/gofiber/recover"
"github.com/gofiber/websocket"
)
func server() {
//Set Config.ini Default Values
utils.ConfigFileSetup()
//Set API Server default Data
db.SetAPIData()
//App Config
app := fiber.New(&fiber.Settings{
DisableStartupMessage: true,
})
//In Memory Static Assets
app.Use("/assets", embed.New(embed.Config{
Root: rice.MustFindBox("app/assets").HTTPBox(),
}))
//Checks if logs saving is activated
utils.Logs(app)
app.Use(recover.New(recover.Config{
Handler: handlers.Recover,
}))
//API Config
api := app.Group("/api")
v1 := api.Group("/v1")
//API Key auth middleware
v1.Use(handlers.AuthAPI)
//nitr API Endpoints
v1.Get("/", handlers.Overview)
v1.Get("/cpu", handlers.CPU)
v1.Get("/bios", handlers.Bios)
v1.Get("/bandwidth", handlers.Bandwidth)
v1.Get("/chassis", handlers.Chassis)
v1.Get("/disks", handlers.Disk)
v1.Get("/drives", handlers.Drive)
v1.Get("/devices", handlers.Devices)
v1.Get("/gpu", handlers.GPU)
v1.Get("/host", handlers.Host)
v1.Get("/isp", handlers.ISP)
v1.Get("/network", handlers.Network)
v1.Get("/processes", handlers.Process)
v1.Get("/ram", handlers.RAM)
v1.Get("/baseboard", handlers.Baseboard)
v1.Get("/product", handlers.Product)
v1.Get("/memory", handlers.Memory)
//Login View
handlers.ViewsBox = rice.MustFindBox("app/views")
app.Get("/", handlers.Login)
//Login Submit
app.Post("/", handlers.LoginSubmit)
//Auth middleware
app.Use(handlers.Auth)
//Panel View
app.Get("/panel", handlers.Panel)
//Panel JSON Data
app.Get("/content", handlers.PanelContent)
//Panel Logout
app.Post("/logout", handlers.Logout)
//Generate new API Key
app.Post("/generate", handlers.GenerateApiKey)
//Change Password View
app.Get("/password", handlers.Password)
//New Password Submit
app.Post("/password", handlers.PasswordSubmit)
app.Get("/status", websocket.New(handlers.SocketReader))
//Server startup
utils.StartServer(app)
}
type program struct{}
var logger service.Logger
func (p *program) Start(s service.Service) error {
go p.run()
return nil
}
func (p *program) run() {
server()
}
func (p *program) Stop(s service.Service) error {
return nil
}
func main() {
if len(os.Args) > 1 {
cmd.Execute()
return
}
svcConfig := &service.Config{
Name: "NitrService",
Description: "A Remote Monitoring Tool for system information gathering, making it available through a JSON API.",
}
prg := &program{}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
logger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
err = s.Run()
if err != nil {
logger.Error(err)
}
}