Skip to content

Commit

Permalink
fix client not starting
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzYanick committed Jan 11, 2024
1 parent 2363cb4 commit 0cf4a85
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
//go:embed _bin/rathole
var filePayload []byte

const clientPath = "/tmp/stupidproxy/rathole"
const clientTmpPath = "/tmp/stupidproxy/client.toml"
const tmpPath = "/tmp/stupidproxy"
const tmpClientPath = tmpPath + "/rathole"
const tmpConfigPath = tmpPath + "/client.toml"

// http
var httpClient *http.Client
Expand All @@ -39,6 +40,12 @@ func debug(message string) {
func main() {
defer cleanup()

// mkdir tmp dir
if err := os.MkdirAll(tmpPath, 0755); err != nil {
fmt.Println(err)
return
}

server = flag.String("server", os.Getenv("STUPIDPROXY_SERVER"), "(required) Server address\n\tExample: https://example.com:8080")
token = flag.String("token", os.Getenv("STUPIDPROXY_TOKEN"), "(required) Token used to authenticate with the server")
help := flag.Bool("help", false, "Show help")
Expand Down Expand Up @@ -101,10 +108,10 @@ func main() {

func cleanup() {
fmt.Println("INFO: Exiting tunnel")
if err := os.Remove(clientTmpPath); err != nil {
if err := os.Remove(tmpConfigPath); err != nil {
fmt.Println(err)
}
if err := os.Remove(clientPath); err != nil {
if err := os.Remove(tmpClientPath); err != nil {
fmt.Println(err)
}
}
Expand Down Expand Up @@ -132,7 +139,7 @@ func get() {
clientCache = string(body)
fmt.Println("INFO: New client config received")
// print to file
if err = os.WriteFile(clientTmpPath, body, 0644); err != nil {
if err = os.WriteFile(tmpConfigPath, body, 0644); err != nil {
fmt.Println(err)
return
}
Expand All @@ -141,15 +148,15 @@ func get() {

func exportBin() {
debug("Exporting bin")
if err := os.WriteFile(clientPath, filePayload, 0755); err != nil {
if err := os.WriteFile(tmpClientPath, filePayload, 0755); err != nil {
fmt.Println(err)
return
}
}

func startBin() {
debug("Starting bin")
cmd := exec.Command(clientPath, "-c", clientTmpPath)
cmd := exec.Command(tmpClientPath, "-c", tmpConfigPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down

0 comments on commit 0cf4a85

Please sign in to comment.