mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 04:22:58 +00:00
Add files via upload
This commit is contained in:
@@ -162,7 +162,7 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
||||
// handleOpenFolder opens a Windows Explorer window to the specified folder path
|
||||
func handleOpenFolder(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
|
||||
// Only allow POST requests
|
||||
if r.Method != http.MethodPost {
|
||||
if r.Method == http.MethodOptions {
|
||||
@@ -173,12 +173,12 @@ func handleOpenFolder(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Only POST method is allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Parse the request body
|
||||
type FolderRequest struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
|
||||
var req FolderRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
@@ -187,25 +187,25 @@ func handleOpenFolder(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to parse request body"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Validate the folder path
|
||||
if req.Path == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Path is required"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Sanitize the path (basic security - you might want to add more validation)
|
||||
// Ensure it's a valid Windows network path
|
||||
if !strings.HasPrefix(req.Path, "M:\\") {
|
||||
if !strings.HasPrefix(req.Path, "C:\\") {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Only network paths on M: drive are allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Construct the command to open Windows Explorer
|
||||
cmd := exec.Command("explorer.exe", req.Path)
|
||||
|
||||
|
||||
// Run the command
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
@@ -214,7 +214,7 @@ func handleOpenFolder(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": fmt.Sprintf("Failed to open folder: %v", err)})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Send a success response
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "success", "message": "Folder opened successfully"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user