2016-04-18 02:55:36 +00:00
< ? php
/**
2016-10-01 22:41:25 +00:00
* @ file Zotlabs / Module / Admin . php
2016-04-18 02:55:36 +00:00
* @ brief Hubzilla ' s admin controller .
*
* Controller for the / admin / area .
*/
2016-10-01 22:41:25 +00:00
namespace Zotlabs\Module ;
2020-09-15 06:58:41 +00:00
use App ;
use Zotlabs\Web\Controller ;
use Zotlabs\Web\SubModule ;
use Zotlabs\Lib\Config ;
2018-07-03 05:43:41 +00:00
2016-04-18 02:55:36 +00:00
/**
2016-10-01 22:41:25 +00:00
* @ brief Admin area .
*
2016-04-18 02:55:36 +00:00
*/
2020-09-15 06:58:41 +00:00
class Admin extends Controller {
2016-04-18 02:55:36 +00:00
2016-09-06 01:11:00 +00:00
private $sm = null ;
function __construct () {
2020-09-15 06:58:41 +00:00
$this -> sm = new SubModule ();
2016-09-06 01:11:00 +00:00
}
2020-09-15 06:58:41 +00:00
function init () {
logger ( 'admin_init' , LOGGER_DEBUG );
2020-09-15 06:11:49 +00:00
2020-09-15 06:58:41 +00:00
if ( ! is_site_admin ()) {
return ;
}
if ( argc () > 1 ) {
$this -> sm -> call ( 'init' );
}
}
2020-09-15 06:11:49 +00:00
2020-09-15 02:23:18 +00:00
2020-09-15 06:58:41 +00:00
function post () {
2020-09-15 02:23:18 +00:00
2016-04-18 02:55:36 +00:00
logger ( 'admin_post' , LOGGER_DEBUG );
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
if ( ! is_site_admin ()) {
2016-04-18 02:55:36 +00:00
return ;
}
2020-09-15 06:58:41 +00:00
2016-04-18 02:55:36 +00:00
if ( argc () > 1 ) {
2016-09-06 04:00:00 +00:00
$this -> sm -> call ( 'post' );
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2020-09-17 01:03:14 +00:00
// goaway(z_root() . '/admin' );
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
/**
* @ return string
*/
2016-09-06 04:00:00 +00:00
2016-05-11 04:46:04 +00:00
function get () {
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
logger ( 'admin_content' , LOGGER_DEBUG );
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
if ( ! is_site_admin ()) {
2016-04-18 02:55:36 +00:00
return login ( false );
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
/*
* Page content
*/
2016-09-06 04:00:00 +00:00
2017-07-21 08:32:21 +00:00
nav_set_selected ( 'Admin' );
2016-04-18 02:55:36 +00:00
$o = '' ;
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
if ( argc () > 1 ) {
2016-09-06 04:00:00 +00:00
$o = $this -> sm -> call ( 'get' );
2020-09-15 06:58:41 +00:00
if ( $o === false ) {
2016-09-06 04:00:00 +00:00
notice ( t ( 'Item not found.' ) );
2016-04-18 02:55:36 +00:00
}
2016-09-05 05:42:13 +00:00
}
else {
2016-09-06 04:08:40 +00:00
$o = $this -> admin_page_summary ();
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
if ( is_ajax ()) {
2016-10-01 22:41:25 +00:00
echo $o ;
2016-04-18 02:55:36 +00:00
killme ();
2016-09-05 05:42:13 +00:00
}
else {
2016-04-18 02:55:36 +00:00
return $o ;
}
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
/**
* @ brief Returns content for Admin Summary Page .
*
* @ return string HTML from parsed admin_summary . tpl
*/
2020-09-15 06:58:41 +00:00
2016-09-06 04:08:40 +00:00
function admin_page_summary () {
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// list total user accounts, expirations etc.
2020-09-15 06:58:41 +00:00
$accounts = [];
2019-02-18 05:45:31 +00:00
$r = q ( " SELECT COUNT(CASE WHEN account_id > 0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account " ,
2016-04-18 02:55:36 +00:00
db_utcnow (),
db_utcnow (),
dbesc ( NULL_DATE ),
intval ( ACCOUNT_BLOCKED )
);
if ( $r ) {
2020-09-15 06:58:41 +00:00
$accounts [ 'total' ] = [ 'label' => t ( 'Accounts' ), 'val' => $r [ 0 ][ 'total' ] ];
$accounts [ 'blocked' ] = [ 'label' => t ( 'Blocked accounts' ), 'val' => $r [ 0 ][ 'blocked' ] ];
$accounts [ 'expired' ] = [ 'label' => t ( 'Expired accounts' ), 'val' => $r [ 0 ][ 'expired' ] ];
$accounts [ 'expiring' ] = [ 'label' => t ( 'Expiring accounts' ), 'val' => $r [ 0 ][ 'expiring' ] ];
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// pending registrations
2018-05-19 07:54:47 +00:00
$pdg = q ( " SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 " ,
intval ( ACCOUNT_PENDING )
);
$pending = (( $pdg ) ? count ( $pdg ) : 0 );
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// available channels, primary and clones
$channels = array ();
2018-09-01 11:43:32 +00:00
$r = q ( " SELECT COUNT(*) AS total, COUNT(CASE WHEN channel_primary = 1 THEN 1 ELSE NULL END) AS main, COUNT(CASE WHEN channel_primary = 0 THEN 1 ELSE NULL END) AS clones FROM channel WHERE channel_removed = 0 and channel_system = 0 " );
2016-04-18 02:55:36 +00:00
if ( $r ) {
2020-09-15 06:58:41 +00:00
$channels [ 'total' ] = [ 'label' => t ( 'Channels' ), 'val' => $r [ 0 ][ 'total' ] ];
$channels [ 'main' ] = [ 'label' => t ( 'Primary' ), 'val' => $r [ 0 ][ 'main' ] ];
$channels [ 'clones' ] = [ 'label' => t ( 'Clones' ), 'val' => $r [ 0 ][ 'clones' ] ];
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// We can do better, but this is a quick queue status
$r = q ( " SELECT COUNT(outq_delivered) AS total FROM outq WHERE outq_delivered = 0 " );
$queue = (( $r ) ? $r [ 0 ][ 'total' ] : 0 );
2020-09-15 06:58:41 +00:00
$queues = [ 'label' => t ( 'Message queues' ), 'queue' => $queue ];
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
$plugins = [];
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
if ( is_array ( App :: $plugins ) && App :: $plugins ) {
foreach ( App :: $plugins as $p ) {
if ( $p ) {
$plugins [] = $p ;
}
}
2017-06-27 05:42:01 +00:00
sort ( $plugins );
2020-09-15 06:58:41 +00:00
}
else {
$plugins = 0 ;
}
2017-06-27 05:42:01 +00:00
2016-04-18 02:55:36 +00:00
// Could be extended to provide also other alerts to the admin
2018-08-24 00:31:41 +00:00
2016-04-18 02:55:36 +00:00
$alertmsg = '' ;
2016-05-11 04:46:04 +00:00
2018-08-24 00:31:41 +00:00
$upgrade = EMPTY_STR ;
2020-09-15 06:58:41 +00:00
if (( ! defined ( 'PLATFORM_ARCHITECTURE' )) || ( PLATFORM_ARCHITECTURE === 'zap' )) {
2020-06-16 03:54:54 +00:00
$vrelease = get_repository_version ( 'release' );
2018-08-24 00:31:41 +00:00
$vdev = get_repository_version ( 'dev' );
2020-06-16 03:54:54 +00:00
$upgrade = (( version_compare ( STD_VERSION , $vrelease ) < 0 ) ? t ( 'Your software should be updated' ) : '' );
2018-08-24 00:31:41 +00:00
}
2016-05-11 04:46:04 +00:00
2016-04-18 02:55:36 +00:00
$t = get_markup_template ( 'admin_summary.tpl' );
2020-09-15 06:58:41 +00:00
return replace_macros ( $t , [
2016-04-18 02:55:36 +00:00
'$title' => t ( 'Administration' ),
'$page' => t ( 'Summary' ),
'$adminalertmsg' => $alertmsg ,
2016-05-11 04:46:04 +00:00
'$queues' => $queues ,
2020-09-15 06:58:41 +00:00
'$accounts' => [ t ( 'Registered accounts' ), $accounts ],
'$pending' => [ t ( 'Pending registrations' ), $pending ],
'$channels' => [ t ( 'Registered channels' ), $channels ],
'$plugins' => (( $plugins ) ? [ t ( 'Active addons' ), $plugins ] : EMPTY_STR ),
'$version' => [ t ( 'Version' ), STD_VERSION ],
'$vmaster' => [ t ( 'Repository version (release)' ), $vrelease ],
'$vdev' => [ t ( 'Repository version (dev)' ), $vdev ],
2016-05-11 04:46:04 +00:00
'$upgrade' => $upgrade ,
2020-09-15 06:58:41 +00:00
'$build' => Config :: Get ( 'system' , 'db_version' )
]);
2016-04-18 02:55:36 +00:00
}
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
}