Skip to content

Commit

Permalink
added config file parsing abilities : See readme for syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aki237 committed Nov 10, 2015
1 parent 536697b commit 7c3db21
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 7c3db21

Please sign in to comment.