2011-06-13 06:52:29 -04:00
< ? php
2017-11-29 20:28:30 -05:00
/**
2016-01-16 21:25:17 -05:00
* @ file mod / admin . php
2017-01-09 07:12:54 -05:00
*
2016-01-16 21:25:17 -05:00
* @ brief Friendica admin
*/
2018-01-14 18:59:08 -05:00
2017-04-30 00:07:00 -04:00
use Friendica\App ;
2018-10-17 15:30:41 -04:00
use Friendica\BaseModule ;
2017-12-04 09:04:36 -05:00
use Friendica\Content\Feature ;
2018-10-24 02:15:24 -04:00
use Friendica\Content\Pager ;
2018-01-14 18:59:08 -05:00
use Friendica\Content\Text\Markdown ;
2017-04-30 00:01:26 -04:00
use Friendica\Core\Config ;
2018-01-21 12:06:27 -05:00
use Friendica\Core\L10n ;
2018-10-29 17:20:46 -04:00
use Friendica\Core\Logger ;
2018-10-31 10:35:50 -04:00
use Friendica\Core\Renderer ;
2019-02-03 16:22:04 -05:00
use Friendica\Core\StorageManager ;
2018-01-14 18:59:08 -05:00
use Friendica\Core\System ;
2018-01-17 13:52:25 -05:00
use Friendica\Core\Theme ;
2018-10-14 07:19:37 -04:00
use Friendica\Core\Update ;
2017-11-05 07:15:53 -05:00
use Friendica\Core\Worker ;
2018-07-20 08:19:26 -04:00
use Friendica\Database\DBA ;
2017-12-14 16:13:02 -05:00
use Friendica\Database\DBStructure ;
2017-12-07 09:04:24 -05:00
use Friendica\Model\Contact ;
2018-01-17 18:22:01 -05:00
use Friendica\Model\Item ;
2018-10-14 11:57:28 -04:00
use Friendica\Model\Register ;
2018-01-24 21:08:45 -05:00
use Friendica\Model\User ;
2018-12-27 20:56:15 -05:00
use Friendica\Module ;
2017-12-17 11:40:59 -05:00
use Friendica\Module\Login ;
2018-05-19 12:52:23 -04:00
use Friendica\Module\Tos ;
2019-02-08 08:38:13 -05:00
use Friendica\Protocol\PortableContact ;
2018-07-30 21:24:26 -04:00
use Friendica\Util\Arrays ;
2019-02-03 16:22:04 -05:00
use Friendica\Util\BasePath ;
2019-04-08 15:12:10 -04:00
use Friendica\Util\BaseURL ;
2018-01-26 21:38:34 -05:00
use Friendica\Util\DateTimeFormat ;
2018-08-25 18:31:22 -04:00
use Friendica\Util\Network ;
2018-11-08 10:14:37 -05:00
use Friendica\Util\Strings ;
2018-10-14 11:57:28 -04:00
use Friendica\Util\Temporal ;
2019-01-22 01:30:52 -05:00
use Psr\Log\LogLevel ;
2016-01-16 21:25:17 -05:00
2012-04-18 03:24:47 -04:00
/**
2016-01-16 21:25:17 -05:00
* @ brief Process send data from the admin panels subpages
2015-12-26 02:49:38 -05:00
*
2018-10-14 11:32:54 -04:00
* This function acts as relay for processing the data send from the subpages
2015-12-26 02:49:38 -05:00
* of the admin panel . Depending on the 1 st parameter of the url ( argv [ 1 ])
* specialized functions are called to process the data from the subpages .
*
2018-10-14 11:32:54 -04:00
* The function itself does not return anything , but the subsequently function
2015-12-26 02:49:38 -05:00
* return the HTML for the pages of the admin panel .
*
2012-04-18 03:24:47 -04:00
* @ param App $a
2019-01-07 01:07:42 -05:00
* @ throws ImagickException
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2012-04-18 03:24:47 -04:00
*/
2017-11-29 20:28:30 -05:00
function admin_post ( App $a )
{
2017-03-13 13:23:02 -04:00
if ( ! is_site_admin ()) {
2011-10-18 03:18:21 -04:00
return ;
2011-06-13 12:03:06 -04:00
}
2012-02-17 02:50:57 -05:00
2012-02-23 23:29:09 -05:00
// do not allow a page manager to access the admin panel at all.
2012-02-17 02:50:57 -05:00
2018-11-30 09:06:22 -05:00
if ( ! empty ( $_SESSION [ 'submanage' ])) {
2012-02-17 02:50:57 -05:00
return ;
2016-12-20 04:35:28 -05:00
}
2012-02-23 23:29:09 -05:00
2018-01-04 19:42:48 -05:00
$return_path = 'admin' ;
2016-12-20 04:35:28 -05:00
if ( $a -> argc > 1 ) {
2017-03-13 13:23:02 -04:00
switch ( $a -> argv [ 1 ]) {
2017-07-07 04:38:07 -04:00
case 'deleteitem' :
admin_page_deleteitem_post ( $a );
break ;
2011-06-13 12:03:06 -04:00
}
}
2018-10-19 14:11:27 -04:00
$a -> internalRedirect ( $return_path );
2013-12-01 18:11:31 -05:00
return ; // NOTREACHED
2011-06-13 12:03:06 -04:00
}
2011-06-13 06:52:29 -04:00
2012-04-18 03:24:47 -04:00
/**
2016-01-16 21:25:17 -05:00
* @ brief Generates content of the admin panel pages
2016-01-16 08:12:55 -05:00
*
2016-01-19 03:15:32 -05:00
* This function generates the content for the admin panel . It consists of the
* aside menu ( same for the entire admin panel ) and the code for the soecified
* subpage of the panel .
*
* The structure of the adress is : / admin / subpage / details though " details " is
* only necessary for some subpages , like themes or addons where it is the name
* of one theme resp . addon from which the details should be shown . Content for
* the subpages is generated in separate functions for each of the subpages .
*
* The returned string hold the generated HTML code of the page .
2016-01-16 08:12:55 -05:00
*
2012-04-18 03:24:47 -04:00
* @ param App $a
* @ return string
2019-01-07 01:07:42 -05:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2012-04-18 03:24:47 -04:00
*/
2017-11-29 20:28:30 -05:00
function admin_content ( App $a )
{
2017-03-13 13:23:02 -04:00
if ( ! is_site_admin ()) {
2017-12-17 11:40:59 -05:00
return Login :: form ();
2011-06-13 06:52:29 -04:00
}
2018-11-30 09:06:22 -05:00
if ( ! empty ( $_SESSION [ 'submanage' ])) {
2012-04-18 03:24:47 -04:00
return " " ;
2016-12-20 04:35:28 -05:00
}
2012-02-17 02:50:57 -05:00
2014-05-03 06:02:25 -04:00
// APC deactivated, since there are problems with PHP 5.5
//if (function_exists("apc_delete")) {
2018-11-30 09:06:22 -05:00
// $toDelete = new APCIterator('user', APC_ITER_VALUE);
// apc_delete($toDelete);
2014-05-03 06:02:25 -04:00
//}
2016-01-16 21:25:17 -05:00
// Header stuff
2018-10-31 10:44:06 -04:00
$a -> page [ 'htmlhead' ] .= Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'admin/settings_head.tpl' ), []);
2016-01-16 21:25:17 -05:00
/*
2011-06-13 06:52:29 -04:00
* Side bar links
*/
2018-01-15 08:05:12 -05:00
$aside_tools = [];
2016-02-17 17:47:32 -05:00
// array(url, name, extra css classes)
2015-11-17 05:34:47 -05:00
// not part of $aside to make the template more adjustable
2018-01-15 08:05:12 -05:00
$aside_sub = [
2018-10-23 16:38:28 -04:00
'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' ],
'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' ]
2018-01-30 07:37:00 -05:00
]],
2018-10-23 16:38:28 -04:00
'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' ]
2018-01-30 07:37:00 -05:00
]]
2018-01-15 08:05:12 -05:00
];
2013-01-27 07:57:44 -05:00
2018-01-17 14:22:38 -05:00
$aside_tools [ 'addons_admin' ] = [];
2013-01-27 07:57:44 -05:00
2018-10-31 10:44:06 -04:00
$t = Renderer :: getMarkupTemplate ( 'admin/aside.tpl' );
2018-10-31 10:35:50 -04:00
$a -> page [ 'aside' ] .= Renderer :: replaceMacros ( $t , [
2016-01-16 21:25:17 -05:00
'$admin' => $aside_tools ,
'$subpages' => $aside_sub ,
2018-01-21 13:33:59 -05:00
'$admtxt' => L10n :: t ( 'Admin' ),
'$plugadmtxt' => L10n :: t ( 'Addon Features' ),
'$h_pending' => L10n :: t ( 'User registrations waiting for confirmation' ),
2017-11-29 20:28:30 -05:00
'$admurl' => " admin/ "
2018-01-15 08:05:12 -05:00
]);
2011-06-13 06:52:29 -04:00
2017-12-01 00:40:55 -05:00
// Page content
2011-06-13 06:52:29 -04:00
$o = '' ;
// urls
2017-03-13 13:23:02 -04:00
if ( $a -> argc > 1 ) {
switch ( $a -> argv [ 1 ]) {
2017-07-07 04:38:07 -04:00
case 'deleteitem' :
$o = admin_page_deleteitem ( $a );
break ;
2011-06-13 06:52:29 -04:00
default :
2018-01-21 13:33:59 -05:00
notice ( L10n :: t ( " Item not found. " ));
2011-06-13 06:52:29 -04:00
}
}
2013-01-27 07:57:44 -05:00
2018-10-13 12:57:31 -04:00
if ( $a -> isAjax ()) {
2014-07-09 15:36:20 -04:00
echo $o ;
2018-12-26 00:40:12 -05:00
exit ();
2012-04-13 05:20:05 -04:00
} else {
return $o ;
}
2014-07-09 15:36:20 -04:00
}
2011-06-13 06:52:29 -04:00
2017-07-07 04:38:07 -04:00
/**
2017-07-07 14:54:26 -04:00
* @ brief Subpage where the admin can delete an item from their node given the GUID
2017-07-07 04:38:07 -04:00
*
2017-07-07 14:54:26 -04:00
* This subpage of the admin panel offers the nodes admin to delete an item from
2017-07-07 04:38:07 -04:00
* the node , given the GUID or the display URL such as http :// example . com / display / 123456.
2017-07-07 14:54:26 -04:00
* The item will then be marked as deleted in the database and processed accordingly .
2017-10-08 04:22:29 -04:00
*
2017-07-07 04:38:07 -04:00
* @ param App $a
* @ return string
2019-01-07 01:07:42 -05:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-07-07 04:38:07 -04:00
*/
2017-11-29 20:28:30 -05:00
function admin_page_deleteitem ( App $a )
{
2018-10-31 10:44:06 -04:00
$t = Renderer :: getMarkupTemplate ( 'admin/deleteitem.tpl' );
2017-07-07 04:38:07 -04:00
2018-10-31 10:35:50 -04:00
return Renderer :: replaceMacros ( $t , [
2018-01-21 13:33:59 -05:00
'$title' => L10n :: t ( 'Administration' ),
'$page' => L10n :: t ( 'Delete Item' ),
'$submit' => L10n :: t ( 'Delete this Item' ),
'$intro1' => L10n :: 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' => 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' ],
2017-08-26 03:32:10 -04:00
'$baseurl' => System :: baseUrl (),
2018-10-17 15:30:41 -04:00
'$form_security_token' => BaseModule :: getFormSecurityToken ( " admin_deleteitem " )
2018-01-15 08:05:12 -05:00
]);
2017-07-07 04:38:07 -04:00
}
2017-11-29 20:28:30 -05:00
2017-07-07 04:38:07 -04:00
/**
* @ 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
2019-01-07 01:07:42 -05:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-07-07 04:38:07 -04:00
*/
2017-11-29 20:28:30 -05:00
function admin_page_deleteitem_post ( App $a )
{
2018-11-30 09:06:22 -05:00
if ( empty ( $_POST [ 'page_deleteitem_submit' ])) {
2017-07-07 04:38:07 -04:00
return ;
}
2018-10-17 15:30:41 -04:00
BaseModule :: checkFormSecurityTokenRedirectOnError ( '/admin/deleteitem/' , 'admin_deleteitem' );
2017-07-10 08:55:40 -04:00
2018-11-30 09:06:22 -05:00
if ( ! empty ( $_POST [ 'page_deleteitem_submit' ])) {
2018-11-09 13:29:42 -05:00
$guid = trim ( Strings :: escapeTags ( $_POST [ 'deleteitemguid' ]));
2017-07-07 04:38:07 -04:00
// 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 , '/' )) {
2017-11-29 20:28:30 -05:00
$guid = substr ( $guid , strrpos ( $guid , '/' ) + 1 );
2017-07-07 04:38:07 -04:00
}
2018-05-29 01:22:57 -04:00
// Now that we have the GUID, drop those items, which will also delete the
2017-07-10 08:55:40 -04:00
// associated threads.
2018-05-29 01:22:57 -04:00
Item :: delete ([ 'guid' => $guid ]);
2017-07-07 04:38:07 -04:00
}
2018-01-21 13:33:59 -05:00
info ( L10n :: t ( 'Item marked for deletion.' ) . EOL );
2018-10-19 14:11:27 -04:00
$a -> internalRedirect ( 'admin/deleteitem' );
2017-07-07 04:38:07 -04:00
return ; // NOTREACHED
}
2018-08-25 18:31:22 -04:00
function admin_page_server_vital ()
{
// Fetch the host-meta to check if this really is a vital server
2018-10-10 15:08:43 -04:00
return Network :: curl ( System :: baseUrl () . '/.well-known/host-meta' ) -> isSuccess ();
2018-08-25 18:31:22 -04:00
}