.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* 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.
*
* 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.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgment:
* "This product includes software developed by the pfSense Project
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
*
* 4. The names "pfSense" and "pfSense Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* coreteam@pfsense.org.
*
* 5. Products derived from this software may not be called "pfSense"
* nor may "pfSense" appear in their names without prior written
* permission of the Electric Sheep Fencing, LLC.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
*
* "This product includes software developed by the pfSense Project
* for use in the pfSense software distribution (http://www.pfsense.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Include authentication routines */
/* THIS MUST BE ABOVE ALL OTHER CODE */
if (!$nocsrf) {
function csrf_startup() {
csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : 240;
csrf_conf('expires', $timeout_minutes * 60);
}
require_once("csrf/csrf-magic.php");
}
/* make sure nothing is cached */
if (!$omit_nocacheheaders) {
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
}
header("X-Frame-Options: SAMEORIGIN");
require_once("authgui.inc");
/* parse the configuration and include all configuration functions */
require_once("functions.inc");
/* Include the autoloader for all the GUI display classes */
require_once("classes/autoload.inc.php");
/* used by progress bar */
$lastseen = "-1";
$navlevelsep = ": "; /* navigation level separator string */
$mandfldhtml = ""; /* display this before mandatory input fields */
$mandfldhtmlspc = ""; /* same as above, but with spacing */
if (!function_exists('set_language')) {
require_once("pfsense-utils.inc");
}
set_language();
/* Some ajax scripts still need access to GUI */
if (!$ignorefirmwarelock) {
if (is_subsystem_dirty('firmwarelock')) {
if (!$d_isfwfile) {
header("Location: system_update.php");
exit;
} else {
return;
}
}
}
/* Reserved table names to avoid collision */
$reserved_table_names = array(
"bogons",
"bogonsv6",
"negate_networks",
"snort2c",
"sshlockout",
"tonatsubnets",
"virusprot",
"vpn_networks",
"webConfiguratorlockout"
);
$firewall_rules_dscp_types = array(
"af11",
"af12",
"af13",
"af21",
"af22",
"af23",
"af31",
"af32",
"af33",
"af41",
"af42",
"af43",
"VA",
"EF",
"cs1",
"cs2",
"cs3",
"cs4",
"cs5",
"cs6",
"cs7",
"0x01",
"0x02",
"0x04");
$auth_server_types = array(
'ldap' => "LDAP",
'radius' => "RADIUS");
$ldap_urltypes = array(
'TCP - Standard' => 389,
'SSL - Encrypted' => 636);
$ldap_scopes = array(
'one' => gettext("One Level"),
'subtree' => gettext("Entire Subtree"));
$ldap_protvers = array(
2,
3);
$ldap_templates = array(
'open' => array(
'desc' => "OpenLDAP",
'attr_user' => "cn",
'attr_group' => "cn",
'attr_member' => "member"),
'msad' => array(
'desc' => "Microsoft AD",
'attr_user' => "samAccountName",
'attr_group' => "cn",
'attr_member' => "memberOf"),
'edir' => array(
'desc' => "Novell eDirectory",
'attr_user' => "cn",
'attr_group' => "cn",
'attr_member' => "uniqueMember"));
$radius_srvcs = array(
'both' => gettext("Authentication and Accounting"),
'auth' => gettext("Authentication"),
'acct' => gettext("Accounting"));
$netbios_nodetypes = array(
'0' => "none",
'1' => "b-node",
'2' => "p-node",
'4' => "m-node",
'8' => "h-node");
/* some well known ports */
$wkports = array(
5999 => "CVSup",
53 => "DNS",
21 => "FTP",
3000 => "HBCI",
80 => "HTTP",
443 => "HTTPS",
5190 => "ICQ",
113 => "IDENT/AUTH",
143 => "IMAP",
993 => "IMAP/S",
4500 => "IPsec NAT-T",
500 => "ISAKMP",
1701 => "L2TP",
389 => "LDAP",
1755 => "MMS/TCP",
7000 => "MMS/UDP",
445 => "MS DS",
3389 => "MS RDP",
1512 => "MS WINS",
1863 => "MSN",
119 => "NNTP",
123 => "NTP",
138 => "NetBIOS-DGM",
137 => "NetBIOS-NS",
139 => "NetBIOS-SSN",
1194 => "OpenVPN",
110 => "POP3",
995 => "POP3/S",
1723 => "PPTP",
1812 => "RADIUS",
1813 => "RADIUS accounting",
5004 => "RTP",
5060 => "SIP",
25 => "SMTP",
465 => "SMTP/S",
161 => "SNMP",
162 => "SNMP-Trap",
22 => "SSH",
3478 => "STUN",
587 => "SUBMISSION",
3544 => "Teredo",
23 => "Telnet",
69 => "TFTP",
5900 => "VNC");
/* TCP flags */
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
$specialnets = array(
"(self)" => gettext("This Firewall"),
"pppoe" => gettext("PPPoE clients"),
"l2tp" => gettext("L2TP clients"));
$spiflist = get_configured_interface_with_descr(false, true);
foreach ($spiflist as $ifgui => $ifdesc) {
$specialnets[$ifgui] = $ifdesc . " net";
$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
}
$medias = array(
"auto" => gettext("autoselect"),
"100full" => gettext("100BASE-TX full-duplex"),
"100half" => gettext("100BASE-TX half-duplex"),
"10full" => gettext("10BASE-T full-duplex"),
"10half" => gettext("10BASE-T half-duplex"));
$wlan_modes = array(
"bss" => gettext("Infrastructure (BSS)"),
"adhoc" => gettext("Ad-hoc (IBSS)"),
"hostap" => gettext("Access Point"));
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
/* check for bad control characters */
foreach ($postdata as $pn => $pd) {
if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
}
}
for ($i = 0; $i < count($reqdfields); $i++) {
if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
}
}
}
function print_input_errors($input_errors) {
echo '
';
echo '
' . gettext('The following input errors were detected:') . '
';
echo '
';
foreach ($input_errors as $ierr) {
echo '
' . htmlspecialchars($ierr) . '
';
}
echo '
';
echo '
';
}
function verify_gzip_file($fname) {
$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
if ($returnvar != 0) {
return 0;
} else {
return 1;
}
}
// print_info_box() has been updated so that any required button is explicitly created, rather than relying on the detection of certain
// strings in the message (such as "apply"). print_info_box_np() has been exterminated.
// $class = the bootstrap style class (default, info, warning, success, danger)
// $btnname and btntext describe the optional button and its display text, the default is an 'x' Close button.
// Note that there is also a shortcut function print_apply_box here that creates a standard "apply" box for you.
// In many cases just substitute that for print_info_box_np() to easily get a warning style "Apply changes" box.
function print_info_box($msg, $class="alert-warning", $btnname = "close", $btntext = "", $btnicon = "", $btnclass = "default") {
if (strpos($class, "alert-") !== 0) {
$class = 'alert-' . $class;
}
$msg = '
' . $msg . '
';
if ($btnname === "close") {
$msg = '' . $msg;
} else if ($btnname != "") {
if (empty($btntext)) {
$btntext = $btnname;
}
if (!empty($btnicon)) {
$btnicon = '';
}
$msg .= '';
}
echo '
';
echo $callout;
}
function get_std_save_message($ok) {
$filter_related = false;
$filter_pages = array("nat", "filter");
$to_return = gettext("The changes have been applied successfully.");
foreach ($filter_pages as $fp) {
if (stristr($_SERVER['SCRIPT_FILENAME'], $fp)) {
$filter_related = true;
}
}
if ($filter_related) {
$to_return .= " " . gettext("Monitor the filter reload progress.");
}
return $to_return;
}
function pprint_address($adr) {
global $specialnets;
if (isset($adr['any'])) {
$padr = "*";
} else if ($adr['network']) {
$padr = $specialnets[$adr['network']];
} else {
$padr = $adr['address'];
}
if (isset($adr['not'])) {
$padr = "! " . $padr;
}
return $padr;
}
function pprint_port($port) {
global $wkports;
$pport = "";
if (!$port) {
return "*";
} else {
$srcport = explode("-", $port);
if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
$pport = $srcport[0];
if ($wkports[$srcport[0]]) {
$pport .= " (" . $wkports[$srcport[0]] . ")";
}
} else {
$pport .= $srcport[0] . " - " . $srcport[1];
}
}
return $pport;
}
function firewall_check_for_advanced_options(&$item) {
$item_set = "";
if ($item['os']) {
$item_set .= "os {$item['os']} ";
}
if ($item['dscp']) {
$item_set .= "dscp {$item['dscp']} ";
}
if ($item['max']) {
$item_set .= "max {$item['max']} ";
}
if ($item['max-src-nodes']) {
$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
}
if ($item['max-src-conn']) {
$item_set .= "max-src-conn {$item['max-src-conn']} ";
}
if ($item['max-src-states']) {
$item_set .= "max-src-states {$item['max-src-states']} ";
}
if (isset($item['nopfsync'])) {
$item_set .= "nopfsync ";
}
if ($item['statetype'] != "keep state" && $item['statetype'] != "") {
$item_set .= "statetype {$item['statetype']} ";
}
if ($item['statetimeout']) {
$item_set .= "statetimeout {$item['statetimeout']} ";
}
if (isset($item['nosync'])) {
$item_set .= "no XMLRPC Sync ";
}
if ($item['max-src-conn-rate']) {
$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
}
if ($item['max-src-conn-rates']) {
$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
}
if ($item['vlanprio']) {
$item_set .= "vlanprio {$item['vlanprio']} ";
}
if ($item['vlanprioset']) {
$item_set .= "vlanprioset {$item['vlanprioset']} ";
}
if ($item['gateway']) {
$item_set .= "gateway {$item['gateway']} ";
}
if ($item['dnpipe']) {
$item_set .= "limiter {$item['dnpipe']} ";
}
if ($item['pdnpipe']) {
$item_set .= "limiter {$item['pdnpipe']} ";
}
if ($item['ackqueue']) {
$item_set .= "ackqueue {$item['ackqueue']} ";
}
if ($item['defaultqueue']) {
$item_set .= "defaultqueue {$item['defaultqueue']} ";
}
if ($item['tag']) {
$item_set .= "tag {$item['tag']} ";
}
if ($item['tagged']) {
$item_set .= "tagged {$item['tagged']} ";
}
if (isset($item['allowopts'])) {
$item_set .= "allowopts ";
}
if (isset($item['disablereplyto'])) {
$item_set .= "disable reply-to ";
}
if ($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2']) {
$item_set .= "tcpflags set";
}
return $item_set;
}
function gentitle($title) {
global $navlevelsep;
if (!is_array($title)) {
return $title;
} else {
return join($navlevelsep, $title);
}
}
function genhtmltitle($title) {
// If the array contains only one element, there are no breadcrumbs, so don't
// add anything else
if (count($title) > 1) {
$bc = '';
foreach ($title as $el) {
$bc .= '
'.$el.'
';
}
$bc .= '';
} else {
$bc = "";
}
return $heading . $bc;
}
/* update the changedesc and changecount(er) variables */
function update_changedesc($update) {
global $changedesc;
global $changecount;
$changedesc .= " {$update}";
$changecount++;
}
// This version of dump_clog() does not output
";
}
}
/****f* pfsense-utils/display_top_tabs
* NAME
* display_top_tabs - display tabs with rounded edges
* INPUTS
* $text - array of tabs
* RESULT
* null
******/
function display_top_tabs(& $tab_array, $no_drop_down = false, $type = 'pills') {
global $config;
global $g;
global $tab_array_indent;
global $tab_array_space;
global $tab_array_char_limit;
/* does the user have access to this tab?
* master user has access to everything.
* if the user does not have access, simply
* unset the tab item.
*/
/* empty string code */
if ($tab_array_indent == '') {
$tab_array_indent = 0;
}
if ($tab_array_space == '') {
$tab_array_space = 1;
}
if ($tab_array_char_limit == '') {
$tab_array_char_limit = 92;
}
foreach ($tab_array as $tab_id => $ta) {
if (!isAllowedPage($ta[2])) {
unset ($tab_array[$tab_id]);
}
}
$tab_active_bg = "#EEEEEE";
$tab_inactive_bg = "#777777";
$nifty_tabs_corners = "#FFF";
$font_color = "white";
$tabcharcount = 0;
foreach ($tab_array as $ta) {
$tabcharcount = $tabcharcount + strlen($ta[0]);
}
if ($no_drop_down == true) {
$tabcharcount = 0;
unset($tab_array_char_limit);
}
// If the character count of the tab names is > 670
// then show a select item dropdown menubox.
if ($tabcharcount > $tab_array_char_limit) {
echo gettext("Currently viewing: ");
echo "\n