Revision 6dc88d53
Added by Ermal Luçi almost 16 years ago
etc/inc/pfsense-utils.inc | ||
---|---|---|
704 | 704 |
return basename($url); |
705 | 705 |
} |
706 | 706 |
|
707 |
/* |
|
708 |
* update_output_window: update bottom textarea dynamically. |
|
709 |
*/ |
|
710 |
function update_output_window($text) { |
|
711 |
global $pkg_interface; |
|
712 |
$log = ereg_replace("\n", "\\n", $text); |
|
713 |
if($pkg_interface == "console") { |
|
714 |
/* too chatty */ |
|
715 |
} else { |
|
716 |
echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"" . $log . "\";</script>"; |
|
717 |
} |
|
718 |
/* ensure that contents are written out */ |
|
719 |
ob_flush(); |
|
720 |
} |
|
721 |
|
|
722 | 707 |
/* |
723 | 708 |
* get_dir: return an array of $dir |
724 | 709 |
*/ |
... | ... | |
732 | 717 |
return $dir_array; |
733 | 718 |
} |
734 | 719 |
|
735 |
/* |
|
736 |
* update_output_window: update top textarea dynamically. |
|
737 |
*/ |
|
738 |
function update_status($status) { |
|
739 |
global $pkg_interface; |
|
740 |
if($pkg_interface == "console") { |
|
741 |
echo $status . "\n"; |
|
742 |
} else { |
|
743 |
echo "\n<script type=\"text/javascript\">this.document.forms[0].status.value=\"" . $status . "\";</script>"; |
|
744 |
} |
|
745 |
/* ensure that contents are written out */ |
|
746 |
ob_flush(); |
|
747 |
} |
|
748 |
|
|
749 |
/* |
|
750 |
* update_progress_bar($percent): updates the javascript driven progress bar. |
|
751 |
*/ |
|
752 |
function update_progress_bar($percent) { |
|
753 |
global $pkg_interface; |
|
754 |
if($percent > 100) $percent = 1; |
|
755 |
if($pkg_interface <> "console") { |
|
756 |
echo "\n<script type=\"text/javascript\" language=\"javascript\">"; |
|
757 |
echo "\ndocument.progressbar.style.width='" . $percent . "%';"; |
|
758 |
echo "\n</script>"; |
|
759 |
} else { |
|
760 |
echo " {$percent}%"; |
|
761 |
} |
|
762 |
} |
|
763 |
|
|
764 | 720 |
/****f* pfsense-utils/WakeOnLan |
765 | 721 |
* NAME |
766 | 722 |
* WakeOnLan - Wake a machine up using the wake on lan format/protocol |
... | ... | |
1071 | 1027 |
// $size, $used, $avail, $cap |
1072 | 1028 |
} |
1073 | 1029 |
|
1074 |
/****f* pfsense-utils/display_top_tabs |
|
1075 |
* NAME |
|
1076 |
* display_top_tabs - display tabs with rounded edges |
|
1077 |
* INPUTS |
|
1078 |
* $text - array of tabs |
|
1079 |
* RESULT |
|
1080 |
* null |
|
1081 |
******/ |
|
1082 |
function display_top_tabs(& $tab_array) { |
|
1083 |
global $HTTP_SERVER_VARS; |
|
1084 |
global $config; |
|
1085 |
global $g; |
|
1086 |
|
|
1087 |
/* does the user have access to this tab? |
|
1088 |
* master user has access to everything. |
|
1089 |
* if the user does not have access, simply |
|
1090 |
* unset the tab item. |
|
1091 |
*/ |
|
1092 |
|
|
1093 |
$tab_temp = array (); |
|
1094 |
foreach ($tab_array as $ta) |
|
1095 |
if(isAllowedPage($ta[2])) |
|
1096 |
$tab_temp[] = $ta; |
|
1097 |
/* |
|
1098 |
// FIXME : if the checks are not good enough |
|
1099 |
// in isAllowedPage, it needs to be |
|
1100 |
// fixed instead of kludging here |
|
1101 |
|
|
1102 |
// TODO: humm what shall we do with pkg_edit.php and pkg.php? |
|
1103 |
if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) { |
|
1104 |
$pos_equal = strpos($link, "="); |
|
1105 |
$pos_xmlsuffix = strpos($link, ".xml"); |
|
1106 |
// do we match an absolute url including ?xml= foo |
|
1107 |
if(!isAllowedPage($link, $allowed)) |
|
1108 |
$link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3)); |
|
1109 |
} |
|
1110 |
// next check - what if the basename contains a query string? |
|
1111 |
if ((strpos($link, "?")) !== false) { |
|
1112 |
$pos_qmark = strpos($link, "?"); |
|
1113 |
$link = substr($link, 0, $pos_qmark); |
|
1114 |
} |
|
1115 |
$authorized_text = print_r($allowed, true); |
|
1116 |
if(is_array($authorized)) |
|
1117 |
if (in_array(basename($link), $authorized)) |
|
1118 |
*/ |
|
1119 |
|
|
1120 |
unset ($tab_array); |
|
1121 |
$tab_array = & $tab_temp; |
|
1122 |
|
|
1123 |
$tab_active_bg = "#EEEEEE"; |
|
1124 |
$tab_inactive_bg = "#777777"; |
|
1125 |
$nifty_tabs_corners = "#FFF"; |
|
1126 |
$font_color = "white"; |
|
1127 |
|
|
1128 |
/* if tabcontrols.php exist for a theme, allow it to be overriden */ |
|
1129 |
$themename = $config['theme']; |
|
1130 |
$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php"; |
|
1131 |
if(file_exists($filename)) { |
|
1132 |
$eval_code = file_get_contents($filename); |
|
1133 |
eval($eval_code); |
|
1134 |
} |
|
1135 |
|
|
1136 |
$tabcharcount = 0; |
|
1137 |
foreach ($tab_array as $ta) |
|
1138 |
$tabcharcount = $tabcharcount + strlen($ta[0]); |
|
1139 |
|
|
1140 |
// If the character count of the tab names is > 670 |
|
1141 |
// then show a select item dropdown menubox. |
|
1142 |
if($tabcharcount > 82) { |
|
1143 |
echo "Currently viewing: "; |
|
1144 |
echo "<select name='TabSelect'>\n"; |
|
1145 |
foreach ($tab_array as $ta) { |
|
1146 |
if($ta[1]=="true") |
|
1147 |
$selected = " SELECTED"; |
|
1148 |
else |
|
1149 |
$selected = ""; |
|
1150 |
echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n"; |
|
1151 |
} |
|
1152 |
echo "</select>\n<p/>"; |
|
1153 |
} else { |
|
1154 |
echo "<table cellpadding='0' cellspacing='0'>\n"; |
|
1155 |
echo " <tr>\n"; |
|
1156 |
$tabscounter = 0; |
|
1157 |
foreach ($tab_array as $ta) { |
|
1158 |
if ($ta[1] == true) { |
|
1159 |
echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n"; |
|
1160 |
} else { |
|
1161 |
echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n"; |
|
1162 |
} |
|
1163 |
$tabscounter++; |
|
1164 |
} |
|
1165 |
echo "</tr>\n<tr>\n"; |
|
1166 |
foreach ($tab_array as $ta) { |
|
1167 |
if ($ta[1] == true) { |
|
1168 |
echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> {$ta[0]}"; |
|
1169 |
echo " "; |
|
1170 |
echo "<font size='-12'> </font></B></td>\n"; |
|
1171 |
} else { |
|
1172 |
echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> <a href='{$ta[2]}'>"; |
|
1173 |
echo "<font color='{$font_color}'>{$ta[0]}</font></a> "; |
|
1174 |
echo "<font size='-12'> </font></B></td>\n"; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
echo "</tr>\n<tr>\n"; |
|
1178 |
foreach ($tab_array as $ta) { |
|
1179 |
if ($ta[1] == true) { |
|
1180 |
echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n"; |
|
1181 |
} else { |
|
1182 |
echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n"; |
|
1183 |
} |
|
1184 |
$tabscounter++; |
|
1185 |
} |
|
1186 |
echo " </tr>\n"; |
|
1187 |
echo "</table>\n"; |
|
1188 |
echo "<script type=\"text/javascript\">"; |
|
1189 |
echo "NiftyCheck();\n"; |
|
1190 |
echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n"; |
|
1191 |
for ($x = 0; $x < $tabscounter; $x++) |
|
1192 |
echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n"; |
|
1193 |
echo "</script>"; |
|
1194 |
} |
|
1195 |
} |
|
1196 |
|
|
1197 |
|
|
1198 |
/****f* pfsense-utils/display_topbar |
|
1199 |
* NAME |
|
1200 |
* display_topbar - top a table off with rounded edges |
|
1201 |
* INPUTS |
|
1202 |
* $text - (optional) Text to include in bar |
|
1203 |
* RESULT |
|
1204 |
* null |
|
1205 |
******/ |
|
1206 |
function display_topbar($text = "", $bg_color="#990000", $replace_color="#FFFFFF", $rounding_style="smooth") { |
|
1207 |
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n"; |
|
1208 |
echo " <tr height='1'>\n"; |
|
1209 |
echo " <td width='100%' valign='top' color='{$bg_color}' bgcolor='{$bg_color}'>"; |
|
1210 |
echo " <div id='topbar'></div></td>\n"; |
|
1211 |
echo " </tr>\n"; |
|
1212 |
echo " <tr height='1'>\n"; |
|
1213 |
if ($text != "") |
|
1214 |
echo " <td height='1' class='listtopic'>{$text}</td>\n"; |
|
1215 |
else |
|
1216 |
echo " <td height='1' class='listtopic'></td>\n"; |
|
1217 |
echo " </tr>\n"; |
|
1218 |
echo " </table>"; |
|
1219 |
echo "<script type=\"text/javascript\">"; |
|
1220 |
echo "NiftyCheck();\n"; |
|
1221 |
echo "Rounded(\"div#topbar\",\"top\",\"{$replace_color}\",\"{$bg_color}\",\"{$rounding_style}\");\n"; |
|
1222 |
echo "</script>"; |
|
1223 |
} |
|
1224 |
|
|
1225 | 1030 |
/****f* pfsense-utils/strncpy |
1226 | 1031 |
* NAME |
1227 | 1032 |
* strncpy - copy strings |
... | ... | |
1579 | 1384 |
return $dhcpdenable; |
1580 | 1385 |
} |
1581 | 1386 |
|
1582 |
/****f* pfsense-utils/isAjax |
|
1583 |
* NAME |
|
1584 |
* isAjax - reports if the request is driven from prototype |
|
1585 |
* INPUTS |
|
1586 |
* none |
|
1587 |
* RESULT |
|
1588 |
* true/false |
|
1589 |
******/ |
|
1590 |
function isAjax() { |
|
1591 |
return isset ($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; |
|
1592 |
} |
|
1593 |
|
|
1594 | 1387 |
//returns interface information |
1595 | 1388 |
function get_interface_info($ifdescr) { |
1596 | 1389 |
global $config, $linkinfo, $netstatrninfo; |
... | ... | |
1889 | 1682 |
return $max_states; |
1890 | 1683 |
} |
1891 | 1684 |
|
1892 |
function rule_popup($src,$srcport,$dst,$dstport){ |
|
1893 |
global $config; |
|
1894 |
$aliases_array = array(); |
|
1895 |
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) |
|
1896 |
{ |
|
1897 |
$span_begin = ""; |
|
1898 |
$alias_src_span_begin = ""; |
|
1899 |
$alias_src_span_end = ""; |
|
1900 |
$alias_src_port_span_begin = ""; |
|
1901 |
$alias_src_port_span_end = ""; |
|
1902 |
$alias_dst_span_begin = ""; |
|
1903 |
$alias_dst_span_end = ""; |
|
1904 |
$alias_dst_port_span_begin = ""; |
|
1905 |
$alias_dst_port_span_end = ""; |
|
1906 |
$alias_content_text = ""; |
|
1907 |
foreach($config['aliases']['alias'] as $alias_name) |
|
1908 |
{ |
|
1909 |
$alias_addresses = explode (" ", $alias_name['address']); |
|
1910 |
$alias_details = explode ("||", $alias_name['detail']); |
|
1911 |
$alias_objects_with_details = ""; |
|
1912 |
$counter = 0; |
|
1913 |
foreach($alias_addresses as $alias_ports_address) |
|
1914 |
{ |
|
1915 |
$alias_objects_with_details .= $alias_addresses[$counter]; |
|
1916 |
$alias_detail_default = strpos ($alias_details[$counter],"Entry added"); |
|
1917 |
if ($alias_details[$counter] != "" && $alias_detail_default === False){ |
|
1918 |
$alias_objects_with_details .=" - " . $alias_details[$counter]; |
|
1919 |
} |
|
1920 |
$alias_objects_with_details .= "<br>"; |
|
1921 |
$counter++; |
|
1922 |
} |
|
1923 |
//max character length for caption field |
|
1924 |
$maxlength = 60; |
|
1925 |
|
|
1926 |
$alias_descr_substr = $alias_name['descr']; |
|
1927 |
$alias_content_text = htmlspecialchars($alias_objects_with_details); |
|
1928 |
$alias_caption = htmlspecialchars($alias_descr_substr . ":"); |
|
1929 |
$strlength = strlen ($alias_caption); |
|
1930 |
if ($strlength >= $maxlength) |
|
1931 |
$alias_caption = substr($alias_caption, 0, $maxlength) . "..."; |
|
1932 |
|
|
1933 |
$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>"; |
|
1934 |
|
|
1935 |
|
|
1936 |
if ($alias_name['name'] == $src) |
|
1937 |
{ |
|
1938 |
$alias_src_span_begin = $span_begin; |
|
1939 |
} |
|
1940 |
if ($alias_name['name'] == $srcport) |
|
1941 |
{ |
|
1942 |
$alias_src_port_span_begin = $span_begin; |
|
1943 |
} |
|
1944 |
if ($alias_name['name'] == $dst) |
|
1945 |
{ |
|
1946 |
$alias_dst_span_begin = $span_begin; |
|
1947 |
} |
|
1948 |
if ($alias_name['name'] == $dstport) |
|
1949 |
{ |
|
1950 |
$alias_dst_port_span_begin = $span_begin; |
|
1951 |
} |
|
1952 |
|
|
1953 |
} |
|
1954 |
$descriptions = array (); |
|
1955 |
$descriptions['src'] = $alias_src_span_begin; |
|
1956 |
$descriptions['srcport'] = $alias_src_port_span_begin; |
|
1957 |
$descriptions['dst'] = $alias_dst_span_begin; |
|
1958 |
$descriptions['dstport'] = $alias_dst_port_span_begin; |
|
1959 |
return $descriptions; |
|
1960 |
} |
|
1961 |
} |
|
1962 |
function download_file_with_progress_bar($url_file, $destination_file, $readbody = 'read_body') { |
|
1963 |
global $ch, $fout, $file_size, $downloaded; |
|
1964 |
$file_size = 1; |
|
1965 |
$downloaded = 1; |
|
1966 |
/* open destination file */ |
|
1967 |
$fout = fopen($destination_file, "wb"); |
|
1968 |
|
|
1969 |
/* |
|
1970 |
* Originally by Author: Keyvan Minoukadeh |
|
1971 |
* Modified by Scott Ullrich to return Content-Length size |
|
1972 |
*/ |
|
1973 |
|
|
1974 |
$ch = curl_init(); |
|
1975 |
curl_setopt($ch, CURLOPT_URL, $url_file); |
|
1976 |
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); |
|
1977 |
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $readbody); |
|
1978 |
curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); |
|
1979 |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '5'); |
|
1980 |
curl_setopt($ch, CURLOPT_TIMEOUT, 0); |
|
1981 |
|
|
1982 |
curl_exec($ch); |
|
1983 |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
1984 |
if($fout) |
|
1985 |
fclose($fout); |
|
1986 |
curl_close($ch); |
|
1987 |
return ($http_code == 200) ? true : $http_code; |
|
1988 |
} |
|
1989 |
|
|
1990 |
function read_header($ch, $string) { |
|
1991 |
global $file_size, $fout; |
|
1992 |
$length = strlen($string); |
|
1993 |
$regs = ""; |
|
1994 |
ereg("(Content-Length:) (.*)", $string, $regs); |
|
1995 |
if($regs[2] <> "") { |
|
1996 |
$file_size = intval($regs[2]); |
|
1997 |
} |
|
1998 |
ob_flush(); |
|
1999 |
return $length; |
|
2000 |
} |
|
2001 |
|
|
2002 |
function read_body($ch, $string) { |
|
2003 |
global $fout, $file_size, $downloaded, $sendto, $static_status, $static_output, $lastseen; |
|
2004 |
$length = strlen($string); |
|
2005 |
$downloaded += intval($length); |
|
2006 |
$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); |
|
2007 |
$downloadProgress = 100 - $downloadProgress; |
|
2008 |
if($lastseen <> $downloadProgress and $downloadProgress < 101) { |
|
2009 |
if($sendto == "status") { |
|
2010 |
$tostatus = $static_status . $downloadProgress . "%"; |
|
2011 |
update_status($tostatus); |
|
2012 |
} else { |
|
2013 |
$tooutput = $static_output . $downloadProgress . "%"; |
|
2014 |
update_output_window($tooutput); |
|
2015 |
} |
|
2016 |
update_progress_bar($downloadProgress); |
|
2017 |
$lastseen = $downloadProgress; |
|
2018 |
} |
|
2019 |
if($fout) |
|
2020 |
fwrite($fout, $string); |
|
2021 |
ob_flush(); |
|
2022 |
return $length; |
|
2023 |
} |
|
2024 |
|
|
2025 | 1685 |
/* Compare the current hostname DNS to the DNS cache we made |
2026 | 1686 |
* if it has changed we return the old records |
2027 | 1687 |
* if no change we return true */ |
Also available in: Unified diff
NOTE: There is some more work to be done for pkg-utils.inc to be removed from backend as a dependency.