From 05c66cf09734829c3249186c9e11529698f75eee Mon Sep 17 00:00:00 2001 From: Robert Anderson <randerson@lbsd.net> Date: Thu, 14 May 2009 12:05:31 +0000 Subject: [PATCH] AdminUserLogs and related functions, EventTimestamp display and search needs fixing --- webgui/ajax.php | 111 ++---------------- .../include/ajax/functions/AdminUserLogs.php | 107 +++++++++++++++++ webgui/js/app/windows/AdminUserLogs.js | 51 ++++---- 3 files changed, 145 insertions(+), 124 deletions(-) create mode 100644 webgui/include/ajax/functions/AdminUserLogs.php diff --git a/webgui/ajax.php b/webgui/ajax.php index 47d5e382..676393cb 100644 --- a/webgui/ajax.php +++ b/webgui/ajax.php @@ -6,6 +6,7 @@ include_once("include/ajax/functions/AdminUsers.php"); include_once("include/ajax/functions/AdminUserAttributes.php"); include_once("include/ajax/functions/AdminUserGroups.php"); + include_once("include/ajax/functions/AdminUserLogs.php"); include_once("include/ajax/functions/AdminGroups.php"); include_once("include/ajax/functions/AdminGroupAttributes.php"); @@ -18,6 +19,8 @@ include_once("include/ajax/functions/WiSPLocationMembers.php"); include_once("include/ajax/functions/WiSPUsers.php"); + include_once("include/radiuscodes.php"); + define('RES_OK',0); define('RES_ERR',-1); @@ -156,6 +159,7 @@ } } + switch ($function) { # AdminGroupMembers.js functions @@ -188,22 +192,27 @@ # AdminUserLogs.js functions case "getAdminUserLogs": - $rawData = getAdminUserLogs($soapParams); + $res = getAdminUserLogs($soapParams); + $rawData = $res[0]; $numResults = $res[1]; $res = new json_response; $res->setID('ID'); $res->addField('ID','int'); + $res->addField('EventTimestamp','int'); $res->addField('AcctStatusType','int'); $res->addField('ServiceType','int'); $res->addField('FramedProtocol','int'); - $res->addField('NASPort','string'); $res->addField('NASPortType','int'); $res->addField('NASPortID','string'); $res->addField('CallingStationID','string'); $res->addField('CalledStationID','string'); $res->addField('AcctSessionID','string'); $res->addField('FramedIPAddress','string'); - $res->parseHash($rawData); + $res->addField('AcctInputMbyte','int'); + $res->addField('AcctOutputMbyte','int'); + $res->addField('ConnectTermReason','string'); + $res->parseArray($rawData); + $res->setDatasetSize($numResults); echo json_encode($res->export()); @@ -774,103 +783,9 @@ echo json_encode($res->export()); break; - case "getWiSPUsers": - - $rawData = array ( - - array( - 'ID' => 10, - 'AgentID' => 5, - 'AgentName' => 'joe agent', - 'Username' => 'johnsmith', - 'UsageCap' => 1000, - 'ClassID' => 7, - 'ClassDesc' => 'ClassTest', - 'RealmDesc' => 'My Realm', - 'Service' => 'My Service', - 'AgentDisabled' => FALSE, - 'Disabled' => FALSE, - 'AgentRef' => 'Reseller ref' - ) - ); - - $numResults = 1; - - $res = new json_response; - $res->setID('ID'); - $res->addField('ID','int'); - $res->addField('AgentID','int'); - $res->addField('AgentName','string'); - $res->addField('Username','string'); - $res->addField('UsageCap','int'); - $res->addField('ClassID','int'); - $res->addField('ClassDesc','string'); - $res->addField('RealmDesc','string'); - $res->addField('Service','string'); - $res->addField('AgentDisabled','boolean'); - $res->addField('Disabled','boolean'); - $res->addField('AgentRef','string'); - $res->parseArray($rawData); - $res->setDatasetSize($numResults); - - echo json_encode($res->export()); - break; - - case "getWiSPUserLogs": - - $rawData = array ( - - array( - 'ID' => 10, - 'Username' => 'johnsmith', - 'Status' => 1, - 'Timestamp' => '10/03/2009', - 'AcctSessionID' => '24234', - 'AcctSessionTime' => '10:30', - 'NASIPAddress' => '192.168.1.254', - 'NASPortType' => '2', - 'NASPort' => '3128', - 'CalledStationID' => '282282', - 'CallingStationID' => '2782872', - 'NASTransmitRate' => '2000', - 'NASReceiveRate' => '4000', - 'FramedIPAddress' => '192.168.1.30', - 'AcctInputMbyte' => '1241', - 'AcctOutputMbyte' => '229', - 'LastAcctUpdate' => '1282893', - 'ConnectTermReason' => 'Failboat' - ) - ); - - $numResults = 1; - - $res = new json_response; - $res->setID('ID'); - $res->addField('ID','int'); - $res->addField('Username','int'); - $res->addField('Status','string'); - $res->addField('Timestamp','string'); - $res->addField('AcctSessionID','int'); - $res->addField('AcctSessionTime','int'); - $res->addField('NASIPAddress','string'); - $res->addField('NASPortType','string'); - $res->addField('NASPort','string'); - $res->addField('CalledStationID','boolean'); - $res->addField('CallingStationID','boolean'); - $res->addField('NASTransmitRate','string'); - $res->addField('NASReceiveRate','string'); - $res->addField('FramedIPAddress','string'); - $res->addField('AcctInputMbyte','string'); - $res->addField('AcctOutputMbyte','string'); - $res->addField('LastAcctUpdate','string'); - $res->addField('ConnectTermReason','string'); - $res->parseArray($rawData); - $res->setDatasetSize($numResults); - - echo json_encode($res->export()); - break; } + exit; # Connect via soap diff --git a/webgui/include/ajax/functions/AdminUserLogs.php b/webgui/include/ajax/functions/AdminUserLogs.php new file mode 100644 index 00000000..b92c4ecb --- /dev/null +++ b/webgui/include/ajax/functions/AdminUserLogs.php @@ -0,0 +1,107 @@ +<?php + +include_once("include/db.php"); + + +# Return list of users +function getAdminUserLogs($params) { + global $db; + + # Filters and sorts are the same here + $filtersorts = array( + 'ID' => 'accounting.ID', + 'EventTimestamp' => 'accounting.EventTimestamp', + 'AcctStatusType' => 'accounting.AcctStatusType', + 'ServiceType' => 'accounting.ServiceType', + 'FramedProtocol' => 'accounting.FramedProtocol', + 'NASPortType' => 'accounting.NASPortType', + 'NASPortID' => 'accounting.NASPortID', + 'CallingStationID' => 'accounting.CallingStationID', + 'CalledStationID' => 'accounting.CalledStationID', + 'AcctSessionID' => 'accounting.AcctSessionID', + 'FramedIPAddress' => 'accounting.FramedIPAddress', + ); + + $res = DBSelectSearch(" + SELECT + accounting.ID, + accounting.EventTimestamp, + accounting.AcctStatusType, + accounting.ServiceType, + accounting.FramedProtocol, + accounting.NASPortType, + accounting.NASPortID, + accounting.CallingStationID, + accounting.CalledStationID, + accounting.AcctSessionID, + accounting.FramedIPAddress, + accounting.AcctInputOctets, + accounting.AcctInputGigawords, + accounting.AcctOutputOctets, + accounting.AcctOutputGigawords, + accounting.AcctTerminateCause + FROM + accounting, users + WHERE + users.Username = accounting.Username + AND + users.ID = ".DBQuote($params[0])." + ",$params[1],$filtersorts,$filtersorts); + + $sth = $res[0]; $numResults = $res[1]; + # If STH is blank, return the error back to whoever requested the data + if (!isset($sth)) { + return $res; + } + + $resultArray = array(); + + # loop through rows + while ($row = $sth->fetchObject()) { + + # Input + $acctInputMbyte = 0; + + if (!empty($row->acctinputoctets) && $row->acctinputoctets > 0) { + $acctInputMbyte += ($row->acctinputoctets / 1024) / 1024; + } + if (!empty($row->acctinputgigawords) && $row->inputgigawords > 0) { + $acctInputMbyte += ($row->acctinputgigawords * 4096); + } + + + # Output + $acctOutputMbyte = 0; + + if (!empty($row->acctoutputoctets) && $row->acctoutputoctets > 0) { + $acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024; + } + if (!empty($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) { + $acctOutputMbyte += ($row->acctoutputgigawords * 4096); + } + + $item = array(); + + $item['ID'] = $row->id; + $item['EventTimestamp'] = $row->eventtimestamp; + $item['AcctStatusType'] = $row->acctstatustype; + $item['ServiceType'] = $row->servicetype; + $item['FramedProtocol'] = $row->framedprotocol; + $item['NASPortType'] = $row->nasporttype; + $item['NASPortID'] = $row->nasportid; + $item['CallingStationID'] = $row->callingstationid; + $item['CalledStationID'] = $row->calledstationid; + $item['AcctSessionID'] = $row->acctsessionid; + $item['FramedIPAddress'] = $row->framedipaddress; + $item['AcctInputMbyte'] = $acctInputMbyte; + $item['AcctOutputMbyte'] = $acctOutputMbyte; + $item['ConnectTermReason'] = strRadiusTermCode($row->servicetype); + + # push this row onto array + array_push($resultArray,$item); + } + + return array($resultArray,$numResults); +} + +?> diff --git a/webgui/js/app/windows/AdminUserLogs.js b/webgui/js/app/windows/AdminUserLogs.js index 87ef2351..72d95d40 100644 --- a/webgui/js/app/windows/AdminUserLogs.js +++ b/webgui/js/app/windows/AdminUserLogs.js @@ -9,7 +9,7 @@ function showAdminUserLogsWindow(id) { var adminUserLogsWindow = new Ext.ux.GenericGridWindow( // Window config { - title: 'User Logs', + title: 'Logs', layout:'border', height: 480, width: 700, @@ -35,7 +35,7 @@ function showAdminUserLogsWindow(id) { name: 'after', width: 180, fieldLabel: 'From', - vtype: 'daterange', +// vtype: 'daterange', format: 'Y-m-d', value: firstOfMonth, endDateField: 'before', @@ -45,7 +45,7 @@ function showAdminUserLogsWindow(id) { name: 'before', width: 180, fieldLabel: 'To', - vtype: 'daterange', +// vtype: 'daterange', format: 'Y-m-d', value: firstOfNext, startDateField: 'after' @@ -66,7 +66,7 @@ function showAdminUserLogsWindow(id) { // Grab timestamp filter var gridFilters = grid.filters; - var timestampFilter = gridFilters.getFilter('Timestamp'); + var timestampFilter = gridFilters.getFilter('EventTimestamp'); // Grab form fields var afterField = form.getForm().findField('after'); @@ -125,6 +125,11 @@ function showAdminUserLogsWindow(id) { ], // Column model colModel: new Ext.grid.ColumnModel([ + { + header: "ID", + hidden: true, + dataIndex: 'ID' + }, { header: "Timestamp", sortable: true, @@ -133,6 +138,7 @@ function showAdminUserLogsWindow(id) { { header: "Status", sortable: true, + hidden: true, dataIndex: 'AcctStatusType' }, { @@ -145,21 +151,11 @@ function showAdminUserLogsWindow(id) { sortable: true, dataIndex: 'FramedProtocol' }, - { - header: "NAS Port", - sortable: true, - dataIndex: 'NASPort' - }, { header: "NAS Port Type", - sortable: true, + hidden: true, dataIndex: 'NASPortType' }, - { - header: "NAS Port ID", - sortable: true, - dataIndex: 'NASPortID' - }, { header: "Calling Station", sortable: true, @@ -167,19 +163,19 @@ function showAdminUserLogsWindow(id) { }, { header: "Called Station", - sortable: true, + hidden: true, dataIndex: 'CalledStationID' }, { header: "Session ID", - sortable: true, + hidden: true, dataIndex: 'AcctSessionID' }, { - header: "Framed IP", - sortable: true, + header: "IP Address", + hidden: true, dataIndex: 'FramedIPAddress' - }/*, + }, { header: "Input Mbyte", dataIndex: 'AcctInputMbyte' @@ -191,7 +187,7 @@ function showAdminUserLogsWindow(id) { { header: "Term. Reason", dataIndex: 'ConnectTermReason' - }*/ + } ]) }, // Store config @@ -209,24 +205,27 @@ function showAdminUserLogsWindow(id) { // Filter config { filters: [ - { + {type: 'numeric', dataIndex: 'ID'}, + /*{ type: 'date', - dataIndex: 'Timestamp', + dataIndex: 'EventTimestamp', value: { after: firstOfMonth, before: firstOfNext } - }, + },*/ {type: 'numeric', dataIndex: 'AcctStatusType'}, {type: 'numeric', dataIndex: 'ServiceType'}, {type: 'numeric', dataIndex: 'FramedProtocol'}, - {type: 'string', dataIndex: 'NASPort'}, {type: 'numeric', dataIndex: 'NASPortType'}, {type: 'string', dataIndex: 'NASPortID'}, {type: 'string', dataIndex: 'CallingStationID'}, {type: 'string', dataIndex: 'CalledStationID'}, {type: 'string', dataIndex: 'AcctSessionID'}, - {type: 'string', dataIndex: 'FramedIPAddress'} + {type: 'string', dataIndex: 'FramedIPAddress'}, + {type: 'numeric', dataIndex: 'AcctInputMbyte'}, + {type: 'numeric', dataIndex: 'AcctOutputMbyte'}, + {type: 'string', dataIndex: 'ConnectTermReason'} ] } ); -- GitLab