feat(sys): add self-check functionality for system settings and frpc binary
This commit is contained in:
+14
-14
@@ -499,16 +499,16 @@ func getNumFromMap(m map[string]interface{}, key string) int {
|
||||
}
|
||||
|
||||
func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
userID, err := utils.Auth(w, r, http.MethodGet)
|
||||
userID, err := utils.Auth(w, r, http.MethodGet, "superuser", "admin")
|
||||
if err != nil {
|
||||
utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||
postLog.Warning(fmt.Sprintf("[ListInstancesHandler] Auth failed: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
instances, err := GetUserInstances(userID)
|
||||
instances, err := database.DBListFrpcInstances()
|
||||
if err != nil {
|
||||
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get user instances: %v", err))
|
||||
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get all instances: %v", err))
|
||||
utils.SendErrorResponse(w, http.StatusInternalServerError, "Failed to get instances")
|
||||
return
|
||||
}
|
||||
@@ -650,14 +650,14 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !watchdog.AddInstance(sysName) {
|
||||
postLog.Warning(fmt.Sprintf("[StartInstanceHandler] Failed to add watchdog instance %s", sysName))
|
||||
utils.SendSuccessResponse(w, "Instance started successfully but watchdog instance add failed", map[string]interface{}{
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
})
|
||||
return
|
||||
} else {
|
||||
utils.SendSuccessResponse(w, "Instance started successfully", map[string]interface{}{
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -767,13 +767,13 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !watchdog.RemoveInstance(sysName) {
|
||||
postLog.Warning(fmt.Sprintf("[StopInstanceHandler] Failed to remove watchdog instance %s", sysName))
|
||||
utils.SendSuccessResponse(w, "Instance stopped successfully but watchdog instance remove failed", map[string]interface{}{
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
})
|
||||
} else {
|
||||
utils.SendSuccessResponse(w, "Instance stopped successfully", map[string]interface{}{
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -883,8 +883,8 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
utils.SendSuccessResponse(w, "Instance restarted successfully", map[string]interface{}{
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
"instanceID": instanceID,
|
||||
"sysName": sysName,
|
||||
})
|
||||
postLog.Info(fmt.Sprintf("[RestartInstanceHandler] Instance %d restarted successfully", instanceID))
|
||||
}
|
||||
@@ -1005,7 +1005,7 @@ func GetInstanceInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
response := map[string]interface{}{
|
||||
"name": instance.Name,
|
||||
"sysName": sysName,
|
||||
"sysName": sysName,
|
||||
"createdAt": instance.CreatedAt.Format(time.RFC3339),
|
||||
"createdBy": instance.CreatedBy,
|
||||
"isRunning": isRunning,
|
||||
|
||||
Reference in New Issue
Block a user