Add missing files, update style

This commit is contained in:
2026-10-05 20:48:08 +02:00
parent e70549337e
commit 9d092ed9df
20 changed files with 1161 additions and 202 deletions
+53
View File
@@ -0,0 +1,53 @@
package web
import (
"fmt"
"log"
"net/http"
"strconv"
"pcap-web-tools/internal/pcap"
)
type reorderPage struct {
MaxUpload string
Error string
}
func (s *Server) handleReorderForm(w http.ResponseWriter, r *http.Request) {
s.render(w, http.StatusOK, "reorder.html", "/reorder", reorderPage{MaxUpload: s.maxUpload()})
}
func (s *Server) handleReorder(w http.ResponseWriter, r *http.Request) {
page := reorderPage{MaxUpload: s.maxUpload()}
fail := func(status int, msg string) {
page.Error = msg
s.render(w, status, "reorder.html", "/reorder", page)
}
file, hdr, status, msg := s.parseUpload(w, r)
if status != 0 {
fail(status, msg)
return
}
defer file.Close()
// Indexing reads the whole file, so problems are reported on the page
// before any of the download is sent.
ro, err := pcap.NewReorder(file, hdr.Size)
if err != nil {
fail(http.StatusBadRequest, hdr.Filename+": "+err.Error())
return
}
w.Header().Set("Content-Type", "application/vnd.tcpdump.pcap")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%q", uploadStem(hdr)+"_reordered.pcap"))
// Summary for scripted clients; browsers just save the file.
w.Header().Set("X-Pcap-Packets", strconv.Itoa(ro.Packets()))
w.Header().Set("X-Pcap-Out-Of-Order", strconv.Itoa(ro.OutOfOrder()))
w.Header().Set("X-Pcap-Truncated", strconv.FormatBool(ro.Truncated()))
if _, err := ro.WriteTo(w); err != nil {
// The response has already started, so the error cannot be shown on the page.
log.Printf("reorder %q: %v", hdr.Filename, err)
}
}
+60
View File
@@ -0,0 +1,60 @@
package web
import (
"bytes"
"io"
"net/http"
"strings"
"testing"
"time"
"pcap-web-tools/internal/pcap"
)
func TestReorderHandler(t *testing.T) {
srv, err := New(Config{MaxUploadBytes: 1 << 20})
if err != nil {
t.Fatal(err)
}
var in bytes.Buffer
w, _ := pcap.NewWriter(&in, pcap.LinkTypeEthernet)
for _, sec := range []int64{3, 1, 2} {
w.WritePacket(time.Unix(sec, 0), []byte{byte(sec)})
}
rec := postUpload(t, srv, "/reorder", "trace.pcap", in.Bytes(), nil)
if rec.Code != http.StatusOK {
t.Fatalf("status %d: %s", rec.Code, rec.Body)
}
if cd := rec.Header().Get("Content-Disposition"); cd != `attachment; filename="trace_reordered.pcap"` {
t.Errorf("Content-Disposition %q", cd)
}
if got := rec.Header().Get("X-Pcap-Out-Of-Order"); got != "2" {
t.Errorf("X-Pcap-Out-Of-Order %q", got)
}
r, err := pcap.NewReader(rec.Body)
if err != nil {
t.Fatal(err)
}
var order []byte
for {
p, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
order = append(order, p[16])
}
if !bytes.Equal(order, []byte{1, 2, 3}) {
t.Errorf("order %v", order)
}
for name, file := range map[string][]byte{"no file": nil, "not pcap": []byte("hello world, not a pcap file")} {
rec := postUpload(t, srv, "/reorder", "x.pcap", file, nil)
if rec.Code != http.StatusBadRequest || !strings.Contains(rec.Body.String(), `class="error"`) {
t.Errorf("%s: status %d", name, rec.Code)
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

+429 -103
View File
@@ -1,127 +1,453 @@
/*
* Shared stylesheet for all pcap tools pages.
*
* Follows the utel-frontend design: dark theme, utel color tokens, Inter /
* Dazzed / Roboto Mono fonts, top bar with a sidebar, "widget" cards and
* pill shaped buttons and inputs.
*/
/* ---------- Fonts ---------- */
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/static/fonts/inter-v12-latin-regular.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/static/fonts/inter-v12-latin-500.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/static/fonts/inter-v12-latin-600.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("/static/fonts/inter-v12-latin-700.woff2") format("woff2"); }
@font-face { font-family: "Dazzed-Medium"; font-display: swap; src: url("/static/fonts/Dazzed-Medium.otf") format("opentype"); }
@font-face { font-family: "Roboto-mono"; font-display: swap; src: url("/static/fonts/RobotoMono-Regular.ttf") format("truetype"); }
/* ---------- Tokens (from utel-frontend variables.scss) ---------- */
:root {
--bg: #f7f7f5;
--fg: #1d1d1f;
--muted: #6b6b70;
--card: #ffffff;
--border: #d9d9de;
--accent: #2463eb;
--accent-fg: #ffffff;
--error-bg: #fdecec;
--error-fg: #9b1c1c;
--l2: #b45309;
--l3: #1d4ed8;
--l7: #047857;
--mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
color-scheme: dark;
--utel-body-background: #191c1c;
--utel-navigation-background: #1f2f2e;
--utel-navigation-background-darken: #15201f;
--utel-text-color: #fff;
--utel-scrollbar-color: #696969;
--utel-icon-label-text-color: #a7a7a7;
--utel-icon-color: #d2d2d2;
--utel-p-text-color: #d3d3d3;
--utel-title-text-color: #d8d8d8;
--utel-title-link-color: #a7a7a7;
--utel-navigation-darker-text-color: #e6e6e6;
--utel-content-background: #242828;
--utel-content-darker-background: #1c1f1f;
--utel-content-text-color: #d8d8d8;
--utel-highlight-text-color: #9ed7aa;
--utel-content-border-color: #707070ac;
--utel-modal-border-color: #303434;
--utel-solid-button-color: #6da478;
--utel-solid-button-color-darker: #5d9568;
--utel-widget-button-color: #3c4343;
--utel-widget-button-color-darker: #434b4b;
--utel-widget-title-border: #1c1f1f;
--utel-widget-border: #323737;
--utel-content-hover-color: #393d3d;
--utel-fraud-color-yellow: #e4b266;
--utel-fraud-color-red: #ea6f80;
--utel-table-color: #2d3232;
--utel-table-split-color: #242828;
--utel-table-header-text-color: #9a9a9a;
--utel-severity-color-low: #6daa9c;
--utel-input-border-color: #3b4040;
--top-bar-height: 55px;
--sidebar-width: 220px;
--font-body: "Inter", system-ui, sans-serif;
--font-heading: "Dazzed-Medium", "Inter", sans-serif;
--font-mono: "Roboto-mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #161618;
--fg: #e8e8ea;
--muted: #9a9aa2;
--card: #1f1f22;
--border: #36363c;
--accent: #5b8cff;
--accent-fg: #0b0b0c;
--error-bg: #3a1717;
--error-fg: #ffb4b4;
--l2: #f5a65b;
--l3: #8fb0ff;
--l7: #5fd3a6;
}
}
/* ---------- Base ---------- */
* { box-sizing: border-box; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
margin: 0;
background: var(--bg);
color: var(--fg);
font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
background: var(--utel-body-background);
color: var(--utel-text-color);
font: 400 15px/1.5 var(--font-body);
scrollbar-color: var(--utel-scrollbar-color) transparent;
scrollbar-width: thin;
}
header { border-bottom: 1px solid var(--border); background: var(--card); }
nav { max-width: 960px; margin: 0 auto; padding: 0.75rem 1rem; display: flex; gap: 1.25rem; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; }
nav a:hover, nav a.active { color: var(--fg); }
nav a.brand { color: var(--fg); font-weight: 600; }
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; border-radius: 80px; }
::-webkit-scrollbar-thumb { background-color: var(--utel-scrollbar-color); border-radius: 80px; }
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1 { margin: 0 0 0.5rem; font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.lead { color: var(--muted); margin-top: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; }
.hint { color: var(--muted); font-weight: normal; font-size: 0.85em; }
h1, h2, h3 { font-family: var(--font-heading); font-weight: normal; margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; color: var(--utel-title-text-color); margin: 16px 0 8px; }
.tools { list-style: none; padding: 0; display: grid; gap: 0.75rem; }
.tools li { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.tools a { font-weight: 600; font-size: 1.05rem; }
.tools p { margin: 0.25rem 0 0; color: var(--muted); }
p { color: var(--utel-p-text-color); }
a { color: var(--utel-highlight-text-color); }
code, pre { font-family: var(--font-mono); font-size: 13px; }
form label { display: block; font-weight: 600; margin: 1rem 0 0.3rem; }
textarea, input, select {
width: 100%;
font: inherit;
color: var(--fg);
background: var(--card);
border: 1px solid var(--border);
border-radius: 6px;
padding: 0.5rem 0.6rem;
.hint { color: var(--utel-icon-label-text-color); font-weight: 400; font-size: 13px; }
.note { color: var(--utel-icon-label-text-color); font-size: 14px; margin: 6px 0; }
.visually-hidden {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
textarea { font-family: var(--mono); font-size: 0.9rem; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset { border: 0; padding: 0; margin: 0; }
label.check { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; font-weight: 600; }
label.check input { width: auto; }
.row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .row { grid-template-columns: 1fr; gap: 0; } }
/* ---------- Top bar ---------- */
.actions { margin-top: 1.25rem; display: flex; gap: 0.75rem; }
button {
font: inherit;
padding: 0.5rem 1.1rem;
border-radius: 6px;
border: 1px solid var(--border);
background: var(--card);
color: var(--fg);
.topbar {
position: sticky;
top: 0;
z-index: 20;
display: flex;
align-items: center;
height: var(--top-bar-height);
background: var(--utel-navigation-background);
border-bottom: 1px solid var(--utel-body-background);
}
.burger {
display: grid;
place-items: center;
width: var(--top-bar-height);
height: var(--top-bar-height);
flex: none;
background: var(--utel-navigation-background-darken);
cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.burger svg { width: 19px; fill: var(--utel-text-color); }
.nav-toggle:focus-visible + .topbar .burger { outline: 2px solid var(--utel-solid-button-color); outline-offset: -2px; }
.error { background: var(--error-bg); color: var(--error-fg); padding: 0.75rem 1rem; border-radius: 6px; margin: 1rem 0; }
.note { color: var(--muted); margin: 0.35rem 0; }
.app-title {
margin-left: 15px;
font: 16px/var(--top-bar-height) var(--font-heading);
color: var(--utel-text-color);
text-decoration: none;
}
.result { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.summary { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; }
.summary dt { color: var(--muted); }
.logo-symbol {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: flex;
}
.logo-symbol svg { width: 40px; height: 40px; fill: var(--utel-text-color); }
/* ---------- Sidebar ---------- */
.sidebar {
position: fixed;
top: var(--top-bar-height);
left: 0;
z-index: 10;
width: var(--sidebar-width);
height: calc(100% - var(--top-bar-height));
overflow-y: auto;
background: var(--utel-navigation-background-darken);
transition: transform 0.15s ease;
}
.nav-section {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
padding: 8px 15px;
color: var(--utel-icon-label-text-color);
font-size: 11px;
letter-spacing: 0.8px;
text-transform: uppercase;
}
.nav-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 15px;
color: var(--utel-text-color);
font-weight: 500;
font-size: 15px;
text-decoration: none;
}
.nav-item:hover, .nav-item.active { background: var(--utel-navigation-background); }
.nav-item.active { color: var(--utel-highlight-text-color); }
.nav-item::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--utel-solid-button-color);
flex: none;
}
/*
* The burger toggles the sidebar using a checkbox, so no JavaScript is needed.
* Wide screens show the sidebar by default and the burger hides it; narrow
* screens hide it by default and the burger shows it over the content.
*/
.content { margin-left: var(--sidebar-width); padding: 10px; transition: margin-left 0.15s ease; }
.nav-toggle:checked ~ .sidebar { transform: translateX(-100%); }
.nav-toggle:checked ~ .content { margin-left: 0; }
@media (max-width: 64rem) {
.sidebar { transform: translateX(-100%); box-shadow: 4px 0 12px rgb(0 0 0 / 0.35); }
.nav-toggle:checked ~ .sidebar { transform: none; }
.content { margin-left: 0; }
.logo-symbol { display: none; }
}
/* ---------- Page toolbar ---------- */
.toolbar {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 0 20px;
margin: 0 5px 10px;
font-size: 16px;
}
.breadcrumb { color: var(--utel-navigation-darker-text-color); }
.toolbar-link { color: var(--utel-title-link-color); text-decoration: none; }
.toolbar-link:hover { color: var(--utel-title-text-color); border-bottom: 1px solid var(--utel-title-text-color); }
.title-separator { margin: 0 5px 0 7px; color: var(--utel-title-link-color); }
.toolbar-title { color: var(--utel-title-text-color); }
.toolbar-info { color: var(--utel-icon-label-text-color); font-size: 14px; }
/* ---------- Widgets ---------- */
.widget {
margin: 5px 5px 10px;
background: var(--utel-content-background);
border-radius: 5px;
}
.widget-title {
display: flex;
align-items: center;
gap: 10px;
min-height: 38px;
border-bottom: 1px solid var(--utel-widget-title-border);
}
.widget-title h2 { padding: 8px 0 8px 10px; color: var(--utel-title-text-color); }
.widget-title .hint { margin-left: auto; padding-right: 10px; }
.widget-content { padding: 10px; border-top: 1px solid var(--utel-widget-border); }
.widget-content > :first-child { margin-top: 0; }
.widget-content > :last-child { margin-bottom: 0; }
.widget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tool-card { display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: background 0.1s; }
.tool-card:hover { background: var(--utel-content-hover-color); }
.tool-card .widget-content { flex: 1; color: var(--utel-p-text-color); font-size: 14px; }
/* ---------- Buttons ---------- */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
height: 35px;
padding: 6px 16px;
border: 0;
border-radius: 80px;
font: 700 15px var(--font-body);
color: var(--utel-text-color);
background: var(--utel-widget-button-color);
cursor: pointer;
text-decoration: none;
white-space: nowrap;
}
.btn:hover { background: var(--utel-widget-button-color-darker); }
.btn:focus-visible { outline: 2px solid var(--utel-highlight-text-color); outline-offset: 2px; }
.btn.primary { background: var(--utel-solid-button-color); }
.btn.primary:hover { background: var(--utel-solid-button-color-darker); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px; }
/* ---------- Forms ---------- */
label, .label {
display: block;
margin: 12px 0 4px;
color: var(--utel-content-text-color);
font-size: 14px;
font-weight: 500;
}
input, select, textarea {
font: 400 14px var(--font-body);
color: var(--utel-content-text-color);
}
/* Single line inputs and selects: utel pill style */
input:not([type=checkbox], [type=radio], [type=file]), select {
width: 100%;
height: 32px;
padding: 0 15px;
background: var(--utel-content-background);
border: 1px solid var(--utel-input-border-color);
border-radius: 64px;
}
select {
appearance: none;
padding-right: 36px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a7a7a7' stroke-width='1.6'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 14px center;
background-size: 12px 8px;
text-overflow: ellipsis;
}
select option { background: var(--utel-content-background); }
/* Multi-line hex input: same border, darker field, rounded rectangle */
textarea {
display: block;
width: 100%;
padding: 8px 12px;
background: var(--utel-content-darker-background);
border: 1px solid var(--utel-input-border-color);
border-radius: 5px;
font-family: var(--font-mono);
font-size: 13px;
resize: vertical;
}
::placeholder { color: var(--utel-icon-label-text-color); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--utel-solid-button-color); }
/* Checkbox and radio: 18px box with the utel green when checked */
input[type=checkbox], input[type=radio] {
appearance: none;
flex: none;
width: 18px;
height: 18px;
margin: 0;
border: 1px solid var(--utel-content-border-color);
border-radius: 3px;
background: transparent;
display: grid;
place-items: center;
cursor: pointer;
}
input[type=radio] { border-radius: 50%; }
input[type=checkbox]:checked, input[type=radio]:checked {
background: var(--utel-solid-button-color);
border-color: var(--utel-solid-button-color);
}
input[type=checkbox]:checked::after {
content: "";
width: 10px;
height: 6px;
margin-top: -3px;
border: solid var(--utel-text-color);
border-width: 0 0 2px 2px;
transform: rotate(-45deg);
}
input[type=radio]:checked::after {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--utel-text-color);
}
input[type=checkbox]:focus-visible, input[type=radio]:focus-visible { outline: 2px solid var(--utel-highlight-text-color); outline-offset: 2px; }
label.check {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
font-weight: 400;
font-size: 15px;
}
/* File input: the button looks like a secondary utel button */
input[type=file] {
width: 100%;
padding: 4px;
border: 1px dashed var(--utel-input-border-color);
border-radius: 5px;
color: var(--utel-icon-label-text-color);
}
input[type=file]::file-selector-button {
height: 30px;
margin-right: 12px;
padding: 0 14px;
border: 0;
border-radius: 80px;
font: 700 14px var(--font-body);
color: var(--utel-text-color);
background: var(--utel-widget-button-color);
cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--utel-widget-button-color-darker); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin: 12px 0 4px; font-size: 14px; font-weight: 500; color: var(--utel-content-text-color); }
/* Three controls on one line: link type, custom link type, file name */
.row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 12px; align-items: start; }
.row label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-hint { display: block; margin: 4px 0 0 15px; }
@media (max-width: 720px) { .row { grid-template-columns: 1fr; } }
/* Split modes: radio with inline number input and unit */
.modes label.check { margin: 8px 0; }
.modes input.num { width: 8rem; }
.modes select.unit { width: 5.5rem; }
/* ---------- Messages ---------- */
.error {
margin: 0 5px 10px;
padding: 10px 15px;
border: 1px solid var(--utel-fraud-color-red);
border-left-width: 4px;
border-radius: 5px;
background: rgb(234 111 128 / 0.1);
color: var(--utel-text-color);
}
/* ---------- Tables (utel table-theme) ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
padding: 0 10px 5px 5px;
text-align: left;
font-weight: 400;
white-space: nowrap;
color: var(--utel-table-header-text-color);
}
td {
padding: 5px 10px 5px 5px;
font-weight: 500;
background: var(--utel-table-color);
border-top: 1px solid var(--utel-table-split-color);
}
tr.changed td:last-child { color: var(--utel-highlight-text-color); }
/* ---------- hex2pcap result ---------- */
.summary { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 14px; }
.summary dt { color: var(--utel-icon-label-text-color); }
.summary dd { margin: 0; }
table { border-collapse: collapse; width: 100%; background: var(--card); border: 1px solid var(--border); }
th, td { text-align: left; padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
tr.changed td:last-child { font-weight: 600; }
.dump {
font-family: var(--mono);
font-size: 0.85rem;
background: var(--card);
border: 1px solid var(--border);
border-radius: 6px;
padding: 0.75rem 1rem;
margin: 0;
padding: 10px 12px;
overflow-x: auto;
background: var(--utel-content-darker-background);
border-radius: 5px;
color: var(--utel-p-text-color);
line-height: 1.6;
}
.dump .off { color: var(--muted); }
.l2 { color: var(--l2); }
.l3 { color: var(--l3); }
.l7 { color: var(--l7); }
.chg { text-decoration: underline; text-underline-offset: 3px; font-weight: 700; }
.dump .off { color: var(--utel-table-header-text-color); }
.l2 { color: var(--utel-fraud-color-yellow); }
.l3 { color: var(--utel-severity-color-low); }
.l7 { color: var(--utel-p-text-color); }
.chg { text-decoration: underline; text-underline-offset: 3px; color: var(--utel-highlight-text-color); font-weight: 700; }
input[type=file] { padding: 0.4rem; }
.modes { margin-top: 1rem; }
.modes legend { font-weight: 600; margin-bottom: 0.3rem; }
.modes label.check { font-weight: normal; margin: 0.5rem 0; align-items: center; }
.modes input.num { width: 8rem; }
.modes select.unit { width: auto; }
/* A hint under a checkbox lines up with the checkbox's text */
label.check + .field-hint { margin: 2px 0 0 26px; }
+63 -50
View File
@@ -1,35 +1,44 @@
{{define "title"}}Hex → pcap{{end}}
{{define "toolbar-info"}}<span class="toolbar-info">Build a pcap file from hex · <a href="/hex2pcap?example" class="toolbar-link">Load example</a></span>{{end}}
{{define "content"}}
{{with .Data}}
<h1>Hex → pcap</h1>
<p class="lead">
Paste hex for each layer. The fields are decoded and concatenated into one packet.
Any field may be empty, so you can also paste a whole packet into a single field.
Spaces, newlines, <code>:</code>, <code>-</code>, <code>0x</code> and <code>\x</code> are ignored.
<a href="/hex2pcap?example">Load example</a>.
</p>
{{if .Error}}<div class="error" role="alert">{{.Error}}</div>{{end}}
<form method="post" action="/hex2pcap">
<label for="l2">Layer 2 <span class="hint">e.g. Ethernet header</span></label>
<textarea id="l2" name="l2" rows="2" spellcheck="false">{{.Form.L2}}</textarea>
<section class="widget">
<div class="widget-title"><h2>Packet</h2></div>
<div class="widget-content">
<p class="note">
Paste hex for each layer. The fields are decoded and concatenated into one packet.
Any field may be empty, so you can also paste a whole packet into a single field.
Spaces, newlines, <code>:</code>, <code>-</code>, <code>0x</code> and <code>\x</code> are ignored.
</p>
<label for="l3">Layer 3 <span class="hint">IPv4/IPv6 header with options, optionally followed by the TCP/UDP/ICMP header, or the SCTP header and chunk header(s)</span></label>
<textarea id="l3" name="l3" rows="4" spellcheck="false">{{.Form.L3}}</textarea>
<label for="l2">Layer 2 <span class="hint">e.g. Ethernet header</span></label>
<textarea id="l2" name="l2" rows="2" spellcheck="false">{{.Form.L2}}</textarea>
<label for="l7">Payload <span class="hint">the rest of the packet, not interpreted</span></label>
<textarea id="l7" name="l7" rows="6" spellcheck="false">{{.Form.L7}}</textarea>
<label for="l3">Layer 3 <span class="hint">IPv4/IPv6 header with options, optionally followed by the TCP/UDP/ICMP header, or the SCTP header and chunk header(s)</span></label>
<textarea id="l3" name="l3" rows="4" spellcheck="false">{{.Form.L3}}</textarea>
<fieldset>
<label for="l7">Payload <span class="hint">the rest of the packet, not interpreted</span></label>
<textarea id="l7" name="l7" rows="6" spellcheck="false">{{.Form.L7}}</textarea>
</div>
</section>
<section class="widget">
<div class="widget-title"><h2>Options</h2></div>
<div class="widget-content">
<label class="check">
<input type="checkbox" name="fix"{{if .Form.Fix}} checked{{end}}>
Recalculate IP lengths and checksums
<span class="hint">IPv4/IPv6 length, IPv4 header checksum, TCP/UDP/ICMP/ICMPv6/SCTP checksum, UDP length.
The end of the layer 3 field also sets the TCP data offset and the length of the SCTP chunk the payload belongs to
(paste chunk data without padding).</span>
</label>
<p class="hint field-hint">
IPv4/IPv6 length, IPv4 header checksum, TCP/UDP/ICMP/ICMPv6/SCTP checksum, UDP length.
The end of the layer 3 field also sets the TCP data offset and the length of the SCTP chunk the payload belongs to
(paste chunk data without padding).
</p>
<div class="row">
<div>
@@ -39,55 +48,59 @@
</select>
</div>
<div>
<label for="customlinktype">Custom link type <span class="hint">when “Custom…” is selected</span></label>
<input id="customlinktype" name="customlinktype" inputmode="numeric" value="{{.Form.CustomLinkType}}" placeholder="e.g. 228">
<label for="customlinktype">Custom link type</label>
<input id="customlinktype" name="customlinktype" inputmode="numeric" value="{{.Form.CustomLinkType}}" placeholder="e.g. 228" aria-describedby="customlinktype-hint">
<span id="customlinktype-hint" class="hint field-hint">Used when “Custom…” is selected</span>
</div>
<div>
<label for="filename">File name</label>
<input id="filename" name="filename" value="{{.Form.Filename}}" placeholder="packet.pcap">
</div>
</div>
</fieldset>
<div class="actions">
<button type="submit" name="action" value="preview">Preview</button>
<button type="submit" name="action" value="download" class="primary">Download pcap</button>
<div class="actions">
<button type="submit" name="action" value="preview" class="btn">Preview</button>
<button type="submit" name="action" value="download" class="btn primary">Download pcap</button>
</div>
</div>
</section>
</form>
{{with .Result}}
<section class="result">
<h2>Preview</h2>
<dl class="summary">
<dt>Packet length</dt><dd>{{len .Packet}} bytes</dd>
<dt>Link type</dt><dd>{{.LinkTypeName}} ({{.LinkType}})</dd>
<dt>Layers</dt>
<dd>
<span class="l2">layer 2: {{.L2Len}}</span> ·
<span class="l3">layer 3: {{.L3Len}}</span> ·
<span class="l7">payload: {{.L7Len}}</span>
</dd>
</dl>
<section class="widget">
<div class="widget-title"><h2>Preview</h2></div>
<div class="widget-content">
<dl class="summary">
<dt>Packet length</dt><dd>{{len .Packet}} bytes</dd>
<dt>Link type</dt><dd>{{.LinkTypeName}} ({{.LinkType}})</dd>
<dt>Layers</dt>
<dd>
<span class="l2">layer 2: {{.L2Len}}</span> ·
<span class="l3">layer 3: {{.L3Len}}</span> ·
<span class="l7">payload: {{.L7Len}}</span>
</dd>
</dl>
{{if .Fixed}}
<h3>Fixups <span class="hint">IP header at offset {{.IPOffset}}</span></h3>
<table>
<thead><tr><th>Field</th><th>Old</th><th>New</th></tr></thead>
<tbody>
{{range .Fix.Changes}}
<tr{{if ne .Old .New}} class="changed"{{end}}><td>{{.Field}}</td><td><code>{{.Old}}</code></td><td><code>{{.New}}</code></td></tr>
{{end}}
</tbody>
</table>
{{range .Fix.Notes}}<p class="note">{{.}}</p>{{end}}
{{end}}
{{if .Fixed}}
<h3>Fixups <span class="hint">IP header at offset {{.IPOffset}}</span></h3>
<table>
<thead><tr><th>Field</th><th>Old</th><th>New</th></tr></thead>
<tbody>
{{range .Fix.Changes}}
<tr{{if ne .Old .New}} class="changed"{{end}}><td>{{.Field}}</td><td><code>{{.Old}}</code></td><td><code>{{.New}}</code></td></tr>
{{end}}
</tbody>
</table>
{{range .Fix.Notes}}<p class="note">{{.}}</p>{{end}}
{{end}}
<h3>Hex dump <span class="hint">changed bytes are underlined</span></h3>
<pre class="dump">
<h3>Hex dump <span class="hint">changed bytes are underlined</span></h3>
<pre class="dump">
{{- range .Dump -}}
<span class="off">{{.Offset}}</span> {{range .Bytes}}<span class="{{.Class}}{{if .Changed}} chg{{end}}">{{.Hex}}</span>{{.Sep}}{{end}} {{.ASCII}}
{{end -}}
</pre>
</div>
</section>
{{end}}
{{end}}
+9 -9
View File
@@ -1,14 +1,14 @@
{{define "title"}}Home{{end}}
{{define "title"}}Tools{{end}}
{{define "toolbar-info"}}<span class="toolbar-info">Small utilities for working with pcap packet captures</span>{{end}}
{{define "content"}}
<h1>pcap tools</h1>
<p class="lead">Small utilities for working with pcap packet captures.</p>
<ul class="tools">
<div class="widget-grid">
{{range .Tools}}
<li>
<a href="{{.Path}}">{{.Name}}</a>
<p>{{.Description}}</p>
</li>
<a href="{{.Path}}" class="widget tool-card">
<div class="widget-title"><h2>{{.Name}}</h2></div>
<div class="widget-content">{{.Description}}</div>
</a>
{{end}}
</ul>
</div>
{{end}}
+25 -6
View File
@@ -3,17 +3,36 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>{{template "title" .}} · pcap tools</title>
<link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicon-16x16.png">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<header>
<nav>
<a href="/" class="brand">pcap tools</a>
{{range .Tools}}<a href="{{.Path}}"{{if eq .Path $.Active}} class="active"{{end}}>{{.Name}}</a>{{end}}
</nav>
<input type="checkbox" id="nav-toggle" class="nav-toggle visually-hidden" aria-label="Toggle navigation">
<header class="topbar">
<label for="nav-toggle" class="burger" title="Menu">
<svg viewBox="0 0 60 50" aria-hidden="true"><rect y="41.8" width="60" height="8.2"/><rect y="20.9" width="60" height="8.2"/><rect width="60" height="8.2"/></svg>
</label>
<a href="/" class="app-title">pcap tools</a>
<a href="/" class="logo-symbol" aria-label="Home">
<svg viewBox="0 0 25 25" aria-hidden="true"><path d="m15.3 18.8 1.9 4.2h2.1l-2.5-6.4zM9.9 19.8 7.5 19l.7 4h2z"/><path d="m18.7 8.1-1.2.8L15 7.1l-1.2 1.3L11 7.3l-.5 2.9 2.1 2.3-6.8 1.1.1-2.6-2.1.9.7 1.8-1 9.3h2.1l1.2-5.2 4.8 1.6 2.5 3.6h2.1l-2-4.3 4.4-6.7-.7-1.6.8-.4 1.4 3 1.4-2.8-2.8-2.1zm-3.8 2.2-.8-.5.9-1.4.8.5-.9 1.4zM9.195 2.368l1.042-.354 1.286 3.788-1.042.353zM5.072 3.737l.747-.808 3.892 3.597-.746.808z"/><path d="m4.483 8.179.274-1.065 3.777.97L8.26 9.15z"/></svg>
</a>
</header>
<main>
<nav class="sidebar" aria-label="Tools">
<div class="nav-section">Tools</div>
{{range .Tools}}<a href="{{.Path}}" class="nav-item{{if eq .Path $.Active}} active{{end}}"{{if eq .Path $.Active}} aria-current="page"{{end}}>{{.Name}}</a>
{{end}}
</nav>
<main class="content">
<div class="toolbar">
<div class="breadcrumb">
{{- if ne .Active "/"}}<a href="/" class="toolbar-link">pcap tools</a><span class="title-separator">/</span>{{end -}}
<span class="toolbar-title">{{template "title" .}}</span>
</div>
{{block "toolbar-info" .}}{{end}}
</div>
{{template "content" .}}
</main>
</body>
+29
View File
@@ -0,0 +1,29 @@
{{define "title"}}Reorder pcap{{end}}
{{define "toolbar-info"}}<span class="toolbar-info">Sort packets by timestamp, like <code>reordercap</code></span>{{end}}
{{define "content"}}
{{with .Data}}
{{if .Error}}<div class="error" role="alert">{{.Error}}</div>{{end}}
<form method="post" action="/reorder" enctype="multipart/form-data">
<section class="widget">
<div class="widget-title"><h2>Reorder</h2></div>
<div class="widget-content">
<p class="note">
Packets with the same timestamp keep their original order. Packet data and the file header are not changed.
</p>
<label for="file">pcap file <span class="hint">classic pcap, up to {{.MaxUpload}}. Convert pcapng with <code>editcap -F pcap</code></span></label>
<input id="file" name="file" type="file" accept=".pcap,.cap,.dmp,application/vnd.tcpdump.pcap" required>
<p class="note">If the capture ends with a truncated packet, that packet is dropped.</p>
<div class="actions">
<button type="submit" class="btn primary">Reorder and download</button>
</div>
</div>
</section>
</form>
{{end}}
{{end}}
+37 -33
View File
@@ -1,47 +1,51 @@
{{define "title"}}Split pcap{{end}}
{{define "toolbar-info"}}<span class="toolbar-info">Split a pcap file by packet count or file size</span>{{end}}
{{define "content"}}
{{with .Data}}
<h1>Split pcap</h1>
<p class="lead">
Upload a pcap file and split it into several files by packet count or by file size.
The parts are downloaded together as a zip.
Packets are copied unchanged, and each part keeps the original file header.
</p>
{{if .Error}}<div class="error" role="alert">{{.Error}}</div>{{end}}
<form method="post" action="/split" enctype="multipart/form-data">
<label for="file">pcap file <span class="hint">classic pcap, up to {{.MaxUpload}}. Convert pcapng with <code>editcap -F pcap</code></span></label>
<input id="file" name="file" type="file" accept=".pcap,.cap,.dmp,application/vnd.tcpdump.pcap" required>
<section class="widget">
<div class="widget-title"><h2>Split</h2></div>
<div class="widget-content">
<p class="note">
The parts are downloaded together as a zip. Packets are copied unchanged, and each part keeps the original file header.
</p>
<fieldset class="modes">
<legend>Split by</legend>
<label class="check">
<input type="radio" name="mode" value="packets"{{if eq .Form.Mode "packets"}} checked{{end}}>
At most
<input name="packets" class="num" inputmode="numeric" value="{{.Form.Packets}}" aria-label="Packets per file">
packets per file
</label>
<label class="check">
<input type="radio" name="mode" value="size"{{if eq .Form.Mode "size"}} checked{{end}}>
At most
<input name="size" class="num" inputmode="decimal" value="{{.Form.Size}}" aria-label="Size per file">
<select name="unit" class="unit" aria-label="Size unit">
{{range .Units}}<option{{if eq . $.Data.Form.Unit}} selected{{end}}>{{.}}</option>{{end}}
</select>
per file
<span class="hint">1 MB = 1,000,000 bytes. A packet bigger than this gets a file to itself.</span>
</label>
</fieldset>
<label for="file">pcap file <span class="hint">classic pcap, up to {{.MaxUpload}}. Convert pcapng with <code>editcap -F pcap</code></span></label>
<input id="file" name="file" type="file" accept=".pcap,.cap,.dmp,application/vnd.tcpdump.pcap" required>
<p class="note">
At most {{.MaxParts}} output files. If the capture ends with a truncated packet, that packet is dropped.
</p>
<fieldset class="modes">
<legend>Split by</legend>
<label class="check">
<input type="radio" name="mode" value="packets"{{if eq .Form.Mode "packets"}} checked{{end}}>
At most
<input name="packets" class="num" inputmode="numeric" value="{{.Form.Packets}}" aria-label="Packets per file">
packets per file
</label>
<label class="check">
<input type="radio" name="mode" value="size"{{if eq .Form.Mode "size"}} checked{{end}}>
At most
<input name="size" class="num" inputmode="decimal" value="{{.Form.Size}}" aria-label="Size per file">
<select name="unit" class="unit" aria-label="Size unit">
{{range .Units}}<option{{if eq . $.Data.Form.Unit}} selected{{end}}>{{.}}</option>{{end}}
</select>
per file
</label>
</fieldset>
<div class="actions">
<button type="submit" class="primary">Split and download zip</button>
<p class="note">
1 MB = 1,000,000 bytes. A packet bigger than the size limit gets a file to itself.
At most {{.MaxParts}} output files. If the capture ends with a truncated packet, that packet is dropped.
</p>
<div class="actions">
<button type="submit" class="btn primary">Split and download zip</button>
</div>
</div>
</section>
</form>
{{end}}
{{end}}
+42
View File
@@ -0,0 +1,42 @@
package web
import (
"errors"
"fmt"
"mime/multipart"
"net/http"
"path"
"strings"
)
// parseUpload parses a multipart form with a file in the "file" field. On
// failure it returns an HTTP status and a message for the page.
//
// Files bigger than 1 MB are spooled to temporary files rather than kept in
// memory; net/http removes them when the handler returns.
func (s *Server) parseUpload(w http.ResponseWriter, r *http.Request) (multipart.File, *multipart.FileHeader, int, string) {
// Allow some slack over the file size limit for the multipart framing and form fields.
r.Body = http.MaxBytesReader(w, r.Body, s.cfg.MaxUploadBytes+64<<10)
if err := r.ParseMultipartForm(1 << 20); err != nil {
var tooBig *http.MaxBytesError
if errors.As(err, &tooBig) {
return nil, nil, http.StatusRequestEntityTooLarge, "file too large; the maximum upload is " + s.maxUpload()
}
return nil, nil, http.StatusBadRequest, "bad upload: " + err.Error()
}
file, hdr, err := r.FormFile("file")
if err != nil {
return nil, nil, http.StatusBadRequest, "choose a pcap file"
}
return file, hdr, 0, ""
}
func (s *Server) maxUpload() string {
return fmt.Sprintf("%d MB", s.cfg.MaxUploadBytes/1e6)
}
// uploadStem returns the sanitized name of an uploaded file without its extension.
func uploadStem(hdr *multipart.FileHeader) string {
name := safeName(hdr.Filename, "capture.pcap")
return strings.TrimSuffix(name, path.Ext(name))
}