= $config['license_expiry_date']) { return true; } return false; } /** * Parses responses from configuration wizard. * * @return void */ function config_wiz_process() { global $config; $email = get_parameter('email', false); $timezone = get_parameter('timezone', false); $language = get_parameter('language', false); if ($email !== false) { config_update_value('language', $language); } if ($timezone !== false) { config_update_value('timezone', $timezone); } if ($email !== false) { db_process_sql_update( 'tusuario', ['email' => $email], ['id_user' => $config['id_user']] ); } // Update the alert action Mail to XXX/Administrator // if it is set to default. $mail_check = 'yourmail@domain.es'; $mail_alert = alerts_get_alert_action_field1(1); if ($mail_check === $mail_alert && $email !== false) { alerts_update_alert_action( 1, [ 'field1' => $email, 'field1_recovery' => $email, ] ); } config_update_value('initial_wizard', 1); } /** * Generates base code to print main configuration modal. * * Asks for timezone, mail. * * @param boolean $return Print output or not. * @param boolean $launch Process JS modal. * @param string $callback Call to JS function at end. * * @return string HTML. */ function config_wiz_modal( $return=false, $launch=true, $callback=false ) { global $config; $email = db_get_value('email', 'tusuario', 'id_user', $config['id_user']); // Avoid to show default email. if ($email == 'admin@example.com') { $email = ''; } $output = ''; // Prints first step pandora registration. $output .= '
'; $output .= __('You could change this options later in "alert actions" and setting your account.'); $output .= '
'; $output .= ''; $output .= __('When you subscribe to the %s Update Manager service, you accept that we register your %s instance as an identifier on a database owned by %s. This data will solely be used to provide you with information about %s and will not be conceded to third parties. You can unregister from said database at any time from the Update Manager options.', $product_name, $product_name, $product_name, $product_name); $output .= '
'; $output .= ''; $output .= __('You will need to update your system manually, through source code or RPM packages to be up to date with latest updates.'); $output .= '
'; $output .= '%s
%s
', __('Stay up to date with updates, upgrades and promotions by subscribing to our newsletter.'), __( 'By subscribing to the newsletter, you accept that your email will be transferred to a database owned by %s. These data will be used only to provide you with information about %s and will not be given to third parties. You can unsubscribe from this database at any time from the newsletter subscription options.', $product_name, $product_name ) ), ], true ); // Email Input case. $emailInputCase = ' '.html_print_input_text_extended( 'email-newsletter', $email, 'text-email-newsletter', '', 30, 255, false, '', ['style' => 'display: inline-block; width: 200px;'], true ); // Generate the submit buttons. // Cancel Button. $submitButtons = html_print_div( [ 'class' => 'left', 'content' => html_print_submit_button( __('Cancel'), 'cancel_newsletter', false, 'class="ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel w100px"', true ), ], true ); // OK Button. $submitButtons .= html_print_div( [ 'class' => 'right', 'content' => html_print_submit_button( __('OK!'), 'newsletter', false, 'class="ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next w100px"', true ), ], true ); $submitButtonsCase = html_print_div( [ 'class' => 'submit_buttons_container', 'content' => $submitButtons, ], true ); $modalContent .= html_print_div( [ 'class' => 'mrgn_lft_4em', 'content' => html_print_div( [ 'id' => 'box_newsletter', 'content' => $emailInputCase.$submitButtonsCase.''.__('You will miss all news about amazing features and fixes!').'
', ], true ); $output .= html_print_div( [ 'id' => 'news_ensure_cancel', 'style' => 'display: none;', 'title' => 'Confirmation Required', 'content' => $verificationContent, ], true ); // Results modal. $resultsContent = html_print_div( [ 'id' => 'news_result_content', 'class' => 'font_12_20', ], true ); $output .= html_print_div( [ 'id' => 'news_result', 'style' => 'display: none;', 'title' => 'Subscription process result', 'content' => $resultsContent, ], true ); ob_start(); ?> $license, 'current_update' => update_manager_get_current_package(), 'limit_count' => $limit_count, 'build' => $build_version, 'version' => $pandora_version, 'puid' => $config['pandora_uid'], ]; } /** * Function to remove dir and files inside. * * @param string $dir Path to dir. * * @return void */ function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != '.' && $object != '..') { if (filetype($dir.'/'.$object) == 'dir') { rrmdir($dir.'/'.$object); } else { unlink($dir.'/'.$object); } } } reset($objects); rmdir($dir); } else { unlink($dir); } } /** * Install updates step2. * * @return void */ function update_manager_install_package_step2() { global $config; ob_clean(); $package = (string) get_parameter('package'); $package = trim($package); $version = (string) get_parameter('version', 0); $path = sys_get_temp_dir().'/pandora_oum/'.$package; // All files extracted. $files_total = $path.'/files.txt'; // Files copied. $files_copied = $path.'/files.copied.txt'; $return = []; if (file_exists($files_copied)) { unlink($files_copied); } if (file_exists($path)) { $files_h = fopen($files_total, 'r'); if ($files_h === false) { $return['status'] = 'error'; $return['message'] = __('An error ocurred while reading a file.'); echo json_encode($return); return; } while ($line = stream_get_line($files_h, 65535, "\n")) { $line = trim($line); // Tries to move the old file to the directory backup // inside the extracted package. if (file_exists($config['homedir'].'/'.$line)) { rename($config['homedir'].'/'.$line, $path.'/backup/'.$line); } // Tries to move the new file to the Integria directory. $dirname = dirname($line); if (!file_exists($config['homedir'].'/'.$dirname)) { $dir_array = explode('/', $dirname); $temp_dir = ''; foreach ($dir_array as $dir) { $temp_dir .= '/'.$dir; if (!file_exists($config['homedir'].$temp_dir)) { mkdir($config['homedir'].$temp_dir); } } } if (is_dir($path.'/'.$line)) { if (!file_exists($config['homedir'].'/'.$line)) { mkdir($config['homedir'].'/'.$line); file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX)); } } else { // Copy the new file. if (rename($path.'/'.$line, $config['homedir'].'/'.$line)) { // Append the moved file to the copied files txt. if (!file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX))) { // If the copy process fail, this code tries to // restore the files backed up before. $files_copied_h = fopen($files_copied, 'r'); if ($files_copied_h === false) { $backup_status = __('Some of your old files might not be recovered.'); } else { while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) { $line_c = trim($line_c); if (!rename($path.'/backup/'.$line, $config['homedir'].'/'.$line_c)) { $backup_status = __('Some of your files might not be recovered.'); } } if (!rename($path.'/backup/'.$line, $config['homedir'].'/'.$line)) { $backup_status = __('Some of your files might not be recovered.'); } fclose($files_copied_h); } fclose($files_h); $return['status'] = 'error'; $return['message'] = __( 'Line "%s" not copied to the progress file.', $line ).' '.$backup_status; echo json_encode($return); return; } } else { // If the copy process fail, this code tries to restore // the files backed up before. $files_copied_h = fopen($files_copied, 'r'); if ($files_copied_h === false) { $backup_status = __('Some of your files might not be recovered.'); } else { while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) { $line_c = trim($line_c); if (!rename( $path.'/backup/'.$line, $config['homedir'].'/'.$line ) ) { $backup_status = __('Some of your old files might not be recovered.'); } } fclose($files_copied_h); } fclose($files_h); $return['status'] = 'error'; $return['message'] = __( 'Line "%s" not copied to the progress file.', $line ).' '.$backup_status; echo json_encode($return); return; } } } fclose($files_h); } else { $return['status'] = 'error'; $return['message'] = __('The package does not exist'); echo json_encode($return); return; } update_manager_enterprise_set_version($version); $product_name = io_safe_output(get_product_name()); // Generate audit entry. db_pandora_audit( 'Update '.$product_name, 'Update version: '.$version.' of '.$product_name.' by '.$config['id_user'] ); $return['status'] = 'success'; $return['message'] = __('The package is installed.'); echo json_encode($return); } /** * Launch update manager client. * * @return void */ function update_manager_main() { global $config; ?> 'newest_package', 'license' => $um_config_values['license'], 'limit_count' => $um_config_values['limit_count'], 'current_package' => $um_config_values['current_update'], 'version' => $um_config_values['version'], 'build' => $um_config_values['build'], 'puid' => $um_config_values['puid'], ]; $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, get_um_url().'server.php'); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_POST, true); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curlObj, CURLOPT_CONNECTTIMEOUT, 4); if (isset($config['update_manager_proxy_server'])) { curl_setopt($curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server']); } if (isset($config['update_manager_proxy_port'])) { curl_setopt($curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port']); } if (isset($config['update_manager_proxy_user'])) { curl_setopt($curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'].':'.$config['update_manager_proxy_password']); } $result = curl_exec($curlObj); $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); curl_close($curlObj); if ($result === false) { return false; } else if ($http_status >= 400 && $http_status < 500) { return false; } else if ($http_status >= 500) { return false; } else { $result = json_decode($result, true); if (empty($result)) { return false; } else { return true; } } } /** * Update process, online packages. * * @param boolean $is_ajax Is ajax call o direct call. * * @return string HTML update message. */ function update_manager_check_online_free_packages($is_ajax=true) { global $config; $update_message = ''; $um_config_values = update_manager_get_config_values(); $params = [ 'action' => 'newest_package', 'license' => $um_config_values['license'], 'limit_count' => $um_config_values['limit_count'], 'current_package' => $um_config_values['current_update'], 'version' => $um_config_values['version'], 'build' => $um_config_values['build'], 'puid' => $um_config_values['puid'], ]; /* * To test using shell execute: * wget https://artica.es/pandoraupdate7/server.php -O- \ * --no-check-certificate --post-data \ * "action=newest_package&license=PANDORA_FREE&limit_count=1¤t_package=1&version=v5.1RC1&build=PC140625" */ $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, get_um_url().'server.php'); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_POST, true); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); if (isset($config['update_manager_proxy_server'])) { curl_setopt( $curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server'] ); } if (isset($config['update_manager_proxy_port'])) { curl_setopt( $curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port'] ); } if (isset($config['update_manager_proxy_user'])) { curl_setopt( $curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'].':'.$config['update_manager_proxy_password'] ); } $result = curl_exec($curlObj); $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); curl_close($curlObj); if ($result === false) { if ($is_ajax) { echo __('Could not connect to internet'); } else { $update_message = __('Could not connect to internet'); } } else if ($http_status >= 400 && $http_status < 500) { if ($is_ajax) { echo __('Server not found.'); } else { $update_message = __('Server not found.'); } } else if ($http_status >= 500) { if ($is_ajax) { echo $result; } else { $update_message = $result; } } else { if ($is_ajax) { $result = json_decode($result, true); if (!empty($result)) { ?> There is a new version: '.$result[0]['version'].''; echo "".__('Update').''; } else { echo __('There is no update available.'); } return $update_message; } else { if (!empty($result)) { $result = json_decode($result, true); $update_message = 'There is a new version: '.$result[0]['version']; } return $update_message; } } } /** * Executes an action against UpdateManager. * * @param string $action Action to perform. * @param boolean $additional_params Extra parameters (optional). * * @return array With UM response. */ function update_manager_curl_request($action, $additional_params=false) { global $config; $error_array = [ 'success' => true, 'update_message' => '', ]; $update_message = ''; $um_config_values = update_manager_get_config_values(); $params = [ 'license' => $um_config_values['license'], 'limit_count' => $um_config_values['limit_count'], 'current_package' => $um_config_values['current_update'], 'version' => $um_config_values['version'], 'build' => $um_config_values['build'], 'puid' => $um_config_values['puid'], ]; if ($additional_params !== false) { $params = array_merge($params, $additional_params); } $params['action'] = $action; $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, get_um_url().'server.php'); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_POST, true); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); if (isset($config['update_manager_proxy_server'])) { curl_setopt($curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server']); } if (isset($config['update_manager_proxy_port'])) { curl_setopt($curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port']); } if (isset($config['update_manager_proxy_user'])) { curl_setopt($curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'].':'.$config['update_manager_proxy_password']); } $result = curl_exec($curlObj); $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); curl_close($curlObj); $error_array['http_status'] = $http_status; if ($result === false) { $error_array['success'] = false; if ($is_ajax) { echo __('Could not connect to internet'); return $error_array; } else { $error_array['update_message'] = __('Could not connect to internet'); return $error_array; } } else if ($http_status >= 400 && $http_status < 500) { $error_array['success'] = false; if ($is_ajax) { echo __('Server not found.'); return $error_array; } else { $error_array['update_message'] = __('Server not found.'); return $error_array; } } else if ($http_status >= 500) { $error_array['success'] = false; if ($is_ajax) { echo $result; return $error_array; } else { $error_array['update_message'] = $result; return $error_array; } } $error_array['update_message'] = $result; return $error_array; } /** * Subscribes an email account into newsletter. * * @param string $email E-mail. * * @return array With success [true/false], message [string]. */ function update_manager_insert_newsletter($email) { global $config; if ($email === '') { return false; } $params = [ 'email' => $email, 'language' => $config['language'], 'license' => db_get_value_filter( 'value', 'tupdate_settings', ['key' => 'customer_key'] ), ]; $result = update_manager_curl_request('new_newsletter', $params); if (!$result['success']) { return [ 'success' => false, 'message' => __('Remote server error on newsletter request'), ]; } switch ($result['http_status']) { case 200: $message = json_decode($result['update_message'], true); if ($message['success'] == 1) { return [ 'success' => true, 'message' => __('E-mail successfully subscribed to newsletter.'), ]; } else { return [ 'success' => true, 'message' => __('E-mail has already subscribed to newsletter.'), ]; } default: return [ 'success' => false, 'message' => __('Update manager returns error code: ').$result['http_status'].'.', ]; } } /** * Registers this console into UpdateManager. * * @return array With success [true/false], message [string]. */ function update_manager_register_instance() { global $config; $email = db_get_value('email', 'tusuario', 'id_user', $config['id_user']); $um_config_values = update_manager_get_config_values(); $params = [ 'action' => 'newest_package', 'license' => $um_config_values['license'], 'limit_count' => $um_config_values['limit_count'], 'current_package' => $um_config_values['current_update'], 'version' => $um_config_values['version'], 'build' => $um_config_values['build'], 'puid' => $um_config_values['puid'], 'email' => $email, 'language' => $config['language'], 'timezone' => $config['timezone'], ]; $result = update_manager_curl_request('new_register', $params); if (!$result['success']) { return [ 'success' => false, 'message' => __('Error while registering console.').'