2024-09-02 09:21:10 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
2024-09-16 12:23:04 +00:00
|
|
|
"errors"
|
2024-09-02 09:21:10 +00:00
|
|
|
"fmt"
|
2024-09-16 12:23:04 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-09-02 09:21:10 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Baipyrus/ProxySwitcher/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mapCmdsToStr(commands []*util.Command) string {
|
|
|
|
var output []string
|
|
|
|
|
|
|
|
for _, command := range commands {
|
|
|
|
cmdArgs := strings.Join(command.Arguments, " ")
|
|
|
|
cmdStr := fmt.Sprintf("%s %s", command.Name, cmdArgs)
|
|
|
|
output = append(output, cmdStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(output, "\n")
|
|
|
|
}
|
|
|
|
|
2024-09-12 22:16:14 +00:00
|
|
|
func Debug(cfgFile string) {
|
2024-09-16 12:23:04 +00:00
|
|
|
path, _ := filepath.Abs(cfgFile)
|
|
|
|
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
|
|
|
path = "[N/A]"
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("\nConfig:\n")
|
|
|
|
fmt.Printf("%s\n\n", path)
|
|
|
|
|
2024-09-12 21:19:57 +00:00
|
|
|
proxy, _ := ReadSystemProxy()
|
2024-09-12 21:39:02 +00:00
|
|
|
proxyServer := proxy.Server
|
|
|
|
if proxyServer == "" {
|
|
|
|
proxyServer = "[N/A]"
|
|
|
|
}
|
|
|
|
|
2024-09-16 12:23:04 +00:00
|
|
|
fmt.Println("System Proxy:")
|
2024-09-02 09:21:10 +00:00
|
|
|
fmt.Printf("Enabled: %t\n", proxy.Enabled)
|
2024-09-12 21:39:02 +00:00
|
|
|
fmt.Printf("Server: %s\n\n", proxyServer)
|
2024-09-02 09:21:10 +00:00
|
|
|
|
2024-09-12 22:16:14 +00:00
|
|
|
configs, _ := util.ReadConfigs(cfgFile)
|
2024-09-02 09:21:10 +00:00
|
|
|
for _, config := range configs {
|
|
|
|
configCmd := config.Name
|
|
|
|
// Use command instead of name, if given
|
|
|
|
if config.Cmd != "" {
|
|
|
|
configCmd = config.Cmd
|
|
|
|
}
|
|
|
|
fmt.Printf("Loading commands for '%s':\n", config.Name)
|
|
|
|
|
2024-09-08 19:46:35 +00:00
|
|
|
// Debug Proxy Set Commands
|
2024-09-02 09:21:10 +00:00
|
|
|
setCmds := generateCommands(config.Set, configCmd, "[PROXY PLACEHOLDER]")
|
|
|
|
fmt.Println("Set Commands:")
|
|
|
|
fmt.Printf("%s\n", mapCmdsToStr(setCmds))
|
|
|
|
|
2024-09-08 19:46:35 +00:00
|
|
|
// Debug Proxy Unset Commands
|
2024-09-02 09:21:10 +00:00
|
|
|
unsetCmds := generateCommands(config.Unset, configCmd, "")
|
|
|
|
fmt.Println("Unset Commands:")
|
|
|
|
fmt.Printf("%s\n\n", mapCmdsToStr(unsetCmds))
|
|
|
|
}
|
|
|
|
}
|