Add a pcap-split tool
This commit is contained in:
+12
-3
@@ -22,21 +22,28 @@ type Tool struct {
|
||||
|
||||
var tools = []Tool{
|
||||
{Name: "Hex → pcap", Path: "/hex2pcap", Description: "Build a pcap file from hex-encoded layer 2, layer 3 and payload bytes, optionally fixing IP lengths and checksums."},
|
||||
{Name: "Split pcap", Path: "/split", Description: "Split a pcap file into several files by packet count or file size, downloaded as a zip."},
|
||||
}
|
||||
|
||||
// Config holds server settings.
|
||||
type Config struct {
|
||||
MaxUploadBytes int64 // largest accepted file upload
|
||||
}
|
||||
|
||||
// Server is the HTTP handler for the whole application.
|
||||
type Server struct {
|
||||
cfg Config
|
||||
mux *http.ServeMux
|
||||
pages map[string]*template.Template
|
||||
}
|
||||
|
||||
// New parses the templates and sets up the routes.
|
||||
func New() (*Server, error) {
|
||||
s := &Server{mux: http.NewServeMux(), pages: map[string]*template.Template{}}
|
||||
func New(cfg Config) (*Server, error) {
|
||||
s := &Server{cfg: cfg, mux: http.NewServeMux(), pages: map[string]*template.Template{}}
|
||||
|
||||
// Each page is parsed together with the shared layout so pages can define
|
||||
// their own "title" and "content" blocks.
|
||||
for _, page := range []string{"index.html", "hex2pcap.html"} {
|
||||
for _, page := range []string{"index.html", "hex2pcap.html", "split.html"} {
|
||||
t, err := template.New(page).ParseFS(assets, "templates/layout.html", "templates/"+page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,6 +59,8 @@ func New() (*Server, error) {
|
||||
s.mux.HandleFunc("GET /{$}", s.handleIndex)
|
||||
s.mux.HandleFunc("GET /hex2pcap", s.handleHex2PcapForm)
|
||||
s.mux.HandleFunc("POST /hex2pcap", s.handleHex2Pcap)
|
||||
s.mux.HandleFunc("GET /split", s.handleSplitForm)
|
||||
s.mux.HandleFunc("POST /split", s.handleSplit)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user