Skip to content

Commit 83fa92b

Browse files
TMHSDigitalclaude
andcommitted
TUI: add Auto Rate, Max Duration and Retry Inconclusive fields (#274)
The form had no fields for -auto-rate, -max-duration or -retry-inconclusive, so TUI users had to switch to the CLI for them. - Three formFields entries: Auto Rate and Retry Inconclusive toggles, and a Max Duration text field that takes a Go duration (blank means no budget). They are seeded from flags, SUBENUM_* and the config file like the other fields, and saved for the next session. - formValues.options maps AutoRate, RetryInconclusive and MaxDuration; beginScan turns MaxDuration into the deadline when the scan starts. A negative duration gets Validate's shared message. - The label column is 20 wide to fit "Retry Inconclusive:". - The drift guards drop these three from the TUI's unmapped list and from tuiOmittedFlags. Passive sources and -permute stay CLI-only for now: they run around the scan rather than inside the engine, so the TUI needs new pre- and post-scan stages for them. Refs #274 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4b22c95 commit 83fa92b

7 files changed

Lines changed: 129 additions & 39 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-u
593593

594594
<img src="docs/assets/tui-form.png" alt="subenum interactive TUI" width="640"/>
595595

596-
Flags and a domain given with `-tui` fill the form, so a prepared command line opens ready to run: `./subenum -tui example.com -w big.txt -r resolvers.txt`. The form takes one wordlist (the first `-w`), and `-tui` warns about any flag it has no field for. The **Resolver Pool** and **Rate/Resolver** fields are `-r` and `-rate-per-resolver`; the pool is not used with Simulate on.
596+
Flags and a domain given with `-tui` fill the form, so a prepared command line opens ready to run: `./subenum -tui example.com -w big.txt -r resolvers.txt`. The form takes one wordlist (the first `-w`), and `-tui` warns about any flag it has no field for. The **Resolver Pool** and **Rate/Resolver** fields are `-r` and `-rate-per-resolver`; the pool is not used with Simulate on. **Auto Rate**, **Max Duration** (blank for none, or a duration such as `20m`) and **Retry Inconclusive** are `-auto-rate`, `-max-duration` and `-retry-inconclusive`.
597597

598598
### Go library
599599

‎internal/tui/config.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"strings"
8+
"time"
89
)
910

