fix: WireGuard client improvements
- Updated WireGuard client to use `wg-quick` instead of `sudo wg-quick`. - Improved error handling in WireGuard client. - Added `sudo` to `wg show` command for proper permissions. - Updated example `wireguard.vsh` script to reflect changes. - Added a new `wg0.conf` file for the WireGuard configuration. - Resolved the issue where the script wasn't finding the configuration file. Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
This commit is contained in:
8
examples/develop/wireguard/wg0.conf
Normal file
8
examples/develop/wireguard/wg0.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
[Interface]
|
||||
Address = 10.10.3.0/24
|
||||
PrivateKey = wDewSiri8jlaGnUDN6SwK7QhN082U7gfX27YMGILvVA=
|
||||
[Peer]
|
||||
PublicKey = 2JEGJQ8FbajdFk0fFs/881H/D3FRjwlUxvNDZFxDeWQ=
|
||||
AllowedIPs = 10.10.0.0/16, 100.64.0.0/16
|
||||
PersistentKeepalive = 25
|
||||
Endpoint = 185.206.122.31:3241
|
||||
@@ -2,15 +2,12 @@
|
||||
|
||||
import freeflowuniverse.herolib.clients.wireguard
|
||||
import time
|
||||
|
||||
println('HIIII')
|
||||
import os
|
||||
|
||||
// Create Wireguard client
|
||||
mut wg := wireguard.get()!
|
||||
println('Hello')
|
||||
config_file_path := '~/wg1.conf'
|
||||
config_file_path := '${os.dir(@FILE)}/wg0.conf'
|
||||
|
||||
println('Before start')
|
||||
wg.start(config_file_path: config_file_path)!
|
||||
println('${config_file_path} is started')
|
||||
|
||||
@@ -19,7 +16,7 @@ time.sleep(time.second * 2)
|
||||
info := wg.show()!
|
||||
println('info: ${info}')
|
||||
|
||||
config := wg.show_config(interface_name: 'wg1')!
|
||||
config := wg.show_config(interface_name: 'wg0')!
|
||||
println('config: ${config}')
|
||||
|
||||
private_key := wg.generate_private_key()!
|
||||
@@ -28,7 +25,5 @@ println('private_key: ${private_key}')
|
||||
public_key := wg.get_public_key(private_key: private_key)!
|
||||
println('public_key: ${public_key}')
|
||||
|
||||
time.sleep(time.second * 2)
|
||||
|
||||
wg.down(config_file_path: config_file_path)!
|
||||
println('${config_file_path} is down')
|
||||
|
||||
@@ -30,7 +30,7 @@ pub mut:
|
||||
}
|
||||
|
||||
pub fn (wg WireGuard) show() !WGShow {
|
||||
cmd := 'wg show'
|
||||
cmd := 'sudo wg show'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to execute show command due to: ${res.output}')
|
||||
@@ -60,12 +60,11 @@ pub:
|
||||
}
|
||||
|
||||
pub fn (wg WireGuard) start(args StartArgs) ! {
|
||||
if os.exists(args.config_file_path) {
|
||||
if !os.exists(args.config_file_path) {
|
||||
return error('File ${args.config_file_path} does not exists.')
|
||||
}
|
||||
|
||||
cmd := 'sudo wg-quick up ${args.config_file_path}'
|
||||
println('cmd: ${cmd}')
|
||||
cmd := 'wg-quick up ${args.config_file_path}'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to execute start command due to: ${res.output}')
|
||||
@@ -79,11 +78,11 @@ pub:
|
||||
}
|
||||
|
||||
pub fn (wg WireGuard) down(args DownArgs) ! {
|
||||
if os.exists(args.config_file_path) {
|
||||
if !os.exists(args.config_file_path) {
|
||||
return error('File ${args.config_file_path} does not exists.')
|
||||
}
|
||||
|
||||
cmd := 'sudo wg-quick down ${args.config_file_path}'
|
||||
cmd := 'wg-quick down ${args.config_file_path}'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to execute down command due to: ${res.output}')
|
||||
|
||||
@@ -28,23 +28,17 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&WireGuard {
|
||||
println('Before the args get')
|
||||
mut args := args_get(args_)
|
||||
println('Before the bigger if')
|
||||
if args.name !in wireguard_global {
|
||||
println('Before the if connd')
|
||||
if args.name == 'wireguard' {
|
||||
println('Before saving')
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
println('When saving')
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
println('When loading')
|
||||
config_load(args)!
|
||||
}
|
||||
println('After all')
|
||||
}
|
||||
return wireguard_global[args.name] or {
|
||||
println(wireguard_global)
|
||||
|
||||
Reference in New Issue
Block a user