915
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
diff
changeset
+ − 5
* Copyright (C) 2006-2009 Dan Fuhry
915
+ − 6
*
+ − 7
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 8
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 9
*
+ − 10
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 11
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 12
*/
+ − 13
+ − 14
function page_Admin_Home()
+ − 15
{
+ − 16
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 17
global $lang;
+ − 18
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
+ − 19
{
+ − 20
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
+ − 21
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
+ − 22
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
+ − 23
return;
+ − 24
}
+ − 25
+ − 26
if ( $paths->getParam(0) == 'updates.xml' )
+ − 27
{
+ − 28
return acphome_process_updates();
+ − 29
}
+ − 30
+ − 31
// Welcome
+ − 32
echo '<h2>' . $lang->get('acphome_heading_main') . '</h2>';
+ − 33
echo '<p>' . $lang->get('acphome_welcome_line1') . '</p>';
+ − 34
+ − 35
// Stats
+ − 36
acphome_show_stats();
+ − 37
+ − 38
//
+ − 39
// Alerts
+ − 40
//
+ − 41
+ − 42
echo '<h3>' . $lang->get('acphome_heading_alerts') . '</h3>';
+ − 43
+ − 44
// Demo mode
+ − 45
if ( defined('ENANO_DEMO_MODE') )
+ − 46
{
+ − 47
echo '<div class="acphome-box info">';
+ − 48
echo '<h3>' . $lang->get('acphome_msg_demo_title') . '</h3>
+ − 49
<p>' . $lang->get('acphome_msg_demo_body', array('reset_url' => makeUrlNS('Special', 'DemoReset', false, true))) . '</p>';
+ − 50
echo '</div>';
+ − 51
}
+ − 52
+ − 53
// Check for the installer scripts
+ − 54
if( file_exists(ENANO_ROOT.'/install/install.php') && !defined('ENANO_DEMO_MODE') )
+ − 55
{
+ − 56
echo '<div class="acphome-box warning">
+ − 57
<h3>' . $lang->get('acphome_msg_install_files_title') . '</h3>
+ − 58
<p>' . $lang->get('acphome_msg_install_files_body') . '</p>
+ − 59
</div>';
+ − 60
}
+ − 61
+ − 62
// Inactive users
+ − 63
$q = $db->sql_query('SELECT time_id FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\';');
+ − 64
if ( $q )
+ − 65
{
+ − 66
if ( $db->numrows() > 0 )
+ − 67
{
+ − 68
$n = $db->numrows();
+ − 69
$um_flags = 'href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'UserManager\'); return false;"';
+ − 70
if ( $n == 1 )
+ − 71
$s = $lang->get('acphome_msg_inactive_users_one', array('um_flags' => $um_flags));
+ − 72
else
1140
+ − 73
$s = $lang->get('acphome_msg_inactive_users_plural', array('um_flags' => $um_flags, 'num_users' => $n));
915
+ − 74
echo '<div class="acphome-box notice">
+ − 75
<h3>' . $lang->get('acphome_heading_inactive_users') . '</h3>
+ − 76
' . $s . '
+ − 77
</div>';
+ − 78
}
+ − 79
}
+ − 80
$db->free_result();
+ − 81
+ − 82
// Update checker
+ − 83
echo '<div class="acphome-box info">';
+ − 84
echo '<h3>' . $lang->get('acphome_heading_updates') . '</h3>';
+ − 85
echo '<p>' . $lang->get('acphome_msg_updates_info', array('updates_url' => 'http://ktulu.enanocms.org/meta/updates.xml')) . '</p>';
+ − 86
echo '<div id="update_check_container"><input type="button" onclick="ajaxUpdateCheck(this.parentNode.id);" value="' . $lang->get('acphome_btn_check_updates') . '" /></div>';
+ − 87
echo '</div>';
+ − 88
+ − 89
// Docs
+ − 90
echo '<div class="acphome-box info halfwidth">';
+ − 91
echo '<h3>' . $lang->get('acphome_heading_docs') . '</h3>';
+ − 92
echo '<p>' . $lang->get('acphome_msg_docs_info') . '</p>';
+ − 93
echo '</div>';
+ − 94
+ − 95
// Support
+ − 96
echo '<div class="acphome-box info halfwidth">';
+ − 97
echo '<h3>' . $lang->get('acphome_heading_support') . '</h3>';
+ − 98
echo '<p>' . $lang->get('acphome_msg_support_info') . '</p>';
+ − 99
echo '</div>';
+ − 100
+ − 101
echo '<span class="menuclear"></span>';
+ − 102
+ − 103
//
+ − 104
// Stats
+ − 105
//
+ − 106
+ − 107
if(getConfig('log_hits') == '1')
+ − 108
{
+ − 109
require_once(ENANO_ROOT . '/includes/stats.php');
+ − 110
$stats = stats_top_pages(10);
+ − 111
//die('<pre>'.print_r($stats,true).'</pre>');
+ − 112
$c = 0;
+ − 113
$cls = 'row2';
+ − 114
echo '<h3>' . $lang->get('acphome_heading_top_pages') . '</h3>
+ − 115
<div class="tblholder">
+ − 116
<table style="width: 100%;" border="0" cellspacing="1" cellpadding="4">
+ − 117
<tr>
+ − 118
<th>' . $lang->get('acphome_th_toppages_page') . '</th>
+ − 119
<th>' . $lang->get('acphome_th_toppages_hits') . '</th>
+ − 120
</tr>';
+ − 121
foreach($stats as $data)
+ − 122
{
+ − 123
echo '<tr>';
+ − 124
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 125
echo '<td class="'.$cls.'">
+ − 126
<a href="'.makeUrl($data['page_urlname']).'">'.$data['page_title'].'</a></td><td style="text-align: center;" class="'.$cls.'">'.$data['num_hits']
+ − 127
. '</td>';
+ − 128
echo '</tr>';
+ − 129
}
+ − 130
echo ' </table>
+ − 131
</div>';
+ − 132
}
+ − 133
+ − 134
// Any hooks?
+ − 135
$code = $plugins->setHook('acp_home');
+ − 136
foreach ( $code as $cmd )
+ − 137
{
+ − 138
eval($cmd);
+ − 139
}
+ − 140
+ − 141
//
+ − 142
// Security log
+ − 143
//
+ − 144
+ − 145
echo '<h3>' . $lang->get('acphome_heading_seclog') . '</h3>';
+ − 146
echo '<p>' . $lang->get('acphome_msg_seclog_info') . '</p>';
+ − 147
$seclog = get_security_log(5);
+ − 148
echo $seclog;
+ − 149
+ − 150
echo '<p><a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'SecurityLog\'); return false;">' . $lang->get('acphome_btn_seclog_full') . '</a></p>';
+ − 151
+ − 152
}
+ − 153
+ − 154
function acphome_process_updates()
+ − 155
{
+ − 156
require_once(ENANO_ROOT . '/includes/http.php');
+ − 157
951
+ − 158
try
+ − 159
{
+ − 160
$req = new Request_HTTP('ktulu.enanocms.org', '/meta/updates.xml');
+ − 161
$response = $req->get_response_body();
+ − 162
header('Content-type: application/xml');
+ − 163
}
+ − 164
catch ( Exception $e )
+ − 165
{
+ − 166
header('Content-type: application/xml');
+ − 167
echo '<enano><error><![CDATA[
+ − 168
Cannot connect to server: ' . $e->getMessage() . '
+ − 169
]]></error></enano>';
+ − 170
return true;
+ − 171
}
915
+ − 172
if ( $req->response_code != HTTP_OK )
+ − 173
{
+ − 174
// Error in response
951
+ − 175
echo '<enano><error><![CDATA[
915
+ − 176
Did not properly receive response from server. Response code: ' . $req->response_code . ' ' . $req->response_string . '
951
+ − 177
]]></error></enano>';
915
+ − 178
}
+ − 179
else
+ − 180
{
+ − 181
// Retrieve first update
+ − 182
$first_update = preg_match('/<release tag="([^"]+)" version="([^"]+)" (codename="([^"]+)" )?relnotes="([^"]+)" ?\/>/', $response, $match);
+ − 183
if ( !$first_update )
+ − 184
{
951
+ − 185
echo '<enano><error><![CDATA[
915
+ − 186
Received invalid XML response.
951
+ − 187
]]></error></enano>';
915
+ − 188
}
+ − 189
else
+ − 190
{
+ − 191
if ( version_compare(enano_version(true), $match[2], '<') )
+ − 192
{
+ − 193
$response = str_replace_once('</latest>', " <haveupdates />\n </latest>", $response);
+ − 194
}
+ − 195
echo $response;
+ − 196
}
+ − 197
}
+ − 198
return true;
+ − 199
}
+ − 200
+ − 201
function acphome_show_stats()
+ − 202
{
+ − 203
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 204
global $lang;
+ − 205
+ − 206
// Page count
+ − 207
$q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "pages");
+ − 208
if ( !$q )
+ − 209
$db->_die();
+ − 210
list($page_count) = $db->fetchrow_num();
+ − 211
$db->free_result();
+ − 212
+ − 213
// Edits per day
+ − 214
$q = $db->sql_query('SELECT ( COUNT(*) - 1 ) AS edit_count, MIN(time_id) AS install_date FROM ' . table_prefix . 'logs WHERE ( log_type = \'page\' AND action = \'edit\' ) OR ( log_type = \'security\' AND action = \'install_enano\' );');
+ − 215
if ( !$q )
+ − 216
$db->_die();
+ − 217
$edit_info = $db->fetchrow();
+ − 218
$install_date =& $edit_info['install_date'];
+ − 219
$db->free_result();
+ − 220
+ − 221
$days_installed = round( (time() / 86400) - ($install_date / 86400) );
916
+ − 222
if ( $days_installed < 1 )
+ − 223
$days_installed = 1;
915
+ − 224
+ − 225
// Comments
+ − 226
$q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "comments");
+ − 227
if ( !$q )
+ − 228
$db->_die();
+ − 229
list($comment_count) = $db->fetchrow_num();
+ − 230
$db->free_result();
+ − 231
+ − 232
// Users
+ − 233
$q = $db->sql_query('SELECT ( COUNT(*) - 1 ) FROM ' . table_prefix . "users");
+ − 234
if ( !$q )
+ − 235
$db->_die();
+ − 236
list($user_count) = $db->fetchrow_num();
+ − 237
$db->free_result();
+ − 238
+ − 239
// Cache size
+ − 240
$cache_size = 0;
+ − 241
if ( $dr = @opendir(ENANO_ROOT . '/cache/') )
+ − 242
{
+ − 243
while ( $dh = @readdir($dr) )
+ − 244
{
+ − 245
$file = ENANO_ROOT . "/cache/$dh";
+ − 246
if ( @is_file($file) )
+ − 247
$cache_size += filesize($file);
+ − 248
}
+ − 249
closedir($dr);
+ − 250
}
+ − 251
$cache_size = humanize_filesize($cache_size);
+ − 252
+ − 253
// Files directory size
+ − 254
$files_size = 0;
+ − 255
if ( $dr = @opendir(ENANO_ROOT . '/files/') )
+ − 256
{
+ − 257
while ( $dh = @readdir($dr) )
+ − 258
{
+ − 259
$file = ENANO_ROOT . "/files/$dh";
+ − 260
if ( @is_file($file) )
+ − 261
$files_size += filesize($file);
+ − 262
}
+ − 263
closedir($dr);
+ − 264
}
+ − 265
$files_size = humanize_filesize($files_size);
+ − 266
+ − 267
// Avatar directory size
+ − 268
$avatar_size = 0;
+ − 269
if ( $dr = @opendir(ENANO_ROOT . '/files/avatars/') )
+ − 270
{
+ − 271
while ( $dh = @readdir($dr) )
+ − 272
{
+ − 273
$file = ENANO_ROOT . "/files/avatars/$dh";
+ − 274
if ( @is_file($file) )
+ − 275
$avatar_size += filesize($file);
+ − 276
}
+ − 277
closedir($dr);
+ − 278
}
+ − 279
$avatar_size = humanize_filesize($avatar_size);
+ − 280
+ − 281
// Database size
+ − 282
$db_size = $lang->get('acphome_stat_dbsize_unsupported');
+ − 283
if ( ENANO_DBLAYER == 'MYSQL' )
+ − 284
{
+ − 285
$q = $db->sql_query('SHOW TABLE STATUS;');
+ − 286
if ( $q )
+ − 287
{
+ − 288
$db_size = 0;
+ − 289
while ( $row = $db->fetchrow() )
+ − 290
{
+ − 291
if ( preg_match('/^' . table_prefix . '/', $row['Name']) )
+ − 292
{
+ − 293
$db_size += $row['Data_length'] + $row['Index_length'];
+ − 294
}
+ − 295
}
+ − 296
$db_size = humanize_filesize($db_size);
+ − 297
}
+ − 298
}
+ − 299
else if ( ENANO_DBLAYER == 'PGSQL' )
+ − 300
{
+ − 301
require(ENANO_ROOT . '/config.php');
+ − 302
global $dbname, $dbuser, $dbpasswd;
+ − 303
$dbuser = false;
+ − 304
$dbpasswd = false;
+ − 305
+ − 306
$q = $db->sql_query('SELECT pg_database_size(\'' . $db->escape($dbname) . '\');');
+ − 307
if ( $q )
+ − 308
{
+ − 309
list($db_size) = $db->fetchrow_num();
+ − 310
$db_size = humanize_filesize($db_size);
+ − 311
$db->free_result();
+ − 312
}
+ − 313
}
+ − 314
+ − 315
// Install date
+ − 316
$install_date_human = MemberlistFormatter::format_date($install_date);
+ − 317
+ − 318
// Last upgrade
+ − 319
$q = $db->sql_query('SELECT time_id FROM ' . table_prefix . "logs WHERE log_type = 'security' AND action = 'upgrade_enano' ORDER BY time_id DESC LIMIT 1;");
+ − 320
if ( !$q )
+ − 321
$db->_die();
+ − 322
+ − 323
if ( $db->numrows() < 1 )
+ − 324
{
+ − 325
$last_upgrade = $lang->get('acphome_stat_lastupdate_never');
+ − 326
}
+ − 327
else
+ − 328
{
+ − 329
list($last_upgrade) = $db->fetchrow_num();
+ − 330
$last_upgrade = MemberlistFormatter::format_date($last_upgrade);
+ − 331
}
+ − 332
$db->free_result();
+ − 333
+ − 334
?>
+ − 335
<div class="tblholder">
+ − 336
<table border="0" cellspacing="1" cellpadding="4">
+ − 337
<tr>
+ − 338
<th colspan="4">
+ − 339
<?php echo $lang->get('acphome_stat_header'); ?>
+ − 340
</th>
+ − 341
</tr>
+ − 342
+ − 343
<tr>
+ − 344
<td class="row2" style="width: 25%;">
+ − 345
<?php echo $lang->get('acphome_stat_numpages'); ?>
+ − 346
</td>
+ − 347
<td class="row1" style="width: 25%;">
+ − 348
<?php echo strval($page_count); ?>
+ − 349
</td>
+ − 350
<td class="row2" style="width: 25%;">
+ − 351
<?php echo $lang->get('acphome_stat_edits'); ?>
+ − 352
</td>
+ − 353
<td class="row1" style="width: 25%;">
+ − 354
<?php echo $lang->get('acphome_stat_edits_data', array('edit_count' => $edit_info['edit_count'], 'per_day' => number_format($edit_info['edit_count'] / $days_installed, 2))); ?>
+ − 355
</td>
+ − 356
</tr>
+ − 357
+ − 358
<tr>
+ − 359
<td class="row2" style="width: 25%;">
+ − 360
<?php echo $lang->get('acphome_stat_comments'); ?>
+ − 361
</td>
+ − 362
<td class="row1" style="width: 25%;">
+ − 363
<?php echo $lang->get('acphome_stat_comments_data', array('comment_count' => $comment_count, 'per_day' => number_format($comment_count / $days_installed, 2))); ?>
+ − 364
</td>
+ − 365
<td class="row2" style="width: 25%;">
+ − 366
<?php echo $lang->get('acphome_stat_users'); ?>
+ − 367
</td>
+ − 368
<td class="row1" style="width: 25%;">
+ − 369
<?php echo strval($user_count); ?>
+ − 370
</td>
+ − 371
</tr>
+ − 372
+ − 373
<tr>
+ − 374
<td class="row2" style="width: 25%;">
+ − 375
<?php echo $lang->get('acphome_stat_filesize'); ?>
+ − 376
</td>
+ − 377
<td class="row1" style="width: 25%;">
+ − 378
<?php echo $files_size; ?>
+ − 379
</td>
+ − 380
<td class="row2" style="width: 25%;">
+ − 381
<?php echo $lang->get('acphome_stat_cachesize'); ?>
+ − 382
</td>
+ − 383
<td class="row1" style="width: 25%;">
+ − 384
<?php echo $cache_size; ?>
+ − 385
</td>
+ − 386
</tr>
+ − 387
+ − 388
<tr>
+ − 389
<td class="row2" style="width: 25%;">
+ − 390
<?php echo $lang->get('acphome_stat_avatarsize'); ?>
+ − 391
</td>
+ − 392
<td class="row1" style="width: 25%;">
+ − 393
<?php echo $avatar_size; ?>
+ − 394
</td>
+ − 395
<td class="row2" style="width: 25%;">
+ − 396
<?php echo $lang->get('acphome_stat_dbsize'); ?>
+ − 397
</td>
+ − 398
<td class="row1" style="width: 25%;">
+ − 399
<?php echo $db_size; ?>
+ − 400
</td>
+ − 401
</tr>
+ − 402
+ − 403
<tr>
+ − 404
<td class="row2" style="width: 25%;">
+ − 405
<?php echo $lang->get('acphome_stat_installdate'); ?>
+ − 406
</td>
+ − 407
<td class="row1" style="width: 25%;">
+ − 408
<?php echo $install_date_human; ?>
+ − 409
</td>
+ − 410
<td class="row2" style="width: 25%;">
+ − 411
<?php echo $lang->get('acphome_stat_lastupdate'); ?>
+ − 412
</td>
+ − 413
<td class="row1" style="width: 25%;">
+ − 414
<?php echo $last_upgrade; ?>
+ − 415
</td>
+ − 416
</tr>
+ − 417
+ − 418
<tr>
+ − 419
<th colspan="4" class="subhead systemversion">
+ − 420
<?php echo $lang->get('acphome_stat_enano_version', array(
+ − 421
'version' => enano_version(true),
+ − 422
'releasename' => enano_codename(),
+ − 423
'aboutlink' => makeUrlNS('Special', 'About_Enano')
+ − 424
)); ?>
+ − 425
</th>
+ − 426
</tr>
+ − 427
+ − 428
</table>
+ − 429
</div>
+ − 430
<?php
+ − 431
}