Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • smradius/smradius
  • centiva-shail/smradius
  • nkukard/smradius
3 results
Show changes
<?php
# Database Interface
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......
<?php
# Footer of page
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......@@ -18,7 +18,7 @@
?>
<div class="copyright">SMRadius - Copyright &copy; 2007-2009, <a href="http://www.allworldit.com" ?>AllWorldIT</a></div>
<div class="copyright">SMRadius - Copyright &copy; 2007-2011, <a href="http://www.allworldit.com" ?>AllWorldIT</a></div>
<br />
</body>
......
<?php
# Top part of radius control panel
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......
<?php
# Misc functions we can use
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......
<?php
# Web User UI PRE
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......
<?php
# Radius term code mappings
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......@@ -23,38 +23,54 @@
function strRadiusTermCode($errCode) {
if (is_numeric($errCode)) {
# Terminate codes RFC 2866
switch ($errCode) {
case 0:
return "Still logged in";
case 45: # Unknown
case 46: # Unknown
case 63: # Unknown
case 1:
return "User request";
return "User Request";
case 2:
case 816: # TCP connection reset? unknown
return "Carrier loss";
return "Lost Carrier";
case 3:
return "Lost Service";
case 4:
return "Idle Timeout";
case 5:
return "Session timeout";
case 6: # Admin reset
case 10: # NAS request
case 11: # NAS reboot
case 831: # NAS request? unknown
case 841: # NAS request? unknown
return "Router reset/reboot";
case 8: # Port error
return "Port error";
case 180: # Unknown
return "Local hangup";
case 827: # Unknown
return "Service unavailable";
return "Session Timeout";
case 6:
return "Admin Reset";
case 7:
return "Admin Reboot";
case 8:
return "Port Error";
case 9:
return "NAS Error";
case 10:
return "NAS Request";
case 11:
return "NAS Reboot";
case 12:
return "Port Unneeded";
case 13:
return "Port Preempted";
case 14:
return "Port Suspended";
case 15:
return "Service Unavailable";
case 16:
return "Callback";
case 17:
return "User Error";
case 18:
return "Host Request";
default:
return "Unkown";
}
} else {
return "Unknown";
switch ($errCode) {
case NULL:
return "Still logged in";
default:
return "Unkown";
}
}
}
......
<?php
# Versioning for this interface
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......@@ -19,7 +19,7 @@
$VERSION = "0.4.0b1";
$VERSION = "0.0.3a";
# vim: ts=4
?>
<?php
# Main User Control Panel Page
# Copyright (c) 2007-2009, AllWorldIT
# Copyright (c) 2007-2015, AllWorldIT
#
# 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
......@@ -25,6 +25,12 @@ include("include/header.php");
# NB: We will only end up here if we authenticated!
# Displays error
function webuiError($msg) {
echo isset($msg) ? $msg : "Unknown error";
}
# Display details
function displayDetails() {
global $db;
......@@ -33,82 +39,90 @@ function displayDetails() {
# Get user's ID
$sql = "
SELECT
ID
ID, Username
FROM
${DB_TABLE_PREFIX}users
WHERE
Username = ".$db->quote($_SESSION['username'])."
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching user information");
}
$row = $res->fetchObject();
# Set user ID
$userID = $row->id;
$username = $row->username;
# Get accounting data
$currentMonth = date("Y-m");
$sql = "
SELECT
AcctSessionTime,
AcctInputOctets,
AcctInputGigawords,
AcctOutputOctets,
AcctOutputGigawords
SUM(AcctSessionTime) / 60 AS AcctSessionTime,
SUM(AcctInputOctets) / 1024 / 1024 +
SUM(AcctInputGigawords) * 4096 +
SUM(AcctOutputOctets) / 1024 / 1024 +
SUM(AcctOutputGigawords) * 4096 AS TotalTraffic
FROM
${DB_TABLE_PREFIX}accounting
WHERE
Username = ".$db->quote($_SESSION['username'])."
Username = ".$db->quote($username)."
AND
EventTimestamp >= ".$db->quote($currentMonth)."
ORDER BY
EventTimestamp
DESC
PeriodKey = ".$db->quote($currentMonth)."
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching user accounting");
}
# 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);
}
# Pull in row
$row = $res->fetchObject();
$totalTraffic += $inputDataItem;
# Traffic
if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$totalTraffic += $row->totaltraffic;
}
# Uptime
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$totalUptime += $row->acctsessiontime;
}
# Traffic out
$outputDataItem = 0;
# Fetch user uptime and traffic cap (group attributes)
$sql = "
SELECT
${DB_TABLE_PREFIX}group_attributes.Name, ${DB_TABLE_PREFIX}group_attributes.Value
FROM
${DB_TABLE_PREFIX}group_attributes, ${DB_TABLE_PREFIX}users_to_groups
WHERE
${DB_TABLE_PREFIX}users_to_groups.GroupID = ${DB_TABLE_PREFIX}group_attributes.GroupID
AND ${DB_TABLE_PREFIX}users_to_groups.UserID = ".$db->quote($userID)."
AND ${DB_TABLE_PREFIX}group_attributes.Disabled = 0
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching user attributes");
}
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$outputDataItem += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$outputDataItem += ($row->acctoutputgigawords * 4096);
# Initial values
$trafficCap = "Prepaid";
$uptimeCap = "Prepaid";
while ($row = $res->fetchObject()) {
if ($row->name === "SMRadius-Capping-Traffic-Limit") {
$trafficCap = (int)$row->value;
}
$totalTraffic += $outputDataItem;
# Uptime
$sessionTimeItem = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$sessionTimeItem += $row->acctsessiontime;
if ($row->name === "SMRadius-Capping-Uptime-Limit") {
$uptimeCap = (int)$row->value;
}
$totalUptime += $sessionTimeItem;
# Round up
$totalUptime = ceil($totalUptime / 60);
}
# Fetch user uptime and traffic cap
# Fetch user uptime and traffic cap (user attributes)
$sql = "
SELECT
Name, Value
......@@ -116,17 +130,19 @@ function displayDetails() {
${DB_TABLE_PREFIX}user_attributes
WHERE
UserID = ".$db->quote($userID)."
AND Disabled = 0
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching user attributes");
}
# Set uptime and traffic cap
$trafficCap = "Prepaid";
$uptimeCap = "Prepaid";
# Override group_attributes with user attributes
while ($row = $res->fetchObject()) {
if ($row->name == "SMRadius-Capping-Traffic-Limit") {
if ($row->name === "SMRadius-Capping-Traffic-Limit") {
$trafficCap = (int)$row->value;
}
if ($row->name == "SMRadius-Capping-Uptime-Limit") {
if ($row->name === "SMRadius-Capping-Uptime-Limit") {
$uptimeCap = (int)$row->value;
}
}
......@@ -136,7 +152,9 @@ function displayDetails() {
SELECT
${DB_TABLE_PREFIX}topups_summary.Balance,
${DB_TABLE_PREFIX}topups.Type,
${DB_TABLE_PREFIX}topups.Value
${DB_TABLE_PREFIX}topups.Value,
${DB_TABLE_PREFIX}topups.ValidFrom,
${DB_TABLE_PREFIX}topups.ValidTo
FROM
${DB_TABLE_PREFIX}topups_summary,
${DB_TABLE_PREFIX}topups
......@@ -146,482 +164,408 @@ function displayDetails() {
AND ${DB_TABLE_PREFIX}topups_summary.PeriodKey = ".$db->quote($currentMonth)."
AND ${DB_TABLE_PREFIX}topups_summary.Depleted = 0
ORDER BY
${DB_TABLE_PREFIX}topups.Timestamp
${DB_TABLE_PREFIX}topups.Timestamp ASC
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching topup summaries");
}
# 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;
$topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['Limit'] = $row->value;
$topups[$i]['ValidFrom'] = $row->validfrom;
$topups[$i]['Expires'] = $row->validto;
$i++;
}
# Fetch user uptime and traffic topups
$thisMonthUnixTime = strtotime($currentMonth);
$now = time();
$thisMonthTimestamp = date("Y-m").'-01';
$now = date("Y-m-d");
$sql = "
SELECT
Value, Type
Value, Type, ValidFrom, ValidTo
FROM
${DB_TABLE_PREFIX}topups
topups
WHERE
${DB_TABLE_PREFIX}topups.UserID = ".$db->quote($userID)."
AND ${DB_TABLE_PREFIX}topups.ValidFrom >= ".$db->quote($thisMonthUnixTime)."
AND ${DB_TABLE_PREFIX}topups.ValidTo > ".$db->quote($now)."
AND ${DB_TABLE_PREFIX}topups.Depleted = 0
UserID = ".$db->quote($userID)."
AND ValidFrom = ".$db->quote($thisMonthTimestamp)."
AND ValidTo >= ".$db->quote($now)."
AND Depleted = 0
ORDER BY
${DB_TABLE_PREFIX}topups.Timestamp
Timestamp ASC
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching topup");
}
# Store normal topups
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$topups[$i]['ValidFrom'] = $row->validfrom;
$topups[$i]['Expires'] = $row->validto;
$i++;
}
# Set excess traffic usage
$excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) {
$excessTraffic += $totalTraffic - $trafficCap;
} elseif (is_string($trafficCap)) {
$excessTraffic += $totalTraffic;
}
# Calculate topup usage for prepaid and normal users
$totalTrafficTopupsAvail = 0;
if (!(is_numeric($trafficCap) && $trafficCap == 0)) {
# Set excess uptime usage
$excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) {
$excessUptime += $totalUptime - $uptimeCap;
} elseif (is_string($uptimeCap)) {
$excessUptime += $totalUptime;
}
# Excess usage
$excess = 0;
if ($trafficCap === "Prepaid") {
$excess = $totalTraffic;
} else {
$excess = $totalTraffic > $trafficCap ? ($totalTraffic - $trafficCap) : 0;
}
# Loop through traffic topups and check for current topup, total topups not being used
if (is_string($trafficCap) || $trafficCap != 0) {
$currentTrafficTopup = array();
$topupTrafficRemaining = 0;
# Loop through all valid topups
$trafficRows = array();
$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'];
}
foreach ($topups as $topup) {
# Traffic topups
if ($topup['Type'] == 1) {
# Topup not currently in use
if ($excess <= 0) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = isset($topup['CurrentLimit']) ? ($topup['Limit'] - $topup['CurrentLimit']) : 0;
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalTrafficTopupsAvail += isset($topup['CurrentLimit']) ? $topup['CurrentLimit'] : $topup['Limit'];
$i++;
# Topup currently in use
} elseif (!isset($topup['CurrentLimit']) && $excess < $topup['Limit']) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = $excess;
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalTrafficTopupsAvail += $topup['Limit'];
# Set current topup
$currentTrafficTopup = array();
$currentTrafficTopup['Used'] = $excess;
$currentTrafficTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
} elseif (isset($topup['CurrentLimit']) && $excess < $topup['CurrentLimit']) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
# Set total available topups
$totalTrafficTopupsAvail += $topup['CurrentLimit'];
# Set current topup
$currentTrafficTopup = array();
$currentTrafficTopup['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
$currentTrafficTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
# Topup has been used up
} else {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = $topup['Limit'];
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Subtract this topup from excess usage
$excess -= isset($topup['CurrentLimit']) ? $topup['CurrentLimit'] : $topup['Limit'];
$i++;
}
}
}
}
# Loop through uptime topups and check for current topup, total topups not being used
if (is_string($uptimeCap) || $uptimeCap != 0) {
$currentUptimeTopup = array();
$topupUptimeRemaining = 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
# Calculate topup usage for prepaid and normal users
$totalUptimeTopupsAvail = 0;
if (!(is_numeric($uptimeCap) && $uptimeCap == 0)) {
# Excess usage
$excess = 0;
if ($uptimeCap === "Prepaid") {
$excess = $totalUptime;
} 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'];
}
}
}
$excess = $totalUptime > $uptimeCap ? ($totalUptime - $uptimeCap) : 0;
}
}
/*
# Fetch user phone and email info
$sql = "
SELECT
Phone, Email
FROM
${DB_TABLE_PREFIX}wisp_userdata
WHERE
UserID = '$userID'
";
# Loop through all valid topups
$uptimeRows = array();
$i = 0;
foreach ($topups as $topup) {
$res = $db->query($sql);
# Uptime topups
if ($topup['Type'] == 2) {
$userPhone = "Not set";
$userEmail = "Not set";
if ($res->rowCount() > 0) {
$row = $res->fetchObject();
$userPhone = $row->phone;
$userEmail = $row->email;
}
*/
# Topup not currently in use
if ($excess <= 0) {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = isset($topup['CurrentLimit']) ? ($topup['Limit'] - $topup['CurrentLimit']) : 0;
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalUptimeTopupsAvail += isset($topup['CurrentLimit']) ? $topup['CurrentLimit'] : $topup['Limit'];
$i++;
# Topup currently in use
} elseif (!isset($topup['CurrentLimit']) && $excess < $topup['Limit']) {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = $excess;
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalUptimeTopupsAvail += $topup['Limit'];
# Set current topup
$currentUptimeTopup = array();
$currentUptimeTopup['Used'] = $excess;
$currentUptimeTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
} elseif (isset($topup['CurrentLimit']) && $excess < $topup['CurrentLimit']) {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
# Set total available topups
$totalUptimeTopupsAvail += $topup['CurrentLimit'];
# These two items need fixing
$isDialup = 0;
$userService = "Not set";
# Set current topup
$currentUptimeTopup = array();
$currentUptimeTopup['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
$currentUptimeTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
# Topup has been used up
} else {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = $topup['Limit'];
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Subtract this topup from excess usage
$excess -= isset($topup['CurrentLimit']) ? $topup['CurrentLimit'] : $topup['Limit'];
$i++;
}
}
}
}
# HTML
?>
<table class="blockcenter">
<tr>
<td colspan="5" class="section">Account Information</td>
<td width="500" colspan="4" class="section">Account Information</td>
</tr>
<tr>
<td colspan="3" class="title">Username</td>
<td colspan="2" class="title">Service</td>
<td align="center" class="title">Username</td>
<td align="center" class="title">Traffic Cap</td>
<td align="center" class="title">Uptime Cap</td>
</tr>
<tr>
<td colspan="3" class="value"><?php echo $_SESSION['username']; ?></td>
<td colspan="2" class="value"><?php echo $userService; ?></td>
<td align="center" class="value"><?php echo $username; ?></td>
<td align="center" class="value">
<?php
if (is_numeric($trafficCap) && $trafficCap == 0) {
echo "Unlimited";
} elseif (is_string($trafficCap) && $trafficCap === "Prepaid") {
echo $trafficCap;
} else {
echo $trafficCap." MB";
}
?>
</td>
<td align="center" class="value">
<?php
if (is_numeric($uptimeCap) && $uptimeCap == 0) {
echo "Unlimited";
} elseif (is_string($uptimeCap) && $uptimeCap === "Prepaid") {
echo $uptimeCap;
} else {
echo $uptimeCap." MB";
}
?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="4" class="section">Traffic Usage</td>
</tr>
<tr>
<td align="center" class="title">Active Topup</td>
<td align="center" class="title">Total Topup</td>
<td align="center" class="title">Total Usage</td>
</tr>
<td align="center" class="value">
<?php
if (isset($currentTrafficTopup) && (!(is_numeric($trafficCap) && $trafficCap == 0))) {
echo sprintf("%.2f",$currentTrafficTopup['Used'])."/".sprintf($currentTrafficTopup['Cap'])." MB";
} else {
echo "None";
}
?>
</td>
<td align="center" class="value"><?php echo $totalTrafficTopupsAvail." MB"; ?></td>
<td align="center" class="value"><?php echo sprintf("%.2f",$totalTraffic)." MB"; ?></td>
<tr>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="4" class="section">Uptime Usage</td>
</tr>
<tr>
<td align="center" class="title">Active Topup</td>
<td align="center" class="title">Total Topup</td>
<td align="center" class="title">Total Usage</td>
</tr>
<tr>
<td align="center" class="value">
<?php
if (isset($currentUptimeTopup) && (!(is_numeric($uptimeCap) && $uptimeCap == 0))) {
echo sprintf("%.2f",$currentUptimeTopup['Used'])."/".sprintf($currentUptimeTopup['Cap'])." MB";
} else {
echo "None";
}
?>
</td>
<td align="center" class="value"><?php echo $totalUptimeTopupsAvail." MB"; ?></td>
<td align="center" class="value"><?php echo sprintf("%.2f",$totalUptime)." Min"; ?></td>
</tr>
</table>
<p>&nbsp;</p>
<?php
# Only display cap for DSL users
if (!$isDialup) {
# Dont display if we unlimited
if (!(is_numeric($trafficCap) && $trafficCap == 0)) {
?>
<table class="blockcenter">
<tr>
<td colspan="5" class="section">Usage Info</td>
<td width="500" colspan="3" class="section">Topup Overview: Traffic</td>
</tr>
<tr>
<td rowspan="2" class="section">Traffic</td>
<td class="title">Traffic Cap</td>
<td class="title">Topup remaining</td>
<td class="title">Current Topup</td>
<td class="title">Used This Month</td>
<td align="center" class="title">Used</td>
<td align="center" class="title">Valid From</td>
<td align="center" class="title">Valid To</td>
</tr>
<tr>
<?php
if (is_numeric($trafficCap) && $trafficCap > 0) {
?>
<td class="value"><?php echo $trafficCap; ?> MB</td>
<?php
} elseif (is_numeric($trafficCap) && $trafficCap == 0) {
?>
<td class="value">Uncapped</td>
<?php
} else {
?>
<td class="value"><?php echo $trafficCap; ?></td>
<?php
}
if (is_numeric($trafficCap) && $trafficCap == 0) {
?>
<td class="value">N/A</td>
<?php
} else {
foreach ($trafficRows as $trafficRow) {
?>
<td class="value"><?php echo $topupTrafficRemaining; ?> MB</td>
<tr>
<td align="center" class="value">
<?php
}
if (isset($currentTrafficTopup['Used']) && isset($currentTrafficTopup['Cap'])) {
echo sprintf("%.2f",$trafficRow['Used'])."/".sprintf($trafficRow['Cap'])." MB";
?>
<td class="value"><?php printf('%.2f', $currentTrafficTopup['Used']);
print("/".$currentTrafficTopup['Cap']); ?> MB</td>
</td>
<td align="center" class="value"><?php $validFrom = strtotime($trafficRow['ValidFrom']); echo date("Y-m-d",$validFrom);?></td>
<td align="center" class="value"><?php $validTo = strtotime($trafficRow['Expires']); echo date("Y-m-d",$validTo);?></td>
</tr>
<?php
} else {
}
?>
<td class="value">N/A</td>
</table>
<?php
}
}
# Dont display if we unlimited
if (!(is_numeric($uptimeCap) && $uptimeCap == 0)) {
?>
<td class="value"><?php printf('%.2f', $totalTraffic); ?> MB</td>
</tr>
<p>&nbsp;</p>
<table class="blockcenter">
<tr>
<td rowspan="2" class="section">Uptime</td>
<td class="title">Uptime Cap</td>
<td class="title">Topup remaining</td>
<td class="title">Current Topup</td>
<td class="title">Used This Month</td>
<td width="500" colspan="3" class="section">Topup Overview: Uptime</td>
</tr>
<tr>
<td align="center" class="title">Used</td>
<td align="center" class="title">Valid From</td>
<td align="center" class="title">Valid To</td>
</tr>
<?php
if (is_numeric($uptimeCap) && $uptimeCap > 0) {
?>
<td class="value"><?php echo $uptimeCap; ?> Min</td>
<?php
} elseif (is_numeric($uptimeCap) && $uptimeCap == 0) {
?>
<td class="value">Uncapped</td>
<?php
} else {
?>
<td class="value"><?php echo $uptimeCap; ?></td>
<?php
}
if (is_numeric($uptimeCap) && $uptimeCap == 0) {
?>
<td class="value">N/A</td>
<?php
} else {
?>
<td class="value"><?php echo $topupUptimeRemaining; ?> Min</td>
<?php
}
if (isset($currentUptimeTopup['Used']) && isset($currentTrafficTopup['Cap'])) {
foreach ($uptimeRows as $uptimeRow) {
?>
<td class="value"><?php printf('%.2f', $currentUptimeTopup['Used']);
print("/".$currentUptimeTopup['Cap']); ?> Min</td>
<tr>
<td align="center" class="value">
<?php
} else {
echo sprintf("%.2f",$uptimeRow['Used'])."/".sprintf($uptimeRow['Cap'])." MB";
?>
<td class="value">N/A</td>
</td>
<td align="center" class="value"><?php $validFrom = strtotime($uptimeRow['ValidFrom']); echo date("Y-m-d",$validFrom);?></td>
<td align="center" class="value"><?php $validTo = strtotime($uptimeRow['Expires']); echo date("Y-m-d",$validTo);?></td>
</tr>
<?php
}
}
?>
<td class="value"><?php printf('%.2f', $totalUptime); ?> Min</td>
</tr>
<!--
<tr>
<td colspan="2" class="section">Notifications</td>
</tr>
<form method="post">
<tr>
<td class="title">Email Address</td>
<td class="value">
<input type="text" name="notifyMethodEmail" value="php echo $userEmail; "></input>
</td>
</tr>
<tr>
<td class="title">Cell Number</td>
<td class="value">
<input type="text" name="notifyMethodCell" value="php echo $userPhone; "></input>
</td>
</tr>
</form>
--!>
</table>
<?php
}
}
?>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="5" align="center">
<a href="logs.php">Usage Logs</a>
</td>
</tr>
</table>
<br><br>
<font size="-1">
Note:
<li>Please contact your ISP if you have any problem using this interface.</li>
</font>
<p>&nbsp;</p>
<p align="center"><a href="logs.php">Usage Logs</a></p>
<?php
}
/*
# If this is a post and we're updating
if (isset($_POST['notifyUpdate']) && $_POST['notifyUpdate'] == "update") {
$username = $_SESSION['username'];
# Get user's ID
$sql = "
SELECT
ID
FROM
${DB_TABLE_PREFIX}users
WHERE
Username = '$username'
";
$res = $db->query($sql);
$row = $res->fetchObject();
$userID = $row->id;
$sql = "
SELECT
Name, Value
FROM
${DB_TABLE_PREFIX}user_attributes
WHERE
UserID = '$userID'
";
$res = $db->query($sql);
$userPhone = "Unavailable";
$userEmail = "Unavailable";
while ($row = $res->fetchObject()) {
if ($row->name == "SMRadius-Notify-Phone") {
$userPhone = $row->value;
}
if ($row->name == "SMRadius-Notify-Email") {
$userEmail = $row->value;
}
}
# If we want to update email address
if (isset($_POST['notifyMethodEmail']) && !empty($_POST['notifyMethodEmail'])) {
$db->beginTransaction();
# Unavailble if no email address is set yet
if ($userEmail == "Unavailable") {
# Prepare to insert email address for the first time
$emailStatement = $db->prepare("INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
('$userID','SMRadius-Notify-Email','=*',?)
");
$emailResult = $emailStatement->execute(array($_POST['notifyMethodEmail'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Email address updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating email address, please contact your ISP.</center>";
}
} else {
# Prepare to update existing email address
$emailStatement = $db->prepare("UPDATE
${DB_TABLE_PREFIX}user_attributes
SET
Value = ?
WHERE
Name = 'SMRadius-Notify-Email'
AND
UserID = '$userID'
");
$emailResult = $emailStatement->execute(array($_POST['notifyMethodEmail'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Email address updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating email address, please contact your ISP.</center>";
}
}
}
# If we want to update phone number
if (isset($_POST['notifyMethodCell']) && !empty($_POST['notifyMethodCell'])) {
$db->beginTransaction();
# Unavailable if there is none found for this user
if ($userPhone == "Unavailable") {
# Prepare to insert first number
$phoneStatement = $db->prepare("INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
('$userID','SMRadius-Notify-Phone','=*',?)
");
$phoneResult = $phoneStatement->execute(array($_POST['notifyMethodCell'],));
# If successful, commit
if ($phoneResult) {
$db->commit();
echo "<center>Mobile phone number updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating mobile phone number, please contact your ISP.</center>";
}
} else {
# Prepare to update existing number
$phoneStatement = $db->prepare("UPDATE
${DB_TABLE_PREFIX}user_attributes
SET
Value = ?
WHERE
Name = 'SMRadius-Notify-Phone'
AND
UserID = '$userID'
");
$phoneResult = $phoneStatement->execute(array($_POST['notifyMethodPhone'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Mobile phone number updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating mobile phone number, please contact your ISP.</center>";
}
}
}
}
*/
displayDetails();
# Footer
......
<?php
# Radius user logs
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# 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
......@@ -43,6 +43,16 @@ function displayLogs() {
<p class="middle center">
Display logs between
<?php
# Validate dates before sending
if (isset($_POST['searchFrom'])) {
if (!(preg_match("/^\d{4}\-(0[1-9]|1[0-2])\-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/",$_POST['searchFrom']))) {
unset($_POST['searchFrom']);
}
}
if (isset($_POST['searchFrom'])) {
$searchFrom = date("Y-m-d",strtotime($_POST['searchFrom']));
$_POST['searchFrom'] = $searchFrom;
}
if (isset($_POST['searchFrom'])) {
?>
<input type="text" name="searchFrom" size="11" value="<?php echo $_POST['searchFrom'] ?>"/>
......@@ -55,6 +65,16 @@ function displayLogs() {
?>
and
<?php
# Validate dates before sending
if (isset($_POST['searchTo'])) {
if (!(preg_match("/^\d{4}\-(0[1-9]|1[0-2])\-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/",$_POST['searchTo']))) {
unset($_POST['searchTo']);
}
}
if (isset($_POST['searchTo'])) {
$searchFrom = date("Y-m-d",strtotime($_POST['searchTo']));
$_POST['searchTo'] = $searchFrom;
}
if (isset($_POST['searchTo'])) {
?>
<input type="text" name="searchTo" size="11" value="<?php echo $_POST['searchTo'] ?>"/>
......@@ -95,79 +115,78 @@ function displayLogs() {
$extraSQL .= " AND EventTimestamp <= ?";
array_push($extraSQLVals,$_POST['searchTo']);
# Query to get all default data
# Accounting query FIXME nas receive and transmit rates
$sql = "
SELECT
EventTimestamp,
CallingStationID,
AcctSessionTime,
AcctInputOctets,
AcctInputGigawords,
AcctOutputOctets,
AcctOutputGigawords,
AcctTerminateCause
FROM
${DB_TABLE_PREFIX}accounting
WHERE
EventTimestamp,
CallingStationID,
AcctSessionTime / 60 AS AcctSessionTime,
AcctInputOctets / 1024 / 1024 +
AcctInputGigawords * 4096 AS AcctInputMbyte,
AcctOutputOctets / 1024 / 1024 +
AcctOutputGigawords * 4096 AS AcctOutputMbyte,
AcctTerminateCause
FROM
${DB_TABLE_PREFIX}accounting
WHERE
Username = ".$db->quote($_SESSION['username'])."
$extraSQL
ORDER BY
EventTimestamp
DESC
";
";
$res = $db->prepare($sql);
$res->execute($extraSQLVals);
# Define totals:
$totalData = 0;
$totalInputData = 0;
$totalOutputData = 0;
$totalSessionTime = 0;
# Display logs
$totalInput = 0;
$totalOutput = 0;
$totalTime = 0;
while ($row = $res->fetchObject()) {
# Input data calculation
$inputDataItem = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$inputDataItem += ($row->acctinputoctets / 1024) / 1024;
$inputData = 0;
if (isset($row->acctinputmbyte) && $row->acctinputmbyte > 0) {
$inputData += $row->acctinputmbyte;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096);
}
$totalInputData += $inputDataItem;
$totalInput += $inputData;
# Output data calculation
$outputDataItem = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$outputDataItem += ($row->acctoutputoctets / 1024) / 1024;
$outputData = 0;
if (isset($row->acctoutputmbyte) && $row->acctoutputmbyte > 0) {
$outputData += $row->acctoutputmbyte;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$outputDataItem += ($row->acctoutputgigawords * 4096);
}
$totalOutputData += $outputDataItem;
$totalData += $totalOutputData + $totalInputData;
$totalOutput += $outputData;
# Time calculation
$sessionTimeItem = 0;
# Uptime calculation
$sessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$sessionTimeItem += ($row->acctsessiontime - ($row->acctsessiontime % 60)) / 60;
$sessionTime += $row->acctsessiontime;
}
$totalSessionTime += $sessionTimeItem;
$totalTime += $sessionTime;
?>
<tr>
<td class="desc"><?php echo $row->eventtimestamp; ?></td>
<td class="desc"><?php echo $row->acctsessiontime; ?></td>
<td class="desc"><?php printf("%.2f",$sessionTime); ?></td>
<td class="desc"><?php echo $row->callingstationid; ?></td>
<td class="center desc"><?php echo strRadiusTermCode($row->acctterminatecause); ?></td>
<td class="center desc"><?php echo "NASTransmitRate"; ?></td>
<td class="center desc"><?php echo "NASReceiveRate"; ?></td>
<td class="right desc"><?php printf('%.2f',$inputDataItem); ?></td>
<td class="right desc"><?php printf('%.2f',$outputDataItem); ?></td>
<td class="center desc">
<?php
if (isset($row->nastransmitrate)) {
echo $row->nastransmitrate;
}
?>
</td>
<td class="center desc">
<?php
if (isset($row->nasreceiverate)) {
echo $row->nasreceiverate;
}
?>
</td>
<td class="right desc"><?php printf("%.2f",$inputData); ?></td>
<td class="right desc"><?php printf("%.2f",$outputData); ?></td>
</tr>
<?php
}
......@@ -178,15 +197,16 @@ function displayLogs() {
</tr>
<?php
} else {
$totalTraffic = $totalInput + $totalOutput;
?>
<tr>
<td colspan="6" class="right">Sub Total:</td>
<td class="right desc"><?php printf('%.2f',$totalInputData); ?></td>
<td class="right desc"><?php printf('%.2f',$totalOutputData); ?></td>
<td class="right desc"><?php printf("%.2f",$totalInput); ?></td>
<td class="right desc"><?php printf("%.2f",$totalOutput); ?></td>
</tr>
<tr>
<td colspan="6" class="right">Total:</td>
<td colspan="2" class="center desc"><?php printf('%.2f',$totalData); ?></td>
<td colspan="2" class="center desc"><?php printf("%.2f",$totalTraffic); ?></td>
</tr>
<?php
}
......
/*
*
* User Control Panel Stylesheet
* Copyright (C) 2007-2009, AllWorldIT
* Copyright (C) 2007-2015, AllWorldIT
*
* 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
......@@ -198,3 +198,20 @@ mtsearchtableorder {
mtsearchtablesubmit {
font-weight: bold;
}
.graph {
position: relative; /* IE is dumb */
margin: auto;
width: 200px;
border: 1px solid #000066;
padding: 2px;
}
.graph .bar {
display: block;
position: relative;
background: #E6E6FA;
text-align: center;
color: #333;
height: 2em;
line-height: 2em;
}
.graph .bar span { position: absolute; left: 1em; }