Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ formatters:
settings:
goimports:
local-prefixes:
- github.com/autobrr/qui
- github.com/autobrr/netronome

linters:
enable:
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,6 @@ NETRONOME__LIBRESPEED_TIMEOUT=60 # LibreSpeed timeout (seconds)

```bash
NETRONOME__DEFAULT_PAGE=1 # Default page number
NETRONOME__DEFAULT_PAGE_SIZE=20 # Default items per page
NETRONOME__MAX_PAGE_SIZE=100 # Maximum items per page
NETRONOME__DEFAULT_TIME_RANGE=1w # Default time range for queries
NETRONOME__DEFAULT_LIMIT=20 # Default query limit
```
Expand All @@ -811,11 +809,9 @@ NETRONOME__GEOIP_ASN_DATABASE_PATH= # Path to GeoLite2-ASN.mmdb

```bash
NETRONOME__PACKETLOSS_ENABLED=true # Enable packet loss monitoring
NETRONOME__PACKETLOSS_DEFAULT_INTERVAL=3600 # Default test interval (seconds)
NETRONOME__PACKETLOSS_DEFAULT_PACKET_COUNT=10 # Packets per test
NETRONOME__PACKETLOSS_MAX_CONCURRENT_MONITORS=10 # Max concurrent monitors
NETRONOME__PACKETLOSS_PRIVILEGED_MODE=true # Use privileged ICMP mode
NETRONOME__PACKETLOSS_RESTORE_MONITORS_ON_STARTUP=false # Restore monitors on startup
NETRONOME__PACKETLOSS_MTR_ENABLE_DNS=false # Resolve hostnames in MTR output
```

### Agent Configuration
Expand All @@ -833,7 +829,6 @@ NETRONOME__AGENT_DISK_EXCLUDES= # Comma-separated paths to exclude

```bash
NETRONOME__MONITOR_ENABLED=true # Enable system monitoring
NETRONOME__MONITOR_RECONNECT_INTERVAL=30s # Agent reconnection interval
```

