mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-07-06 20:42:33 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 31bb2aa439 | |||
| b3caa9852c | |||
| 39248e2be6 | |||
| 9d0ef598a7 | |||
| 77b102791f | |||
| 2e0ad98a4a | |||
| b0afb7cb56 | |||
| acee3df1bc |
@@ -23,6 +23,7 @@
|
||||
- [Installation](#installation)
|
||||
- [Project Management](#project-management)
|
||||
- [Configuration](#configuration)
|
||||
- [Per-project configuration](#per-project-configuration)
|
||||
- [CLI Flags](#cli-flags)
|
||||
- [Plugin System](#plugin-system)
|
||||
- [Vim / Neovim Integration](#vim--neovim-integration)
|
||||
@@ -107,9 +108,9 @@ Spilltea organizes work into **projects**. Each project maps to a SQLite databas
|
||||
|
||||
On startup, you choose:
|
||||
|
||||
- **New project**: enter a name, stored in `~/.local/share/spilltea/projects/` by default
|
||||
- **New project**: enter a name, stored in `~/.local/share/spilltea/<name>/` by default
|
||||
- **Existing project**: pick from a list of previous projects
|
||||
- **Temporary**: no name needed, stored in `/tmp/spilltea/projects/` and will be deleted on your next reboot!
|
||||
- **Temporary**: no name needed, stored in `/tmp/spilltea/<random-id>/` and will be deleted on your next reboot!
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -118,6 +119,18 @@ Check the default configuration with all the options [here](./internal/config/de
|
||||
|
||||
Colors and styles can be customized using [ilovetui](https://github.com/anotherhadi/ilovetui), which applies theme changes across all compatible TUI applications at once.
|
||||
|
||||
### Per-project configuration
|
||||
|
||||
You can override any config value on a per-project basis by placing a `config.yaml` file inside the project directory (e.g. `~/.local/share/spilltea/projects/my-project/config.yaml`).
|
||||
|
||||
Only the keys present in that file are overridden; everything else falls back to the global config.
|
||||
|
||||
The priority order is:
|
||||
|
||||
1. Global config (`~/.config/spilltea/config.yaml`)
|
||||
2. Project config (`<project-dir>/config.yaml`)
|
||||
3. CLI flags (always win)
|
||||
|
||||
## CLI Flags
|
||||
|
||||
```
|
||||
@@ -135,6 +148,7 @@ Flags:
|
||||
--plugins-dir string path to plugins dir (overrides config)
|
||||
-p, --port int proxy port (overrides config)
|
||||
-P, --project string project name to open directly, or "tmp" for a temporary session
|
||||
--ssl-insecure skip TLS certificate verification (overrides config)
|
||||
--upstream-proxy string upstream proxy URL, e.g. http://user:pass@host:8888 (overrides config)
|
||||
-v, --version version for spilltea
|
||||
```
|
||||
|
||||
+26
-11
@@ -38,6 +38,7 @@ func main() {
|
||||
flagPort int
|
||||
flagUpstreamProxy string
|
||||
flagProject string
|
||||
flagSslInsecure bool
|
||||
flagAddDefaultPlugins bool
|
||||
flagAddDefaultConfig bool
|
||||
)
|
||||
@@ -98,18 +99,26 @@ func main() {
|
||||
}
|
||||
config.Global.Version = version
|
||||
|
||||
if flagPluginsDir != "" {
|
||||
config.Global.App.PluginsDir = flagPluginsDir
|
||||
}
|
||||
if flagHost != "" {
|
||||
config.Global.App.Host = flagHost
|
||||
}
|
||||
if flagPort != 0 {
|
||||
config.Global.App.Port = flagPort
|
||||
}
|
||||
if flagUpstreamProxy != "" {
|
||||
config.Global.App.UpstreamProxy = flagUpstreamProxy
|
||||
sslInsecureChanged := cmd.Flags().Changed("ssl-insecure")
|
||||
applyCLI := func(c *config.Config) {
|
||||
if flagPluginsDir != "" {
|
||||
c.App.PluginsDir = flagPluginsDir
|
||||
}
|
||||
if flagHost != "" {
|
||||
c.App.Host = flagHost
|
||||
}
|
||||
if flagPort != 0 {
|
||||
c.App.Port = flagPort
|
||||
}
|
||||
if flagUpstreamProxy != "" {
|
||||
c.App.UpstreamProxy = flagUpstreamProxy
|
||||
}
|
||||
if sslInsecureChanged {
|
||||
c.App.SslInsecure = flagSslInsecure
|
||||
}
|
||||
}
|
||||
applyCLI(config.Global)
|
||||
config.SetCLIOverrides(applyCLI)
|
||||
|
||||
style.Init()
|
||||
icons.Init(config.Global)
|
||||
@@ -122,6 +131,11 @@ func main() {
|
||||
if err != nil {
|
||||
return fmt.Errorf("project: %w", err)
|
||||
}
|
||||
if err := config.MergeProjectConfig(filepath.Dir(project.Path)); err != nil {
|
||||
return fmt.Errorf("project config: %w", err)
|
||||
}
|
||||
icons.Init(config.Global)
|
||||
keys.Init(config.Global)
|
||||
broker := intercept.NewBroker()
|
||||
m := appUI.New(broker, project.Name, project.Path)
|
||||
final, err := tea.NewProgram(m).Run()
|
||||
@@ -155,6 +169,7 @@ func main() {
|
||||
rootCmd.Flags().StringVar(&flagHost, "host", "", "proxy host (overrides config)")
|
||||
rootCmd.Flags().IntVarP(&flagPort, "port", "p", 0, "proxy port (overrides config)")
|
||||
rootCmd.Flags().StringVar(&flagUpstreamProxy, "upstream-proxy", "", "upstream proxy URL, e.g. http://user:pass@host:8888 (overrides config)")
|
||||
rootCmd.Flags().BoolVar(&flagSslInsecure, "ssl-insecure", false, "skip TLS certificate verification (overrides config)")
|
||||
rootCmd.Flags().StringVarP(&flagProject, "project", "P", "", `project name to open directly, or "tmp" for a temporary session`)
|
||||
rootCmd.Flags().BoolVar(&flagAddDefaultPlugins, "add-default-plugins", false, "copy built-in example plugins into the plugins dir and exit")
|
||||
rootCmd.Flags().BoolVar(&flagAddDefaultConfig, "add-default-config", false, "copy the default config file to the config path and exit")
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
"github.com/anotherhadi/spilltea/internal/icons"
|
||||
"github.com/anotherhadi/spilltea/internal/intercept"
|
||||
"github.com/anotherhadi/spilltea/internal/keys"
|
||||
appUI "github.com/anotherhadi/spilltea/internal/ui/app"
|
||||
homeUI "github.com/anotherhadi/spilltea/internal/ui/home"
|
||||
)
|
||||
@@ -34,6 +40,11 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
if m.state == rootStateHome {
|
||||
if sel, ok := msg.(homeUI.ProjectSelectedMsg); ok {
|
||||
if err := config.MergeProjectConfig(filepath.Dir(sel.Project.Path)); err != nil {
|
||||
log.Printf("project config: %v", err)
|
||||
}
|
||||
icons.Init(config.Global)
|
||||
keys.Init(config.Global)
|
||||
broker := intercept.NewBroker()
|
||||
app := appUI.New(broker, sel.Project.Name, sel.Project.Path)
|
||||
m.app = app
|
||||
|
||||
+15
-2
@@ -4,9 +4,9 @@ Spilltea organizes work into **projects**. Each project maps to a SQLite databas
|
||||
|
||||
On startup, you choose:
|
||||
|
||||
- **New project**: enter a name, stored in `~/.local/share/spilltea/projects/` by default
|
||||
- **New project**: enter a name, stored in `~/.local/share/spilltea/<name>/` by default
|
||||
- **Existing project**: pick from a list of previous projects
|
||||
- **Temporary**: no name needed, stored in `/tmp/spilltea/projects/` and will be deleted on your next reboot!
|
||||
- **Temporary**: no name needed, stored in `/tmp/spilltea/<random-id>/` and will be deleted on your next reboot!
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -15,6 +15,18 @@ Check the default configuration with all the options [here](./internal/config/de
|
||||
|
||||
Colors and styles can be customized using [ilovetui](https://github.com/anotherhadi/ilovetui), which applies theme changes across all compatible TUI applications at once.
|
||||
|
||||
### Per-project configuration
|
||||
|
||||
You can override any config value on a per-project basis by placing a `config.yaml` file inside the project directory (e.g. `~/.local/share/spilltea/projects/my-project/config.yaml`).
|
||||
|
||||
Only the keys present in that file are overridden; everything else falls back to the global config.
|
||||
|
||||
The priority order is:
|
||||
|
||||
1. Global config (`~/.config/spilltea/config.yaml`)
|
||||
2. Project config (`<project-dir>/config.yaml`)
|
||||
3. CLI flags (always win)
|
||||
|
||||
## CLI Flags
|
||||
|
||||
<!-- exec: echo '```' && go run ./cmd/spilltea -h && echo '```' -->
|
||||
@@ -33,6 +45,7 @@ Flags:
|
||||
--plugins-dir string path to plugins dir (overrides config)
|
||||
-p, --port int proxy port (overrides config)
|
||||
-P, --project string project name to open directly, or "tmp" for a temporary session
|
||||
--ssl-insecure skip TLS certificate verification (overrides config)
|
||||
--upstream-proxy string upstream proxy URL, e.g. http://user:pass@host:8888 (overrides config)
|
||||
-v, --version version for spilltea
|
||||
```
|
||||
|
||||
@@ -11,5 +11,7 @@
|
||||
# Spilltea Documentation
|
||||
|
||||
- **Version**: `{{.Cfg.Version}}`
|
||||
- **Proxy**: `{{.Cfg.App.Host}}:{{.Cfg.App.Port}}`
|
||||
- **SSL Insecure**: `{{.Cfg.App.SslInsecure}}`
|
||||
- **Repository**: `https://github.com/anotherhadi/spilltea`
|
||||
- **Sponsor this project**: `https://ko-fi.com/anotherhadi`
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ If the user **dismisses** a finding it is permanently hidden and will never reap
|
||||
|
||||
## Configuration
|
||||
|
||||
Plugin configuration is stored in a `plugins.yaml` file alongside the project database.
|
||||
Plugin configuration is stored in a `plugins.yaml` file alongside the project database and can be edited through the "Proxy" TUI page.
|
||||
Each plugin is keyed by its filename (without the `.lua` extension) and has an `enable` toggle and an optional `config` block (arbitrary YAML).
|
||||
|
||||
```yaml
|
||||
|
||||
+7
-1
@@ -1,6 +1,12 @@
|
||||
## Configuring your browser's proxy settings
|
||||
|
||||
We recommend installing **FoxyProxy** to manage your browser's proxies.
|
||||
**If you use Nix**, you can launch a pre-configured browser (LibreWolf) with the proxy and certificate already set up:
|
||||
|
||||
```sh
|
||||
nix run github:anotherhadi/spilltea#browser{{if or (ne .Cfg.App.Host "127.0.0.1") (ne .Cfg.App.Port 8080) (ne .Cfg.App.CertDir "~/.local/share/spilltea")}} --{{end}}{{if ne .Cfg.App.Host "127.0.0.1"}} --host {{.Cfg.App.Host}}{{end}}{{if ne .Cfg.App.Port 8080}} --port {{.Cfg.App.Port}}{{end}}{{if ne .Cfg.App.CertDir "~/.local/share/spilltea"}} --cert-dir {{.Cfg.App.CertDir}}{{end}}
|
||||
```
|
||||
|
||||
Otherwise, we recommend installing **FoxyProxy** to manage your browser's proxies.
|
||||
You can install it from the [Google Chrome extension store](https://chromewebstore.google.com/) or from the [Firefox extension store](https://addons.mozilla.org/en-US/firefox/extensions)
|
||||
|
||||
1. Open FoxyProxy's options, then click on `Add New Proxy` button.
|
||||
|
||||
@@ -28,6 +28,7 @@ type Config struct {
|
||||
ProxyAuth string `mapstructure:"proxy_auth"`
|
||||
MaxBodySizeMB int `mapstructure:"max_body_size_mb"`
|
||||
ExternalEditor string `mapstructure:"external_editor"`
|
||||
SslInsecure bool `mapstructure:"ssl_insecure"`
|
||||
} `mapstructure:"app"`
|
||||
|
||||
TUI struct {
|
||||
@@ -64,6 +65,43 @@ type GlobalPlugin struct {
|
||||
|
||||
var Global *Config
|
||||
|
||||
var projectCLIOverrides func(*Config)
|
||||
|
||||
// SetCLIOverrides stores a function that re-applies CLI flag overrides.
|
||||
// It is called automatically after MergeProjectConfig so that CLI flags
|
||||
// always win over both global and per-project config.
|
||||
func SetCLIOverrides(fn func(*Config)) {
|
||||
projectCLIOverrides = fn
|
||||
}
|
||||
|
||||
// MergeProjectConfig merges <projectDir>/config.yaml on top of the current
|
||||
// Global config, then re-applies any registered CLI overrides.
|
||||
// If no config.yaml exists in the project directory, this is a no-op.
|
||||
func MergeProjectConfig(projectDir string) error {
|
||||
projectConfigPath := filepath.Join(projectDir, "config.yaml")
|
||||
if _, err := os.Stat(projectConfigPath); errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
|
||||
pv := viper.New()
|
||||
pv.SetConfigFile(projectConfigPath)
|
||||
if err := pv.ReadInConfig(); err != nil {
|
||||
return fmt.Errorf("project config: %w", err)
|
||||
}
|
||||
if err := viper.MergeConfigMap(pv.AllSettings()); err != nil {
|
||||
return fmt.Errorf("merge project config: %w", err)
|
||||
}
|
||||
if err := viper.Unmarshal(Global); err != nil {
|
||||
return err
|
||||
}
|
||||
Global.App.ProxyAuth = expandEnvValue(Global.App.ProxyAuth)
|
||||
Global.App.UpstreamProxy = expandEnvValue(Global.App.UpstreamProxy)
|
||||
if projectCLIOverrides != nil {
|
||||
projectCLIOverrides(Global)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Load(path string) error {
|
||||
var defaults map[string]any
|
||||
if err := yaml.Unmarshal(defaultConfig, &defaults); err != nil {
|
||||
@@ -82,7 +120,12 @@ func Load(path string) error {
|
||||
}
|
||||
|
||||
Global = &Config{}
|
||||
return viper.Unmarshal(Global)
|
||||
if err := viper.Unmarshal(Global); err != nil {
|
||||
return err
|
||||
}
|
||||
Global.App.ProxyAuth = expandEnvValue(Global.App.ProxyAuth)
|
||||
Global.App.UpstreamProxy = expandEnvValue(Global.App.UpstreamProxy)
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteDefaultConfig(path string) error {
|
||||
@@ -106,6 +149,17 @@ func ExpandPath(p string) string {
|
||||
return p
|
||||
}
|
||||
|
||||
// expandEnvValue replaces a value starting with "$" with the corresponding
|
||||
// environment variable, enabling secrets to be kept out of config files.
|
||||
func expandEnvValue(s string) string {
|
||||
if len(s) > 1 && s[0] == '$' {
|
||||
if val := os.Getenv(s[1:]); val != "" {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func flatten(prefix string, m map[string]any) map[string]any {
|
||||
out := make(map[string]any)
|
||||
for k, v := range m {
|
||||
|
||||
@@ -4,15 +4,16 @@ app:
|
||||
cert_dir: ~/.local/share/spilltea
|
||||
project_dir: ~/.local/share/spilltea
|
||||
plugins_dir: ~/.config/spilltea/plugins
|
||||
upstream_proxy: "" # e.g. http://corporate-proxy:8888 or http://user:pass@host:8888
|
||||
proxy_auth: "" # require basic auth to use the proxy, format: user:pass (empty = disabled). Also run: chmod 600 ~/.config/spilltea/config.yaml
|
||||
upstream_proxy: "" # e.g. http://corporate-proxy:8888 or $ENV_VAR
|
||||
proxy_auth: "" # require basic auth to use the spilltea proxy, format: user:pass or $ENV_VAR (empty = disabled).
|
||||
max_body_size_mb: 50 # max response body size read into memory for large streamed responses (MB)
|
||||
external_editor: "" # override $EDITOR for external editing (e.g. nvim, code --wait)
|
||||
ssl_insecure: false # bypass TLS certificate verification (enable for self-signed cert targets)
|
||||
|
||||
intercept:
|
||||
default_intercept_enabled: true
|
||||
default_capture_response: false
|
||||
queue_size: 64 # max pending intercepted requests/responses before the proxy blocks
|
||||
queue_size: 128 # max pending intercepted requests/responses before the proxy blocks
|
||||
auto_forward_regex:
|
||||
- '\.(js|css|png|gif|ico|woff2?|ttf|svg)(\?.*)?$'
|
||||
|
||||
@@ -31,6 +32,7 @@ tui:
|
||||
keybindings:
|
||||
global:
|
||||
quit: "q,ctrl+c"
|
||||
escape: "esc,ctrl+c"
|
||||
help: "?"
|
||||
open_logs: "ctrl+g"
|
||||
toggle_sidebar: "ctrl+b"
|
||||
|
||||
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
type GlobalKeys struct {
|
||||
Quit string `mapstructure:"quit"`
|
||||
Escape string `mapstructure:"escape"`
|
||||
OpenLogs string `mapstructure:"open_logs"`
|
||||
ToggleSidebar string `mapstructure:"toggle_sidebar"`
|
||||
Help string `mapstructure:"help"`
|
||||
|
||||
@@ -41,7 +41,7 @@ func newGlobalKeyMap(cfg config.GlobalKeys) GlobalKeyMap {
|
||||
CycleFocus: binding(cfg.CycleFocus, "cycle focus"),
|
||||
CopyAs: binding(cfg.CopyAs, "copy as..."),
|
||||
Copy: binding(cfg.Copy, "copy..."),
|
||||
Escape: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
|
||||
Escape: binding(cfg.Escape, "cancel"),
|
||||
SendToReplay: binding(cfg.SendToReplay, "send to replay"),
|
||||
ScrollUp: binding(cfg.ScrollUp, "scroll up"),
|
||||
ScrollDown: binding(cfg.ScrollDown, "scroll down"),
|
||||
|
||||
@@ -120,6 +120,7 @@ func Start(broker *intercept.Broker, mgr *plugins.Manager) error {
|
||||
StreamLargeBodies: int64(cfg.MaxBodySizeMB) * 1024 * 1024,
|
||||
CaRootPath: caPath,
|
||||
Upstream: cfg.UpstreamProxy,
|
||||
SslInsecure: cfg.SslInsecure,
|
||||
}
|
||||
|
||||
p, err := goproxy.NewProxy(opts)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ func readDoc(name string) string {
|
||||
|
||||
var contentMarkdown = strings.Join([]string{
|
||||
readDoc("main.md"),
|
||||
readDoc("legal-disclaimer.md"),
|
||||
readDoc("basics.md"),
|
||||
readDoc("proxy.md"),
|
||||
readDoc("certificate.md"),
|
||||
readDoc("legal-disclaimer.md"),
|
||||
readDoc("basics.md"),
|
||||
readDoc("history.md"),
|
||||
}, "\n")
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -2,24 +2,17 @@ package intercept
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/icons"
|
||||
"github.com/anotherhadi/spilltea/internal/keys"
|
||||
)
|
||||
|
||||
type interceptKeyMap struct{ width int }
|
||||
|
||||
func iconBinding(b key.Binding, icon string) key.Binding {
|
||||
h := b.Help()
|
||||
return key.NewBinding(key.WithKeys(b.Keys()...), key.WithHelp(h.Key, icon+h.Desc))
|
||||
}
|
||||
|
||||
func (interceptKeyMap) ShortHelp() []key.Binding {
|
||||
ic := keys.Keys.Intercept
|
||||
i := icons.I
|
||||
return []key.Binding{
|
||||
iconBinding(ic.Forward, i.Forward),
|
||||
iconBinding(ic.Drop, i.Drop),
|
||||
iconBinding(ic.Edit, i.Edit),
|
||||
ic.Forward,
|
||||
ic.Drop,
|
||||
ic.Edit,
|
||||
keys.Keys.Global.Help,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ type EditorFinishedMsg struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func resolveEditor() string {
|
||||
func ResolveEditor() string {
|
||||
editor := config.Global.App.ExternalEditor
|
||||
if editor == "" {
|
||||
editor = os.Getenv("EDITOR")
|
||||
@@ -39,7 +39,7 @@ func openWithEditor(content string, callback func(string, error) tea.Msg) tea.Cm
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("editor: closing temp file: %v", err)
|
||||
}
|
||||
return tea.ExecProcess(exec.Command(resolveEditor(), tmpPath), func(err error) tea.Msg { // #nosec G204 -- editor from trusted config/$EDITOR, tmpPath from os.CreateTemp
|
||||
return tea.ExecProcess(exec.Command(ResolveEditor(), tmpPath), func(err error) tea.Msg { // #nosec G204 -- editor from trusted config/$EDITOR, tmpPath from os.CreateTemp
|
||||
defer os.Remove(tmpPath)
|
||||
return callback(tmpPath, err)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
{pkgs}: let
|
||||
defaultCertDir = "$HOME/.local/share/spilltea";
|
||||
defaultHost = "127.0.0.1";
|
||||
defaultPort = "8080";
|
||||
in
|
||||
pkgs.writeShellApplication {
|
||||
name = "spilltea-browser";
|
||||
runtimeInputs = with pkgs; [nss.tools librewolf netcat-gnu procps];
|
||||
text = ''
|
||||
CERT_DIR="${defaultCertDir}"
|
||||
HOST="${defaultHost}"
|
||||
PORT="${defaultPort}"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--cert-dir) CERT_DIR="$2"; shift 2 ;;
|
||||
--host) HOST="$2"; shift 2 ;;
|
||||
--port) PORT="$2"; shift 2 ;;
|
||||
*) echo "Unknown argument: $1"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
CERT_FILE="$CERT_DIR/mitmproxy-ca-cert.pem"
|
||||
|
||||
if [[ ! -f "$CERT_FILE" ]]; then
|
||||
echo "Certificate not found at $CERT_FILE"
|
||||
echo "Launch spilltea first, or use --cert-dir if you changed cert_dir in your config."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! pgrep -x spilltea > /dev/null 2>&1; then
|
||||
echo "spilltea is not running. Launch spilltea first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! nc -z "$HOST" "$PORT" > /dev/null 2>&1; then
|
||||
echo "Nothing is listening on $HOST:$PORT."
|
||||
echo "Is spilltea configured on that port? Use --host and --port if you changed them in your config."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROFILE=$(mktemp -d)
|
||||
trap 'rm -rf "$PROFILE"' EXIT
|
||||
|
||||
certutil -N -d sql:"$PROFILE" --empty-password
|
||||
certutil -d sql:"$PROFILE" -A -n "spilltea" -t "CT,," -i "$CERT_FILE"
|
||||
|
||||
cat > "$PROFILE/user.js" <<EOF
|
||||
user_pref("network.proxy.type", 1);
|
||||
user_pref("network.proxy.http", "$HOST");
|
||||
user_pref("network.proxy.http_port", $PORT);
|
||||
user_pref("network.proxy.ssl", "$HOST");
|
||||
user_pref("network.proxy.ssl_port", $PORT);
|
||||
user_pref("network.proxy.no_proxies_on", "");
|
||||
user_pref("network.stricttransportsecurity.preloadlist", false);
|
||||
user_pref("dom.security.https_only_mode", false);
|
||||
EOF
|
||||
|
||||
librewolf --profile "$PROFILE" --no-remote
|
||||
'';
|
||||
}
|
||||
+4
-2
@@ -2,14 +2,15 @@
|
||||
pkgs,
|
||||
buildGoApplication,
|
||||
}: let
|
||||
browser = import ./browser.nix {inherit pkgs;};
|
||||
pname = "spilltea";
|
||||
version = "0.0.6";
|
||||
version = "0.0.7";
|
||||
ldflags = ["-s" "-w" "-X main.version=${version}"];
|
||||
pkg = buildGoApplication {
|
||||
inherit pname version ldflags;
|
||||
src = ../.;
|
||||
modules = ./gomod2nix.toml;
|
||||
nativeBuildInputs = [ pkgs.installShellFiles ];
|
||||
nativeBuildInputs = [pkgs.installShellFiles];
|
||||
env.GOTOOLCHAIN = "local";
|
||||
postInstall = ''
|
||||
installShellCompletion --cmd spilltea \
|
||||
@@ -26,4 +27,5 @@
|
||||
in {
|
||||
"${pname}" = pkg;
|
||||
default = pkg;
|
||||
browser = browser;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user