diff --git a/index.html b/index.html index 63d4c20..745cc38 100644 --- a/index.html +++ b/index.html @@ -72,7 +72,7 @@

OSTicket

Systém technické podpory a hlášení problémů

- + Otevřít aplikaci @@ -82,9 +82,9 @@
-

Canboard úkolníček

+

Kanboard úkolníček

Správa úkolů a projektů v přehledném kanban stylu

- + Otevřít aplikaci @@ -185,20 +185,43 @@ }); }); - // Function to open Windows Explorer with a specific path + // Function to open Windows folders via Go server function openWindowsFolder(path) { - // Using ActiveX to open Windows Explorer (works in IE) - try { - const shell = new ActiveXObject("Shell.Application"); - shell.Explore(path); - return; - } catch (e) { - console.log("ActiveX not supported or disabled"); - } + // Show loading indicator or disable button + const allButtons = document.querySelectorAll('button'); + allButtons.forEach(button => { + if (button.innerHTML.includes('Otevřít složku')) { + button.disabled = true; + } + }); - // Fallback to file:// protocol - const encodedPath = path.split('\\').map(part => encodeURIComponent(part)).join('/'); - window.open('file:///' + encodedPath, '_blank'); + // Make API call to our Go endpoint + fetch('/open-folder', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ path: path }) + }) + .then(response => response.json()) + .then(data => { + if (data.error) { + console.error('Chyba při otevírání složky:', data.error); + alert('Chyba při otevírání složky: ' + data.error); + } else { + console.log('Složka úspěšně otevřena'); + } + }) + .catch(error => { + console.error('Chyba při komunikaci se serverem:', error); + alert('Chyba při komunikaci se serverem. Zkuste to prosím později.'); + }) + .finally(() => { + // Re-enable buttons + allButtons.forEach(button => { + button.disabled = false; + }); + }); } diff --git a/main.go b/main.go index 89102d1..a3bef21 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "log" "net/http" "os" + "os/exec" "strings" "time" @@ -50,6 +51,8 @@ func main() { http.ServeFile(w, r, "evidence-aut.html") })) + http.HandleFunc("/open-folder", enableCORS(handleOpenFolder)) + port := os.Getenv("PORT") if port == "" { port = "8080" @@ -156,6 +159,66 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"message":"Záznam byl úspěšně uložen a email odeslán"}`)) } +// 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 { + w.WriteHeader(http.StatusOK) + return + } + w.WriteHeader(http.StatusMethodNotAllowed) + 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 { + log.Printf("Chyba při čtení těla požadavku: %v", err) + w.WriteHeader(http.StatusBadRequest) + 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:\\") { + 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 { + log.Printf("Chyba při spouštění explorer.exe: %v", err) + w.WriteHeader(http.StatusInternalServerError) + 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"}) +} + func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error { smtpHost := "mail.pp-kunovice.cz" smtpPort := 465