### Tailscale Configuration
Expand Down Expand Up @@ -862,7 +857,6 @@ NETRONOME__TAILSCALE_DISCOVERY_PREFIX= # Hostname prefix filter
# Deprecated (for backward compatibility)
NETRONOME__TAILSCALE_PREFER_HOST=false # Prefer host mode over tsnet
NETRONOME__TAILSCALE_AGENT_ENABLED=false # Enable agent mode
NETRONOME__TAILSCALE_AGENT_ACCEPT_ROUTES=true # Accept Tailscale routes
```

</details>
Expand Down
3 changes: 0 additions & 3 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ asn_database_path = "./GeoLite2-ASN.mmdb"

[packetloss]
enabled = true
default_interval = 3600
default_packet_count = 10
max_concurrent_monitors = 10
privileged_mode = true
mtr_enable_dns = false

[monitor]
enabled = true
reconnect_interval = "30s"

[tailscale]
enabled = true
Expand Down
19 changes: 2 additions & 17 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"errors"
"fmt"
"strings"

"golang.org/x/crypto/bcrypt"
)

var (
Expand All @@ -30,19 +28,6 @@ var (
// return nil
//}

func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(bytes), nil
}

func CheckPassword(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}

// MemoryOnlyPrefix is used to mark tokens that should only exist in memory
const MemoryOnlyPrefix = "mem_"

Expand Down Expand Up @@ -70,9 +55,9 @@ func VerifyToken(signedToken, secret string) (string, error) {

if secret != "" {
parts := strings.Split(signedToken, ".")

var token, signature string

// Handle different token formats
if len(parts) == 2 {
// Regular signed token: token.signature
Expand Down
4 changes: 0 additions & 4 deletions internal/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ func getProviderEndpoints(ctx context.Context, client *http.Client, issuer strin
}, discovery.UserinfoURL, nil
}

func (c *OIDCConfig) AuthURL() string {
return c.OAuth2Config.AuthCodeURL("state")
}

func containsScope(scopes []string, target string) bool {
return slices.Contains(scopes, target)
}
Expand Down
10 changes: 0 additions & 10 deletions internal/broadcaster/broadcaster.go

This file was deleted.

107 changes: 19 additions & 88 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package config

import (
"crypto/rand"
"fmt"
"io"
"os"
Expand All @@ -14,8 +15,6 @@ import (

"github.com/BurntSushi/toml"
"github.com/rs/zerolog/log"

"github.com/autobrr/netronome/internal/utils"
)

const (
Expand Down Expand Up @@ -113,8 +112,6 @@ type PingConfig struct {

type PaginationConfig struct {
DefaultPage int `toml:"default_page" env:"DEFAULT_PAGE"`
DefaultPageSize int `toml:"default_page_size" env:"DEFAULT_PAGE_SIZE"`
MaxPageSize int `toml:"max_page_size" env:"MAX_PAGE_SIZE"`
DefaultTimeRange string `toml:"default_time_range" env:"DEFAULT_TIME_RANGE"`
DefaultLimit int `toml:"default_limit" env:"DEFAULT_LIMIT"`
}
Expand All @@ -129,13 +126,10 @@ type GeoIPConfig struct {
}

type PacketLossConfig struct {
Enabled bool `toml:"enabled" env:"PACKETLOSS_ENABLED"`
DefaultInterval int `toml:"default_interval" env:"PACKETLOSS_DEFAULT_INTERVAL"`
DefaultPacketCount int `toml:"default_packet_count" env:"PACKETLOSS_DEFAULT_PACKET_COUNT"`
MaxConcurrentMonitors int `toml:"max_concurrent_monitors" env:"PACKETLOSS_MAX_CONCURRENT_MONITORS"`
PrivilegedMode bool `toml:"privileged_mode" env:"PACKETLOSS_PRIVILEGED_MODE"`
MTREnableDNS bool `toml:"mtr_enable_dns" env:"PACKETLOSS_MTR_ENABLE_DNS"`
RestoreMonitorsOnStartup bool `toml:"restore_monitors_on_startup" env:"PACKETLOSS_RESTORE_MONITORS_ON_STARTUP"`
Enabled bool `toml:"enabled" env:"PACKETLOSS_ENABLED"`
MaxConcurrentMonitors int `toml:"max_concurrent_monitors" env:"PACKETLOSS_MAX_CONCURRENT_MONITORS"`
PrivilegedMode bool `toml:"privileged_mode" env:"PACKETLOSS_PRIVILEGED_MODE"`
MTREnableDNS bool `toml:"mtr_enable_dns" env:"PACKETLOSS_MTR_ENABLE_DNS"`
}

type AgentConfig struct {
Expand All @@ -149,8 +143,7 @@ type AgentConfig struct {
}

type MonitorConfig struct {
Enabled bool `toml:"enabled" env:"MONITOR_ENABLED"`
ReconnectInterval string `toml:"reconnect_interval" env:"MONITOR_RECONNECT_INTERVAL"`
Enabled bool `toml:"enabled" env:"MONITOR_ENABLED"`
}

type TailscaleConfig struct {
Expand Down Expand Up @@ -182,9 +175,8 @@ type TailscaleConfig struct {

// Deprecated - kept for backward compatibility
type TailscaleAgentConfig struct {
Enabled bool `toml:"enabled" env:"TAILSCALE_AGENT_ENABLED"`
AcceptRoutes bool `toml:"accept_routes" env:"TAILSCALE_AGENT_ACCEPT_ROUTES"`
Port int `toml:"port" env:"TAILSCALE_AGENT_PORT"`
Enabled bool `toml:"enabled" env:"TAILSCALE_AGENT_ENABLED"`
Port int `toml:"port" env:"TAILSCALE_AGENT_PORT"`
}

// Deprecated - kept for backward compatibility
Expand Down Expand Up @@ -264,8 +256,6 @@ func New() *Config {
},
Pagination: PaginationConfig{
DefaultPage: 1,
DefaultPageSize: 20,
MaxPageSize: 100,
DefaultTimeRange: "1w",
DefaultLimit: 20,
},
Expand All @@ -277,13 +267,10 @@ func New() *Config {
ASNDatabasePath: "",
},
PacketLoss: PacketLossConfig{
Enabled: true,
DefaultInterval: 3600,
DefaultPacketCount: 10,
MaxConcurrentMonitors: 10,
PrivilegedMode: true,
MTREnableDNS: false,
RestoreMonitorsOnStartup: false,
Enabled: true,
MaxConcurrentMonitors: 10,
PrivilegedMode: true,
MTREnableDNS: false,
},
Agent: AgentConfig{
Host: "0.0.0.0",
Expand All @@ -293,8 +280,7 @@ func New() *Config {
DiskExcludes: []string{},
},
Monitor: MonitorConfig{
Enabled: true,
ReconnectInterval: "30s",
Enabled: true,
},
Tailscale: TailscaleConfig{
Enabled: false,
Expand All @@ -311,9 +297,8 @@ func New() *Config {
DiscoveryPrefix: "",
// Deprecated fields - kept for compatibility during migration
Agent: TailscaleAgentConfig{
Enabled: false,
AcceptRoutes: true,
Port: 8200,
Enabled: false,
Port: 8200,
},
Monitor: TailscaleMonitorConfig{
AutoDiscover: true,
Expand Down Expand Up @@ -569,16 +554,6 @@ func (c *Config) loadPaginationFromEnv() {
c.Pagination.DefaultPage = page
}
}
if v := getEnv("DEFAULT_PAGE_SIZE"); v != "" {
if size, err := strconv.Atoi(v); err == nil {
c.Pagination.DefaultPageSize = size
}
}
if v := getEnv("MAX_PAGE_SIZE"); v != "" {
if size, err := strconv.Atoi(v); err == nil {
c.Pagination.MaxPageSize = size
}
}
if v := getEnv("DEFAULT_TIME_RANGE"); v != "" {
c.Pagination.DefaultTimeRange = v
}
Expand Down Expand Up @@ -610,16 +585,6 @@ func (c *Config) loadPacketLossFromEnv() {
c.PacketLoss.Enabled = enabled
}
}
if v := getEnv("PACKETLOSS_DEFAULT_INTERVAL"); v != "" {
if interval, err := strconv.Atoi(v); err == nil {
c.PacketLoss.DefaultInterval = interval
}
}
if v := getEnv("PACKETLOSS_DEFAULT_PACKET_COUNT"); v != "" {
if count, err := strconv.Atoi(v); err == nil {
c.PacketLoss.DefaultPacketCount = count
}
}
if v := getEnv("PACKETLOSS_MAX_CONCURRENT_MONITORS"); v != "" {
if max, err := strconv.Atoi(v); err == nil {
c.PacketLoss.MaxConcurrentMonitors = max
Expand All @@ -635,11 +600,6 @@ func (c *Config) loadPacketLossFromEnv() {
c.PacketLoss.MTREnableDNS = enableDNS
}
}
if v := getEnv("PACKETLOSS_RESTORE_MONITORS_ON_STARTUP"); v != "" {
if restore, err := strconv.ParseBool(v); err == nil {
c.PacketLoss.RestoreMonitorsOnStartup = restore
}
}
}

func (c *Config) loadAgentFromEnv() {
Expand Down Expand Up @@ -682,9 +642,6 @@ func (c *Config) loadMonitorFromEnv() {
c.Monitor.Enabled = enabled
}
}
if v := getEnv("MONITOR_RECONNECT_INTERVAL"); v != "" {
c.Monitor.ReconnectInterval = v
}
}

func (c *Config) loadTailscaleFromEnv() {
Expand All @@ -695,11 +652,10 @@ func (c *Config) WriteToml(w io.Writer) error {
cfg := New()
cfg.Database.Path = "netronome.db"

secret, err := utils.GenerateSecureToken(32)
if err != nil {
return fmt.Errorf("failed to generate session secret: %w", err)
}
cfg.Session.Secret = secret
// Two rand.Text() calls: this is a long-lived signing key, so keep the
// ~256 bits the old 32-byte generator gave. One call (~130 bits) is
// plenty for the per-request tokens elsewhere, but not worth shaving here.
cfg.Session.Secret = rand.Text() + rand.Text()

if isRunningInContainer() {
cfg.Server.Host = "0.0.0.0"
Expand Down Expand Up @@ -934,12 +890,6 @@ func (c *Config) WriteToml(w io.Writer) error {
if _, err := fmt.Fprintf(w, "enabled = %v\n", cfg.PacketLoss.Enabled); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "default_interval = %d # seconds between tests\n", cfg.PacketLoss.DefaultInterval); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "default_packet_count = %d # packets per test\n", cfg.PacketLoss.DefaultPacketCount); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "max_concurrent_monitors = %d\n", cfg.PacketLoss.MaxConcurrentMonitors); err != nil {
return err
}
Expand All @@ -960,9 +910,6 @@ func (c *Config) WriteToml(w io.Writer) error {
if _, err := fmt.Fprintf(w, "enabled = %v\n", cfg.Monitor.Enabled); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "reconnect_interval = \"%s\"\n", cfg.Monitor.ReconnectInterval); err != nil {
return err
}

// Tailscale section
if _, err := fmt.Fprintln(w, ""); err != nil {
Expand Down Expand Up @@ -1029,17 +976,6 @@ func (c *Config) WriteToml(w io.Writer) error {
return nil
}

func GetDefaultConfigPath() string {
if configDir, err := os.UserConfigDir(); err == nil {
configPath := filepath.Join(configDir, AppName, "config.toml")
if _, err := os.Stat(configPath); err == nil {
return configPath
}
}

return "config.toml"
}

func DefaultConfigPaths() []string {
var paths []string

Expand Down Expand Up @@ -1328,11 +1264,6 @@ func (t *TailscaleConfig) loadFromEnv() {
t.Agent.Enabled = enabled
}
}
if v := getEnv("TAILSCALE_AGENT_ACCEPT_ROUTES"); v != "" {
if accept, err := strconv.ParseBool(v); err == nil {
t.Agent.AcceptRoutes = accept
}
}
if v := getEnv("TAILSCALE_AGENT_PORT"); v != "" {
if port, err := strconv.Atoi(v); err == nil {
t.Agent.Port = port
Expand Down
Loading
Loading