mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-07-06 20:42:33 +02:00
fix: add ssl_insecure, expand values, edit keybindings, ...
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -36,11 +36,9 @@ func tickCmd() tea.Cmd {
|
||||
})
|
||||
}
|
||||
|
||||
var sidebarEntries = pageRegistry
|
||||
|
||||
var pageShortcuts = func() map[string]page {
|
||||
m := make(map[string]page, len(sidebarEntries))
|
||||
for i, e := range sidebarEntries {
|
||||
m := make(map[string]page, len(pageRegistry))
|
||||
for i, e := range pageRegistry {
|
||||
m[strconv.Itoa(i+1)] = e.id
|
||||
}
|
||||
return m
|
||||
@@ -55,6 +53,7 @@ type Model struct {
|
||||
logFile *os.File
|
||||
pluginManager *plugins.Manager
|
||||
fatalErr error
|
||||
logFileErr error
|
||||
|
||||
width int
|
||||
height int
|
||||
@@ -96,7 +95,8 @@ func New(broker *intercept.Broker, name, path string) Model {
|
||||
|
||||
d, err := db.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("db: %v", err)
|
||||
m.fatalErr = err
|
||||
return m
|
||||
}
|
||||
m.database = d
|
||||
broker.SetDB(d)
|
||||
@@ -129,6 +129,8 @@ func New(broker *intercept.Broker, name, path string) Model {
|
||||
m.logFile = lf
|
||||
log.SetOutput(lf)
|
||||
logrus.SetOutput(lf)
|
||||
} else {
|
||||
m.logFileErr = err
|
||||
}
|
||||
|
||||
return m
|
||||
@@ -138,7 +140,7 @@ func (m Model) FatalErr() error { return m.fatalErr }
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
mgr := m.pluginManager
|
||||
return tea.Batch(
|
||||
cmds := []tea.Cmd{
|
||||
intercept.WaitForRequest(m.broker),
|
||||
intercept.WaitForResponse(m.broker),
|
||||
tickCmd(),
|
||||
@@ -147,5 +149,16 @@ func (m Model) Init() tea.Cmd {
|
||||
plugins.WaitForQuit(mgr),
|
||||
findingsUI.RefreshCmd(m.database),
|
||||
func() tea.Msg { mgr.RunOnStart(); return nil },
|
||||
)
|
||||
}
|
||||
if m.logFileErr != nil {
|
||||
err := m.logFileErr
|
||||
cmds = append(cmds, func() tea.Msg {
|
||||
return notificationsUI.NotificationMsg{
|
||||
Title: "Warning",
|
||||
Body: "Could not open log file: " + err.Error(),
|
||||
Kind: notificationsUI.KindWarning,
|
||||
}
|
||||
})
|
||||
}
|
||||
return tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (m *Model) renderSidebar() string {
|
||||
var items strings.Builder
|
||||
badgeUnread := lipgloss.NewStyle().Foreground(ilovetui.S.Warning).Bold(true)
|
||||
|
||||
for i, entry := range sidebarEntries {
|
||||
for i, entry := range pageRegistry {
|
||||
selected := entry.id == m.page
|
||||
badgeStyle, textStyle := badgeNormal, textNormal
|
||||
if selected {
|
||||
|
||||
@@ -2,7 +2,6 @@ package app
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
@@ -21,6 +20,7 @@ import (
|
||||
historyUI "github.com/anotherhadi/spilltea/internal/ui/history"
|
||||
interceptUI "github.com/anotherhadi/spilltea/internal/ui/intercept"
|
||||
replayUI "github.com/anotherhadi/spilltea/internal/ui/replay"
|
||||
"github.com/anotherhadi/spilltea/internal/util"
|
||||
)
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@@ -162,23 +162,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, cmd
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
// ctrl+c always quits, even when a textarea is focused.
|
||||
if msg.String() == "ctrl+c" {
|
||||
m.pluginManager.RunOnQuit()
|
||||
return m, tea.Quit
|
||||
}
|
||||
if key.Matches(msg, keys.Keys.Global.Quit) && !m.activeIsEditing() {
|
||||
m.pluginManager.RunOnQuit()
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
if key.Matches(msg, keys.Keys.Global.OpenLogs) {
|
||||
editor := os.Getenv("EDITOR")
|
||||
if editor == "" {
|
||||
editor = "vi"
|
||||
}
|
||||
logPath := filepath.Join(filepath.Dir(m.projectPath), "logs.log")
|
||||
return m, tea.ExecProcess(exec.Command(editor, logPath), nil) // #nosec G204 G702 -- editor from trusted $EDITOR env var, logPath is a fixed path
|
||||
return m, tea.ExecProcess(exec.Command(util.ResolveEditor(), logPath), nil) // #nosec G204 G702 -- editor from trusted config/$EDITOR, logPath is a fixed path
|
||||
}
|
||||
|
||||
if !m.activeIsEditing() {
|
||||
|
||||
@@ -16,7 +16,7 @@ type parsedRequest struct {
|
||||
path string
|
||||
host string
|
||||
scheme string
|
||||
headers []header // garder header{key, value} pour compat locale
|
||||
headers []header
|
||||
body string
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ func LoadEntriesCmd(database *db.DB) tea.Cmd {
|
||||
if database == nil {
|
||||
return EntriesLoadedMsg{}
|
||||
}
|
||||
entries, _ := database.ListEntries()
|
||||
entries, err := database.ListEntries()
|
||||
if err != nil {
|
||||
log.Printf("history: load entries: %v", err)
|
||||
}
|
||||
return EntriesLoadedMsg{Entries: entries}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,13 +318,14 @@ func (m Model) renderHelpLine() string {
|
||||
}
|
||||
|
||||
var parts []string
|
||||
escKey := keys.Keys.Global.Escape.Help().Key
|
||||
if fs == list.Filtering {
|
||||
parts = append(parts, item("enter", "apply filter"))
|
||||
parts = append(parts, item("esc", "cancel"))
|
||||
parts = append(parts, item(escKey, "cancel"))
|
||||
} else {
|
||||
parts = append(parts, item("↑/↓", "navigate"))
|
||||
if fs == list.FilterApplied {
|
||||
parts = append(parts, item("esc", "clear filter"))
|
||||
parts = append(parts, item(escKey, "clear filter"))
|
||||
} else {
|
||||
parts = append(parts, binding(k.Filter))
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
ilovetui "github.com/anotherhadi/ilovetui"
|
||||
"github.com/anotherhadi/spilltea/internal/keys"
|
||||
"github.com/anotherhadi/spilltea/internal/ui/components/teapot"
|
||||
)
|
||||
|
||||
@@ -70,7 +71,8 @@ func (m Model) renderNamingPanel() string {
|
||||
Width(panelW).
|
||||
Render(label + "\n" + inputLine)
|
||||
|
||||
hint := ilovetui.S.Faint.Render("[enter] confirm [esc] cancel")
|
||||
escKey := keys.Keys.Global.Escape.Help().Key
|
||||
hint := ilovetui.S.Faint.Render("[enter] confirm [" + escKey + "] cancel")
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(center(iw, panel))
|
||||
|
||||
@@ -5,10 +5,14 @@ import (
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -99,24 +103,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg.Button {
|
||||
case tea.MouseWheelUp:
|
||||
if msg.Mod.Contains(tea.ModShift) {
|
||||
m.requestViewport.ScrollLeft(6)
|
||||
m.responseViewport.ScrollLeft(6)
|
||||
m.scrollBothViewports(true)
|
||||
} else {
|
||||
m.scrollFocusedViewportVertical(-1)
|
||||
}
|
||||
case tea.MouseWheelDown:
|
||||
if msg.Mod.Contains(tea.ModShift) {
|
||||
m.requestViewport.ScrollRight(6)
|
||||
m.responseViewport.ScrollRight(6)
|
||||
m.scrollBothViewports(false)
|
||||
} else {
|
||||
m.scrollFocusedViewportVertical(1)
|
||||
}
|
||||
case tea.MouseWheelLeft:
|
||||
m.requestViewport.ScrollLeft(6)
|
||||
m.responseViewport.ScrollLeft(6)
|
||||
m.scrollBothViewports(true)
|
||||
case tea.MouseWheelRight:
|
||||
m.requestViewport.ScrollRight(6)
|
||||
m.responseViewport.ScrollRight(6)
|
||||
m.scrollBothViewports(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +327,16 @@ func (m *Model) setFocusedViewport(vp viewport.Model) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) scrollBothViewports(left bool) {
|
||||
if left {
|
||||
m.requestViewport.ScrollLeft(6)
|
||||
m.responseViewport.ScrollLeft(6)
|
||||
} else {
|
||||
m.requestViewport.ScrollRight(6)
|
||||
m.responseViewport.ScrollRight(6)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) scrollFocusedViewportVertical(delta int) {
|
||||
vp := m.focusedViewport()
|
||||
vp.SetYOffset(vp.YOffset() + delta)
|
||||
@@ -403,11 +413,27 @@ func doSend(entry Entry) (responseRaw string, statusCode int, err error) {
|
||||
}
|
||||
req.Header = headers
|
||||
|
||||
tlsCfg := &tls.Config{InsecureSkipVerify: config.Global.App.SslInsecure} // #nosec G402 -- controlled by ssl_insecure config
|
||||
if !config.Global.App.SslInsecure {
|
||||
if certPool, err := x509.SystemCertPool(); err == nil {
|
||||
caPath := filepath.Join(config.ExpandPath(config.Global.App.CertDir), "mitmproxy-ca-cert.pem")
|
||||
if pem, err := os.ReadFile(caPath); err == nil {
|
||||
certPool.AppendCertsFromPEM(pem)
|
||||
}
|
||||
tlsCfg.RootCAs = certPool
|
||||
}
|
||||
}
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: tlsCfg,
|
||||
}
|
||||
if up := config.Global.App.UpstreamProxy; up != "" {
|
||||
if proxyURL, err := url.Parse(up); err == nil {
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
}
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // #nosec G402 -- intentional for replay feature
|
||||
},
|
||||
Timeout: 30 * time.Second,
|
||||
Transport: transport,
|
||||
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user