pandorafms/pandora_console/godmode/setup/license.php

464 lines
12 KiB
PHP
Raw Normal View History

<?php
2019-05-22 18:50:51 +02:00
/**
* License form.
*
* @category Form
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
2019-05-22 18:50:51 +02:00
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright (c) 2005-2023 Pandora FMS
2023-06-08 13:19:01 +02:00
* Please see https://pandorafms.com/community/ for full contribution list
2019-05-22 18:50:51 +02:00
* 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 for 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.
* ============================================================================
*/
// File begin.
global $config;
check_login();
if (! check_acl($config['id_user'], 0, 'PM')) {
2022-02-01 13:39:18 +01:00
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to change License settings'
);
include 'general/noaccess.php';
return;
}
$update_settings = (bool) get_parameter_post('update_settings');
2023-03-02 12:46:47 +01:00
ui_require_javascript_file_enterprise('load_enterprise', is_metaconsole() === true);
enterprise_include_once('include/functions_license.php');
// Header.
ui_print_standard_header(
__('License management'),
'images/extensions.png',
false,
'',
true,
[],
[
[
'link' => '',
'label' => __('License'),
],
]
);
2022-09-20 11:37:07 +02:00
enterprise_include_once('include/functions_crypto.php');
if ($renew_license_result !== null) {
echo $renew_license_result;
}
if ($update_settings) {
2019-05-22 18:50:51 +02:00
if (!is_metaconsole()) {
// Node.
foreach ($_POST['keys'] as $key => $value) {
db_process_sql_update(
'tupdate_settings',
[db_escape_key_identifier('value') => $value],
[db_escape_key_identifier('key') => $key]
);
}
2022-09-20 11:37:07 +02:00
$customer_key = $_POST['keys']['customer_key'];
$license_encryption_key = get_parameter('license_encryption_key', '');
$check = db_get_value_sql('SELECT `key` FROM tupdate_settings WHERE `key` LIKE "license_encryption_key"');
if ($check === false) {
db_process_sql_insert(
'tupdate_settings',
[
db_escape_key_identifier('value') => $license_encryption_key,
db_escape_key_identifier('key') => 'license_encryption_key',
]
);
} else {
db_process_sql_update(
'tupdate_settings',
[db_escape_key_identifier('value') => $license_encryption_key],
[db_escape_key_identifier('key') => 'license_encryption_key']
);
}
2022-09-20 11:37:07 +02:00
if (empty($license_encryption_key) === false) {
2022-09-20 11:37:07 +02:00
$customer_key = openssl_blowfish_encrypt_hex($customer_key, io_safe_output($license_encryption_key));
}
2022-03-31 16:52:50 +02:00
// Update the license file.
2022-09-20 11:37:07 +02:00
$result = file_put_contents($config['remote_config'].'/'.LICENSE_FILE, $customer_key);
2022-03-31 16:52:50 +02:00
if ($result === false) {
ui_print_error_message(__('Failed to Update license file'));
}
2019-05-22 18:50:51 +02:00
ui_print_success_message(__('License updated'));
}
}
$license = enterprise_hook('license_get_info');
$rows = db_get_all_rows_in_table('tupdate_settings');
$settings = new StdClass;
foreach ($rows as $row) {
$settings->{$row['key']} = $row['value'];
}
?>
<script type="text/javascript">
var texts = {
error_connecting: '<?php echo __('Error while connecting to licence server.'); ?>',
error_license: '<?php echo __('Invalid response while validating license.'); ?>',
error_unknown: '<?php echo __('Unknown error'); ?>',
}
<?php
if (enterprise_installed()) {
print_js_var_enteprise();
}
?>
</script>
<?php
2023-03-02 12:46:47 +01:00
echo '<form method="post" id="form-license" class="max_floating_element_size">';
2019-05-22 18:50:51 +02:00
// Retrieve UM url configured (or default).
$url = get_um_url();
2015-06-25 10:40:35 +02:00
$table = new stdClass();
2015-06-16 16:09:50 +02:00
$table->width = '100%';
2023-03-02 12:46:47 +01:00
$table->class = 'databox filter-table-adv';
$table->size = [];
$table->size[0] = '50%';
$table->size[1] = '50%';
$table->data = [];
2023-03-02 12:46:47 +01:00
$table->colspan = [];
2023-03-04 13:22:52 +01:00
$table->colspan[-1][0] = 2;
2023-03-02 12:46:47 +01:00
$table->data[-1][0] = '<div class="section_table_title">'.__('Licence').'</div>';
2023-03-02 12:46:47 +01:00
$table->colspan[0][0] = 2;
$table->data[0][0] = html_print_label_input_block(
__('Customer key'),
html_print_textarea(
'keys[customer_key]',
10,
255,
$settings->customer_key,
'style="width: 100%; height:80px;"',
2022-09-20 15:16:56 +02:00
true
2023-03-02 12:46:47 +01:00
)
);
$table->data[1][0] = html_print_label_input_block(
__($license['expiry_caption']),
html_print_input_text(
'expires',
$license['expiry_date'],
'',
10,
255,
true,
true
)
);
$table->data[1][1] = html_print_label_input_block(
__('Platform Limit'),
html_print_input_text(
'expires',
$license['limit'],
2022-09-20 11:37:07 +02:00
'',
10,
255,
true,
2023-03-02 12:46:47 +01:00
true
2023-07-03 13:18:50 +02:00
)
// .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules'))
2023-03-02 12:46:47 +01:00
);
$table->data[2][0] = html_print_label_input_block(
__('Current Platform Count'),
html_print_input_text(
'expires',
$license['count'],
'',
10,
255,
true,
true
2023-07-03 13:18:50 +02:00
)
// .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules'))
2023-03-02 12:46:47 +01:00
);
$table->data[2][1] = html_print_label_input_block(
__('Current Platform Count (enabled: items)'),
html_print_input_text(
'expires',
$license['count_enabled'],
'',
10,
255,
true,
true
2023-07-03 13:18:50 +02:00
)
// .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules'))
2023-03-02 12:46:47 +01:00
);
$table->data[3][0] = html_print_label_input_block(
__('Current Platform Count (disabled: items)'),
html_print_input_text(
'expires',
$license['count_disabled'],
'',
10,
255,
true,
true
2023-07-03 13:18:50 +02:00
)
// .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules'))
2023-03-02 12:46:47 +01:00
);
$table->data[3][1] = html_print_label_input_block(
__('License Mode'),
html_print_input_text(
'expires',
$license['license_mode'],
'',
10,
255,
true,
true
)
);
$table->data[4][0] = html_print_label_input_block(
__('NMS'),
html_print_input_text(
'expires',
($license['nms'] == 1 ? __('enabled') : __('disabled')),
'',
10,
255,
true,
true
)
);
$table->data[4][1] = html_print_label_input_block(
__('Satellite'),
html_print_input_text(
'expires',
($license['dhpm'] == 1 ? __('enabled') : __('disabled')),
'',
10,
255,
true,
true
)
);
$table->data[5][0] = html_print_label_input_block(
__('Licensed to'),
html_print_input_text(
'licensed_to',
$license['licensed_to'],
'',
64,
255,
true,
true
)
);
if ($license['dhpm'] == 1) {
$table->data[5][1] = html_print_label_input_block(
__('License encryption key').'</strong>'.ui_print_help_tip(
__('This key is used to encrypt your Pandora FMS license when it is shared with other Pandora FMS components'),
true
),
html_print_input_password(
'license_encryption_key',
io_safe_output($settings->license_encryption_key),
'',
10,
255,
true,
false
)
2022-09-20 11:37:07 +02:00
);
}
html_print_table($table);
2019-06-18 11:35:59 +02:00
// If DESTDIR is defined the enterprise license is expired.
if (enterprise_installed() || defined('DESTDIR')) {
2023-03-02 12:46:47 +01:00
$buttons = html_print_input_hidden('update_settings', 1, true);
$buttons .= html_print_submit_button(
__('Validate'),
'update_button',
false,
['icon' => 'next'],
true
);
$buttons .= html_print_button(
__('Request new license'),
'license',
false,
'generate_request_code()',
[
'fixed_id' => 'button-',
'icon' => 'next',
'mode' => 'secondary',
],
true
);
2023-07-03 13:18:50 +02:00
$buttons .= html_print_button(
__('Show agent usage details'),
'agents_details',
false,
'show_agents_details_dialog()',
[
'fixed_id' => 'button-agents_details',
'icon' => 'next',
'mode' => 'secondary',
],
true
);
2023-03-02 12:46:47 +01:00
html_print_action_buttons(
$buttons
);
}
2023-03-02 12:46:47 +01:00
echo '</form>';
2019-05-22 18:50:51 +02:00
if (is_metaconsole()) {
ui_require_css_file('pandora_enterprise', ENTERPRISE_DIR.'/include/styles/');
ui_require_css_file('register', 'include/styles/');
2019-05-22 18:50:51 +02:00
} else {
ui_require_css_file('pandora');
ui_require_css_file('pandora_enterprise', ENTERPRISE_DIR.'/include/styles/');
ui_require_css_file('register');
}
if (enterprise_hook('print_activate_licence_dialog') == ENTERPRISE_NOT_HOOK) {
echo '<div id="code_license_dialog" class="invisible left" title="'.__('Request new license').'">';
echo '<div id="logo">';
html_print_image(ui_get_custom_header_logo(true));
echo '</div>';
echo ''.__('To get your <b>%s Enterprise License</b>:', get_product_name()).'<br />';
echo '<ul>';
echo '<li>';
2019-05-22 18:50:51 +02:00
echo ''.sprintf(__('Go to %s'), '<a target="_blank" href="'.$url.'/index.php?section=generate_key_client">'.$url.'index.php?section=generate_key_client</a>');
echo '</li>';
echo '<li>';
echo ''.__('Enter the <b>auth key</b> and the following <b>request key</b>:');
echo '</li>';
echo '</ul>';
echo '<div id="code"></div>';
echo '<ul>';
echo '<li>';
echo ''.__('Enter your name (or a company name) and a contact email address.');
echo '</li>';
echo '<li>';
echo ''.__('Click on <b>Generate</b>.');
echo '</li>';
echo '<li>';
echo ''.__('Click <a href="javascript: close_code_license_dialog();">here</a>, enter the generated license key and click on <b>Validate</b>.');
echo '</li>';
echo '</ul>';
echo '</div>';
}
2023-07-03 13:18:50 +02:00
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filter-table-adv';
$table->size = [];
$table->size[0] = '50%';
$table->size[1] = '50%';
$table->data = [];
$table->colspan = [];
$table->data[0][0] = html_print_label_input_block(
__('Total Agents'),
html_print_input_text(
'total_agents',
$total_agents,
'',
30,
255,
true,
true
)
);
$table->data[0][1] = html_print_label_input_block(
__('Network & other devices'),
html_print_input_text(
'type_network',
$network_others,
'',
30,
255,
true,
true
)
);
$table->data[1][0] = html_print_label_input_block(
__('Workstations'),
html_print_input_text(
'type_workstation',
$workstations,
'',
30,
255,
true,
true
)
);
$table->data[1][1] = html_print_label_input_block(
__('Servers'),
html_print_input_text(
'type_server',
$servers,
'',
30,
255,
true,
true
)
);
$table->data[2][0] = html_print_label_input_block(
__('Show disabled agents'),
html_print_checkbox_switch(
'show_disabled_agents',
1,
1,
true,
false,
'show_disabled_agents()'
)
);
echo '<div id="agents_details_dialog" class="invisible left" title="'.__('Agents usage details').'">';
html_print_table($table);
echo '</div>';