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:
2025-02-02 14:59:05 +02:00
parent 7bd997e368
commit c27fcc6983
4 changed files with 16 additions and 20 deletions

View File

@@ -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}')

View File

@@ -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)