diff options
Diffstat (limited to 'usr/local/sbin')
-rwxr-xr-x | usr/local/sbin/WipePackages.php | 12 | ||||
-rw-r--r-- | usr/local/sbin/gmirror_status_check.php | 15 | ||||
-rwxr-xr-x | usr/local/sbin/openvpn.attributes.sh | 2 | ||||
-rwxr-xr-x | usr/local/sbin/ovpn-linkup | 2 | ||||
-rwxr-xr-x | usr/local/sbin/pfSsh.php | 176 | ||||
-rw-r--r-- | usr/local/sbin/prefixes.php | 27 | ||||
-rwxr-xr-x | usr/local/sbin/show_filter_reload_status.php | 30 |
7 files changed, 136 insertions, 128 deletions
diff --git a/usr/local/sbin/WipePackages.php b/usr/local/sbin/WipePackages.php index d802521..44f24bf 100755 --- a/usr/local/sbin/WipePackages.php +++ b/usr/local/sbin/WipePackages.php @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ -if(!function_exists("readline")) { +if (!function_exists("readline")) { echo "\nThis script requires the readline() libary which is not present on this system."; echo "\n\nSorry, but we cannot continue.\n"; die("Need readline() library"); @@ -42,23 +42,23 @@ require("config.inc"); echo "\nThis script will wipe all installed packages off of your pfSense installation.\n"; $command = readline("\nAre you sure you would like to continue [y/N]? "); -if(strtoupper($command) == "Y" || strtoupper($command) == "YES") { +if (strtoupper($command) == "Y" || strtoupper($command) == "YES") { $rmconfig = readline("\nWould you like to remove all package configuration information as well [y/N]? "); echo "\n\nStarting package wipe... One moment please... "; exec("cd /var/db/pkg/ && find . -exec 'pkg_delete {}' \; "); exec("rm -rf /var/db/pkg/*"); - - if(strtoupper($rmconfig) == "Y" || strtoupper($rmconfig) == "YES") { + + if (strtoupper($rmconfig) == "Y" || strtoupper($rmconfig) == "YES") { echo "\nRemoving pfSense package configuration information..."; - if($config['installedpackages']['package']) { + if ($config['installedpackages']['package']) { unset($config['installedpackages']['package']); write_config("Package wipe procedure completed."); } echo "\n"; } - + echo "\npfSense package wipe procedure has completed.\n\n"; } diff --git a/usr/local/sbin/gmirror_status_check.php b/usr/local/sbin/gmirror_status_check.php index d5a55c1..4f73baf 100644 --- a/usr/local/sbin/gmirror_status_check.php +++ b/usr/local/sbin/gmirror_status_check.php @@ -9,11 +9,11 @@ modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY @@ -54,8 +54,9 @@ if (file_exists($status_file)) { sort($previous_mirror_list); if (count($previous_mirror_status) > 0) { // Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared - if ($mirror_list != $previous_mirror_list) + if ($mirror_list != $previous_mirror_list) { $notices[] = sprintf(gettext("List of mirrors changed. Old: (%s) New: (%s)"), implode(", ", $previous_mirror_list), implode(", ", $mirror_list)); + } // For each mirror, check the mirror status, notify if changed foreach ($mirror_list as $mirror) { @@ -73,11 +74,12 @@ if (file_exists($status_file)) { // Check the drive status as it may be different. asort($mirror_status[$mirror]['components']); asort($previous_mirror_status[$mirror]['components']); - if ($mirror_status[$mirror]['components'] != $previous_mirror_status[$mirror]['components']) + if ($mirror_status[$mirror]['components'] != $previous_mirror_status[$mirror]['components']) { $notices[] = sprintf(gettext("Mirror %s drive status changed. Old: (%s) New: (%s)"), $mirror, implode(", ", $previous_mirror_status[$mirror]['components']), implode(", ", $mirror_status[$mirror]['components'])); + } } } } @@ -87,7 +89,8 @@ if (count($notices)) { file_notice("gmirror", implode("\n ", $notices), "GEOM Mirror Status Change", 1); } // Write out current status if changed -if ($mirror_status != $previous_mirror_status) +if ($mirror_status != $previous_mirror_status) { file_put_contents($status_file, serialize($mirror_status)); +} ?> diff --git a/usr/local/sbin/openvpn.attributes.sh b/usr/local/sbin/openvpn.attributes.sh index b88d1df..add8e32 100755 --- a/usr/local/sbin/openvpn.attributes.sh +++ b/usr/local/sbin/openvpn.attributes.sh @@ -8,7 +8,7 @@ if [ "$script_type" = "client-connect" ]; then fi elif [ "$script_type" = "client-disconnect" ]; then command="/sbin/pfctl -a 'openvpn/$common_name' -F rules" - eval $command + eval $command /sbin/pfctl -k $ifconfig_pool_remote_ip /sbin/pfctl -K $ifconfig_pool_remote_ip fi diff --git a/usr/local/sbin/ovpn-linkup b/usr/local/sbin/ovpn-linkup index 7c9817a..1164835 100755 --- a/usr/local/sbin/ovpn-linkup +++ b/usr/local/sbin/ovpn-linkup @@ -16,6 +16,6 @@ if [ "${dev_type}" = "tun" ]; then fi /usr/bin/touch /tmp/${1}up -# reload filter +# reload filter /usr/local/sbin/pfSctl -c "interface newip ${1}" exit 0 diff --git a/usr/local/sbin/pfSsh.php b/usr/local/sbin/pfSsh.php index 16aaa0a..068198f 100755 --- a/usr/local/sbin/pfSsh.php +++ b/usr/local/sbin/pfSsh.php @@ -1,5 +1,5 @@ #!/usr/local/bin/php -f - + <?php require_once("globals.inc"); @@ -11,39 +11,39 @@ echo "."; require_once("util.inc"); echo "."; -$shell_cmds = array("alias", "alloc", "bg", "bind", "bindkey", "break", - "breaksw", "builtins", "case", "cd", "chdir", "command", "complete", "continue", "default", - "dirs", "do", "done", "echo", "echotc", "elif", "else", "end", "endif", "endsw", "esac", "eval", - "exec", "exit", "export", "false", "fc", "fg", "filetest", "fi", "for", "foreach", "getopts", - "glob", "goto", "hash", "hashstat", "history", "hup", "if", "jobid", "jobs", "kill", "limit", - "local", "log", "login", "logout", "ls-F", "nice", "nohup", "notify", "onintr", "popd", - "printenv", "pushd", "pwd", "read", "readonly", "rehash", "repeat", "return", "sched", "set", - "setenv", "settc", "setty", "setvar", "shift", "source", "stop", "suspend", "switch", - "telltc", "test", "then", "time", "trap", "true", "type", "ulimit", "umask", "unalias", - "uncomplete", "unhash", "unlimit", "unset", "unsetenv", "until", "wait", "where", "which", - "while"); +$shell_cmds = array("alias", "alloc", "bg", "bind", "bindkey", "break", + "breaksw", "builtins", "case", "cd", "chdir", "command", "complete", "continue", "default", + "dirs", "do", "done", "echo", "echotc", "elif", "else", "end", "endif", "endsw", "esac", "eval", + "exec", "exit", "export", "false", "fc", "fg", "filetest", "fi", "for", "foreach", "getopts", + "glob", "goto", "hash", "hashstat", "history", "hup", "if", "jobid", "jobs", "kill", "limit", + "local", "log", "login", "logout", "ls-F", "nice", "nohup", "notify", "onintr", "popd", + "printenv", "pushd", "pwd", "read", "readonly", "rehash", "repeat", "return", "sched", "set", + "setenv", "settc", "setty", "setvar", "shift", "source", "stop", "suspend", "switch", + "telltc", "test", "then", "time", "trap", "true", "type", "ulimit", "umask", "unalias", + "uncomplete", "unhash", "unlimit", "unset", "unsetenv", "until", "wait", "where", "which", + "while"); function pipe_cmd($command, $text_to_pipe) { $descriptorspec = array( - 0 => array("pipe", "r"), // stdin - 1 => array("pipe", "w"), // stdout - 2 => array("pipe", "w")); // stderr ?? instead of a file - + 0 => array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w")); // stderr ?? instead of a file + $fd = proc_open("$command", $descriptorspec, $pipes); if (is_resource($fd)) { - fwrite($pipes[0], "{$text_to_pipe}"); - fclose($pipes[0]); - while($s= fgets($pipes[1], 1024)) { - // read from the pipe - $buffer .= $s; - } - fclose($pipes[1]); - fclose($pipes[2]); + fwrite($pipes[0], "{$text_to_pipe}"); + fclose($pipes[0]); + while ($s= fgets($pipes[1], 1024)) { + // read from the pipe + $buffer .= $s; + } + fclose($pipes[1]); + fclose($pipes[2]); } return $buffer; } -if(!function_exists("readline")) { +if (!function_exists("readline")) { function readline() { $fp = fopen('php://stdin', 'r'); $textinput = chop(fgets($fp)); @@ -53,21 +53,22 @@ if(!function_exists("readline")) { } function more($text, $count=24) { - $counter=0; - $lines = explode("\n", $text); - foreach($lines as $line) { - if($counter > $count) { - echo "Press RETURN to continue ..."; - $fp = fopen('php://stdin', 'r'); - $pressreturn = chop(fgets($fp)); - if($pressreturn == "q" || $pressreturn == "quit") - return; - fclose($fp); - $counter = 0; - } - echo "{$line}\n"; - $counter++; - } + $counter=0; + $lines = explode("\n", $text); + foreach ($lines as $line) { + if ($counter > $count) { + echo "Press RETURN to continue ..."; + $fp = fopen('php://stdin', 'r'); + $pressreturn = chop(fgets($fp)); + if ($pressreturn == "q" || $pressreturn == "quit") { + return; + } + fclose($fp); + $counter = 0; + } + echo "{$line}\n"; + $counter++; + } } function show_help() { @@ -75,7 +76,7 @@ function show_help() { $show_help_text = <<<EOF Enter a series of commands and then execute the set with "exec". - + For example: echo "foo"; // php command echo "foo2"; // php command @@ -95,54 +96,54 @@ $show_help_text = <<<EOF /* to output a configuration array */ print_r(\$config); - + /* to output the interfaces configuration portion of config.xml */ print_r(\$config['interfaces']); - + /* to output the dhcp server configuration */ print_r(\$config['dhcpd']); /* to exit the {$g['product_name']} developer shell */ exit - + /* to output supported wireless modes for an interface */ print_r(get_wireless_modes(\"ath0\")); - + /* to enable SSH */ \$config['system']['enablesshd'] = true; - + /* change OPTX to the OPT interface name such as BACKHAUL */ \$config['interfaces']['optx']['wireless']['standard'] = "11a"; \$config['interfaces']['optx']['wireless']['mode'] = "hostap"; \$config['interfaces']['optx']['wireless']['channel'] = "6"; - + /* to enable dhcp server for an optx interface */ \$config['dhcpd']['optx']['enable'] = true; \$config['dhcpd']['optx']['range']['from'] = "192.168.31.100"; \$config['dhcpd']['optx']['range']['to'] = "192.168.31.150"; - + /* to disable the firewall filter */ \$config['system']['disablefilter'] = true; - + /* to enable an interface and configure it as a DHCP client */ \$config['interfaces']['optx']['disabled'] = false; \$config['interfaces']['optx']['ipaddr'] = "dhcp"; - + /* to enable an interface and set a static IPv4 address */ \$config['interfaces']['wan']['enable'] = true; \$config['interfaces']['wan']['ipaddr'] = "192.168.100.1"; \$config['interfaces']['wan']['subnet'] = "24"; - + /* to save out the new configuration (config.xml) */ write_config(); - + /* to reboot the system after saving */ system_reboot_sync(); - + EOF; more($show_help_text); - + } $fp = fopen('php://stdin', 'r'); @@ -161,16 +162,16 @@ function completion($string, $index) { readline_completion_function("completion"); -if($argc < 2) { +if ($argc < 2) { echo "Welcome to the {$g['product_name']} developer shell\n"; echo "\nType \"help\" to show common usage scenarios.\n"; echo "\nAvailable playback commands:\n "; $files = scandir("/etc/phpshellsessions/"); $tccommands[] = "playback"; - foreach($files as $file) { - if($file <> "." and $file <> "..") { + foreach ($files as $file) { + if ($file <> "." and $file <> "..") { echo $file . " "; - if(function_exists("readline_add_history")) { + if (function_exists("readline_add_history")) { readline_add_history("playback $file"); $tccommands[] = "$file"; } @@ -183,8 +184,8 @@ $recording = false; $playback_file_split = array(); $playbackbuffer = ""; -if($argv[1]=="playback" or $argv[1]=="run") { - if(!file_exists("/etc/phpshellsessions/{$argv[2]}")) { +if ($argv[1]=="playback" or $argv[1]=="run") { + if (!file_exists("/etc/phpshellsessions/{$argv[2]}")) { echo "Could not locate playback file."; exit; } @@ -205,14 +206,14 @@ $tccommands[] = "reset"; $tccommands[] = "master"; $tccommands[] = "RELENG_1_2"; -while($shell_active == true) { +while ($shell_active == true) { $command = readline("{$g['product_name']} shell: "); readline_add_history($command); - $command_split = explode(" ", $command); - $first_command = $command_split[0]; - if($first_command == "playback" || $first_command == "run") { + $command_split = explode(" ", $command); + $first_command = $command_split[0]; + if ($first_command == "playback" || $first_command == "run") { $playback_file = $command_split[1]; - if(!$playback_file || !file_exists("/etc/phpshellsessions/{$playback_file}")) { + if (!$playback_file || !file_exists("/etc/phpshellsessions/{$playback_file}")) { $command = ""; echo "Could not locate playback file.\n"; } else { @@ -222,42 +223,43 @@ while($shell_active == true) { continue; } } - if($first_command == "exit" or $first_command == "quit") + if ($first_command == "exit" or $first_command == "quit") { die; - if($first_command == "help" or $first_command == "?") { + } + if ($first_command == "help" or $first_command == "?") { show_help(); $playbackbuffer = ""; continue; } - if($first_command == "exec" or $first_command == "exec;") { + if ($first_command == "exec" or $first_command == "exec;") { playback_text($playbackbuffer); $playbackbuffer = ""; continue; } - if($first_command == "stoprecording" || $first_command == "stoprecord" || $first_command == "stop") { - if($recording) { + if ($first_command == "stoprecording" || $first_command == "stoprecord" || $first_command == "stop") { + if ($recording) { fwrite($recording_fd, $playbackbuffer); fclose($recording_fd); $command = ""; conf_mount_ro(); echo "Recording stopped.\n"; - $recording = false; + $recording = false; } else { echo "No recording session in progress.\n"; $command = ""; } } - if($first_command == "showrecordings") { + if ($first_command == "showrecordings") { show_recordings(); - $command = ""; + $command = ""; } - if($first_command == "reset") { + if ($first_command == "reset") { $playbackbuffer = ""; echo "\nBuffer reset.\n\n"; continue; } - if($first_command == "record") { - if(!$command_split[1]) { + if ($first_command == "record") { + if (!$command_split[1]) { echo "usage: record playbackname\n"; $command = ""; } else { @@ -265,10 +267,10 @@ while($shell_active == true) { conf_mount_rw(); safe_mkdir("/etc/phpshellsessions"); $recording_fd = fopen("/etc/phpshellsessions/{$command_split[1]}","w"); - if(!$recording_fd) { + if (!$recording_fd) { echo "Could not start recording session.\n"; $command = ""; - } else { + } else { $recording = true; echo "Recording of {$command_split[1]} started.\n"; $command = ""; @@ -281,28 +283,30 @@ while($shell_active == true) { function show_recordings() { conf_mount_rw(); safe_mkdir("/etc/phpshellsessions"); - if($recording) + if ($recording) { conf_mount_ro(); + } echo "==> Sessions available for playback are:\n"; system("cd /etc/phpshellsessions && ls /etc/phpshellsessions"); - echo "==> end of list.\n"; + echo "==> end of list.\n"; } function returnlastchar($command) { $commandlen = strlen($command); $endofstring = substr($command, ($commandlen-1)); - return $endofstring; + return $endofstring; } function returnfirstchar($command) { $commandlen = strlen($command); $endofstring = substr($command, 0, 1); - return $endofstring; + return $endofstring; } function str_replace_all($search,$replace,$subject) { - while(strpos($subject,$search)!==false) + while (strpos($subject,$search)!==false) { $subject = str_replace($search,$replace,$subject); + } return $subject; } @@ -312,11 +316,11 @@ function playback_text($playback_file_contents) { $playback_text .= "require_once('globals.inc');\n"; $playback_text .= "require_once('config.inc');\n"; $toquote = '"'; - $toquotereplace = '\\"'; - foreach($playback_file_split as $pfs) { + $toquotereplace = '\\"'; + foreach ($playback_file_split as $pfs) { $firstchar = returnfirstchar($pfs); $currentline = $pfs; - if($firstchar == "!") { + if ($firstchar == "!") { /* XXX: encode " in $pfs */ $pfsa = str_replace($toquote, $toquotereplace, $currentline); $playback_text .= str_replace("!", "system(\"", $pfsa) . "\");\n"; diff --git a/usr/local/sbin/prefixes.php b/usr/local/sbin/prefixes.php index 85cb496..118bd9e 100644 --- a/usr/local/sbin/prefixes.php +++ b/usr/local/sbin/prefixes.php @@ -1,7 +1,7 @@ <?php $leases_file = "/var/dhcpd/var/db/dhcpd6.leases"; -if(!file_exists($leases_file)) { +if (!file_exists($leases_file)) { exit(1); } @@ -10,31 +10,31 @@ $fd = fopen($leases_file, 'r'); $duid_arr = array(); while (( $line = fgets($fd, 4096)) !== false) { // echo "$line"; - if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i", $line, $duidmatch)) { + if (preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i", $line, $duidmatch)) { $type = $duidmatch[1]; $duid = $duidmatch[2]; continue; } /* is it active? otherwise just discard */ - if(preg_match("/binding state active/i", $line, $activematch)) { + if (preg_match("/binding state active/i", $line, $activematch)) { $active = true; continue; } - if(preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) { + if (preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) { $ia_na = $addressmatch[1]; continue; } - if(preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) { + if (preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) { $ia_pd = $prefixmatch[1]; continue; } /* closing bracket */ - if(preg_match("/^}/i", $line)) { - switch($type) { + if (preg_match("/^}/i", $line)) { + switch ($type) { case "ia-na": $duid_arr[$duid][$type] = $ia_na; break; @@ -54,13 +54,13 @@ fclose($fd); $routes = array(); foreach ($duid_arr as $entry) { - if(!empty($entry['ia-pd'])) { + if (!empty($entry['ia-pd'])) { $routes[$entry['ia-na']] = $entry['ia-pd']; } } // echo "add routes\n"; -if(count($routes) > 0) { +if (count($routes) > 0) { foreach ($routes as $address => $prefix) { echo "/sbin/route change -inet6 {$prefix} {$address}\n"; } @@ -69,13 +69,14 @@ if(count($routes) > 0) { /* get clog from dhcpd */ $dhcpdlogfile = "/var/log/dhcpd.log"; $expires = array(); -if(file_exists($dhcpdlogfile)) { +if (file_exists($dhcpdlogfile)) { $fd = popen("clog $dhcpdlogfile", 'r'); while (($line = fgets($fd)) !== false) { //echo $line; - if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) { - if(in_array($expire[1], $routes)) + if (preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) { + if (in_array($expire[1], $routes)) { continue; + } $expires[$expire[1]] = $expire[1]; } } @@ -83,7 +84,7 @@ if(file_exists($dhcpdlogfile)) { } // echo "remove routes\n"; -if(count($expires) > 0) { +if (count($expires) > 0) { foreach ($expires as $prefix) { echo "/sbin/route delete -inet6 {$prefix['prefix']}\n"; } diff --git a/usr/local/sbin/show_filter_reload_status.php b/usr/local/sbin/show_filter_reload_status.php index 5251c3e..daa35ad 100755 --- a/usr/local/sbin/show_filter_reload_status.php +++ b/usr/local/sbin/show_filter_reload_status.php @@ -3,24 +3,24 @@ $last_text = ""; -while(!stristr($status, "Done")) { - $status = get_status(); - if($status <> "") { - echo $status . "\n"; - } - sleep(1); +while (!stristr($status, "Done")) { + $status = get_status(); + if ($status <> "") { + echo $status . "\n"; + } + sleep(1); } function get_status() { - global $last_text; - $status = file_get_contents("/var/run/filter_reload_status"); - $status = str_replace("...", "", $status); - $status .= "..."; - if($status <> $last_text) { - $last_text = $status; - return $status; - } - return ""; + global $last_text; + $status = file_get_contents("/var/run/filter_reload_status"); + $status = str_replace("...", "", $status); + $status .= "..."; + if ($status <> $last_text) { + $last_text = $status; + return $status; + } + return ""; } ?> |