This commit is contained in:
octeep 2023-05-22 17:25:01 +01:00
commit 08131d2aeb
No known key found for this signature in database
GPG key ID: 2EFF053CB733B81C
5 changed files with 15 additions and 6 deletions

View file

@ -35,4 +35,3 @@ jobs:
run: curl --proxy http://peter:hunter123@localhost:64424 http://zx2c4.com/ip | grep -q "demo.wireguard.com" run: curl --proxy http://peter:hunter123@localhost:64424 http://zx2c4.com/ip | grep -q "demo.wireguard.com"
- name: Test http with wrong password - name: Test http with wrong password
run: bash -c "! curl --proxy http://peter:wrongpass@localhost:64424 http://zx2c4.com/ip" run: bash -c "! curl --proxy http://peter:wrongpass@localhost:64424 http://zx2c4.com/ip"

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
*.sw? *.sw?
/.idea /.idea
.goreleaser.yml .goreleaser.yml
*.conf

View file

@ -34,8 +34,8 @@ anything.
``` ```
``` ```
usage: wireproxy [-h|--help] -c|--config "<value>" [-d|--daemon] usage: wireproxy [-h|--help] [-c|--config "<value>"] [-s|--silent]
[-n|--configtest] [-d|--daemon] [-v|--version] [-n|--configtest]
Userspace wireguard client for proxying Userspace wireguard client for proxying
@ -43,7 +43,9 @@ Arguments:
-h --help Print help information -h --help Print help information
-c --config Path of configuration file -c --config Path of configuration file
-s --silent Silent mode
-d --daemon Make wireproxy run in background -d --daemon Make wireproxy run in background
-v --version Print version
-n --configtest Configtest mode. Only check the configuration file for -n --configtest Configtest mode. Only check the configuration file for
validity. validity.
``` ```

View file

@ -8,6 +8,7 @@ import (
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
"github.com/octeep/wireproxy" "github.com/octeep/wireproxy"
"golang.zx2c4.com/wireguard/device"
"suah.dev/protect" "suah.dev/protect"
) )
@ -63,6 +64,7 @@ func main() {
parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying") parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying")
config := parser.String("c", "config", &argparse.Options{Help: "Path of configuration file"}) config := parser.String("c", "config", &argparse.Options{Help: "Path of configuration file"})
silent := parser.Flag("s", "silent", &argparse.Options{Help: "Silent mode"})
daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"}) daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"})
printVerison := parser.Flag("v", "version", &argparse.Options{Help: "Print version"}) printVerison := parser.Flag("v", "version", &argparse.Options{Help: "Print version"})
configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."}) configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."})
@ -114,10 +116,15 @@ func main() {
return return
} }
logLevel := device.LogLevelVerbose
if *silent {
logLevel = device.LogLevelSilent
}
// no file access is allowed from now on, only networking // no file access is allowed from now on, only networking
pledgeOrPanic("stdio inet dns") pledgeOrPanic("stdio inet dns")
tnet, err := wireproxy.StartWireguard(conf.Device) tnet, err := wireproxy.StartWireguard(conf.Device, logLevel)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -53,7 +53,7 @@ func createIPCRequest(conf *DeviceConfig) (*DeviceSetting, error) {
} }
// StartWireguard creates a tun interface on netstack given a configuration // StartWireguard creates a tun interface on netstack given a configuration
func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) { func StartWireguard(conf *DeviceConfig, logLevel int) (*VirtualTun, error) {
setting, err := createIPCRequest(conf) setting, err := createIPCRequest(conf)
if err != nil { if err != nil {
return nil, err return nil, err
@ -63,7 +63,7 @@ func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, "")) dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(logLevel, ""))
err = dev.IpcSet(setting.ipcRequest) err = dev.IpcSet(setting.ipcRequest)
if err != nil { if err != nil {
return nil, err return nil, err