1011
type savedConfig struct {
@@ -30,6 +31,20 @@ type savedConfig struct {
3031
Force bool `json:"force"`
3132
Recursive bool `json:"recursive"`
3233
NoAbort bool `json:"no_abort"`
34+
// AutoRate, MaxDuration and RetryInconclusive are -auto-rate,
35+
// -max-duration (as typed, e.g. "20m") and -retry-inconclusive (#274).
36+
AutoRate bool `json:"auto_rate,omitempty"`
37+
MaxDuration string `json:"max_duration,omitempty"`
38+
RetryInconclusive bool `json:"retry_inconclusive,omitempty"`
39+
}
40+
41+
// durationText is how a max duration is saved: "" for none, so the form
42+
// shows its placeholder again, else the duration as Go prints it.
43+
func durationText(d time.Duration) string {
44+
if d <= 0 {
45+
return ""
46+
}
47+
return d.String()
3348
}
3449

3550
func configPath() (string, error) {
@@ -85,6 +100,10 @@ func saveConfig(fv formValues) error {
85100
Force: fv.force,
86101
Recursive: fv.recursive,
87102
NoAbort: fv.noAbort,
103+
104+
AutoRate: fv.autoRate,
105+
MaxDuration: durationText(fv.maxDuration),
106+
RetryInconclusive: fv.retryIncon,
88107
}
89108
data, err := json.MarshalIndent(sc, "", " ")
90109
if err != nil {

‎internal/tui/form.go‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77
"strconv"
88
"strings"
9+
"time"
910

1011
"charm.land/bubbles/v2/textinput"
1112
tea "charm.land/bubbletea/v2"
@@ -35,12 +36,15 @@ const (
3536
fieldRecursive
3637
fieldDepth // only reachable when Recursive is ON
3738
fieldRate
39+
fieldAutoRate // -auto-rate (#274)
3840
fieldMaxQueries
41+
fieldMaxDuration // -max-duration (#274)
3942
fieldExclude
4043
fieldOutput
4144
fieldFormat
4245
fieldForce
4346
fieldNoAbort
47+
fieldRetryIncon // -retry-inconclusive (#274)
4448
fieldCount
4549
)
4650

@@ -102,8 +106,12 @@ var formFields = [fieldCount]formField{
102106
saved: func(c *savedConfig) any { return &c.Depth }},
103107
fieldRate: {setting: scan.SettingRate, kind: textField, placeholder: "0 = unlimited", def: "0",
104108
saved: func(c *savedConfig) any { return &c.Rate }},
109+
fieldAutoRate: {label: "Auto Rate", flag: "auto-rate", kind: toggleField,
110+
saved: func(c *savedConfig) any { return &c.AutoRate }},
105111
fieldMaxQueries: {setting: scan.SettingMaxQueries, kind: textField, placeholder: "0 = unlimited", def: "0",
106112
saved: func(c *savedConfig) any { return &c.MaxQueries }},
113+
fieldMaxDuration: {setting: scan.SettingMaxDuration, kind: textField, placeholder: "optional, e.g. 20m",
114+
saved: func(c *savedConfig) any { return &c.MaxDuration }},
107115
fieldExclude: {setting: scan.SettingExclude, kind: textField, placeholder: "optional, e.g. vpn.example.com,*.corp.example.com",
108116
saved: func(c *savedConfig) any { return &c.Exclude }},
109117
fieldOutput: {label: "Output File", flag: "o", kind: textField, placeholder: "optional, e.g. results.txt",
@@ -114,6 +122,8 @@ var formFields = [fieldCount]formField{
114122
saved: func(c *savedConfig) any { return &c.Force }},
115123
fieldNoAbort: {label: "No Abort", flag: "no-abort", kind: toggleField,
116124
saved: func(c *savedConfig) any { return &c.NoAbort }},
125+
fieldRetryIncon: {label: "Retry Inconclusive", flag: "retry-inconclusive", kind: toggleField,
126+
saved: func(c *savedConfig) any { return &c.RetryInconclusive }},
117127
}
118128

119129
// name is the field's row label.
@@ -171,7 +181,7 @@ func (f formField) set(c *savedConfig, v string) {
171181
var (
172182
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("86"))
173183
blurredStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))
174-
labelStyle = lipgloss.NewStyle().Width(18)
184+
labelStyle = lipgloss.NewStyle().Width(20) // fits "Retry Inconclusive:"
175185
titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("86")).MarginBottom(1)
176186
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("196"))
177187
hintStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).MarginTop(1)
@@ -310,7 +320,9 @@ func (m formModel) View() string {
310320
for f, spec := range formFields {
311321
if !m.shown(f) {
312322
gate := formFields[spec.gate].name()
313-
b.WriteString(dimmedRow.Render(fmt.Sprintf(" %-20s(enable %s)", spec.name()+":", gate)) + "\n")
323+
// The label's width plus the "> " of a text field, so the hint
324+
// lines up with the values.
325+
b.WriteString(dimmedRow.Render(fmt.Sprintf(" %-22s(enable %s)", spec.name()+":", gate)) + "\n")
314326
continue
315327
}
316328
var content string
@@ -422,6 +434,13 @@ func (m *formModel) validate() (formValues, string) {
422434
rate := num(fieldRate, "Rate", 0) // blank means unlimited
423435
maxQueries := num(fieldMaxQueries, "Max queries", 0) // blank means unlimited
424436
ratePerResolver := num(fieldRatePerResolver, formFields[fieldRatePerResolver].name(), 0)
437+
var maxDuration time.Duration // blank means unlimited, as -max-duration 0
438+
if s := strings.TrimSpace(text(fieldMaxDuration)); err == nil && s != "" {
439+
var perr error
440+
if maxDuration, perr = time.ParseDuration(s); perr != nil {
441+
err = fmt.Errorf("%s must be a duration such as 20m or 1h30m, got %q", formFields[fieldMaxDuration].name(), s)
442+
}
443+
}
425444
var exclude []string // out-of-scope names, never queried (#87)
426445
for _, p := range strings.Split(text(fieldExclude), ",") {
427446
if p = strings.TrimSpace(p); p != "" {
@@ -463,9 +482,12 @@ func (m *formModel) validate() (formValues, string) {
463482
recursive: m.toggles[fieldRecursive],
464483
depth: depth,
465484
rate: rate,
485+
autoRate: m.toggles[fieldAutoRate],
466486
maxQueries: maxQueries,
487+
maxDuration: maxDuration,
467488
exclude: exclude,
468489
noAbort: m.toggles[fieldNoAbort],
490+
retryIncon: m.toggles[fieldRetryIncon],
469491
outputFile: outputFile,
470492
format: format,
471493
formatName: formatStr,
@@ -496,11 +518,14 @@ func (v formValues) options(entries []string, seed uint64) scan.Options {
496518
Recursive: v.recursive,
497519
Depth: v.depth,
498520
Rate: v.rate,
521+
AutoRate: v.autoRate,
499522
MaxQueries: v.maxQueries,
523+
MaxDuration: v.maxDuration,
500524
Exclude: v.exclude,
501525
NoAbort: v.noAbort,
502526

503-
RatePerResolver: v.ratePerResolver,
527+
RatePerResolver: v.ratePerResolver,
528+
RetryInconclusive: v.retryIncon,
504529
}
505530
}
506531

@@ -521,9 +546,12 @@ type formValues struct {
521546
recursive bool
522547
depth int
523548
rate int
549+
autoRate bool
524550
maxQueries int
551+
maxDuration time.Duration // 0 = unlimited; beginScan turns it into the deadline
525552
exclude []string
526553
noAbort bool
554+
retryIncon bool
527555
outputFile string
528556
format output.Format
529557
formatName string

‎internal/tui/form_keys_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,24 @@ func TestFormTabOrderWrapsAndSkipsGatedFields(t *testing.T) {
6262
t.Fatalf("tab visited gated field %d with its toggle off: %v", f, order)
6363
}
6464
}
65-
// 18 fields less the 2 gated ones: the 16th tab is back on the domain.
65+
// Every field less the 2 gated ones: that many tabs are back on the domain.
6666
if order[fieldCount-3] != fieldDomain {
67-
t.Fatalf("tab order %v does not wrap to the domain after 16 steps", order)
67+
t.Fatalf("tab order %v does not wrap to the domain after %d steps", order, fieldCount-2)
6868
}
6969

7070
// Backwards from the domain wraps to the last field.
7171
m = newFormModel(savedConfig{})
7272
m, _ = m.Update(keyShiftTab)
73-
if m.focus != fieldNoAbort || m.inputs[fieldDomain].Focused() {
73+
if m.focus != fieldRetryIncon || m.inputs[fieldDomain].Focused() {
7474
t.Fatalf("shift+tab from the domain: focus=%d domain focused=%v", m.focus, m.inputs[fieldDomain].Focused())
7575
}
7676
m, _ = m.Update(keyUp)
77-
if m.focus != fieldForce {
78-
t.Fatalf("up: focus=%d, want Force", m.focus)
77+
if m.focus != fieldNoAbort {
78+
t.Fatalf("up: focus=%d, want No Abort", m.focus)
7979
}
8080
m, _ = m.Update(keyDown)
81-
if m.focus != fieldNoAbort {
82-
t.Fatalf("down: focus=%d, want No Abort", m.focus)
81+
if m.focus != fieldRetryIncon {
82+
t.Fatalf("down: focus=%d, want Retry Inconclusive", m.focus)
8383
}
8484
}
8585

‎internal/tui/form_test.go‎

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,44 @@ func TestFormBuildsSharedConfig(t *testing.T) {
214214
}
215215
}
216216

217+
// TestAutoRateDurationRetryFields covers #274: Auto Rate, Max Duration and
218+
// Retry Inconclusive reach the scan options, a bad or negative duration is
219+
// rejected on the form, and the values are saved for the next session.
220+
func TestAutoRateDurationRetryFields(t *testing.T) {
221+
m := newFormModel(savedConfig{})
222+
m.inputs[fieldDomain].SetValue("example.com")
223+
m.toggles[fieldAutoRate] = true
224+
m.toggles[fieldRetryIncon] = true
225+
m.inputs[fieldMaxDuration].SetValue(" 1h30m ")
226+
vals, errStr := m.validate()
227+
if errStr != "" {
228+
t.Fatalf("validate: %s", errStr)
229+
}
230+
opts := vals.options(nil, 0)
231+
if !opts.AutoRate || !opts.RetryInconclusive || opts.MaxDuration != 90*time.Minute {
232+
t.Errorf("options: AutoRate %v, RetryInconclusive %v, MaxDuration %s", opts.AutoRate, opts.RetryInconclusive, opts.MaxDuration)
233+
}
234+
saved := savedConfig{AutoRate: vals.autoRate, MaxDuration: durationText(vals.maxDuration), RetryInconclusive: vals.retryIncon}
235+
again := newFormModel(saved)
236+
if !again.toggles[fieldAutoRate] || !again.toggles[fieldRetryIncon] || again.inputs[fieldMaxDuration].Value() != "1h30m0s" {
237+
t.Errorf("reloaded form: auto rate %v, retry %v, max duration %q", again.toggles[fieldAutoRate], again.toggles[fieldRetryIncon], again.inputs[fieldMaxDuration].Value())
238+
}
239+
240+
for value, want := range map[string]string{
241+
"soon": `Max Duration must be a duration such as 20m or 1h30m, got "soon"`,
242+
"-5m": "max duration (Max Duration) must be 0 (unlimited) or positive, got -5m0s",
243+
} {
244+
m.inputs[fieldMaxDuration].SetValue(value)
245+
if _, errStr := m.validate(); errStr != want {
246+
t.Errorf("max duration %q: got %q, want %q", value, errStr, want)
247+
}
248+
}
249+
m.inputs[fieldMaxDuration].SetValue("")
250+
if vals, errStr := m.validate(); errStr != "" || vals.maxDuration != 0 {
251+
t.Errorf("blank max duration: %q, %s; want no error and no budget", errStr, vals.maxDuration)
252+
}
253+
}
254+
217255
// TestValidateExclude covers #87 in the TUI: the Exclude field reaches the
218256
// scan config, and an invalid pattern is rejected on the form.
219257
func TestValidateExclude(t *testing.T) {
@@ -289,26 +327,29 @@ func TestFormViewRows(t *testing.T) {
289327
}
290328
}
291329
want := []string{
292-
"▸ Domain*: > e.g. example.com",
293-
" Wordlist*: > examples/sample_wordlist.txt",
294-
" Simulate: OFF",
295-
" Hit Rate (%): (enable Simulate)",
296-
" DNS Server: > 8.8.8.8:53",
297-
" Resolver Pool: > optional, file of resolver addresses",
298-
" Rate/Resolver: > 0",
299-
" Concurrency: > 100",
300-
" Timeout (ms): > 1000",
301-
" Attempts: > 1",
302-
" Record Types: > A,AAAA",
303-
" Recursive: OFF",
304-
" Depth: (enable Recursive)",
305-
" Rate (qps): > 0",
306-
" Max Names: > 0",
307-
" Exclude: > optional, e.g. vpn.example.com,*.corp.example.com",
308-
" Output File: > optional, e.g. results.txt",
309-
" Format: > text",
310-
" Force: OFF",
311-
" No Abort: OFF",
330+
"▸ Domain*: > e.g. example.com",
331+
" Wordlist*: > examples/sample_wordlist.txt",
332+
" Simulate: OFF",
333+
" Hit Rate (%): (enable Simulate)",
334+
" DNS Server: > 8.8.8.8:53",
335+
" Resolver Pool: > optional, file of resolver addresses",
336+
" Rate/Resolver: > 0",
337+
" Concurrency: > 100",
338+
" Timeout (ms): > 1000",
339+
" Attempts: > 1",
340+
" Record Types: > A,AAAA",
341+
" Recursive: OFF",
342+
" Depth: (enable Recursive)",
343+
" Rate (qps): > 0",
344+
" Auto Rate: OFF",
345+
" Max Names: > 0",
346+
" Max Duration: > optional, e.g. 20m",
347+
" Exclude: > optional, e.g. vpn.example.com,*.corp.example.com",
348+
" Output File: > optional, e.g. results.txt",
349+
" Format: > text",
350+
" Force: OFF",
351+
" No Abort: OFF",
352+
" Retry Inconclusive: OFF",
312353
}
313354
if !reflect.DeepEqual(rows, want) {
314355
t.Errorf("form rows:\n got %q\nwant %q", rows, want)
@@ -432,10 +473,7 @@ func TestWithSettingsSeedsEveryFlaggedField(t *testing.T) {
432473
func TestOptionsSetsEveryField(t *testing.T) {
433474
tuiUnmapped := map[string]string{
434475
"Pool": "beginScan sets it from the pool loadPool built",
435-
"AutoRate": "no form field yet (#274)",
436-
"RetryInconclusive": "no form field yet (#274)",
437-
"MaxDuration": "no form field yet (#274)",
438-
"Deadline": "no form field yet (#274)",
476+
"Deadline": "beginScan sets it from MaxDuration when the scan starts",
439477
"TakeoverProviders": "the form has no takeover provider file; the built-in list applies",
440478
"ResumeFrom": "the TUI does not resume interrupted scans",
441479
"ResumeParents": "the TUI does not resume interrupted scans",
@@ -445,8 +483,8 @@ func TestOptionsSetsEveryField(t *testing.T) {
445483
v := formValues{
446484
domain: "example.com", wordlist: "words.txt", dnsServer: "192.0.2.53:53", resolvers: "pool.txt",
447485
ratePerResolver: 5, concurrency: 7, timeoutMs: 700, attempts: 2, hitRate: 40, recordTypes: []string{"A"},
448-
recursive: true, depth: 3, rate: 50, maxQueries: 10, exclude: []string{"vpn.example.com"},
449-
noAbort: true, simulate: true, force: true,
486+
recursive: true, depth: 3, rate: 50, autoRate: true, maxQueries: 10, maxDuration: time.Minute,
487+
exclude: []string{"vpn.example.com"}, noAbort: true, retryIncon: true, simulate: true, force: true,
450488
}
451489
opts := reflect.ValueOf(v.options([]string{"www"}, 9))
452490
for i := range opts.NumField() {

‎internal/tui/model.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ func (m Model) beginScan(vals formValues, entries []string, skipped int, pool *d
241241

242242
opts := vals.options(entries, seed)
243243
opts.Pool = pool
244+
if vals.maxDuration > 0 {
245+
// The budget starts with the scan, as -max-duration's starts when the
246+
// CLI's scans do (#274).
247+
opts.Deadline = time.Now().Add(vals.maxDuration)
248+
}
244249
cfg := opts.Config()
245250

246251
// Persist form values for next session (best-effort).

‎main_config_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ func TestPrintConfigEffectiveAttempts(t *testing.T) {
306306
// seeds the form (-tui warns about one given on the command line).
307307
var tuiOmittedFlags = map[string]bool{
308308
"tui": true, "print-config": true, "dry-run": true, "version": true, "v": true, "progress": true, "silent": true,
309-
"simulate-zone": true, "retries": true, "show-records": true, "max-duration": true, "stats": true,
309+
"simulate-zone": true, "retries": true, "show-records": true, "stats": true,
310310
"sarif": true, "exclude-file": true, "permute": true, "ct": true, "sources": true, "axfr": true, "seeds": true, "state": true,
311311
"diff": true, "diff-records": true, "dL": true, "seed": true, "resume": true, "log-format": true,
312-
"retry-inconclusive": true, "inconclusive": true, "takeover-providers": true, "takeover-providers-only": true, "auto-rate": true,
312+
"inconclusive": true, "takeover-providers": true, "takeover-providers-only": true,
313313
}
314314

315315
// TestSettingNamesAgreeAcrossFrontEnds covers #160: every flag is either wired

0 commit comments

Comments
 (0)