X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fadmin.php;h=730d21984d0f7c90fd816f91b0f2bb6addd39a93;hb=0e01568ccd5b5ce081eff83e2ed0b888e0b6db55;hp=fae20f79bd9635238ff8708d4ae1f0bb2c943e2d;hpb=55c10a3fc9e53d9d283e941c8217feaf5dc079fa;p=friendica.git diff --git a/mod/admin.php b/mod/admin.php index fae20f79bd..730d21984d 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -6,22 +6,31 @@ */ use Friendica\App; +use Friendica\BaseModule; use Friendica\Content\Feature; +use Friendica\Content\Pager; use Friendica\Content\Text\Markdown; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\Logger; +use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Theme; +use Friendica\Core\Update; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\Login; use Friendica\Module\Tos; +use Friendica\Util\Arrays; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Network; +use Friendica\Util\Strings; use Friendica\Util\Temporal; require_once 'include/enotify.php'; @@ -31,11 +40,11 @@ require_once 'include/items.php'; /** * @brief Process send data from the admin panels subpages * - * This function acts as relais for processing the data send from the subpages + * This function acts as relay for processing the data send from the subpages * of the admin panel. Depending on the 1st parameter of the url (argv[1]) * specialized functions are called to process the data from the subpages. * - * The function itself does not return anything, but the subsequencely function + * The function itself does not return anything, but the subsequently function * return the HTML for the pages of the admin panel. * * @param App $a @@ -75,16 +84,16 @@ function admin_post(App $a) break; case 'themes': if ($a->argc < 2) { - if (is_ajax()) { + if ($a->isAjax()) { return; } - goaway('admin/'); + $a->internalRedirect('admin/'); return; } $theme = $a->argv[2]; if (is_file("view/theme/$theme/config.php")) { - $orig_theme = $a->theme; + $orig_theme = Renderer::$theme; $orig_page = $a->page; $orig_session_theme = $_SESSION['theme']; require_once "view/theme/$theme/theme.php"; @@ -100,12 +109,12 @@ function admin_post(App $a) } $_SESSION['theme'] = $orig_session_theme; - $a->theme = $orig_theme; + Renderer::$theme = $orig_theme; $a->page = $orig_page; } info(L10n::t('Theme settings updated.')); - if (is_ajax()) { + if ($a->isAjax()) { return; } $return_path = 'admin/themes/' . $theme; @@ -131,7 +140,7 @@ function admin_post(App $a) } } - goaway($return_path); + $a->internalRedirect($return_path); return; // NOTREACHED } @@ -168,7 +177,7 @@ function admin_content(App $a) // apc_delete($toDelete); //} // Header stuff - $a->page['htmlhead'] .= replace_macros(get_markup_template('admin/settings_head.tpl'), []); + $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []); /* * Side bar links @@ -177,32 +186,33 @@ function admin_content(App $a) // array(url, name, extra css classes) // not part of $aside to make the template more adjustable $aside_sub = [ - 'information' => [ L10n::t('Information'), [ - "overview" => ["admin/", L10n::t("Overview"), "overview" ], - 'federation' => ["admin/federation/" , L10n::t('Federation Statistics'), "federation"] ]], - 'configuration' => [ L10n::t('Configuration'), [ - 'site' => ["admin/site/" , L10n::t("Site") , "site"], - 'users' => ["admin/users/" , L10n::t("Users") , "users"], - 'addons' => ["admin/addons/" , L10n::t("Addons") , "addons"], - 'themes' => ["admin/themes/" , L10n::t("Themes") , "themes"], - 'features' => ["admin/features/" , L10n::t("Additional features") , "features"], - 'tos' => ["admin/tos/" , L10n::t("Terms of Service") , "tos"] ]], - 'database' => [ L10n::t('Database'), [ - 'dbsync' => ["admin/dbsync/" , L10n::t('DB updates') , "dbsync"], - 'queue' => ["admin/queue/" , L10n::t('Inspect Queue') , "queue"], - 'workerqueue' => ["admin/workerqueue/" , L10n::t('Inspect worker Queue') , "workerqueue"] ]], - 'tools' => [ L10n::t('Tools'), [ - 'contactblock' => ["admin/contactblock/", L10n::t('Contact Blocklist') , "contactblock"], - 'blocklist' => ["admin/blocklist/" , L10n::t('Server Blocklist') , "blocklist"], - 'deleteitem' => ["admin/deleteitem/" , L10n::t('Delete Item') , 'deleteitem'], ]], - "logs" => [ L10n::t("Logs"), [ - "logsconfig" => ["admin/logs/", L10n::t("Logs"), "logs"], - "logsview" => ["admin/viewlogs/", L10n::t("View Logs"), 'viewlogs'] + 'information' => [L10n::t('Information'), [ + 'overview' => ['admin/', L10n::t('Overview'), 'overview'], + 'federation' => ['admin/federation/' , L10n::t('Federation Statistics'), 'federation']]], + 'configuration' => [L10n::t('Configuration'), [ + 'site' => ['admin/site/' , L10n::t('Site') , 'site'], + 'users' => ['admin/users/' , L10n::t('Users') , 'users'], + 'addons' => ['admin/addons/' , L10n::t('Addons') , 'addons'], + 'themes' => ['admin/themes/' , L10n::t('Themes') , 'themes'], + 'features' => ['admin/features/' , L10n::t('Additional features') , 'features'], + 'tos' => ['admin/tos/' , L10n::t('Terms of Service') , 'tos']]], + 'database' => [L10n::t('Database'), [ + 'dbsync' => ['admin/dbsync/' , L10n::t('DB updates') , 'dbsync'], + 'queue' => ['admin/queue/' , L10n::t('Inspect Queue') , 'queue'], + 'deferred' => ['admin/deferred/' , L10n::t('Inspect Deferred Workers'), 'deferred'], + 'workerqueue' => ['admin/workerqueue/' , L10n::t('Inspect worker Queue') , 'workerqueue']]], + 'tools' => [L10n::t('Tools'), [ + 'contactblock' => ['admin/contactblock/', L10n::t('Contact Blocklist') , 'contactblock'], + 'blocklist' => ['admin/blocklist/' , L10n::t('Server Blocklist') , 'blocklist'], + 'deleteitem' => ['admin/deleteitem/' , L10n::t('Delete Item') , 'deleteitem'],]], + 'logs' => [L10n::t('Logs'), [ + 'logsconfig' => ['admin/logs/', L10n::t('Logs'), 'logs'], + 'logsview' => ['admin/viewlogs/', L10n::t('View Logs'), 'viewlogs'] ]], - "diagnostics" => [ L10n::t("Diagnostics"), [ - "phpinfo" => ['phpinfo/', L10n::t('PHP Info'), 'phpinfo'], - "probe" => ['probe/', L10n::t('probe address'), 'probe'], - "webfinger" =>['webfinger/', L10n::t('check webfinger'), 'webfinger'] + 'diagnostics' => [L10n::t('Diagnostics'), [ + 'phpinfo' => ['phpinfo/', L10n::t('PHP Info'), 'phpinfo'], + 'probe' => ['probe/', L10n::t('probe address'), 'probe'], + 'webfinger' =>['webfinger/', L10n::t('check webfinger'), 'webfinger'] ]] ]; @@ -210,15 +220,16 @@ function admin_content(App $a) $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`"); $aside_tools['addons_admin'] = []; + $addons_admin = []; foreach ($r as $h) { $addon = $h['name']; $aside_tools['addons_admin'][] = ["admin/addons/" . $addon, $addon, "addon"]; // temp addons with admin - $a->addons_admin[] = $addon; + $addons_admin[] = $addon; } - $t = get_markup_template('admin/aside.tpl'); - $a->page['aside'] .= replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/aside.tpl'); + $a->page['aside'] .= Renderer::replaceMacros($t, [ '$admin' => $aside_tools, '$subpages' => $aside_sub, '$admtxt' => L10n::t('Admin'), @@ -239,7 +250,7 @@ function admin_content(App $a) $o = admin_page_users($a); break; case 'addons': - $o = admin_page_addons($a); + $o = admin_page_addons($a, $addons_admin); break; case 'themes': $o = admin_page_themes($a); @@ -259,8 +270,11 @@ function admin_content(App $a) case 'queue': $o = admin_page_queue($a); break; + case 'deferred': + $o = admin_page_workerqueue($a, true); + break; case 'workerqueue': - $o = admin_page_workerqueue($a); + $o = admin_page_workerqueue($a, false); break; case 'federation': $o = admin_page_federation($a); @@ -284,7 +298,7 @@ function admin_content(App $a) $o = admin_page_summary($a); } - if (is_ajax()) { + if ($a->isAjax()) { echo $o; killme(); return ''; @@ -302,8 +316,8 @@ function admin_content(App $a) function admin_page_tos(App $a) { $tos = new Tos(); - $t = get_markup_template('admin/tos.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/tos.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Terms of Service'), '$displaytos' => ['displaytos', L10n::t('Display Terms of Service'), Config::get('system', 'tosdisplay'), L10n::t('Enable the Terms of Service page. If this is enabled a link to the terms will be added to the registration form and the general information page.')], @@ -311,7 +325,7 @@ function admin_page_tos(App $a) '$preview' => L10n::t('Privacy Statement Preview'), '$privtext' => $tos->privacy_complete, '$tostext' => ['tostext', L10n::t('The Terms of Service'), Config::get('system', 'tostext'), L10n::t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')], - '$form_security_token' => get_form_security_token("admin_tos"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_tos"), '$submit' => L10n::t('Save Settings'), ]); } @@ -322,7 +336,7 @@ function admin_page_tos(App $a) */ function admin_page_tos_post(App $a) { - check_form_security_token_redirectOnErr('/admin/tos', 'admin_tos'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos'); if (!x($_POST, "page_tos")) { return; @@ -336,7 +350,7 @@ function admin_page_tos_post(App $a) Config::set('system', 'tosprivstatement', $displayprivstatement); Config::set('system', 'tostext', $tostext); - goaway('admin/tos'); + $a->internalRedirect('admin/tos'); return; // NOTREACHED } @@ -364,8 +378,8 @@ function admin_page_blocklist(App $a) ]; } } - $t = get_markup_template('admin/blocklist.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/blocklist.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Server Blocklist'), '$intro' => L10n::t('This page can be used to define a black list of servers from the federated network that are not allowed to interact with your node. For all entered domains you should also give a reason why you have blocked the remote server.'), @@ -382,7 +396,7 @@ function admin_page_blocklist(App $a) '$entries' => $blocklistform, '$baseurl' => System::baseUrl(true), '$confirm_delete' => L10n::t('Delete entry from blocklist?'), - '$form_security_token' => get_form_security_token("admin_blocklist") + '$form_security_token' => BaseModule::getFormSecurityToken("admin_blocklist") ]); } @@ -397,14 +411,14 @@ function admin_page_blocklist_post(App $a) return; } - check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/blocklist', 'admin_blocklist'); if (x($_POST['page_blocklist_save'])) { // Add new item to blocklist $blocklist = Config::get('system', 'blocklist'); $blocklist[] = [ - 'domain' => notags(trim($_POST['newentry_domain'])), - 'reason' => notags(trim($_POST['newentry_reason'])) + 'domain' => Strings::removeTags(trim($_POST['newentry_domain'])), + 'reason' => Strings::removeTags(trim($_POST['newentry_reason'])) ]; Config::set('system', 'blocklist', $blocklist); info(L10n::t('Server added to blocklist.') . EOL); @@ -413,8 +427,8 @@ function admin_page_blocklist_post(App $a) $blocklist = []; foreach ($_POST['domain'] as $id => $domain) { // Trimming whitespaces as well as any lingering slashes - $domain = notags(trim($domain, "\x00..\x1F/")); - $reason = notags(trim($_POST['reason'][$id])); + $domain = Strings::removeTags(trim($domain, "\x00..\x1F/")); + $reason = Strings::removeTags(trim($_POST['reason'][$id])); if (!x($_POST['delete'][$id])) { $blocklist[] = [ 'domain' => $domain, @@ -425,7 +439,7 @@ function admin_page_blocklist_post(App $a) Config::set('system', 'blocklist', $blocklist); info(L10n::t('Site blocklist updated.') . EOL); } - goaway('admin/blocklist'); + $a->internalRedirect('admin/blocklist'); return; // NOTREACHED } @@ -440,7 +454,7 @@ function admin_page_contactblock_post(App $a) $contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : ''; $contacts = x($_POST, 'contacts') ? $_POST['contacts'] : []; - check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/contactblock', 'admin_contactblock'); if (x($_POST, 'page_contactblock_block')) { $contact_id = Contact::getIdForURL($contact_url); @@ -457,7 +471,7 @@ function admin_page_contactblock_post(App $a) } notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts))); } - goaway('admin/contactblock'); + $a->internalRedirect('admin/contactblock'); return; // NOTREACHED } @@ -473,15 +487,14 @@ function admin_page_contactblock(App $a) $total = DBA::count('contact', $condition); - $a->set_pager_total($total); - $a->set_pager_itemspage(30); + $pager = new Pager($a->query_string, 30); - $statement = DBA::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]); + $statement = DBA::select('contact', [], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); $contacts = DBA::toArray($statement); - $t = get_markup_template('admin/contactblock.tpl'); - $o = replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/contactblock.tpl'); + $o = Renderer::replaceMacros($t, [ // strings // '$title' => L10n::t('Administration'), '$page' => L10n::t('Remote Contact Blocklist'), @@ -497,14 +510,14 @@ function admin_page_contactblock(App $a) '$h_newblock' => L10n::t('Block New Remote Contact'), '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')], - '$form_security_token' => get_form_security_token("admin_contactblock"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_contactblock"), // values // '$baseurl' => System::baseUrl(true), '$contacts' => $contacts, '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), - '$paginate' => paginate($a), + '$paginate' => $pager->renderFull($total), '$contacturl' => ['contact_url', L10n::t("Profile URL"), '', L10n::t("URL of the remote contact to block.")], ]); return $o; @@ -522,9 +535,9 @@ function admin_page_contactblock(App $a) */ function admin_page_deleteitem(App $a) { - $t = get_markup_template('admin/deleteitem.tpl'); + $t = Renderer::getMarkupTemplate('admin/deleteitem.tpl'); - return replace_macros($t, [ + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Delete Item'), '$submit' => L10n::t('Delete this Item'), @@ -532,7 +545,7 @@ function admin_page_deleteitem(App $a) '$intro2' => L10n::t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'), '$deleteitemguid' => ['deleteitemguid', L10n::t("GUID"), '', L10n::t("The GUID of the item you want to delete."), 'required', 'autofocus'], '$baseurl' => System::baseUrl(), - '$form_security_token' => get_form_security_token("admin_deleteitem") + '$form_security_token' => BaseModule::getFormSecurityToken("admin_deleteitem") ]); } @@ -550,10 +563,10 @@ function admin_page_deleteitem_post(App $a) return; } - check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/deleteitem/', 'admin_deleteitem'); if (x($_POST['page_deleteitem_submit'])) { - $guid = trim(notags($_POST['deleteitemguid'])); + $guid = trim(Strings::removeTags($_POST['deleteitemguid'])); // The GUID should not include a "/", so if there is one, we got an URL // and the last part of it is most likely the GUID. if (strpos($guid, '/')) { @@ -565,7 +578,7 @@ function admin_page_deleteitem_post(App $a) } info(L10n::t('Item marked for deletion.') . EOL); - goaway('admin/deleteitem'); + $a->internalRedirect('admin/deleteitem'); return; // NOTREACHED } @@ -715,8 +728,8 @@ function admin_page_federation(App $a) $hint = L10n::t('The Auto Discovered Contact Directory feature is not enabled, it will improve the data displayed here.'); // load the template, replace the macros and return the page content - $t = get_markup_template('admin/federation.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/federation.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Federation Statistics'), '$intro' => $intro, @@ -745,13 +758,21 @@ function admin_page_federation(App $a) function admin_page_queue(App $a) { // get content from the queue table - $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last` - FROM `queue` AS `q`, `contact` AS `c` - WHERE `c`.`id` = `q`.`cid` - ORDER BY `q`.`cid`, `q`.`created`;"); + $entries = DBA::p("SELECT `contact`.`name`, `contact`.`nurl`, + `queue`.`id`, `queue`.`network`, `queue`.`created`, `queue`.`last` + FROM `queue` INNER JOIN `contact` ON `contact`.`id` = `queue`.`cid` + ORDER BY `queue`.`cid`, `queue`.`created`"); + + $r = []; + while ($entry = DBA::fetch($entries)) { + $entry['created'] = DateTimeFormat::local($entry['created']); + $entry['last'] = DateTimeFormat::local($entry['last']); + $r[] = $entry; + } + DBA::close($entries); - $t = get_markup_template('admin/queue.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/queue.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Inspect Queue'), '$count' => count($r), @@ -777,27 +798,40 @@ function admin_page_queue(App $a) * @param App $a * @return string */ -function admin_page_workerqueue(App $a) +function admin_page_workerqueue(App $a, $deferred) { // get jobs from the workerqueue table - $statement = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]); - $r = DBA::toArray($statement); + if ($deferred) { + $condition = ["NOT `done` AND `next_try` > ?", DateTimeFormat::utcNow()]; + $sub_title = L10n::t('Inspect Deferred Worker Queue'); + $info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time."); + } else { + $condition = ["NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()]; + $sub_title = L10n::t('Inspect Worker Queue'); + $info = L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.'); + } + + $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['order'=> ['priority']]); - for($i = 0; $i < count($r); $i++) { + $r = []; + while ($entry = DBA::fetch($entries)) { // fix GH-5469. ref: src/Core/Worker.php:217 - $r[$i]['parameter'] = implode(json_decode($r[$i]['parameter'], true), ': '); + $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': '); + $entry['created'] = DateTimeFormat::local($entry['created']); + $r[] = $entry; } + DBA::close($entries); - $t = get_markup_template('admin/workerqueue.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/workerqueue.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), - '$page' => L10n::t('Inspect Worker Queue'), + '$page' => $sub_title, '$count' => count($r), '$id_header' => L10n::t('ID'), '$param_header' => L10n::t('Job Parameters'), '$created_header' => L10n::t('Created'), '$prio_header' => L10n::t('Priority'), - '$info' => L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.'), + '$info' => $info, '$entries' => $r, ]); } @@ -833,10 +867,10 @@ function admin_page_summary(App $a) } } - if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) { + if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) { DBStructure::update(false, true); } - if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) { + if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) { $showwarning = true; $warningtext[] = L10n::t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.'); } @@ -853,7 +887,15 @@ function admin_page_summary(App $a) // Legacy config file warning if (file_exists('.htconfig.php')) { $showwarning = true; - $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php. See the Config help page for help with the transition.', $a->get_baseurl() . '/help/Config'); + $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php. See the Config help page for help with the transition.', $a->getBaseURL() . '/help/Config'); + } + + // Check server vitality + if (!admin_page_server_vital()) { + $showwarning = true; + $well_known = $a->getBaseURL() . '/.well-known/host-meta'; + $warningtext[] = L10n::t('%s is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See the installation page for help.', + $well_known, $well_known, $a->getBaseURL() . '/help/Install'); } $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`"); @@ -872,24 +914,34 @@ function admin_page_summary(App $a) $users+= $u['count']; } - logger('accounts: ' . print_r($accounts, true), LOGGER_DATA); + Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA); - $r = q("SELECT COUNT(`id`) AS `count` FROM `register`"); - $pending = $r[0]['count']; + $pending = Register::getPendingCount(); - $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1"); - $queue = (($r) ? $r[0]['total'] : 0); + $queue = DBA::count('queue', []); - $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`"); - $workerqueue = (($r) ? $r[0]['total'] : 0); + $deferred = DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` > ?", + DBA::NULL_DATETIME, DateTimeFormat::utcNow()]); + + $workerqueue = DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` < ?", + DBA::NULL_DATETIME, DateTimeFormat::utcNow()]); // We can do better, but this is a quick queue status - $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue]; + $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue]; + + $r = q("SHOW variables LIKE 'max_allowed_packet'"); + $max_allowed_packet = (($r) ? $r[0]['Value'] : 0); - $t = get_markup_template('admin/summary.tpl'); - return replace_macros($t, [ + $server_settings = ['label' => L10n::t('Server Settings'), + 'php' => ['upload_max_filesize' => ini_get('upload_max_filesize'), + 'post_max_size' => ini_get('post_max_size'), + 'memory_limit' => ini_get('memory_limit')], + 'mysql' => ['max_allowed_packet' => $max_allowed_packet]]; + + $t = Renderer::getMarkupTemplate('admin/summary.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Summary'), '$queues' => $queues, @@ -901,7 +953,8 @@ function admin_page_summary(App $a) '$platform' => FRIENDICA_PLATFORM, '$codename' => FRIENDICA_CODENAME, '$build' => Config::get('system', 'build'), - '$addons' => [L10n::t('Active addons'), $a->addons], + '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()], + '$serversettings' => $server_settings, '$showwarning' => $showwarning, '$warningtext' => $warningtext ]); @@ -914,7 +967,7 @@ function admin_page_summary(App $a) */ function admin_page_site_post(App $a) { - check_form_security_token_redirectOnErr('/admin/site', 'admin_site'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site'); if (!empty($_POST['republish_directory'])) { Worker::add(PRIORITY_LOW, 'Directory'); @@ -933,7 +986,7 @@ function admin_page_site_post(App $a) $parsed = @parse_url($new_url); if (!is_array($parsed) || !x($parsed, 'host') || !x($parsed, 'scheme')) { notice(L10n::t("Can not parse base url. Must have at least ://")); - goaway('admin/site'); + $a->internalRedirect('admin/site'); } /* steps: @@ -941,13 +994,13 @@ function admin_page_site_post(App $a) * send relocate for every local user * */ - $old_url = System::baseUrl(true); + $old_url = $a->getBaseURL(true); // Generate host names for relocation the addresses in the format user@address.tld $new_host = str_replace("http://", "@", normalise_link($new_url)); $old_host = str_replace("http://", "@", normalise_link($old_url)); - function update_table($table_name, $fields, $old_url, $new_url) + function update_table(App $a, $table_name, $fields, $old_url, $new_url) { $dbold = DBA::escape($old_url); $dbnew = DBA::escape($new_url); @@ -963,25 +1016,25 @@ function admin_page_site_post(App $a) if (!DBA::isResult($r)) { notice("Failed updating '$table_name': " . DBA::errorMessage()); - goaway('admin/site'); + $a->internalRedirect('admin/site'); } } // update tables // update profile links in the format "http://server.tld" - update_table("profile", ['photo', 'thumb'], $old_url, $new_url); - update_table("term", ['url'], $old_url, $new_url); - update_table("contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url); - update_table("gcontact", ['url', 'nurl', 'photo', 'server_url', 'notify', 'alias'], $old_url, $new_url); - update_table("item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url); + update_table($a, "profile", ['photo', 'thumb'], $old_url, $new_url); + update_table($a, "term", ['url'], $old_url, $new_url); + update_table($a, "contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url); + update_table($a, "gcontact", ['url', 'nurl', 'photo', 'server_url', 'notify', 'alias'], $old_url, $new_url); + update_table($a, "item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url); // update profile addresses in the format "user@server.tld" - update_table("contact", ['addr'], $old_host, $new_host); - update_table("gcontact", ['connect', 'addr'], $old_host, $new_host); + update_table($a, "contact", ['addr'], $old_host, $new_host); + update_table($a, "gcontact", ['connect', 'addr'], $old_host, $new_host); // update config Config::set('system', 'hostname', parse_url($new_url, PHP_URL_HOST)); Config::set('system', 'url', $new_url); - $a->set_baseurl($new_url); + $a->setBaseURL($new_url); // send relocate $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0"); @@ -992,20 +1045,20 @@ function admin_page_site_post(App $a) info("Relocation started. Could take a while to complete."); - goaway('admin/site'); + $a->internalRedirect('admin/site'); } // end relocate - $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : ''); - $hostname = ((x($_POST,'hostname')) ? notags(trim($_POST['hostname'])) : ''); - $sender_email = ((x($_POST,'sender_email')) ? notags(trim($_POST['sender_email'])) : ''); + $sitename = ((x($_POST,'sitename')) ? Strings::removeTags(trim($_POST['sitename'])) : ''); + $hostname = ((x($_POST,'hostname')) ? Strings::removeTags(trim($_POST['hostname'])) : ''); + $sender_email = ((x($_POST,'sender_email')) ? Strings::removeTags(trim($_POST['sender_email'])) : ''); $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false); - $shortcut_icon = ((x($_POST,'shortcut_icon')) ? notags(trim($_POST['shortcut_icon'])) : ''); - $touch_icon = ((x($_POST,'touch_icon')) ? notags(trim($_POST['touch_icon'])) : ''); + $shortcut_icon = ((x($_POST,'shortcut_icon')) ? Strings::removeTags(trim($_POST['shortcut_icon'])) : ''); + $touch_icon = ((x($_POST,'touch_icon')) ? Strings::removeTags(trim($_POST['touch_icon'])) : ''); $info = ((x($_POST,'info')) ? trim($_POST['info']) : false); - $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : ''); - $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : ''); - $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : ''); + $language = ((x($_POST,'language')) ? Strings::removeTags(trim($_POST['language'])) : ''); + $theme = ((x($_POST,'theme')) ? Strings::removeTags(trim($_POST['theme'])) : ''); + $theme_mobile = ((x($_POST,'theme_mobile')) ? Strings::removeTags(trim($_POST['theme_mobile'])) : ''); $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0); $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH); $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY); @@ -1017,14 +1070,14 @@ function admin_page_site_post(App $a) $register_text = ((x($_POST,'register_text')) ? strip_tags(trim($_POST['register_text'])) : ''); - $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : ''); - $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : ''); - $forbidden_nicknames = ((x($_POST,'forbidden_nicknames')) ? strtolower(notags(trim($_POST['forbidden_nicknames']))) : ''); + $allowed_sites = ((x($_POST,'allowed_sites')) ? Strings::removeTags(trim($_POST['allowed_sites'])) : ''); + $allowed_email = ((x($_POST,'allowed_email')) ? Strings::removeTags(trim($_POST['allowed_email'])) : ''); + $forbidden_nicknames = ((x($_POST,'forbidden_nicknames')) ? strtolower(Strings::removeTags(trim($_POST['forbidden_nicknames']))) : ''); $no_oembed_rich_content = x($_POST,'no_oembed_rich_content'); - $allowed_oembed = ((x($_POST,'allowed_oembed')) ? notags(trim($_POST['allowed_oembed'])) : ''); + $allowed_oembed = ((x($_POST,'allowed_oembed')) ? Strings::removeTags(trim($_POST['allowed_oembed'])) : ''); $block_public = ((x($_POST,'block_public')) ? True : False); $force_publish = ((x($_POST,'publish_all')) ? True : False); - $global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : ''); + $global_directory = ((x($_POST,'directory')) ? Strings::removeTags(trim($_POST['directory'])) : ''); $newuser_private = ((x($_POST,'newuser_private')) ? True : False); $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False); $private_addons = ((x($_POST,'private_addons')) ? True : False); @@ -1039,8 +1092,8 @@ function admin_page_site_post(App $a) $max_author_posts_community_page = ((x($_POST,'max_author_posts_community_page')) ? intval(trim($_POST['max_author_posts_community_page'])) : 0); $verifyssl = ((x($_POST,'verifyssl')) ? True : False); - $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : ''); - $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); + $proxyuser = ((x($_POST,'proxyuser')) ? Strings::removeTags(trim($_POST['proxyuser'])) : ''); + $proxy = ((x($_POST,'proxy')) ? Strings::removeTags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50); @@ -1064,16 +1117,16 @@ function admin_page_site_post(App $a) $dbclean_expire_days = ((x($_POST,'dbclean_expire_days')) ? intval($_POST['dbclean_expire_days']) : 0); $dbclean_unclaimed = ((x($_POST,'dbclean_unclaimed')) ? intval($_POST['dbclean_unclaimed']) : 0); $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False); - $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : ''); + $itemcache = ((x($_POST,'itemcache')) ? Strings::removeTags(trim($_POST['itemcache'])) : ''); $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0); $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0); - $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : ''); - $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : ''); - $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : ''); + $temppath = ((x($_POST,'temppath')) ? Strings::removeTags(trim($_POST['temppath'])) : ''); + $basepath = ((x($_POST,'basepath')) ? Strings::removeTags(trim($_POST['basepath'])) : ''); + $singleuser = ((x($_POST,'singleuser')) ? Strings::removeTags(trim($_POST['singleuser'])) : ''); $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False); $only_tag_search = ((x($_POST,'only_tag_search')) ? True : False); $rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0); - $check_new_version_url = ((x($_POST, 'check_new_version_url')) ? notags(trim($_POST['check_new_version_url'])) : 'none'); + $check_new_version_url = ((x($_POST, 'check_new_version_url')) ? Strings::removeTags(trim($_POST['check_new_version_url'])) : 'none'); $worker_queues = ((x($_POST,'worker_queues')) ? intval($_POST['worker_queues']) : 10); $worker_dont_fork = ((x($_POST,'worker_dont_fork')) ? True : False); @@ -1081,10 +1134,10 @@ function admin_page_site_post(App $a) $worker_frontend = ((x($_POST,'worker_frontend')) ? True : False); $relay_directly = ((x($_POST,'relay_directly')) ? True : False); - $relay_server = ((x($_POST,'relay_server')) ? notags(trim($_POST['relay_server'])) : ''); + $relay_server = ((x($_POST,'relay_server')) ? Strings::removeTags(trim($_POST['relay_server'])) : ''); $relay_subscribe = ((x($_POST,'relay_subscribe')) ? True : False); - $relay_scope = ((x($_POST,'relay_scope')) ? notags(trim($_POST['relay_scope'])) : ''); - $relay_server_tags = ((x($_POST,'relay_server_tags')) ? notags(trim($_POST['relay_server_tags'])) : ''); + $relay_scope = ((x($_POST,'relay_scope')) ? Strings::removeTags(trim($_POST['relay_scope'])) : ''); + $relay_server_tags = ((x($_POST,'relay_server_tags')) ? Strings::removeTags(trim($_POST['relay_server_tags'])) : ''); $relay_user_tags = ((x($_POST,'relay_user_tags')) ? True : False); // Has the directory url changed? If yes, then resubmit the existing profiles there @@ -1093,7 +1146,7 @@ function admin_page_site_post(App $a) Worker::add(PRIORITY_LOW, 'Directory'); } - if ($a->get_path() != "") { + if ($a->getURLPath() != "") { $diaspora_enabled = false; } if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) { @@ -1230,7 +1283,7 @@ function admin_page_site_post(App $a) Config::set('system', 'dbclean-expire-unclaimed', $dbclean_unclaimed); if ($itemcache != '') { - $itemcache = App::realpath($itemcache); + $itemcache = App::getRealPath($itemcache); } Config::set('system', 'itemcache', $itemcache); @@ -1238,13 +1291,13 @@ function admin_page_site_post(App $a) Config::set('system', 'max_comments', $max_comments); if ($temppath != '') { - $temppath = App::realpath($temppath); + $temppath = App::getRealPath($temppath); } Config::set('system', 'temppath', $temppath); if ($basepath != '') { - $basepath = App::realpath($basepath); + $basepath = App::getRealPath($basepath); } Config::set('system', 'basepath', $basepath); @@ -1266,7 +1319,7 @@ function admin_page_site_post(App $a) Config::set('system', 'rino_encrypt', $rino); info(L10n::t('Site settings updated.') . EOL); - goaway('admin/site'); + $a->internalRedirect('admin/site'); return; // NOTREACHED } @@ -1388,9 +1441,9 @@ function admin_page_site(App $a) ]; if (empty(Config::get('config', 'hostname'))) { - Config::set('config', 'hostname', $a->get_hostname()); + Config::set('config', 'hostname', $a->getHostName()); } - $diaspora_able = ($a->get_path() == ""); + $diaspora_able = ($a->getURLPath() == ""); $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', -1); @@ -1398,8 +1451,8 @@ function admin_page_site(App $a) $optimize_max_tablesize = -1; } - $t = get_markup_template('admin/site.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/site.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Site'), '$submit' => L10n::t('Save Settings'), @@ -1457,7 +1510,7 @@ function admin_page_site(App $a) '$community_page_style' => ['community_page_style', L10n::t("Community pages for visitors"), Config::get('system','community_page_style'), L10n::t("Which community pages should be available for visitors. Local users always see both pages."), $community_page_style_choices], '$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t("Posts per user on community page"), Config::get('system','max_author_posts_community_page'), L10n::t("The maximum number of posts per user on the community page. \x28Not valid for 'Global Community'\x29")], '$ostatus_disabled' => ['ostatus_disabled', L10n::t("Enable OStatus support"), !Config::get('system','ostatus_disabled'), L10n::t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")], - '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")], + '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus/ActivityPub threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.")], '$ostatus_not_able' => L10n::t("OStatus support can only be enabled if threading is enabled."), '$diaspora_able' => $diaspora_able, '$diaspora_not_able' => L10n::t("Diaspora support can't be enabled because Friendica was installed into a sub directory."), @@ -1510,7 +1563,7 @@ function admin_page_site(App $a) '$relay_server_tags' => ['relay_server_tags', L10n::t("Server tags"), Config::get('system','relay_server_tags'), L10n::t("Comma separated list of tags for the 'tags' subscription.")], '$relay_user_tags' => ['relay_user_tags', L10n::t("Allow user tags"), Config::get('system', 'relay_user_tags', true), L10n::t("If enabled, the tags from the saved searches will used for the 'tags' subscription in addition to the 'relay_server_tags'.")], - '$form_security_token' => get_form_security_token("admin_site"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_site"), '$relocate_button' => L10n::t('Start Relocation'), ]); } @@ -1538,14 +1591,15 @@ function admin_page_dbsync(App $a) Config::set('system', 'build', intval($curr) + 1); } info(L10n::t('Update has been marked successful') . EOL); - goaway('admin/dbsync'); + $a->internalRedirect('admin/dbsync'); } if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) { $retval = DBStructure::update(false, true); if ($retval === '') { $o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "
"; - Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); + Config::set('database', 'last_successful_update', DB_UPDATE_VERSION); + Config::set('database', 'last_successful_update_time', time()); } else { $o .= L10n::t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "
"; } @@ -1562,9 +1616,9 @@ function admin_page_dbsync(App $a) if (function_exists($func)) { $retval = $func(); - if ($retval === UPDATE_FAILED) { + if ($retval === Update::FAILED) { $o .= L10n::t("Executing %s failed with error: %s", $func, $retval); - } elseif ($retval === UPDATE_SUCCESS) { + } elseif ($retval === Update::SUCCESS) { $o .= L10n::t('Update %s was successfully applied.', $func); Config::set('database', $func, 'success'); } else { @@ -1592,13 +1646,13 @@ function admin_page_dbsync(App $a) } if (!count($failed)) { - $o = replace_macros(get_markup_template('structure_check.tpl'), [ + $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('structure_check.tpl'), [ '$base' => System::baseUrl(true), '$banner' => L10n::t('No failed updates.'), '$check' => L10n::t('Check database structure'), ]); } else { - $o = replace_macros(get_markup_template('failed_updates.tpl'), [ + $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('failed_updates.tpl'), [ '$base' => System::baseUrl(true), '$banner' => L10n::t('Failed Updates'), '$desc' => L10n::t('This does not include updates prior to 1139, which did not return a status.'), @@ -1625,7 +1679,7 @@ function admin_page_users_post(App $a) $nu_email = defaults($_POST, 'new_user_email' , ''); $nu_language = Config::get('system', 'language'); - check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users'); if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) { try { @@ -1677,11 +1731,14 @@ function admin_page_users_post(App $a) $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], Config::get('config', 'sitename')); notification([ - 'type' => SYSTEM_EMAIL, + 'type' => SYSTEM_EMAIL, + 'language' => $user['language'], + 'to_name' => $user['username'], 'to_email' => $user['email'], - 'subject' => L10n::t('Registration details for %s', Config::get('config', 'sitename')), + 'uid' => $user['uid'], + 'subject' => L10n::t('Registration details for %s', Config::get('config', 'sitename')), 'preamble' => $preamble, - 'body' => $body]); + 'body' => $body]); } if (x($_POST, 'page_users_block')) { @@ -1710,7 +1767,7 @@ function admin_page_users_post(App $a) user_deny($hash); } } - goaway('admin/users'); + $a->internalRedirect('admin/users'); return; // NOTREACHED } @@ -1733,19 +1790,19 @@ function admin_page_users(App $a) $user = DBA::selectFirst('user', ['username', 'blocked'], ['uid' => $uid]); if (!DBA::isResult($user)) { notice('User not found' . EOL); - goaway('admin/users'); + $a->internalRedirect('admin/users'); return ''; // NOTREACHED } switch ($a->argv[2]) { case "delete": - check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); // delete user User::remove($uid); notice(L10n::t("User '%s' deleted", $user['username']) . EOL); break; case "block": - check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", intval(1 - $user['blocked']), intval($uid) @@ -1753,23 +1810,14 @@ function admin_page_users(App $a) notice(sprintf(($user['blocked'] ? L10n::t("User '%s' unblocked") : L10n::t("User '%s' blocked")), $user['username']) . EOL); break; } - goaway('admin/users'); + $a->internalRedirect('admin/users'); return ''; // NOTREACHED } /* get pending */ - $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email` - FROM `register` - INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;"); - + $pending = Register::getPending(); - /* get users */ - $total = q("SELECT COUNT(*) AS `total` FROM `user` WHERE 1"); - if (count($total)) { - $a->set_pager_total($total[0]['total']); - $a->set_pager_itemspage(100); - } + $pager = new Pager($a->query_string, 100); /* ordering */ $valid_orders = [ @@ -1801,7 +1849,7 @@ function admin_page_users(App $a) FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` WHERE `user`.`verified` - ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", intval($a->pager['start']), intval($a->pager['itemspage']) + ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", $pager->getStart(), $pager->getItemsPerPage() ); $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))); @@ -1865,8 +1913,8 @@ function admin_page_users(App $a) $th_users = array_map(null, [L10n::t('Name'), L10n::t('Email'), L10n::t('Register date'), L10n::t('Last login'), L10n::t('Last item'), L10n::t('Type')], $valid_orders); - $t = get_markup_template('admin/users.tpl'); - $o = replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/users.tpl'); + $o = Renderer::replaceMacros($t, [ // strings // '$title' => L10n::t('Administration'), '$page' => L10n::t('Users'), @@ -1888,7 +1936,7 @@ function admin_page_users(App $a) '$h_users' => L10n::t('Users'), '$h_newuser' => L10n::t('New User'), - '$th_deleted' => [L10n::t('Name'), L10n::t('Email'), L10n::t('Register date'), L10n::t('Last login'), L10n::t('Last item'), L10n::t('Deleted since')], + '$th_deleted' => [L10n::t('Name'), L10n::t('Email'), L10n::t('Register date'), L10n::t('Last login'), L10n::t('Last item'), L10n::t('Delete in')], '$th_users' => $th_users, '$order_users' => $order, '$order_direction_users' => $order_direction, @@ -1896,10 +1944,10 @@ function admin_page_users(App $a) '$confirm_delete_multi' => L10n::t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'), '$confirm_delete' => L10n::t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'), - '$form_security_token' => get_form_security_token("admin_users"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_users"), // values // - '$baseurl' => System::baseUrl(true), + '$baseurl' => $a->getBaseURL(true), '$pending' => $pending, 'deleted' => $deleted, @@ -1908,7 +1956,7 @@ function admin_page_users(App $a) '$newusernickname' => ['new_user_nickname', L10n::t("Nickname"), '', L10n::t("Nickname of the new user.")], '$newuseremail' => ['new_user_email', L10n::t("Email"), '', L10n::t("Email address of the new user."), '', '', 'email'], ]); - $o .= paginate($a); + $o .= $pager->renderFull(DBA::count('user')); return $o; } @@ -1925,10 +1973,11 @@ function admin_page_users(App $a) * * The returned string returned hulds the HTML code of the page. * - * @param App $a + * @param App $a + * @param array $addons_admin A list of admin addon names * @return string */ -function admin_page_addons(App $a) +function admin_page_addons(App $a, array $addons_admin) { /* * Single addon @@ -1940,27 +1989,25 @@ function admin_page_addons(App $a) return ''; } - if (x($_GET, "a") && $_GET['a'] == "t") { - check_form_security_token_redirectOnErr('/admin/addons', 'admin_themes', 't'); + if (defaults($_GET, 'a', '') == "t") { + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't'); // Toggle addon status - $idx = array_search($addon, $a->addons); - if ($idx !== false) { - unset($a->addons[$idx]); + if (Addon::isEnabled($addon)) { Addon::uninstall($addon); info(L10n::t("Addon %s disabled.", $addon)); } else { - $a->addons[] = $addon; Addon::install($addon); info(L10n::t("Addon %s enabled.", $addon)); } - Config::set("system", "addon", implode(", ", $a->addons)); - goaway('admin/addons'); + + Addon::saveEnabledList(); + $a->internalRedirect('admin/addons'); return ''; // NOTREACHED } // display addon details - if (in_array($addon, $a->addons)) { + if (Addon::isEnabled($addon)) { $status = "on"; $action = L10n::t("Disable"); } else { @@ -1976,20 +2023,20 @@ function admin_page_addons(App $a) } $admin_form = ""; - if (in_array($addon, $a->addons_admin)) { + if (in_array($addon, $addons_admin)) { require_once "addon/$addon/$addon.php"; $func = $addon . '_addon_admin'; $func($a, $admin_form); } - $t = get_markup_template('admin/addon_details.tpl'); + $t = Renderer::getMarkupTemplate('admin/addon_details.tpl'); - return replace_macros($t, [ + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Addons'), '$toggle' => L10n::t('Toggle'), '$settings' => L10n::t('Settings'), - '$baseurl' => System::baseUrl(true), + '$baseurl' => $a->getBaseURL(true), '$addon' => $addon, '$status' => $status, @@ -2003,7 +2050,7 @@ function admin_page_addons(App $a) '$screenshot' => '', '$readme' => $readme, - '$form_security_token' => get_form_security_token("admin_themes"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), ]); } @@ -2011,10 +2058,10 @@ function admin_page_addons(App $a) * List addons */ if (x($_GET, "a") && $_GET['a'] == "r") { - check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/addons', 'admin_themes', 't'); + BaseModule::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/addons', 'admin_themes', 't'); Addon::reload(); info("Addons reloaded"); - goaway(System::baseUrl() . '/admin/addons'); + $a->internalRedirect('admin/addons'); } $addons = []; @@ -2027,7 +2074,7 @@ function admin_page_addons(App $a) $show_addon = true; // If the addon is unsupported, then only show it, when it is enabled - if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->addons)) { + if ((strtolower($info["status"]) == "unsupported") && !Addon::isEnabled($id)) { $show_addon = false; } @@ -2037,14 +2084,14 @@ function admin_page_addons(App $a) } if ($show_addon) { - $addons[] = [$id, (in_array($id, $a->addons) ? "on" : "off"), $info]; + $addons[] = [$id, (Addon::isEnabled($id) ? "on" : "off"), $info]; } } } } - $t = get_markup_template('admin/addons.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/addons.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Addons'), '$submit' => L10n::t('Save Settings'), @@ -2054,7 +2101,7 @@ function admin_page_addons(App $a) '$addons' => $addons, '$pcount' => count($addons), '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'), - '$form_security_token' => get_form_security_token("admin_themes"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), ]); } @@ -2189,7 +2236,7 @@ function admin_page_themes(App $a) } if (x($_GET, "a") && $_GET['a'] == "t") { - check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't'); // Toggle theme status @@ -2204,7 +2251,7 @@ function admin_page_themes(App $a) } Config::set('system', 'allowed_themes', $s); - goaway('admin/themes'); + $a->internalRedirect('admin/themes'); return ''; // NOTREACHED } @@ -2227,7 +2274,7 @@ function admin_page_themes(App $a) $admin_form = ''; if (is_file("view/theme/$theme/config.php")) { - $orig_theme = $a->theme; + $orig_theme = Renderer::$theme; $orig_page = $a->page; $orig_session_theme = $_SESSION['theme']; require_once "view/theme/$theme/theme.php"; @@ -2244,7 +2291,7 @@ function admin_page_themes(App $a) } $_SESSION['theme'] = $orig_session_theme; - $a->theme = $orig_theme; + Renderer::$theme = $orig_theme; $a->page = $orig_page; } @@ -2253,8 +2300,8 @@ function admin_page_themes(App $a) $screenshot = null; } - $t = get_markup_template('admin/addon_details.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/addon_details.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Themes'), '$toggle' => L10n::t('Toggle'), @@ -2271,13 +2318,13 @@ function admin_page_themes(App $a) '$screenshot' => $screenshot, '$readme' => $readme, - '$form_security_token' => get_form_security_token("admin_themes"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), ]); } // reload active themes if (x($_GET, "a") && $_GET['a'] == "r") { - check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); + BaseModule::checkFormSecurityTokenRedirectOnError(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); foreach ($themes as $th) { if ($th['allowed']) { Theme::uninstall($th['name']); @@ -2285,7 +2332,7 @@ function admin_page_themes(App $a) } } info("Themes reloaded"); - goaway(System::baseUrl() . '/admin/themes'); + $a->internalRedirect('admin/themes'); } /* @@ -2297,8 +2344,8 @@ function admin_page_themes(App $a) $addons[] = [$th['name'], (($th['allowed']) ? "on" : "off"), Theme::getInfo($th['name'])]; } - $t = get_markup_template('admin/addons.tpl'); - return replace_macros($t, [ + $t = Renderer::getMarkupTemplate('admin/addons.tpl'); + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Themes'), '$submit' => L10n::t('Save Settings'), @@ -2310,7 +2357,7 @@ function admin_page_themes(App $a) '$noplugshint' => L10n::t('No themes found on the system. They should be placed in %1$s', '/view/themes'), '$experimental' => L10n::t('[Experimental]'), '$unsupported' => L10n::t('[Unsupported]'), - '$form_security_token' => get_form_security_token("admin_themes"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), ]); } @@ -2322,9 +2369,9 @@ function admin_page_themes(App $a) function admin_page_logs_post(App $a) { if (x($_POST, "page_logs")) { - check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs'); - $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : ''); + $logfile = ((x($_POST,'logfile')) ? Strings::removeTags(trim($_POST['logfile'])) : ''); $debugging = ((x($_POST,'debugging')) ? true : false); $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0); @@ -2334,7 +2381,7 @@ function admin_page_logs_post(App $a) } info(L10n::t("Log settings updated.")); - goaway('admin/logs'); + $a->internalRedirect('admin/logs'); return; // NOTREACHED } @@ -2357,12 +2404,12 @@ function admin_page_logs_post(App $a) function admin_page_logs(App $a) { $log_choices = [ - LOGGER_WARNING => 'Warning', - LOGGER_INFO => 'Info', - LOGGER_TRACE => 'Trace', - LOGGER_DEBUG => 'Debug', - LOGGER_DATA => 'Data', - LOGGER_ALL => 'All' + Logger::WARNING => 'Warning', + Logger::INFO => 'Info', + Logger::TRACE => 'Trace', + Logger::DEBUG => 'Debug', + Logger::DATA => 'Data', + Logger::ALL => 'All' ]; if (ini_get('log_errors')) { @@ -2371,9 +2418,9 @@ function admin_page_logs(App $a) $phplogenabled = L10n::t('PHP log currently disabled.'); } - $t = get_markup_template('admin/logs.tpl'); + $t = Renderer::getMarkupTemplate('admin/logs.tpl'); - return replace_macros($t, [ + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('Logs'), '$submit' => L10n::t('Save Settings'), @@ -2384,7 +2431,7 @@ function admin_page_logs(App $a) '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""], '$logfile' => ['logfile', L10n::t("Log file"), Config::get('system', 'logfile'), L10n::t("Must be writable by web server. Relative to your Friendica top-level directory.")], '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices], - '$form_security_token' => get_form_security_token("admin_logs"), + '$form_security_token' => BaseModule::getFormSecurityToken("admin_logs"), '$phpheader' => L10n::t("PHP logging"), '$phphint' => L10n::t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."), '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');", @@ -2412,7 +2459,7 @@ function admin_page_logs(App $a) */ function admin_page_viewlogs(App $a) { - $t = get_markup_template('admin/viewlogs.tpl'); + $t = Renderer::getMarkupTemplate('admin/viewlogs.tpl'); $f = Config::get('system', 'logfile'); $data = ''; @@ -2431,16 +2478,16 @@ function admin_page_viewlogs(App $a) } $seek = fseek($fp, 0 - $size, SEEK_END); if ($seek === 0) { - $data = escape_tags(fread($fp, $size)); + $data = Strings::escapeTags(fread($fp, $size)); while (!feof($fp)) { - $data .= escape_tags(fread($fp, 4096)); + $data .= Strings::escapeTags(fread($fp, 4096)); } } } fclose($fp); } } - return replace_macros($t, [ + return Renderer::replaceMacros($t, [ '$title' => L10n::t('Administration'), '$page' => L10n::t('View Logs'), '$data' => $data, @@ -2455,9 +2502,9 @@ function admin_page_viewlogs(App $a) */ function admin_page_features_post(App $a) { - check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features'); + BaseModule::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features'); - logger('postvars: ' . print_r($_POST, true), LOGGER_DATA); + Logger::log('postvars: ' . print_r($_POST, true), Logger::DATA); $features = Feature::get(false); @@ -2482,7 +2529,7 @@ function admin_page_features_post(App $a) } } - goaway('admin/features'); + $a->internalRedirect('admin/features'); return; // NOTREACHED } @@ -2502,7 +2549,7 @@ function admin_page_features_post(App $a) */ function admin_page_features(App $a) { - if ((argc() > 1) && (argv(1) === 'features')) { + if (($a->argc > 1) && ($a->getArgumentValue(1) === 'features')) { $arr = []; $features = Feature::get(false); @@ -2518,9 +2565,9 @@ function admin_page_features(App $a) } } - $tpl = get_markup_template('admin/settings_features.tpl'); - $o = replace_macros($tpl, [ - '$form_security_token' => get_form_security_token("admin_manage_features"), + $tpl = Renderer::getMarkupTemplate('admin/settings_features.tpl'); + $o = Renderer::replaceMacros($tpl, [ + '$form_security_token' => BaseModule::getFormSecurityToken("admin_manage_features"), '$title' => L10n::t('Manage Additional Features'), '$features' => $arr, '$submit' => L10n::t('Save Settings'), @@ -2529,3 +2576,9 @@ function admin_page_features(App $a) return $o; } } + +function admin_page_server_vital() +{ + // Fetch the host-meta to check if this really is a vital server + return Network::curl(System::baseUrl() . '/.well-known/host-meta')->isSuccess(); +}