X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fadmin.php;h=ee95a180a5b30aa7049fdee99aee9a536ad24fec;hb=d0dfcc71a82ac423db68a12fd2eaf6d13cb18e1f;hp=81fa1fb575542997f4a4ca5decedbd5f15f883a8;hpb=d7b411e9bc7c115bcb88ce362ef7f211fff2c868;p=friendica.git diff --git a/mod/admin.php b/mod/admin.php index 81fa1fb575..ee95a180a5 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -7,10 +7,12 @@ */ use Friendica\App; +use Friendica\Core\System; use Friendica\Core\Config; require_once("include/enotify.php"); require_once("include/text.php"); +require_once('include/items.php'); /** * @brief Process send data from the admin panels subpages @@ -113,6 +115,9 @@ function admin_post(App $a) { case 'blocklist': admin_page_blocklist_post($a); break; + case 'deleteitem': + admin_page_deleteitem_post($a); + break; } } @@ -172,6 +177,7 @@ function admin_content(App $a) { 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"), 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"), 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"), + 'deleteitem' => array("admin/deleteitem/", t('Delete Item'), 'deleteitem'), ); /* get plugins admin page */ @@ -244,6 +250,9 @@ function admin_content(App $a) { case 'blocklist': $o = admin_page_blocklist($a); break; + case 'deleteitem': + $o = admin_page_deleteitem($a); + break; default: notice(t("Item not found.")); } @@ -299,7 +308,7 @@ function admin_page_blocklist(App $a) { '$threason' => t('Reason for the block'), '$delentry' => t('Delete entry from blocklist'), '$entries' => $blocklistform, - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$confirm_delete' => t('Delete entry from blocklist?'), '$form_security_token' => get_form_security_token("admin_blocklist") )); @@ -348,6 +357,67 @@ function admin_page_blocklist_post(App $a) { return; // NOTREACHED } +/** + * @brief Subpage where the admin can delete an item from their node given the GUID + * + * This subpage of the admin panel offers the nodes admin to delete an item from + * the node, given the GUID or the display URL such as http://example.com/display/123456. + * The item will then be marked as deleted in the database and processed accordingly. + * + * @param App $a + * @return string + */ +function admin_page_deleteitem(App $a) { + $t = get_markup_template("admin_deleteitem.tpl"); + + return replace_macros($t, array( + '$title' => t('Administration'), + '$page' => t('Delete Item'), + '$submit' => t('Delete this Item'), + '$intro1' => t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'), + '$intro2' => 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' => array('deleteitemguid', t("GUID"), '', t("The GUID of the item you want to delete."), 'required', 'autofocus'), + '$baseurl' => System::baseUrl(), + '$form_security_token' => get_form_security_token("admin_deleteitem") + )); +} +/** + * @brief Process send data from Admin Delete Item Page + * + * The GUID passed through the form should be only the GUID. But we also parse + * URLs like the full /display URL to make the process more easy for the admin. + * + * @param App $a + */ +function admin_page_deleteitem_post(App $a) { + if (!x($_POST['page_deleteitem_submit'])) { + return; + } + + check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem'); + + if (x($_POST['page_deleteitem_submit'])) { + $guid = trim(notags($_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, '/')) { + $guid = substr($guid, strrpos($guid, '/')+1); + } + // Now that we have the GUID get all IDs of the associated entries in the + // item table of the DB and drop those items, which will also delete the + // associated threads. + $r = dba::select('item', array('id'), array('guid'=>$guid)); + while ($row = dba::fetch($r)) { + drop_item($row['id'], false); + } + dba::close($r); + } + + info(t('Item marked for deletion.').EOL); + goaway('admin/deleteitem'); + return; // NOTREACHED +} + /** * @brief Subpage with some stats about "the federation" network * @@ -371,7 +441,7 @@ function admin_page_federation(App $a) { // off one % two of them are needed in the query // Add more platforms if you like, when one returns 0 known nodes it is not // displayed on the stats page. - $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon'); + $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma'); $colors = array('Friendi%%a' => '#ffc018', // orange from the logo 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray '%%red%%' => '#c50001', // fire red from the logo @@ -379,14 +449,15 @@ function admin_page_federation(App $a) { 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com 'GNU Social'=> '#a22430', // dark red from the logo 'StatusNet' => '#789240', // the green from the logo (red and blue have already others - 'Mastodon' => '#1a9df9'); // blue from the Mastodon logo + 'Mastodon' => '#1a9df9', // blue from the Mastodon logo + 'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances $counts = array(); $total = 0; foreach ($platforms as $p) { // get a total count for the platform, the name and version of the // highest version and the protocol tpe - $c = qu('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`, + $c = q('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`, ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver` WHERE `platform` LIKE "%s" AND `last_contact` >= `last_failure` ORDER BY `version` ASC;', $p); @@ -394,7 +465,7 @@ function admin_page_federation(App $a) { // what versions for that platform do we know at all? // again only the active nodes - $v = qu('SELECT COUNT(*) AS `total`, `version` FROM `gserver` + $v = q('SELECT COUNT(*) AS `total`, `version` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `platform` LIKE "%s" GROUP BY `version` ORDER BY `version`;', $p); @@ -483,7 +554,7 @@ function admin_page_federation(App $a) { '$counts' => $counts, '$version' => FRIENDICA_VERSION, '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total), - '$baseurl' => App::get_baseurl(), + '$baseurl' => System::baseUrl(), )); } @@ -573,13 +644,13 @@ function admin_page_summary(App $a) { logger('accounts: '.print_r($accounts,true),LOGGER_DATA); - $r = qu("SELECT COUNT(`id`) AS `count` FROM `register`"); + $r = q("SELECT COUNT(`id`) AS `count` FROM `register`"); $pending = $r[0]['count']; - $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1"); + $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1"); $queue = (($r) ? $r[0]['total'] : 0); - $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1"); + $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`"); $workerqueue = (($r) ? $r[0]['total'] : 0); // We can do better, but this is a quick queue status @@ -596,7 +667,7 @@ function admin_page_summary(App $a) { '$accounts' => $accounts, '$pending' => array(t('Pending registrations'), $pending), '$version' => array(t('Version'), FRIENDICA_VERSION), - '$baseurl' => App::get_baseurl(), + '$baseurl' => System::baseUrl(), '$platform' => FRIENDICA_PLATFORM, '$codename' => FRIENDICA_CODENAME, '$build' => get_config('system','build'), @@ -634,7 +705,7 @@ function admin_page_site_post(App $a) { * send relocate for every local user * */ - $old_url = App::get_baseurl(true); + $old_url = System::baseUrl(true); // Generate host names for relocation the addresses in the format user@address.tld $new_host = str_replace("http://", "@", normalise_link($new_url)); @@ -904,10 +975,25 @@ function admin_page_site_post(App $a) { set_config('system', 'force_ssl', $force_ssl); set_config('system', 'hide_help', $hide_help); + + if ($itemcache != '') { + $itemcache = App::realpath($itemcache); + } + set_config('system', 'itemcache', $itemcache); set_config('system', 'itemcache_duration', $itemcache_duration); set_config('system', 'max_comments', $max_comments); + + if ($temppath != '') { + $temppath = App::realpath($temppath); + } + set_config('system', 'temppath', $temppath); + + if ($basepath != '') { + $basepath = App::realpath($basepath); + } + set_config('system', 'basepath', $basepath); set_config('system', 'proxy_disabled', $proxy_disabled); set_config('system', 'only_tag_search', $only_tag_search); @@ -1067,7 +1153,7 @@ function admin_page_site(App $a) { '$performance' => t('Performance'), '$worker_title' => t('Worker'), '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), // name, label, value, help string, extra data... '$sitename' => array('sitename', t("Site name"), $a->config['sitename'],''), '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""), @@ -1142,14 +1228,14 @@ function admin_page_site(App $a) { '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")), '$only_tag_search' => array('only_tag_search', t("Only search in tags"), get_config('system','only_tag_search'), t("On large systems the text search can slow down the system extremely.")), - '$relocate_url' => array('relocate_url', t("New base url"), App::get_baseurl(), t("Change base url for this server. Sends relocate message to all DFRN contacts of all users.")), + '$relocate_url' => array('relocate_url', t("New base url"), System::baseUrl(), t("Change base url for this server. Sends relocate message to all DFRN contacts of all users.")), '$rino' => array('rino', t("RINO Encryption"), intval(get_config('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")), '$worker_queues' => array('worker_queues', t("Maximum number of parallel workers"), get_config('system','worker_queues'), t("On shared hosters set this to 2. On larger systems, values of 10 are great. Default value is 4.")), '$worker_dont_fork' => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), get_config('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of poller calls in your crontab.")), '$worker_fastlane' => array('worker_fastlane', t("Enable fastlane"), get_config('system','worker_fastlane'), t("When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.")), - '$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), get_config('system','frontend_worker'), t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call yourdomain.tld/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server. The worker background process needs to be activated for this.')), + '$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), get_config('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())), '$form_security_token' => get_form_security_token("admin_site") @@ -1232,13 +1318,13 @@ function admin_page_dbsync(App $a) { } if (! count($failed)) { $o = replace_macros(get_markup_template('structure_check.tpl'),array( - '$base' => App::get_baseurl(true), + '$base' => System::baseUrl(true), '$banner' => t('No failed updates.'), '$check' => t('Check database structure'), )); } else { $o = replace_macros(get_markup_template('failed_updates.tpl'),array( - '$base' => App::get_baseurl(true), + '$base' => System::baseUrl(true), '$banner' => t('Failed Updates'), '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), '$mark' => t('Mark success (if update was manually applied)'), @@ -1306,10 +1392,10 @@ function admin_page_users_post(App $a) { Thank you and welcome to %4$s.')); $preamble = sprintf($preamble, $nu['username'], $a->config['sitename']); - $body = sprintf($body, App::get_baseurl(), $nu['email'], $result['password'], $a->config['sitename']); + $body = sprintf($body, System::baseUrl(), $nu['email'], $result['password'], $a->config['sitename']); notification(array( - 'type' => "SYSTEM_EMAIL", + 'type' => SYSTEM_EMAIL, 'to_email' => $nu['email'], 'subject'=> sprintf(t('Registration details for %s'), $a->config['sitename']), 'preamble'=> $preamble, @@ -1401,7 +1487,7 @@ function admin_page_users(App $a) { /* get users */ - $total = qu("SELECT COUNT(*) AS `total` FROM `user` WHERE 1"); + $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); @@ -1436,7 +1522,7 @@ function admin_page_users(App $a) { $sql_order = "`".str_replace('.','`.`',$order)."`"; $sql_order_direction = ($order_direction === "+")?"ASC":"DESC"; - $users = qu("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date` + $users = q("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` WHERE `user`.`verified` @@ -1530,7 +1616,7 @@ function admin_page_users(App $a) { '$form_security_token' => get_form_security_token("admin_users"), // values // - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$pending' => $pending, 'deleted' => $deleted, @@ -1603,7 +1689,7 @@ function admin_page_plugins(App $a) { $readme=Null; if (is_file("addon/$plugin/README.md")) { $readme = file_get_contents("addon/$plugin/README.md"); - $readme = Markdown($readme); + $readme = Markdown($readme, false); } elseif (is_file("addon/$plugin/README")) { $readme = "
". file_get_contents("addon/$plugin/README") ."
"; } @@ -1622,7 +1708,7 @@ function admin_page_plugins(App $a) { '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$plugin' => $plugin, '$status' => $status, @@ -1647,10 +1733,10 @@ function admin_page_plugins(App $a) { */ if (x($_GET,"a") && $_GET['a']=="r") { - check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/plugins', 'admin_themes', 't'); + check_form_security_token_redirectOnErr(System::baseUrl().'/admin/plugins', 'admin_themes', 't'); reload_plugins(); info("Plugins reloaded"); - goaway(App::get_baseurl().'/admin/plugins'); + goaway(System::baseUrl().'/admin/plugins'); } $plugins = array(); @@ -1685,7 +1771,7 @@ function admin_page_plugins(App $a) { '$page' => t('Plugins'), '$submit' => t('Save Settings'), '$reload' => t('Reload active plugins'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$function' => 'plugins', '$plugins' => $plugins, '$pcount' => count($plugins), @@ -1855,7 +1941,7 @@ function admin_page_themes(App $a) { $readme = Null; if (is_file("view/theme/$theme/README.md")) { $readme = file_get_contents("view/theme/$theme/README.md"); - $readme = Markdown($readme); + $readme = Markdown($readme, false); } elseif (is_file("view/theme/$theme/README")) { $readme = "
". file_get_contents("view/theme/$theme/README") ."
"; } @@ -1898,7 +1984,7 @@ function admin_page_themes(App $a) { '$page' => t('Themes'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$plugin' => $theme, '$status' => $status, '$action' => $action, @@ -1917,7 +2003,7 @@ function admin_page_themes(App $a) { // reload active themes if (x($_GET,"a") && $_GET['a']=="r") { - check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/themes', 'admin_themes', 't'); + check_form_security_token_redirectOnErr(System::baseUrl().'/admin/themes', 'admin_themes', 't'); if ($themes) { foreach ($themes as $th) { if ($th['allowed']) { @@ -1927,7 +2013,7 @@ function admin_page_themes(App $a) { } } info("Themes reloaded"); - goaway(App::get_baseurl().'/admin/themes'); + goaway(System::baseUrl().'/admin/themes'); } /* @@ -1948,7 +2034,7 @@ function admin_page_themes(App $a) { '$page' => t('Themes'), '$submit' => t('Save Settings'), '$reload' => t('Reload active themes'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$function' => 'themes', '$plugins' => $xthemes, '$pcount' => count($themes), @@ -2022,7 +2108,7 @@ function admin_page_logs(App $a) { '$page' => t('Logs'), '$submit' => t('Save Settings'), '$clear' => t('Clear'), - '$baseurl' => App::get_baseurl(true), + '$baseurl' => System::baseUrl(true), '$logname' => get_config('system','logfile'), // name, label, value, help string, extra data...