* Portions created by the Initial Developer are Copyright (C) 2008-2024 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Mark J Crane * Tim Fry */ //check permission require_once dirname(__DIR__, 2) . '/resources/require.php'; require_once "resources/check_auth.php"; require_once "resources/paging.php"; require_once __DIR__ . '/resources/functions.php'; if (permission_exists('maintenance_view')) { // permission granted } else { die('Unauthorized'); } if (!empty($_REQUEST['search'])) { $search = urldecode($_REQUEST['search']); } else { $search = ''; } //set the domain and user $domain_uuid = $_SESSION['domain_uuid'] ?? ''; $user_uuid = $_SESSION['user_uuid'] ?? ''; //internationalization $language = new text; $text = $language->get(); //create a database object $database = database::new(); //process registering maintenance applications if (!empty($_REQUEST['action'])) { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'], 'negative'); header('Location: maintenance.php'); exit; } $action = $_REQUEST['action']; $checked_apps = $_REQUEST['maintenance_apps'] ?? []; switch($action) { case 'toggle': if (permission_exists('maintenance_edit')) { if (maintenance::register_applications($database, $checked_apps)) { message::add($text['message-toggle']); } else { message::add($text['message-register_failed'], 'negative'); } } else { message::add($text['message-action_prohibited'], 'negative'); } break; } $toggle_maintenance_apps = $_REQUEST['toggle']; unset($token); } //create a boolean value to represent if show_all is enabled $show_all = !empty($_REQUEST['show']) && $_REQUEST['show'] === 'all' && permission_exists('maintenance_show_all'); //order by if (!empty($_REQUEST['order_by'])) { $order_by = $_REQUEST['order_by']; } else { $order_by = ''; } //paging $rows_per_page = $_SESSION['domain']['paging']['numeric'] ?? 50; if (!empty($_REQUEST['page'])) { $page = $_REQUEST['page']; $offset = $rows_per_page * $page; } else { $page = ''; } //load the global settings only $default_settings = new settings(['database' => $database]); //get the list in the default settings $classes = $default_settings->get('maintenance', 'application', []); //get the display array $maintenance_apps = []; if ($show_all) { //get a list of domain names $domains = maintenance::get_domains($database); //get maintainers foreach ($classes as $maintainer) { $tasks = ['database', 'filesystem']; foreach ($tasks as $task) { $has_task = "has_{$task}_maintenance"; if (maintenance::$has_task($maintainer)) { $category_method = "get_{$task}_category"; $subcategory_method = "get_{$task}_subcategory"; $category = maintenance::$category_method($maintainer); $subcategory = maintenance::$subcategory_method($maintainer); //get all UUIDs in the database associated with this setting $uuids = maintenance::find_all_uuids($database, $category, $subcategory); foreach ($uuids as $match) { $uuid = $match['uuid']; $status = $match['status']; $table = $match['table']; $domain_uuid = $match['domain_uuid'] ?? 'global'; $value = $match['value']; $maintenance_apps[$category]["{$task}_maintenance"][$domain_uuid]["{$table}_setting_enabled"] = $match['status']; $maintenance_apps[$category]["{$task}_maintenance"][$domain_uuid]["{$table}_setting_value"] = $value; $maintenance_apps[$category]["{$task}_maintenance"][$domain_uuid]["{$table}_setting_uuid"] = $uuid; } } } } } else { //use the settings object to get the maintenance apps and their values foreach ($classes as $maintainer) { $domain_settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'] ?? $domain_uuid]); //database retention days $database_retention_days = maintenance::get_database_retention_days($domain_settings, $maintainer); if (!empty($database_retention_days)) { $category = maintenance::get_database_category($maintainer); $maintenance_apps[$category]['database_maintenance'][$domain_uuid]['domain_setting_value'] = $database_retention_days; $maintenance_apps[$category]['database_maintenance'][$domain_uuid]['domain_setting_enabled'] = 'true'; } //filesystem retention days $filesystem_retention_days = maintenance::get_filesystem_retention_days($domain_settings, $maintainer); if (!empty($filesystem_retention_days)) { $category = maintenance::get_filesystem_category($maintainer); $maintenance_apps[$category]['filesystem_maintenance'][$domain_uuid]['domain_setting_value'] = $filesystem_retention_days; $maintenance_apps[$category]['filesystem_maintenance'][$domain_uuid]['domain_setting_enabled'] = 'true'; } } } //sort the result ksort($maintenance_apps); //set URL parameters $url_params = ''; if ($show_all) { $url_params = '?show=all'; } if (!empty($page)) { $url_params .= (empty($url_params) ? '?' : '&') . 'page=' . $page; } if (!empty($search)) { $url_params .= (empty($url_params) ? '?' : '&') . 'search=' . urlencode($search); } //get the list of domains $domain_names = maintenance::get_domains($database); //create the token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //show the content require_once dirname(__DIR__, 2) . '/resources/header.php'; $document['title'] = $text['title-maintenance']; echo "
"; echo "
Maintenance
"; echo "
"; echo button::create(['type'=>'button','label'=>$text['button-logs'],'icon'=>'fas fa-scroll fa-fw','id'=>'btn_logs', 'link'=>'maintenance_logs.php']); //show all if (!$show_all) { echo button::create(['type'=>'button','alt'=>$text['button-show_all']??'Show All','label'=>$text['button-show_all']??'Show All','class'=>'btn btn-default','icon'=>$_SESSION['theme']['button_icon_all']??'globe','link'=>(empty($url_params) ? '?show=all' : $url_params . '&show=all')]); } //search form echo " "; echo "
"; //javascript modal boxes echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=> button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=> button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=> button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); echo "
"; echo "

