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