added safety and color

This commit is contained in:
visionmercer 2026-04-20 11:56:24 +02:00
commit 25d607e68c
3 changed files with 129 additions and 41 deletions

View file

@ -205,7 +205,36 @@ func (h *Handler) DownloadFile(w http.ResponseWriter, r *http.Request) {
func (h *Handler) RawFile(w http.ResponseWriter, r *http.Request) { func (h *Handler) RawFile(w http.ResponseWriter, r *http.Request) {
fileName := strings.TrimPrefix(r.URL.Path, "/raw/") fileName := strings.TrimPrefix(r.URL.Path, "/raw/")
http.ServeFile(w, r, filepath.Join(h.dir, fileName))
// Security: Prevent path traversal attacks
if fileName == "" || strings.Contains(fileName, "..") || strings.HasPrefix(fileName, "/") {
http.Error(w, "Invalid path", http.StatusBadRequest)
return
}
// Clean the path to prevent any directory traversal
cleanPath := filepath.Clean(fileName)
if strings.Contains(cleanPath, "..") {
http.Error(w, "Invalid path", http.StatusBadRequest)
return
}
fullPath := filepath.Join(h.dir, cleanPath)
// Verify the file exists and is within the allowed directory
fileInfo, err := os.Stat(fullPath)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
// Ensure it's not a directory
if fileInfo.IsDir() {
http.Error(w, "Not found", http.StatusNotFound)
return
}
http.ServeFile(w, r, fullPath)
} }
func (h *Handler) ServeStatic(w http.ResponseWriter, r *http.Request) { func (h *Handler) ServeStatic(w http.ResponseWriter, r *http.Request) {
@ -318,10 +347,18 @@ func fileIcon(name string) string {
return "💿" return "💿"
case ".pdf": case ".pdf":
return "📄" return "📄"
case ".jpg", ".png", ".jpeg": case ".jpg", ".png", ".jpeg", ".gif", ".pcx", ".bmp":
return "🖼️" return "🖼️"
case ".txt", ".md": case ".txt", ".md":
return "📝" return "📝"
case ".mp3", ".mod", ".ogg", ".wav", ".flac":
return "🎵"
case ".mp4", ".avi", ".mov":
return "🎬"
case ".zip", ".rar", ".7z":
return "📦"
case ".exe", ".msi":
return "📦"
default: default:
return "📄" return "📄"
} }

View file

@ -1,23 +1,26 @@
:root { :root {
/* Gruvbox Dark Palette */ /* Gruvbox Dark Palette */
--bg: #282828; /* dark0 */ --bg: #282828; /* dark0 */
--surface: #3c3836; /* dark1 */ --surface: #3c3836; /* dark1 */
--border: #504945; /* dark2 */ --border: #504945; /* dark2 */
--accent: #fabd2f; /* yellow */ --accent: #fabd2f; /* yellow */
--text: #ebdbb2; /* light1 */ --text: #ebdbb2; /* light1 */
--muted: #a89984; /* gray */ --muted: #a89984; /* gray */
--radius: 0px; /* Forced to 0 for sharp corners */ --radius: 0px; /* Forced to 0 for sharp corners */
} }
body { body {
background: var(--bg); background: var(--bg);
color: var(--text); color: var(--text);
font-family: system-ui, -apple-system, sans-serif; font-family:
system-ui,
-apple-system,
sans-serif;
margin: 0; margin: 0;
} }
header { header {
background: #1d2021; /* dark0_hard */ background: #1d2021; /* dark0_hard */
border-bottom: 1px solid var(--border); border-bottom: 1px solid var(--border);
padding: 0 2rem; padding: 0 2rem;
height: 56px; height: 56px;
@ -26,7 +29,7 @@ header {
} }
.logo { .logo {
color: var(--accent); color: var(--text);
font-weight: bold; font-weight: bold;
text-decoration: none; text-decoration: none;
font-family: monospace; font-family: monospace;
@ -95,7 +98,7 @@ main {
.card-name { .card-name {
font-weight: bold; font-weight: bold;
color: var(--accent); color: var(--text);
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
display: block; display: block;
overflow: hidden; overflow: hidden;
@ -103,6 +106,10 @@ main {
white-space: nowrap; white-space: nowrap;
} }
.card-name:hover {
color: var(--accent);
}
.card-desc { .card-desc {
font-size: 0.8rem; font-size: 0.8rem;
color: var(--muted); color: var(--muted);
@ -120,10 +127,14 @@ main {
} }
.bc a { .bc a {
color: var(--accent); color: var(--text);
text-decoration: none; text-decoration: none;
} }
.bc a:hover {
color: var(--accent);
}
.tbl { .tbl {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
@ -159,7 +170,9 @@ main {
cursor: pointer; cursor: pointer;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
transition: background 0.2s, color 0.2s; transition:
background 0.2s,
color 0.2s;
} }
.btn:hover { .btn:hover {
@ -198,7 +211,7 @@ main {
max-height: 80vh; max-height: 80vh;
overflow-y: auto; overflow-y: auto;
position: relative; position: relative;
box-shadow: 0 10px 30px rgba(0,0,0,0.5); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
} }
.modal-header { .modal-header {

View file

@ -1,27 +1,65 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head><title>{{.Title}}</title><link rel="stylesheet" href="/static/css/style.css"></head> <head>
<body> <title>{{.Title}}</title>
<header><a class="logo" href="/">💿 ISOSilo</a></header> <link rel="stylesheet" href="/static/css/style.css" />
<main> </head>
<nav class="bc"> <body>
{{range $i, $c := .Breadcrumbs}}<a href="{{$c.URL}}">{{$c.Name}}</a> {{if lt (add1 $i) (len $.Breadcrumbs)}}/{{end}} {{end}} <header><a class="logo" href="/">💿 ISOSilo</a></header>
</nav> <main>
<table class="tbl"> <nav class="bc">
<thead><tr><th>Name</th><th>Size</th><th>Action</th></tr></thead> {{range $i, $c := .Breadcrumbs}}<a href="{{$c.URL}}"
<tbody> >{{$c.Name}}</a
{{range .Entries}} >
<tr> {{if lt (add1 $i) (len $.Breadcrumbs)}}/{{end}} {{end}}
<td> </nav>
{{if .IsDir}}📁 <a href="/browse/{{urlenc $.ISOName}}/{{urlenc .Path}}" style="color:var(--text); text-decoration:none;">{{.Name}}</a> <table class="tbl">
{{else}}{{fileIcon .Name}} <a href="/file/{{urlenc $.ISOName}}/{{urlenc .Path}}" target="_blank" style="color:var(--text); text-decoration:none;">{{.Name}}</a>{{end}} <thead>
</td> <tr>
<td>{{if .IsDir}}—{{else}}{{humanSize .Size}}{{end}}</td> <th>Name</th>
<td>{{if not .IsDir}}<a href="/file/{{urlenc $.ISOName}}/{{urlenc .Path}}" class="dl-btn" download>Download</a>{{end}}</td> <th>Size</th>
</tr> <th>Action</th>
{{end}} </tr>
</tbody> </thead>
</table> <tbody>
</main> {{range .Entries}}
</body> <tr>
<td>
{{if .IsDir}}📁
<a
href="/browse/{{urlenc $.ISOName}}/{{urlenc .Path}}"
style="
color: var(--text);
text-decoration: none;
"
>{{.Name}}</a
>
{{else}}{{fileIcon .Name}}
<a
href="/file/{{urlenc $.ISOName}}/{{urlenc .Path}}"
target="_blank"
style="
color: var(--text);
text-decoration: none;
"
>{{.Name}}</a
>{{end}}
</td>
<td>
{{if .IsDir}}—{{else}}{{humanSize .Size}}{{end}}
</td>
<td>
{{if not .IsDir}}<a
href="/file/{{urlenc $.ISOName}}/{{urlenc .Path}}"
class="btn"
download
>Download</a
>{{end}}
</td>
</tr>
{{end}}
</tbody>
</table>
</main>
</body>
</html> </html>