Last active
February 22, 2022 08:14
-
-
Save zedug/b21b820a3b8cb57b262e34b6f2b507da to your computer and use it in GitHub Desktop.
Script to restart OpenVPN client on pfSense 2.6.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php | |
# script based on https://gist.github.com/patricknwn/4acd813f43ac7786ca6a6fe71419ef17 | |
# verified to work for OpenVPN clients in pfSense 2.6.0 | |
# use at your own risk | |
<?php | |
# Preload | |
require_once('service-utils.inc'); | |
require_once("openvpn.inc"); | |
# Init | |
function fubar($reason) {print $reason . "\n"; exit(1);} | |
$xml=simplexml_load_file("/cf/conf/config.xml") or fubar("Error: Cannot load config.xml"); | |
$found = false; | |
$sleeptime = 20; | |
# OpenVPN | |
foreach($xml->openvpn->{'openvpn-client'} as $vpn) { | |
$desc = html_entity_decode((string)$vpn->description); | |
print "Found OpenVPN: $desc\n"; | |
print "Restarting VPN with ID " . $vpn->vpnid . "\n"; | |
# code figured out from /etc/inc/status_services.inc | |
openvpn_restart_by_vpnid('client', $vpn->vpnid); | |
print "Sleep for a few seconds while the service restarts before proceeding to the next service (if any)\n"; | |
sleep($sleeptime); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment