Add macOS support for golang proxy

This commit is contained in:
NBTX 2019-12-07 17:24:21 -06:00
parent 58ebbe7b27
commit 733c36ea50
25 changed files with 358 additions and 47 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -17,12 +17,17 @@ A simple proxy server created for [Postwoman](https://github.com/liyasthomas/pos
## Building
*These build scripts are for macOS/Linux systems. Currently, Windows build scripts have not yet been created.*
- For *NIX (Linux/macOS) systems:
- For macOS systems:
```bash
$ ./build.sh unix
$ ./build.sh darwin
```
- For Linux systems:
```bash
$ ./build.sh linux
```
- For Windows systems:
```bash
$ ./build.sh win32
$ ./build.sh windows
```

View file

@ -1,7 +1,7 @@
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 <unix|win32>"
echo "Usage: $0 <darwin|linux|windows>"
exit 3
fi
@ -13,14 +13,25 @@ PLATFORM="$1"
[ -f icons/icon_win.go ] && rm icons/icon_win.go
# Build the icon for the appropriate platform.
if [ "$PLATFORM" == "unix" ]; then
if [ "$PLATFORM" == "darwin" ] || [ "$PLATFORM" == "linux" ]; then
cat "icons/icon.png" | go run github.com/cratonica/2goarray Data icon >> icons/icon_unix.go
elif [ "$PLATFORM" == "win32" ]; then
elif [ "$PLATFORM" == "windows" ]; then
cat "icons/icon.ico" | go run github.com/cratonica/2goarray Data icon >> icons/icon_win.go
else
echo "Unknown platform: $1"
exit 3
fi
go run main.go
[ -d "out/$PLATFORM" ] || mkdir "out/"
[ -d "out/$PLATFORM" ] && rm -r "out/$PLATFORM"
mkdir "out/$PLATFORM"
cp -r "resources/$PLATFORM" "out"
if [ "$PLATFORM" == "darwin" ]; then
mkdir -p "out/darwin/PostwomanProxy.app/Contents/MacOS"
mkdir -p "out/darwin/PostwomanProxy.app/Contents/MacOS/icons"
cp icons/icon.png out/darwin/PostwomanProxy.app/Contents/MacOS/icons/
GOOS="darwin" go build -o "out/darwin/PostwomanProxy.app/Contents/MacOS/postwoman-proxy"
elif [ "$PLATFORM" == "windows" ]; then
GOOS="windows" go build -o "out/windows/postwoman-proxy.exe"
fi

9
go.mod
View file

@ -3,14 +3,15 @@ module postwoman.io/proxy
go 1.12
require (
fyne.io/fyne v1.1.2
github.com/atotto/clipboard v0.1.2
github.com/cratonica/2goarray v0.0.0-20190331194516-514510793eaa // indirect
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb // indirect
github.com/gen2brain/dlgs v0.0.0-20191023125645-8832682fb7f8 // indirect
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb
github.com/gen2brain/dlgs v0.0.0-20191023125645-8832682fb7f8
github.com/getlantern/systray v0.0.0-20191206015929-6658a36a3306
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4
github.com/markbates/pkger v0.12.8
github.com/martinlindhe/inputbox v0.0.0-20170822001701-56d473fa6ae3
github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
)

42
go.sum
View file

@ -1,12 +1,12 @@
fyne.io/fyne v1.1.2/go.mod h1:ukZVsvlHO29NK4HARH2B4rqgVqgx6WbtWKfEUOz4ZNo=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/cratonica/2goarray v0.0.0-20190331194516-514510793eaa h1:Wg+722vs7a2zQH5lR9QWYsVbplKeffaQFIs5FTdfNNo=
github.com/cratonica/2goarray v0.0.0-20190331194516-514510793eaa/go.mod h1:6Arca19mRx58CA7OWEd7Wu1NpC1rd3uDnNs6s1pj/DI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb h1:6S+TKObz6+Io2c8IOkcbK4Sz7nj6RpEVU7TkvmsZZcw=
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb/go.mod h1:wf3nKtOnQqCp7kp9xB7hHnNlZ6m3NoiOxjrB9hFRq4Y=
github.com/gen2brain/dlgs v0.0.0-20191023125645-8832682fb7f8 h1:A1aYLIvXDeTkCPrSPGDZ9gUVRvmKQo6MRWw5IjaTKPY=
github.com/gen2brain/dlgs v0.0.0-20191023125645-8832682fb7f8/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
@ -22,42 +22,44 @@ github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSl
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
github.com/getlantern/systray v0.0.0-20191206015929-6658a36a3306 h1:E2nuJCbj40KrULBPU5oymEkfdb1LUR2nZuP0XMW/geY=
github.com/getlantern/systray v0.0.0-20191206015929-6658a36a3306/go.mod h1:4yRvwNSBNJtSOi3dRLNxhG40wXg9nEwdDjX2IrGZJo8=
github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw=
github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc=
github.com/josephspurrier/goversioninfo v0.0.0-20190124120936-8611f5a5ff3f/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lxn/walk v0.0.0-20191113135339-bf589de20b3c h1:4pJw1uBKndwiBBJpcbqP1Bf90YfqTJUsHG9DVoAfIQ8=
github.com/lxn/walk v0.0.0-20191113135339-bf589de20b3c/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
github.com/lxn/win v0.0.0-20191106123917-121afc750dd3 h1:DvGEvKK/Qnhph/EgdBN9zXA7pEosgJ0k57ojII51JAo=
github.com/lxn/win v0.0.0-20191106123917-121afc750dd3/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
github.com/markbates/pkger v0.12.8 h1:4mEUzWb1HzRnxPwUevBX8g8ntsQ4rWw2R8CRB2QdZVI=
github.com/markbates/pkger v0.12.8/go.mod h1:C7e5A6bnWZT+nXkUwkvysGW7sxl/IGd63HEa6N/JY8s=
github.com/martinlindhe/inputbox v0.0.0-20170822001701-56d473fa6ae3 h1:teGYw72DnPQhz2p9tyWfPJBrgMud6TsW6SAGf/UNbrE=
github.com/martinlindhe/inputbox v0.0.0-20170822001701-56d473fa6ae3/go.mod h1:NzLiokHFxkMAoDQlhgRFNCM7PmhTzJAjenmXrYSX/oU=
github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a h1:nQcAxLK581HrmqF0TVy2GC3iFjB8X+aWGtxQ/t2uyGE=
github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a/go.mod h1:zL1p4SieQ27ZZ4V4KdVYdEcSkVl1OwNoi8xI1r5hJkc=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/srwiley/oksvg v0.0.0-20190829233741-58e08c8fe40e/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4=
github.com/srwiley/rasterx v0.0.0-20181219215540-696f7edb7a7e/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13 h1:/zi0zzlPHWXYXrO1LjNRByFu8sdGgCkj2JLDdBIB84k=
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/Knetic/govaluate.v3 v3.0.0 h1:18mUyIt4ZlRlFZAAfVetz4/rzlJs9yhN+U02F4u1AOc=
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

132
libproxy/crypto.go Normal file
View file

@ -0,0 +1,132 @@
package libproxy
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"github.com/gen2brain/dlgs"
"io/ioutil"
"log"
"math/big"
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"
)
func publicKeyOf(priv interface{}) interface{} {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
case *ecdsa.PrivateKey:
return &k.PublicKey
default:
return nil
}
}
func pemBlockOf(priv interface{}) *pem.Block {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}
case *ecdsa.PrivateKey:
b, err := x509.MarshalECPrivateKey(k)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to marshal ECDSA private key: %v", err)
os.Exit(2)
}
return &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}
default:
return nil
}
}
func CreateKeyPair() *[2]bytes.Buffer {
private, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatal(err)
}
template := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
Organization: []string{"The Postwoman Project"},
},
NotBefore: time.Now(),
// Make certificate expire after 10 years.
NotAfter: time.Now().Add(time.Hour * 24 * 3650),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
template.IPAddresses = append(template.IPAddresses, net.ParseIP("127.0.0.1"));
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKeyOf(private), private);
if err != nil {
log.Fatalf("Failed to create certificate: %s", err);
}
keypair := new([2]bytes.Buffer);
certificatePairItem := &bytes.Buffer{};
_ = pem.Encode(certificatePairItem, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes});
keypair[0] = *certificatePairItem;
privatePairItem := &bytes.Buffer{};
privBytes, _ := x509.MarshalPKCS8PrivateKey(private);
_ = pem.Encode(privatePairItem, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes });
keypair[1] = *privatePairItem;
return keypair;
}
func EnsurePrivateKeyInstalled () error {
_, err := os.Stat(GetDataPath() + "/cert.pem");
_, err = os.Stat(GetDataPath() + "/key.pem");
// If the error is that the file does not exist, create the file
// and then return no error (unless one was thrown in the process of creating the key.)
if(os.IsNotExist(err)){
encodedPEM := CreateKeyPair();
err = ioutil.WriteFile(GetDataPath() + "/cert.pem", encodedPEM[0].Bytes(), 0600);
err = ioutil.WriteFile(GetDataPath() + "/key.pem", encodedPEM[1].Bytes(), 0600);
if runtime.GOOS == "darwin" {
_ = exec.Command("open", GetDataPath()).Run();
_, _ = dlgs.Warning("Postwoman Proxy", "Postwoman needs you to install a root certificate authority (cert.pem).\nPlease double-click the certificate file to open it in Keychain Access and follow the installation and trust process.\n\nFor more information about this process and why it's required, please click the Postwoman icon in the status tray and select 'Help'.\n\nClick OK when you have installed the certificate and marked it as trusted.");
}
return err;
}
// Otherwise return any errors that may have occurred.
// (This is nil if no errors occurred.)
return err;
}
func LoadKeyPair() error {
encodedPem, _ := ioutil.ReadFile(GetDataPath() + "/cert.pem");
block, _ := pem.Decode(encodedPem);
if(block.Type != "CERTIFICATE"){
return nil;
}
//derBytes := block.Bytes;
//_, _ := x509.ParsePKCS1PrivateKey(derBytes);
return nil;
}
func GetDataPath() string {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]));
return dir + "/data";
}

