From c88ead7e994c3ae137589beba89191cfb048d1ee Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Thu, 12 Apr 2012 14:43:26 +0000 Subject: [PATCH] 2012-04-12 Juan Manuel Ramon * include/javascript/jquery.pandora.js extensions/update_manager.php extensions/update_manager/settings.php: Added modal window with UM license info. * extensions/update_license_info.php: Added extension with UM license info. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5960 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 10 ++ .../extensions/update_license_info.php | 128 ++++++++++++++++++ pandora_console/extensions/update_manager.php | 124 +++++++++++++++++ .../extensions/update_manager/settings.php | 2 + .../include/javascript/jquery.pandora.js | 28 ++++ 5 files changed, 292 insertions(+) create mode 100644 pandora_console/extensions/update_license_info.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 585a42eb28..84857664a1 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2012-04-12 Juan Manuel Ramon + + * include/javascript/jquery.pandora.js + extensions/update_manager.php + extensions/update_manager/settings.php: Added modal window with UM + license info. + + * extensions/update_license_info.php: Added extension with UM + license info. + 2012-04-12 Miguel de Dios * include/styles/pandora.css: add changes for the new standarized messages. diff --git a/pandora_console/extensions/update_license_info.php b/pandora_console/extensions/update_license_info.php new file mode 100644 index 0000000000..51bc66419f --- /dev/null +++ b/pandora_console/extensions/update_license_info.php @@ -0,0 +1,128 @@ += ord ('A') && $ascii_ord <= ord ('Z')) { + return $ascii_ord - ord ('A'); + } + if ($ascii_ord >= ord ('0') && $ascii_ord <= ord ('9')) { + return sizeof (range ('A','Z')) + $ascii_ord - ord ('0'); + } + + return -1; + } + + // Un-shift a string given a key: string[i] = shifted_string[i] - key[i] mod |Alphabet| + $Alphabet = array_merge (range ('A','Z'), range('0', '9')); + $AlphabetSize = sizeof ($Alphabet); + + function license_unshift_string ($string, $key) { + global $Alphabet; + global $AlphabetSize; + + // Get the minimum length + $string_length = strlen ($string); + $key_length = strlen ($key); + if ($string_length < $key_length) { + $min_length = $string_length; + } else { + $min_length = $key_length; + } + + // Shift the string + $unshifted_string = ''; + for ($i = 0; $i < $min_length; $i++) { + $unshifted_string .= $Alphabet[($AlphabetSize + license_char_ord ($string[$i]) - license_char_ord ($key[$i])) % $AlphabetSize]; + } + + return $unshifted_string; + } + + function show_check_pandora_license ($license) { + + if (strlen ($license) != 32) { + return array ("Invalid license!", '', '', '', '', '', ''); + } + + $company_name = trim (substr ($license, 0, 4), "0"); + $random_string = substr ($license, 4, 8); + $max_agents = (int) license_unshift_string (substr ($license, 12, 6), $random_string); + $license_mode_string = license_unshift_string (substr ($license, 18, 6), $random_string); + $license_mode = (int) substr ($license_mode_string, 0, 1); + $expiry_date_string = license_unshift_string (substr ($license, 24, 8), $random_string); + $expiry_year = substr ($expiry_date_string, 0, 4); + $expiry_month = substr ($expiry_date_string, 4, 2); + $expiry_day = substr ($expiry_date_string, 6, 2); + return array ("Valid license.", $company_name, $max_agents, $expiry_day, $expiry_month, $expiry_year, $license_mode); + } + + $license = db_get_value_sql ('SELECT value FROM tupdate_settings WHERE `key`="customer_key"'); + + if ($license === false) { + echo "

License not available

