Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-21 13:12:46 +02:00
committed by GitHub
parent c31e86ed0c
commit db484a637b
2 changed files with 101 additions and 15 deletions
+38 -15
View File
@@ -72,7 +72,7 @@
</div> </div>
<h2 class="text-xl font-bold text-gray-800 mb-2">OSTicket</h2> <h2 class="text-xl font-bold text-gray-800 mb-2">OSTicket</h2>
<p class="text-gray-600 mb-4">Systém technické podpory a hlášení problémů</p> <p class="text-gray-600 mb-4">Systém technické podpory a hlášení problémů</p>
<a href="#" class="block text-center bg-orange-600 hover:bg-orange-700 text-white font-medium py-2 px-4 rounded-lg transition-colors"> <a href="http://osticket/" class="block text-center bg-orange-600 hover:bg-orange-700 text-white font-medium py-2 px-4 rounded-lg transition-colors">
Otevřít aplikaci Otevřít aplikaci
</a> </a>
</div> </div>
@@ -82,9 +82,9 @@
<div class="rounded-full w-14 h-14 flex items-center justify-center bg-purple-100 text-purple-600 mb-4"> <div class="rounded-full w-14 h-14 flex items-center justify-center bg-purple-100 text-purple-600 mb-4">
<i class="fas fa-tasks text-2xl"></i> <i class="fas fa-tasks text-2xl"></i>
</div> </div>
<h2 class="text-xl font-bold text-gray-800 mb-2">Canboard úkolníček</h2> <h2 class="text-xl font-bold text-gray-800 mb-2">Kanboard úkolníček</h2>
<p class="text-gray-600 mb-4">Správa úkolů a projektů v přehledném kanban stylu</p> <p class="text-gray-600 mb-4">Správa úkolů a projektů v přehledném kanban stylu</p>
<a href="#" class="block text-center bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-lg transition-colors"> <a href="http://kanboard/" class="block text-center bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-lg transition-colors">
Otevřít aplikaci Otevřít aplikaci
</a> </a>
</div> </div>
@@ -185,20 +185,43 @@
}); });
}); });
// Function to open Windows Explorer with a specific path // Function to open Windows folders via Go server
function openWindowsFolder(path) { function openWindowsFolder(path) {
// Using ActiveX to open Windows Explorer (works in IE) // Show loading indicator or disable button
try { const allButtons = document.querySelectorAll('button');
const shell = new ActiveXObject("Shell.Application"); allButtons.forEach(button => {
shell.Explore(path); if (button.innerHTML.includes('Otevřít složku')) {
return; button.disabled = true;
} catch (e) { }
console.log("ActiveX not supported or disabled"); });
}
// Fallback to file:// protocol // Make API call to our Go endpoint
const encodedPath = path.split('\\').map(part => encodeURIComponent(part)).join('/'); fetch('/open-folder', {
window.open('file:///' + encodedPath, '_blank'); 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;
});
});
} }
</script> </script>
</body> </body>
+63
View File
@@ -8,6 +8,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@@ -50,6 +51,8 @@ func main() {
http.ServeFile(w, r, "evidence-aut.html") http.ServeFile(w, r, "evidence-aut.html")
})) }))
http.HandleFunc("/open-folder", enableCORS(handleOpenFolder))
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port == "" { if port == "" {
port = "8080" 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"}`)) 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 { func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error {
smtpHost := "mail.pp-kunovice.cz" smtpHost := "mail.pp-kunovice.cz"
smtpPort := 465 smtpPort := 465