Skip to content

Commit

Permalink
Add new service error
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmcdonald91 committed Jun 28, 2021
1 parent 97330f0 commit 20fa287
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ define('WG_ERROR_IF_DOWN', 64);
define('WG_ERROR_IF_SYNC', 128);
define('WG_ERROR_IF_DESTROY', 256);

define('WG_ERROR_SVC_RUNNING', 1);
define('WG_ERROR_SVC_START', 2);
define('WG_ERROR_SVC_STOP', 4);
define('WG_ERROR_SVC_CREATE', 8);
define('WG_ERROR_SVC_DISABLED', 1);
define('WG_ERROR_SVC_RUNNING', 2);
define('WG_ERROR_SVC_START', 4);
define('WG_ERROR_SVC_STOP', 8);
define('WG_ERROR_SVC_CREATE', 16);

$wgg = array(
'wg' => '/usr/local/bin/wg',
Expand Down Expand Up @@ -90,6 +91,7 @@ $wgg = array(
WG_ERROR_IF_SYNC => gettext('Unable to sync WireGuard tunnel configuration with wg(8)'),
WG_ERROR_IF_DESTROY => gettext('Unable to destroy WireGuard tunnel interface')),
'service' => array(
WG_ERROR_SVC_DISABLED => gettext('WireGuard service is diabled'),
WG_ERROR_SVC_RUNNING => gettext('WireGuard service is already running'),
WG_ERROR_SVC_START => gettext('Unable to start WireGuard service'),
WG_ERROR_SVC_STOP => gettext('Unable to stop WireGuard service'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ function wg_service_cli_start($serialize = true) {

$ret_code = 0;

if (!wg_is_cli() || (!wg_is_service_enabled())) {
if (!wg_is_service_enabled()) {

$ret_code |= WG_ERROR_SVC_START;
$ret_code |= WG_ERROR_SVC_DISABLED;

wg_service_parse_errors($ret_code, $serialize);

Expand All @@ -247,6 +247,16 @@ function wg_service_cli_start($serialize = true) {

}

if (!wg_is_cli()) {

$ret_code |= WG_ERROR_SVC_START;

wg_service_parse_errors($ret_code, $serialize);

return $ret_code;

}

// Register the service environment and lock early to ensure singletons
wg_register_service_env(false);

Expand Down Expand Up @@ -380,6 +390,8 @@ function wg_restart_extra_services() {
function wg_service_daemon() {
global $wgg;

$esa = fn($s) => escapeshellarg($s);

// Re-register the service environment
wg_register_service_env(true);

Expand All @@ -389,11 +401,7 @@ function wg_service_daemon() {
// Attempt to load the kmod, required to run the service without any tunnels configured
if (!is_module_loaded($wgg['kmod'])) {

$kmod = $wgg['kmod'];

wg_escapeshellarg($kmod);

mwexec("{$wgg['kldload']} {$kmod}");
mwexec("{$wgg['kldload']} {$esa($wgg['kmod'])}");

}

Expand Down

0 comments on commit 20fa287

Please sign in to comment.