diff options
author | Ermal Luci <eri@pfsense.org> | 2009-06-18 12:40:11 +0000 |
---|---|---|
committer | Ermal Luci <eri@pfsense.org> | 2009-06-18 12:40:11 +0000 |
commit | 6dc88d5352ea963d85708379405e238e0518e990 (patch) | |
tree | e51eb1a505ff148a495c642c9b6ed225476a58ce /usr | |
parent | 4b9980ecfff36202b6ea8dbf7d41e44f78ba52f3 (diff) | |
download | pfsense-6dc88d5352ea963d85708379405e238e0518e990.zip pfsense-6dc88d5352ea963d85708379405e238e0518e990.tar.gz |
* Move functions that output html to guiconfig.inc
* Remove some recursive dependency on some includes
* Remove ^M or \r from files
* Remove some entries from functions.inc to avoid including them twice
* Remove some unneccessary includes from some files
NOTE: There is some more work to be done for pkg-utils.inc to be removed from backend as a dependency.
Diffstat (limited to 'usr')
-rwxr-xr-x | usr/local/www/guiconfig.inc | 325 | ||||
-rw-r--r-- | usr/local/www/vpn_l2tp_users_edit.php | 1 |
2 files changed, 309 insertions, 17 deletions
diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index b60614f..f80c375 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -1103,25 +1103,318 @@ function echo_array($array,$return_me=false){ } } +/****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) { + global $HTTP_SERVER_VARS; + global $config; + global $g; + + /* 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. + */ + + $tab_temp = array (); + foreach ($tab_array as $ta) + if(isAllowedPage($ta[2])) + $tab_temp[] = $ta; + /* + // FIXME : if the checks are not good enough + // in isAllowedPage, it needs to be + // fixed instead of kludging here + + // TODO: humm what shall we do with pkg_edit.php and pkg.php? + if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) { + $pos_equal = strpos($link, "="); + $pos_xmlsuffix = strpos($link, ".xml"); + // do we match an absolute url including ?xml= foo + if(!isAllowedPage($link, $allowed)) + $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3)); + } + // next check - what if the basename contains a query string? + if ((strpos($link, "?")) !== false) { + $pos_qmark = strpos($link, "?"); + $link = substr($link, 0, $pos_qmark); + } + $authorized_text = print_r($allowed, true); + if(is_array($authorized)) + if (in_array(basename($link), $authorized)) + */ + + unset ($tab_array); + $tab_array = & $tab_temp; + + $tab_active_bg = "#EEEEEE"; + $tab_inactive_bg = "#777777"; + $nifty_tabs_corners = "#FFF"; + $font_color = "white"; + + /* if tabcontrols.php exist for a theme, allow it to be overriden */ + $themename = $config['theme']; + $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php"; + if(file_exists($filename)) { + $eval_code = file_get_contents($filename); + eval($eval_code); + } + + $tabcharcount = 0; + foreach ($tab_array as $ta) + $tabcharcount = $tabcharcount + strlen($ta[0]); + + // If the character count of the tab names is > 670 + // then show a select item dropdown menubox. + if($tabcharcount > 82) { + echo "Currently viewing: "; + echo "<select name='TabSelect'>\n"; + foreach ($tab_array as $ta) { + if($ta[1]=="true") + $selected = " SELECTED"; + else + $selected = ""; + echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n"; + } + echo "</select>\n<p/>"; + } else { + echo "<table cellpadding='0' cellspacing='0'>\n"; + echo " <tr>\n"; + $tabscounter = 0; + foreach ($tab_array as $ta) { + if ($ta[1] == true) { + echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n"; + } else { + echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n"; + } + $tabscounter++; + } + echo "</tr>\n<tr>\n"; + foreach ($tab_array as $ta) { + if ($ta[1] == true) { + echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> {$ta[0]}"; + echo " "; + echo "<font size='-12'> </font></B></td>\n"; + } else { + echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> <a href='{$ta[ +2]}'>"; + echo "<font color='{$font_color}'>{$ta[0]}</font></a> "; + echo "<font size='-12'> </font></B></td>\n"; + } + } + echo "</tr>\n<tr>\n"; + foreach ($tab_array as $ta) { + if ($ta[1] == true) { + echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n"; + } else { + echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n"; + } + $tabscounter++; + } + echo " </tr>\n"; + echo "</table>\n"; + echo "<script type=\"text/javascript\">"; + echo "NiftyCheck();\n"; + echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n"; + for ($x = 0; $x < $tabscounter; $x++) + echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n"; + echo "</script>"; + } +} + function add_package_tabs($tabgroup, & $tab_array) { - global $config, $g; + global $config, $g; - if(!is_array($config['installedpackages'])) - return; - if(!is_array($config['installedpackages']['tab'])) - return; + if(!is_array($config['installedpackages'])) + return; + if(!is_array($config['installedpackages']['tab'])) + return; - foreach($config['installedpackages']['tab'] as $tab) { - if ($tab['group'] !== $group) - continue; - $tab_entry = array(); - if($tab['name']) { - $tab_entry[] = $tab['name']; - $tab_entry[] = false; - $tab_entry[] = $tab['url']; - $tab_array[] = $tab_entry; - } - } + foreach($config['installedpackages']['tab'] as $tab) { + if ($tab['group'] !== $group) + continue; + $tab_entry = array(); + if($tab['name']) { + $tab_entry[] = $tab['name']; + $tab_entry[] = false; + $tab_entry[] = $tab['url']; + $tab_array[] = $tab_entry; + } + } +} + +/* + * update_output_window: update bottom textarea dynamically. + */ +function update_output_window($text) { + global $pkg_interface; + $log = ereg_replace("\n", "\\n", $text); + if($pkg_interface == "console") { + /* too chatty */ + } else { + echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"" . $log . "\";</script>"; + } + /* ensure that contents are written out */ + ob_flush(); +} + +/* + * update_output_window: update top textarea dynamically. + */ +function update_status($status) { + global $pkg_interface; + if($pkg_interface == "console") { + echo $status . "\n"; + } else { + echo "\n<script type=\"text/javascript\">this.document.forms[0].status.value=\"" . $status . "\";</script>"; + } + /* ensure that contents are written out */ + ob_flush(); +} + +/* + * update_progress_bar($percent): updates the javascript driven progress bar. + */ +function update_progress_bar($percent) { + global $pkg_interface; + if($percent > 100) $percent = 1; + if($pkg_interface <> "console") { + echo "\n<script type=\"text/javascript\" language=\"javascript\">"; + echo "\ndocument.progressbar.style.width='" . $percent . "%';"; + echo "\n</script>"; + } else { + echo " {$percent}%"; + } +} + +function read_header($ch, $string) { + global $file_size, $fout; + $length = strlen($string); + $regs = ""; + ereg("(Content-Length:) (.*)", $string, $regs); + if($regs[2] <> "") { + $file_size = intval($regs[2]); + } + ob_flush(); + return $length; +} + +function read_body($ch, $string) { + global $fout, $file_size, $downloaded, $sendto, $static_status, $static_output, $lastseen; + $length = strlen($string); + $downloaded += intval($length); + $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); + $downloadProgress = 100 - $downloadProgress; + if($lastseen <> $downloadProgress and $downloadProgress < 101) { + if($sendto == "status") { + $tostatus = $static_status . $downloadProgress . "%"; + update_status($tostatus); + } else { + $tooutput = $static_output . $downloadProgress . "%"; + update_output_window($tooutput); + } + update_progress_bar($downloadProgress); + $lastseen = $downloadProgress; + } + if($fout) + fwrite($fout, $string); + ob_flush(); + return $length; +} + +function rule_popup($src,$srcport,$dst,$dstport){ + global $config; + $aliases_array = array(); + if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) + { + $span_begin = ""; + $alias_src_span_begin = ""; + $alias_src_span_end = ""; + $alias_src_port_span_begin = ""; + $alias_src_port_span_end = ""; + $alias_dst_span_begin = ""; + $alias_dst_span_end = ""; + $alias_dst_port_span_begin = ""; + $alias_dst_port_span_end = ""; + $alias_content_text = ""; + foreach($config['aliases']['alias'] as $alias_name) + { + $alias_addresses = explode (" ", $alias_name['address']); + $alias_details = explode ("||", $alias_name['detail']); + $alias_objects_with_details = ""; + $counter = 0; + foreach($alias_addresses as $alias_ports_address) + { + $alias_objects_with_details .= $alias_addresses[$counter]; + $alias_detail_default = strpos ($alias_details[$counter],"Entry added"); + if ($alias_details[$counter] != "" && $alias_detail_default === False){ + $alias_objects_with_details .=" - " . $alias_details[$counter]; + } + $alias_objects_with_details .= "<br>"; + $counter++; + } + //max character length for caption field + $maxlength = 60; + + $alias_descr_substr = $alias_name['descr']; + $alias_content_text = htmlspecialchars($alias_objects_with_details); + $alias_caption = htmlspecialchars($alias_descr_substr . ":"); + $strlength = strlen ($alias_caption); + if ($strlength >= $maxlength) + $alias_caption = substr($alias_caption, 0, $maxlength) . "..."; + + $span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>$alias_caption</h1><p>$alias_content_text</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><U>"; + + if ($alias_name['name'] == $src) + $alias_src_span_begin = $span_begin; + if ($alias_name['name'] == $srcport) + $alias_src_port_span_begin = $span_begin; + if ($alias_name['name'] == $dst) + $alias_dst_span_begin = $span_begin; + if ($alias_name['name'] == $dstport) + $alias_dst_port_span_begin = $span_begin; + } + $descriptions = array (); + $descriptions['src'] = $alias_src_span_begin; + $descriptions['srcport'] = $alias_src_port_span_begin; + $descriptions['dst'] = $alias_dst_span_begin; + $descriptions['dstport'] = $alias_dst_port_span_begin; + + return $descriptions; + } +} + +function download_file_with_progress_bar($url_file, $destination_file, $readbody = 'read_body') { + global $ch, $fout, $file_size, $downloaded; + $file_size = 1; + $downloaded = 1; + /* open destination file */ + $fout = fopen($destination_file, "wb"); + + /* + * Originally by Author: Keyvan Minoukadeh + * Modified by Scott Ullrich to return Content-Length size + */ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url_file); + curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); + curl_setopt($ch, CURLOPT_WRITEFUNCTION, $readbody); + curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '5'); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + + curl_exec($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if($fout) + fclose($fout); + curl_close($ch); + return ($http_code == 200) ? true : $http_code; } ?> diff --git a/usr/local/www/vpn_l2tp_users_edit.php b/usr/local/www/vpn_l2tp_users_edit.php index 98d2dc7..4cf816b 100644 --- a/usr/local/www/vpn_l2tp_users_edit.php +++ b/usr/local/www/vpn_l2tp_users_edit.php @@ -127,7 +127,6 @@ include("head.inc"); <?php if ($input_errors) print_input_errors($input_errors); ?> <div id="inputerrors"></div> <form action="vpn_l2tp_users_edit.php" method="post" name="iform" id="iform"> - <?display_topbar()?> <div id="mainarea"> <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0"> <tr> |