Add a pcap-split tool

This commit is contained in:
2026-10-05 20:16:01 +02:00
parent 5b5cf211d0
commit c11c893845
13 changed files with 769 additions and 22 deletions
+28
View File
@@ -0,0 +1,28 @@
package web
import (
"path"
"strings"
)
// safeName reduces a user supplied file name to a safe base name: directory
// components are dropped and unusual characters replaced by '_'. fallback is
// returned if nothing usable is left.
func safeName(name, fallback string) string {
name = path.Base(strings.ReplaceAll(strings.TrimSpace(name), `\`, "/"))
name = strings.Map(func(r rune) rune {
if r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' || r == '-' || r == '_' || r == '.' {
return r
}
return '_'
}, name)
if strings.Trim(name, "._") == "" {
return fallback
}
return name
}
// pcapFilename sanitizes a user supplied download name and gives it a .pcap extension.
func pcapFilename(name string) string {
return strings.TrimSuffix(safeName(name, "packet.pcap"), ".pcap") + ".pcap"
}