From 898b67a24bf2fec234c92f58f2dec3acfe01c1d6 Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Fri, 8 May 2026 14:16:20 +0800 Subject: [PATCH] fix: making sure all users can access all functions of all instances --- frpLogger/handler.go | 10 +++++----- handlers/instance.go | 19 ++++++++++--------- handlers/proxy.go | 39 +++++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/frpLogger/handler.go b/frpLogger/handler.go index 46405a3..d112eee 100644 --- a/frpLogger/handler.go +++ b/frpLogger/handler.go @@ -59,16 +59,16 @@ func (h *LogSocketHandler) Handle(w http.ResponseWriter, r *http.Request) { return } - instance, err := DBQueryFrpcInstanceByID(instanceID) + _, err = DBQueryFrpcInstanceByID(instanceID) if err != nil { SendHTTPError(w, http.StatusNotFound, "Instance not found") return } - if instance.UserID != userID { - SendHTTPError(w, http.StatusForbidden, "You don't have access to this instance") - return - } + // if instance.UserID != userID { + // SendHTTPError(w, http.StatusForbidden, "You don't have access to this instance") + // return + // } serviceName, err := GetServiceNameByInstanceID(instanceID) if err != nil { diff --git a/handlers/instance.go b/handlers/instance.go index 1d833ed..ec0b6a1 100644 --- a/handlers/instance.go +++ b/handlers/instance.go @@ -537,7 +537,7 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - // instance, err := database.DBQueryFrpcInstanceByID(instanceID) + _, err = database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start a not existed instance: %d", userID, instanceID)) @@ -665,7 +665,7 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - // instance, err := database.DBQueryFrpcInstanceByID(instanceID) + _, err = database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop a not existed instance: %d", userID, instanceID)) @@ -781,7 +781,7 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - // instance, err := database.DBQueryFrpcInstanceByID(instanceID) + _, err = database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart a not existed instance: %d", userID, instanceID)) @@ -855,7 +855,7 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) { } func GetInstanceStatusHandler(w http.ResponseWriter, r *http.Request) { - userID, err := utils.Auth(w, r, http.MethodGet) + _, err := utils.Auth(w, r, http.MethodGet) if err != nil { utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error()) postLog.Warning(fmt.Sprintf("[GetInstanceStatusHandler] Auth failed: %v", err)) @@ -875,7 +875,7 @@ func GetInstanceStatusHandler(w http.ResponseWriter, r *http.Request) { return } - instance, err := database.DBQueryFrpcInstanceByID(instanceID) + _, err = database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") return @@ -886,10 +886,11 @@ func GetInstanceStatusHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") - return - } + // Check if the instance belongs to the user + // if instance.UserID != userID { + // utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") + // return + // } err = sys.IsInstanceRunning(instanceID) isRunning := err == nil diff --git a/handlers/proxy.go b/handlers/proxy.go index 5762105..2a24ede 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -17,7 +17,7 @@ import ( ) func CreateProxyHandler(w http.ResponseWriter, r *http.Request) { - userID, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") + _, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") if err != nil { utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error()) postLog.Warning(fmt.Sprintf("[CreateProxyHandler] Auth failed: %v", err)) @@ -77,11 +77,12 @@ func CreateProxyHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - postLog.Error(fmt.Sprintf("[CreateProxyHandler] Instance not found for user %d", userID)) - utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") - return - } + // Check if the instance belongs to the user + // if instance.UserID != userID { + // postLog.Error(fmt.Sprintf("[CreateProxyHandler] Instance not found for user %d", userID)) + // utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") + // return + // } configContent, err := os.ReadFile(instance.ConfigPath) if err != nil { @@ -112,7 +113,7 @@ func CreateProxyHandler(w http.ResponseWriter, r *http.Request) { } func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) { - userID, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") + _, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") if err != nil { utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error()) postLog.Warning(fmt.Sprintf("[ModifyProxyHandler] Auth failed: %v", err)) @@ -180,11 +181,12 @@ func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - postLog.Error(fmt.Sprintf("[ModifyProxyHandler] Instance not found for user %d", userID)) - utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") - return - } + // Check if the instance belongs to the user + // if instance.UserID != userID { + // postLog.Error(fmt.Sprintf("[ModifyProxyHandler] Instance not found for user %d", userID)) + // utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") + // return + // } configContent, err := os.ReadFile(instance.ConfigPath) if err != nil { @@ -215,7 +217,7 @@ func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) { } func DeleteProxyHandler(w http.ResponseWriter, r *http.Request) { - userID, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") + _, err := utils.Auth(w, r, http.MethodPost, "superuser", "admin") if err != nil { utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error()) postLog.Warning(fmt.Sprintf("[DeleteProxyHandler] Auth failed: %v", err)) @@ -260,11 +262,12 @@ func DeleteProxyHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - postLog.Error(fmt.Sprintf("[DeleteProxyHandler] Instance not found for user %d", userID)) - utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") - return - } + // Check if the instance belongs to the user + // if instance.UserID != userID { + // postLog.Error(fmt.Sprintf("[DeleteProxyHandler] Instance not found for user %d", userID)) + // utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") + // return + // } configContent, err := os.ReadFile(instance.ConfigPath) if err != nil {