Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-21 09:10:43 +02:00
committed by GitHub
parent 933e2c5a45
commit af5e92d817
4 changed files with 330 additions and 123 deletions
+68
View File
@@ -0,0 +1,68 @@
package main
import (
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)
func main() {
// Set up HTTP server
http.HandleFunc("/open", openFolderHandler)
// Start server on port 8080
fmt.Println("Folder opener server running on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func openFolderHandler(w http.ResponseWriter, r *http.Request) {
// Set CORS headers to allow requests from any origin
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
// Handle preflight OPTIONS request
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
// Only allow GET requests
if r.Method != "GET" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
// Get the folder path from the query parameter
folderPath := r.URL.Query().Get("path")
if folderPath == "" {
http.Error(w, "Missing path parameter", http.StatusBadRequest)
return
}
// Log the request
fmt.Printf("Opening folder: %s\n", folderPath)
// Open the folder in Windows Explorer
// The /select flag opens Explorer with the specified folder selected
cmd := exec.Command("explorer.exe", folderPath)
err := cmd.Start()
if err != nil {
// If there was an error, try to clean the path and retry
cleanPath := strings.ReplaceAll(folderPath, "/", "\\")
cmd = exec.Command("explorer.exe", cleanPath)
err = cmd.Start()
if err != nil {
http.Error(w, fmt.Sprintf("Error opening folder: %v", err), http.StatusInternalServerError)
return
}
}
// Return success response
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Opening folder: %s", folderPath)
}
+4
View File
@@ -0,0 +1,4 @@
@echo off
echo Starting Folder Opener Server...
cd %~dp0
go run main.go
+89 -7
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,18 +82,82 @@
<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</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>
</div>
<!-- Separator with heading -->
<div class="my-10 text-center">
<div class="relative">
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-gray-300"></div>
</div>
<div class="relative flex justify-center">
<span class="bg-gray-100 px-4 text-sm text-gray-500">WINDOWS SDÍLENÉ SLOŽKY</span>
</div>
</div>
</div>
<!-- Windows Folders Grid - smaller and more subtle cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- 1. Telefonní seznam -->
<div class="card bg-white rounded-lg shadow-sm p-4 border border-gray-200" data-name="telefonní seznam telefony kontakty">
<div class="flex items-center">
<div class="rounded-full w-10 h-10 flex items-center justify-center bg-gray-100 text-gray-600 mr-3">
<i class="fas fa-phone-alt"></i>
</div>
<div class="flex-1">
<h3 class="text-md font-medium text-gray-800">Telefonní seznam</h3>
<p class="text-xs text-gray-500 mb-2">Aktuální telefonní seznam společnosti</p>
</div>
</div>
<button onclick="openWindowsFolder('M:\\X. IT\\0. PUBLIC\\Aktuální telefonní seznam')" class="block w-full text-center bg-gray-200 hover:bg-gray-300 text-gray-700 text-sm py-1 px-3 rounded transition-colors mt-2">
<i class="fas fa-folder-open mr-1"></i> Otevřít složku
</button>
</div>
<!-- 2. Řízená dokumentace -->
<div class="card bg-white rounded-lg shadow-sm p-4 border border-gray-200" data-name="řízená dokumentace dokumenty">
<div class="flex items-center">
<div class="rounded-full w-10 h-10 flex items-center justify-center bg-gray-100 text-gray-600 mr-3">
<i class="fas fa-file-alt"></i>
</div>
<div class="flex-1">
<h3 class="text-md font-medium text-gray-800">Řízená dokumentace</h3>
<p class="text-xs text-gray-500 mb-2">Přístup k firemní řízené dokumentaci</p>
</div>
</div>
<button onclick="openWindowsFolder('M:\\06. ŘÍZENÁ DOKUMENTACE')" class="block w-full text-center bg-gray-200 hover:bg-gray-300 text-gray-700 text-sm py-1 px-3 rounded transition-colors mt-2">
<i class="fas fa-folder-open mr-1"></i> Otevřít složku
</button>
</div>
<!-- 3. Management úkolů -->
<div class="card bg-white rounded-lg shadow-sm p-4 border border-gray-200" data-name="management úkolů úkoly projekty">
<div class="flex items-center">
<div class="rounded-full w-10 h-10 flex items-center justify-center bg-gray-100 text-gray-600 mr-3">
<i class="fas fa-clipboard-list"></i>
</div>
<div class="flex-1">
<h3 class="text-md font-medium text-gray-800">Management úkolů</h3>
<p class="text-xs text-gray-500 mb-2">Systém pro správu a sledování firemních úkolů</p>
</div>
</div>
<button onclick="openWindowsFolder('M:\\10. MANAGEMENT ÚKOLŮ')" class="block w-full text-center bg-gray-200 hover:bg-gray-300 text-gray-700 text-sm py-1 px-3 rounded transition-colors mt-2">
<i class="fas fa-folder-open mr-1"></i> Otevřít složku
</button>
</div>
</div> </div>
</main> </main>
<footer class="bg-gray-800 text-gray-400 py-6 mt-12"> <footer class="bg-gray-800 text-gray-400 py-6 mt-12">
<div class="container mx-auto px-4 text-center"> <div class="container mx-auto px-4 text-center">
<p>© 2025 Poppe + Potthoff</p> <p>&copy; 2025 Poppe + Potthoff</p>
<p class="mt-2 text-sm">Created by <a href="https://tdvorak.dev" class="text-blue-400 hover:text-blue-300">TDvorak</a></p> <p class="mt-2 text-sm">Created by <a href="https://tdvorak.dev" class="text-blue-400 hover:text-blue-300">TDvorak</a></p>
</div> </div>
</footer> </footer>
@@ -108,16 +172,34 @@
appCards.forEach(card => { appCards.forEach(card => {
const cardName = card.getAttribute('data-name').toLowerCase(); const cardName = card.getAttribute('data-name').toLowerCase();
const cardTitle = card.querySelector('h2').textContent.toLowerCase(); const cardTitle = card.querySelector('h2') || card.querySelector('h3');
const cardDesc = card.querySelector('p').textContent.toLowerCase(); const cardDesc = card.querySelector('p');
const titleText = cardTitle ? cardTitle.textContent.toLowerCase() : '';
const descText = cardDesc ? cardDesc.textContent.toLowerCase() : '';
if (cardName.includes(searchTerm) || cardTitle.includes(searchTerm) || cardDesc.includes(searchTerm)) { if (cardName.includes(searchTerm) || titleText.includes(searchTerm) || descText.includes(searchTerm)) {
card.style.display = 'block'; card.style.display = 'block';
} else { } else {
card.style.display = 'none'; card.style.display = 'none';
} }
}); });
}); });
// Function to open Windows Explorer with a specific path using our integrated Go server
function openWindowsFolder(path) {
// Call our Go server to open the folder in Windows Explorer
fetch(`/open?path=${encodeURIComponent(path)}`)
.then(response => {
if (!response.ok) {
throw new Error('Failed to open folder');
}
console.log('Folder opened successfully');
})
.catch(error => {
console.error('Error opening folder:', error);
alert('Could not open folder. Make sure the server is running.');
});
}
</script> </script>
</body> </body>
</html> </html>
+54 -1
View File
@@ -8,6 +8,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@@ -50,12 +51,15 @@ func main() {
http.ServeFile(w, r, "evidence-aut.html") http.ServeFile(w, r, "evidence-aut.html")
})) }))
// Add folder opener endpoint
http.HandleFunc("/open", enableCORS(openFolderHandler))
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port == "" { if port == "" {
port = "8080" port = "8080"
} }
log.Printf("Server běží na portu %s", port) log.Printf("Server běží na portu %s (včetně otevírání složek Windows)", port)
err := http.ListenAndServe(":"+port, nil) err := http.ListenAndServe(":"+port, nil)
if err != nil { if err != nil {
log.Fatalf("Chyba při spuštění serveru: %v", err) log.Fatalf("Chyba při spuštění serveru: %v", err)
@@ -156,6 +160,55 @@ 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"}`))
} }
// Handler pro otevírání Windows složek přímo z prohlížeče
func openFolderHandler(w http.ResponseWriter, r *http.Request) {
// Get the folder path from the query parameter
folderPath := r.URL.Query().Get("path")
if folderPath == "" {
http.Error(w, "Missing path parameter", http.StatusBadRequest)
return
}
// Log the request
log.Printf("Otevírání složky: %s", folderPath)
// Properly handle backslashes in Windows paths
// First, replace any forward slashes with backslashes
folderPath = strings.ReplaceAll(folderPath, "/", "\\")
// Fix any double backslashes that might have been created by JavaScript escaping
for strings.Contains(folderPath, "\\\\") {
folderPath = strings.ReplaceAll(folderPath, "\\\\", "\\")
}
// Log the cleaned path
log.Printf("Upravená cesta: %s", folderPath)
// Open the folder in Windows Explorer
cmd := exec.Command("explorer.exe", folderPath)
err := cmd.Start()
if err != nil {
// If there was an error, try opening the parent directory
log.Printf("Chyba při otevírání složky: %v, zkouším jinou metodu", err)
// Try using /root,path format which sometimes works better
cmd = exec.Command("explorer.exe", "/root," + folderPath)
err = cmd.Start()
if err != nil {
log.Printf("Chyba při otevírání složky: %v", err)
http.Error(w, fmt.Sprintf("Error opening folder: %v", err), http.StatusInternalServerError)
return
}
}
// Return success response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success", "message": fmt.Sprintf("Opening folder: %s", folderPath)})
}
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