1
0

New module to examine active sessions

This commit is contained in:
Bharat Mediratta 2012-02-05 16:38:05 -08:00
parent 228946e98c
commit 32b620f33a
4 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Session_Explorer_Controller extends Admin_Controller {
public function index() {
list($uas, $ips) = $this->get_uas_and_ips();
$view = new Admin_View("admin.html");
$view->page_title = t("Akismet spam filtering");
$view->content = new View("admin_session_explorer.html");
$view->content->uas = $uas;
$view->content->ips = $ips;
print $view;
}
private function get_uas_and_ips() {
$uas = array();
$ips = array();
$d = new Session_Database_Driver();
foreach (db::build()
->select("session_id")
->from("sessions")
->execute() as $r) {
$data = explode("|", $d->read($r->session_id));
$ua = unserialize($data[4]);
$ip = unserialize($data[5]);
if (!isset($uas[$ua])) {
$uas[$ua] = 0;
}
if (!isset($ips[$ip])) {
$ips[$ip] = 0;
}
$uas[$ua]++;
$ips[$ip]++;
}
arsort($uas);
arsort($ips);
// Top 20 only
array_splice($uas, 20);
array_splice($ips, 20);
return array($uas, $ips);
}
}

View File

@ -0,0 +1,29 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class session_explorer_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("statistics_menu")
->append(Menu::factory("link")
->id("session_explorer")
->label(t("Explore sessions"))
->url(url::site("admin/session_explorer")));
}
}

View File

@ -0,0 +1,7 @@
name = "Session Explorer"
description = "Explore the sessions currently active in your Gallery"
version = 1
author_name = "Gallery Team"
author_url = "http://codex.gallery2.org/Gallery:Team"
info_url = "http://codex.gallery2.org/Gallery3:Modules:session_explorer"
discuss_url = "http://gallery.menalto.com/forum_module_session_explorer"

View File

@ -0,0 +1,44 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="g-admin-session-explorer" class="g-block">
<h1> <?= t("Top user agents and ips") ?> </h1>
<div class="g-block-content">
<h2> <?= t("User agents") ?> </h2>
<table>
<tr>
<th> <?= t("Rank") ?> </th>
<th> <?= t("Count") ?> </th>
<th> <?= t("User agent") ?> </th>
</tr>
<? foreach ($uas as $ua => $count): ?>
<? $rank = 0; ?>
<tr class="<?= text::alternate("g-odd", "g-even") ?>">
<td> <?= ++$rank ?> </td>
<td> <?= $count ?> </td>
<td> <?= $ua ?> </td>
</tr>
<? endforeach ?>
</table>
</div>
<div class="g-block-content">
<h2> <?= t("Internet addresses") ?> </h2>
<table>
<tr>
<th> <?= t("Rank") ?> </th>
<th> <?= t("Count") ?> </th>
<th> <?= t("Internet address") ?> </th>
</tr>
<? foreach ($ips as $ip => $count): ?>
<? $rank = 0; ?>
<tr class="<?= text::alternate("g-odd", "g-even") ?>">
<td> <?= ++$rank ?> </td>
<td> <?= $count ?> </td>
<td> <?= $ip ?> </td>
</tr>
<? endforeach ?>
</table>
</div>
</div>