fix: making sure all users can access all functions of all instances

This commit is contained in:
2026-05-08 14:16:20 +08:00
parent a78e715293
commit 898b67a24b
3 changed files with 36 additions and 32 deletions
+21 -18
View File
@@ -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 {