2011-06-13 10:52:29 +00:00
< ? php
2017-11-30 01:28:30 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ file mod / admin . php
2017-01-09 12:12:54 +00:00
*
2016-01-17 02:25:17 +00:00
* @ brief Friendica admin
*/
2018-01-14 23:59:08 +00:00
2017-04-30 04:07:00 +00:00
use Friendica\App ;
2018-10-17 19:30:41 +00:00
use Friendica\BaseModule ;
2017-12-04 14:04:36 +00:00
use Friendica\Content\Feature ;
2018-10-24 06:15:24 +00:00
use Friendica\Content\Pager ;
2018-01-14 23:59:08 +00:00
use Friendica\Content\Text\Markdown ;
2017-04-30 04:01:26 +00:00
use Friendica\Core\Config ;
2018-01-21 17:06:27 +00:00
use Friendica\Core\L10n ;
2018-10-29 21:20:46 +00:00
use Friendica\Core\Logger ;
2018-10-31 14:35:50 +00:00
use Friendica\Core\Renderer ;
2019-02-03 21:22:04 +00:00
use Friendica\Core\StorageManager ;
2018-01-14 23:59:08 +00:00
use Friendica\Core\System ;
2018-01-17 18:52:25 +00:00
use Friendica\Core\Theme ;
2018-10-14 11:19:37 +00:00
use Friendica\Core\Update ;
2017-11-05 12:15:53 +00:00
use Friendica\Core\Worker ;
2018-07-20 12:19:26 +00:00
use Friendica\Database\DBA ;
2017-12-14 21:13:02 +00:00
use Friendica\Database\DBStructure ;
2017-12-07 14:04:24 +00:00
use Friendica\Model\Contact ;
2018-01-17 23:22:01 +00:00
use Friendica\Model\Item ;
2018-10-14 15:57:28 +00:00
use Friendica\Model\Register ;
2018-01-25 02:08:45 +00:00
use Friendica\Model\User ;
2018-12-28 01:56:15 +00:00
use Friendica\Module ;
2017-12-17 16:40:59 +00:00
use Friendica\Module\Login ;
2018-05-19 16:52:23 +00:00
use Friendica\Module\Tos ;
2019-02-08 13:38:13 +00:00
use Friendica\Protocol\PortableContact ;
2018-07-31 01:24:26 +00:00
use Friendica\Util\Arrays ;
2019-02-03 21:22:04 +00:00
use Friendica\Util\BasePath ;
2019-04-08 19:12:10 +00:00
use Friendica\Util\BaseURL ;
2018-01-27 02:38:34 +00:00
use Friendica\Util\DateTimeFormat ;
2018-08-25 22:31:22 +00:00
use Friendica\Util\Network ;
2018-11-08 15:14:37 +00:00
use Friendica\Util\Strings ;
2018-10-14 15:57:28 +00:00
use Friendica\Util\Temporal ;
2019-01-22 06:30:52 +00:00
use Psr\Log\LogLevel ;
2016-01-17 02:25:17 +00:00
2012-04-18 07:24:47 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Process send data from the admin panels subpages
2015-12-26 07:49:38 +00:00
*
2018-10-14 15:32:54 +00:00
* This function acts as relay for processing the data send from the subpages
2015-12-26 07:49:38 +00: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 15:32:54 +00:00
* The function itself does not return anything , but the subsequently function
2015-12-26 07:49:38 +00:00
* return the HTML for the pages of the admin panel .
*
2012-04-18 07:24:47 +00:00
* @ param App $a
2019-01-07 06:07:42 +00:00
* @ throws ImagickException
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2012-04-18 07:24:47 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_post ( App $a )
{
2017-03-13 17:23:02 +00:00
if ( ! is_site_admin ()) {
2011-10-18 07:18:21 +00:00
return ;
2011-06-13 16:03:06 +00:00
}
2012-02-17 07:50:57 +00:00
2012-02-24 04:29:09 +00:00
// do not allow a page manager to access the admin panel at all.
2012-02-17 07:50:57 +00:00
2018-11-30 14:06:22 +00:00
if ( ! empty ( $_SESSION [ 'submanage' ])) {
2012-02-17 07:50:57 +00:00
return ;
2016-12-20 09:35:28 +00:00
}
2012-02-24 04:29:09 +00:00
2018-01-05 00:42:48 +00:00
$return_path = 'admin' ;
2016-12-20 09:35:28 +00:00
if ( $a -> argc > 1 ) {
2017-03-13 17:23:02 +00:00
switch ( $a -> argv [ 1 ]) {
2011-06-14 09:54:14 +00:00
case 'logs' :
admin_page_logs_post ( $a );
break ;
2017-07-07 08:38:07 +00:00
case 'deleteitem' :
admin_page_deleteitem_post ( $a );
break ;
2011-06-13 16:03:06 +00:00
}
}
2018-10-19 18:11:27 +00:00
$a -> internalRedirect ( $return_path );
2013-12-01 23:11:31 +00:00
return ; // NOTREACHED
2011-06-13 16:03:06 +00:00
}
2011-06-13 10:52:29 +00:00
2012-04-18 07:24:47 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Generates content of the admin panel pages
2016-01-16 13:12:55 +00:00
*
2016-01-19 08:15:32 +00: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 13:12:55 +00:00
*
2012-04-18 07:24:47 +00:00
* @ param App $a
* @ return string
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2012-04-18 07:24:47 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_content ( App $a )
{
2017-03-13 17:23:02 +00:00
if ( ! is_site_admin ()) {
2017-12-17 16:40:59 +00:00
return Login :: form ();
2011-06-13 10:52:29 +00:00
}
2018-11-30 14:06:22 +00:00
if ( ! empty ( $_SESSION [ 'submanage' ])) {
2012-04-18 07:24:47 +00:00
return " " ;
2016-12-20 09:35:28 +00:00
}
2012-02-17 07:50:57 +00:00
2014-05-03 10:02:25 +00:00
// APC deactivated, since there are problems with PHP 5.5
//if (function_exists("apc_delete")) {
2018-11-30 14:06:22 +00:00
// $toDelete = new APCIterator('user', APC_ITER_VALUE);
// apc_delete($toDelete);
2014-05-03 10:02:25 +00:00
//}
2016-01-17 02:25:17 +00:00
// Header stuff
2018-10-31 14:44:06 +00:00
$a -> page [ 'htmlhead' ] .= Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'admin/settings_head.tpl' ), []);
2016-01-17 02:25:17 +00:00
/*
2011-06-13 10:52:29 +00:00
* Side bar links
*/
2018-01-15 13:05:12 +00:00
$aside_tools = [];
2016-02-17 22:47:32 +00:00
// array(url, name, extra css classes)
2015-11-17 10:34:47 +00:00
// not part of $aside to make the template more adjustable
2018-01-15 13:05:12 +00:00
$aside_sub = [
2018-10-23 20:38:28 +00: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 12:37:00 +00:00
]],
2018-10-23 20:38:28 +00: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 12:37:00 +00:00
]]
2018-01-15 13:05:12 +00:00
];
2013-01-27 12:57:44 +00:00
2018-01-17 19:22:38 +00:00
$aside_tools [ 'addons_admin' ] = [];
2013-01-27 12:57:44 +00:00
2018-10-31 14:44:06 +00:00
$t = Renderer :: getMarkupTemplate ( 'admin/aside.tpl' );
2018-10-31 14:35:50 +00:00
$a -> page [ 'aside' ] .= Renderer :: replaceMacros ( $t , [
2016-01-17 02:25:17 +00:00
'$admin' => $aside_tools ,
'$subpages' => $aside_sub ,
2018-01-21 18:33:59 +00:00
'$admtxt' => L10n :: t ( 'Admin' ),
'$plugadmtxt' => L10n :: t ( 'Addon Features' ),
'$h_pending' => L10n :: t ( 'User registrations waiting for confirmation' ),
2017-11-30 01:28:30 +00:00
'$admurl' => " admin/ "
2018-01-15 13:05:12 +00:00
]);
2011-06-13 10:52:29 +00:00
2017-12-01 05:40:55 +00:00
// Page content
2011-06-13 10:52:29 +00:00
$o = '' ;
// urls
2017-03-13 17:23:02 +00:00
if ( $a -> argc > 1 ) {
switch ( $a -> argv [ 1 ]) {
2011-06-14 09:54:14 +00:00
case 'logs' :
$o = admin_page_logs ( $a );
2011-07-08 15:12:08 +00:00
break ;
2015-12-27 07:23:26 +00:00
case 'viewlogs' :
$o = admin_page_viewlogs ( $a );
break ;
2012-04-30 02:10:07 +00:00
case 'dbsync' :
$o = admin_page_dbsync ( $a );
break ;
2017-07-07 08:38:07 +00:00
case 'deleteitem' :
$o = admin_page_deleteitem ( $a );
break ;
2011-06-13 10:52:29 +00:00
default :
2018-01-21 18:33:59 +00:00
notice ( L10n :: t ( " Item not found. " ));
2011-06-13 10:52:29 +00:00
}
}
2013-01-27 12:57:44 +00:00
2018-10-13 16:57:31 +00:00
if ( $a -> isAjax ()) {
2014-07-09 19:36:20 +00:00
echo $o ;
2018-12-26 05:40:12 +00:00
exit ();
2012-04-13 09:20:05 +00:00
} else {
return $o ;
}
2014-07-09 19:36:20 +00:00
}
2011-06-13 10:52:29 +00:00
2017-07-07 08:38:07 +00:00
/**
2017-07-07 18:54:26 +00:00
* @ brief Subpage where the admin can delete an item from their node given the GUID
2017-07-07 08:38:07 +00:00
*
2017-07-07 18:54:26 +00:00
* This subpage of the admin panel offers the nodes admin to delete an item from
2017-07-07 08:38:07 +00:00
* the node , given the GUID or the display URL such as http :// example . com / display / 123456.
2017-07-07 18:54:26 +00:00
* The item will then be marked as deleted in the database and processed accordingly .
2017-10-08 08:22:29 +00:00
*
2017-07-07 08:38:07 +00:00
* @ param App $a
* @ return string
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-07-07 08:38:07 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_page_deleteitem ( App $a )
{
2018-10-31 14:44:06 +00:00
$t = Renderer :: getMarkupTemplate ( 'admin/deleteitem.tpl' );
2017-07-07 08:38:07 +00:00
2018-10-31 14:35:50 +00:00
return Renderer :: replaceMacros ( $t , [
2018-01-21 18:33:59 +00: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 07:32:10 +00:00
'$baseurl' => System :: baseUrl (),
2018-10-17 19:30:41 +00:00
'$form_security_token' => BaseModule :: getFormSecurityToken ( " admin_deleteitem " )
2018-01-15 13:05:12 +00:00
]);
2017-07-07 08:38:07 +00:00
}
2017-11-30 01:28:30 +00:00
2017-07-07 08:38:07 +00: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 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2017-07-07 08:38:07 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_page_deleteitem_post ( App $a )
{
2018-11-30 14:06:22 +00:00
if ( empty ( $_POST [ 'page_deleteitem_submit' ])) {
2017-07-07 08:38:07 +00:00
return ;
}
2018-10-17 19:30:41 +00:00
BaseModule :: checkFormSecurityTokenRedirectOnError ( '/admin/deleteitem/' , 'admin_deleteitem' );
2017-07-10 12:55:40 +00:00
2018-11-30 14:06:22 +00:00
if ( ! empty ( $_POST [ 'page_deleteitem_submit' ])) {
2018-11-09 18:29:42 +00:00
$guid = trim ( Strings :: escapeTags ( $_POST [ 'deleteitemguid' ]));
2017-07-07 08:38:07 +00: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-30 01:28:30 +00:00
$guid = substr ( $guid , strrpos ( $guid , '/' ) + 1 );
2017-07-07 08:38:07 +00:00
}
2018-05-29 05:22:57 +00:00
// Now that we have the GUID, drop those items, which will also delete the
2017-07-10 12:55:40 +00:00
// associated threads.
2018-05-29 05:22:57 +00:00
Item :: delete ([ 'guid' => $guid ]);
2017-07-07 08:38:07 +00:00
}
2018-01-21 18:33:59 +00:00
info ( L10n :: t ( 'Item marked for deletion.' ) . EOL );
2018-10-19 18:11:27 +00:00
$a -> internalRedirect ( 'admin/deleteitem' );
2017-07-07 08:38:07 +00:00
return ; // NOTREACHED
}
2015-12-26 07:49:38 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Generates admin panel subpage for DB syncronization
2016-01-04 08:55:30 +00:00
*
* This page checks if the database of friendica is in sync with the specs .
* Should this not be the case , it attemps to sync the structure and notifies
* the admin if the automatic process was failing .
*
* The returned string holds the HTML code of the page .
*
2015-12-26 07:49:38 +00:00
* @ param App $a
* @ return string
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
2017-11-30 01:28:30 +00:00
function admin_page_dbsync ( App $a )
{
2012-04-30 02:10:07 +00:00
$o = '' ;
2017-03-13 17:23:02 +00:00
if ( $a -> argc > 3 && intval ( $a -> argv [ 3 ]) && $a -> argv [ 2 ] === 'mark' ) {
2017-11-30 01:28:30 +00:00
Config :: set ( 'database' , 'update_' . intval ( $a -> argv [ 3 ]), 'success' );
$curr = Config :: get ( 'system' , 'build' );
2017-03-13 17:23:02 +00:00
if ( intval ( $curr ) == intval ( $a -> argv [ 3 ])) {
2017-11-30 01:28:30 +00:00
Config :: set ( 'system' , 'build' , intval ( $curr ) + 1 );
2017-03-13 17:23:02 +00:00
}
2018-01-21 18:33:59 +00:00
info ( L10n :: t ( 'Update has been marked successful' ) . EOL );
2018-10-19 18:11:27 +00:00
$a -> internalRedirect ( 'admin/dbsync' );
2012-04-30 02:10:07 +00:00
}
2017-06-08 02:00:59 +00:00
if (( $a -> argc > 2 ) && ( intval ( $a -> argv [ 2 ]) || ( $a -> argv [ 2 ] === 'check' ))) {
2019-02-03 21:46:50 +00:00
$retval = DBStructure :: update ( $a -> getBasePath (), false , true );
2018-01-05 00:42:48 +00:00
if ( $retval === '' ) {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( " Database structure update %s was successfully applied. " , DB_UPDATE_VERSION ) . " <br /> " ;
2018-10-07 08:42:14 +00:00
Config :: set ( 'database' , 'last_successful_update' , DB_UPDATE_VERSION );
Config :: set ( 'database' , 'last_successful_update_time' , time ());
2017-03-13 17:23:02 +00:00
} else {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( " Executing of database structure update %s failed with error: %s " , DB_UPDATE_VERSION , $retval ) . " <br /> " ;
2017-03-13 17:23:02 +00:00
}
if ( $a -> argv [ 2 ] === 'check' ) {
2014-09-04 07:26:56 +00:00
return $o ;
2017-03-13 17:23:02 +00:00
}
2014-09-04 07:26:56 +00:00
}
2017-03-13 17:23:02 +00:00
if ( $a -> argc > 2 && intval ( $a -> argv [ 2 ])) {
2017-11-30 01:28:30 +00:00
require_once 'update.php' ;
2018-05-13 14:46:58 +00:00
2017-11-30 01:28:30 +00:00
$func = 'update_' . intval ( $a -> argv [ 2 ]);
2018-05-13 14:46:58 +00:00
2017-03-13 17:23:02 +00:00
if ( function_exists ( $func )) {
2012-04-30 02:10:07 +00:00
$retval = $func ();
2018-05-13 14:46:58 +00:00
2018-10-14 11:19:37 +00:00
if ( $retval === Update :: FAILED ) {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( " Executing %s failed with error: %s " , $func , $retval );
2018-10-14 11:19:37 +00:00
} elseif ( $retval === Update :: SUCCESS ) {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( 'Update %s was successfully applied.' , $func );
2017-11-30 01:28:30 +00:00
Config :: set ( 'database' , $func , 'success' );
2017-03-13 17:23:02 +00:00
} else {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( 'Update %s did not return a status. Unknown if it succeeded.' , $func );
2017-03-13 17:23:02 +00:00
}
2014-09-04 07:26:56 +00:00
} else {
2018-01-21 18:33:59 +00:00
$o .= L10n :: t ( 'There was no additional update function %s that needed to be called.' , $func ) . " <br /> " ;
2017-11-30 01:28:30 +00:00
Config :: set ( 'database' , $func , 'success' );
2012-04-30 02:10:07 +00:00
}
2018-05-13 14:46:58 +00:00
2012-04-30 02:10:07 +00:00
return $o ;
}
2018-01-15 13:05:12 +00:00
$failed = [];
2016-06-11 08:12:03 +00:00
$r = q ( " SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' " );
2018-05-13 14:46:58 +00:00
2018-07-21 12:46:04 +00:00
if ( DBA :: isResult ( $r )) {
2016-12-20 20:15:53 +00:00
foreach ( $r as $rr ) {
2017-11-30 01:28:30 +00:00
$upd = intval ( substr ( $rr [ 'k' ], 7 ));
2017-03-13 17:23:02 +00:00
if ( $upd < 1139 || $rr [ 'v' ] === 'success' ) {
2012-04-30 02:10:07 +00:00
continue ;
2017-03-13 17:23:02 +00:00
}
2012-04-30 02:10:07 +00:00
$failed [] = $upd ;
}
}
2018-05-13 14:46:58 +00:00
2017-11-30 01:28:30 +00:00
if ( ! count ( $failed )) {
2018-10-31 14:44:06 +00:00
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'structure_check.tpl' ), [
2017-11-30 01:28:30 +00:00
'$base' => System :: baseUrl ( true ),
2018-01-21 18:33:59 +00:00
'$banner' => L10n :: t ( 'No failed updates.' ),
'$check' => L10n :: t ( 'Check database structure' ),
2018-01-15 13:05:12 +00:00
]);
2014-09-04 07:26:56 +00:00
} else {
2018-10-31 14:44:06 +00:00
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'failed_updates.tpl' ), [
2017-11-30 01:28:30 +00:00
'$base' => System :: baseUrl ( true ),
2018-01-21 18:33:59 +00:00
'$banner' => L10n :: t ( 'Failed Updates' ),
'$desc' => L10n :: t ( 'This does not include updates prior to 1139, which did not return a status.' ),
2018-01-24 21:51:32 +00:00
'$mark' => L10n :: t ( " Mark success \x28 if update was manually applied \x29 " ),
2018-01-21 18:33:59 +00:00
'$apply' => L10n :: t ( 'Attempt to execute this update step automatically' ),
2014-09-04 07:26:56 +00:00
'$failed' => $failed
2018-01-15 13:05:12 +00:00
]);
2014-09-04 07:26:56 +00:00
}
2012-04-30 02:10:07 +00:00
return $o ;
}
2011-06-14 09:54:14 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Prosesses data send by Logs admin page
2017-01-09 12:12:54 +00:00
*
2012-04-18 07:24:47 +00:00
* @ param App $a
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2011-06-14 09:54:14 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_page_logs_post ( App $a )
{
2018-11-30 14:06:22 +00:00
if ( ! empty ( $_POST [ 'page_logs' ])) {
2018-10-17 19:30:41 +00:00
BaseModule :: checkFormSecurityTokenRedirectOnError ( '/admin/logs' , 'admin_logs' );
2011-06-14 09:54:14 +00:00
2018-11-30 14:06:22 +00:00
$logfile = ( ! empty ( $_POST [ 'logfile' ]) ? Strings :: escapeTags ( trim ( $_POST [ 'logfile' ])) : '' );
$debugging = ! empty ( $_POST [ 'debugging' ]);
2019-01-22 06:30:52 +00:00
$loglevel = defaults ( $_POST , 'loglevel' , LogLevel :: ERROR );
2011-06-14 09:54:14 +00:00
2017-11-30 01:28:30 +00:00
Config :: set ( 'system' , 'logfile' , $logfile );
Config :: set ( 'system' , 'debugging' , $debugging );
Config :: set ( 'system' , 'loglevel' , $loglevel );
2011-06-14 09:54:14 +00:00
}
2018-01-21 18:33:59 +00:00
info ( L10n :: t ( " Log settings updated. " ));
2018-10-19 18:11:27 +00:00
$a -> internalRedirect ( 'admin/logs' );
2014-04-29 12:22:37 +00:00
return ; // NOTREACHED
2011-06-14 09:54:14 +00:00
}
2012-04-18 07:24:47 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Generates admin panel subpage for configuration of the logs
2015-12-27 07:23:26 +00:00
*
* This function take the view / templates / admin_logs . tpl file and generates a
* page where admin can configure the logging of friendica .
*
* Displaying the log is separated from the log config as the logfile can get
* big depending on the settings and changing settings regarding the logs can
* thus waste bandwidth .
*
* The string returned contains the content of the template file with replaced
* macros .
*
2012-04-18 07:24:47 +00:00
* @ param App $a
* @ return string
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2012-04-18 07:24:47 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_page_logs ( App $a )
{
2018-01-15 13:05:12 +00:00
$log_choices = [
2019-01-22 06:30:52 +00:00
LogLevel :: ERROR => 'Error' ,
LogLevel :: WARNING => 'Warning' ,
LogLevel :: NOTICE => 'Notice' ,
LogLevel :: INFO => 'Info' ,
LogLevel :: DEBUG => 'Debug' ,
2018-01-15 13:05:12 +00:00
];
2017-01-09 12:12:54 +00:00
2016-09-13 20:52:21 +00:00
if ( ini_get ( 'log_errors' )) {
2018-01-21 18:33:59 +00:00
$phplogenabled = L10n :: t ( 'PHP log currently enabled.' );
2016-09-13 20:52:21 +00:00
} else {
2018-01-21 18:33:59 +00:00
$phplogenabled = L10n :: t ( 'PHP log currently disabled.' );
2016-09-13 20:52:21 +00:00
}
2014-04-29 12:22:37 +00:00
2018-10-31 14:44:06 +00:00
$t = Renderer :: getMarkupTemplate ( 'admin/logs.tpl' );
2011-06-17 05:20:12 +00:00
2018-10-31 14:35:50 +00:00
return Renderer :: replaceMacros ( $t , [
2018-01-21 18:33:59 +00:00
'$title' => L10n :: t ( 'Administration' ),
'$page' => L10n :: t ( 'Logs' ),
'$submit' => L10n :: t ( 'Save Settings' ),
'$clear' => L10n :: t ( 'Clear' ),
2017-08-26 07:32:10 +00:00
'$baseurl' => System :: baseUrl ( true ),
2017-11-30 01:28:30 +00:00
'$logname' => Config :: get ( 'system' , 'logfile' ),
2016-01-17 02:25:17 +00:00
// name, label, value, help string, extra data...
2018-01-21 18:33:59 +00:00
'$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 ],
2018-10-17 19:30:41 +00:00
'$form_security_token' => BaseModule :: getFormSecurityToken ( " admin_logs " ),
2018-01-21 18:33:59 +00:00
'$phpheader' => L10n :: t ( " PHP logging " ),
2018-06-25 00:26:00 +00:00
'$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. " ),
2016-02-17 22:47:32 +00:00
'$phplogcode' => " error_reporting(E_ERROR | E_WARNING | E_PARSE); \n ini_set('error_log','php.out'); \n ini_set('log_errors','1'); \n ini_set('display_errors', '1'); " ,
2016-09-13 20:52:21 +00:00
'$phplogenabled' => $phplogenabled ,
2018-01-15 13:05:12 +00:00
]);
2011-06-14 09:54:14 +00:00
}
2015-12-27 07:23:26 +00:00
/**
2016-01-17 02:25:17 +00:00
* @ brief Generates admin panel subpage to view the Friendica log
2015-12-27 07:23:26 +00:00
*
* This function loads the template view / templates / admin_viewlogs . tpl to
* display the systemlog content . The filename for the systemlog of friendica
* is relative to the base directory and taken from the config entry 'logfile'
* in the 'system' category .
*
* Displaying the log is separated from the log config as the logfile can get
* big depending on the settings and changing settings regarding the logs can
* thus waste bandwidth .
*
* The string returned contains the content of the template file with replaced
* macros .
*
* @ param App $a
* @ return string
2019-01-07 06:07:42 +00:00
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
2015-12-27 07:23:26 +00:00
*/
2017-11-30 01:28:30 +00:00
function admin_page_viewlogs ( App $a )
{
2018-10-31 14:44:06 +00:00
$t = Renderer :: getMarkupTemplate ( 'admin/viewlogs.tpl' );
2017-11-30 01:28:30 +00:00
$f = Config :: get ( 'system' , 'logfile' );
2015-12-27 07:23:26 +00:00
$data = '' ;
2017-03-13 17:23:02 +00:00
if ( ! file_exists ( $f )) {
2018-01-24 21:51:32 +00:00
$data = L10n :: t ( 'Error trying to open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s exist and is readable.' , $f );
2017-03-13 17:23:02 +00:00
} else {
2015-12-27 07:23:26 +00:00
$fp = fopen ( $f , 'r' );
2017-03-13 17:23:02 +00:00
if ( ! $fp ) {
2018-01-24 21:51:32 +00:00
$data = L10n :: t ( 'Couldn\'t open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s is readable.' , $f );
2017-03-13 17:23:02 +00:00
} else {
2015-12-27 07:23:26 +00:00
$fstat = fstat ( $fp );
$size = $fstat [ 'size' ];
2017-03-13 17:23:02 +00:00
if ( $size != 0 ) {
if ( $size > 5000000 || $size < 0 ) {
2015-12-27 07:23:26 +00:00
$size = 5000000 ;
2017-03-13 17:23:02 +00:00
}
2017-11-30 01:28:30 +00:00
$seek = fseek ( $fp , 0 - $size , SEEK_END );
2017-03-13 17:23:02 +00:00
if ( $seek === 0 ) {
2018-11-09 18:27:58 +00:00
$data = Strings :: escapeHtml ( fread ( $fp , $size ));
2017-11-30 01:28:30 +00:00
while ( ! feof ( $fp )) {
2018-11-09 18:27:58 +00:00
$data .= Strings :: escapeHtml ( fread ( $fp , 4096 ));
2017-03-13 17:23:02 +00:00
}
2015-12-27 07:23:26 +00:00
}
}
fclose ( $fp );
}
}
2018-10-31 14:35:50 +00:00
return Renderer :: replaceMacros ( $t , [
2018-01-21 18:33:59 +00:00
'$title' => L10n :: t ( 'Administration' ),
'$page' => L10n :: t ( 'View Logs' ),
2015-12-27 07:23:26 +00:00
'$data' => $data ,
2017-11-30 01:28:30 +00:00
'$logname' => Config :: get ( 'system' , 'logfile' )
2018-01-15 13:05:12 +00:00
]);
2015-12-27 07:23:26 +00:00
}
2016-01-17 02:25:17 +00:00
2018-08-25 22:31:22 +00:00
function admin_page_server_vital ()
{
// Fetch the host-meta to check if this really is a vital server
2018-10-10 19:08:43 +00:00
return Network :: curl ( System :: baseUrl () . '/.well-known/host-meta' ) -> isSuccess ();
2018-08-25 22:31:22 +00:00
}