123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- "net/http"
- "os"
- "os/signal"
- "syscall"
- "time"
- "github.com/google/uuid"
- "github.com/gorilla/csrf"
- "imuslab.com/zoraxy/mod/geodb"
- "imuslab.com/zoraxy/mod/update"
- "imuslab.com/zoraxy/mod/utils"
- )
- func SetupCloseHandler() {
- c := make(chan os.Signal, 2)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- ShutdownSeq()
- os.Exit(0)
- }()
- }
- func main() {
-
- flag.Parse()
-
- if *showver {
- fmt.Println(SYSTEM_NAME + " - Version " + SYSTEM_VERSION)
- os.Exit(0)
- }
- if *geoDbUpdate {
- geodb.DownloadGeoDBUpdate("./conf/geodb")
- os.Exit(0)
- }
-
- if !utils.ValidateListeningAddress(*webUIPort) {
- fmt.Println("Malformed -port (listening address) paramter. Do you mean -port=:" + *webUIPort + "?")
- os.Exit(0)
- }
- if *enableAutoUpdate {
- fmt.Println("Checking required config update")
- update.RunConfigUpdate(0, update.GetVersionIntFromVersionNumber(SYSTEM_VERSION))
- }
- SetupCloseHandler()
-
- uuidRecord := *path_uuid
- if !utils.FileExists(uuidRecord) {
- newSystemUUID := uuid.New().String()
- os.WriteFile(uuidRecord, []byte(newSystemUUID), 0775)
- }
- uuidBytes, err := os.ReadFile(uuidRecord)
- if err != nil {
- SystemWideLogger.PrintAndLog("ZeroTier", "Unable to read system uuid from file system", nil)
- panic(err)
- }
- nodeUUID = string(uuidBytes)
-
- webminPanelMux = http.NewServeMux()
- csrfMiddleware = csrf.Protect(
- []byte(nodeUUID),
- csrf.CookieName(CSRF_COOKIENAME),
- csrf.Secure(false),
- csrf.Path("/"),
- csrf.SameSite(csrf.SameSiteLaxMode),
- )
-
- startupSequence()
-
- requireAuth = !(*noauth)
- initAPIs(webminPanelMux)
-
- go func() {
- ReverseProxtInit()
- }()
- time.Sleep(500 * time.Millisecond)
-
- finalSequence()
- SystemWideLogger.Println(SYSTEM_NAME + " started. Visit control panel at http://localhost" + *webUIPort)
- err = http.ListenAndServe(*webUIPort, csrfMiddleware(webminPanelMux))
- if err != nil {
- log.Fatal(err)
- }
- }
|