Added connection with update manager and some design changes

This commit is contained in:
fermin831 2016-06-08 13:51:34 +02:00
parent 39ec80731e
commit bdbb74e6db
7 changed files with 238 additions and 129 deletions

View File

@ -44,6 +44,8 @@ function display_newsletter ($data) {
if (is_ajax()) {
include_once($config['homedir'] . "/include/functions_update_manager.php");
$open_wizard = get_parameter ('open_wizard', 0);
$not_return = get_parameter ('not_return', 0);
@ -55,17 +57,23 @@ if (is_ajax()) {
$future_8_days = time() + 8 * SECONDS_1DAY;
if ($register_pandora) {
//TODO: Pandora registration
config_update_value ('instance_registered', 1);
// Pandora register update
if (update_manager_register_instance ()) {
config_update_value ('instance_registered', 1);
}
} elseif (!$forced) {
config_update_value ('identification_reminder_timestamp', $future_8_days);
}
if ($newsletter) {
//TODO: Newsletter subscribe
db_process_sql_update ('tusuario', array ('middlename' => 1), array('id_user' => $config['id_user']));
// Pandora newsletter update
$email = get_parameter ('email', '');
if (update_manager_insert_newsletter ($email)){
db_process_sql_update ('tusuario', array ('middlename' => 1), array('id_user' => $config['id_user']));
}
} elseif (!$forced) {
html_debug ('future days');
db_process_sql_update ('tusuario', array ('lastname' => $future_8_days), array('id_user' => $config['id_user']));
}
}
@ -112,27 +120,27 @@ if ($email == 'admin@example.com') $email = '';
// Prints accept register license
echo '<div id="login_accept_register" title="' .
__('Pandora FMS instance identification wizard') . '" style="">';
echo '<div style="font-size: 15pt; margin: 20px; float: left; padding-left: 150px;">';
echo '<div style="font-size: 15pt; margin: 20px 0; float: left; padding-left: 15px;">';
echo html_print_image ('images/support.png', true);
echo '</div>';
echo '<div style="font-size: 15pt; margin: 20px; float: left;">';
echo __('KEEP UPDATED!');
echo '</div>';
echo '<div style="">';
echo '<div id="license_newsletter">';
$license_text = file('license.lic');
$license_text = implode ($license_text);
html_print_textarea ("text-license", 1, 65, $license_text,
'readonly="readonly"; ', false);
foreach ($license_text as $paragraph) {
echo '<p>' . $paragraph . "</p>";
}
echo '</div>';
echo '<div style="position:absolute; margin: 0 auto; bottom: 0px; right: 10px; border: 1px solid #FFF; width: 570px">';
echo '<div style="float: right; width: 20%;">';
echo '<div style="position:absolute; margin: 0 auto; bottom: 0px; padding-top:10px; position:relative; border: 1px solid #FFF;">';
echo '<div style="float: right;">';
html_print_submit_button("Finish", 'finish_dialog_button', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok" style="width:100px;"');
echo '</div>';
$display_status_return = $return_button ? 'block' : 'none';
echo '<div style="float: left; width: 20%; display: ' . $display_status_return . ';">';
html_print_submit_button("Return", 'return_dialog_button', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok" style="width:100px;"');
echo '<div style="float: right; width: 20%; display: ' . $display_status_return . ';">';
html_print_submit_button("Return", 'return_dialog_button', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd" style="width:100px;"');
echo '</div>';
echo '<div style="float: left; margin-left: 0px; width: 50%; text-align: left;">';
html_print_checkbox('register', 1, false, false, false, 'cursor: \'pointer\'');
@ -140,10 +148,11 @@ echo '<div id="login_accept_register" title="' .
html_print_checkbox('newsletter', 1, false, false, false, 'cursor: \'pointer\'');
echo '&nbsp;<span style="font-size: 12px;" id="label-newsletter">' .__("Subscribe to newsletter") . '</span>';
echo "<br>";
echo '&nbsp;<span id="label-email-newsletter"style="font-size: 12px; display: none">' .__("Email") . ': </span>';
//html_print_input_text ('email-newsletter', '', '', 30, 255, false);
html_print_input_text_extended ('email-newsletter', $email, 'text-email-newsletter', '', 30, 255, false, '', array ("style" => "display:none; ")); echo '&nbsp;<span id="label-email-newsletter"style="font-size: 12px; display: none">' .__("Email") . ': </span>';
echo '&nbsp;<span id="required-email-newsletter" style="font-size: 9px; display: none; color: red;">'.__("*Required") .' </span>';
echo '<div id="email_container">';
echo '&nbsp;<span id="label-email-newsletter"style="font-size: 12px; display: none">' .__("Email") . ': </span>';
html_print_input_text_extended ('email-newsletter', $email, 'text-email-newsletter', '', 30, 255, false, '', array ("style" => "display:none; ")); echo '&nbsp;<span id="label-email-newsletter"style="font-size: 12px; display: none">' .__("Email") . ': </span>';
echo '&nbsp;<span id="required-email-newsletter">*'.__("Required") .' </span>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
@ -154,11 +163,11 @@ echo '<div id="login_registration_yesno" title="' .
echo '<div style="font-size: 15pt; margin: 20px;">';
echo __("Do you want to continue without any registration") . "?";
echo '</div>';
echo '<div style="float: left; width: 50%;">';
html_print_submit_button("No", 'no_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok" style="width:100px;"');
echo '<div style="float: left; padding-left: 15px; padding-top: 20px;">';
html_print_submit_button("No", 'no_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub cancel" style="width:100px;"');
echo '</div>';
echo '<div style="float: left; width: 50%;">';
html_print_submit_button("Yes", 'yes_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok" style="width:100px;"');
echo '<div style="float: right; padding-right: 15px; padding-top: 20px;">';
html_print_submit_button("Yes", 'yes_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd" style="width:100px;"');
echo '</div>';
echo '</div>';
?>
@ -171,7 +180,6 @@ var display_register = <?php echo json_encode($display_register); ?>;
var display_newsletter = <?php echo json_encode($display_newsletter); ?>;
var display_forced = <?php echo json_encode($display_forced); ?>;
var return_button = <?php echo json_encode($return_button); ?>;
////////////////////////////////////////////////////////////////////////
//HELPER FUNCTIONS
@ -247,22 +255,17 @@ $("#checkbox-newsletter").click (function () {
$(document).ready (function () {
$("#login_accept_register").dialog({
resizable: true,
resizable: false,
draggable: true,
modal: true,
height: 350,
width: 630,
overlay: {
opacity: 0.5,
background: "black"
},
});
$("#login_registration_yesno").dialog({
resizable: true,
resizable: false,
draggable: true,
modal: true,
height: 250,
width: 350,
overlay: {
opacity: 1,
@ -288,3 +291,39 @@ $(document).ready (function () {
/* ]]> */
</script>
<style type="text/css">
#required-email-newsletter{
font-size : 9px;
color: red;
float:right;
left: -26px;
top: 3px;
position: relative;
display: none;
}
#email_container{
margin-top: 3px;
}
#license_newsletter {
height: 100px;
width: 100%;
overflow-y: scroll;
border: 1px solid grey;
border-radius: 3px;
}
#license_newsletter p{
padding: 0 3px;
}
.ui-widget-overlay {
background: #000;
opacity: .6;
}
</style>

View File

@ -39,6 +39,7 @@ if (is_ajax()) {
if ($not_read_single) {
$message_id = get_parameter ('message_id', 0);
update_manger_set_read_message ($message_id, 1);
update_manager_remote_read_messages ($message_id);
}
return;
@ -74,6 +75,7 @@ if ($total_messages){
// Get all messages
$sql = 'SELECT data, svn_version, filename, data_rollback, db_field_value FROM tupdate ';
$sql .= 'WHERE description NOT LIKE \'%"' . $config['id_user'] . '":1%\' ';
$sql .= 'OR description IS NULL ';
$sql .= 'LIMIT ' . $offset . ',' . $config['block_size'];
$um_messages = array ();
$um_messages = db_get_all_rows_sql ($sql);
@ -84,12 +86,12 @@ if ($total_messages){
html_print_input_hidden ('offset', $offset);
echo '<div class="action-buttons" style="float:right; padding: 10px 5px">';
html_print_submit_button (__('Delete'), 'delete_button', false,
'class="sub upd"');
'class="sub delete"');
echo '</div>';
echo '<div class="action-buttons" style="float:right; padding: 10px 5px">';
html_print_submit_button (__('Mark as not read'), 'not_read_button', false,
'class="sub upd"');
'class="sub wand"');
echo '</div>';
if ($total_messages > $config['block_size']) {
@ -113,26 +115,32 @@ if ($total_messages){
$table->align[3] = "left";
$table->align[4] = "left";
$table->size[0] = "20px";
$table->size[0] = "30px";
$table->size[1] = "100px";
$table->size[3] = "80px";
$table->size[4] = "60px";
$table->head[0] = __('Message Id');
$table->head[1] = __('Expiration date');
$table->style[0] = "padding-left: 20px";
$table->head[0] = html_print_checkbox_extended('all_selection[]', 0, false, false, '', '', true);
$table->head[1] = __('Message Id');
$table->head[2] = __('Subject');
$table->head[3] = html_print_checkbox_extended('all_selection[]', 0, false, false, '', '', true);
$table->head[3] = __('Expiration date');
$i = 0;
foreach ($um_messages as $message) {
$data[0] = $message['svn_version'];
$data[0] = html_print_checkbox_extended('select_multiple[]', $message['svn_version'], false, false, '', 'class="check_selection"', true);
$table->cellclass[count($table->data)][0] = 'um_individual_check';
$data[1] = $message['filename'];
$data[1] = $message['svn_version'];
$table->cellclass[count($table->data)][1] = 'um_individual_info';
$data[2] = $message['db_field_value'];
$table->cellclass[count($table->data)][2] = 'um_individual_subject';
//~ $delete_link = 'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&amp;tab=messages&amp;delete_single=1&amp;message_id=' . $message['svn_version'];
$data[3] = html_print_checkbox_extended('select_multiple[]', $message['svn_version'], false, false, '', 'class="check_selection"', true);
$data[3] = $message['filename'];
$table->cellclass[count($table->data)][3] = 'um_individual_info';
// Change row class if message is read or not by this user
@ -156,14 +164,14 @@ if ($total_messages){
}
html_print_table($table);
echo '<div class="action-buttons" style="float:right"; padding: 0 5px>';
echo '<div class="action-buttons" style="float:right; padding: 0 5px;">';
html_print_submit_button (__('Delete'), 'delete_button', false,
'class="sub upd"');
'class="sub delete"');
echo '</div>';
echo '<div class="action-buttons" style="float:right; padding: 0 5px">';
echo '<div class="action-buttons" style="float:right; padding: 0 5px;">';
html_print_submit_button (__('Mark as not read'), 'not_read_button', false,
'class="sub upd"');
'class="sub wand"');
echo '</div>';
echo '</form>';
} else {
@ -176,8 +184,10 @@ if ($total_messages){
$("#checkbox-all_selection").click( function() {
if ($("#checkbox-all_selection").is(':checked')) {
$(".check_selection").prop('checked', true);
$(".check_selection").parent().parent().css('background', "#FFFFEE");
} else {
$(".check_selection").prop('checked', false);
$(".check_selection").parent().parent().css('background', "inherit");
}
});
@ -194,14 +204,14 @@ if ($total_messages){
var column = raw_position.replace(/.*-/ig, "");
// Delete and mark as not read column will do not open the message
if (column > 2) return;
if (column == 0) return;
if (row%2 == 0) {
// Clicking a tittle
// Class where object will be displayed
var current_class = ".um_message_" + row/2;
var message_id = $("#"+target).parent().find(":first-child").html();
var message_id = $("#"+target).parent().find(":nth-child(2)").html();
var div_id = 'um_individual_message' + row/2;
// Get the message via Ajax (only if it is not checked now
@ -230,17 +240,77 @@ if ($total_messages){
"message_id": message_id},
function (data) {}
);
$("#"+target).parent().find(".um_not_read_message").attr('class', 'um_read_message');
$("#"+target).parent().children().each(function(){
var full_class = $(this).attr('class');
console.log ("current_class: " + full_class);
full_class = full_class.replace (/um_not_read_message/g, "um_read_message");
console.log ("modified_class: " + full_class);
$(this).attr('class', full_class);
});
}
}
// Display message
$(current_class).toggle ();
} else {
// Clicking a message
$(".um_message_" + Math.floor(row/2)).hide();
}
});
$(".check_selection").click(function (event) {
console.log(event.target.id);
if ($("#" + event.target.id).is(':checked')) {
$("#" + event.target.id).parent().parent().css('background', "#FFFFEE");
} else {
$("#" + event.target.id).parent().parent().css('background', 'inherit');
}
});
$(".um_individual_info, .um_individual_subject").hover(
function () {
$(this).parent().css('background', '#EFFFEF');
},
function () {
if ($(this).parent().find(":first-child").is(':checked')) {
$(this).parent().css('background', "#FFFFEE");
} else {
$(this).parent().css('background', 'inherit');
}
}
);
</script>
<style type="text/css">
.um_not_read_message{
font-weight: 900;
}
.um_read_message{
font-weight: 500;
color: #909090;
}
.um_individual_info, .um_individual_subject {
cursor: pointer;
}
.databox td {
padding-top: 15px;
padding-bottom: 15px;
}
td input[type=checkbox] {
ms-transform: scale(1);
moz-transform: scale(1);
o-transform: scale(1);
webkit-transform: scale(1);
transform: scale(1);
}
.c0 {
padding-left: 17px !important;
}
</style>

View File

@ -201,6 +201,8 @@ function config_update_config () {
$error_update[] = __('Allow create planned downtimes in the past');
if (!config_update_value ('limit_parameters_massive', get_parameter('limit_parameters_massive')))
$error_update[] = __('Limit parameters massive');
if (!config_update_value ('identification_reminder', get_parameter('identification_reminder')))
$error_update[] = __('Identification_reminder');
break;
case 'enterprise':
if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) {
@ -1464,7 +1466,7 @@ function config_check () {
//Registration advice
if (!isset ($config['instance_registered']) || ($config['instance_registered'] != 1)) {
set_pandora_error_for_header(
__('Click <a style="font-weight:bold;" href="javascript: force_run_register();"> HERE </a> to init the registration process'),
__('Click <a style="font-weight:bold; text-decoration:underline" href="javascript: force_run_register();"> here </a> to init the registration process'),
__("This PandoraFMS instance is not registered"));
}
@ -1472,7 +1474,7 @@ function config_check () {
$newsletter = db_get_value ('middlename', 'tusuario', 'id_user', $config['id_user']);
if ($newsletter != 1) {
set_pandora_error_for_header(
__('Click <a style="font-weight:bold;" href="javascript: force_run_newsletter();"> HERE </a> to init the newsletter subscription process'),
__('Click <a style="font-weight:bold; text-decoration:underline" href="javascript: force_run_newsletter();"> here </a> to init the newsletter subscription process'),
__("Missing user in newsletter"));
}
}

View File

@ -383,11 +383,9 @@ function update_manager_curl_request ($action, $additional_params = false) {
'build' => $um_config_values['build']
);
if ($additional_params !== false) {
html_debug ($additional_params, true);
$params = array_merge ($params, $additional_params);
}
$params['action'] = $action;
html_debug ($params, true);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $config['url_update_manager']);
@ -454,38 +452,30 @@ function update_manager_curl_request ($action, $additional_params = false) {
}
function update_manager_insert_newsletter () {
function update_manager_insert_newsletter ($email) {
global $config;
$email = db_get_value ('email', 'tusuario', 'id_user', $config['id_user']);
if ($email === '') return false;
$params = array(
'email' => $email,
'language' => $config['language']
);
//For to test in the shell ?????????????????
/*
wget https://artica.es/pandoraupdate6/server.php -O- --no-check-certificate --post-data "action=new_newsletter&email=m@d.com&language=es"
*/
$result = update_manager_curl_request ('new_newsletter', $params);
if (!$result['success']) {
html_debug ("FAIL update_manager_insert_newsletter", true);
html_debug ($result, true);
return ($result['update_message']);
return false;
}
switch ($resul['http_status']) {
switch ($result['http_status']) {
case 200:
//SUCESS
break;
case 201: //provisional
//EMAIL ON DB
break;
$message = json_decode($result['update_message'], true);
if ($message['success'] == 1) return true;
return false;
default:
//FAILS
return false;
break;
}
}
@ -496,39 +486,38 @@ function update_manager_register_instance () {
$email = db_get_value ('email', 'tusuario', 'id_user', $config['id_user']);
$params = array(
'language' => $config['language'],
'timezone' => $config['timezone']
'timezone' => $config['timezone'],
'email' => $email
);
//For to test in the shell ??????????????
/*
wget https://artica.es/pandoraupdate6/server.php -O- --no-check-certificate --post-data "action=new_instance&language=es&timezone=Europe/Berlin"
*/
$result = update_manager_curl_request ('new_instance', $params);
$result = update_manager_curl_request ('new_register', $params);
if (!$result['success']) {
html_debug ("FAIL update_manager_register_instance", true);
html_debug ($result, true);
return ($result['update_message']);
return false;
}
switch ($resul['http_status']) {
switch ($result['http_status']) {
case 200:
//SUCESS
//Retrieve the PUID
$update_message = json_decode($result['update_message'], true);
$puid = $update_message[0]['pandora_uid'];
config_update_value ('pandora_uid', $puid);
//The tupdate table is reused to display messages. A specific entry to tupdate_package is required.
//Then, this tupdate_package id is saved in tconfig
db_process_sql_insert ('tupdate_package', array ('description' => '__UMMESSAGES__'));
$id_um_package_messages = db_get_value('id', 'tupdate_package', 'description', '__UMMESSAGES__');
config_update_config ('id_um_package_messages', $id_um_package_messages);
$message = json_decode($result['update_message'], true);
if ($message['success'] == 1) {
$puid = $message['pandora_uid'];
config_update_value ('pandora_uid', $puid);
//The tupdate table is reused to display messages. A specific entry to tupdate_package is required.
//Then, this tupdate_package id is saved in tconfig
db_process_sql_insert ('tupdate_package', array ('description' => '__UMMESSAGES__'));
$id_um_package_messages = db_get_value('id', 'tupdate_package', 'description', '__UMMESSAGES__');
config_update_value ('id_um_package_messages', $id_um_package_messages);
return true;
} else {
return false;
}
break;
default:
//FAILS
return false;
break;
}
}
@ -537,56 +526,66 @@ function update_manager_download_messages () {
// TODO: Delete old messages
$email = db_get_value ('email', 'tusuario', 'id_user', $config['id_user']);
$params = array(
'pandora_uid' => $config['puid']
);
'pandora_uid' => $config['pandora_uid']
);
//For to test in the shell ??????????????
/*
wget https://artica.es/pandoraupdate6/server.php -O- --no-check-certificate --post-data "action=download_messages&language=es&timezone=Europe/Berlin"
*/
$result = update_manager_curl_request ('download_messages', $params);
$result = update_manager_curl_request ('get_messages', $params);
//Do not ask in next 2 hours
config_update_value ('last_um_check', time() + 2 * SECONDS_1HOUR);
if (!$result['success']) {
//Do not ask in next 2 hours
//~ html_debug ("FAIL update_manager_download_messages", true);
//~ html_debug ($result, true);
config_update_value ('last_um_check', time() + 2 * SECONDS_1HOUR);
return ($result['update_message']);
}
switch ($resul['http_status']) {
switch ($result['http_status']) {
case 200:
//SUCESS
$message = json_decode($result['update_message'], true);
if ($message['success'] == 1) {
foreach ($message['messages'] as $single_message) {
// Convert subject -> db_field_value; message_html -> data; expiration -> filename; message_id -> svn_version
$single_message['db_field_value'] = $single_message['subject'];
unset ($single_message['subject']);
$single_message['data'] = $single_message['message_html'];
unset ($single_message['message_html']);
$single_message['filename'] = $single_message['expiration'];
unset ($single_message['expiration']);
$single_message['svn_version'] = $single_message['message_id'];
unset ($single_message['message_id']);
// Add common tconfig id_update_package
$single_message['id_update_package'] = $config['id_um_package_messages'];
$result = db_process_sql_insert('tupdate', $single_message);
}
}
break;
default:
}
//Do not ask in next 2 hours
config_update_value ('last_um_check', time() + 2 * SECONDS_1HOUR);
//FAILS
break;
}
}
function update_manager_remote_read_messages ($id_message) {
global $config;
$email = db_get_value ('email', 'tusuario', 'id_user', $config['id_user']);
$params = array(
'pandora_uid' => $config['puid'],
'id_message' => $id_message
'pandora_uid' => $config['pandora_uid'],
'message_id' => $id_message
);
//For to test in the shell ??????????????
/*
wget https://artica.es/pandoraupdate6/server.php -O- --no-check-certificate --post-data "action=download_messages&language=es&timezone=Europe/Berlin"
*/
$result = update_manager_curl_request ('mark_as_read', $params);
$result = update_manager_curl_request ('read_message', $params);
//if (!$result['success']) {
// html_debug ($result['update_message'], true);
//}
html_debug ("Update_manager_read_messages", true);
html_debug ($result, true);
return $result['success'];
}

View File

@ -3087,14 +3087,6 @@ table#policy_modules td * {
margin-left: 3%;
}
.um_not_read_message{
font-weight: 900;
}
.um_read_message{
font-weight: 500;
color: #bbbbbb;
}
/* The items with the class 'spinner' will rotate */
/* Not supported on IE9 and below */
.spinner {

View File

@ -528,6 +528,14 @@ clear_pandora_error_for_header();
$config['logged'] = false;
extensions_load_extensions ($process_login);
// Check for update manager messages
if ($config['last_um_check'] > (time() + 2 * SECONDS_1HOUR)) {
require_once("include/functions_update_manager.php");
update_manager_download_messages ();
}
if ($process_login) {
/* Call all extensions login function */
extensions_call_login_function ();
@ -615,7 +623,6 @@ if (get_parameter ('login', 0) !== 0) {
include_once("general/login_help_dialog.php");
}
}
// Header

View File

@ -362,10 +362,10 @@ if (license_free()) {
$data[1] = __('Newsletter Subscribed');
$data[1] .= $jump . ui_print_help_tip(__('Subs news'), true);
if ($user_info["middlename"]) {
$data[1] .= $jump . __('You are subscribed to PandoraFMS newsletter');
$data[1] .= $jump . '<span style="font-weight:initial;">' . __('You are subscribed to PandoraFMS newsletter') . "</span>";
}
else {
$data[1] .= $jump . __('Click <a style="font-weight:bold;" href="javascript: force_run_newsletter();"> HERE </a> to init the newsletter subscription process');
$data[1] .= $jump . '<span style="font-weight:initial;">' . __('Click <a style="text-decoration:underline; font-weight:bold;" href="javascript: force_run_newsletter();"> here </a> to init the newsletter subscription process') . "</span>";
}
$data[2] = __('Newsletter Reminder');