2016-04-18 02:55:36 +00:00
< ? php
2021-12-03 03:01:39 +00:00
2016-04-18 02:55:36 +00:00
/**
2022-02-16 04:08:28 +00:00
* @ file Code / Module / Admin . php
2016-04-18 02:55:36 +00:00
* @ brief Hubzilla ' s admin controller .
*
* Controller for the / admin / area .
*/
2022-02-16 04:08:28 +00:00
namespace Code\Module ;
2016-10-01 22:41:25 +00:00
2020-09-15 06:58:41 +00:00
use App ;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller ;
use Code\Web\SubModule ;
use Code\Lib\Config ;
use Code\Lib\Channel ;
use Code\Lib\Navbar ;
use Code\Lib\Addon ;
use Code\Render\Theme ;
2022-02-12 20:43:29 +00:00
2022-02-12 08:50:48 +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
*/
2021-12-02 23:02:31 +00:00
class Admin extends Controller
{
private $sm = null ;
public function __construct ()
{
$this -> sm = new SubModule ();
}
public function init ()
{
logger ( 'admin_init' , LOGGER_DEBUG );
if ( ! is_site_admin ()) {
logger ( 'admin denied.' );
return ;
}
if ( argc () > 1 ) {
$this -> sm -> call ( 'init' );
}
}
public function post ()
{
logger ( 'admin_post' , LOGGER_DEBUG );
if ( ! is_site_admin ()) {
logger ( 'admin denied.' );
return ;
}
if ( argc () > 1 ) {
$this -> sm -> call ( 'post' );
}
// goaway(z_root() . '/admin' );
}
/**
* @ return string
*/
public function get ()
{
logger ( 'admin_content' , LOGGER_DEBUG );
if ( ! is_site_admin ()) {
logger ( 'admin denied.' );
return login ( false );
}
/*
* Page content
*/
2022-01-25 04:16:38 +00:00
Navbar :: set_selected ( 'Admin' );
2021-12-02 23:02:31 +00:00
$o = '' ;
if ( argc () > 1 ) {
$o = $this -> sm -> call ( 'get' );
if ( $o === false ) {
notice ( t ( 'Item not found.' ));
}
} else {
$o = $this -> admin_page_summary ();
}
if ( is_ajax ()) {
echo $o ;
killme ();
} else {
return $o ;
}
}
/**
* @ brief Returns content for Admin Summary Page .
*
* @ return string HTML from parsed admin_summary . tpl
*/
public function admin_page_summary ()
{
// list total user accounts, expirations etc.
$accounts = [];
2021-12-03 03:01:39 +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 " ,
2021-12-02 23:02:31 +00:00
db_utcnow (),
db_utcnow (),
dbesc ( NULL_DATE ),
intval ( ACCOUNT_BLOCKED )
);
if ( $r ) {
$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' ]];
}
// pending registrations
2021-12-03 03:01:39 +00:00
$pdg = q (
" SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 " ,
2021-12-02 23:02:31 +00:00
intval ( ACCOUNT_PENDING )
);
$pending = (( $pdg ) ? count ( $pdg ) : 0 );
// available channels, primary and clones
$channels = [];
$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 " );
if ( $r ) {
$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' ]];
}
// 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 = [ 'label' => t ( 'Message queues' ), 'queue' => $queue ];
2022-02-12 08:50:48 +00:00
$plugins = Addon :: list_installed ();
2021-12-02 23:02:31 +00:00
// Could be extended to provide also other alerts to the admin
$alertmsg = '' ;
$upgrade = EMPTY_STR ;
if (( ! defined ( 'PLATFORM_ARCHITECTURE' )) || ( PLATFORM_ARCHITECTURE === 'zap' )) {
$vrelease = get_repository_version ( 'release' );
$vdev = get_repository_version ( 'dev' );
$upgrade = (( version_compare ( STD_VERSION , $vrelease ) < 0 ) ? t ( 'Your software should be updated' ) : '' );
}
2022-02-12 20:43:29 +00:00
$t = Theme :: get_template ( 'admin_summary.tpl' );
2021-12-02 23:02:31 +00:00
return replace_macros ( $t , [
'$title' => t ( 'Administration' ),
'$page' => t ( 'Summary' ),
'$adminalertmsg' => $alertmsg ,
'$queues' => $queues ,
'$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 ],
'$upgrade' => $upgrade ,
'$build' => Config :: Get ( 'system' , 'db_version' )
]);
}
2016-04-18 02:55:36 +00:00
}