summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-01 19:29:14 +0200
committerSimon Rettberg2016-09-01 19:29:14 +0200
commitc7dad7af7974c648ef69e0eb57fab66fea90b36b (patch)
tree948bb6318a4cba0804744bab43cb5aef0bb15079 /modules-available
parent[dozmod] Don't wrap date/time column in table (diff)
downloadslx-admin-c7dad7af7974c648ef69e0eb57fab66fea90b36b.tar.gz
slx-admin-c7dad7af7974c648ef69e0eb57fab66fea90b36b.tar.xz
slx-admin-c7dad7af7974c648ef69e0eb57fab66fea90b36b.zip
[statistics] Show current lecture, use new logging format/columns if possible
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/statistics/api.inc.php44
-rw-r--r--modules-available/statistics/page.inc.php22
-rw-r--r--modules-available/statistics/templates/machine-main.html9
3 files changed, 59 insertions, 16 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index 1cd578d8..5fc57194 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -100,7 +100,7 @@ if ($type{0} === '~') {
. ' macaddr = VALUES(macaddr),'
. ' clientip = VALUES(clientip),'
. ' lastseen = VALUES(lastseen),'
- . ($uptime < 180 ? ' logintime = 0,' : '')
+ . ($uptime < 180 ? ' logintime = 0, currentuser = NULL, currentsession = NULL,' : '')
. ' lastboot = VALUES(lastboot),'
. ' realcores = VALUES(realcores),'
. ' mbram = VALUES(mbram),'
@@ -194,24 +194,42 @@ if ($type{0} === '~') {
* Session information
*/
-if (!isset($_POST['description'])) die('Missing options..');
-$description = $_POST['description'];
-
-
-// For backwards compat, we require the . prefix and username embedded in message
-if ($type{0} === '.' && preg_match('#^\[([^\]]+)\]\s*(.*)$#', $description, $out)) {
-
+function writeStatisticLog($type, $username, $data)
+{
+ global $ip;
// Spam from IP
$row = Database::queryFirst('SELECT Count(*) AS cnt FROM statistic WHERE clientip = :client AND dateline + 300 > UNIX_TIMESTAMP()', array(':client' => $ip));
- if ($row !== false && $row['cnt'] > 4) exit(0);
+ if ($row !== false && $row['cnt'] > 8) {
+ return;
+ }
Database::exec('INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (UNIX_TIMESTAMP(), :type, :client, :username, :data)', array(
- 'type' => $type,
- 'client' => $ip,
- 'username' => $out[1],
- 'data' => $out[2],
+ 'type' => $type,
+ 'client' => $ip,
+ 'username' => $username,
+ 'data' => $data,
));
+}
+// For backwards compat, we require the . prefix
+if ($type{0} === '.') {
+ if ($type === '.vmchooser-session') {
+ $user = Request::post('user', 'unknown', 'string');
+ $loguser = Request::post('loguser', 0, 'int') !== 0;
+ $sessionName = Request::post('name', 'unknown', 'string');
+ $sessionUuid = Request::post('uuid', '', 'string');
+ $session = strlen($sessionUuid) === 36 ? $sessionUuid : $sessionName;
+ Database::exec("UPDATE machine SET currentuser = :user, currentsession = :session WHERE clientip = :ip",
+ compact('user', 'session', 'ip'));
+ writeStatisticLog('.vmchooser-session-name', ($loguser ? $user : 'anonymous'), $sessionName);
+ } else {
+ if (!isset($_POST['description'])) die('Missing options..');
+ $description = $_POST['description'];
+ // and username embedded in message
+ if (preg_match('#^\[([^\]]+)\]\s*(.*)$#m', $description, $out)) {
+ writeStatisticLog($type, $out[1], $out[2]);
+ }
+ }
}
echo "OK.\n";
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index 0639d784..43b3a6e8 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -101,6 +101,11 @@ class Page_Statistics extends Page
'op' => Page_Statistics::$op_nominal,
'type' => 'string',
'column' => false
+ ],
+ 'currentuser' => [
+ 'op' => Page_Statistics::$op_nominal,
+ 'type' => 'string',
+ 'column' => false
]
];
if (Module::isAvailable('locations')) {
@@ -597,7 +602,20 @@ class Page_Statistics extends Page
private function fillSessionInfo(&$row)
{
- $res = Database::simpleQuery('SELECT dateline, username, data FROM statistic'
+ if (!empty($row['currentuser'])) {
+ $row['username'] = $row['currentuser'];
+ if (strlen($row['currentsession']) === 36 && Module::isAvailable('dozmod')) {
+ $lecture = Database::simpleQuery("SELECT lectureid, displayname FROM sat.lecture WHERE lectureid = :lectureid",
+ array('lectureid' => $row['currentsession']));
+ if ($lecture !== false) {
+ $row['currentsession'] = $lecture['displayname'];
+ $row['lectureid'] = $lecture['lectureid'];
+ }
+ }
+ $row['session'] = $row['currentsession'];
+ return;
+ }
+ $res = Database::queryFirst('SELECT dateline, username, data FROM statistic'
. " WHERE clientip = :ip AND typeid = '.vmchooser-session-name'"
. ' AND dateline BETWEEN :start AND :end', array(
'ip' => $row['clientip'],
@@ -619,7 +637,7 @@ class Page_Statistics extends Page
private function showMachine($uuid)
{
$client = Database::queryFirst('SELECT machineuuid, locationid, macaddr, clientip, firstseen, lastseen, logintime, lastboot,'
- . ' mbram, kvmstate, cpumodel, id44mb, data, hostname, notes FROM machine WHERE machineuuid = :uuid',
+ . ' mbram, kvmstate, cpumodel, id44mb, data, hostname, currentuser, currentsession, notes FROM machine WHERE machineuuid = :uuid',
array('uuid' => $uuid));
// Hack: Get raw collected data
if (Request::get('raw', false)) {
diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html
index 333af1ec..0b333a27 100644
--- a/modules-available/statistics/templates/machine-main.html
+++ b/modules-available/statistics/templates/machine-main.html
@@ -66,7 +66,14 @@
<div>{{logintime_s}}</div>
{{/state_occupied}}
{{#session}}
- <div>{{session}}</div>
+ <div>
+ {{#lectureid}}
+ <a href="?do=dozmod&section=actionlog&action=showtarget&uuid={{lectureid}}">{{session}}</a>
+ {{/lectureid}}
+ {{^lectureid}}
+ {{session}}
+ {{/lectureid}}
+ </div>
{{/session}}
</td>
</tr>