diff --git a/webgui/ajax.php b/webgui/ajax.php index 7e62d4d47dabd65e679856c5b11a8a96247d3e44..95f4facc20bca331e952dc97f00b8f265f36bf4e 100644 --- a/webgui/ajax.php +++ b/webgui/ajax.php @@ -165,6 +165,48 @@ switch ($function) { + case "getWiSPUserLogsSummary": + + $res = getWiSPUserLogsSummary($soapParams); + $rawData = $res[0]; $numResults = $res[1]; + + $res = new json_response; + $res->addField('uptimeCap','int'); + $res->addField('trafficCap','int'); + $res->addField('trafficCurrentTopupUsed','int'); + $res->addField('trafficCurrentTopupCap','int'); + $res->addField('uptimeCurrentTopupUsed','int'); + $res->addField('uptimeCurrentTopupCap','int'); + $res->addField('trafficTopupRemaining','int'); + $res->addField('uptimeTopupRemaining','int'); + $res->parseHash($rawData); + $res->setDatasetSize($numResults); + + echo json_encode($res->export()); + + break; + + case "getAdminUserLogsSummary": + + $res = getAdminUserLogsSummary($soapParams); + $rawData = $res[0]; $numResults = $res[1]; + + $res = new json_response; + $res->addField('uptimeCap','int'); + $res->addField('trafficCap','int'); + $res->addField('trafficCurrentTopupUsed','int'); + $res->addField('trafficCurrentTopupCap','int'); + $res->addField('uptimeCurrentTopupUsed','int'); + $res->addField('uptimeCurrentTopupCap','int'); + $res->addField('trafficTopupRemaining','int'); + $res->addField('uptimeTopupRemaining','int'); + $res->parseHash($rawData); + $res->setDatasetSize($numResults); + + echo json_encode($res->export()); + + break; + # AdminUserTopups.js functions case "getAdminUserTopups": @@ -339,6 +381,7 @@ $res->addField('FramedIPAddress','string'); $res->addField('AcctInputMbyte','int'); $res->addField('AcctOutputMbyte','int'); + $res->addField('AcctSessionTime','int'); $res->addField('ConnectTermReason','string'); $res->parseArray($rawData); $res->setDatasetSize($numResults); diff --git a/webgui/include/ajax/functions/AdminUserLogs.php b/webgui/include/ajax/functions/AdminUserLogs.php index e38a71866a0c0dcce4601d30895ca6bd1ebec9f1..0d11e94bccd549f2dc89885f708cff694801c5c8 100644 --- a/webgui/include/ajax/functions/AdminUserLogs.php +++ b/webgui/include/ajax/functions/AdminUserLogs.php @@ -3,6 +3,300 @@ include_once("include/db.php"); +# Return user logs summary +function getAdminUserLogsSummary($params) { + + $res = DBSelect(" + SELECT + user_attributes.Name, + user_attributes.Value + FROM + user_attributes + WHERE + user_attributes.UserID = ?", + array($params[0]['ID']) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Array of results + $resultArray = array(); + + # Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int + $trafficCap = -1; + $uptimeCap = -1; + while ($row = $res->fetchObject()) { + if ($row->name == 'SMRadius-Capping-Traffic-Limit') { + $trafficCap = (int)$row->value; + } + if ($row->name == 'SMRadius-Capping-Uptime-Limit') { + $uptimeCap = (int)$row->value; + } + } + + # Add cap type / amount to result + $resultArray['trafficCap'] = $trafficCap; + $resultArray['uptimeCap'] = $uptimeCap; + + # Dates we want to use to search search + $dateFrom = new DateTime($params[0]['From']); + $dateTo = new DateTime($params[0]['To']); + + # Fetch user uptime and traffic summary + $res = DBSelect(" + SELECT + topups_summary.Balance, + topups.Type, + topups.Value + FROM + topups_summary, + topups + WHERE + topups_summary.TopupID = topups.ID + AND topups.UserID = ? + AND topups_summary.PeriodKey = ? + AND topups.Depleted = 0 + ORDER BY + topups.Timestamp", + array($params[0]['ID'],$dateFrom->format('Y-m')) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Store summary topups + $topups = array(); + $i = 0; + while ($row = $res->fetchObject()) { + $topups[$i] = array(); + $topups[$i]['Type'] = $row->type; + $topups[$i]['Limit'] = $row->balance; + $topups[$i]['OriginalLimit'] = $row->value; + $i++; + } + + # Fetch user uptime and traffic topups + $res = DBSelect(" + SELECT + Value, Type + FROM + topups + WHERE + topups.UserID = ? + AND topups.ValidFrom = ? + AND topups.ValidTo >= ? + AND topups.Depleted = 0 + ORDER BY + topups.Timestamp", + array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d')) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Store normal topups + while ($row = $res->fetchObject()) { + $topups[$i] = array(); + $topups[$i]['Type'] = $row->type; + $topups[$i]['Limit'] = $row->value; + $i++; + } + + $res = DBSelect(" + SELECT + accounting.AcctSessionTime, + accounting.AcctInputOctets, + accounting.AcctInputGigawords, + accounting.AcctOutputOctets, + accounting.AcctOutputGigawords + FROM + accounting, users + WHERE + users.ID = ? + AND EventTimestamp >= ? + AND accounting.Username = users.Username", + array($params[0]['ID'],$dateFrom->format('Y-m-d')) + ); + + if (!is_object($res)) { + return $res; + } + + # Set total traffic and uptime used + $totalTraffic = 0; + $totalUptime = 0; + while ($row = $res->fetchObject()) { + + # Traffic in + $inputDataItem = 0; + + if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { + $inputDataItem += ($row->acctinputoctets / 1024) / 1024; + } + if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) { + $inputDataItem += ($row->acctinputgigawords * 4096); + } + + $totalTraffic += $inputDataItem; + + # Traffic out + $outputDataItem = 0; + + if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) { + $outputDataItem += ($row->acctoutputoctets / 1024) / 1024; + } + if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) { + $outputDataItem += ($row->acctoutputgigawords * 4096); + } + + $totalTraffic += $outputDataItem; + + # Uptime + $sessionTimeItem = 0; + if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { + $sessionTimeItem += $row->acctsessiontime; + } + + $totalUptime += $sessionTimeItem; + # Round up + $totalUptime = ceil($totalUptime / 60); + } + + # Set excess traffic usage + $excessTraffic = 0; + if (is_numeric($trafficCap) && $trafficCap > 0) { + $excessTraffic += $totalTraffic - $trafficCap; + } else { + $excessTraffic += $totalTraffic; + } + + # Set excess uptime usage + $excessUptime = 0; + if (is_numeric($uptimeCap) && $uptimeCap > 0) { + $excessUptime += $totalUptime - $uptimeCap; + } else { + $excessUptime += $totalUptime; + } + + $currentTrafficTopup = array(); + $topupTrafficRemaining = 0; + # Loop through traffic topups and check for current topup, total topups not being used + if (is_string($trafficCap) || $trafficCap != 0) { + $i = 0; + # User is using traffic from topups + if ($excessTraffic > 0) { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 1) { + if ($excessTraffic <= 0) { + $topupTrafficRemaining += $topupItem['Limit']; + next($topupItem); + } elseif ($excessTraffic >= $topupItem['Limit']) { + $excessTraffic -= $topupItem['Limit']; + } else { + if (isset($topupItem['OriginalLimit'])) { + $currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentTrafficTopup['Cap'] = $topupItem['Limit']; + } + $currentTrafficTopup['Used'] = $excessTraffic; + $excessTraffic -= $topupItem['Limit']; + } + } + } + # User has not used traffic topups yet + } else { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 1) { + if ($i == 0) { + if (isset($topupItem['OriginalLimit'])) { + $currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentTrafficTopup['Cap'] = $topupItem['Limit']; + } + $i = 1; + $currentTrafficTopup['Used'] = 0; + } else { + $topupTrafficRemaining += $topupItem['Limit']; + } + } + } + } + } + + $currentUptimeTopup = array(); + $topupUptimeRemaining = 0; + # Loop through uptime topups and check for current topup, total topups not being used + if (is_string($uptimeCap) || $uptimeCap != 0) { + $i = 0; + # User is using uptime from topups + if ($excessUptime > 0) { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 2) { + if ($excessUptime <= 0) { + $topupUptimeRemaining += $topupItem['Limit']; + next($topupItem); + } elseif ($excessUptime >= $topupItem['Limit']) { + $excessUptime -= $topupItem['Limit']; + } else { + if (isset($topupItem['OriginalLimit'])) { + $currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentUptimeTopup['Cap'] = $topupItem['Limit']; + } + $currentUptimeTopup['Used'] = $excessUptime; + $excessUptime -= $topupItem['Limit']; + } + } + } + # User has not used uptime topups yet + } else { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 2) { + if ($i == 0) { + if (isset($topupItem['OriginalLimit'])) { + $currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentUptimeTopup['Cap'] = $topupItem['Limit']; + } + $i = 1; + $currentUptimeTopup['Used'] = 0; + } else { + $topupUptimeRemaining += $topupItem['Limit']; + } + } + } + } + } + + # Traffic.. + $resultArray['trafficCurrentTopupUsed'] = -1; + $resultArray['trafficCurrentTopupCap'] = -1; + if (count($currentTrafficTopup) > 0) { + $resultArray['trafficCurrentTopupUsed'] = $currentTrafficTopup['Used']; + $resultArray['trafficCurrentTopupCap'] = (int)$currentTrafficTopup['Cap']; + } + $resultArray['trafficTopupRemaining'] = $topupTrafficRemaining; + + # Uptime.. + $resultArray['uptimeCurrentTopupUsed'] = -1; + $resultArray['uptimeCurrentTopupCap'] = -1; + if (count($currentUptimeTopup) > 0) { + $resultArray['uptimeCurrentTopupUsed'] = $currentUptimeTopup['Used']; + $resultArray['uptimeCurrentTopupCap'] = (int)$currentUptimeTopup['Cap']; + } + $resultArray['uptimeTopupRemaining'] = $topupUptimeRemaining; + + # Return results + return array($resultArray, 1); +} + # Return list of user logs function getAdminUserLogs($params) { @@ -39,7 +333,8 @@ function getAdminUserLogs($params) { accounting.AcctInputGigawords, accounting.AcctOutputOctets, accounting.AcctOutputGigawords, - accounting.AcctTerminateCause + accounting.AcctTerminateCause, + accounting.AcctSessionTime FROM accounting, users WHERE @@ -79,6 +374,13 @@ function getAdminUserLogs($params) { $acctOutputMbyte += ($row->acctoutputgigawords * 4096); } + # Uptime + $acctSessionTime = 0; + if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { + $acctSessionTime += ($row->acctsessiontime / 60); + } + ceil($acctSessionTime); + # Build array for this row $item = array(); @@ -98,6 +400,7 @@ function getAdminUserLogs($params) { $item['FramedIPAddress'] = $row->framedipaddress; $item['AcctInputMbyte'] = $acctInputMbyte; $item['AcctOutputMbyte'] = $acctOutputMbyte; + $item['AcctSessionTime'] = $acctSessionTime; $item['ConnectTermReason'] = strRadiusTermCode($row->servicetype); # Push this row onto main array diff --git a/webgui/include/ajax/functions/WiSPUserLogs.php b/webgui/include/ajax/functions/WiSPUserLogs.php index bf1f0874506c5911e0628634e9484b1159fd2161..c8ffd4c083f66232420b90edd1263aac9165dbbe 100644 --- a/webgui/include/ajax/functions/WiSPUserLogs.php +++ b/webgui/include/ajax/functions/WiSPUserLogs.php @@ -3,6 +3,300 @@ include_once("include/db.php"); +# Return user logs summary +function getWiSPUserLogsSummary($params) { + + $res = DBSelect(" + SELECT + user_attributes.Name, + user_attributes.Value + FROM + user_attributes + WHERE + user_attributes.UserID = ?", + array($params[0]['ID']) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Array of results + $resultArray = array(); + + # Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int + $trafficCap = -1; + $uptimeCap = -1; + while ($row = $res->fetchObject()) { + if ($row->name == 'SMRadius-Capping-Traffic-Limit') { + $trafficCap = (int)$row->value; + } + if ($row->name == 'SMRadius-Capping-Uptime-Limit') { + $uptimeCap = (int)$row->value; + } + } + + # Add cap type / amount to result + $resultArray['trafficCap'] = $trafficCap; + $resultArray['uptimeCap'] = $uptimeCap; + + # Dates we want to use to search search + $dateFrom = new DateTime($params[0]['From']); + $dateTo = new DateTime($params[0]['To']); + + # Fetch user uptime and traffic summary + $res = DBSelect(" + SELECT + topups_summary.Balance, + topups.Type, + topups.Value + FROM + topups_summary, + topups + WHERE + topups_summary.TopupID = topups.ID + AND topups.UserID = ? + AND topups_summary.PeriodKey = ? + AND topups.Depleted = 0 + ORDER BY + topups.Timestamp", + array($params[0]['ID'],$dateFrom->format('Y-m')) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Store summary topups + $topups = array(); + $i = 0; + while ($row = $res->fetchObject()) { + $topups[$i] = array(); + $topups[$i]['Type'] = $row->type; + $topups[$i]['Limit'] = $row->balance; + $topups[$i]['OriginalLimit'] = $row->value; + $i++; + } + + # Fetch user uptime and traffic topups + $res = DBSelect(" + SELECT + Value, Type + FROM + topups + WHERE + topups.UserID = ? + AND topups.ValidFrom = ? + AND topups.ValidTo >= ? + AND topups.Depleted = 0 + ORDER BY + topups.Timestamp", + array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d')) + ); + + # Return if error + if (!is_object($res)) { + return $res; + } + + # Store normal topups + while ($row = $res->fetchObject()) { + $topups[$i] = array(); + $topups[$i]['Type'] = $row->type; + $topups[$i]['Limit'] = $row->value; + $i++; + } + + $res = DBSelect(" + SELECT + accounting.AcctSessionTime, + accounting.AcctInputOctets, + accounting.AcctInputGigawords, + accounting.AcctOutputOctets, + accounting.AcctOutputGigawords + FROM + accounting, users + WHERE + users.ID = ? + AND EventTimestamp >= ? + AND accounting.Username = users.Username", + array($params[0]['ID'],$dateFrom->format('Y-m-d')) + ); + + if (!is_object($res)) { + return $res; + } + + # Set total traffic and uptime used + $totalTraffic = 0; + $totalUptime = 0; + while ($row = $res->fetchObject()) { + + # Traffic in + $inputDataItem = 0; + + if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { + $inputDataItem += ($row->acctinputoctets / 1024) / 1024; + } + if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) { + $inputDataItem += ($row->acctinputgigawords * 4096); + } + + $totalTraffic += $inputDataItem; + + # Traffic out + $outputDataItem = 0; + + if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) { + $outputDataItem += ($row->acctoutputoctets / 1024) / 1024; + } + if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) { + $outputDataItem += ($row->acctoutputgigawords * 4096); + } + + $totalTraffic += $outputDataItem; + + # Uptime + $sessionTimeItem = 0; + if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { + $sessionTimeItem += $row->acctsessiontime; + } + + $totalUptime += $sessionTimeItem; + # Round up + $totalUptime = ceil($totalUptime / 60); + } + + # Set excess traffic usage + $excessTraffic = 0; + if (is_numeric($trafficCap) && $trafficCap > 0) { + $excessTraffic += $totalTraffic - $trafficCap; + } else { + $excessTraffic += $totalTraffic; + } + + # Set excess uptime usage + $excessUptime = 0; + if (is_numeric($uptimeCap) && $uptimeCap > 0) { + $excessUptime += $totalUptime - $uptimeCap; + } else { + $excessUptime += $totalUptime; + } + + $currentTrafficTopup = array(); + $topupTrafficRemaining = 0; + # Loop through traffic topups and check for current topup, total topups not being used + if (is_string($trafficCap) || $trafficCap != 0) { + $i = 0; + # User is using traffic from topups + if ($excessTraffic > 0) { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 1) { + if ($excessTraffic <= 0) { + $topupTrafficRemaining += $topupItem['Limit']; + next($topupItem); + } elseif ($excessTraffic >= $topupItem['Limit']) { + $excessTraffic -= $topupItem['Limit']; + } else { + if (isset($topupItem['OriginalLimit'])) { + $currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentTrafficTopup['Cap'] = $topupItem['Limit']; + } + $currentTrafficTopup['Used'] = $excessTraffic; + $excessTraffic -= $topupItem['Limit']; + } + } + } + # User has not used traffic topups yet + } else { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 1) { + if ($i == 0) { + if (isset($topupItem['OriginalLimit'])) { + $currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentTrafficTopup['Cap'] = $topupItem['Limit']; + } + $i = 1; + $currentTrafficTopup['Used'] = 0; + } else { + $topupTrafficRemaining += $topupItem['Limit']; + } + } + } + } + } + + $currentUptimeTopup = array(); + $topupUptimeRemaining = 0; + # Loop through uptime topups and check for current topup, total topups not being used + if (is_string($uptimeCap) || $uptimeCap != 0) { + $i = 0; + # User is using uptime from topups + if ($excessUptime > 0) { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 2) { + if ($excessUptime <= 0) { + $topupUptimeRemaining += $topupItem['Limit']; + next($topupItem); + } elseif ($excessUptime >= $topupItem['Limit']) { + $excessUptime -= $topupItem['Limit']; + } else { + if (isset($topupItem['OriginalLimit'])) { + $currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentUptimeTopup['Cap'] = $topupItem['Limit']; + } + $currentUptimeTopup['Used'] = $excessUptime; + $excessUptime -= $topupItem['Limit']; + } + } + } + # User has not used uptime topups yet + } else { + foreach ($topups as $topupItem) { + if ($topupItem['Type'] == 2) { + if ($i == 0) { + if (isset($topupItem['OriginalLimit'])) { + $currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; + } else { + $currentUptimeTopup['Cap'] = $topupItem['Limit']; + } + $i = 1; + $currentUptimeTopup['Used'] = 0; + } else { + $topupUptimeRemaining += $topupItem['Limit']; + } + } + } + } + } + + # Traffic.. + $resultArray['trafficCurrentTopupUsed'] = -1; + $resultArray['trafficCurrentTopupCap'] = -1; + if (count($currentTrafficTopup) > 0) { + $resultArray['trafficCurrentTopupUsed'] = $currentTrafficTopup['Used']; + $resultArray['trafficCurrentTopupCap'] = (int)$currentTrafficTopup['Cap']; + } + $resultArray['trafficTopupRemaining'] = $topupTrafficRemaining; + + # Uptime.. + $resultArray['uptimeCurrentTopupUsed'] = -1; + $resultArray['uptimeCurrentTopupCap'] = -1; + if (count($currentUptimeTopup) > 0) { + $resultArray['uptimeCurrentTopupUsed'] = $currentUptimeTopup['Used']; + $resultArray['uptimeCurrentTopupCap'] = (int)$currentUptimeTopup['Cap']; + } + $resultArray['uptimeTopupRemaining'] = $topupUptimeRemaining; + + # Return results + return array($resultArray, 1); +} + # Return list of user logs function getWiSPUserLogs($params) { @@ -39,7 +333,8 @@ function getWiSPUserLogs($params) { accounting.AcctInputGigawords, accounting.AcctOutputOctets, accounting.AcctOutputGigawords, - accounting.AcctTerminateCause + accounting.AcctTerminateCause, + accounting.AcctSessionTime FROM accounting, users WHERE @@ -78,6 +373,13 @@ function getWiSPUserLogs($params) { $acctOutputMbyte += ($row->acctoutputgigawords * 4096); } + # Uptime + $acctSessionTime = 0; + if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { + $acctSessionTime += ($row->acctsessiontime / 60); + } + ceil($acctSessionTime); + # Build array for this row $item = array(); @@ -97,6 +399,7 @@ function getWiSPUserLogs($params) { $item['FramedIPAddress'] = $row->framedipaddress; $item['AcctInputMbyte'] = $acctInputMbyte; $item['AcctOutputMbyte'] = $acctOutputMbyte; + $item['AcctSessionTime'] = $acctSessionTime; $item['ConnectTermReason'] = strRadiusTermCode($row->servicetype); # Push this row onto main array diff --git a/webgui/js/app/windows/AdminUserLogs.js b/webgui/js/app/windows/AdminUserLogs.js index 94455141b85ed16edd7c6ef4b7c868cdf57f7cab..b4105aff71ed3fcfd9e50e6e34c017d50c21743d 100644 --- a/webgui/js/app/windows/AdminUserLogs.js +++ b/webgui/js/app/windows/AdminUserLogs.js @@ -204,9 +204,9 @@ function showAdminUserLogsWindow(id) { filters: [ {type: 'numeric', dataIndex: 'ID'}, { - type: 'date', + type: 'date', format: 'Y-m-d H:i:s', - dataIndex: 'EventTimestamp', + dataIndex: 'EventTimestamp', value: { after: firstOfMonth, before: firstOfNext @@ -240,13 +240,6 @@ function showAdminUserLogsWindow(id) { var afterField = (searchForm.getForm().findField('after')).getValue(); var beforeField = (searchForm.getForm().findField('before')).getValue(); - var trafficCap; - var uptimeCap; - var trafficTopups; - var uptimeTopups; - - var response; - // Mask parent window adminUserLogsWindow.getEl().mask(); @@ -254,71 +247,120 @@ function showAdminUserLogsWindow(id) { adminUserLogsWindow, { params: { - From: afterField, - To: beforeField, - ID: id, - SOAPUsername: globalConfig.soap.username, - SOAPPassword: globalConfig.soap.password, - SOAPAuthType: globalConfig.soap.authtype, - SOAPModule: 'AdminUserLogs', - SOAPFunction: 'getAdminUserLogsSummary', - SOAPParams: '0:ID,0:From,0:To' - }, - customSuccess: function (result) { - response = Ext.decode(result.responseText); + From: afterField, + To: beforeField, + ID: id, + SOAPUsername: globalConfig.soap.username, + SOAPPassword: globalConfig.soap.password, + SOAPAuthType: globalConfig.soap.authtype, + SOAPModule: 'AdminUserLogs', + SOAPFunction: 'getAdminUserLogsSummary', + SOAPParams: '0:ID,0:From,0:To' + }, - trafficCap = response.data.trafficCap; - uptimeCap = response.data.uptimeCap; - trafficTopups = response.data.trafficTopups; - uptimeTopups = response.data.uptimeTopups; + customSuccess: function (result) { + response = Ext.decode(result.responseText); - // Total up traffic - var trafficTotalAllowed; - if (trafficCap < 0) { - trafficTotalAllowed = trafficTopups; - } else { - trafficTotalAllowed = trafficCap + trafficTopups; - } - var trafficUsage = inputTotal + outputTotal; - var trafficRemaining = trafficTotalAllowed - trafficUsage; + // Traffic variables + var trafficCap = response.data.trafficCap; // value of -1: prepaid + + var trafficCurrentTopupUsed = response.data.trafficCurrentTopupUsed; // value of -1: no current topup + var trafficCurrentTopupCap = response.data.trafficCurrentTopupCap; // value of -1: no current topup + var trafficTopupRemaining = response.data.trafficTopupRemaining; + + // Uptime variables + var uptimeCap = response.data.uptimeCap; // value of -1: prepaid - var form = adminUserLogsWindow.getComponent('summary-form'); - var summaryTotal = form.getForm().findField('summaryTotal'); + var uptimeCurrentTopupUsed = response.data.uptimeCurrentTopupUsed; // value of -1: no current topup + var uptimeCurrentTopupCap = response.data.uptimeCurrentTopupCap; // value of -1: no current topup + var uptimeTopupRemaining = response.data.uptimeTopupRemaining; - // Format string before printing - var summaryString = ''; - if (trafficCap == -1) { - trafficCap = 'Prepaid'; - summaryString += sprintf( - 'Traffic Cap: %s Traffic Topups: %d\n------------------------------------\n'+ - 'Allowed: %d Used: %d\n-------------------------------\nRemaining: %d', - trafficCap,trafficTopups,trafficTotalAllowed,trafficUsage,trafficRemaining - ); + // Total up traffic + var trafficTotalAllowed; + var validTrafficTopups; + if (trafficCurrentTopupCap > 0) { + validTrafficTopups = trafficCurrentTopupCap; + validTrafficTopups += trafficTopupRemaining; + } else { + validTrafficTopups = trafficTopupRemaining; + } - } else if (trafficCap == 0) { - summaryString += sprintf( - 'Traffic Cap: Uncapped\n---------------------------------\nUsed: %d', - trafficUsage - ); + if (trafficCap < 0) { + trafficTotalAllowed = validTrafficTopups; + } else { + trafficTotalAllowed = trafficCap + validTrafficTopups; + } - } else { - summaryString += sprintf( - 'Traffic Cap: %d Traffic Topups: %d\n------------------------------------\n'+ - 'Allowed: %d Used: %d\n-------------------------------\nRemaining: %d', - trafficCap,trafficTopups,trafficTotalAllowed,trafficUsage,trafficRemaining - ); - } + // Traffic usage + var trafficUsage = inputTotal + outputTotal; + + // Total up uptime + var uptimeTotalAllowed; + var validUptimeTopups; + if (uptimeCurrentTopupCap > 0) { + validUptimeTopups = uptimeCurrentTopupCap; + validUptimeTopups += uptimeTopupRemaining; + } else { + validUptimeTopups = uptimeTopupRemaining; + } -alert(summaryString); - summaryTotal.setValue(summaryString); - }, - failure: function (result) { - Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date); - }, - }); - + if (uptimeCap < 0) { + uptimeTotalAllowed = validUptimeTopups; + } else { + uptimeTotalAllowed = uptimeCap + validUptimeTopups; + } + + // Get summary field + var form = adminUserLogsWindow.getComponent('summary-form'); + var summaryTotal = form.getForm().findField('summaryTotal'); + + // Format string before printing + var trafficString = ''; + // Prepaid traffic + if (trafficCap == -1) { + trafficCap = 'Prepaid'; + trafficString += sprintf(' Traffic\nCap: %s MB Topup: %d MB\n'+ + 'Usage: %d/%d MB\n=====================================\n', + trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed); + // Uncapped traffic + } else if (trafficCap == 0) { + trafficString += sprintf(' Traffic\nCap: Uncapped Used: %d\n=====================================n', + trafficUsage); + // Capped traffic + } else { + trafficString += sprintf(' Traffic\nCap: %d MB Topup: %d MB\n'+ + 'Usage: %d/%d MB\n=====================================\n', + trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed); + } + + // Format string before printing + var uptimeString = ''; + // Prepaid uptime + if (uptimeCap == -1) { + uptimeCap = 'Prepaid'; + uptimeString += sprintf(' Uptime\nCap: %s MB Topup: %d MB\n'+ + 'Usage: %d/%d MB', + uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed); + // Uncapped uptime + } else if (uptimeCap == 0) { + uptimeString += sprintf(' Uptime\nCap: Uncapped Used: %d', + uptimeTotal); + // Capped uptime + } else { + uptimeString += sprintf(' Uptime\nCap: %d MB Topup: %d MB\n'+ + 'Usage: %d/%d MB', + uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed); + } + + summaryTotal.setValue(trafficString+uptimeString); + }, + failure: function (result) { + Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date); + }, + } + ); }); - adminUserLogsWindow.show(); + adminUserLogsWindow.show(); } // vim: ts=4 diff --git a/webgui/js/app/windows/WiSPUserLogs.js b/webgui/js/app/windows/WiSPUserLogs.js index b25b4d41dd48f345a7605de97dddc85c23f81784..71ed9260aec280a3ce99dfb8eb6f12e1eebfffce 100644 --- a/webgui/js/app/windows/WiSPUserLogs.js +++ b/webgui/js/app/windows/WiSPUserLogs.js @@ -177,6 +177,10 @@ function showWiSPUserLogsWindow(id) { header: "Output Mbyte", dataIndex: 'AcctOutputMbyte' }, + { + header: "Session Uptime", + dataIndex: 'AcctSessionTime' + }, { header: "Term. Reason", dataIndex: 'ConnectTermReason' @@ -219,6 +223,7 @@ function showWiSPUserLogsWindow(id) { {type: 'string', dataIndex: 'FramedIPAddress'}, {type: 'numeric', dataIndex: 'AcctInputMbyte'}, {type: 'numeric', dataIndex: 'AcctOutputMbyte'}, + {type: 'numeric', dataIndex: 'AcctSessionTime'}, {type: 'string', dataIndex: 'ConnectTermReason'} ] } @@ -229,21 +234,130 @@ function showWiSPUserLogsWindow(id) { store.on('load',function() { var inputTotal = store.sum('AcctInputMbyte'); var outputTotal = store.sum('AcctOutputMbyte'); + var uptimeTotal = store.sum('AcctSessionTime'); + + var searchForm = wispUserLogsWindow.getComponent('search-form'); + var afterField = (searchForm.getForm().findField('after')).getValue(); + var beforeField = (searchForm.getForm().findField('before')).getValue(); + + // Mask parent window + wispUserLogsWindow.getEl().mask(); + + uxAjaxRequest( + wispUserLogsWindow, + { + params: { + From: afterField, + To: beforeField, + ID: id, + SOAPUsername: globalConfig.soap.username, + SOAPPassword: globalConfig.soap.password, + SOAPAuthType: globalConfig.soap.authtype, + SOAPModule: 'WiSPUserLogs', + SOAPFunction: 'getWiSPUserLogsSummary', + SOAPParams: '0:ID,0:From,0:To' + }, + + customSuccess: function (result) { + response = Ext.decode(result.responseText); - var userCap = 3000; - var userTopups = 1000; - - // Total up into this ... - - var userTotalAllowed = userCap + userTopups; - var userUsage = inputTotal + outputTotal; - var userLeft = userTotalAllowed - userUsage; + // Traffic variables + var trafficCap = response.data.trafficCap; // value of -1: prepaid + + var trafficCurrentTopupUsed = response.data.trafficCurrentTopupUsed; // value of -1: no current topup + var trafficCurrentTopupCap = response.data.trafficCurrentTopupCap; // value of -1: no current topup + var trafficTopupRemaining = response.data.trafficTopupRemaining; + + // Uptime variables + var uptimeCap = response.data.uptimeCap; // value of -1: prepaid + + var uptimeCurrentTopupUsed = response.data.uptimeCurrentTopupUsed; // value of -1: no current topup + var uptimeCurrentTopupCap = response.data.uptimeCurrentTopupCap; // value of -1: no current topup + var uptimeTopupRemaining = response.data.uptimeTopupRemaining; + + // Total up traffic + var trafficTotalAllowed; + var validTrafficTopups; + if (trafficCurrentTopupCap > 0) { + validTrafficTopups = trafficCurrentTopupCap; + validTrafficTopups += trafficTopupRemaining; + } else { + validTrafficTopups = trafficTopupRemaining; + } + + if (trafficCap < 0) { + trafficTotalAllowed = validTrafficTopups; + } else { + trafficTotalAllowed = trafficCap + validTrafficTopups; + } - var form = wispUserLogsWindow.getComponent('summary-form'); - var summaryTotal = form.getForm().findField('summaryTotal'); + // Traffic usage + var trafficUsage = inputTotal + outputTotal; - summaryTotal.setValue( - sprintf('Cap Total: %6d\nTopups : %6d\n-----------------\n %6d\n-----------------\nUsage : %6d\n=================\nAvailable: %6d',userCap,userTopups,userTotalAllowed,userUsage,userLeft) + // Total up uptime + var uptimeTotalAllowed; + var validUptimeTopups; + if (uptimeCurrentTopupCap > 0) { + validUptimeTopups = uptimeCurrentTopupCap; + validUptimeTopups += uptimeTopupRemaining; + } else { + validUptimeTopups = uptimeTopupRemaining; + } + + if (uptimeCap < 0) { + uptimeTotalAllowed = validUptimeTopups; + } else { + uptimeTotalAllowed = uptimeCap + validUptimeTopups; + } + + // Get summary field + var form = wispUserLogsWindow.getComponent('summary-form'); + var summaryTotal = form.getForm().findField('summaryTotal'); + + // Format string before printing + var trafficString = ''; + // Prepaid traffic + if (trafficCap == -1) { + trafficCap = 'Prepaid'; + trafficString += sprintf(' Traffic\nCap: %s MB Topup: %d MB\n'+ + 'Usage: %d/%d MB\n=====================================\n', + trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed); + // Uncapped traffic + } else if (trafficCap == 0) { + trafficString += sprintf(' Traffic\nCap: Uncapped Used: %d\n=====================================n', + trafficUsage); + // Capped traffic + } else { + trafficString += sprintf(' Traffic\nCap: %d MB Topup: %d MB\n'+ + 'Usage: %d/%d MB\n=====================================\n', + trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed); + } + + // Format string before printing + var uptimeString = ''; + // Prepaid uptime + if (uptimeCap == -1) { + uptimeCap = 'Prepaid'; + uptimeString += sprintf(' Uptime\nCap: %s MB Topup: %d MB\n'+ + 'Usage: %d/%d MB', + uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed); + // Uncapped uptime + } else if (uptimeCap == 0) { + uptimeString += sprintf(' Uptime\nCap: Uncapped Used: %d', + uptimeTotal); + // Capped uptime + } else { + uptimeString += sprintf(' Uptime\nCap: %d MB Topup: %d MB\n'+ + 'Usage: %d/%d MB', + uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed); + } + + summaryTotal.setValue(trafficString+uptimeString); + }, + failure: function (result) { + Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date); + }, + } ); }); wispUserLogsWindow.show();