\n"; }else{ print "\n"; } return $current_color; } /* form_selectable_cell - format's a table row such that it can be highlighted using cacti's js actions @arg $contents - the readable portion of the @arg $id - the id of the object that will be highlighted @arg $width - the width of the table element @arg $style - the style to apply to the table element */ function form_selectable_cell($contents, $id, $width="", $style="") { print "\t" . $contents . "\n"; } /* form_checkbox_cell - format's a tables checkbox form element so that the cacti js actions work on it @arg $title - the text that will be displayed if your hover over the checkbox */ function form_checkbox_cell($title, $id) { print "\t\n"; print "\t\t\n"; print "\t\n"; } /* form_end_row - ends a table row that is started with form_alternate_row */ function form_end_row() { print "\n"; } /* html_boolean - returns the boolean equivalent of an HTML checkbox value @arg $html_boolean - the value of the HTML checkbox @returns - true or false based on the value of the HTML checkbox */ function html_boolean($html_boolean) { if ($html_boolean == "on") { return true; }else{ return false; } } /* html_boolean_friendly - returns the natural language equivalent of an HTML checkbox value @arg $html_boolean - the value of the HTML checkbox @returns - 'Selected' or 'Not Selected' based on the value of the HTML checkbox */ function html_boolean_friendly($html_boolean) { if ($html_boolean == "on") { return "Selected"; }else{ return "Not Selected"; } } /* get_checkbox_style - finds the proper CSS padding to apply based on the current client browser in use @returns - a CSS style string which should be used with an HTML checkbox control */ function get_checkbox_style() { if (get_web_browser() == "moz") { return "padding: 4px; margin: 4px;"; }elseif (get_web_browser() == "ie") { return "padding: 0px; margin: 0px;"; }elseif (get_web_browser() == "other") { return "padding: 4px; margin: 4px;"; } } /* get_request_var - returns the current value of a PHP $_GET variable, optionally returning a default value if the request variable does not exist @arg $name - the name of the request variable. this should be a valid key in the $_GET array @arg $default - the value to return if the specified name does not exist in the $_GET array @returns - the value of the request variable */ function get_request_var($name, $default = "") { if (isset($_GET[$name])) { if (isset($_POST[$name])) { unset($_POST[$name]); $_REQUEST[$name] = $_GET[$name]; } return $_GET[$name]; }else{ return $default; } } /* get_request_var_post - returns the current value of a PHP $_POST variable, optionally returning a default value if the request variable does not exist @arg $name - the name of the request variable. this should be a valid key in the $_POST array @arg $default - the value to return if the specified name does not exist in the $_POST array @returns - the value of the request variable */ function get_request_var_post($name, $default = "") { if (isset($_POST[$name])) { if (isset($_GET[$name])) { unset($_GET[$name]); $_REQUEST[$name] = $_POST[$name]; } return $_POST[$name]; }else{ return $default; } } /* get_request_var_request - returns the current value of a PHP $_POST variable, optionally returning a default value if the request variable does not exist @arg $name - the name of the request variable. this should be a valid key in the $_REQUEST array @arg $default - the value to return if the specified name does not exist in the $_REQUEST array @returns - the value of the request variable */ function get_request_var_request($name, $default = "") { if (isset($_REQUEST[$name])) { return $_REQUEST[$name]; } else { return $default; } } /* load_current_session_value - finds the correct value of a variable that is being cached as a session variable on an HTML form @arg $request_var_name - the array index name for the request variable @arg $session_var_name - the array index name for the session variable @arg $default_value - the default value to use if values cannot be obtained using the session or request array */ function load_current_session_value($request_var_name, $session_var_name, $default_value) { if (isset($_REQUEST[$request_var_name])) { $_SESSION[$session_var_name] = $_REQUEST[$request_var_name]; }elseif (isset($_SESSION[$session_var_name])) { $_REQUEST[$request_var_name] = $_SESSION[$session_var_name]; }else{ $_REQUEST[$request_var_name] = $default_value; } } /* get_colored_device_status - given a device's status, return the colored text in HTML format suitable for display @arg $disabled (bool) - true if the device is disabled, false is it is not @arg $status - the status type of the device as defined in global_constants.php @returns - a string containing html that represents the device's current status */ function get_colored_device_status($disabled, $status) { $disabled_color = "a1a1a1"; $status_colors = array( HOST_DOWN => "ff0000", HOST_ERROR => "750F7D", HOST_RECOVERING => "ff8f1e", HOST_UP => "198e32" ); if ($disabled) { return "Disabled"; }else{ switch ($status) { case HOST_DOWN: return "Down"; break; case HOST_RECOVERING: return "Recovering"; break; case HOST_UP: return "Up"; break; case HOST_ERROR: return "Error"; break; default: return "Unknown"; break; } } } /* get_current_graph_start - determine the correct graph start time selected using the timespan selector @returns - the number of seconds relative to now where the graph should begin */ function get_current_graph_start() { if (isset($_SESSION["sess_current_timespan_begin_now"])) { return $_SESSION["sess_current_timespan_begin_now"]; }else{ return "-" . DEFAULT_TIMESPAN; } } /* get_current_graph_end - determine the correct graph end time selected using the timespan selector @returns - the number of seconds relative to now where the graph should end */ function get_current_graph_end() { if (isset($_SESSION["sess_current_timespan_end_now"])) { return $_SESSION["sess_current_timespan_end_now"]; }else{ return "0"; } } /* get_page_list - generates the html necessary to present the user with a list of pages limited in length and number of rows per page @arg $current_page - the current page number @arg $pages_per_screen - the maximum number of pages allowed on a single screen. odd numbered values for this argument are prefered for equality reasons @arg $current_page - the current page number @arg $total_rows - the total number of available rows @arg $url - the url string to prepend to each page click @returns - a string containing html that represents the a page list */ function get_page_list($current_page, $pages_per_screen, $rows_per_page, $total_rows, $url, $page_var = "page") { $url_page_select = ""; $total_pages = ceil($total_rows / $rows_per_page); $start_page = max(1, ($current_page - floor(($pages_per_screen - 1) / 2))); $end_page = min($total_pages, ($current_page + floor(($pages_per_screen - 1) / 2))); /* adjust if we are close to the beginning of the page list */ if ($current_page <= ceil(($pages_per_screen) / 2)) { $end_page += ($pages_per_screen - $end_page); }else{ $url_page_select .= "..."; } /* adjust if we are close to the end of the page list */ if (($total_pages - $current_page) < ceil(($pages_per_screen) / 2)) { $start_page -= (($pages_per_screen - ($end_page - $start_page)) - 1); } /* stay within limits */ $start_page = max(1, $start_page); $end_page = min($total_pages, $end_page); //print "start: $start_page, end: $end_page, total: $total_pages
"; for ($page_number=0; (($page_number+$start_page) <= $end_page); $page_number++) { if ($page_number < $pages_per_screen) { if ($current_page == ($page_number + $start_page)) { $url_page_select .= "" . ($page_number + $start_page) . ""; }else{ $url_page_select .= "" . ($page_number + $start_page) . ""; } } if (($page_number+$start_page) < $end_page) { $url_page_select .= ","; } } if (($total_pages - $current_page) >= ceil(($pages_per_screen) / 2)) { $url_page_select .= "..."; } return $url_page_select; } /* clean_html_output - Remove all known cross site script (xss) attack vectors from user input @arg $data - User input to process @returns - Cleaned user input */ function clean_html_output($data) { /* remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed this prevents some character re-spacing such as note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs */ $data = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $data); /* straight replacements, the user should never need these since they're normal characters this prevents like */ $search = "abcdefghijklmnopqrstuvwxyz"; $search .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $search .= "1234567890!@#$%^&*()"; $search .= "~`\";:?+/={}[]-_|\'\\"; for ($i = 0; $i < strlen($search); $i++) { /* ;? matches the ;, which is optional 0{0,7} matches any padded zeros, which are optional and go up to 8 chars */ /* @ @ search for the hex values */ $data = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $data); /* @ @ 0{0,7} matches '0' zero to seven times */ $data = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $data); } /* defined keywords to process for removal */ $keywords = Array( "javascript", "vbscript", "expression", "applet", "meta", "xml", "blink", "link", "style", "script", "embed", "object", "iframe", "frame", "frameset", "ilayer", "layer", "bgsound", "title", "base", "onabort", "onactivate", "onafterprint", "onafterupdate", "onbeforeactivate", "onbeforecopy", "onbeforecut", "onbeforedeactivate", "onbeforeeditfocus", "onbeforepaste", "onbeforeprint", "onbeforeunload", "onbeforeupdate", "onblur", "onbounce", "oncellchange", "onchange", "onclick", "oncontextmenu", "oncontrolselect", "oncopy", "oncut", "ondataavailable", "ondatasetchanged", "ondatasetcomplete", "ondblclick", "ondeactivate", "ondrag", "ondragend", "ondragenter", "ondragleave", "ondragover", "ondragstart", "ondrop", "onerror", "onerrorupdate", "onfilterchange", "onfinish", "onfocus", "onfocusin", "onfocusout", "onhelp", "onkeydown", "onkeypress", "onkeyup", "onlayoutcomplete", "onload", "onlosecapture", "onmousedown", "onmouseenter", "onmouseleave", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onmousewheel", "onmove", "onmoveend", "onmovestart", "onpaste", "onpropertychange", "onreadystatechange", "onreset", "onresize", "onresizeend", "onresizestart", "onrowenter", "onrowexit", "onrowsdelete", "onrowsinserted", "onscroll", "onselect", "onselectionchange", "onselectstart", "onstart", "onstop", "onsubmit", "onunload" ); $found = true; while ($found == true) { $data_before = $data; for ($i = 0; $i < sizeof($keywords); $i++) { $pattern = '/'; for ($j = 0; $j < strlen($keywords[$i]); $j++) { if ($j > 0) { $pattern .= '('; $pattern .= '(&#[xX]0{0,8}([9ab]);)'; $pattern .= '|'; $pattern .= '|(�{0,8}([9|10|13]);)'; $pattern .= ')*'; } $pattern .= $keywords[$i][$j]; } $pattern .= '/i'; /* add in <> to nerf the tag */ $replacement = substr($keywords[$i], 0, 2).''.substr($keywords[$i], 2); $data = preg_replace($pattern, $replacement, $data); /* filter out the hex tags */ if ($data_before == $data) { /* no replacements were made, so exit the loop */ $found = false; } } } return $data; } ?>