View file

@ -1,4 +1,4 @@
package proxy
package libproxy
import (
"encoding/json"
@ -33,22 +33,42 @@ type Response struct {
Headers map[string]string `json:"headers"`;
}
func Initialize(initialAccessToken string, proxyURL string, onStatusChange statusChangeFunction) {
func Initialize(initialAccessToken string, proxyURL string, onStatusChange statusChangeFunction, withSSL bool) {
accessToken = initialAccessToken;
fmt.Println("Starting proxy server...");
http.HandleFunc("/", proxyHandler);
go func() {
httpServerError := http.ListenAndServe(proxyURL, nil);
if(!withSSL){
go func() {
httpServerError := http.ListenAndServe(proxyURL, nil);
if httpServerError != nil {
if httpServerError != nil {
onStatusChange("An error occurred.", false);
}
}();
onStatusChange("Listening on http://" + proxyURL + "/", true);
fmt.Println("Proxy server listening on http://" + proxyURL + "/");
}else{
onStatusChange("Checking SSL certificate...", false);
err := EnsurePrivateKeyInstalled();
if err != nil {
onStatusChange("An error occurred.", false);
}
}();
onStatusChange("Listening on http://" + proxyURL + "/", true);
fmt.Println("Proxy server listening on http://" + proxyURL + "/");
go func() {
httpServerError := http.ListenAndServeTLS(proxyURL, GetDataPath() + "/cert.pem", GetDataPath() + "/key.pem", nil);
if httpServerError != nil {
onStatusChange("An error occurred.", false);
}
}();
onStatusChange("Listening on https://" + proxyURL + "/", true);
fmt.Println("Proxy server listening on https://" + proxyURL + "/");
}
}
func GetAccessToken() string {
@ -62,7 +82,7 @@ func SetAccessToken(newAccessToken string) {
func proxyHandler(response http.ResponseWriter, request *http.Request) {
// We want to allow all types of requests to the proxy, though we only want to allow certain
// origins.
response.Header().Add("Access-Control-Allow-Origin", "*");
response.Header().Add("Access-Control-Allow-Origin", "https://postwoman.io");
response.Header().Add("Access-Control-Allow-Headers", "*");
if request.Method == "OPTIONS" {
response.WriteHeader(200);

19
main.go
View file

@ -4,11 +4,11 @@ import (
"github.com/atotto/clipboard"
"github.com/getlantern/systray"
"github.com/martinlindhe/inputbox"
"github.com/martinlindhe/notify"
"github.com/pkg/browser"
"postwoman.io/proxy/icons"
"postwoman.io/proxy/proxy"
"postwoman.io/proxy/libproxy"
"postwoman.io/proxy/notifier"
);
var mStatus *systray.MenuItem;
@ -59,8 +59,8 @@ func onReady() {
_ = browser.OpenURL("https://postwoman.io/");
case <- mCopyAccessToken.ClickedCh:
_ = clipboard.WriteAll(proxy.GetAccessToken());
notify.Notify("Postwoman", "Proxy Access Token copied...", "The Proxy Access Token has been copied to your clipboard.", "icons/icon.png");
_ = clipboard.WriteAll(libproxy.GetAccessToken());
_ = notifier.Notify("Postwoman Proxy", "Proxy Access Token copied...", "The Proxy Access Token has been copied to your clipboard.", notifier.GetIcon());
case <- mViewHelp.ClickedCh:
_ = browser.OpenURL("https://github.com/NBTX/postwoman-proxy/wiki");
@ -68,8 +68,13 @@ func onReady() {
case <- mSetAccessToken.ClickedCh:
newAccessToken, success := inputbox.InputBox("Postwoman Proxy", "Please enter the new Proxy Access Token...\n(Leave this blank to disable access checks.)", "");
if success {
proxy.SetAccessToken(newAccessToken);
notify.Notify("Postwoman", "Proxy Access Token updated...", "The Proxy Access Token has been updated.", "icons/icon.png")
libproxy.SetAccessToken(newAccessToken);
if(len(newAccessToken) == 0){
_ = notifier.Notify("Postwoman Proxy", "Proxy Access check disabled.", "**Anyone can access your proxy server!** The Proxy Access Token check has been disabled.", notifier.GetIcon());
}else{
_ = notifier.Notify("Postwoman Proxy", "Proxy Access Token updated...", "The Proxy Access Token has been updated.", notifier.GetIcon());
}
}
case <- mUpdateCheck.ClickedCh:
@ -88,7 +93,7 @@ func onExit() {
}
func runPostwomanProxy() {
proxy.Initialize("test", "postwoman-proxy.local:9159", onProxyStateChange);
libproxy.Initialize("postwoman", "127.0.0.1:9159", onProxyStateChange, true);
}
func onProxyStateChange(status string, isListening bool){

15
notifier/notifier.go Normal file
View file

@ -0,0 +1,15 @@
package notifier
import (
"os"
"path/filepath"
)
func GetIcon () string {
return GetIconPath() + "/icon.png";
}
func GetIconPath() string {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]));
return dir + "/icons";
}

View file

@ -0,0 +1,15 @@
package notifier
import (
"github.com/deckarep/gosx-notifier"
)
func Notify(appName string, title string, message string, icon string) error {
notification := gosxnotifier.NewNotification(message);
notification.Title = appName;
notification.Subtitle = title;
notification.AppIcon = icon;
notification.Sender = "io.postwoman.proxy";
_ = notification.Push();
return nil;
}

View file

@ -0,0 +1,5 @@
package notifier
func Notify(appName string, title string, message string, icon string) error {
return nil;
}

View file

@ -0,0 +1,5 @@
package notifier
func Notify(appName string, title string, message string, icon string) error {
return nil;
}

BIN
out/.DS_Store vendored Normal file

Binary file not shown.

BIN
out/darwin/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSBackgroundOnly</key>
<true/>
<key>CFBundleDisplayName</key>
<string>PostwomanProxy</string>
<key>CFBundleExecutable</key>
<string>postwoman-proxy</string>
<key>CFBundleIconFile</key>
<string>postwoman.icns</string>
<key>CFBundleIdentifier</key>
<string>io.postwoman.proxy</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>PostwomanProxy</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>10.8.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>MIT License; The Postwoman Project</string>
</dict>
</plist>

View file

@ -0,0 +1,10 @@
-----BEGIN CERTIFICATE-----
MIIBdTCCARugAwIBAgIBATAKBggqhkjOPQQDAjAgMR4wHAYDVQQKExVUaGUgUG9z
dHdvbWFuIFByb2plY3QwHhcNMTkxMjA3MjMyMTExWhcNMjkxMjA0MjMyMTExWjAg
MR4wHAYDVQQKExVUaGUgUG9zdHdvbWFuIFByb2plY3QwWTATBgcqhkjOPQIBBggq
hkjOPQMBBwNCAASQhslJnfZSuCst/Gmv4tNLvVdd9CYScZDecCB6+iWySjVHaIu9
8noBfbnPG25PzD87jhHZoWosECjYYcWrrRGqo0YwRDAOBgNVHQ8BAf8EBAMCBaAw
EwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADAPBgNVHREECDAGhwR/
AAABMAoGCCqGSM49BAMCA0gAMEUCIQDg7e2PvJhoZdkXS+KixqvvUhzzt8BppvVt
Xfg8oGKe3gIgRtmUh2Bivrc0zDjQcqHmZleHyPBQDhjQoWVnpj9862I=
-----END CERTIFICATE-----

View file

@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgsUY1DwOeq35mYKPW
B8xpT5bE7t6plRX1dhSn/ZjggjihRANCAASQhslJnfZSuCst/Gmv4tNLvVdd9CYS
cZDecCB6+iWySjVHaIu98noBfbnPG25PzD87jhHZoWosECjYYcWrrRGq
-----END PRIVATE KEY-----

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

8
pkged.go Normal file
View file

@ -0,0 +1,8 @@
package main
import "github.com/markbates/pkger"
import "github.com/markbates/pkger/pkging/mem"
var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec9031abc2301446ffcb37e735f48d990b8f37545c748ff4d6c636b921495129f9ef120517457477bddcf371380b8ceb39422df01cd391ad769561e9039fcee5da980005b98914a28cda1ef4c83bd9501c137b79677e6e80c0bff51cd25aa701ead9a440cbdd3c51d97ef9a58d834a6126f1b1c31fb7dcbd4fc83d5796bb2bb8a5100d3b28d455fd8b2cb0d296a0608b4fce02bd99a8f4ca020305fa367a6874010000ffff010000ffffa8454ef954020000`)))

BIN
resources/.DS_Store vendored Normal file

Binary file not shown.

BIN
resources/darwin/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSBackgroundOnly</key>
<true/>
<key>CFBundleDisplayName</key>
<string>PostwomanProxy</string>
<key>CFBundleExecutable</key>
<string>postwoman-proxy</string>
<key>CFBundleIconFile</key>
<string>postwoman.icns</string>
<key>CFBundleIdentifier</key>
<string>io.postwoman.proxy</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>PostwomanProxy</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>10.8.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>MIT License; The Postwoman Project</string>
</dict>
</plist>