* Copyright (c) 2014-2015 Gear Consulting Pty Ltd * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ function generate_priority_icon($priority) { $map = array( "emerg" => "server_delete", "alert" => "cancel", "crit" => "application_lightning", "err" => "application_delete", "warning" => "application_error", "notice" => "application_edit", "info" => "application", "debug" => "bug", "" => "application", ); $image = isset($map[$priority]) ? $map[$priority] : 'application'; return ''; } function generate_priority_status($priority) { $map = array( "emerg" => 2, "alert" => 2, "crit" => 2, "err" => 2, "warning" => 1, "notice" => 0, "info" => 0, "debug" => 3, "" => 0, ); return isset($map[$priority]) ? $map[$priority] : 0; } function format_number_short($number, $sf) { // This formats a number so that we only send back three digits plus an optional decimal point. // Example: 723.42 -> 723 72.34 -> 72.3 2.23 -> 2.23 list($whole, $decimal) = explode(".", $number); if (strlen($whole) >= $sf || !is_numeric($decimal)) { $number = $whole; } elseif (strlen($whole) < $sf) { $diff = $sf - strlen($whole); $number = $whole .".".substr($decimal, 0, $diff); } return $number; } function external_exec($command) { global $debug,$vdebug; if ($debug && !$vdebug) { $debug_command = preg_replace('/-c [\S]+/', '-c COMMUNITY', $command); $debug_command = preg_replace('/(udp|udp6|tcp|tcp6):(.*):([\d]+)/', '\1:HOSTNAME:\3', $debug_command); d_echo($debug_command); } elseif ($vdebug) { d_echo($command."\n"); } $output = shell_exec($command); if ($debug && !$vdebug) { $debug_output = preg_replace('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/', '*', $output); d_echo("$debug_output\n"); } elseif ($vdebug) { d_echo($output."\n"); } return $output; } function shorthost($hostname, $len = 12) { // IP addresses should not be shortened if (filter_var($hostname, FILTER_VALIDATE_IP)) { return $hostname; } $parts = explode(".", $hostname); $shorthost = $parts[0]; $i = 1; while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len) { $shorthost = $shorthost.'.'.$parts[$i]; $i++; } return ($shorthost); } function isCli() { if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { return true; } else { return false; } } function print_error($text) { if (isCli()) { c_echo("%r".$text."%n\n"); } else { echo('
'.$text.'
'); } } function print_message($text) { if (isCli()) { c_echo("%g".$text."%n\n"); } else { echo('