-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (55 loc) · 1.64 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
package main
import (
"fmt"
"os"
"os/signal"
"context"
"syscall"
"path/filepath"
redis "github.com/redis/go-redis/v9"
logger "github.com/0187773933/FireC2Server/v1/logger"
utils "github.com/0187773933/FireC2Server/v1/utils"
types "github.com/0187773933/FireC2Server/v1/types"
server "github.com/0187773933/FireC2Server/v1/server"
)
var s server.Server
var DB *redis.Client
func SetupCloseHandler() {
c := make( chan os.Signal )
signal.Notify( c , os.Interrupt , syscall.SIGTERM , syscall.SIGINT )
go func() {
<-c
// logger.Log.Println( "\r- Ctrl+C pressed in Terminal" )
fmt.Println( "\r" )
logger.Log.Println( "Ctrl+C pressed in Terminal" )
logger.Log.Printf( "Shutting Down %s Server" , s.Config.ServerName )
DB.Close()
s.FiberApp.Shutdown()
os.Exit( 0 )
}()
}
// https://pkg.go.dev/github.com/redis/go-redis/v9#Options
func SetupDB( config *types.ConfigFile ) {
DB = redis.NewClient( &redis.Options{
Addr: config.RedisAddress ,
Password: config.RedisPassword ,
DB: config.RedisDBNumber ,
})
var ctx = context.Background()
ping_result , err := DB.Ping( ctx ).Result()
logger.Log.Printf( "DB Connected : PING = %s" , ping_result )
if err != nil { panic( err ) }
}
func main() {
defer utils.SetupStackTraceReport()
config_file_path := "./config.yaml"
if len( os.Args ) > 1 { config_file_path , _ = filepath.Abs( os.Args[ 1 ] ) }
config := utils.ParseConfig( config_file_path )
SetupCloseHandler()
SetupDB( &config )
// utils.GenerateNewKeys()
utils.WriteLoginURLPrefix( config.ServerLoginUrlPrefix )
s = server.New( DB , config )
logger.Log.Printf( "Loaded Config File From : %s" , config_file_path )
s.Start()
}