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 ;
2016-04-18 02:55:36 +00:00
require_once ( 'include/queue_fn.php' );
require_once ( 'include/account.php' );
/**
2016-10-01 22:41:25 +00:00
* @ brief Admin area .
*
2016-04-18 02:55:36 +00:00
*/
class Admin extends \Zotlabs\Web\Controller {
2016-09-06 01:11:00 +00:00
private $sm = null ;
function __construct () {
2016-09-06 01:16:29 +00:00
$this -> sm = new \Zotlabs\Web\SubModule ();
2016-09-06 01:11:00 +00:00
}
2016-04-18 02:55:36 +00:00
function post (){
logger ( 'admin_post' , LOGGER_DEBUG );
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
if ( ! is_site_admin ()) {
return ;
}
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
2016-04-18 02:55:36 +00:00
goaway ( z_root () . '/admin' );
}
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
2016-04-18 02:55:36 +00:00
if ( ! is_site_admin ()) {
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
2016-09-06 04:00:00 +00:00
if ( argc () > 1 ) {
$o = $this -> sm -> call ( 'get' );
if ( $o === false ) {
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
2016-04-18 02:55:36 +00:00
if ( is_ajax ()) {
2016-10-01 22:41:25 +00:00
echo $o ;
2016-04-18 02:55:36 +00:00
killme ();
return '' ;
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
*/
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.
$accounts = array ();
2016-09-26 00:06:13 +00:00
$r = q ( " SELECT COUNT(*) 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 ) {
2017-06-27 05:42:01 +00:00
$accounts [ 'total' ] = array ( 'label' => t ( 'Accounts' ), 'val' => $r [ 0 ][ 'total' ]);
$accounts [ 'blocked' ] = array ( 'label' => t ( 'Blocked accounts' ), 'val' => $r [ 0 ][ 'blocked' ]);
$accounts [ 'expired' ] = array ( 'label' => t ( 'Expired accounts' ), 'val' => $r [ 0 ][ 'expired' ]);
$accounts [ 'expiring' ] = array ( '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
2016-10-04 02:47:36 +00:00
$r = q ( " SELECT COUNT(id) AS rtotal FROM register WHERE uid != '0' " );
$pending = $r [ 0 ][ 'rtotal' ];
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// available channels, primary and clones
$channels = array ();
$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 " );
if ( $r ) {
2017-06-27 05:42:01 +00:00
$channels [ 'total' ] = array ( 'label' => t ( 'Channels' ), 'val' => $r [ 0 ][ 'total' ]);
$channels [ 'main' ] = array ( 'label' => t ( 'Primary' ), 'val' => $r [ 0 ][ 'main' ]);
$channels [ 'clones' ] = array ( '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 );
$queues = array ( 'label' => t ( 'Message queues' ), 'queue' => $queue );
2016-10-01 22:41:25 +00:00
2016-04-18 02:55:36 +00:00
// If no plugins active return 0, otherwise list of plugin names
$plugins = ( count ( \App :: $plugins ) == 0 ) ? count ( \App :: $plugins ) : \App :: $plugins ;
2016-10-01 22:41:25 +00:00
2017-06-27 05:42:01 +00:00
if ( is_array ( $plugins ))
sort ( $plugins );
2016-04-18 02:55:36 +00:00
// Could be extended to provide also other alerts to the admin
$alertmsg = '' ;
2016-05-11 04:46:04 +00:00
$vmaster = get_repository_version ( 'master' );
$vdev = get_repository_version ( 'dev' );
$upgrade = (( version_compare ( STD_VERSION , $vmaster ) < 0 ) ? t ( 'Your software should be updated' ) : '' );
2016-04-18 02:55:36 +00:00
$t = get_markup_template ( 'admin_summary.tpl' );
return replace_macros ( $t , array (
'$title' => t ( 'Administration' ),
'$page' => t ( 'Summary' ),
'$adminalertmsg' => $alertmsg ,
2016-05-11 04:46:04 +00:00
'$queues' => $queues ,
2016-04-18 02:55:36 +00:00
'$accounts' => array ( t ( 'Registered accounts' ), $accounts ),
2016-05-11 04:46:04 +00:00
'$pending' => array ( t ( 'Pending registrations' ), $pending ),
2016-04-18 02:55:36 +00:00
'$channels' => array ( t ( 'Registered channels' ), $channels ),
2016-05-11 04:46:04 +00:00
'$plugins' => array ( t ( 'Active plugins' ), $plugins ),
'$version' => array ( t ( 'Version' ), STD_VERSION ),
'$vmaster' => array ( t ( 'Repository version (master)' ), $vmaster ),
'$vdev' => array ( t ( 'Repository version (dev)' ), $vdev ),
'$upgrade' => $upgrade ,
2016-10-01 22:41:25 +00:00
'$build' => get_config ( '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
}