Skip to content

Instantly share code, notes, and snippets.

@zedug
Last active February 22, 2022 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zedug/b21b820a3b8cb57b262e34b6f2b507da to your computer and use it in GitHub Desktop.
Save zedug/b21b820a3b8cb57b262e34b6f2b507da to your computer and use it in GitHub Desktop.
Script to restart OpenVPN client on pfSense 2.6.0
#!/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