diff --git a/debug/main.py b/debug/main.py index 232b450..d7a3ffc 100644 --- a/debug/main.py +++ b/debug/main.py @@ -54,13 +54,13 @@ def test_socks5_with_http_no_auth(): def test_socks5_with_http_with_file_auth(): - #assert requests.get( - # "http://127.0.0.1:8080", - # proxies={ - # "http": "socks5://sulcud:password@127.0.0.1:9050", - # "https": "socks5://sulcud:password@127.0.0.1:9050" - # } - #) + # assert requests.get( + # "http://127.0.0.1:8000", + # proxies={ + # "http": "socks5://sulcud:password@127.0.0.1:9050", + # "https": "socks5://sulcud:password@127.0.0.1:9050" + # } + # ) assert requests.get( "https://google.com", proxies={ @@ -77,8 +77,8 @@ def main(): # test_socks5_with_http_no_auth() - test_http_with_http_no_auth() -# test_socks5_with_http_with_file_auth() + #test_http_with_http_no_auth() + test_socks5_with_http_with_file_auth() if __name__ == '__main__': diff --git a/driver.go b/driver.go index 4c3a355..c04db65 100644 --- a/driver.go +++ b/driver.go @@ -19,7 +19,7 @@ var ( func authScript(username, password []byte) []byte { bytecode, _ := assembler.Assemble( ast3.Program{ - ast3.Call{ + &ast3.Call{ Function: &ast3.Selector{ X: &ast3.Identifier{ Symbol: "-driver", @@ -45,7 +45,7 @@ func authScript(username, password []byte) []byte { func inboundScript(address []byte) []byte { bytecode, _ := assembler.Assemble( ast3.Program{ - ast3.Call{ + &ast3.Call{ Function: &ast3.Selector{ X: &ast3.Identifier{ Symbol: "-driver", @@ -68,7 +68,7 @@ func inboundScript(address []byte) []byte { func outboundScript(address []byte) []byte { bytecode, _ := assembler.Assemble( ast3.Program{ - ast3.Call{ + &ast3.Call{ Function: &ast3.Selector{ X: &ast3.Identifier{ Symbol: "-driver", @@ -91,7 +91,7 @@ func outboundScript(address []byte) []byte { func listenScript(address []byte) []byte { bytecode, _ := assembler.Assemble( ast3.Program{ - ast3.Call{ + &ast3.Call{ Function: &ast3.Selector{ X: &ast3.Identifier{ Symbol: "-driver", @@ -114,7 +114,7 @@ func listenScript(address []byte) []byte { func acceptScript(address []byte) []byte { bytecode, _ := assembler.Assemble( ast3.Program{ - ast3.Call{ + &ast3.Call{ Function: &ast3.Selector{ X: &ast3.Identifier{ Symbol: "-driver", @@ -238,23 +238,27 @@ func (d *Driver) Accept(address string) error { return nil } -func (r *runner) loadDriver(script string) (*Driver, error) { +func (r *runner) loadDriver(scriptPath string) (*Driver, error) { + scriptContents, readError := os.ReadFile(scriptPath) + if readError != nil { + return nil, readError + } d := &Driver{ plasma: initializeVM(), } // Setup the names used by the script - _, errorChannel, _ := d.plasma.ExecuteString(script) + _, errorChannel, _ := d.plasma.ExecuteString(string(scriptContents)) // if err := <-errorChannel; err != nil { - return nil, errors.New("driver script execution error") + return nil, err } return d, nil } func initializeVM() *vm.Plasma { plasma := vm.NewVM(os.Stdin, os.Stdout, os.Stderr) - plasma.Load("-driver", func(_ *vm.Plasma) *vm.Value { return plasma.None() }) + plasma.Load("-driver", func(_ *vm.Plasma) *vm.Value { return plasma.Value() }) plasma.Load("set_auth", func(p *vm.Plasma) *vm.Value { return p.NewBuiltInFunction( diff --git a/go.mod b/go.mod index 30fd4c8..2d12939 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/gorilla/websocket v1.5.0 - github.com/shoriwe/gplasma v1.0.1 + github.com/shoriwe/gplasma v1.0.2 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 golang.org/x/net v0.0.0-20210908191846-a5e095526f91 gopkg.in/elazarl/goproxy.v1 v1.0.0-20180725130230-947c36da3153 diff --git a/go.sum b/go.sum index a709a68..2d13ea8 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= github.com/shoriwe/gplasma v1.0.1 h1:q4peogYDCTSWrSKWNP8+OLvmDWMdEeS7wsT3hF69EOc= github.com/shoriwe/gplasma v1.0.1/go.mod h1:f9gs3jQQMWvY+XCbKe1oB7xpiJSuU5FjKQvP9aNs2Ko= +github.com/shoriwe/gplasma v1.0.2 h1:M3+Q6WzYjxVwoCpq6mZWpufLV42SB88ViSFnzC3h4QE= +github.com/shoriwe/gplasma v1.0.2/go.mod h1:f9gs3jQQMWvY+XCbKe1oB7xpiJSuU5FjKQvP9aNs2Ko= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/net v0.0.0-20210908191846-a5e095526f91 h1:E8wdt+zBjoxD3MA65wEc3pl25BsTi7tbkpwc4ANThjc= diff --git a/sample-config/configs/sample.yaml b/sample-config/configs/sample.yaml index 92f51d9..d47f813 100644 --- a/sample-config/configs/sample.yaml +++ b/sample-config/configs/sample.yaml @@ -20,8 +20,8 @@ services: network: tcp address: 127.0.0.1:9050 filters: - #inbound: filter - #outbound: filter + # inbound: filter + outbound: filter listen: filter accept: filter protocol: diff --git a/sample-config/scripts/auth.pm b/sample-config/scripts/auth.pm index 6e16b58..371b95c 100644 --- a/sample-config/scripts/auth.pm +++ b/sample-config/scripts/auth.pm @@ -1,8 +1,8 @@ def basic_login(username, password) if username == "sulcud" and password == "password" - return True + return true end - return False + return false end set_auth(basic_login) \ No newline at end of file diff --git a/sample-config/scripts/filter.pm b/sample-config/scripts/filter.pm index e500b2f..07d848e 100644 --- a/sample-config/scripts/filter.pm +++ b/sample-config/scripts/filter.pm @@ -1,10 +1,10 @@ def no_localhost(address) if "127.0.0.1" in address - return False + return false elif "localhost" in address return false end - return True + return true end set_inbound(no_localhost) diff --git a/vendor/github.com/shoriwe/gplasma/pkg/vm/symbol-table.go b/vendor/github.com/shoriwe/gplasma/pkg/vm/symbol-table.go index 7246969..c0b9018 100644 --- a/vendor/github.com/shoriwe/gplasma/pkg/vm/symbol-table.go +++ b/vendor/github.com/shoriwe/gplasma/pkg/vm/symbol-table.go @@ -6,7 +6,7 @@ import ( ) var ( - SymbolNotFoundError = fmt.Errorf("symbol not found") + SymbolNotFoundError = "symbol not found: %s" ) type ( @@ -50,7 +50,7 @@ func (symbols *Symbols) Get(name string) (*Value, error) { return value, nil } } - return nil, SymbolNotFoundError + return nil, fmt.Errorf(SymbolNotFoundError, name) } func (symbols *Symbols) Del(name string) error { @@ -58,7 +58,7 @@ func (symbols *Symbols) Del(name string) error { defer symbols.mutex.Unlock() _, found := symbols.values[name] if !found { - return SymbolNotFoundError + return fmt.Errorf(SymbolNotFoundError, name) } delete(symbols.values, name) return nil diff --git a/vendor/github.com/shoriwe/gplasma/pkg/vm/value.go b/vendor/github.com/shoriwe/gplasma/pkg/vm/value.go index 199082b..8a5a8ef 100644 --- a/vendor/github.com/shoriwe/gplasma/pkg/vm/value.go +++ b/vendor/github.com/shoriwe/gplasma/pkg/vm/value.go @@ -151,7 +151,7 @@ func (value *Value) Get(symbol string) (*Value, error) { defer value.mutex.Unlock() onDemand, found := value.onDemand[symbol] if !found { - return nil, SymbolNotFoundError + return nil, fmt.Errorf(SymbolNotFoundError, symbol) } result = onDemand(value) value.vtable.Set(symbol, result) diff --git a/vendor/modules.txt b/vendor/modules.txt index 03f3b84..41bb8e2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -5,7 +5,7 @@ # github.com/gorilla/websocket v1.5.0 ## explicit; go 1.12 github.com/gorilla/websocket -# github.com/shoriwe/gplasma v1.0.1 +# github.com/shoriwe/gplasma v1.0.2 ## explicit; go 1.18 github.com/shoriwe/gplasma/pkg/ast github.com/shoriwe/gplasma/pkg/ast2