Hopefully get the main server to forward requests correctly, and make the helper scripts detect their directory to determine the right binary name

This commit is contained in:
Kelvin Ly 2019-07-18 23:11:12 -04:00
parent 738f6623ec
commit 74deb5f9a1
4 changed files with 17 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
main-server main-server
*.pem *.pem
webhook_secret webhook_secret
dev-server
threefortiethofonehamster.com

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"crypto/tls"
"encoding/hex" "encoding/hex"
"flag" "flag"
"fmt" "fmt"
@ -268,6 +269,12 @@ func readWebhookKey() []byte {
return b[:len(b)-1] return b[:len(b)-1]
} }
var transportNoTlsVerify = http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
// copied from https://stackoverflow.com/questions/34724160/go-http-send-incoming-http-request-to-an-other-server-using-client-do // copied from https://stackoverflow.com/questions/34724160/go-http-send-incoming-http-request-to-an-other-server-using-client-do
func forwardRequest(port int, proxyScheme string) func(http.ResponseWriter, *http.Request) { func forwardRequest(port int, proxyScheme string) func(http.ResponseWriter, *http.Request) {
proxyHost := "0.0.0.0" + ":" + strconv.Itoa(port) proxyHost := "0.0.0.0" + ":" + strconv.Itoa(port)
@ -295,7 +302,7 @@ func forwardRequest(port int, proxyScheme string) func(http.ResponseWriter, *htt
proxyReq.Header[h] = val proxyReq.Header[h] = val
} }
resp, err := (&http.Client{}).Do(proxyReq) resp, err := (&http.Client{Transport: &transportNoTlsVerify}).Do(proxyReq)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway) http.Error(w, err.Error(), http.StatusBadGateway)
return return

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
kill `cat /tmp/main-server-pid` ./stop-server.sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# lol # lol
sleep 1 sleep 1
$DIR/main-server $DIR/main-server

View File

@ -1,3 +1,7 @@
#!/bin/bash #!/bin/bash
kill `cat /tmp/main-server-pid` SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
BASENAME=`basename $SCRIPTPATH`
echo $BASENAME
kill `cat /tmp/$BASENAME-pid`