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 /etc/inc/pfsense-utils.inc | |
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 'etc/inc/pfsense-utils.inc')
-rw-r--r-- | etc/inc/pfsense-utils.inc | 340 |
1 files changed, 0 insertions, 340 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 401787d..9c62180 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -705,21 +705,6 @@ function get_filename_from_url($url) { } /* - * 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(); -} - -/* * get_dir: return an array of $dir */ function get_dir($dir) { @@ -732,35 +717,6 @@ function get_dir($dir) { return $dir_array; } -/* - * 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}%"; - } -} - /****f* pfsense-utils/WakeOnLan * NAME * WakeOnLan - Wake a machine up using the wake on lan format/protocol @@ -1071,157 +1027,6 @@ function get_disk_info() { // $size, $used, $avail, $cap } -/****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>"; - } -} - - -/****f* pfsense-utils/display_topbar - * NAME - * display_topbar - top a table off with rounded edges - * INPUTS - * $text - (optional) Text to include in bar - * RESULT - * null - ******/ -function display_topbar($text = "", $bg_color="#990000", $replace_color="#FFFFFF", $rounding_style="smooth") { - echo " <table width='100%' cellpadding='0' cellspacing='0'>\n"; - echo " <tr height='1'>\n"; - echo " <td width='100%' valign='top' color='{$bg_color}' bgcolor='{$bg_color}'>"; - echo " <div id='topbar'></div></td>\n"; - echo " </tr>\n"; - echo " <tr height='1'>\n"; - if ($text != "") - echo " <td height='1' class='listtopic'>{$text}</td>\n"; - else - echo " <td height='1' class='listtopic'></td>\n"; - echo " </tr>\n"; - echo " </table>"; - echo "<script type=\"text/javascript\">"; - echo "NiftyCheck();\n"; - echo "Rounded(\"div#topbar\",\"top\",\"{$replace_color}\",\"{$bg_color}\",\"{$rounding_style}\");\n"; - echo "</script>"; -} - /****f* pfsense-utils/strncpy * NAME * strncpy - copy strings @@ -1579,18 +1384,6 @@ function is_dhcp_server_enabled() return $dhcpdenable; } -/****f* pfsense-utils/isAjax - * NAME - * isAjax - reports if the request is driven from prototype - * INPUTS - * none - * RESULT - * true/false - ******/ -function isAjax() { - return isset ($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; -} - //returns interface information function get_interface_info($ifdescr) { global $config, $linkinfo, $netstatrninfo; @@ -1889,139 +1682,6 @@ function pfsense_default_state_size() { return $max_states; } -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; -} - -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; -} - /* Compare the current hostname DNS to the DNS cache we made * if it has changed we return the old records * if no change we return true */ |