2012-04-09 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: cleaned source code style. * extensions/update_pandora, extensions/update_pandora/functions.ajax.php, extensions/update_pandora/functions.php, extensions/update_manager/lib/functions.ajax.php, extensions/update_manager/lib/functions.php: moved this files into the extension update_manager. * extensions/update_manager/main.php: added hook (as a tab) the "update_pandora". Merged from the branch pandora_4.0 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5917 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a93d5c5bdf
commit
3f3bfb1629
|
@ -1,3 +1,19 @@
|
|||
2012-04-09 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/functions_ui.php: cleaned source code style.
|
||||
|
||||
* extensions/update_pandora,
|
||||
extensions/update_pandora/functions.ajax.php,
|
||||
extensions/update_pandora/functions.php,
|
||||
extensions/update_manager/lib/functions.ajax.php,
|
||||
extensions/update_manager/lib/functions.php: moved this files into the
|
||||
extension update_manager.
|
||||
|
||||
* extensions/update_manager/main.php: added hook (as a tab) the
|
||||
"update_pandora".
|
||||
|
||||
Merged from the branch pandora_4.0
|
||||
|
||||
2012-04-09 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
|
||||
|
||||
* include/javascript/pandora.js
|
||||
|
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
function update_pandora_get_packages_online_ajax() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/load_updatemanager.php");
|
||||
|
||||
$last = get_parameter('last', 0);
|
||||
|
||||
db_clean_cache();
|
||||
$settings = um_db_load_settings ();
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
$params = array(
|
||||
new xmlrpcval((int)$conf_update_pandora['last_contact'], 'int'),
|
||||
new xmlrpcval($user_key, 'string'),
|
||||
new xmlrpcval($settings->customer_key, 'string'));
|
||||
|
||||
$result = @um_xml_rpc_client_call($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_lastest_package_update_open',
|
||||
$params);
|
||||
|
||||
if ($result == false) {
|
||||
$return['last'] = $last;
|
||||
$return['correct'] = 0;
|
||||
$return['package'] = __('Error download packages.');
|
||||
$return['end'] = 1;
|
||||
}
|
||||
else {
|
||||
$value = $result->value();
|
||||
$package = $value->scalarval();
|
||||
|
||||
$return['correct'] = 1;
|
||||
if (empty($package)) {
|
||||
$return['correct'] = 0;
|
||||
}
|
||||
|
||||
$return['last'] = $last;
|
||||
$return['package'] = $package;
|
||||
$return['end'] = 1;
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_download_package() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
|
||||
$params = array(new xmlrpcval($package, 'string'));
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$result = @um_xml_rpc_client_call ($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_lastest_package_url_update_open',
|
||||
$params);
|
||||
|
||||
if ($result == false) {
|
||||
$info_json = json_encode(array('correct' => 0));
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX);
|
||||
|
||||
$return = array('correct' => 0);
|
||||
}
|
||||
else {
|
||||
$conf_update_pandora['last_contact'] = time();
|
||||
update_pandora_update_conf();
|
||||
|
||||
$value = $result->value();
|
||||
$package_url = $value->scalarval();
|
||||
|
||||
if (empty($package_url)) {
|
||||
$info_json = json_encode(array('correct' => 0));
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX);
|
||||
|
||||
$return = array('correct' => 0);
|
||||
}
|
||||
else {
|
||||
$targz = $package;
|
||||
$url = $package_url;
|
||||
|
||||
$file = fopen($dir . $targz, "w");
|
||||
|
||||
$mch = curl_multi_init();
|
||||
$c = curl_init();
|
||||
|
||||
curl_setopt($c, CURLOPT_URL, $url);
|
||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($c, CURLOPT_FILE, $file);
|
||||
|
||||
curl_multi_add_handle($mch ,$c);
|
||||
$running = null;
|
||||
do {
|
||||
curl_multi_exec($mch ,$running);
|
||||
$info = curl_getinfo ($c);
|
||||
|
||||
$data = array();
|
||||
$data['correct'] = 1;
|
||||
$data['filename'] = $targz;
|
||||
$data['size'] = $info['download_content_length'];
|
||||
$data['size_download'] = $info['size_download'];
|
||||
$data['speed_download'] = $info['speed_download'];
|
||||
|
||||
$info_json = json_encode($data);
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
while($running > 0);
|
||||
|
||||
$return = array('correct' => 1);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_check_download_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$return = array('correct' => 1,
|
||||
'info_download' => "<b>Size:</b> %s/%s bytes <b>Speed:</b> %s bytes/second",
|
||||
'progres_bar' => progress_bar(0, 300, 20, '0%', 1, false, "#00ff00"),
|
||||
'progres_bar_text' => '0%',
|
||||
'percent' => 0);
|
||||
|
||||
$info_json = @file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$info = json_decode($info_json, true);
|
||||
|
||||
if ($info['correct'] == 0) {
|
||||
$return['correct'] = 0;
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
}
|
||||
else {
|
||||
$percent = 0;
|
||||
$size_download = 0;
|
||||
$size = 0;
|
||||
$speed_download = 0;
|
||||
if ($info['size_download'] > 0) {
|
||||
$percent = format_numeric(
|
||||
($info['size_download'] / $info['size']) * 100, 2);
|
||||
$return['percent'] = $percent;
|
||||
$size_download = $info['size_download'];
|
||||
$size = $info['size'];
|
||||
$speed_download = $info['speed_download'];
|
||||
|
||||
$return['info_download'] = sprintf($return['info_download'],
|
||||
format_for_graph($size_download, 2), format_for_graph($size, 2),
|
||||
format_for_graph($speed_download, 2));
|
||||
}
|
||||
else {
|
||||
$return['info_download'] = __('<b>Starting: </b> connect to server');
|
||||
}
|
||||
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#00ff00");
|
||||
$return['progres_bar'] = $img;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_title'] = $attr[1];
|
||||
$return['filename'] = $info['filename'];
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_install_package() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
//Get total files
|
||||
$command = 'tar tzvf ' . $dir . $filename . '| wc -l > /tmp/' . $package . '.info.txt';
|
||||
exec($command, $output, $status);
|
||||
html_debug_print($command, true);
|
||||
|
||||
$command = 'tar xzvf ' . $dir . $filename . ' -C ' . $config['homedir'] . ' 1>/tmp/' . $package . '.files.info.txt';
|
||||
html_debug_print($command, true);
|
||||
|
||||
//Maybe this line run for seconds or minutes
|
||||
exec($command, $output, $status);
|
||||
|
||||
if (($status == 0) || ($status == 2)) {
|
||||
$conf_update_pandora['last_installed'] = $filename;
|
||||
update_pandora_update_conf();
|
||||
echo json_encode(array('correct' => 1));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('correct' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
function update_pandora_check_install_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
$files = @file('/tmp/' . $package . '.files.info.txt');
|
||||
if (empty($files))
|
||||
$files = array();
|
||||
$total = (int)file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$return = array('correct' => 1,
|
||||
'info' => "<div id='list_files_install'
|
||||
style='text-align: left; margin: 10px; padding: 5px; width: 90%%; height: 100px;
|
||||
overflow: scroll; border: 1px solid #666'>%s</div>",
|
||||
'src' => progress_bar(0, 300, 20, '0%', 1, false, "#0000ff"),
|
||||
'alt' => '0%',
|
||||
'percent' => 0);
|
||||
|
||||
$percent = 0;
|
||||
if ((count($files) > 0) && ($total > 0)) {
|
||||
$percent = format_numeric((count($files) / $total) * 100, 2);
|
||||
if ($percent > 100)
|
||||
$percent = 100;
|
||||
}
|
||||
|
||||
$files_txtbox = (string)implode("<br />", $files);
|
||||
$return['info'] = sprintf($return['info'], $files_txtbox);
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#0000ff");
|
||||
$return['percent'] = $percent;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['title'] = $attr[1];
|
||||
|
||||
if ($percent == 100) {
|
||||
unlink('/tmp/' . $package . '.files.info.txt');
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
?>
|
|
@ -91,7 +91,7 @@ function update_pandora_update_conf() {
|
|||
$return = db_process_sql_update('tconfig', $values,
|
||||
array('token' => 'update_pandora_conf_last_installed'));
|
||||
$values = array('value' => $conf_update_pandora['last_contact']);
|
||||
$return = db_process_sql_insert('tconfig', $values,
|
||||
$return = db_process_sql_update('tconfig', $values,
|
||||
array('token' => 'update_pandora_conf_last_contact'));
|
||||
|
||||
return $return;
|
||||
|
@ -178,6 +178,9 @@ function update_pandora_print_javascript() {
|
|||
ajax_get_online_package_list();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -186,7 +189,7 @@ function update_pandora_print_javascript() {
|
|||
}
|
||||
|
||||
function update_pandora_print_javascript_admin() {
|
||||
$extension_php_file = 'extensions/update_pandora';
|
||||
$extension_php_file = 'extensions/update_manager/update_pandora';
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
@ -287,6 +290,15 @@ function update_pandora_print_javascript_admin() {
|
|||
install_package(package, data['filename']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$("#title_downloading_update_pandora").hide();
|
||||
$("#title_error_update_pandora").show();
|
||||
$("#progress_bar_img").hide();
|
||||
|
||||
$("#info_text").html('');
|
||||
|
||||
$("#button_close_download").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -384,6 +396,9 @@ function update_pandora_print_javascript_admin() {
|
|||
ajax_get_online_package_list_admin();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -15,6 +15,8 @@
|
|||
// Load global vars
|
||||
global $config;
|
||||
|
||||
require_once("update_pandora.php");
|
||||
|
||||
check_login ();
|
||||
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
|
@ -23,7 +25,41 @@ um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
|||
$settings = um_db_load_settings ();
|
||||
$error = '';
|
||||
|
||||
ui_print_page_header (__('Update manager'), "images/extensions.png", false, "", false, "" );
|
||||
$url = 'index.php?sec=extensions&sec2=extensions/update_manager';
|
||||
|
||||
$update_free = (bool)get_parameter('update_free', false);
|
||||
|
||||
$buttons_active = array();
|
||||
if ($update_free) {
|
||||
$buttons_active['updatemanager'] = false;
|
||||
$buttons_active['updatefree'] = true;
|
||||
}
|
||||
else {
|
||||
$buttons_active['updatemanager'] = true;
|
||||
$buttons_active['updatefree'] = false;
|
||||
}
|
||||
|
||||
$buttons = array(
|
||||
'updatefree' => array('active' => $buttons_active['updatefree'],
|
||||
'text' => '<a href="'.$url.'&update_free=1">' .
|
||||
html_print_image("images/upd.png", true, array ("title" => __('Update free'))) .'</a>'),
|
||||
'updatemanager' => array('active' => $buttons_active['updatemanager'],
|
||||
'text' => '<a href="'.$url.'&update_manager=1">' .
|
||||
html_print_image("images/package.png", true, array ("title" => __('Update manager'))) .'</a>'));
|
||||
|
||||
|
||||
ui_print_page_header (__('Update manager'), "images/extensions.png",
|
||||
false, "", false, $buttons);
|
||||
|
||||
if ($update_free) {
|
||||
//Call to update pandora free.
|
||||
|
||||
update_pandora_administration();
|
||||
|
||||
//Don't call the code of update manager.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ($settings->customer_key == FREE_USER) {
|
||||
echo '<div class="notify" style="width: 80%; text-align:left;" >';
|
||||
|
|
|
@ -14,10 +14,21 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
require_once('update_pandora/functions.php');
|
||||
require_once('lib/functions.php');
|
||||
|
||||
if (is_ajax ()) {
|
||||
require_once('update_pandora/functions.ajax.php');
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('lib/functions.ajax.php');
|
||||
|
||||
$get_packages_online = (bool) get_parameter('get_packages_online');
|
||||
$download_package = (bool) get_parameter('download_package');
|
||||
|
@ -39,51 +50,18 @@ if (is_ajax ()) {
|
|||
return;
|
||||
}
|
||||
|
||||
function update_pandora_operation() {
|
||||
global $conf_update_pandora;
|
||||
|
||||
ui_print_page_header(__('Update Pandora'), "images/extensions.png");
|
||||
|
||||
if (!update_pandora_check_installation()) {
|
||||
ui_print_error_message(__('First execution of Update Pandora or lost configuration.'));
|
||||
update_pandora_installation();
|
||||
}
|
||||
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
if (empty($conf_update_pandora['last_installed'])) {
|
||||
ui_print_error_message(__('Your Pandora FMS Console never have been update.'));
|
||||
}
|
||||
else {
|
||||
$text = sprintf(__('The last package for Pandora FMS Console is %s'),
|
||||
$conf_update_pandora['last_installed']);
|
||||
ui_print_success_message($text);
|
||||
}
|
||||
|
||||
echo "<h3>" . __('Downloaded Packages') . "</h3>";
|
||||
$list_downloaded_packages = update_pandora_get_list_downloaded_packages('operation');
|
||||
$table = null;
|
||||
$table->width = '80%';
|
||||
$table->head = array(__('Packages'));
|
||||
$table->data = $list_downloaded_packages;
|
||||
html_print_table($table);
|
||||
|
||||
echo "<h3>" . __('Online Packages') . "</h3>";
|
||||
$table = null;
|
||||
$table->id = 'online_packages';
|
||||
$table->width = '80%';
|
||||
$table->head = array(__('Packages'));
|
||||
$table->rowclass[0] = 'spinner_row';
|
||||
$table->data[0][0] = __('Get list online Packages') . html_print_image('images/spinner.gif', true);
|
||||
html_print_table($table);
|
||||
|
||||
update_pandora_print_javascript();
|
||||
}
|
||||
|
||||
function update_pandora_administration() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
|
||||
ui_print_page_header(__('Update Pandora'), "images/extensions.png", false, "", true);
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!update_pandora_check_installation()) {
|
||||
ui_print_error_message(__('First execution of Update Pandora'));
|
||||
|
@ -150,6 +128,7 @@ function update_pandora_administration() {
|
|||
html_print_image('images/spinner.gif');
|
||||
echo '</h2>';
|
||||
echo '<h2 style="display: none;" id="title_installed_update_pandora">' . __('Installed <span class="package_name">package</span> in progress') . '</h2>';
|
||||
echo '<h2 style="display: none;" id="title_error_update_pandora">' . __('Fail download <span class="package_name">package</span>') . '</h2>';
|
||||
echo '<br /><br />';
|
||||
echo "<div id='progress_bar_img'>";
|
||||
echo progress_bar(0, 300, 20, 0 . '%', 1, false, "#00ff00");
|
||||
|
@ -175,10 +154,4 @@ function update_pandora_administration() {
|
|||
|
||||
update_pandora_print_javascript_admin();
|
||||
}
|
||||
|
||||
extensions_add_godmode_function('update_pandora_administration');
|
||||
extensions_add_godmode_menu_option (__('Pandora Update'), 'PM');
|
||||
|
||||
extensions_add_main_function('update_pandora_operation');
|
||||
extensions_add_operation_menu_option(__('Pandora Update'));
|
||||
?>
|
|
@ -1,233 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
function update_pandora_get_packages_online_ajax() {
|
||||
global $config;
|
||||
|
||||
$last = get_parameter('last', 0);
|
||||
|
||||
//TODO Make all code, at the moment I uknown the method to get list.
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
$conf_update_pandora['last_contact'] = time();
|
||||
update_pandora_update_conf();
|
||||
|
||||
$last++;
|
||||
|
||||
sleep(1);
|
||||
|
||||
$return = array('correct' => 0);
|
||||
$return['last'] = $last;
|
||||
$return['correct'] = 1;
|
||||
$return['package'] = uniqid();
|
||||
$return['end'] = 0;
|
||||
if ($last == 1) {
|
||||
$return['end'] = 1;
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
function update_pandora_download_package() {
|
||||
global $config;
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
|
||||
//TODO Make all code, at the moment.
|
||||
$url = 'http://sourceforge.net/projects/pandora/files/Pandora%20FMS%204.0.1/Pandora_FMS_4.0.1_OpenSource.i686-0.0.3.vmx.tar.gz/download';
|
||||
$url = 'http://sourceforge.net/projects/pandora/files/Nightly/Tarball/pandorafms_console-4.1dev-120330.tar.gz/download';
|
||||
$url = 'http://sourceforge.net/projects/pandora/files/Nightly/Tarball/pandorafms_server-4.1dev-120330.tar.gz/download';
|
||||
preg_match_all('/Tarball\/(.*.tar.gz)/i', $url, $targz);
|
||||
$targz = $targz[1][0];
|
||||
|
||||
$url = 'http://127.0.0.1/test000.tar.gz';
|
||||
$url = 'http://127.0.0.1/test001.tar.gz';
|
||||
$targz = 'test001.tar.gz';
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$file = fopen($dir . $targz, "w");
|
||||
|
||||
$mch = curl_multi_init();
|
||||
$c = curl_init();
|
||||
|
||||
curl_setopt($c, CURLOPT_URL, $url);
|
||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($c, CURLOPT_FILE, $file);
|
||||
|
||||
curl_multi_add_handle($mch ,$c);
|
||||
$running = null;
|
||||
do {
|
||||
curl_multi_exec($mch ,$running);
|
||||
$info = curl_getinfo ($c);
|
||||
|
||||
$data = array();
|
||||
$data['filename'] = $targz;
|
||||
$data['size'] = $info['download_content_length'];
|
||||
$data['size_download'] = $info['size_download'];
|
||||
$data['speed_download'] = $info['speed_download'];
|
||||
|
||||
$info_json = json_encode($data);
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
while($running > 0);
|
||||
|
||||
|
||||
$return = array('correct' => 1);
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_check_download_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$return = array('correct' => 1,
|
||||
'info_download' => "<b>Size:</b> %s/%s bytes <b>Speed:</b> %s bytes/second",
|
||||
'progres_bar' => progress_bar(0, 300, 20, '0%', 1, false, "#00ff00"),
|
||||
'progres_bar_text' => '0%',
|
||||
'percent' => 0);
|
||||
|
||||
$info_json = @file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$info = json_decode($info_json, true);
|
||||
|
||||
$percent = 0;
|
||||
$size_download = 0;
|
||||
$size = 0;
|
||||
$speed_download = 0;
|
||||
if ($info['size_download'] > 0) {
|
||||
$percent = format_numeric(
|
||||
($info['size_download'] / $info['size']) * 100, 2);
|
||||
$return['percent'] = $percent;
|
||||
$size_download = $info['size_download'];
|
||||
$size = $info['size'];
|
||||
$speed_download = $info['speed_download'];
|
||||
|
||||
$return['info_download'] = sprintf($return['info_download'],
|
||||
format_for_graph($size_download, 2), format_for_graph($size, 2),
|
||||
format_for_graph($speed_download, 2));
|
||||
}
|
||||
else {
|
||||
$return['info_download'] = __('<b>Starting: </b> connect to server');
|
||||
}
|
||||
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#00ff00");
|
||||
$return['progres_bar'] = $img;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_title'] = $attr[1];
|
||||
$return['filename'] = $info['filename'];
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_install_package() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
//Get total files
|
||||
$command = 'tar tzvf ' . $dir . $filename . '| wc -l > /tmp/' . $package . '.info.txt';
|
||||
exec($command, $output, $status);
|
||||
html_debug_print($command, true);
|
||||
|
||||
$command = 'tar xzvf ' . $dir . $filename . ' -C ' . $config['homedir'] . ' 1>/tmp/' . $package . '.files.info.txt';
|
||||
html_debug_print($command, true);
|
||||
|
||||
//Maybe this line run for seconds or minutes
|
||||
exec($command, $output, $status);
|
||||
|
||||
if (($status == 0) || ($status == 2)) {
|
||||
$conf_update_pandora['last_installed'] = $filename;
|
||||
update_pandora_update_conf();
|
||||
echo json_encode(array('correct' => 1));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('correct' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
function update_pandora_check_install_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
//TODO MAYBE THE FILE OF FILES DON'T EXIST AT THE MOMENT
|
||||
|
||||
$files = @file('/tmp/' . $package . '.files.info.txt');
|
||||
if (empty($files))
|
||||
$files = array();
|
||||
$total = (int)file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$return = array('correct' => 1,
|
||||
'info' => "<div id='list_files_install'
|
||||
style='text-align: left; margin: 10px; padding: 5px; width: 90%%; height: 100px;
|
||||
overflow: scroll; border: 1px solid #666'>%s</div>",
|
||||
'src' => progress_bar(0, 300, 20, '0%', 1, false, "#0000ff"),
|
||||
'alt' => '0%',
|
||||
'percent' => 0);
|
||||
|
||||
$percent = 0;
|
||||
if ((count($files) > 0) && ($total > 0)) {
|
||||
$percent = format_numeric((count($files) / $total) * 100, 2);
|
||||
if ($percent > 100)
|
||||
$percent = 100;
|
||||
}
|
||||
|
||||
$files_txtbox = (string)implode("<br />", $files);
|
||||
$return['info'] = sprintf($return['info'], $files_txtbox);
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#0000ff");
|
||||
$return['percent'] = $percent;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['title'] = $attr[1];
|
||||
|
||||
if ($percent == 100) {
|
||||
unlink('/tmp/' . $package . '.files.info.txt');
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
?>
|
|
@ -19,12 +19,12 @@
|
|||
* @subpackage UI
|
||||
*/
|
||||
|
||||
require_once ($config['homedir'].'/include/functions_agents.php');
|
||||
require_once($config['homedir'] . "/include/functions_modules.php");
|
||||
require_once($config['homedir'] . "/include/functions.php");
|
||||
require_once ($config['homedir'] . '/include/functions_groups.php');
|
||||
require_once ($config['homedir'] . '/include/functions_users.php');
|
||||
require_once ($config['homedir'] . '/include/functions_html.php');
|
||||
require_once($config['homedir'].'/include/functions_agents.php');
|
||||
require_once($config['homedir'] . '/include/functions_modules.php');
|
||||
require_once($config['homedir'] . '/include/functions.php');
|
||||
require_once($config['homedir'] . '/include/functions_groups.php');
|
||||
require_once($config['homedir'] . '/include/functions_users.php');
|
||||
require_once($config['homedir'] . '/include/functions_html.php');
|
||||
|
||||
|
||||
/**
|
||||
|
@ -110,11 +110,14 @@ function printSmallFont ($string, $return = true) {
|
|||
$length = strlen($str);
|
||||
if ($length >= 30) {
|
||||
$size = 0.7;
|
||||
} elseif ($length >= 20) {
|
||||
}
|
||||
elseif ($length >= 20) {
|
||||
$size = 0.8;
|
||||
} elseif ($length >= 10) {
|
||||
}
|
||||
elseif ($length >= 10) {
|
||||
$size = 0.9;
|
||||
} elseif ($length < 10) {
|
||||
}
|
||||
elseif ($length < 10) {
|
||||
$size = 1;
|
||||
}
|
||||
|
||||
|
@ -123,7 +126,8 @@ function printSmallFont ($string, $return = true) {
|
|||
$s .= '</span>';
|
||||
if ($return) {
|
||||
return $s;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
echo $s;
|
||||
}
|
||||
}
|
||||
|
@ -227,32 +231,36 @@ function ui_print_timestamp ($unixtime, $return = false, $option = array ()) {
|
|||
|
||||
if (isset ($option["html_attr"])) {
|
||||
$attributes = $option["html_attr"];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$attributes = "";
|
||||
}
|
||||
|
||||
if (isset ($option["tag"])) {
|
||||
$tag = $option["tag"];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$tag = "span";
|
||||
}
|
||||
|
||||
if (empty ($option["style"])) {
|
||||
$style = 'style="white-space:nowrap;"';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$style = 'style="'.$option["style"].'"';
|
||||
}
|
||||
|
||||
if (!empty ($option["prominent"])) {
|
||||
$prominent = $option["prominent"];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$prominent = $config["prominent_time"];
|
||||
}
|
||||
|
||||
|
||||
if (!is_numeric ($unixtime)) {
|
||||
$unixtime = strtotime ($unixtime);
|
||||
}
|
||||
|
||||
|
||||
//prominent_time is either timestamp or comparation
|
||||
if ($unixtime <= 0) {
|
||||
$title = __('Unknown').'/'.__('Never');
|
||||
|
@ -273,16 +281,19 @@ function ui_print_timestamp ($unixtime, $return = false, $option = array ()) {
|
|||
|
||||
$output = '<'.$tag;
|
||||
switch ($tag) {
|
||||
default:
|
||||
//Usually tags have title attributes, so by default we add, then fall through to add attributes and data
|
||||
$output .= ' title="'.$title.'"';
|
||||
case "h1":
|
||||
case "h2":
|
||||
case "h3":
|
||||
//Above tags don't have title attributes
|
||||
$output .= ' '.$attributes.' '.$style.'>'.$data.'</'.$tag.'>';
|
||||
default:
|
||||
//Usually tags have title attributes, so by default we add,
|
||||
//then fall through to add attributes and data
|
||||
$output .= ' title="'.$title.'"';
|
||||
break;
|
||||
case "h1":
|
||||
case "h2":
|
||||
case "h3":
|
||||
//Above tags don't have title attributes
|
||||
$output .= ' '.$attributes.' '.$style.'>'.$data.'</'.$tag.'>';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($return)
|
||||
return $output;
|
||||
|
||||
|
@ -393,7 +404,7 @@ function ui_print_group_icon_path ($id_group, $return = false, $path = "images/g
|
|||
function ui_print_os_icon ($id_os, $name = true, $return = false, $apply_skin = true, $networkmap = false, $only_src = false) {
|
||||
$subfolter = 'os_icons';
|
||||
if ($networkmap) {
|
||||
$subfolter = 'networkmap';
|
||||
$subfolter = 'networkmap';
|
||||
}
|
||||
|
||||
$icon = (string) db_get_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os);
|
||||
|
@ -467,14 +478,14 @@ function ui_print_agent_name ($id_agent, $return = false, $cutoff = 0, $style =
|
|||
* @return array A formatted array with proper html for use in $table->data (6 columns)
|
||||
*/
|
||||
function ui_format_alert_row ($alert, $compound = false, $agent = true, $url = '', $agent_style = false) {
|
||||
|
||||
|
||||
global $config;
|
||||
|
||||
|
||||
$actionText = "";
|
||||
require_once ("include/functions_alerts.php");
|
||||
$isFunctionPolicies = enterprise_include_once ('include/functions_policies.php');
|
||||
$id_group = (int) get_parameter ("ag_group", 0); //0 is the All group (selects all groups)
|
||||
|
||||
|
||||
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
|
||||
if ($agent) {
|
||||
$index = array('policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 4,
|
||||
|
@ -537,7 +548,7 @@ function ui_format_alert_row ($alert, $compound = false, $agent = true, $url = '
|
|||
$data[$index['policy']] = '';
|
||||
else {
|
||||
$img = 'images/policies.png';
|
||||
|
||||
|
||||
$data[$index['policy']] = '<a href="?sec=gpolicies&sec2=enterprise/godmode/policies/policies&id=' . $policyInfo['id'] . '">' .
|
||||
html_print_image($img,true, array('title' => $policyInfo['name'])) .
|
||||
'</a>';
|
||||
|
@ -602,7 +613,7 @@ function ui_format_alert_row ($alert, $compound = false, $agent = true, $url = '
|
|||
$data[$index['description']] .= $disabledHtmlStart . ui_print_truncate_text (io_safe_input ($description), 35, false, true, true, '[…]', 'font-size: 7.1pt') . $disabledHtmlEnd;
|
||||
|
||||
$actions = alerts_get_alert_agent_module_actions ($alert['id'], false, $compound);
|
||||
|
||||
|
||||
if (!empty($actions)) {
|
||||
$actionText = '<div style="margin-left: 10px;"><ul class="action_list">';
|
||||
foreach ($actions as $action) {
|
||||
|
@ -618,12 +629,12 @@ function ui_format_alert_row ($alert, $compound = false, $agent = true, $url = '
|
|||
if ($actionDefault != "")
|
||||
$actionText = db_get_sql ("SELECT name FROM talert_actions WHERE id = $actionDefault"). " <i>(".__("Default") . ")</i>";
|
||||
}
|
||||
|
||||
|
||||
$data[$index['action']] = $actionText;
|
||||
|
||||
$data[$index['last_fired']] = $disabledHtmlStart . ui_print_timestamp ($alert["last_fired"], true) . $disabledHtmlEnd;
|
||||
|
||||
|
||||
|
||||
$status = STATUS_ALERT_NOT_FIRED;
|
||||
$title = "";
|
||||
|
||||
|
@ -648,7 +659,7 @@ function ui_format_alert_row ($alert, $compound = false, $agent = true, $url = '
|
|||
$data[$index['validate']] = html_print_checkbox ("validate[]", $alert["id"], false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -676,14 +687,15 @@ function ui_print_string_substr ($string, $cutoff = 16, $return = false, $fontsi
|
|||
|
||||
$font_size_mod = "";
|
||||
|
||||
if ($fontsize > 0){
|
||||
if ($fontsize > 0) {
|
||||
$font_size_mod = "style='font-size: ".$fontsize."px'";
|
||||
}
|
||||
$string = '<span '.$font_size_mod.' title="'.io_safe_input($string2).'">'.mb_substr ($string2, 0, $cutoff, "UTF-8").$string3.'</span>';
|
||||
|
||||
if ($return === false) {
|
||||
echo $string;
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
@ -705,50 +717,50 @@ function ui_print_alert_template_example ($id_alert_template, $return = false, $
|
|||
$template = alerts_get_alert_template ($id_alert_template);
|
||||
|
||||
switch ($template['type']) {
|
||||
case 'equal':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is <span id="value"></span>');
|
||||
break;
|
||||
case 'not_equal':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is not <span id="value"></span>');
|
||||
break;
|
||||
case 'regex':
|
||||
if ($template['matches_value'])
|
||||
case 'equal':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value matches <span id="value"></span>');
|
||||
else
|
||||
$output .= __('The alert would fire when the value is <span id="value"></span>');
|
||||
break;
|
||||
case 'not_equal':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value doesn\'t match <span id="value"></span>');
|
||||
$value = $template['value'];
|
||||
break;
|
||||
case 'max_min':
|
||||
if ($template['matches_value'])
|
||||
$output .= __('The alert would fire when the value is not <span id="value"></span>');
|
||||
break;
|
||||
case 'regex':
|
||||
if ($template['matches_value'])
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value matches <span id="value"></span>');
|
||||
else
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value doesn\'t match <span id="value"></span>');
|
||||
$value = $template['value'];
|
||||
break;
|
||||
case 'max_min':
|
||||
if ($template['matches_value'])
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is between <span id="min"></span> and <span id="max"></span>');
|
||||
else
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is not between <span id="min"></span> and <span id="max"></span>');
|
||||
break;
|
||||
case 'max':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is between <span id="min"></span> and <span id="max"></span>');
|
||||
else
|
||||
$output .= __('The alert would fire when the value is over <span id="max"></span>');
|
||||
|
||||
break;
|
||||
case 'min':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is not between <span id="min"></span> and <span id="max"></span>');
|
||||
break;
|
||||
case 'max':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is over <span id="max"></span>');
|
||||
|
||||
break;
|
||||
case 'min':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the value is under <span id="min"></span>');
|
||||
|
||||
break;
|
||||
case 'warning':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the module is in warning status');
|
||||
|
||||
break;
|
||||
case 'critical':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the module is in critical status');
|
||||
break;
|
||||
$output .= __('The alert would fire when the value is under <span id="min"></span>');
|
||||
|
||||
break;
|
||||
case 'warning':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the module is in warning status');
|
||||
|
||||
break;
|
||||
case 'critical':
|
||||
/* Do not translate the HTML attributes */
|
||||
$output .= __('The alert would fire when the module is in critical status');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($print_values) {
|
||||
|
@ -1069,7 +1081,6 @@ function ui_process_page_head ($string, $bitfield) {
|
|||
|
||||
//Then add each script as necessary
|
||||
$loaded = array ('');
|
||||
|
||||
foreach ($config['jquery'] as $name => $filename) {
|
||||
if (in_array ($name, $loaded))
|
||||
continue;
|
||||
|
@ -1786,17 +1797,17 @@ function ui_get_full_url ($url = '') {
|
|||
|
||||
function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = ""){
|
||||
$title = io_safe_input_html($title);
|
||||
if (($icon == "") && ($godmode == true)){
|
||||
if (($icon == "") && ($godmode == true)) {
|
||||
$icon = "images/setup.png";
|
||||
}
|
||||
|
||||
if (($icon == "") && ($godmode == false)){
|
||||
|
||||
if (($icon == "") && ($godmode == false)) {
|
||||
$icon = "images/comments.png";
|
||||
}
|
||||
|
||||
if ($godmode == true){
|
||||
|
||||
if ($godmode == true) {
|
||||
$type = "nomn";
|
||||
$type2 = "menu_tab_frame";
|
||||
$type2 = "menu_tab_frame";
|
||||
$separator_class = "separator";
|
||||
}
|
||||
else {
|
||||
|
@ -1804,17 +1815,17 @@ function ui_print_page_header ($title, $icon = "", $return = false, $help = "",
|
|||
$type2 = "menu_tab_frame_view";
|
||||
$separator_class = "separator_view";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$buffer = '<div id="'.$type2.'" style=""><div id="menu_tab_left">';
|
||||
|
||||
|
||||
|
||||
|
||||
$buffer .= '<ul class="mn"><li class="'.$type.'"> ' . html_print_image($icon, true, array("style" => "margin-bottom: -3px;", "class" => "bottom", "border" => "0", "alt" => "")) . ' ';
|
||||
$buffer .= $title;
|
||||
if ($help != "")
|
||||
$buffer .= " " . ui_print_help_icon ($help, true);
|
||||
$buffer .= '</li></ul></div>';
|
||||
|
||||
|
||||
if (is_array($options)) {
|
||||
$buffer .= '<div id="menu_tab"><ul class="mn">';
|
||||
foreach ($options as $key => $option) {
|
||||
|
|
Loading…
Reference in New Issue