1<?php 2 3// Pandora FMS - http://pandorafms.com 4// ================================================== 5// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas 6// Please see http://pandorafms.org for full contribution list 7 8// This program is free software; you can redistribute it and/or 9// modify it under the terms of the GNU Lesser General Public License 10// as published by the Free Software Foundation; version 2 11 12// This program is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17/** 18 * @package Include 19 * @subpackage UI 20 */ 21 22// Check to avoid error when load this library in error screen situations 23if (isset($config['homedir'])) { 24 require_once($config['homedir'] . '/include/functions_agents.php'); 25 require_once($config['homedir'] . '/include/functions_modules.php'); 26 require_once($config['homedir'] . '/include/functions.php'); 27 require_once($config['homedir'] . '/include/functions_groups.php'); 28 require_once($config['homedir'] . '/include/functions_users.php'); 29 require_once($config['homedir'] . '/include/functions_html.php'); 30} 31 32function ui_bbcode_to_html($text, $allowed_tags = array('[url]')) { 33 $return = ""; 34 35 $return = $text; 36 37 if (array_search('[url]', $allowed_tags) !== false) { 38 $return = str_replace('[/url]', '</a>', $return); 39 $return = preg_replace("/\[url=([^\]]*)\]/", "<a href=\"$1\">", $return); 40 } 41 42 return $return; 43} 44 45/** 46 * Truncate a text to num chars (pass as parameter) and if flag show tooltip is 47 * true the html artifal to show the tooltip with rest of text. 48 * 49 * @param string $text The text to truncate. 50 * @param mixed $numChars Number chars (-3 for char "[...]") max the text. Or the strings "agent_small", "agent_medium", "module_small", "module_medium", "description" or "generic" for to take the values from user config. 51 * @param boolean $showTextInAToopTip Flag to show the tooltip. 52 * @param boolean $return Flag to return as string or not. 53 * @param boolean $showTextInTitle Flag to show the text on title. 54 * @param string $suffix String at the end of a strimmed string. 55 * @param string $style Style associated to the text. 56 * 57 * @return string Truncated text. 58 */ 59function ui_print_truncate_text($text, $numChars = GENERIC_SIZE_TEXT, $showTextInAToopTip = true, $return = true, $showTextInTitle = true, $suffix = '…', $style = false) { 60 global $config; 61 62 if (is_string($numChars)) { 63 switch ($numChars) { 64 case 'agent_small': 65 $numChars = $config['agent_size_text_small']; 66 break; 67 case 'agent_medium': 68 $numChars = $config['agent_size_text_medium']; 69 break; 70 case 'module_small': 71 $numChars = $config['module_size_text_small']; 72 break; 73 case 'module_medium': 74 $numChars = $config['module_size_text_medium']; 75 break; 76 case 'description': 77 $numChars = $config['description_size_text']; 78 break; 79 case 'item_title': 80 $numChars = $config['item_title_size_text']; 81 break; 82 default: 83 $numChars = (int)$numChars; 84 break; 85 } 86 } 87 88 89 if ($numChars == 0) { 90 if ($return == true) { 91 return $text; 92 } 93 else { 94 echo $text; 95 } 96 } 97 98 $text = io_safe_output($text); 99 if (mb_strlen($text, "UTF-8") > ($numChars)) { 100 // '/2' because [...] is in the middle of the word. 101 $half_length = intval(($numChars - 3) / 2); 102 103 // Depending on the strange behavior of mb_strimwidth() itself, 104 // the 3rd parameter is not to be $numChars but the length of 105 // original text (just means 'large enough'). 106 $truncateText2 = mb_strimwidth($text, 107 (mb_strlen($text, "UTF-8") - $half_length), 108 mb_strlen($text, "UTF-8"), "", "UTF-8" ); 109 110 $truncateText = mb_strimwidth($text, 0, 111 ($numChars - $half_length), "", "UTF-8") . $suffix; 112 113 $truncateText = $truncateText . $truncateText2; 114 115 if ($showTextInTitle) { 116 if ($style === null) { 117 $truncateText = $truncateText; 118 } 119 else if ($style !== false) { 120 $truncateText = '<span style="' . $style . '" title="' . $text . '">' . 121 $truncateText . '</span>'; 122 } 123 else { 124 $truncateText = '<span title="' . $text . '">' . $truncateText . '</span>'; 125 } 126 } 127 if ($showTextInAToopTip) { 128 $truncateText = $truncateText . ui_print_help_tip($text, true); 129 } 130 else { 131 if ($style !== false) { 132 $truncateText = '<span style="' . $style . '">' . $truncateText . '</span>'; 133 } 134 } 135 } 136 else { 137 if ($style !== false) { 138 $truncateText = '<span style="' . $style . '">' . $text . '</span>'; 139 } 140 else { 141 $truncateText = $text; 142 } 143 } 144 145 if ($return == true) { 146 return $truncateText; 147 } 148 else { 149 echo $truncateText; 150 } 151} 152 153/** 154 * Print a string with a smaller font depending on its size. 155 * 156 * @param string $string String to be display with a smaller font. 157 * @param boolean $return Flag to return as string or not. 158 */ 159function printSmallFont ($string, $return = true) { 160 $str = io_safe_output($string); 161 $length = strlen($str); 162 if ($length >= 30) { 163 $size = 0.7; 164 } 165 elseif ($length >= 20) { 166 $size = 0.8; 167 } 168 elseif ($length >= 10) { 169 $size = 0.9; 170 } 171 elseif ($length < 10) { 172 $size = 1; 173 } 174 175 $s = '<span style="font-size: '.$size.'em;">'; 176 $s .= $string; 177 $s .= '</span>'; 178 if ($return) { 179 return $s; 180 } 181 else { 182 echo $s; 183 } 184} 185 186/** 187 * Prints a generic message between tags. 188 * 189 * @param mixed The string message or array ('title', 'message', 'icon', 'no_close', 'force_style') to be displayed 190 * @param string the class to user 191 * @param string Any other attributes to be set for the tag. 192 * @param bool Whether to output the string or return it 193 * @param string What tag to use (you could specify something else than 194 * h3 like div or h2) 195 * 196 * @return string HTML code if return parameter is true. 197 */ 198function ui_print_message ($message, $class = '', $attributes = '', $return = false, $tag = 'h3') { 199 static $first_execution = true; 200 201 $text_title = ''; 202 $text_message = ''; 203 $icon_image = ''; 204 $no_close_bool = false; 205 $force_style = ''; 206 if (is_array($message)) { 207 if (!empty($message['title'])) 208 $text_title = $message['title']; 209 if (!empty($message['message'])) 210 $text_message = $message['message']; 211 if (!empty($message['icon'])) 212 $icon_image = $message['icon']; 213 if (!empty($message['no_close'])) 214 $no_close_bool = $message['no_close']; 215 if (!empty($message['force_style'])) 216 $force_style = $message['force_style']; 217 } 218 else { 219 $text_message = $message; 220 } 221 222 if (empty($text_title)) { 223 switch ($class) { 224 default: 225 case 'info': 226 $text_title = __('Information'); 227 break; 228 case 'error': 229 $text_title = __('Error'); 230 break; 231 case 'suc': 232 $text_title = __('Success'); 233 break; 234 case 'warning': 235 $text_title = __('Warning'); 236 break; 237 } 238 } 239 240 if (empty($icon_image)) { 241 switch ($class) { 242 default: 243 case 'info': 244 $icon_image = 'images/information_big.png'; 245 break; 246 case 'error': 247 $icon_image = 'images/err.png'; 248 break; 249 case 'suc': 250 $icon_image = 'images/suc.png'; 251 break; 252 case 'warning': 253 $icon_image = 'images/warning_big.png'; 254 break; 255 } 256 257 $icon_image = $icon_image; 258 } 259 260 $id = 'info_box_' . uniqid(); 261 262 //Use the no_meta parameter because this image is only in the base console 263 $output = '<table cellspacing="0" cellpadding="0" id="' . $id . '" ' . $attributes . ' 264 class="info_box ' . $id . ' ' . $class . '" style="' . $force_style . '"> 265 <tr> 266 <td class="icon" rowspan="2" style="padding-right: 10px; padding-top: 3px;">' . html_print_image($icon_image, true, false, false, false, true) . '</td> 267 <td class="title" style="text-transform: uppercase; padding-top: 10px;"><b>' . $text_title . '</b></td> 268 <td class="icon" style="text-align: right; padding-right: 3px;">'; 269 if (!$no_close_bool) { 270 //Use the no_meta parameter because this image is only in the base console 271 $output .= '<a href="javascript: close_info_box(\'' . $id . '\')">' . 272 html_print_image('images/blade.png', true, false, false, false, true) . '</a>'; 273 } 274 275 $output .= '</td> 276 </tr> 277 <tr> 278 <td style="color:#222">' . $text_message . '</td> 279 <td></td> 280 </tr> 281 </table>'; 282 283 if (($first_execution) && (!$no_close_bool)) { 284 $first_execution = false; 285 286 $output .= ' 287 <script type="text/javascript"> 288 function close_info_box(id) { 289 $("." + id).hide(); 290 } 291 </script> 292 '; 293 } 294 295 if ($return) 296 return $output; 297 else 298 echo $output; 299 300 return ''; 301} 302 303/** 304 * Prints an error message. 305 * 306 * @param mixed The string error message or array ('title', 'message', 'icon', 'no_close') to be displayed 307 * @param string Any other attributes to be set for the tag. 308 * @param bool Whether to output the string or return it 309 * @param string What tag to use (you could specify something else than 310 * h3 like div or h2) 311 * 312 * @return string HTML code if return parameter is true. 313 */ 314function ui_print_error_message ($message, $attributes = '', $return = false, $tag = 'h3') { 315 return ui_print_message ($message, 'error', $attributes, $return, $tag); 316} 317 318/** 319 * Prints an operation success message. 320 * 321 * @param mixed The string message or array ('title', 'message', 'icon', 'no_close') to be displayed 322 * @param string Any other attributes to be set for the tag. 323 * @param bool Whether to output the string or return it 324 * @param string What tag to use (you could specify something else than 325 * h3 like div or h2) 326 * 327 * @return string HTML code if return parameter is true. 328 */ 329function ui_print_success_message ($message, $attributes = '', $return = false, $tag = 'h3') { 330 return ui_print_message ($message, 'suc', $attributes, $return, $tag); 331} 332 333/** 334 * Prints an operation info message. 335 * 336 * @param mixed The string message or array ('title', 'message', 'icon', 'no_close') to be displayed 337 * @param string Any other attributes to be set for the tag. 338 * @param bool Whether to output the string or return it 339 * @param string What tag to use (you could specify something else than 340 * h3 like div or h2) 341 * 342 * @return string HTML code if return parameter is true. 343 */ 344function ui_print_info_message ($message, $attributes = '', $return = false, $tag = 'h3') { 345 return ui_print_message ($message, 'info', $attributes, $return, $tag); 346} 347 348function ui_print_empty_data($message, $attributes = '', $return = false, $tag = 'h3') { 349 return ui_print_message ($message, 'info', $attributes, $return, $tag); 350} 351 352/** 353 * Evaluates a result using empty() and then prints an error or success message 354 * 355 * @param mixed The results to evaluate. 0, NULL, false, '' or 356 * array() is bad, the rest is good 357 * @param mixed The string or array ('title', 'message') to be displayed if the result was good 358 * @param mixed The string or array ('title', 'message') to be displayed if the result was bad 359 * @param string Any other attributes to be set for the h3 360 * @param bool Whether to output the string or return it 361 * @param string What tag to use (you could specify something else than 362 * h3 like div or h2) 363 * 364 * @return string HTML code if return parameter is true. 365 */ 366function ui_print_result_message ($result, $good = '', $bad = '', $attributes = '', $return = false, $tag = 'h3') { 367 if ($good == '' || $good === false) 368 $good = __('Request successfully processed'); 369 370 if ($bad == '' || $bad === false) 371 $bad = __('Error processing request'); 372 373 if (empty ($result)) { 374 return ui_print_error_message ($bad, $attributes, $return, $tag); 375 } 376 else { 377 return ui_print_success_message ($good, $attributes, $return, $tag); 378 } 379} 380 381/** 382 * Prints an warning message. 383 * 384 * @param mixed The string warning message or array ('title', 'message', 'icon', 'no_close') to be displayed 385 * @param string Any other attributes to be set for the tag. 386 * @param bool Whether to output the string or return it 387 * @param string What tag to use (you could specify something else than 388 * h3 like div or h2) 389 * 390 * @return string HTML code if return parameter is true. 391 */ 392function ui_print_warning_message ($message, $attributes = '', $return = false, $tag = 'h3') { 393 return ui_print_message ($message, 'warning', $attributes, $return, $tag); 394} 395 396/** 397 * Evaluates a unix timestamp and returns a span (or whatever tag specified) 398 * with as title the correctly formatted full timestamp and a time comparation 399 * in the tag 400 * 401 * @param int Any type of timestamp really, but we prefer unixtime 402 * @param bool Whether to output the string or return it 403 * @param array An array with different options for this function 404 * Key html_attr: which html attributes to add (defaults to none) 405 * Key tag: Which html tag to use (defaults to span) 406 * Key prominent: Overrides user preference and display "comparation" or "timestamp" 407 * key units: The type of units. 408 * 409 * @return string HTML code if return parameter is true. 410 */ 411function ui_print_timestamp ($unixtime, $return = false, $option = array ()) { 412 global $config; 413 414 //TODO: Add/use a javascript timer for the seconds so it automatically updates as time passes by 415 416 if (isset ($option["html_attr"])) { 417 $attributes = $option["html_attr"]; 418 } 419 else { 420 $attributes = ""; 421 } 422 423 if (isset ($option["tag"])) { 424 $tag = $option["tag"]; 425 } 426 else { 427 $tag = "span"; 428 } 429 430 if (empty ($option["style"])) { 431 $style = 'style="white-space:nowrap;"'; 432 } 433 else { 434 $style = 'style="' . $option["style"] . '"'; 435 } 436 437 if (!empty ($option["prominent"])) { 438 $prominent = $option["prominent"]; 439 } 440 else { 441 $prominent = $config["prominent_time"]; 442 } 443 444 if (!is_numeric ($unixtime)) { 445 $unixtime = strtotime ($unixtime); 446 } 447 448 //prominent_time is either timestamp or comparation 449 if ($unixtime <= 0) { 450 $title = __('Unknown') . '/' . __('Never'); 451 $data = __('Unknown'); 452 } 453 elseif ($prominent == "timestamp") { 454 $title = human_time_comparation ($unixtime); 455 $data = date ($config["date_format"], $unixtime); 456 } 457 else { 458 $title = date ($config["date_format"], $unixtime); 459 $units = 'large'; 460 if (isset($option['units'])) { 461 $units = $option['units']; 462 } 463 $data = human_time_comparation ($unixtime, $units); 464 } 465 466 $output = '<'.$tag; 467 switch ($tag) { 468 default: 469 //Usually tags have title attributes, so by default we add, 470 //then fall through to add attributes and data 471 $output .= ' title="'.$title.'" '.$style.'>'.$data.'</'.$tag.'>'; 472 break; 473 case "h1": 474 case "h2": 475 case "h3": 476 //Above tags don't have title attributes 477 $output .= ' '.$attributes.' '.$style.'>'.$data.'</'.$tag.'>'; 478 break; 479 } 480 481 if ($return) 482 return $output; 483 484 echo $output; 485} 486 487/** 488 * Prints a username with real name, link to the user_edit page etc. 489 * 490 * @param string The username to render 491 * @param bool Whether to return or print 492 * 493 * @return string HTML code if return parameter is true. 494 */ 495function ui_print_username ($username, $return = false) { 496 $string = '<a href="index.php?sec=usuario&sec2=operation/users/user_edit&id='.$username.'">'.get_user_fullname ($username).'</a>'; 497 498 if ($return) 499 return $string; 500 501 echo $string; 502} 503 504function ui_print_tags_warning ($return = false) { 505 $msg = '<div id="notify_conf" class="notify">'; 506 $msg .= __("Is possible that this view uses part of information which your user has not access"); 507 $msg .= '</div>'; 508 509 if ($return) { 510 return $msg; 511 } 512 else { 513 echo $msg; 514 } 515} 516 517/** 518 * Print group icon within a link 519 * 520 * @param int Group id 521 * @param bool Whether to return or print 522 * @param string What path to use (relative to images/). Defaults to groups_small 523 * @param string Style for group image 524 * @param bool Whether the group have link or not 525 * 526 * @return string HTML code if return parameter is true. 527 */ 528function ui_print_group_icon ($id_group, $return = false, $path = "groups_small", $style='', $link = true, $force_show_image = false, $show_as_image = false) { 529 global $config; 530 531 if ($id_group > 0) 532 $icon = (string) db_get_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); 533 else 534 $icon = "world"; 535 536 537 $output = ''; 538 539 // Don't show link in metaconsole 540 if (defined('METACONSOLE')) 541 $link = false; 542 543 if ($link) 544 $output = '<a href="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$id_group.'">'; 545 546 if ($config['show_group_name']) { 547 $output .= '<span title="'. groups_get_name($id_group, true) .'">' . 548 groups_get_name($id_group, true) . ' </span>'; 549 } 550 else { 551 if (empty ($icon)) 552 $output .= '<span title="'. groups_get_name($id_group, true).'"> </span>'; 553 else { 554 $output .= html_print_image("images/" . $path . "/" . $icon . ".png", 555 true, array("style" => $style, "class" => "bot", "alt" => groups_get_name($id_group, true), "title" => groups_get_name ($id_group, true))); 556 } 557 } 558 559 if ($link) 560 $output .= '</a>'; 561 562 if (!$return) 563 echo $output; 564 565 return $output; 566} 567 568/** 569 * Print group icon within a link. Other version. 570 * 571 * @param int Group id 572 * @param bool Whether to return or print 573 * @param string What path to use (relative to images/). Defaults to groups_small 574 * 575 * @return string HTML code if return parameter is true. 576 */ 577function ui_print_group_icon_path ($id_group, $return = false, $path = "images/groups_small", $style='', $link = true) { 578 if ($id_group > 0) 579 $icon = (string) db_get_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); 580 else 581 $icon = "world"; 582 583 if ($style == '') 584 $style = 'width: 16px; height: 16px;'; 585 586 $output = ''; 587 if ($link) 588 $output = '<a href="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$id_group.'">'; 589 590 if (empty ($icon)) 591 $output .= '<span title="'. groups_get_name($id_group, true).'"> - </span>'; 592 else 593 $output .= '<img style="' . $style . '" class="bot" src="'.$path.'/'.$icon.'.png" alt="'.groups_get_name ($id_group, true).'" title="'.groups_get_name ($id_group, true).'" />'; 594 595 if ($link) 596 $output .= '</a>'; 597 598 if (!$return) 599 echo $output; 600 601 return $output; 602} 603 604/** 605 * Get the icon of an operating system. 606 * 607 * @param int Operating system id 608 * @param bool Whether to also append the name of the OS after the icon 609 * @param bool Whether to return or echo the result 610 * @param bool Whether to apply skin or not 611 * 612 * @return string HTML with icon of the OS 613 */ 614function ui_print_os_icon ($id_os, $name = true, $return = false, 615 $apply_skin = true, $networkmap = false, $only_src = false, 616 $relative = false, $options = false) { 617 618 619 620 $subfolter = 'os_icons'; 621 if ($networkmap) { 622 $subfolter = 'networkmap'; 623 } 624 625 $icon = (string) db_get_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os); 626 $os_name = get_os_name ($id_os); 627 if (empty ($icon)) { 628 if ($only_src) { 629 $output = html_print_image("images/" . $subfolter . "/unknown.png", 630 true, $options, true, $relative); 631 } 632 else { 633 return "-"; 634 } 635 } 636 637 if ($apply_skin) { 638 if ($only_src) { 639 $output = html_print_image("images/" . $subfolter . "/" . $icon, true, $options, true, $relative); 640 } 641 else { 642 if (!isset($options['title'])) { 643 $options['title'] = $os_name; 644 } 645 $output = html_print_image("images/" . $subfolter . "/" . $icon, true, $options, false, $relative); 646 } 647 } 648 else 649 //$output = "<img src='images/os_icons/" . $icon . "' alt='" . $os_name . "' title='" . $os_name . "'>"; 650 $output = "images/" . $subfolter . "/" . $icon; 651 652 if ($name === true) { 653 $output .= ' ' . $os_name; 654 } 655 656 if (!$return) 657 echo $output; 658 659 return $output; 660} 661 662/** 663 * Prints an agent name with the correct link 664 * 665 * @param int Agent id 666 * @param bool Whether to return the string or echo it too 667 * @param int Now uses styles to accomplish this 668 * @param string Style of name in css. 669 * @param string server url to concatenate at the begin of the link 670 * @param string extra parameters to concatenate in the link 671 * @param string name of the agent to avoid the query in some cases 672 * @param bool if the agent will provided with link or not 673 * 674 * @return string HTML with agent name and link 675 */ 676function ui_print_agent_name ($id_agent, $return = false, $cutoff = 'agent_medium', $style = '', $cutname = false, $server_url = '', $extra_params = '', $known_agent_name = false, $link = true) { 677 if ($known_agent_name === false) { 678 $agent_name = (string) agents_get_name ($id_agent); 679 } 680 else { 681 $agent_name = $known_agent_name; 682 } 683 684 $agent_name_full = $agent_name; 685 if ($cutname) { 686 $agent_name = ui_print_truncate_text($agent_name, $cutoff, true, true, true, '[…]', $style); 687 } 688 689 if ($link) { 690 $url = $server_url . 'index.php?sec=estado&'. 691 'sec2=operation/agentes/ver_agente&' . 692 'id_agente=' . $id_agent.$extra_params; 693 694 $output = '<a style="' . $style . '"' . 695 ' href="' . $url . '"' . 696 ' title="'.$agent_name_full.'"><b><span style="'.$style.'">'.$agent_name.'</span></b></a>'; 697 } 698 else { 699 $output = '<b><span style="'.$style.'">'.$agent_name.'</span></b>'; 700 } 701 702 //TODO: Add a pretty javascript (using jQuery) popup-box with agent details 703 704 if ($return) 705 return $output; 706 707 echo $output; 708} 709 710/** 711 * Formats a row from the alert table and returns an array usable in the table function 712 * 713 * @param array A valid (non empty) row from the alert table 714 * @param bool Whether or not this is a combined alert 715 * @param bool Whether to print the agent information with the module information 716 * @param string Tab where the function was called from (used for urls) 717 * @param mixed Style for agent name or default (false) 718 * 719 * @return array A formatted array with proper html for use in $table->data (6 columns) 720 */ 721function ui_format_alert_row ($alert, $agent = true, $url = '', $agent_style = false) { 722 global $config; 723 724 if (!isset($alert['server_data'])) { 725 $server_name = ''; 726 $server_id = ''; 727 $url_hash = ''; 728 $console_url = ''; 729 } 730 else { 731 $server_data = $alert['server_data']; 732 $server_name = $server_data['server_name']; 733 $server_id = $server_data['id']; 734 $console_url = $server_data['server_url'] . '/'; 735 $url_hash = metaconsole_get_servers_url_hash($server_data); 736 } 737 738 $actionText = ""; 739 require_once ($config['homedir'] . "/include/functions_alerts.php"); 740 $isFunctionPolicies = enterprise_include_once ('include/functions_policies.php'); 741 $id_group = (int) get_parameter ("ag_group", 0); //0 is the All group (selects all groups) 742 743 if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { 744 if ($agent) { 745 $index = array('policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 4, 746 'description' => 5, 'template' => 5, 'action' => 6, 'last_fired' => 7, 'status' => 8, 747 'validate' => 9); 748 } 749 else { 750 $index = array('policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 3, 751 'description' => 4, 'template' => 4, 'action' => 5, 'last_fired' => 6, 'status' => 7, 752 'validate' => 8); 753 } 754 } 755 else { 756 if ($agent) { 757 $index = array('standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 3, 758 'description' => 4, 'template' => 4, 'action' => 5, 'last_fired' => 6, 'status' => 7, 759 'validate' => 8); 760 } 761 else { 762 $index = array('standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 2, 763 'description' => 3, 'template' => 3, 'action' => 4, 'last_fired' => 5, 'status' => 6, 764 'validate' => 7); 765 } 766 } 767 768 if ($alert['disabled']) { 769 $disabledHtmlStart = '<span style="font-style: italic; color: #aaaaaa;">'; 770 $disabledHtmlEnd = '</span>'; 771 $styleDisabled = "font-style: italic; color: #aaaaaa;"; 772 } 773 else { 774 $disabledHtmlStart = ''; 775 $disabledHtmlEnd = ''; 776 $styleDisabled = ""; 777 } 778 779 if (empty ($alert)) 780 { 781 if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) 782 return array ("", "", "", "", "", "", "", ""); 783 else 784 return array ("", "", "", "", "", "", ""); 785 } 786 787 // Get agent id 788 $id_agent = modules_get_agentmodule_agent ($alert['id_agent_module']); 789 $template = alerts_get_alert_template ($alert['id_alert_template']); 790 $description = io_safe_output($template['name']); 791 792 $data = array (); 793 794 if (!defined('METACONSOLE')) { 795 if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { 796 $policyInfo = policies_is_alert_in_policy2($alert['id'], false); 797 if ($policyInfo === false) 798 $data[$index['policy']] = ''; 799 else { 800 $img = 'images/policies.png'; 801 802 $data[$index['policy']] = '<a href="?sec=gpolicies&sec2=enterprise/godmode/policies/policies&id=' . $policyInfo['id'] . '">' . 803 html_print_image($img,true, array('title' => $policyInfo['name'])) . 804 '</a>'; 805 } 806 } 807 } 808 809 // Standby 810 $data[$index['standby']] = ''; 811 if (isset ($alert["standby"]) && $alert["standby"] == 1) { 812 $data[$index['standby']] = html_print_image ('images/bell_pause.png', true, array('title' => __('Standby on'))); 813 } 814 815 if (!defined('METACONSOLE')) { 816 // Force alert execution 817 $data[$index['force_execution']] = ''; 818 if ($alert["force_execution"] == 0) { 819 $data[$index['force_execution']] = 820 '<a href="'.$url.'&id_alert='.$alert["id"].'&force_execution=1&refr=60">' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . '</a>'; 821 } 822 else { 823 $data[$index['force_execution']] = 824 '<a href="'.$url.'&id_alert='.$alert["id"].'&refr=60">' . html_print_image("images/refresh.png", true) . '</a>'; 825 } 826 } 827 828 $data[$index['agent_name']] = $disabledHtmlStart; 829 if ($agent == 0) { 830 $data[$index['module_name']] .= 831 ui_print_truncate_text(isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name ($alert["id_agent_module"]), 'module_small', false, true, true, '[…]', 'font-size: 7.2pt'); 832 } 833 else { 834 if (defined('METACONSOLE')) { 835 $agent_name = $alert['agent_name']; 836 $id_agent = $alert['id_agent']; 837 } 838 else { 839 $agent_name = false; 840 $id_agent = modules_get_agentmodule_agent ($alert["id_agent_module"]); 841 } 842 843 if (defined('METACONSOLE') && !can_user_access_node ()) { 844 $data[$index['agent_name']] = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '[…]', 'font-size:7.5pt;'); 845 } 846 else { 847 if ($agent_style !== false) { 848 $data[$index['agent_name']] .= ui_print_agent_name ($id_agent, true, 'agent_medium', $styleDisabled . " $agent_style", false, $console_url, $url_hash, $agent_name); 849 } 850 else { 851 $data[$index['agent_name']] .= ui_print_agent_name ($id_agent, true, 'agent_medium', $styleDisabled, false, $console_url, $url_hash); 852 } 853 } 854 855 $data[$index['module_name']] = 856 ui_print_truncate_text (isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name ($alert["id_agent_module"]), 'module_small', false, true, true, '[…]', 'font-size: 7.2pt'); 857 } 858 859 $data[$index['agent_name']] .= $disabledHtmlEnd; 860 861 $data[$index['description']] = ''; 862 863 if (defined('METACONSOLE')) { 864 $data[$index['template']] .= '<a class="template_details" href="' . ui_get_full_url('/', false, false, false) . '/ajax.php?page=enterprise/meta/include/ajax/tree_view.ajax&action=get_template_tooltip&id_template=' . $template['id'] . '&server_name=' . $alert['server_data']['server_name'] . '">'; 865 } 866 else { 867 $data[$index['template']] .= '<a class="template_details" href="ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template=' . $template['id'] . '">'; 868 } 869 $data[$index['template']] .= html_print_image ('images/zoom.png', true); 870 $data[$index['template']] .= '</a> '; 871 $actionDefault = db_get_value_sql("SELECT id_alert_action 872 FROM talert_templates WHERE id = " . $alert['id_alert_template']); 873 874 $data[$index['description']] .= $disabledHtmlStart . 875 ui_print_truncate_text (io_safe_output($description), 'description', false, true, true, '[…]', 'font-size: 7.1pt') . 876 $disabledHtmlEnd; 877 878 $actions = alerts_get_alert_agent_module_actions ($alert['id'], false); 879 880 if (!empty($actions)) { 881 $actionText = '<div><ul class="action_list">'; 882 foreach ($actions as $action) { 883 $actionText .= '<div style="margin-bottom: 5px;" ><span class="action_name"><li>' . $action['name']; 884 if ($action["fires_min"] != $action["fires_max"]) { 885 $actionText .= " (".$action["fires_min"] . " / ". $action["fires_max"] . ")"; 886 } 887 $actionText .= '</li></span></div>'; 888 } 889 $actionText .= '</ul></div>'; 890 } 891 else { 892 if ($actionDefault != "") 893 $actionText = db_get_sql ("SELECT name FROM talert_actions WHERE id = $actionDefault"). " <i>(".__("Default") . ")</i>"; 894 } 895 896 $data[$index['action']] = $actionText; 897 898 $data[$index['last_fired']] = $disabledHtmlStart . ui_print_timestamp ($alert["last_fired"], true) . $disabledHtmlEnd; 899 900 901 $status = STATUS_ALERT_NOT_FIRED; 902 $title = ""; 903 904 if ($alert["times_fired"] > 0) { 905 $status = STATUS_ALERT_FIRED; 906 $title = __('Alert fired').' '.$alert["times_fired"].' '.__('times'); 907 } 908 elseif ($alert["disabled"] > 0) { 909 $status = STATUS_ALERT_DISABLED; 910 $title = __('Alert disabled'); 911 } 912 else { 913 $status = STATUS_ALERT_NOT_FIRED; 914 $title = __('Alert not fired'); 915 } 916 917 $data[$index['status']] = ui_print_status_image($status, $title, true); 918 919 if (!defined('METACONSOLE')) { 920 if (check_acl ($config["id_user"], $id_group, "LW") || check_acl ($config["id_user"], $id_group, "LM")) { 921 $data[$index['validate']] = ''; 922 923 924 $data[$index['validate']] .= html_print_checkbox ("validate[]", $alert["id"], false, true); 925 } 926 } 927 928 return $data; 929} 930 931/** 932 * Prints a substracted string, length specified by cutoff, the full string will be in a rollover. 933 * 934 * @param string The string to be cut 935 * @param int At how much characters to cut 936 * @param bool Whether to return or print it out 937 * @param int Size font (fixed) in px, applyed as CSS style (optional) 938 * 939 * @return An HTML string 940 */ 941function ui_print_string_substr ($string, $cutoff = 16, $return = false, $fontsize = 0) { 942 if (empty ($string)) { 943 return ""; 944 } 945 946 $string2 = io_safe_output ($string); 947 if (mb_strlen($string2, "UTF-8") > $cutoff) { 948 $string3 = "..."; 949 } 950 else { 951 $string3 = ""; 952 } 953 954 $font_size_mod = ""; 955 956 if ($fontsize > 0) { 957 $font_size_mod = "style='font-size: ".$fontsize."pt'"; 958 } 959 $string = '<span '.$font_size_mod.' title="'.io_safe_input($string2).'">'.mb_substr ($string2, 0, $cutoff, "UTF-8").$string3.'</span>'; 960 961 if ($return === false) { 962 echo $string; 963 } 964 965 return $string; 966} 967 968/** 969 * Gets a helper text explaining the requirement needs for an alert template 970 * to get it fired. 971 * 972 * @param int Alert template id. 973 * @param bool Wheter to return or print it out. 974 * @param bool Wheter to put the values in the string or not. 975 * 976 * @return An HTML string if return was true. 977 */ 978function ui_print_alert_template_example ($id_alert_template, $return = false, $print_values = true) { 979 $output = ''; 980 981 $output .= html_print_image("images/information.png", true); 982 $output .= '<span id="example">'; 983 $template = alerts_get_alert_template ($id_alert_template); 984 985 switch ($template['type']) { 986 case 'equal': 987 /* Do not translate the HTML attributes */ 988 $output .= __('The alert would fire when the value is <span id="value"></span>'); 989 break; 990 case 'not_equal': 991 /* Do not translate the HTML attributes */ 992 $output .= __('The alert would fire when the value is not <span id="value"></span>'); 993 break; 994 case 'regex': 995 if ($template['matches_value']) 996 /* Do not translate the HTML attributes */ 997 $output .= __('The alert would fire when the value matches <span id="value"></span>'); 998 else 999 /* Do not translate the HTML attributes */ 1000 $output .= __('The alert would fire when the value doesn\'t match <span id="value"></span>'); 1001 $value = $template['value']; 1002 break; 1003 case 'max_min': 1004 if ($template['matches_value']) 1005 /* Do not translate the HTML attributes */ 1006 $output .= __('The alert would fire when the value is between <span id="min"></span> and <span id="max"></span>'); 1007 else 1008 /* Do not translate the HTML attributes */ 1009 $output .= __('The alert would fire when the value is not between <span id="min"></span> and <span id="max"></span>'); 1010 break; 1011 case 'max': 1012 /* Do not translate the HTML attributes */ 1013 $output .= __('The alert would fire when the value is over <span id="max"></span>'); 1014 1015 break; 1016 case 'min': 1017 /* Do not translate the HTML attributes */ 1018 $output .= __('The alert would fire when the value is under <span id="min"></span>'); 1019 1020 break; 1021 case 'warning': 1022 /* Do not translate the HTML attributes */ 1023 $output .= __('The alert would fire when the module is in warning status'); 1024 1025 break; 1026 case 'critical': 1027 /* Do not translate the HTML attributes */ 1028 $output .= __('The alert would fire when the module is in critical status'); 1029 break; 1030 } 1031 1032 if ($print_values) { 1033 /* Replace span elements with real values. This is done in such way to avoid 1034 duplicating strings and make it easily modificable via Javascript. */ 1035 $output = str_replace ('<span id="value"></span>', $template['value'], $output); 1036 $output = str_replace ('<span id="max"></span>', $template['max_value'], $output); 1037 $output = str_replace ('<span id="min"></span>', $template['min_value'], $output); 1038 } 1039 $output .= '</span>'; 1040 if ($return) 1041 return $output; 1042 echo $output; 1043} 1044 1045/** 1046 * Prints a help tip icon. 1047 * 1048 * @param string Id of the help article 1049 * @param bool Whether to return or output the result 1050 * @param string Home url if its necessary 1051 * @param string Image path 1052 * 1053 * @return string The help tip 1054 */ 1055function ui_print_help_icon ($help_id, $return = false, $home_url = '', $image = "images/help.png") { 1056 if (empty($home_url)) 1057 $home_url = ""; 1058 1059 if (defined('METACONSOLE')) { 1060 $home_url = "../../" . $home_url; 1061 } 1062 1063 $output = html_print_image ($image, true, 1064 array ("class" => "img_help", 1065 "title" => __('Help'), 1066 "onclick" => "open_help ('" . $help_id . "','" . $home_url . "')")); 1067 if (!$return) 1068 echo $output; 1069 1070 return $output; 1071} 1072 1073/** 1074 * Add a CSS file to the HTML head tag. 1075 * 1076 * To make a CSS file available just put it in include/styles. The 1077 * file name should be like "name.css". The "name" would be the value 1078 * needed to pass to this function. 1079 * 1080 * @param string Script name to add without the "jquery." prefix and the ".js" 1081 * suffix. Example: 1082 * <code> 1083 * ui_require_css_file ('pandora'); 1084 * // Would include include/styles/pandora.js 1085 * </code> 1086 * 1087 * @return bool True if the file was added. False if the file doesn't exist. 1088 */ 1089function ui_require_css_file ($name, $path = 'include/styles/') { 1090 global $config; 1091 1092 $filename = $path . $name . '.css'; 1093 1094 if (! isset ($config['css'])) 1095 $config['css'] = array (); 1096 1097 if (isset ($config['css'][$name])) 1098 return true; 1099 1100 if (! file_exists ($filename) && 1101 ! file_exists ($config['homedir'] . '/' . $filename)) 1102 return false; 1103 1104 $config['css'][$name] = $filename; 1105 1106 return true; 1107} 1108 1109/** 1110 * Add a javascript file to the HTML head tag. 1111 * 1112 * To make a javascript file available just put it in include/javascript. The 1113 * file name should be like "name.js". The "name" would be the value 1114 * needed to pass to this function. 1115 * 1116 * @param string Script name to add without the "jquery." prefix and the ".js" 1117 * suffix. Example: 1118 * <code> 1119 * ui_require_javascript_file ('pandora'); 1120 * // Would include include/javascript/pandora.js 1121 * </code> 1122 * @param bool Just echo the script tag of the file. 1123 * 1124 * @return bool True if the file was added. False if the file doesn't exist. 1125 */ 1126function ui_require_javascript_file ($name, $path = 'include/javascript/', $echo_tag = false) { 1127 global $config; 1128 1129 $filename = $path . $name . '.js'; 1130 1131 if ($echo_tag) { 1132 echo '<script type="text/javascript" src="' . 1133 ui_get_full_url(false, false, false, false) . 1134 $filename . '"></script>'; 1135 return; 1136 } 1137 1138 if (! isset ($config['js'])) 1139 $config['js'] = array (); 1140 1141 if (isset ($config['js'][$name])) 1142 return true; 1143 1144 /* We checks two paths because it may fails on enterprise */ 1145 if (! file_exists ($filename) && ! file_exists ($config['homedir'] . '/' . $filename)) 1146 return false; 1147 1148 if (defined('METACONSOLE')) { 1149 $config['js'][$name] = "../../" . $filename; 1150 } 1151 else { 1152 $config['js'][$name] = $filename; 1153 } 1154 1155 return true; 1156} 1157 1158/** 1159 * Add a enteprise javascript file to the HTML head tag. 1160 * 1161 * To make a javascript file available just put it in <ENTERPRISE_DIR>/include/javascript. The 1162 * file name should be like "name.js". The "name" would be the value 1163 * needed to pass to this function. 1164 * 1165 * @param string Script name to add without the "jquery." prefix and the ".js" 1166 * suffix. Example: 1167 * <code> 1168 * ui_require_javascript_file ('pandora'); 1169 * // Would include include/javascript/pandora.js 1170 * </code> 1171 * 1172 * @return bool True if the file was added. False if the file doesn't exist. 1173 */ 1174function ui_require_javascript_file_enterprise($name, $disabled_metaconsole = false) { 1175 global $config; 1176 1177 $metaconsole_hack = ''; 1178 if ($disabled_metaconsole) { 1179 $metaconsole_hack = '../../'; 1180 } 1181 1182 $filename = $metaconsole_hack . ENTERPRISE_DIR . '/include/javascript/' .$name.'.js'; 1183 1184 if (! isset ($config['js'])) 1185 $config['js'] = array (); 1186 1187 if (isset ($config['js'][$name])) 1188 return true; 1189 1190 /* We checks two paths because it may fails on enterprise */ 1191 if (!file_exists ($filename) && 1192 !file_exists ($config['homedir'] . '/' . $filename)) { 1193 1194 return false; 1195 } 1196 1197 $config['js'][$name] = $filename; 1198 1199 return true; 1200} 1201 1202/** 1203 * Add a jQuery file to the HTML head tag. 1204 * 1205 * To make a jQuery script available just put it in include/javascript. The 1206 * file name should be like "jquery.name.js". The "name" would be the value 1207 * needed to pass to this function. Notice that this function does not manage 1208 * jQuery denpendencies. 1209 * 1210 * @param string Script name to add without the "jquery." prefix and the ".js" 1211 * suffix. Example: 1212 * <code> 1213 * ui_require_jquery_file ('form'); 1214 * // Would include include/javascript/jquery.form.js 1215 * </code> 1216 * @param bool Just echo the script tag of the file. 1217 * 1218 * @return bool True if the file was added. False if the file doesn't exist. 1219 */ 1220function ui_require_jquery_file ($name, $path = 'include/javascript/', $echo_tag = false) { 1221 global $config; 1222 1223 $filename = $path.'jquery.'.$name.'.js'; 1224 1225 if ($echo_tag) { 1226 echo '<script type="text/javascript" src="' . 1227 ui_get_full_url(false, false, false, false) . 1228 $filename . '"></script>'; 1229 return; 1230 } 1231 1232 if (! isset ($config['jquery'])) 1233 $config['jquery'] = array (); 1234 if (isset ($config['jquery'][$name])) 1235 return true; 1236 /* We checks two paths because it may fails on enterprise */ 1237 if (! file_exists ($filename) && ! file_exists ($config['homedir'].'/'.$filename)) 1238 return false; 1239 1240 $config['jquery'][$name] = $filename; 1241 1242 return true; 1243} 1244 1245/** 1246 * Callback function to add stuff to the head. This allows us to add scripts 1247 * to the header after the fact as well as extensive validation. 1248 * 1249 * DO NOT CALL print_f, echo, ob_start, ob_flush, ob_end functions here. 1250 * 1251 * To add css just put them in include/styles and then add them to the 1252 * $config['css'] array 1253 * 1254 * @param string Callback will fill this with the current buffer. 1255 * @param bitfield Callback will fill this with a bitfield (see ob_start) 1256 * 1257 * @return string String to return to the browser 1258 */ 1259function ui_process_page_head ($string, $bitfield) { 1260 global $config; 1261 global $vc_public_view; 1262 1263 if (isset ($config['ignore_callback']) && $config['ignore_callback'] == true) { 1264 return; 1265 } 1266 1267 $output = ''; 1268 1269 $config_refr = -1; 1270 if (isset($config["refr"])) 1271 $config_refr = $config["refr"]; 1272 1273 // If user is logged or displayed view is the public view of visual console 1274 if ($config_refr > 0 && 1275 (isset($config['id_user']) || $vc_public_view == 1)) { 1276 1277 if ($config['enable_refr'] || 1278 $_GET['sec2'] == 'operation/agentes/estado_agente' || 1279 $_GET['sec2'] == 'operation/agentes/tactical' || 1280 $_GET['sec2'] == 'operation/agentes/group_view' || 1281 $_GET['sec2'] == 'operation/events/events' || 1282 $_GET['sec2'] == 'operation/snmpconsole/snmp_view' || 1283 $_GET['sec2'] == 'enterprise/dashboard/main_dashboard') { 1284 1285 $query = ui_get_url_refresh (false, false); 1286 $output .= '<meta http-equiv="refresh" content="' . 1287 $config_refr . '; URL=' . $query . '" />'; 1288 1289 } 1290 } 1291 $output .= "\n\t"; 1292 $output .= '<title>Pandora FMS - '.__('the Flexible Monitoring System').'</title> 1293 <meta http-equiv="expires" content="never" /> 1294 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 1295 <meta http-equiv="Content-Style-Type" content="text/css" /> 1296 <meta name="resource-type" content="document" /> 1297 <meta name="distribution" content="global" /> 1298 <meta name="author" content="Pandora FMS Developer team" /> 1299 <meta name="copyright" content="(c) Artica Soluciones Tecnologicas" /> 1300 <meta name="keywords" content="pandora, monitoring, system, GPL, software" /> 1301 <meta name="robots" content="index, follow" /> 1302 <link rel="icon" href="images/pandora.ico" type="image/ico" /> 1303 <link rel="shortcut icon" href="images/pandora.ico" type="image/x-icon" /> 1304 <link rel="alternate" href="operation/events/events_rss.php" title="Pandora RSS Feed" type="application/rss+xml" />'; 1305 1306 if ($config["language"] != "en") { 1307 //Load translated strings - load them last so they overload all the objects 1308 ui_require_javascript_file ("time_".$config["language"]); 1309 ui_require_javascript_file ("date".$config["language"]); 1310 ui_require_javascript_file ("countdown_".$config["language"]); 1311 } 1312 $output .= "\n\t"; 1313 1314 1315 1316 1317 1318 //////////////////////////////////////////////////////////////////// 1319 //Load CSS 1320 //////////////////////////////////////////////////////////////////// 1321 if (empty ($config['css'])) { 1322 $config['css'] = array (); 1323 } 1324 1325 $login_ok = true; 1326 if (! isset ($config['id_user']) && isset ($_GET["login"])) { 1327 if (isset($_POST['nick']) and isset($_POST['pass'])) { 1328 $nick = get_parameter_post ("nick"); //This is the variable with the login 1329 $pass = get_parameter_post ("pass"); //This is the variable with the password 1330 $nick = db_escape_string_sql($nick); 1331 $pass = db_escape_string_sql($pass); 1332 1333 // process_user_login is a virtual function which should be defined in each auth file. 1334 // It accepts username and password. The rest should be internal to the auth file. 1335 // The auth file can set $config["auth_error"] to an informative error output or reference their internal error messages to it 1336 // process_user_login should return false in case of errors or invalid login, the nickname if correct 1337 $nick_in_db = process_user_login ($nick, $pass); 1338 1339 if ($nick_in_db === false) { 1340 $login_ok = false; 1341 } 1342 } 1343 } 1344 1345 //First, if user has assigned a skin then try to use css files of 1346 //skin subdirectory 1347 $isFunctionSkins = enterprise_include_once ('include/functions_skins.php'); 1348 if (!$login_ok) { 1349 if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { 1350 enterprise_hook('skins_cleanup'); 1351 } 1352 } 1353 1354 1355 $exists_css = false; 1356 if ($login_ok and $isFunctionSkins !== ENTERPRISE_NOT_HOOK) { 1357 //Checks if user's skin is available 1358 $exists_skin = enterprise_hook('skins_is_path_set'); 1359 if ($exists_skin) { 1360 $skin_path = enterprise_hook('skins_get_skin_path'); 1361 $skin_styles = themes_get_css ($skin_path . 'include/styles/'); 1362 $exists_css = !empty($skin_styles); 1363 } 1364 } 1365 //If skin's css files exists then add them 1366 if ($exists_css) { 1367 foreach ($skin_styles as $filename => $name) { 1368 $style = substr ($filename, 0, strlen ($filename) - 4); 1369 $config['css'][$style] = $skin_path . 'include/styles/' . $filename; 1370 } 1371 } 1372 //Otherwise assign default and user's css 1373 else { 1374 //User style should go last so it can rewrite common styles 1375 $config['css'] = array_merge (array ( 1376 "common" => "include/styles/common.css", 1377 "menu" => "include/styles/menu.css", 1378 $config['style'] => "include/styles/" . $config['style'] . ".css"), 1379 $config['css']); 1380 } 1381 1382 1383 1384 // Add the jquery UI styles CSS 1385 $config['css']['jquery-UI'] = "include/styles/jquery-ui-1.10.0.custom.css"; 1386 // Add the dialog styles CSS 1387 $config['css']['dialog'] = "include/styles/dialog.css"; 1388 // Add the dialog styles CSS 1389 $config['css']['dialog'] = "include/javascript/introjs.css"; 1390 1391 1392 1393 //We can't load empty and we loaded (conditionally) ie 1394 $loaded = array ('', 'ie'); 1395 1396 foreach ($config['css'] as $name => $filename) { 1397 if (in_array ($name, $loaded)) 1398 continue; 1399 1400 array_push ($loaded, $name); 1401 1402 $url_css = ui_get_full_url($filename); 1403 $output .= '<link rel="stylesheet" href="' . $url_css . '" type="text/css" />'."\n\t"; 1404 1405 } 1406 //////////////////////////////////////////////////////////////////// 1407 //End load CSS 1408 //////////////////////////////////////////////////////////////////// 1409 1410 1411 1412 1413 //////////////////////////////////////////////////////////////////// 1414 //Load JS 1415 //////////////////////////////////////////////////////////////////// 1416 if (empty ($config['js'])) { 1417 $config['js'] = array (); //If it's empty, false or not init set array to empty just in case 1418 } 1419 1420 1421 //Pandora specific JavaScript should go first 1422 $config['js'] = array_merge (array ("pandora" => "include/javascript/pandora.js"), $config['js']); 1423 //Load base64 javascript library 1424 $config['js']['base64'] = "include/javascript/encode_decode_base64.js"; 1425 //Load webchat javascript library 1426 $config['js']['webchat'] = "include/javascript/webchat.js"; 1427 //Load qrcode library 1428 $config['js']['qrcode'] = "include/javascript/qrcode.js"; 1429 //Load intro.js library (for bubbles and clippy) 1430 $config['js']['intro'] = "include/javascript/intro.js"; 1431 $config['js']['clippy'] = "include/javascript/clippy.js"; 1432 //Load Underscore.js library 1433 $config['js']['underscore'] = "include/javascript/underscore-min.js"; 1434 1435 1436 //Load other javascript 1437 //We can't load empty 1438 $loaded = array (''); 1439 foreach ($config['js'] as $name => $filename) { 1440 if (in_array ($name, $loaded)) 1441 continue; 1442 1443 array_push ($loaded, $name); 1444 1445 $url_js = ui_get_full_url($filename); 1446 $output .= '<script type="text/javascript" src="' . $url_js . '"></script>'."\n\t"; 1447 } 1448 //////////////////////////////////////////////////////////////////// 1449 //End load JS 1450 //////////////////////////////////////////////////////////////////// 1451 1452 1453 1454 //////////////////////////////////////////////////////////////////// 1455 //Load jQuery 1456 //////////////////////////////////////////////////////////////////// 1457 if (empty ($config['jquery'])) { 1458 $config['jquery'] = array (); //If it's empty, false or not init set array to empty just in case 1459 } 1460 1461 //Pandora specific jquery should go first 1462 $black_list_pages_old_jquery = array('operation/gis_maps/index'); 1463 if (in_array(get_parameter('sec2'), $black_list_pages_old_jquery)) { 1464 $config['jquery'] = array_merge ( 1465 array ("jquery" => "include/javascript/jquery.js", 1466 "ui" => "include/javascript/jquery.ui.core.js", 1467 "dialog" => "include/javascript/jquery.ui.dialog.js", 1468 "pandora" => "include/javascript/jquery.pandora.js"), 1469 $config['jquery']); 1470 } 1471 else { 1472 $config['jquery'] = array_merge( 1473 array ("jquery" => "include/javascript/jquery-1.9.0.js", 1474 "pandora" => "include/javascript/jquery.pandora.js", 1475 'jquery-ui' => 'include/javascript/jquery.jquery-ui-1.10.0.custom.js'), 1476 $config['jquery']); 1477 } 1478 1479 // Include the datapicker language if exists 1480 if (file_exists('include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js')) { 1481 $config['jquery']['datepicker_language'] = 'include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js'; 1482 } 1483 1484 1485 // Include countdown library 1486 $config['jquery']['countdown'] = 'include/javascript/jquery.countdown.js'; 1487 1488 1489 //Then add each script as necessary 1490 $loaded = array (''); 1491 foreach ($config['jquery'] as $name => $filename) { 1492 if (in_array ($name, $loaded)) 1493 continue; 1494 1495 array_push ($loaded, $name); 1496 1497 $url_js = ui_get_full_url($filename); 1498 $output .= '<script type="text/javascript" src="' . $url_js . '"></script>'."\n\t"; 1499 } 1500 //////////////////////////////////////////////////////////////////// 1501 //End load JQuery 1502 //////////////////////////////////////////////////////////////////// 1503 1504 1505 1506 1507 if ($config['flash_charts']) { 1508 //Include the javascript for the js charts library 1509 include_once($config["homedir"] . '/include/graphs/functions_flot.php'); 1510 $output .= include_javascript_dependencies_flot_graph(true); 1511 } 1512 1513 1514 $output .= '<!--[if gte IE 6]> 1515 <link rel="stylesheet" href="include/styles/ie.css" type="text/css"/> 1516 <![endif]-->'; 1517 1518 $output .= $string; 1519 1520 1521 return $output; 1522} 1523 1524/** 1525 * Callback function to add stuff to the body 1526 * 1527 * @param string Callback will fill this with the current buffer. 1528 * @param bitfield Callback will fill this with a bitfield (see ob_start) 1529 * 1530 * @return string String to return to the browser 1531 */ 1532function ui_process_page_body ($string, $bitfield) { 1533 global $config; 1534 1535 if (isset ($config['ignore_callback']) && 1536 $config['ignore_callback'] == true) { 1537 return; 1538 } 1539 1540 // Show custom background 1541 $output = '<body'.($config["pure"] ? ' class="pure"' : '').'>'; 1542 1543 1544 $output .= $string; 1545 1546 1547 $output .= '</body>'; 1548 1549 return $output; 1550} 1551 1552/** 1553 * Prints a pagination menu to browse into a collection of data. 1554 * 1555 * @param int $count Number of elements in the collection. 1556 * @param string $url URL of the pagination links. It must include all form 1557 * values as GET form. 1558 * @param int $offset Current offset for the pagination. Default value would be 1559 * taken from $_REQUEST['offset'] 1560 * @param int $pagination Current pagination size. If a user requests a larger 1561 * pagination than config["block_size"] 1562 * @param bool $return Whether to return or print this 1563 * @param string $offset_name The name of parameter for the offset. 1564 * @param bool $print_total_items Show the text with the total items. By default true. 1565 * 1566 * @return string The pagination div or nothing if no pagination needs to be done 1567 */ 1568function ui_pagination ($count, $url = false, $offset = 0, 1569 $pagination = 0, $return = false, $offset_name = 'offset', 1570 $print_total_items = true, $other_class = '', 1571 $script = "", 1572 $parameter_script = array('count' => '', 'offset' => 'offset_param')) { 1573 1574 global $config; 1575 1576 if (empty ($pagination)) { 1577 $pagination = (int) $config["block_size"]; 1578 } 1579 1580 if (is_string ($offset)) { 1581 $offset_name = $offset; 1582 $offset = (int) get_parameter ($offset_name); 1583 } 1584 1585 if (empty ($offset)) { 1586 $offset = (int) get_parameter ($offset_name); 1587 } 1588 1589 if (empty ($url)) { 1590 $url = ui_get_url_refresh (array ($offset_name => false)); 1591 } 1592 1593 /* 1594 URL passed render links with some parameter 1595 &offset - Offset records passed to next page 1596 &counter - Number of items to be blocked 1597 Pagination needs $url to build the base URL to render links, its a base url, like 1598 " http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs " 1599 */ 1600 $block_limit = PAGINATION_BLOCKS_LIMIT; // Visualize only $block_limit blocks 1601 if ($count <= $pagination) { 1602 1603 if ($print_total_items) { 1604 $output = "<div class='pagination $other_class'>"; 1605 //Show the count of items 1606 $output .= sprintf(__('Total items: %s'), $count); 1607 // End div and layout 1608 $output .= "</div>"; 1609 1610 if ($return === false) 1611 echo $output; 1612 1613 return $output; 1614 } 1615 1616 return false; 1617 } 1618 1619 $number_of_pages = ceil($count / $pagination); 1620 //~ html_debug_print('number_of_pages'); 1621 //~ html_debug_print($number_of_pages); 1622 $actual_page = floor($offset / $pagination); 1623 //~ html_debug_print('actual_page'); 1624 //~ html_debug_print($actual_page); 1625 $ini_page = floor($actual_page / $block_limit) * $block_limit; 1626 //~ html_debug_print('ini_page'); 1627 //~ html_debug_print($ini_page); 1628 $end_page = $ini_page + $block_limit - 1; 1629 if ($end_page > $number_of_pages) { 1630 $end_page = $number_of_pages - 1; 1631 } 1632 //~ html_debug_print('end_page'); 1633 //~ html_debug_print($end_page); 1634 1635 1636 $output = "<div class='pagination $other_class'>"; 1637 1638 //Show the count of items 1639 if ($print_total_items) { 1640 $output .= sprintf(__('Total items: %s'), $count); 1641 $output .= '<br>'; 1642 } 1643 1644 // Show GOTO FIRST PAGE button 1645 if ($number_of_pages > $block_limit) { 1646 1647 if (!empty($script)) { 1648 $script_modified = $script; 1649 $script_modified = str_replace( 1650 $parameter_script['count'], $count, $script_modified); 1651 $script_modified = str_replace( 1652 $parameter_script['offset'], 0, $script_modified); 1653 1654 $output .= "<a class='pagination $other_class offset_0' 1655 href='javascript: $script_modified;'>" . 1656 html_print_image ("images/go_first.png", true, array ("class" => "bot")) . 1657 "</a> "; 1658 } 1659 else { 1660 $output .= "<a class='pagination $other_class offset_0' href='$url&$offset_name=0'>" . 1661 html_print_image ("images/go_first.png", true, array ("class" => "bot")) . 1662 "</a> "; 1663 } 1664 } 1665 1666 // Show PREVIOUS PAGE GROUP OF PAGES 1667 // For example 1668 // You are in the 12 page with a block of 5 pages 1669 // << < 10 - 11 - [12] - 13 - 14 > >> 1670 // Click in < 1671 // Result << < 5 - 6 - 7 - 8 - [9] > >> 1672 if ($ini_page >= $block_limit) { 1673 $offset_previous_page = ($ini_page - 1) * $pagination; 1674 1675 if (!empty($script)) { 1676 $script_modified = $script; 1677 $script_modified = str_replace( 1678 $parameter_script['count'], $count, $script_modified); 1679 $script_modified = str_replace( 1680 $parameter_script['offset'], $offset_previous_page, $script_modified); 1681 1682 $output .= "<a class='pagination $other_class offset_$offset_previous_page' 1683 href='javacript: $script_modified;'>" . 1684 html_print_image ("images/go_previous.png", true, array ("class" => "bot")) . 1685 "</a>"; 1686 } 1687 else { 1688 $output .= "<a class='pagination $other_class offset_$offset_previous_page' href='$url&$offset_name=$offset_previous_page'>" . 1689 html_print_image ("images/go_previous.png", true, array ("class" => "bot")) . 1690 "</a>"; 1691 } 1692 } 1693 1694 1695 // Show pages 1696 for ($iterator = $ini_page; $iterator <= $end_page; $iterator++) { 1697 1698 $actual_page = (int)($offset / $pagination); 1699 1700 if ($iterator == $actual_page) { 1701 $output .= "<span style='font-weight: bold;'>"; 1702 } 1703 else { 1704 $output .= "<span>"; 1705 } 1706 1707 $offset_page = $iterator * $pagination; 1708 1709 if (!empty($script)) { 1710 $script_modified = $script; 1711 $script_modified = str_replace( 1712 $parameter_script['count'], $count, $script_modified); 1713 $script_modified = str_replace( 1714 $parameter_script['offset'], $offset_page, $script_modified); 1715 1716 $output .= "<a class='pagination $other_class offset_$offset_page' 1717 href='javascript: $script_modified;'>"; 1718 } 1719 else { 1720 1721 $output .= "<a class='pagination $other_class offset_$offset_page' href='$url&$offset_name=$offset_page'>"; 1722 1723 } 1724 1725 $output .= "[ $iterator ]"; 1726 1727 $output .= '</a></span>'; 1728 1729 } 1730 1731 1732 // Show NEXT PAGE GROUP OF PAGES 1733 // For example 1734 // You are in the 12 page with a block of 5 pages 1735 // << < 10 - 11 - [12] - 13 - 14 > >> 1736 // Click in > 1737 // Result << < [15] - 16 - 17 - 18 - 19 > >> 1738 if ($number_of_pages - $ini_page > $block_limit) { 1739 $offset_next_page = ($end_page + 1) * $pagination; 1740 1741 if (!empty($script)) { 1742 $script_modified = $script; 1743 $script_modified = str_replace( 1744 $parameter_script['count'], $count, $script_modified); 1745 $script_modified = str_replace( 1746 $parameter_script['offset'], $offset_next_page, $script_modified); 1747 1748 $output .= "<a class='pagination $other_class offset_$offset_next_page' 1749 href='javascript: $script_modified;'>" . 1750 html_print_image ("images/go_next.png", true, array ("class" => "bot")) . 1751 "</a>"; 1752 } 1753 else { 1754 $output .= "<a class='pagination $other_class offset_$offset_next_page' href='$url&$offset_name=$offset_next_page'>" . 1755 html_print_image ("images/go_next.png", true, array ("class" => "bot")) . 1756 "</a>"; 1757 } 1758 } 1759 1760 //Show GOTO LAST PAGE button 1761 if ($number_of_pages > $block_limit) { 1762 $offset_lastpage = ($number_of_pages - 1) * $pagination; 1763 1764 1765 if (!empty($script)) { 1766 $script_modified = $script; 1767 $script_modified = str_replace( 1768 $parameter_script['count'], $count, $script_modified); 1769 $script_modified = str_replace( 1770 $parameter_script['offset'], $offset_lastpage, $script_modified); 1771 1772 $output .= "<a class='pagination $other_class offset_$offset_lastpage' 1773 href='javascript: $script_modified;'>" . 1774 html_print_image ("images/go_last.png", true, array ("class" => "bot")) . 1775 "</a>"; 1776 } 1777 else { 1778 $output .= "<a class='pagination $other_class offset_$offset_lastpage' href='$url&$offset_name=$offset_lastpage'>" . 1779 html_print_image ("images/go_last.png", true, array ("class" => "bot")) . 1780 "</a>"; 1781 } 1782 } 1783 1784 // End div and layout 1785 $output .= "</div>"; 1786 1787 if ($return === false) 1788 echo $output; 1789 1790 return $output; 1791} 1792 1793/** 1794 * Prints only a tip button which shows a text when the user puts the mouse over it. 1795 * 1796 * @param string Complete text to show in the tip 1797 * @param bool whether to return an output string or echo now 1798 * @param img displayed image 1799 * 1800 * @return string HTML code if return parameter is true. 1801 */ 1802function ui_print_session_action_icon ($action, $return = false) { 1803 $key_icon = array( 1804 'acl' => 'images/delete.png', 1805 'agent' => 'images/agent.png', 1806 'module' => 'images/module.png', 1807 'alert' => 'images/bell.png', 1808 'incident' => 'images/default_list.png', 1809 'logon' => 'images/house.png', 1810 'logoff' => 'images/house.png', 1811 'massive' => 'images/config.png', 1812 'hack' => 'images/application_edit.png', 1813 'event' => 'images/lightning_go.png', 1814 'policy' => 'images/policies.png', 1815 'report' => 'images/reporting.png', 1816 'file collection' => 'images/collection_col.png', 1817 'user' => 'images/user_green.png', 1818 'password' => 'images/lock.png', 1819 'session' => 'images/heart_col.png', 1820 'snmp' => 'images/snmp.png', 1821 'command' => 'images/bell.png', 1822 'category' => 'images/category_col.png', 1823 'dashboard' => 'images/dashboard_col.png', 1824 'api' => 'images/eye.png', 1825 'db' => 'images/database.png', 1826 'setup' => 'images/cog.png'); 1827 1828 $output = ''; 1829 foreach($key_icon as $key => $icon) { 1830 if (stristr($action, $key) !== false) { 1831 $output = html_print_image($icon, true, array('title' => $action)) . ' '; 1832 break; 1833 } 1834 } 1835 1836 if ($return) 1837 return $output; 1838 echo $output; 1839} 1840 1841/** 1842 * Prints only a tip button which shows a text when the user puts the mouse over it. 1843 * 1844 * @param string Complete text to show in the tip 1845 * @param bool whether to return an output string or echo now 1846 * @param img displayed image 1847 * 1848 * @return string HTML code if return parameter is true. 1849 */ 1850function ui_print_help_tip ($text, $return = false, $img = 'images/tip.png') { 1851 $output = '<a href="javascript:" class="tip" >' . html_print_image ($img, true, array('title' => $text)) . '</a>'; 1852 1853 if ($return) 1854 return $output; 1855 echo $output; 1856} 1857 1858/** 1859 * Powerful debug function that also shows a backtrace. 1860 * 1861 * This functions need to have active $config['debug'] variable to work. 1862 * 1863 * @param mixed Variable name to debug 1864 * @param bool Wheter to print the backtrace or not. 1865 * 1866 * @return bool Tru if the debug was actived. False if not. 1867 */ 1868function ui_debug ($var, $backtrace = true) { 1869 global $config; 1870 if (! isset ($config['debug'])) 1871 return false; 1872 1873 static $id = 0; 1874 static $trace_id = 0; 1875 1876 $id++; 1877 1878 if ($backtrace) { 1879 echo '<div class="debug">'; 1880 echo '<a href="#" onclick="$(\'#trace-'.$id.'\').toggle ();return false;">Backtrace</a>'; 1881 echo '<div id="trace-'.$id.'" class="backtrace invisible">'; 1882 echo '<ol>'; 1883 $traces = debug_backtrace (); 1884 /* Ignore debug function */ 1885 unset ($traces[0]); 1886 foreach ($traces as $trace) { 1887 $trace_id++; 1888 1889 /* Many classes are used to allow better customization. 1890 Please, do not remove them */ 1891 echo '<li>'; 1892 if (isset ($trace['class'])) 1893 echo '<span class="class">'.$trace['class'].'</span>'; 1894 if (isset ($trace['type'])) 1895 echo '<span class="type">'.$trace['type'].'</span>'; 1896 echo '<span class="function">'; 1897 echo '<a href="#" onclick="$(\'#args-'.$trace_id.'\').toggle ();return false;">'.$trace['function'].'()</a>'; 1898 echo '</span>'; 1899 if (isset ($trace['file'])) { 1900 echo ' - <span class="filename">'; 1901 echo str_replace ($config['homedir'].'/', '', $trace['file']); 1902 echo ':'.$trace['line'].'</span>'; 1903 } 1904 else { 1905 echo ' - <span class="filename"><em>Unknown file</em></span>'; 1906 } 1907 echo '<pre id="args-'.$trace_id.'" class="invisible">'; 1908 echo '<div class="parameters">Parameter values:</div>'; 1909 echo '<ol>'; 1910 foreach ($trace['args'] as $arg) { 1911 echo '<li>'; 1912 print_r ($arg); 1913 echo '</li>'; 1914 } 1915 echo '</ol>'; 1916 echo '</pre>'; 1917 echo '</li>'; 1918 } 1919 echo '</ol>'; 1920 echo '</div></div>'; 1921 } 1922 1923 /* Actually print the variable given */ 1924 echo '<pre class="debug">'; 1925 print_r ($var); 1926 echo '</pre>'; 1927 1928 return true; 1929} 1930 1931/** 1932 * Prints icon of a module type 1933 * 1934 * @param int Module Type ID 1935 * @param bool Whether to return or print 1936 * @param bool $relative Whether to use relative path to image or not (i.e. $relative= true : /pandora/<img_src>). 1937 * @param bool $options Whether to use image options like style, border or title on the icon. 1938 * 1939 * @return string An HTML string with the icon. Printed if return is false 1940 */ 1941function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative = false, $options = true, $src = false) { 1942 global $config; 1943 1944 $type = db_get_row ("ttipo_modulo", "id_tipo", (int) $id_moduletype, array ("descripcion", "icon")); 1945 if ($type === false) { 1946 $type = array (); 1947 $type["descripcion"] = __('Unknown type'); 1948 $type["icon"] = 'b_down.png'; 1949 } 1950 $imagepath = 'images/'.$type["icon"]; 1951 if (! file_exists ($config['homedir'].'/'.$imagepath)) 1952 $imagepath = ENTERPRISE_DIR.'/'.$imagepath; 1953 1954 if ($src) { 1955 return $imagepath; 1956 } 1957 1958 if ($options) { 1959 return html_print_image ($imagepath, $return, 1960 array ("border" => 0, 1961 "title" => $type["descripcion"]), false, $relative); 1962 } 1963 else { 1964 return html_print_image ($imagepath, $return, 1965 false, false, $relative); 1966 } 1967} 1968 1969/** 1970 * Print module max/min values for warning/critical state 1971 * 1972 * @param float Max value for warning state 1973 * @param float Min value for warning state 1974 * @param float Max value for critical state 1975 * @param float Min value for critical state 1976 * 1977 * @return string HTML string 1978 */ 1979function ui_print_module_warn_value ($max_warning, $min_warning, $str_warning, $max_critical, $min_critical, $str_critical) { 1980 $data = "<span style='font-size: 8px' title='" . __("Warning") . ": " . __("Max") . $max_warning . "/" . __("Min") . $min_warning . " - " . __("Critical") . ": " . __("Max") . $max_critical . "/" . __("Min") . $min_critical . "'>"; 1981 1982 if ($max_warning != $min_warning) { 1983 $data .= format_for_graph($max_warning) ."/". format_for_graph ($min_warning); 1984 } 1985 else { 1986 $data .= __("N/A"); 1987 } 1988 1989 $data .= " - "; 1990 1991 if ($max_critical != $min_critical) { 1992 $data .= format_for_graph($max_critical) . "/" . 1993 format_for_graph ($min_critical); 1994 } 1995 else { 1996 $data .= __("N/A"); 1997 } 1998 $data .= "</span>"; 1999 return $data; 2000} 2001 2002/** 2003* Format a file size from bytes to a human readable meassure. 2004* 2005* @param int File size in bytes 2006* @return string Bytes converted to a human readable meassure. 2007*/ 2008function ui_format_filesize ($bytes) { 2009 $bytes = (int) $bytes; 2010 $strs = array ('B', 'kB', 'MB', 'GB', 'TB'); 2011 if ($bytes <= 0) { 2012 return "0 ".$strs[0]; 2013 } 2014 $con = 1024; 2015 $log = (int) (log ($bytes, $con)); 2016 2017 return format_numeric ($bytes / pow ($con, $log), 1).' '.$strs[$log]; 2018} 2019 2020 2021/** 2022 * Returns the current path to the selected image set to show the 2023 * status of agents and alerts. 2024 * 2025 * @return array An array with the image path, image width and image height. 2026 */ 2027function ui_get_status_images_path () { 2028 global $config; 2029 2030 $imageset = $config["status_images_set"]; 2031 2032 if (strpos ($imageset, ",") === false) 2033 $imageset .= ",40x18"; 2034 list ($imageset, $sizes) = preg_split ("/\,/", $imageset); 2035 2036 if (strpos ($sizes, "x") === false) 2037 $sizes .= "x18"; 2038 list ($imagewidth, $imageheight) = preg_split ("/x/", $sizes); 2039 2040 $imagespath = 'images/status_sets/'.$imageset; 2041 2042 return array ($imagespath); 2043} 2044 2045/** 2046 * Prints an image representing a status. 2047 * 2048 * @param string 2049 * @param string 2050 * @param bool Whether to return an output string or echo now (optional, echo by default). 2051 * @param array options to set image attributes: I.E.: style 2052 * @param Path of the image, if not provided use the status path 2053 * 2054 * @return string HTML code if return parameter is true. 2055 */ 2056function ui_print_status_image ($type, $title = "", $return = false, $options = false, $path = false) { 2057 if ($path === false) { 2058 list ($imagepath) = ui_get_status_images_path (); 2059 } 2060 else { 2061 $imagepath = $path; 2062 } 2063 2064 $imagepath .= "/" . $type; 2065 2066 if ($options === false) { 2067 $options = array(); 2068 } 2069 2070 $options['title'] = $title; 2071 2072 return html_print_image ($imagepath, $return, $options); 2073} 2074 2075/** 2076 * Print a code into a DIV and enable a toggle to show and hide it 2077 * 2078 * @param string html code 2079 * @param string name of the link 2080 * @param string title of the link 2081 * @param bool if the div will be hidden by default (default: true) 2082 * @param bool Whether to return an output string or echo now (default: true) 2083 * 2084 */ 2085 2086function ui_toggle($code, $name, $title = '', $hidden_default = true, $return = false) { 2087 // Generate unique Id 2088 $uniqid = uniqid(''); 2089 2090 // Options 2091 if ($hidden_default) { 2092 $style = 'display:none'; 2093 $image_a = html_print_image("images/down.png", true, false, true); 2094 $image_b = html_print_image("images/go.png", true, false, true); 2095 $original = "images/go.png"; 2096 } 2097 else { 2098 $style = ''; 2099 $image_a = html_print_image("images/down.png", true, false, true); 2100 $image_b = html_print_image("images/go.png", true, false, true); 2101 $original = "images/down.png"; 2102 } 2103 2104 // Link to toggle 2105 $output = ''; 2106 $output .= '<a href="javascript:" id="tgl_ctrl_'.$uniqid.'">' . html_print_image ($original, true, array ("title" => $title, "id" => "image_".$uniqid)) . ' <b>'.$name.'</b></a>'; 2107 $output .= '<br />'; 2108 2109 //if (!defined("METACONSOLE")) 2110 //$output .= '<br />'; 2111 2112 // Code into a div 2113 $output .= "<div id='tgl_div_".$uniqid."' style='".$style."'>\n"; 2114 $output .= $code; 2115 $output .= "</div>"; 2116 2117 // JQuery Toggle 2118 $output .= '<script type="text/javascript">' . "\n"; 2119 $output .= " var hide_tgl_ctrl_" . $uniqid . " = " . (int)$hidden_default . ";\n"; 2120 $output .= ' /* <![CDATA[ */' . "\n"; 2121 $output .= " $(document).ready (function () {\n"; 2122 $output .= " $('#tgl_ctrl_".$uniqid."').click(function() {\n"; 2123 $output .= " if (hide_tgl_ctrl_" . $uniqid . ") {\n"; 2124 $output .= " hide_tgl_ctrl_" . $uniqid . " = 0;\n"; 2125 $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; 2126 $output .= " $('#image_".$uniqid."').attr({src: '".$image_a."'});\n"; 2127 $output .= " }\n"; 2128 $output .= " else {\n"; 2129 $output .= " hide_tgl_ctrl_" . $uniqid . " = 1;\n"; 2130 $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; 2131 $output .= " $('#image_".$uniqid."').attr({src: '".$image_b."'});\n"; 2132 $output .= " }\n"; 2133 $output .= " });\n"; 2134 $output .= " });\n"; 2135 $output .= '/* ]]> */'; 2136 $output .= '</script>'; 2137 2138 if (!$return) { 2139 echo $output; 2140 } 2141 else { 2142 return $output; 2143 } 2144} 2145 2146/** 2147 * Construct and return the URL to be used in order to refresh the current page correctly. 2148 * 2149 * @param array Extra parameters to be added to the URL. It has prevalence over 2150 * GET and POST. False values will be ignored. 2151 * @param bool Whether to return the relative URL or the absolute URL. Returns 2152 * relative by default 2153 * @param bool Whether to add POST values to the URL. 2154 */ 2155function ui_get_url_refresh ($params = false, $relative = true, $add_post = true) { 2156 // Agent selection filters and refresh 2157 global $config; 2158 2159 // slerena, 8/Ene/2015 - Need to put index.php on URL which have it. 2160 if (strpos($_SERVER['REQUEST_URI'], 'index.php') === false) 2161 $url = ''; 2162 else 2163 $url = 'index.php'; 2164 2165 if (sizeof ($_REQUEST)) { 2166 //Some (old) browsers don't like the ?&key=var 2167 $url .= '?'; 2168 } 2169 2170 if (! is_array ($params)) 2171 $params = array (); 2172 /* Avoid showing login info */ 2173 $params['pass'] = false; 2174 $params['nick'] = false; 2175 $params['unnamed'] = false; 2176 2177 //We don't clean these variables up as they're only being passed along 2178 foreach ($_GET as $key => $value) { 2179 if (isset ($params[$key])) 2180 continue; 2181 if (strstr ($key, 'create')) 2182 continue; 2183 if (strstr ($key, 'update')) 2184 continue; 2185 if (strstr ($key, 'new')) 2186 continue; 2187 if (strstr ($key, 'delete')) 2188 continue; 2189 if (is_array($value)) { 2190 foreach ($value as $k => $v) { 2191 $url .= $key."[".$k.']='.$v.'&'; 2192 } 2193 } 2194 else { 2195 $url .= $key.'='.$value.'&'; 2196 } 2197 } 2198 2199 if ($add_post) { 2200 foreach ($_POST as $key => $value) { 2201 if (isset ($params[$key])) 2202 continue; 2203 if (strstr ($key, 'create')) 2204 continue; 2205 if (strstr ($key, 'update')) 2206 continue; 2207 if (strstr ($key, 'new')) 2208 continue; 2209 if (strstr ($key, 'delete')) 2210 continue; 2211 if (is_array($value)) { 2212 foreach ($value as $k => $v) { 2213 $url .= $key."[".$k.']='.$v.'&'; 2214 } 2215 } 2216 else { 2217 $url .= $key.'='.$value.'&'; 2218 } 2219 2220 } 2221 } 2222 2223 foreach ($params as $key => $value) { 2224 if ($value === false) 2225 continue; 2226 if (is_array($value)) { 2227 foreach ($value as $k => $v) { 2228 $url .= $key."[".$k.']='.$v.'&'; 2229 } 2230 } 2231 else { 2232 $url .= $key.'='.$value.'&'; 2233 } 2234 } 2235 2236 /* Removes final & */ 2237 $pos = strrpos ($url, '&', 0); 2238 if ($pos) { 2239 $url = substr_replace ($url, '', $pos, 5); 2240 } 2241 2242 $url = htmlspecialchars ($url); 2243 2244 if (! $relative) { 2245 return ui_get_full_url ($url); 2246 } 2247 2248 return $url; 2249} 2250 2251/** 2252 * Returns a full URL in Pandora. (with the port and https in some systems) 2253 * 2254 * An example of full URL is http:/localhost/pandora_console/index.php?sec=gsetup&sec2=godmode/setup/setup 2255 * 2256 * @param mixed $url If provided, it will be added after the index.php, but it is false boolean value, put the homeurl in the url. 2257 * @param boolean $no_proxy To avoid the proxy checks, by default it is false. 2258 * @param boolean $metaconsole_root Set the root to the metaconsole dir if the metaconsole is enabled, true by default. 2259 * 2260 * @return string A full URL in Pandora. 2261 */ 2262function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = false, $metaconsole_root = true) { 2263 global $config; 2264 2265 $port = null; // null means 'use the starndard port' 2266 $proxy = false; //By default Pandora FMS doesn't run across proxy. 2267 2268 if (isset ($_SERVER['HTTPS']) 2269 && ($_SERVER['HTTPS'] === true 2270 || $_SERVER['HTTPS'] == 'on')) { 2271 $protocol = 'https'; 2272 if ( $_SERVER['SERVER_PORT'] != 443) { 2273 $port = $_SERVER['SERVER_PORT']; 2274 } 2275 } 2276 elseif ($config['https']) { 2277 //When $config["https"] is set, enforce https 2278 $protocol = 'https'; 2279 } 2280 else { 2281 $protocol = 'http'; 2282 2283 if ( $_SERVER['SERVER_PORT'] != 80) { 2284 $port = $_SERVER['SERVER_PORT']; 2285 } 2286 } 2287 2288 if (!$no_proxy) { 2289 //Check if the PandoraFMS runs across the proxy like as 2290 //mod_proxy of Apache 2291 //and check if public_url is setted 2292 if (!empty($config['public_url']) 2293 && (!empty($_SERVER['HTTP_X_FORWARDED_HOST']))) { 2294 $fullurl = $config['public_url']; 2295 $proxy = true; 2296 } 2297 else { 2298 $fullurl = $protocol.'://' . $_SERVER['SERVER_NAME']; 2299 } 2300 } 2301 else { 2302 $fullurl = $protocol.'://' . $_SERVER['SERVER_NAME']; 2303 } 2304 2305 // using a different port than the standard 2306 if (!$proxy) { 2307 // using a different port than the standard 2308 if ( $port != null ) { 2309 $fullurl .= ":" . $port; 2310 } 2311 } 2312 2313 if ($url === '') { 2314 if ($proxy) { 2315 $url = ''; 2316 } 2317 else { 2318 $url = $_SERVER['REQUEST_URI']; 2319 } 2320 } 2321 elseif ($url === false) { 2322 if ($proxy) { 2323 $url = ''; 2324 } 2325 else { 2326 //Only add the home url 2327 $url = $config['homeurl_static'] . '/'; 2328 } 2329 2330 if (defined('METACONSOLE') && $metaconsole_root) { 2331 $url .= 'enterprise/meta/'; 2332 } 2333 } 2334 elseif (!strstr($url, ".php")) { 2335 if ($proxy) { 2336 $fullurl .= '/'; 2337 } 2338 else { 2339 $fullurl .= $config['homeurl_static'] . '/'; 2340 } 2341 2342 if (defined('METACONSOLE') && $metaconsole_root) { 2343 $fullurl .= 'enterprise/meta/'; 2344 } 2345 } 2346 else { 2347 if ($proxy) { 2348 $fullurl .= '/'; 2349 } 2350 else { 2351 if ($add_name_php_file) { 2352 $fullurl .= $_SERVER['SCRIPT_NAME']; 2353 } 2354 else { 2355 $fullurl .= $config['homeurl_static'] . '/'; 2356 2357 if (defined('METACONSOLE') && $metaconsole_root) { 2358 $fullurl .= 'enterprise/meta/'; 2359 } 2360 } 2361 } 2362 } 2363 2364 if (substr($fullurl, -1, 1) === substr($url, 0, 1)) { 2365 if (substr($fullurl, -1, 1) === '/') { 2366 $url = substr($url, 1); 2367 } 2368 } 2369 2370 return $fullurl . $url; 2371} 2372 2373/** 2374 * Return a standard page header (Pandora FMS 3.1 version) 2375 * 2376 * @param string Title 2377 * @param string Icon path 2378 * @param boolean Return (false will print using a echo) 2379 * @param boolean help (Help ID to print the Help link) 2380 * @param boolean Godmode (false = operation mode). 2381 * @param string Options (HTML code for make tabs or just a brief info string 2382 * @return string Header HTML 2383 */ 2384 2385function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = "") { 2386 $title = io_safe_input_html($title); 2387 if (($icon == "") && ($godmode == true)) { 2388 $icon = "images/gm_setup.png"; 2389 } 2390 2391 if (($icon == "") && ($godmode == false)) { 2392 $icon = ""; 2393 } 2394 2395 if ($godmode == true) { 2396 $type = "view"; 2397 $type2 = "menu_tab_frame_view"; 2398 $separator_class = "separator"; 2399 } 2400 else { 2401 $type = "view"; 2402 $type2 = "menu_tab_frame_view"; 2403 $separator_class = "separator_view"; 2404 } 2405 2406 2407 $buffer = '<div id="'.$type2.'" style=""><div id="menu_tab_left">'; 2408 2409 2410 $buffer .= '<ul class="mn"><li class="' . $type . '"> ' . ' '; 2411 $buffer .= '<span style="">' . 2412 ui_print_truncate_text($title, 38); 2413 if ($help != "") 2414 $buffer .= "<div class='head_help' style='float: right; margin-top: -2px !important; margin-left: 2px !important;'>" . 2415 ui_print_help_icon ($help, true, '', 'images/help_w.png') . "</div>"; 2416 $buffer .= '</span></li></ul></div>'; 2417 2418 if (is_array($options)) { 2419 $buffer .= '<div id="menu_tab"><ul class="mn">'; 2420 foreach ($options as $key => $option) { 2421 if (empty($option)) { 2422 continue; 2423 } 2424 else if ($key === 'separator') { 2425 continue; 2426 //$buffer .= '<li class='.$separator_class.'>'; 2427 //$buffer .= '</li>'; 2428 } 2429 else { 2430 if (is_array($option)) { 2431 $class = 'nomn'; 2432 if (isset($option['active'])) { 2433 if ($option['active']) { 2434 $class = 'nomn_high'; 2435 } 2436 } 2437 2438 // Tabs forced to other styles 2439 if (isset($option['godmode']) && $option['godmode']) { 2440 $class .= ' tab_godmode'; 2441 } 2442 else if (isset($option['operation']) && ($option['operation'])) { 2443 $class .= ' tab_operation'; 2444 } 2445 else { 2446 $class .= $godmode ? ' tab_godmode' : ' tab_operation'; 2447 } 2448 2449 $buffer .= '<li class="' . $class . '">'; 2450 $buffer .= $option['text']; 2451 if (isset($option['sub_menu'])) 2452 $buffer .= $option['sub_menu']; 2453 $buffer .= '</li>'; 2454 2455 } 2456 else { 2457 $buffer .= '<li class="nomn">'; 2458 $buffer .= $option; 2459 $buffer .= '</li>'; 2460 } 2461 } 2462 } 2463 $buffer .= '</ul></div>'; 2464 } 2465 else { 2466 if ($options != "") { 2467 $buffer .= '<div id="menu_tab"><ul class="mn"><li>'; 2468 $buffer .= $options; 2469 $buffer .= '</li></ul></div>'; 2470 } 2471 } 2472 2473 $buffer .= '</div>'; 2474 2475 if (!$return) 2476 echo $buffer; 2477 2478 return $buffer; 2479} 2480 2481 2482/** 2483 * Print a input for agent autocomplete, this input search into your 2484 * pandora DB (or pandoras DBs when you have metaconsole) for agents 2485 * that have name near to equal that you are writing into the input. 2486 * 2487 * This generate a lot of lines of html and javascript code. 2488 * 2489 * @parameters array Array with several properties: 2490 * - $parameters['return'] boolean, by default is false 2491 * true - return as html string the code (html and js) 2492 * false - print the code. 2493 * 2494 * - $parameters['input_name'] the input name (needs to get the value) 2495 * string - The name. 2496 * default - "agent_autocomplete_<aleatory_uniq_raw_letters/numbers>" 2497 * 2498 * - $parameters['input_id'] the input id (needs to get the value) 2499 * string - The ID. 2500 * default - "text-<input_name>" 2501 * 2502 * - $parameters['selectbox_group'] the id of selectbox with the group 2503 * string - The ID of selectbox. 2504 * default - "" empty string 2505 * 2506 * - $parameters['icon_image'] the small icon to show into the input in 2507 * the right side. 2508 * string - The url for the image. 2509 * default - "images/lightning.png" 2510 * 2511 * - $parameters['value'] The initial value to set the input. 2512 * string - The value. 2513 * default - "" emtpy string 2514 * 2515 * - $parameters['show_helptip'] boolean, by default is false 2516 * true - print the icon out the field in side right the tiny star 2517 * for tip. 2518 * false - does not print 2519 * 2520 * - $parameters['helptip_text'] The text to show in the tooltip. 2521 * string - The text to show into the tooltip. 2522 * default - "Type at least two characters to search." (translate) 2523 * 2524 * - $parameters['use_hidden_input_idagent'] boolean, Use a field for 2525 * store the id of agent from the ajax query. By default is false. 2526 * true - Use the field for id agent and the sourcecode work with 2527 * this. 2528 * false - Doesn't use the field (maybe this doesn't exist outer) 2529 * 2530 * - $parameters['print_hidden_input_idagent'] boolean, Print a field 2531 * for store the id of agent from the ajax query. By default is 2532 * false. 2533 * true - Print the field for id agent and the sourcecode work with 2534 * this. 2535 * false - Doesn't print the field (maybe this doesn't exist outer) 2536 * 2537 * - $parameters['hidden_input_idagent_name'] The name of hidden input 2538 * for to store the id agent. 2539 * string - The name of hidden input. 2540 * default - "agent_autocomplete_idagent_<aleatory_uniq_raw_letters/numbers>" 2541 * 2542 * - $parameters['hidden_input_idagent_id'] The id of hidden input 2543 * for to store the id agent. 2544 * string - The id of hidden input. 2545 * default - "hidden-<hidden_input_idagent_name>" 2546 * 2547 * - $parameters['hidden_input_idagent_value'] The initial value to set 2548 * the input id agent for store the id agent. 2549 * string - The value. 2550 * default - 0 2551 * 2552 * - $parameters['size'] The size in characters for the input of agent. 2553 * string - A number of characters. 2554 * default - 30 2555 * 2556 * - $parameters['maxlength'] The max characters that can store the 2557 * input of agent. 2558 * string - A number of characters max to store 2559 * default - 100 2560 * 2561 * - $parameters['disabled'] Set as disabled the input of agent. By 2562 * default is false 2563 * true - Set disabled the input of agent. 2564 * false - Set enabled the input of agent. 2565 * 2566 * - $parameters['selectbox_id'] The id of select box that stores the 2567 * list of modules of agent select. 2568 * string - The id of select box. 2569 * default - "id_agent_module" 2570 * 2571 * - $parameters['add_none_module'] Boolean, add the list of modules 2572 * the "none" entry, with value 0. By default is true 2573 * true - add the none entry. 2574 * false - does not add the none entry. 2575 * 2576 * - $parameters['none_module_text'] Boolean, add the list of modules 2577 * the "none" entry, with value 0. 2578 * string - The text to put for none module for example "select a 2579 * module" 2580 * default - "none" (translate) 2581 * 2582 * - $parameters['print_input_server'] Boolean, print the hidden field 2583 * to store the server (metaconsole). By default false. 2584 * true - Print the hidden input for the server. 2585 * false - Does not print. 2586 * 2587 * - $parameters['use_input_server'] Boolean, use the hidden field 2588 * to store the server (metaconsole). By default false. 2589 * true - Use the hidden input for the server. 2590 * false - Does not print. 2591 * 2592 * - $parameters['input_server_name'] The name for hidden field to 2593 * store the server. 2594 * string - The name of field for server. 2595 * default - "server_<aleatory_uniq_raw_letters/numbers>" 2596 * 2597 * - $parameters['input_server_id'] The id for hidden field to store 2598 * the server. 2599 * string - The id of field for server. 2600 * default - "hidden-<input_server_name>" 2601 * 2602 * - $parameters['input_server_value'] The value to store into the 2603 * field server. 2604 * string - The name of server. 2605 * default - "" empty string 2606 * 2607 * - $parameters['metaconsole_enabled'] Boolean, set the sourcecode for 2608 * to make some others things that run of without metaconsole. By 2609 * default false. 2610 * true - Set the gears for metaconsole. 2611 * false - Run as without metaconsole. 2612 * 2613 * - $parameters['javascript_ajax_page'] The page to send the ajax 2614 * queries. 2615 * string - The url to ajax page, remember the url must be into your 2616 * domain (ajax security). 2617 * default - "ajax.php" 2618 * 2619 * - $parameters['javascript_function_action_after_select'] The name of 2620 * function to call after the user select a agent into the list in 2621 * the autocomplete field. 2622 * string - The name of function. 2623 * default - "" 2624 * 2625 * - $parameters['javascript_function_action_after_select_js_call'] The 2626 * call of this function to call after user select a agent into the 2627 * list in the autocomplete field. Instead the 2628 * $parameters['javascript_function_action_after_select'], this is 2629 * overwrite the previous element. And this is necesary when you need 2630 * to set some params in your custom function. 2631 * string - The call line as javascript code. 2632 * default - "" 2633 * 2634 * - $parameters['javascript_function_action_into_source'] The source 2635 * code as block string to call when the autocomplete starts to get 2636 * the data from ajax. 2637 * string - A huge string with your function as javascript. 2638 * default - "" 2639 * 2640 * - $parameters['javascript'] Boolean, set the autocomplete agent to 2641 * use javascript or enabled javascript. By default true. 2642 * true - Enabled the javascript. 2643 * false - Disabled the javascript. 2644 * 2645 * - $parameters['javascript_is_function_select'] Boolean, set to 2646 * enable to call a function when user select a agent in the 2647 * autocomplete list. By default false. 2648 * true - Enabled this feature. 2649 * false - Disabled this feature. 2650 * 2651 * - $parameters['javascript_code_function_select'] The name of 2652 * function to call when user select a agent in the autocomplete 2653 * list. 2654 * string - The name of function but remembers this function pass 2655 * the parameter agent_name. 2656 * default - "function_select_<input_name>" 2657 * 2658 * - $parameters['javascript_name_function_select'] The source 2659 * code as block string to call when user select a agent into the 2660 * list in the autocomplete field. Althought use this element, you 2661 * need use the previous parameter to set name of your custom 2662 * function or call line. 2663 * string - A huge string with your function as javascript. 2664 * default - A lot of lines of source code into a string, please this 2665 * lines you can read in the source code of function. 2666 * 2667 * - $parameters['javascript_change_ajax_params'] The params to pass in 2668 * the ajax query for the list of agents. 2669 * array - The associative array with the key and value to pass in 2670 * the ajax query. 2671 * default - A lot of lines of source code into a string, please this 2672 * lines you can read in the source code of function. 2673 * 2674 * - $parameters['javascript_function_change'] The source code as block 2675 * string with all javascript code to run autocomplete field. 2676 * string - The source code javascript into a string. 2677 * default - A lot of lines of source code into a string, please this 2678 * lines you can read in the source code of function. 2679 * 2680 * - $parameters['javascript_document_ready'] Boolean, set the 2681 * javascript sourcecode to run with the document is ready. By 2682 * default is true. 2683 * true - Set to run when document is ready. 2684 * false - Not set to run. 2685 * 2686 * - $parameters['javascript_tags'] Boolean, print the html tags for 2687 * javascript. By default is true. 2688 * true - Print the javascript tags. 2689 * false - Doesn't print the tags. 2690 * 2691 * - $parameters['javascript_tags'] Boolean, print the html tags for 2692 * javascript. By default is true. 2693 * true - Print the javascript tags. 2694 * false - Doesn't print the tags. 2695 * 2696 * @return string HTML code if return parameter is true. 2697 */ 2698function ui_print_agent_autocomplete_input($parameters) { 2699 global $config; 2700 2701 //Normalize and extract the data from $parameters 2702 //------------------------------------------------------------------ 2703 $return = false; //Default value 2704 if (isset($parameters['return'])) { 2705 $return = $parameters['return']; 2706 } 2707 2708 2709 $input_name = uniqid('agent_autocomplete_'); //Default value 2710 if (isset($parameters['input_name'])) { 2711 $input_name = $parameters['input_name']; 2712 } 2713 2714 2715 $input_id = 'text-' . $input_name; //Default value 2716 if (isset($parameters['input_id'])) { 2717 $input_id = $parameters['input_id']; 2718 } 2719 2720 2721 $selectbox_group = ''; //Default value 2722 if (isset($parameters['selectbox_group'])) { 2723 $selectbox_group = $parameters['selectbox_group']; 2724 } 2725 2726 2727 //Default value 2728 $icon_image = html_print_image('images/input_agent.png', true, false, true); 2729 if (isset($parameters['icon_image'])) { 2730 $icon_image = $parameters['icon_image']; 2731 } 2732 2733 2734 $value = ''; //Default value 2735 if (isset($parameters['value'])) { 2736 $value = $parameters['value']; 2737 } 2738 2739 2740 $show_helptip = true; //Default value 2741 if (isset($parameters['show_helptip'])) { 2742 $show_helptip = $parameters['show_helptip']; 2743 } 2744 2745 2746 $helptip_text = __("Type at least two characters to search."); //Default value 2747 if (isset($parameters['helptip_text'])) { 2748 $helptip_text = $parameters['helptip_text']; 2749 } 2750 2751 2752 $use_hidden_input_idagent = false; //Default value 2753 if (isset($parameters['use_hidden_input_idagent'])) { 2754 $use_hidden_input_idagent = $parameters['use_hidden_input_idagent']; 2755 } 2756 2757 2758 $print_hidden_input_idagent = false; //Default value 2759 if (isset($parameters['print_hidden_input_idagent'])) { 2760 $print_hidden_input_idagent = $parameters['print_hidden_input_idagent']; 2761 } 2762 2763 2764 $hidden_input_idagent_name = uniqid('agent_autocomplete_idagent_'); //Default value 2765 if (isset($parameters['hidden_input_idagent_name'])) { 2766 $hidden_input_idagent_name = $parameters['hidden_input_idagent_name']; 2767 } 2768 2769 2770 $hidden_input_idagent_id = 'hidden-' . $input_name; //Default value 2771 if (isset($parameters['hidden_input_idagent_id'])) { 2772 $hidden_input_idagent_id = $parameters['hidden_input_idagent_id']; 2773 } 2774 2775 $hidden_input_idagent_value = (int)get_parameter($hidden_input_idagent_name, 0); //Default value 2776 if (isset($parameters['hidden_input_idagent_value'])) { 2777 $hidden_input_idagent_value = $parameters['hidden_input_idagent_value']; 2778 } 2779 2780 2781 $size = 30; //Default value 2782 if (isset($parameters['size'])) { 2783 $size = $parameters['size']; 2784 } 2785 2786 2787 $maxlength = 100; //Default value 2788 if (isset($parameters['maxlength'])) { 2789 $maxlength = $parameters['maxlength']; 2790 } 2791 2792 2793 $disabled = false; //Default value 2794 if (isset($parameters['disabled'])) { 2795 $disabled = $parameters['disabled']; 2796 } 2797 2798 2799 $selectbox_id = 'id_agent_module'; //Default value 2800 if (isset($parameters['selectbox_id'])) { 2801 $selectbox_id = $parameters['selectbox_id']; 2802 } 2803 2804 2805 $add_none_module = true; //Default value 2806 if (isset($parameters['add_none_module'])) { 2807 $add_none_module = $parameters['add_none_module']; 2808 } 2809 2810 2811 $none_module_text = '--'; //Default value 2812 if (isset($parameters['none_module_text'])) { 2813 $none_module_text = $parameters['none_module_text']; 2814 } 2815 2816 2817 $print_input_server = false; //Default value 2818 if (isset($parameters['print_input_server'])) { 2819 $print_input_server = $parameters['print_input_server']; 2820 } 2821 2822 2823 $print_input_id_server = false; //Default value 2824 if (isset($parameters['print_input_id_server'])) { 2825 $print_input_id_server = $parameters['print_input_id_server']; 2826 } 2827 2828 2829 $use_input_server = false; //Default value 2830 if (isset($parameters['use_input_server'])) { 2831 $use_input_server = $parameters['use_input_server']; 2832 } 2833 2834 2835 $use_input_id_server = false; //Default value 2836 if (isset($parameters['use_input_id_server'])) { 2837 $use_input_id_server = $parameters['use_input_id_server']; 2838 } 2839 2840 2841 $input_server_name = uniqid('server_'); //Default value 2842 if (isset($parameters['input_server_name'])) { 2843 $input_server_name = $parameters['input_server_name']; 2844 } 2845 2846 2847 $input_id_server_name = uniqid('server_'); //Default value 2848 if (isset($parameters['input_id_server_name'])) { 2849 $input_id_server_name = $parameters['input_id_server_name']; 2850 } 2851 2852 2853 $input_server_id = 'hidden-' . $input_server_name; //Default value 2854 if (isset($parameters['input_server_id'])) { 2855 $input_server_id = $parameters['input_server_id']; 2856 } 2857 2858 2859 $input_id_server_id = 'hidden-' . $input_id_server_name; //Default value 2860 if (isset($parameters['input_id_server_id'])) { 2861 $input_id_server_id = $parameters['input_id_server_id']; 2862 } 2863 2864 2865 $input_server_value = ''; //Default value 2866 if (isset($parameters['input_server_value'])) { 2867 $input_server_value = $parameters['input_server_value']; 2868 } 2869 2870 2871 $input_id_server_value = ''; //Default value 2872 if (isset($parameters['input_id_server_value'])) { 2873 $input_id_server_value = $parameters['input_id_server_value']; 2874 } 2875 2876 2877 $metaconsole_enabled = false; //Default value 2878 if (isset($parameters['metaconsole_enabled'])) { 2879 $metaconsole_enabled = $parameters['metaconsole_enabled']; 2880 } 2881 else { 2882 // If metaconsole_enabled param is not setted then pick source configuration 2883 if (defined('METACONSOLE')) 2884 $metaconsole_enabled = true; 2885 else 2886 $metaconsole_enabled = false; 2887 } 2888 2889 $spinner_image = html_print_image('images/spinner.gif', true, false, true); 2890 if (isset($parameters['spinner_image'])) { 2891 $spinner_image = $parameters['spinner_image']; 2892 } 2893 2894 2895 // Javascript configurations 2896 //------------------------------------------------------------------ 2897 $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); //Default value 2898 if (isset($parameters['javascript_ajax_page'])) { 2899 $javascript_ajax_page = $parameters['javascript_ajax_page']; 2900 } 2901 2902 2903 2904 $javascript_function_action_after_select = ''; //Default value 2905 $javascript_function_action_after_select_js_call = ''; //Default value 2906 if (isset($parameters['javascript_function_action_after_select'])) { 2907 $javascript_function_action_after_select = $parameters['javascript_function_action_after_select']; 2908 $javascript_function_action_after_select_js_call = 2909 $javascript_function_action_after_select . '();'; 2910 } 2911 2912 2913 2914 if (isset($parameters['javascript_function_action_after_select_js_call'])) { 2915 if ($javascript_function_action_after_select_js_call != 2916 $parameters['javascript_function_action_after_select_js_call']) { 2917 $javascript_function_action_after_select_js_call = 2918 $parameters['javascript_function_action_after_select_js_call']; 2919 } 2920 } 2921 2922 2923 2924 $javascript_function_action_into_source = ''; //Default value 2925 $javascript_function_action_into_source_js_call = ''; //Default value 2926 if (isset($parameters['javascript_function_action_into_source'])) { 2927 $javascript_function_action_into_source = $parameters['javascript_function_action_into_source']; 2928 $javascript_function_action_into_source_js_call = 2929 $javascript_function_action_into_source . '();'; 2930 } 2931 2932 2933 2934 if (isset($parameters['javascript_function_action_into_source_js_call'])) { 2935 if ($javascript_function_action_into_source_js_call != 2936 $parameters['javascript_function_action_into_source_js_call']) { 2937 $javascript_function_action_into_source_js_call = 2938 $parameters['javascript_function_action_into_source_js_call']; 2939 } 2940 } 2941 2942 2943 2944 $javascript = true; //Default value 2945 if (isset($parameters['javascript'])) { 2946 $javascript = $parameters['javascript']; 2947 } 2948 2949 2950 2951 $javascript_is_function_select = false; //Default value 2952 if (isset($parameters['javascript_is_function_select'])) { 2953 $javascript_is_function_select = $parameters['javascript_is_function_select']; 2954 } 2955 2956 2957 2958 $javascript_name_function_select = 'function_select_' . $input_name; //Default value 2959 if (isset($parameters['javascript_name_function_select'])) { 2960 $javascript_name_function_select = $parameters['javascript_name_function_select']; 2961 } 2962 2963 2964 2965 $javascript_code_function_select = ' 2966 function function_select_' . $input_name . '(agent_name) { 2967 2968 $("#' . $selectbox_id . '").empty (); 2969 2970 var inputs = []; 2971 inputs.push ("agent_name=" + agent_name); 2972 inputs.push ("delete_pending=0"); 2973 inputs.push ("get_agent_modules_json=1"); 2974 inputs.push ("page=operation/agentes/ver_agente"); 2975 2976 if (' . ((int) !$metaconsole_enabled) . ') { 2977 inputs.push ("force_local_modules=1"); 2978 } 2979 2980 if (' . ((int)$metaconsole_enabled) . ') { 2981 if ((' . ((int)$use_input_server) . ') 2982 || (' . ((int)$print_input_server) . ')) { 2983 inputs.push ("server_name=" + $("#' . $input_server_id . '").val()); 2984 } 2985 2986 if ((' . ((int)$use_input_id_server) . ') 2987 || (' . ((int)$print_input_id_server) . ')) { 2988 inputs.push ("server_id=" + $("#' . $input_id_server_id . '").val()); 2989 } 2990 2991 } 2992 2993 if ((' . ((int)$print_hidden_input_idagent) . ') 2994 || (' . ((int)$use_hidden_input_idagent) . ')) { 2995 2996 inputs.push ("id_agent=" + $("#' . $hidden_input_idagent_id . '").val()); 2997 } 2998 2999 jQuery.ajax ({ 3000 data: inputs.join ("&"), 3001 type: "POST", 3002 url: action="' . $javascript_ajax_page . '", 3003 dataType: "json", 3004 success: function (data) { 3005 if (' . ((int)$add_none_module) . ') { 3006 $("#' . $selectbox_id . '") 3007 .append($("<option></option>") 3008 .attr("value", 0).text("' . $none_module_text . '")); 3009 } 3010 3011 jQuery.each (data, function(i, val) { 3012 s = js_html_entity_decode(val["nombre"]); 3013 $("#' . $selectbox_id . '") 3014 .append ($("<option></option>") 3015 .attr("value", val["id_agente_modulo"]).text (s)); 3016 }); 3017 3018 $("#' . $selectbox_id . '").enable(); 3019 $("#' . $selectbox_id . '").fadeIn ("normal"); 3020 } 3021 }); 3022 3023 return false; 3024 } 3025 '; 3026 if (isset($parameters['javascript_code_function_select'])) { 3027 $javascript_code_function_select = $parameters['javascript_code_function_select']; 3028 } 3029 3030 3031 3032 //============ INIT javascript_change_ajax_params ================== 3033 //Default value 3034 $javascript_page = 'include/ajax/agent'; 3035 if (isset($parameters['javascript_page'])) { 3036 $javascript_page = $parameters['javascript_page']; 3037 } 3038 3039 3040 3041 $javascript_change_ajax_params_original = array( 3042 'page' => '"' . $javascript_page . '"', 3043 'search_agents' => 1, 3044 'id_group' => 'function() { 3045 var group_id = 0; 3046 3047 if (' . ((int)!empty($selectbox_group)) . ') { 3048 group_id = $("#' . $selectbox_group . '").val(); 3049 } 3050 3051 return group_id; 3052 }', 3053 'q' => 'term'); 3054 3055 if (!$metaconsole_enabled) { 3056 $javascript_change_ajax_params_original['force_local'] = 1; 3057 } 3058 3059 if (isset($parameters['javascript_change_ajax_params'])) { 3060 $javascript_change_ajax_params = array(); 3061 3062 $found_page = false; 3063 foreach ($parameters['javascript_change_ajax_params'] as $key => $param_ajax) { 3064 if ($key == 'page') { 3065 $found_page = true; 3066 if ($javascript_page != $param_ajax) { 3067 $javascript_change_ajax_params['page'] = $param_ajax; 3068 } 3069 else { 3070 $javascript_change_ajax_params['page'] = $javascript_page; 3071 } 3072 } 3073 else { 3074 $javascript_change_ajax_params[$key] = $param_ajax; 3075 } 3076 } 3077 3078 if (!$found_page) { 3079 $javascript_change_ajax_params['page'] = $javascript_page; 3080 } 3081 } 3082 else { 3083 $javascript_change_ajax_params = $javascript_change_ajax_params_original; 3084 } 3085 $first = true; 3086 $javascript_change_ajax_params_text = 'var data_params = {'; 3087 foreach ($javascript_change_ajax_params as $key => $param_ajax) { 3088 if (!$first) $javascript_change_ajax_params_text .= ",\n"; 3089 else $first = false; 3090 $javascript_change_ajax_params_text .= '"' . $key . '":' . $param_ajax; 3091 } 3092 $javascript_change_ajax_params_text .= '};'; 3093 //============ END javascript_change_ajax_params =================== 3094 3095 3096 3097 $javascript_function_change = ''; //Default value 3098 $javascript_function_change .=' 3099 function set_functions_change_autocomplete_' . $input_name . '() { 3100 var cache_' . $input_name . ' = {}; 3101 3102 $("#' . $input_id . '").autocomplete({ 3103 minLength: 2, 3104 source: function( request, response ) { 3105 var term = request.term; //Word to search 3106 3107 //Set loading 3108 $("#' . $input_id . '") 3109 .css("background","url(\"' . $spinner_image . '\") right center no-repeat"); 3110 3111 //Function to call when the source 3112 if (' . ((int)!empty($javascript_function_action_into_source_js_call)) . ') { 3113 ' . $javascript_function_action_into_source_js_call . ' 3114 } 3115 3116 //==== CACHE CODE ================================== 3117 //Check the cache 3118 var found = false; 3119 if (term in cache_' . $input_name . ') { 3120 response(cache_' . $input_name . '[term]); 3121 3122 //Set icon 3123 $("#' . $input_id . '") 3124 .css("background","url(\"' . $icon_image . '\") right center no-repeat"); 3125 return; 3126 } 3127 else { 3128 //Check if other terms cached start with same 3129 //letters. 3130 //TODO: At the moment DISABLED CODE 3131 /* 3132 for (i = 1; i < term.length; i++) { 3133 var term_match = term.substr(0, term.length - i); 3134 3135 $.each(cache_' . $input_name . ', function (oldterm, olddata) { 3136 var pattern = new RegExp("^" + term_match + ".*","gi"); 3137 3138 if (oldterm.match(pattern)) { 3139 response(cache_' . $input_name . '[oldterm]); 3140 3141 found = true; 3142 3143 return; 3144 } 3145 }); 3146 3147 if (found) { 3148 break; 3149 } 3150 } 3151 */ 3152 } 3153 //================================================== 3154 3155 3156 if (found) { 3157 //Set icon 3158 $("#' . $input_id . '") 3159 .css("background","url(\"' . $icon_image . '\") right center no-repeat"); 3160 3161 select_item_click = 0; 3162 3163 return; 3164 } 3165 3166 ' . $javascript_change_ajax_params_text . ' 3167 3168 jQuery.ajax ({ 3169 data: data_params, 3170 type: "POST", 3171 url: action="' . $javascript_ajax_page . '", 3172 dataType: "json", 3173 success: function (data) { 3174 cache_' . $input_name . '[term] = data; //Save the cache 3175 3176 response(data); 3177 3178 //Set icon 3179 $("#' . $input_id . '") 3180 .css("background", 3181 "url(\"' . $icon_image . '\") right center no-repeat"); 3182 3183 select_item_click = 0; 3184 3185 return; 3186 } 3187 }); 3188 3189 return; 3190 }, 3191 //---END source----------------------------------------- 3192 3193 3194 select: function( event, ui ) { 3195 var agent_name = ui.item.name; 3196 var agent_id = ui.item.id; 3197 var server_name = ""; 3198 var server_id = ""; 3199 3200 3201 if (' . ((int)$metaconsole_enabled) . ') { 3202 server_name = ui.item.server; 3203 } 3204 else { 3205 server_name = ui.item.ip; 3206 } 3207 3208 3209 if ((' . ((int)$use_input_id_server) . ') 3210 || (' . ((int)$print_input_id_server) . ')) { 3211 server_id = ui.item.id_server; 3212 } 3213 3214 3215 3216 //Put the name 3217 $(this).val(agent_name); 3218 3219 if ((' . ((int)$print_hidden_input_idagent) . ') 3220 || (' . ((int)$use_hidden_input_idagent) . ')) { 3221 $("#' . $hidden_input_idagent_id . '").val(agent_id); 3222 } 3223 3224 //Put the server id into the hidden input 3225 if ((' . ((int)$use_input_server) . ') 3226 || (' . ((int)$print_input_server) . ')) { 3227 $("#' . $input_server_id . '").val(server_name); 3228 } 3229 3230 //Put the server id into the hidden input 3231 if ((' . ((int)$use_input_id_server) . ') 3232 || (' . ((int)$print_input_id_server) . ')) { 3233 $("#' . $input_id_server_id . '").val(server_id); 3234 } 3235 3236 //Call the function to select (example fill the modules) 3237 if (' . ((int)$javascript_is_function_select) . ') { 3238 ' . $javascript_name_function_select . '(agent_name); 3239 } 3240 3241 //Function to call after the select 3242 if (' . ((int)!empty($javascript_function_action_after_select_js_call)) . ') { 3243 ' . $javascript_function_action_after_select_js_call . ' 3244 } 3245 3246 select_item_click = 1; 3247 3248 return false; 3249 } 3250 }) 3251 .data("ui-autocomplete")._renderItem = function( ul, item ) { 3252 if (item.ip == "") { 3253 text = "<a>" + item.name + "</a>"; 3254 } 3255 else { 3256 text = "<a>" + item.name 3257 + "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>"; 3258 } 3259 3260 switch (item.filter) { 3261 default: 3262 case \'agent\': 3263 return $("<li style=\'background: #DFFFC4;\'></li>") 3264 .data("item.autocomplete", item) 3265 .append(text) 3266 .appendTo(ul); 3267 break; 3268 case \'address\': 3269 return $("<li style=\'background: #F7CFFF;\'></li>") 3270 .data("item.autocomplete", item) 3271 .append(text) 3272 .appendTo(ul); 3273 break; 3274 case \'description\': 3275 return $("<li style=\'background: #FEFCC6;\'></li>") 3276 .data("item.autocomplete", item) 3277 .append(text) 3278 .appendTo(ul); 3279 break; 3280 } 3281 3282 3283 }; 3284 3285 //Force the size of autocomplete 3286 $(".ui-autocomplete").css("max-height", "100px"); 3287 $(".ui-autocomplete").css("overflow-y", "auto"); 3288 /* prevent horizontal scrollbar */ 3289 $(".ui-autocomplete").css("overflow-x", "hidden"); 3290 /* add padding to account for vertical scrollbar */ 3291 $(".ui-autocomplete").css("padding-right", "20px"); 3292 3293 //Force to style of items 3294 $(".ui-autocomplete").css("text-align", "left"); 3295 }'; 3296 3297 if (isset($parameters['javascript_function_change'])) { 3298 $javascript_function_change = $parameters['javascript_function_change']; 3299 } 3300 3301 $javascript_document_ready = true;//Default value 3302 if (isset($parameters['javascript_document_ready'])) { 3303 $javascript_document_ready = $parameters['javascript_document_ready']; 3304 } 3305 3306 $javascript_tags = true;//Default value 3307 if (isset($parameters['javascript_tags'])) { 3308 $javascript_tags = $parameters['javascript_tags']; 3309 } 3310 3311 $disabled_javascript_on_blur_function = false;//Default value 3312 if (isset($parameters['disabled_javascript_on_blur_function'])) { 3313 $disabled_javascript_on_blur_function = $parameters['disabled_javascript_on_blur_function']; 3314 } 3315 3316 $javascript_on_blur_function_name = 'function_on_blur_' . $input_name;//Default value 3317 if (isset($parameters['javascript_on_blur_function_name'])) { 3318 $javascript_on_blur_function_name = $parameters['javascript_on_blur_function_name']; 3319 } 3320 3321 $check_only_empty_javascript_on_blur_function = false;//Default value 3322 if (isset($parameters['check_only_empty_javascript_on_blur_function'])) { 3323 $check_only_empty_javascript_on_blur_function = $parameters['check_only_empty_javascript_on_blur_function']; 3324 } 3325 3326 //Default value 3327 $javascript_on_blur = ' 3328 /* 3329 This function is a callback when the autocomplete agent 3330 input lost the focus. 3331 */ 3332 function ' . $javascript_on_blur_function_name . '() { 3333 input_value = $("#' . $input_id . '").val(); 3334 3335 if (input_value.length == 0) { 3336 if ((' . ((int)$print_hidden_input_idagent) . ') 3337 || (' . ((int)$use_hidden_input_idagent) . ')) { 3338 $("#' . $hidden_input_idagent_id . '").val(0); 3339 } 3340 3341 //Put the server id into the hidden input 3342 if ((' . ((int)$use_input_server) . ') 3343 || (' . ((int)$print_input_server) . ')) { 3344 $("#' . $input_server_id . '").val(""); 3345 } 3346 3347 //Put the server id into the hidden input 3348 if ((' . ((int)$use_input_id_server) . ') 3349 || (' . ((int)$print_input_id_server) . ')) { 3350 $("#' . $input_id_server_id . '").val(""); 3351 } 3352 3353 return; 3354 } 3355 3356 if (' . ((int)$check_only_empty_javascript_on_blur_function) . ') { 3357 return 3358 } 3359 3360 3361 if (select_item_click) { 3362 return; 3363 } 3364 3365 //Set loading 3366 $("#' . $input_id . '") 3367 .css("background", 3368 "url(\"' . $spinner_image . '\") right center no-repeat"); 3369 3370 3371 3372 var term = input_value; //Word to search 3373 3374 ' . $javascript_change_ajax_params_text . ' 3375 3376 if (' . ((int) !$metaconsole_enabled) . ') { 3377 data_params[\'force_local\'] = 1; 3378 } 3379 3380 jQuery.ajax ({ 3381 data: data_params, 3382 type: "POST", 3383 url: action="' . $javascript_ajax_page . '", 3384 dataType: "json", 3385 success: function (data) { 3386 if (data.length == 0) { 3387 //Set icon 3388 $("#' . $input_id . '") 3389 .css("background", 3390 "url(\"' . $icon_image . '\") right center no-repeat"); 3391 3392 return; 3393 } 3394 3395 var agent_name = data[0].name; 3396 var agent_id = data[0].id; 3397 var server_name = ""; 3398 var server_id = ""; 3399 3400 if (' . ((int)$metaconsole_enabled) . ') { 3401 server_name = data[0].server; 3402 } 3403 else { 3404 server_name = data[0].ip; 3405 } 3406 3407 if ((' . ((int)$use_input_id_server) . ') 3408 || (' . ((int)$print_input_id_server) . ')) { 3409 server_id = data[0].id_server; 3410 } 3411 3412 if ((' . ((int)$print_hidden_input_idagent) . ') 3413 || (' . ((int)$use_hidden_input_idagent) . ')) { 3414 $("#' . $hidden_input_idagent_id . '").val(agent_id); 3415 } 3416 3417 //Put the server id into the hidden input 3418 if ((' . ((int)$use_input_server) . ') 3419 || (' . ((int)$print_input_server) . ')) { 3420 $("#' . $input_server_id . '").val(server_name); 3421 } 3422 3423 //Put the server id into the hidden input 3424 if ((' . ((int)$use_input_id_server) . ') 3425 || (' . ((int)$print_input_id_server) . ')) { 3426 $("#' . $input_id_server_id . '").val(server_id); 3427 } 3428 3429 //Call the function to select (example fill the modules) 3430 if (' . ((int)$javascript_is_function_select) . ') { 3431 ' . $javascript_name_function_select . '(agent_name); 3432 } 3433 3434 //Function to call after the select 3435 if (' . ((int)!empty($javascript_function_action_after_select_js_call)) . ') { 3436 ' . $javascript_function_action_after_select_js_call . ' 3437 } 3438 3439 //Set icon 3440 $("#' . $input_id . '") 3441 .css("background", 3442 "url(\"' . $icon_image . '\") right center no-repeat"); 3443 3444 return; 3445 } 3446 }); 3447 } 3448 '; 3449 if (isset($parameters['javascript_on_blur'])) { 3450 $javascript_on_blur = $parameters['javascript_on_blur']; 3451 } 3452 3453 //------------------------------------------------------------------ 3454 3455 $html = ''; 3456 3457 3458 $attrs = array(); 3459 $attrs['style'] = 3460 'background: url(' . $icon_image . ') no-repeat right;'; 3461 3462 if (!$disabled_javascript_on_blur_function) { 3463 $attrs['onblur'] = $javascript_on_blur_function_name . '()'; 3464 } 3465 3466 $html = html_print_input_text_extended($input_name, $value, 3467 $input_id, $helptip_text, $size, $maxlength, $disabled, '', $attrs, true); 3468 if ($show_helptip) { 3469 $html .= ui_print_help_tip ($helptip_text, true); 3470 } 3471 3472 if ($print_hidden_input_idagent) { 3473 $html .= html_print_input_hidden_extended($hidden_input_idagent_name, 3474 $hidden_input_idagent_value, $hidden_input_idagent_id, true); 3475 } 3476 3477 if ($print_input_server) { 3478 $html .= html_print_input_hidden_extended($input_server_name, 3479 $input_server_value, $input_server_id, true); 3480 } 3481 3482 if ($print_input_id_server) { 3483 $html .= html_print_input_hidden_extended($input_id_server_name, 3484 $input_id_server_value, $input_id_server_id, true); 3485 } 3486 3487 //Write the javascript 3488 if ($javascript) { 3489 if ($javascript_tags) { 3490 $html .= '<script type="text/javascript"> 3491 /* <![CDATA[ */'; 3492 } 3493 3494 $html .= 'var select_item_click = 0;' . "\n"; 3495 3496 $html .= $javascript_function_change; 3497 if ($javascript_is_function_select) { 3498 $html .= $javascript_code_function_select; 3499 } 3500 3501 $html .= $javascript_on_blur; 3502 3503 if ($javascript_document_ready) { 3504 $html .= '$(document).ready (function () { 3505 set_functions_change_autocomplete_' . $input_name . '(); 3506 });'; 3507 } 3508 3509 if ($javascript_tags) { 3510 $html .= '/* ]]> */ 3511 </script>'; 3512 } 3513 } 3514 3515 if ($return) { 3516 return $html; 3517 } 3518 else { 3519 echo $html; 3520 } 3521} 3522 3523 3524/** 3525 * Return error strings (title and message) for each error code 3526 * 3527 * @param string error code 3528 */ 3529function ui_get_error ($error_code) { 3530 switch($error_code) { 3531 case 'error_authconfig': 3532 case 'error_dbconfig': 3533 $title = __('Problem with Pandora FMS database'); 3534 $message = __('Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file.<i><br/><br/> 3535 Probably your database, hostname, user or password values are incorrect or 3536 the database server is not running.').'<br /><br />'; 3537 $message .= '<span class="red">'; 3538 $message .= '<b>' . __('DB ERROR') . ':</b><br>'; 3539 $message .= db_get_last_error(); 3540 $message .= '</span>'; 3541 3542 if ($error_code == 'error_authconfig') { 3543 $message .= '<br/><br/>'; 3544 $message .= __('If you have modified auth system, this problem could be because Pandora cannot override authorization variables from the config database. Remove them from your database by executing:<br><pre>DELETE FROM tconfig WHERE token = "auth";</pre>'); 3545 } 3546 break; 3547 case 'error_emptyconfig': 3548 $title = __('Empty configuration table'); 3549 $message = __('Cannot load configuration variables from database. Please check your database setup in the 3550 <b>include/config.php</b> file.<i><br><br> 3551 Most likely your database schema has been created but there are is no data in it, you have a problem with the database access credentials or your schema is out of date. 3552 <br><br>Pandora FMS Console cannot find <i>include/config.php</i> or this file has invalid 3553 permissions and HTTP server cannot read it. Please read documentation to fix this problem.</i>').'<br /><br />'; 3554 break; 3555 case 'error_noconfig': 3556 $title = __('No configuration file found'); 3557 $message = __('Pandora FMS Console cannot find <i>include/config.php</i> or this file has invalid 3558 permissions and HTTP server cannot read it. Please read documentation to fix this problem.').'<br /><br />'; 3559 if (file_exists('install.php')) { 3560 $link_start = '<a href="install.php">'; 3561 $link_end = '</a>'; 3562 } 3563 else { 3564 $link_start = ''; 3565 $link_end = ''; 3566 } 3567 3568 $message .= sprintf(__('You may try to run the %s<b>installation wizard</b>%s to create one.'), $link_start, $link_end); 3569 break; 3570 case 'error_install': 3571 $title = __('Installer active'); 3572 $message = __('For security reasons, normal operation is not possible until you delete installer file. 3573 Please delete the <i>./install.php</i> file before running Pandora FMS Console.'); 3574 break; 3575 case 'error_perms': 3576 $title = __('Bad permission for include/config.php'); 3577 $message = __('For security reasons, <i>config.php</i> must have restrictive permissions, and "other" users 3578 should not read it or write to it. It should be written only for owner 3579 (usually www-data or http daemon user), normal operation is not possible until you change 3580 permissions for <i>include/config.php</i> file. Please do it, it is for your security.'); 3581 break; 3582 } 3583 3584 return array('title' => $title, 'message' => $message); 3585} 3586 3587function ui_include_time_picker($echo_tags = false) { 3588 if (is_ajax () || $echo_tags) { 3589 echo '<script type="text/javascript" src="' . 3590 ui_get_full_url(false, false, false, false) . 3591 'include/javascript/jquery.ui-timepicker-addon.js' . '"></script>'; 3592 } 3593 else { 3594 ui_require_jquery_file ("ui-timepicker-addon"); 3595 } 3596 3597 if (file_exists('include/javascript/i18n/jquery-ui-timepicker-' . substr(get_user_language(), 0, 2) . '.js')) { 3598 echo '<script type="text/javascript" src="' . 3599 ui_get_full_url('include/javascript/i18n/jquery-ui-timepicker-' . substr(get_user_language(), 0, 2) . '.js', false, false, false) . '"></script>'; 3600 } 3601} 3602 3603function ui_print_module_string_value($value, $id_agente_module, 3604 $current_interval, $module_name = null) { 3605 3606 global $config; 3607 3608 if (is_null($module_name)) 3609 $module_name = modules_get_agentmodule_name($id_agente_module); 3610 3611 $id_type_web_content_string = db_get_value('id_tipo', 3612 'ttipo_modulo', 'nombre', 'web_content_string'); 3613 3614 $is_web_content_string = (bool)db_get_value_filter('id_agente_modulo', 3615 'tagente_modulo', 3616 array('id_agente_modulo' => $id_agente_module, 3617 'id_tipo_modulo' => $id_type_web_content_string)); 3618 3619 //Fixed the goliat sends the strings from web 3620 //without HTML entities 3621 if ($is_web_content_string) { 3622 $value = io_safe_input($value); 3623 } 3624 3625 3626 3627 $is_snapshot = is_snapshot_data($value); 3628 3629 if (($config['command_snapshot']) && ($is_snapshot)) { 3630 $handle = "snapshot" . "_" . $id_agente_module; 3631 $url = 'include/procesos.php?agente=' . $id_agente_module; 3632 $win_handle = dechex(crc32($handle)); 3633 3634 $link = "winopeng_var('operation/agentes/snapshot_view.php?" . 3635 "id=" . $id_agente_module . 3636 "&refr=" . $current_interval . 3637 "&label=" . rawurlencode(urlencode(io_safe_output($module_name))) . "','" . $win_handle . "', 700,480)"; 3638 3639 $salida = '<a href="javascript:' . $link . '">' . 3640 html_print_image("images/default_list.png", true, 3641 array("border" => '0', 3642 "alt" => "", 3643 "title" => __("Snapshot view"))) . '</a> '; 3644 } 3645 else { 3646 3647 $sub_string = substr(io_safe_output($value), 0, 12); 3648 if ($value == $sub_string) { 3649 if ($value == 0 && !$sub_string) { 3650 $salida = 0; 3651 } 3652 else { 3653 $salida = $value; 3654 } 3655 } 3656 else { 3657 //Fixed the goliat sends the strings from web 3658 //without HTML entities 3659 if ($is_web_content_string) { 3660 $sub_string = substr($value, 0, 12); 3661 } 3662 else { 3663 //Fixed the data from Selenium Plugin 3664 if ($value != strip_tags($value)) { 3665 $value = io_safe_input($value); 3666 $sub_string = substr($value, 0, 12); 3667 } 3668 else { 3669 $sub_string = substr(io_safe_output($value),0, 12); 3670 } 3671 } 3672 3673 3674 3675 if ($value == $sub_string) { 3676 $salida = $value; 3677 } 3678 else { 3679 $title_dialog = 3680 modules_get_agentmodule_agent_name($id_agente_module) . 3681 " / " . $module_name; 3682 $salida = "<div " . 3683 "id='hidden_value_module_" . $id_agente_module . "' 3684 style='display: none;' title='" . $title_dialog . "'>" . 3685 $value . 3686 "</div>" . 3687 "<span " . 3688 "id='value_module_" . $id_agente_module . "' 3689 style='white-space: nowrap;'>" . 3690 '<span id="value_module_text_' . $id_agente_module . '">' . 3691 $sub_string . '</span> ' . 3692 "<a href='javascript: toggle_full_value(" . $id_agente_module . ")'>" . 3693 html_print_image("images/zoom.png", true) . "</a>" . "</span>"; 3694 } 3695 } 3696 } 3697 3698 return $salida; 3699} 3700?> 3701