fix: making sure all users can access all functions of all instances
This commit is contained in:
+10
-9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user