"; + return; + } + + $license_info = array(); + $license_info = show_check_pandora_license($license); + + $table->width = '98%'; + $table->data = array (); + + $table->data[0][0] = ''.__('Company').''; + $table->data[0][1] = $license_info[1]; + $table->data[1][0] = ''.__('Expires').''; + $table->data[1][1] = $license_info[3] . ' / ' . $license_info[4] . ' / ' . $license_info[5]; + $table->data[2][0] = ''.__('Platform Limit').''; + $table->data[2][1] = $license_info[2]; + $table->data[3][0] = ''.__('Current Platform Count').''; + $count_agents = db_get_value_sql ('SELECT count(*) FROM tagente'); + $table->data[3][1] = $count_agents; + $table->data[4][0] = ''.__('License Mode').''; + if ($license_info[6] == 1) + $license_mode_string = 'Client'; + else + $license_mode_string = 'Trial'; + $table->data[4][1] = $license_mode_string; + + html_print_table ($table); + +} + +extensions_add_godmode_menu_option (__('Update manager license info'), 'PM'); +extensions_add_godmode_function ('update_manage_license_info_main'); diff --git a/pandora_console/extensions/update_manager.php b/pandora_console/extensions/update_manager.php index d127d416b7..8d048bf13f 100644 --- a/pandora_console/extensions/update_manager.php +++ b/pandora_console/extensions/update_manager.php @@ -31,8 +31,132 @@ if (is_ajax ()) { $checking_online_enterprise_package = (bool)get_parameter('checking_online_enterprise_package', false); + $get_license_info = get_parameter('get_license_info', 0); + if ($checking_online_enterprise_package) { checking_online_enterprise_package(); + + return; + } + + if ($get_license_info) { + + include_once("include/functions_db.php"); + + $Alphabet = array_merge (range ('A','Z'), range('0', '9')); + $AlphabetSize = sizeof ($Alphabet); + + // Return the order of the given char in ('A'..'Z', 0-9) + function char_ord ($char) { + + $ascii_ord = ord ($char); + if ($ascii_ord >= ord ('A') && $ascii_ord <= ord ('Z')) { + return $ascii_ord - ord ('A'); + } + if ($ascii_ord >= ord ('0') && $ascii_ord <= ord ('9')) { + return sizeof (range ('A','Z')) + $ascii_ord - ord ('0'); + } + + return -1; + } + + // Generate a random string of the given length + function random_string ($length) { + global $Alphabet, $AlphabetSize; + + $random_string = ''; + for ($i = 0; $i < $length; $i++) { + $random_string .= $Alphabet[rand (0, $AlphabetSize - 1)]; + } + + return $random_string; + } + + // Shift a string given a key: shifted_string[i] = string[i] + key[i] mod |Alphabet| + function shift_string ($string, $key) { + global $Alphabet, $AlphabetSize; + + // Get the minimum length + $string_length = strlen ($string); + $key_length = strlen ($key); + $min_length = $string_length < $key_length ? $string_length : $key_length; + + // Shift the string + $shifted_string = ''; + for ($i = 0; $i < $min_length; $i++) { + $shifted_string .= $Alphabet[(char_ord ($string[$i]) + char_ord ($key[$i])) % $AlphabetSize]; + } + + return $shifted_string; + } + // Un-shift a string given a key: string[i] = shifted_string[i] - key[i] mod |Alphabet| + function unshift_string ($string, $key) { + global $Alphabet, $AlphabetSize; + + // Get the minimum length + $string_length = strlen ($string); + $key_length = strlen ($key); + $min_length = $string_length < $key_length ? $string_length : $key_length; + + // Shift the string + $unshifted_string = ''; + for ($i = 0; $i < $min_length; $i++) { + $unshifted_string .= $Alphabet[($AlphabetSize + char_ord ($string[$i]) - char_ord ($key[$i])) % $AlphabetSize]; + } + + return $unshifted_string; + } + + function check_pandora_license ($license) { + + if (strlen ($license) != 32) { + return array ("Invalid license!", '', '', '', '', '', ''); + } + + $company_name = trim (substr ($license, 0, 4), "0"); + $random_string = substr ($license, 4, 8); + $max_agents = (int) unshift_string (substr ($license, 12, 6), $random_string); + $license_mode_string = unshift_string (substr ($license, 18, 6), $random_string); + $license_mode = (int) substr ($license_mode_string, 0, 1); + $expiry_date_string = unshift_string (substr ($license, 24, 8), $random_string); + $expiry_year = substr ($expiry_date_string, 0, 4); + $expiry_month = substr ($expiry_date_string, 4, 2); + $expiry_day = substr ($expiry_date_string, 6, 2); + return array ("Valid license.", $company_name, $max_agents, $expiry_day, $expiry_month, $expiry_year, $license_mode); + } + + $license = db_get_value_sql ('SELECT value FROM tupdate_settings WHERE `key`="customer_key"'); + + if ($license === false) { + echo "

License not available

"; + return; + } + + $license_info = array(); + $license_info = check_pandora_license($license); + + $table->width = '98%'; + $table->data = array (); + + $table->data[0][0] = ''.__('Company').''; + $table->data[0][1] = $license_info[1]; + $table->data[1][0] = ''.__('Expires').''; + $table->data[1][1] = $license_info[3] . ' / ' . $license_info[4] . ' / ' . $license_info[5]; + $table->data[2][0] = ''.__('Platform Limit').''; + $table->data[2][1] = $license_info[2]; + $table->data[3][0] = ''.__('Current Platform Count').''; + $count_agents = db_get_value_sql ('SELECT count(*) FROM tagente'); + $table->data[3][1] = $count_agents; + $table->data[4][0] = ''.__('License Mode').''; + if ($license_info[6] == 1) + $license_mode_string = 'Client'; + else + $license_mode_string = 'Trial'; + $table->data[4][1] = $license_mode_string; + + html_print_table ($table); + + return; } return; diff --git a/pandora_console/extensions/update_manager/settings.php b/pandora_console/extensions/update_manager/settings.php index 988f5912ae..1c96f2e481 100644 --- a/pandora_console/extensions/update_manager/settings.php +++ b/pandora_console/extensions/update_manager/settings.php @@ -67,6 +67,8 @@ $table->data = array (); $table->data[0][0] = ''.__('Customer key').''; $table->data[0][1] = html_print_input_text ('keys[customer_key]', $settings->customer_key, '', 40, 255, true); +$table->data[0][1] .= ' '.html_print_image('images/lock.png', true, array('class' => 'bot', 'title' => __('License info'))).''; +$table->data[0][1] .= ''; $table->data[1][0] = ''.__('Update server host').''; $table->data[1][1] = html_print_input_text ('keys[update_server_host]', $settings->update_server_host, '', 20, 255, true); diff --git a/pandora_console/include/javascript/jquery.pandora.js b/pandora_console/include/javascript/jquery.pandora.js index 6aa6f866b7..f8b30ea95f 100644 --- a/pandora_console/include/javascript/jquery.pandora.js +++ b/pandora_console/include/javascript/jquery.pandora.js @@ -106,6 +106,34 @@ $(document).ready (function () { }); + $("a#dialog_license_info").click (function () { + jQuery.get ("ajax.php", + {"page": "extensions/update_manager", + "get_license_info": "1"}, + function (data, status) { + $("#dialog_show_license").hide () + .empty () + .append (data) + .dialog ({ + title: $("a#dialog_license_info").attr ("title"), + resizable: false, + draggable: true, + modal: true, + overlay: { + opacity: 0.5, + background: "black" + }, + bgiframe: jQuery.browser.msie, + width: 500, + height: 180 + }) + .show (); + }, + "html" + ); + return false; + }); + } );