53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package sys
|
|
|
|
import (
|
|
"net/http"
|
|
"fmt"
|
|
"super-frpc/global"
|
|
"super-frpc/utils"
|
|
"super-frpc/postLog"
|
|
)
|
|
|
|
func SelfCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
userID, err := utils.Auth(w, r, http.MethodGet, "visitor", "superuser", "admin")
|
|
if err != nil {
|
|
utils.SendErrorResponse(w, http.StatusUnauthorized, "invalid token or timestamp")
|
|
postLog.Warning(fmt.Sprintf("[SelfCheckHandler] Auth failed: %v, userID: %d", err, userID))
|
|
return
|
|
}
|
|
err = SettingsSelfCheck()
|
|
if err != nil {
|
|
utils.SendErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
err = FrpBinaryCheck()
|
|
if err != nil {
|
|
utils.SendErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
utils.SendSuccessResponse(w, "Self check passed", nil)
|
|
postLog.Info(fmt.Sprintf("[SelfCheckHandler] [%d] Self check passed", userID))
|
|
}
|
|
|
|
func SettingsSelfCheck() error {
|
|
if global.CurrentConfig.ListenAddr == "" {
|
|
return fmt.Errorf("listenAddr is not set")
|
|
}
|
|
if global.CurrentConfig.ListenPort == "0" {
|
|
return fmt.Errorf("listenPort is invalid")
|
|
}
|
|
if global.CurrentConfig.FrpcPath == "" {
|
|
return fmt.Errorf("frpcPath is not set")
|
|
}
|
|
if global.CurrentConfig.InstancePath == "" {
|
|
return fmt.Errorf("instancePath is not set")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func FrpBinaryCheck() error {
|
|
if !utils.IsFileExist(global.CurrentConfig.FrpcPath) {
|
|
return fmt.Errorf("frpc binary is not exist")
|
|
}
|
|
return nil
|
|
} |