1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<?php
/**
* @file Zotlabs/Module/Admin.php
* @brief Hubzilla's admin controller.
*
* Controller for the /admin/ area.
*/
namespace Zotlabs\Module;
require_once('include/account.php');
/**
* @brief Admin area.
*
*/
class Admin extends \Zotlabs\Web\Controller {
private $sm = null;
function __construct() {
$this->sm = new \Zotlabs\Web\SubModule();
}
function post(){
logger('admin_post', LOGGER_DEBUG);
if(! is_site_admin()) {
return;
}
if (argc() > 1) {
$this->sm->call('post');
}
goaway(z_root() . '/admin' );
}
/**
* @return string
*/
function get() {
logger('admin_content', LOGGER_DEBUG);
if(! is_site_admin()) {
return login(false);
}
/*
* Page content
*/
nav_set_selected('Admin');
$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();
return '';
}
else {
return $o;
}
}
/**
* @brief Returns content for Admin Summary Page.
*
* @return string HTML from parsed admin_summary.tpl
*/
function admin_page_summary() {
// list total user accounts, expirations etc.
$accounts = array();
$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) {
$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']);
}
// pending registrations
// $pdg = q("SELECT account.*, register.reg_hash from account left join register on account_id = register.reg_uid // where (account_flags & %d ) > 0 ",
// intval(ACCOUNT_PENDING)
// );
$pdg = q("SELECT COUNT(*) AS pdg FROM register WHERE reg_vital = 1 AND reg_expires > '%s' ",
dbesc(date('Y-m-d H:i:s'))
);
$pending = ($pdg ? $pdg[0]['pdg'] : 0);
// available channels, primary and clones
$channels = array();
$r = q("SELECT COUNT(*) AS total FROM channel WHERE channel_removed = 0 and channel_system = 0");
if ($r) {
$channels['total'] = array('label' => t('Channels'), 'val' => $r[0]['total']);
}
// 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 );
// If no plugins active return 0, otherwise list of plugin names
$plugins = (count(\App::$plugins) == 0) ? count(\App::$plugins) : \App::$plugins;
if(is_array($plugins))
sort($plugins);
// Could be extended to provide also other alerts to the admin
$alertmsg = '';
$vmaster = get_repository_version('master');
$vdev = get_repository_version('dev');
$upgrade = ((version_compare(STD_VERSION,$vmaster) < 0) ? t('Your software should be updated') : '');
$t = get_markup_template('admin_summary.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Summary'),
'$adminalertmsg' => $alertmsg,
'$queues' => $queues,
'$accounts' => array( t('Registered accounts'), $accounts),
'$pending' => array( t('Pending registrations'), $pending),
'$channels' => array( t('Registered channels'), $channels),
'$plugins' => array( t('Active addons'), $plugins ),
'$version' => array( t('Version'), STD_VERSION),
'$vmaster' => array( t('Repository version (master)'), $vmaster),
'$vdev' => array( t('Repository version (dev)'), $vdev),
'$upgrade' => $upgrade,
'$build' => get_config('system', 'db_version')
));
}
}
|