streams/Zotlabs/Module/Admin.php

192 lines
4.7 KiB
PHP
Raw Normal View History

<?php
/**
* @file Zotlabs/Module/Admin.php
* @brief Hubzilla's admin controller.
*
* Controller for the /admin/ area.
*/
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
/**
* @brief Admin area.
*
*/
2020-09-15 06:58:41 +00:00
class Admin extends Controller {
private $sm = null;
function __construct() {
2020-09-15 06:58:41 +00:00
$this->sm = new SubModule();
}
2020-09-15 06:58:41 +00:00
function init() {
logger('admin_init', LOGGER_DEBUG);
2020-09-15 06:58:41 +00:00
if (! is_site_admin()) {
2020-12-22 03:23:58 +00:00
logger('admin denied.');
2020-09-15 06:58:41 +00:00
return;
}
if (argc() > 1) {
$this->sm->call('init');
}
}
2020-09-15 06:58:41 +00:00
function post() {
logger('admin_post', LOGGER_DEBUG);
2020-09-15 06:58:41 +00:00
if (! is_site_admin()) {
2020-12-22 03:23:58 +00:00
logger('admin denied.');
return;
}
2020-09-15 06:58:41 +00:00
if (argc() > 1) {
$this->sm->call('post');
}
2020-09-17 01:03:14 +00:00
// goaway(z_root() . '/admin' );
}
/**
* @return string
*/
function get() {
logger('admin_content', LOGGER_DEBUG);
2020-09-15 06:58:41 +00:00
if (! is_site_admin()) {
2020-12-22 03:23:58 +00:00
logger('admin denied.');
return login(false);
}
/*
* Page content
*/
nav_set_selected('Admin');
$o = '';
2020-09-15 06:58:41 +00:00
if (argc() > 1) {
$o = $this->sm->call('get');
2020-09-15 06:58:41 +00:00
if ($o === false) {
notice( t('Item not found.') );
}
}
else {
2016-09-06 04:08:40 +00:00
$o = $this->admin_page_summary();
}
2020-09-15 06:58:41 +00:00
if (is_ajax()) {
echo $o;
killme();
}
else {
return $o;
}
}
/**
* @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() {
// 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",
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'] ];
}
// pending registrations
$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);
// available channels, primary and clones
$channels = [];
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");
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'] ];
}
// 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 ];
2020-09-15 06:58:41 +00:00
$plugins = [];
2020-09-15 06:58:41 +00:00
if (is_array(App::$plugins) && App::$plugins) {
foreach (App::$plugins as $p) {
if ($p) {
$plugins[] = $p;
}
}
sort($plugins);
2020-09-15 06:58:41 +00:00
}
else {
$plugins = 0;
}
// Could be extended to provide also other alerts to the admin
2018-08-24 00:31:41 +00:00
$alertmsg = '';
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
}
$t = get_markup_template('admin_summary.tpl');
2020-09-15 06:58:41 +00:00
return replace_macros($t, [
'$title' => t('Administration'),
'$page' => t('Summary'),
'$adminalertmsg' => $alertmsg,
'$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 ],
'$upgrade' => $upgrade,
2020-09-15 06:58:41 +00:00
'$build' => Config::Get('system', 'db_version')
]);
}
}