2024-10-31 17:04:25 +00:00
|
|
|
//go:build windows
|
|
|
|
|
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-11-01 15:38:29 +00:00
|
|
|
"log"
|
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-24 12:40:42 +00:00
|
|
|
func Debug(cfgPath string) {
|
|
|
|
path, _ := filepath.Abs(cfgPath)
|
2024-09-16 12:23:04 +00:00
|
|
|
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
|
|
|
path = "[N/A]"
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("\nConfig:\n")
|
|
|
|
fmt.Printf("%s\n\n", path)
|
|
|
|
|
2024-11-01 15:38:29 +00:00
|
|
|
proxy, err := ReadSystemProxy()
|
2024-09-12 21:39:02 +00:00
|
|
|
proxyServer := proxy.Server
|
2024-11-01 15:38:29 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
} else if proxyServer == "" {
|
2024-09-12 21:39:02 +00:00
|
|
|
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-11-01 15:38:29 +00:00
|
|
|
configs, err := util.ReadConfigs(cfgPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
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-10-01 18:09:54 +00:00
|
|
|
setCmds := generateCommands(configCmd, config.Set, "[PROXY PLACEHOLDER]")
|
2024-09-02 09:21:10 +00:00
|
|
|
fmt.Println("Set Commands:")
|
|
|
|
fmt.Printf("%s\n", mapCmdsToStr(setCmds))
|
|
|
|
|
2024-09-08 19:46:35 +00:00
|
|
|
// Debug Proxy Unset Commands
|
2024-10-01 18:09:54 +00:00
|
|
|
unsetCmds := generateCommands(configCmd, config.Unset, "")
|
2024-09-02 09:21:10 +00:00
|
|
|
fmt.Println("Unset Commands:")
|
|
|
|
fmt.Printf("%s\n\n", mapCmdsToStr(unsetCmds))
|
|
|
|
}
|
|
|
|
}
|