Skip to content

Instantly share code, notes, and snippets.

@libcrack
Created May 12, 2024 14:35
Show Gist options
  • Save libcrack/ee95712f76767dd8fdfc5b74595c94bf to your computer and use it in GitHub Desktop.
Save libcrack/ee95712f76767dd8fdfc5b74595c94bf to your computer and use it in GitHub Desktop.
PHP script to update auth details for specific vpn clients pfSense boxes
#!/usr/local/bin/php-cgi -f
# devnull@libcrack.so
# Sun Nov 24 04:22:26 CET 2019
<?php
require_once("globals.inc");
require_once("filter.inc");
require_once("util.inc");
require_once("config.inc");
require_once("service-utils.inc");
require_once("openvpn.inc");
if (count($argv) != 4) {
echo "Usage: ".basename(__FILE__)." <username> <password> <vpn_description_string>\n";
echo "\t".basename(__FILE__)." username1 myComplesPassword mullvad\n";
exit(1);
}
global $config;
$username = $argv[1];
$password = $argv[2];
$needle = $argv[3];
$config = parse_config(true);
foreach($config['openvpn']['openvpn-client'] as &$vpnclient) {
if (stristr($vpnclient['description'], $needle) !== false) {
//echo "[$count] server_addr: ".$vpnclient['server_addr']."\n";
//echo "[$count] description: ".$vpnclient['description']."\n";
//echo "[$count] username: ".$vpnclient['auth_user']."\n";
//echo "[$count] password: ".$vpnclient['auth_pass']."\n";
//echo "[$count] new user: ".$username."\n";
//echo "[$count] new pass: ".$password."\n";
$vpnclient['auth_user'] = $username;
$vpnclient['auth_pass'] = $password;
///usr/local/sbin/pfSsh.php playback svc restart openvpn client 1
//openvpn_resync_all();
if (!isset($vpnclient["disable"])){
echo "Restarting client ".$vpnclient['vpnid'].": ".$vpnclient['description']."\n";
service_control_restart("openvpn", array('vpnmode' => 'client', 'id' => $vpnclient['vpnid']));
}
}
}
write_config($needle." OpenVPN config updated");
$retval |= filter_configure();
//system_reboot_sync();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment