diff --git a/Readme.md b/Readme.md index e3069ad..4658fd8 100644 --- a/Readme.md +++ b/Readme.md @@ -21,3 +21,26 @@ If the network traffic is to be monitored : add a -v to the command. THis make l If a LAN IP is assigned to the host PC ,say 192.168.1.100, then proGY can be run in that address, thus accessible to all the devices in the network. +Actually I got sick of the commandline arguments. So write a config file ".progy" in json format that conatains the +following ... + +```Json +{ + "listenaddress":"[local_listen_address]:[port]", + "remoteproxyaddress":"[remote_proxy_address]:[remote_proxy_port]", + "username":"[remote_proxy_username]", + "password":"[remote_proxy_password]", + "verbose":[true or false without quotes] +} +``` + +### Example +```Json +{ + "listenaddress":"127.0.0.1:9999", + "remoteproxyaddress":"10.8.8.90:80", + "username":"alanthick", + "password":"canadian", + "verbose":true +} +``` diff --git a/main.go b/main.go index 1d69c93..37ea966 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,22 @@ import ( "flag" "fmt" "io" + "io/ioutil" "os" "strings" "net" + "encoding/json" b64 "encoding/base64" ) +type Config struct{ + Listenaddress string + Remoteproxyaddress string + Username string + Password string + Verbose bool +} + //A proxy represents a pair of connections and their state type proxy struct { sentBytes uint64 @@ -34,7 +44,18 @@ var nagles = flag.Bool("n", false, "disable nagles algorithm") //Main function to start the server func main() { + home := os.Getenv("HOME") flag.Parse() + content,err := ioutil.ReadFile(home+"/.progy") + if (err != nil){ + fmt.Println("Unable to open config file : Using defaults",err) + } + var conf Config + err = json.Unmarshal(content,&conf) + *localAddr = conf.Listenaddress + *remoteAddr = conf.Remoteproxyaddress + *authpair = conf.Username+":"+conf.Password + *verbose = conf.Verbose fmt.Printf("Proxying from %v to %v\n", *localAddr, *remoteAddr) laddr, err := net.ResolveTCPAddr("tcp", *localAddr) check(err)