-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
99 lines (83 loc) · 2.57 KB
/
api.go
File metadata and controls
99 lines (83 loc) · 2.57 KB
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
package main
import (
"fmt"
"github.com/valyala/fasthttp"
"net"
"strconv"
)
var DefaultHeaderPassword = ""
var DefaultIpRestrict = ""
// Handlers part
func handle_limits(ctx *fasthttp.RequestCtx) {
if DefaultHeaderPassword != "" {
if string(ctx.Request.Header.Peek("X-Pass")) != DefaultHeaderPassword {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
ctx.SetBodyString("Unauthorized: Incorrect password")
return
}
}
if DefaultIpRestrict != "" {
if !ctx.RemoteIP().Equal(net.ParseIP(DefaultIpRestrict)) {
ctx.SetStatusCode(fasthttp.StatusForbidden)
ctx.SetBodyString("Forbidden: Access is restricted")
return
}
}
// Continue with the rest of your handler if the checks pass.
}
var request_handler = func(ctx *fasthttp.RequestCtx) {
handle_limits(ctx)
if ctx.Response.StatusCode() != fasthttp.StatusOK {
// The handle_limits function has already set the response, so we just return.
return
}
ctx.SetContentType("application/json")
switch string(ctx.Path()) {
case "/system/status":
handel_get_system_status(ctx)
case "/system/memory":
handel_get_system_mem(ctx)
case "/system/disks":
handel_get_system_disk(ctx)
case "/network/traffic/per_second":
handel_get_per_second(ctx)
case "/network/traffic/graph":
handel_get_graph(ctx)
case "/network/traffic/live_graph":
handel_live_graph(ctx)
case "/network/interface_list":
handel_get_interface_list(ctx)
case "/network/connections":
handel_get_connections(ctx)
case "/network/incoming/bytes":
handel_get_income_bytes(ctx)
case "/network/incoming/packets":
handel_get_income_packets(ctx)
case "/network/incoming/errors":
handel_get_income_erros(ctx)
case "/network/incoming/dropped":
handel_get_income_dropped(ctx)
case "/network/outgoing/bytes":
handel_get_outgo_bytes(ctx)
case "/network/outgoing/packets":
handel_get_outgo_packets(ctx)
case "/network/outgoing/errors":
handel_get_outgo_erros(ctx)
case "/network/outgoing/dropped":
handel_get_outgo_dropped(ctx)
default:
ctx.Error("nothing here, *- check https://github.com/aDarkDev", fasthttp.StatusNotFound)
}
statusCode := ctx.Response.StatusCode()
status_res := ""
if statusCode == 200{
status_res = "\033[92m200\033[0m"
}else{
status_res = "\033[91m"+strconv.Itoa(statusCode)+"\033[0m"
}
ctx.Response.Header.SetServer("SysSpecter/aDarkDev")
fmt.Println("[+] " + ctx.RemoteIP().To4().String() + " \033[96m" + string(ctx.Method()) + "\033[0m " + string(ctx.URI().RequestURI()) + " - " + status_res)
}
func Run(host string, port int) {
fasthttp.ListenAndServe(host+":"+strconv.Itoa(port), request_handler)
}