"; echo "
"; echo " "; echo " "; echo "
\n"; echo " "; echo " "; echo " "; if ($show_all) { echo " "; } echo " "; echo " "; echo " "; echo " "; echo " "; //list all maintenance applications from the defaults settings for global and each domain and show if they are enabled or disabled foreach ($maintenance_apps as $class => $app_settings) { //make the class name more user-friendly if ($class === 'cdr') { $display_name = strtoupper(str_replace('_', ' ', $class)); } else { $display_name = ucwords(str_replace('_', ' ', $class)); } //display global first if ((isset($app_settings['database_maintenance']['global']) || isset($app_settings['filesystem_maintenance']['global'])) && $show_all) { echo ""; echo " "; echo " "; if (isset($app_settings['database_maintenance']['global'])) { $enabled = $app_settings['database_maintenance']['global']['default_setting_enabled'] ? $text['label-yes'] : $text['label-no']; $value = $app_settings['database_maintenance']['global']['default_setting_value']; echo ""; echo ""; } else { echo ""; echo ""; } if (isset($app_settings['filesystem_maintenance']['global'])) { $enabled = $app_settings['filesystem_maintenance']['global']['default_setting_enabled'] ? $text['label-yes'] : $text['label-no']; $value = $app_settings['filesystem_maintenance']['global']['default_setting_value']; echo ""; echo ""; } else { echo ""; echo ""; } echo ""; } if (isset($app_settings['database_maintenance']) || isset($app_settings['filesystem_maintenance'])) { //get all domains with database traits $database_domain_uuids = array_keys($app_settings['database_maintenance'] ?? []); //get all domains with filesystem traits $filesystem_domain_uuids = array_keys($app_settings['filesystem_maintenance'] ?? []); //combine database and filesystem domain_uuids without duplicates $domain_uuids = $database_domain_uuids + $filesystem_domain_uuids; //loop through domains that have the database and filesystem traits foreach ($domain_uuids as $domain_uuid) { //skip global it has already been done if ($domain_uuid === 'global') { continue; } echo ""; echo " "; if ($show_all) { echo ""; } if (isset($app_settings['database_maintenance'][$domain_uuid])) { $enabled = $app_settings['database_maintenance'][$domain_uuid]['domain_setting_enabled'] ? $text['label-yes'] : $text['label-no']; $value = $app_settings['database_maintenance'][$domain_uuid]['domain_setting_value']; echo ""; echo ""; } else { echo ""; echo ""; } if (isset($app_settings['filesystem_maintenance'][$domain_uuid])) { $enabled = $app_settings['filesystem_maintenance'][$domain_uuid]['domain_setting_enabled'] ? $text['label-yes'] : $text['label-no']; $value = $app_settings['filesystem_maintenance'][$domain_uuid]['domain_setting_value']; echo ""; echo ""; } else { echo ""; echo ""; } echo ""; } } } echo "
NameDomainDatabase EnabledRetention DaysFile System EnabledRetention Days
$display_name".$text['label-global']."$enabled$value  $enabled$value  
$display_name".$domain_names[$domain_uuid]."$enabled$value  $enabled$value  
"; echo "
"; echo " "; echo "
"; echo "
"; //include the footer require_once dirname(__DIR__, 2) . '/resources/footer.php';