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
Showing
with 2460 additions and 676 deletions
<?php
# Admin User Topups functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -10,13 +26,13 @@ function createAdminUserTopup($params) {
$timestamp = date('Y-m-d H:i:s');
# Perform query
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
$res = DBDo("INSERT INTO @TP@topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo'])
);
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -27,7 +43,7 @@ function createAdminUserTopup($params) {
function updateAdminUserTopup($params) {
# Perform query
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -36,7 +52,7 @@ function updateAdminUserTopup($params) {
);
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -46,11 +62,19 @@ function updateAdminUserTopup($params) {
# Delete user topup
function removeAdminUserTopup($params) {
# Perform query
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
# Delete topup summary
$res = DBDo("DELETE FROM @TP@topups_summary WHERE TopupID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
# Delete topup
$res = DBDo("DELETE FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -61,7 +85,7 @@ function removeAdminUserTopup($params) {
function getAdminUserTopup($params) {
# Perform query
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -93,11 +117,11 @@ function getAdminUserTopups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'topups.ID',
'Type' => 'topups.Type',
'Value' => 'topups.Value',
'ValidFrom' => 'topups.ValidFrom',
'ValidTo' => 'topups.ValidTo'
'ID' => '@TP@topups.ID',
'Type' => '@TP@topups.Type',
'Value' => '@TP@topups.Value',
'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => '@TP@topups.ValidTo'
);
# Perform query
......@@ -105,7 +129,7 @@ function getAdminUserTopups($params) {
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......
<?php
# Admin Users functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -8,13 +24,13 @@ function getAdminUsers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users.ID',
'Username' => 'users.Username',
'Disabled' => 'users.Disabled',
'ID' => '@TP@users.ID',
'Username' => '@TP@users.Username',
'Disabled' => '@TP@users.Disabled',
);
# Perform query
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM users",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM @TP@users",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -45,7 +61,7 @@ function getAdminUsers($params) {
function getAdminUser($params) {
# Perform query
$res = DBSelect("SELECT ID, Username, Disabled FROM users WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Username, Disabled FROM @TP@users WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -71,32 +87,74 @@ function removeAdminUser($params) {
DBBegin();
# Delete user information, if any
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_userdata WHERE UserID = ?",array($params[0]));
# Delete user attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE UserID = ?",array($params[0]));
}
# Remove user from groups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE UserID = ?",array($params[0]));
}
# Delete user
# Get list of topups and delete summaries
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
$topupList = array();
$res = DBSelect("
SELECT
@TP@topups_summary.TopupID
FROM
@TP@topups_summary, @TP@topups
WHERE
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?",
array($params[0])
);
if (!is_object($res)) {
$res = FALSE;
} else {
while ($row = $res->fetchObject()) {
array_push($topupList,$row->topupid);
}
$res = TRUE;
}
if (sizeof($topupList) > 0 && $res !== FALSE) {
# Remove topup summaries
foreach ($topupList as $id) {
if ($res !== FALSE) {
$res = DBDo("
DELETE FROM
@TP@topups_summary
WHERE
TopupID = ?",
array($id)
);
}
}
}
}
# Commit and return if successful
# Remove topups
if ($res !== FALSE) {
DBCommit();
$res = DBDo("DELETE FROM @TP@topups WHERE UserID = ?",array($params[0]));
}
# Delete user
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
}
# Return result
if ($res !== TRUE) {
DBRollback();
return $res;
# Else rollback database
} else {
DBRollback();
DBCommit();
}
return NULL;
}
......@@ -104,10 +162,10 @@ function removeAdminUser($params) {
function createAdminUser($params) {
# Perform query
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($params[0]['Username'],$params[0]['Disabled']));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -118,10 +176,10 @@ function createAdminUser($params) {
function updateAdminUser($params) {
# Perform query
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......
<?php
# WiSP Location Members functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -6,10 +22,10 @@ include_once("include/db.php");
function removeWiSPLocationMember($params) {
# Perform query
$res = DBDo("UPDATE wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -21,20 +37,20 @@ function getWiSPLocationMembers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users.ID',
'Username' => 'users.Username'
'ID' => '@TP@users.ID',
'Username' => '@TP@users.Username'
);
# Perform query
$res = DBSelectSearch("
SELECT
users.ID, users.Username
@TP@users.ID, @TP@users.Username
FROM
wisp_userdata, users
@TP@wisp_userdata, @TP@users
WHERE
wisp_userdata.LocationID = ".DBQuote($params[0])."
@TP@wisp_userdata.LocationID = ".DBQuote($params[0])."
AND
users.ID = wisp_userdata.UserID
@TP@users.ID = @TP@wisp_userdata.UserID
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......
<?php
# WiSP Locations functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -8,12 +24,12 @@ function getWiSPLocations($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'wisp_locations.ID',
'Name' => 'wisp_locations.Name'
'ID' => '@TP@wisp_locations.ID',
'Name' => '@TP@wisp_locations.Name'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name FROM wisp_locations",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Name FROM @TP@wisp_locations",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -43,7 +59,7 @@ function getWiSPLocations($params) {
function getWiSPLocation($params) {
# Perform query
$res = DBSelect("SELECT ID, Name FROM wisp_locations WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name FROM @TP@wisp_locations WHERE ID = ?",array($params[0]));
# Return if error or nothing to return
if (!is_object($res)) {
......@@ -68,20 +84,19 @@ function removeWiSPLocation($params) {
DBBegin();
# Unlink users from this location
$res = DBDo("UPDATE wisp_userdata SET LocationID = NULL WHERE LocationID = ?",array($params[0]));
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = NULL WHERE LocationID = ?",array($params[0]));
# Delete location
if ($res !== FALSE) {
$res = DBDo("DELETE FROM wisp_locations WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_locations WHERE ID = ?",array($params[0]));
}
# Commit changes if successful
if ($res !== FALSE) {
DBCommit();
# Return result
if ($res !== TRUE) {
DBRollback();
return $res;
# Rollback database if error
} else {
DBRollback();
DBCommit();
}
return NULL;
......@@ -91,10 +106,10 @@ function removeWiSPLocation($params) {
function createWiSPLocation($params) {
# Perform query
$res = DBDo("INSERT INTO wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
$res = DBDo("INSERT INTO @TP@wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -105,10 +120,10 @@ function createWiSPLocation($params) {
function updateWiSPLocation($params) {
# Perform query
$res = DBDo("UPDATE wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......
<?php
# WiSP User Logs functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -6,14 +22,18 @@ include_once("include/db.php");
# Return user logs summary
function getWiSPUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect("
SELECT
user_attributes.Name,
user_attributes.Value
@TP@group_attributes.Name,
@TP@group_attributes.Value
FROM
user_attributes
@TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE
user_attributes.UserID = ?",
@TP@group_attributes.GroupID = @TP@groups.ID
AND @TP@groups.ID = @TP@users_to_groups.GroupID
AND @TP@users_to_groups.UserID = ?",
array($params[0]['ID'])
);
......@@ -22,10 +42,7 @@ function getWiSPUserLogsSummary($params) {
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
# 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()) {
......@@ -37,31 +54,65 @@ function getWiSPUserLogsSummary($params) {
}
}
# Add cap type / amount to result
# Get user attributes
$res = DBSelect("
SELECT
Name,
Value
FROM
@TP@user_attributes
WHERE
UserID = ?",
array($params[0]['ID'])
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
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 caps to result
$resultArray = array();
$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']);
$periodKey = new DateTime($params[0]['PeriodKey']."-01");
# Return if error
if (!is_object($periodKey)) {
return $periodKey;
}
# Fetch user uptime and traffic summary
$res = DBSelect("
SELECT
topups_summary.Balance,
topups.Type,
topups.Value
@TP@topups_summary.Balance,
@TP@topups.ID,
@TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM
topups_summary,
topups
@TP@topups_summary,
@TP@topups
WHERE
topups_summary.TopupID = topups.ID
AND topups.UserID = ?
AND topups_summary.PeriodKey = ?
AND topups.Depleted = 0
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?
AND @TP@topups_summary.PeriodKey = ?
AND @TP@topups_summary.Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m'))
@TP@topups.Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
# Return if error
......@@ -74,26 +125,30 @@ function getWiSPUserLogsSummary($params) {
$i = 0;
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$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;
$i++;
}
# Fetch user uptime and traffic topups
$periodKeyEnd = new DateTime($periodKey->format('Y-m-d'));
$periodKeyEnd->modify("+1 month");
$res = DBSelect("
SELECT
Value, Type
ID, Value, Type, ValidTo
FROM
topups
@TP@topups
WHERE
topups.UserID = ?
AND topups.ValidFrom = ?
AND topups.ValidTo >= ?
AND topups.Depleted = 0
UserID = ?
AND ValidFrom = ?
AND ValidTo >= ?
AND Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d'))
Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
);
# Return if error
......@@ -104,6 +159,8 @@ function getWiSPUserLogsSummary($params) {
# Store normal topups
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$i++;
......@@ -111,18 +168,18 @@ function getWiSPUserLogsSummary($params) {
$res = DBSelect("
SELECT
accounting.AcctSessionTime,
accounting.AcctInputOctets,
accounting.AcctInputGigawords,
accounting.AcctOutputOctets,
accounting.AcctOutputGigawords
SUM(@TP@accounting.AcctSessionTime) / 60 AS TotalSessionTime,
SUM(@TP@accounting.AcctInputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctInputGigawords) * 4096 +
SUM(@TP@accounting.AcctOutputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctOutputGigawords) * 4096 AS TotalTraffic
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.ID = ?
AND EventTimestamp >= ?
AND accounting.Username = users.Username",
array($params[0]['ID'],$dateFrom->format('Y-m-d'))
@TP@users.ID = ?
AND @TP@accounting.PeriodKey = ?
AND @TP@accounting.Username = @TP@users.Username",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
if (!is_object($res)) {
......@@ -130,169 +187,178 @@ function getWiSPUserLogsSummary($params) {
}
# Set total traffic and uptime used
$totalTraffic = 0;
$totalUptime = 0;
while ($row = $res->fetchObject()) {
$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);
# Add usage to our return array
$resultArray['trafficUsage'] = 0;
$resultArray['uptimeUsage'] = 0;
if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$resultArray['trafficUsage'] += $row->totaltraffic;
}
if (isset($row->totalsessiontime) && $row->totalsessiontime > 0) {
$resultArray['uptimeUsage'] += $row->totalsessiontime;
}
# Set excess traffic usage
# Excess usage
$excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) {
$excessTraffic += $totalTraffic - $trafficCap;
if ($trafficCap == -1) {
$excessTraffic = $resultArray['trafficUsage'];
} else {
$excessTraffic += $totalTraffic;
$excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
}
# Set excess uptime usage
$excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) {
$excessUptime += $totalUptime - $uptimeCap;
if ($uptimeCap == -1) {
$excessUptime = $resultArray['uptimeUsage'];
} else {
$excessUptime += $totalUptime;
$excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
}
$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'];
}
}
# Loop through topups and add to return array
$resultArray['trafficTopups'] = 0;
$resultArray['uptimeTopups'] = 0;
$resultArray['TotalTrafficTopups'] = 0;
$resultArray['TotalUptimeTopups'] = 0;
# Traffic and uptime topups
$resultArray['AllTrafficTopups'] = array();
$resultArray['AllUptimeTopups'] = array();
$t = 0; $u = 0;
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
# Topup not currently in use
if ($excessTraffic <= 0) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Subtract this topup from excessTraffic usage
$excessTraffic -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $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'];
}
}
if ($topupItem['Type'] == 2) {
# Topup not currently in use
if ($excessUptime <= 0) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Subtract this topup from excessUptime usage
$excessUptime -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $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);
}
......@@ -302,45 +368,45 @@ function getWiSPUserLogs($params) {
# 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',
'ID' => '@TP@accounting.ID',
'EventTimestamp' => '@TP@accounting.EventTimestamp',
'AcctStatusType' => '@TP@accounting.AcctStatusType',
'ServiceType' => '@TP@accounting.ServiceType',
'FramedProtocol' => '@TP@accounting.FramedProtocol',
'NASPortType' => '@TP@accounting.NASPortType',
'NASPortID' => '@TP@accounting.NASPortID',
'CallingStationID' => '@TP@accounting.CallingStationID',
'CalledStationID' => '@TP@accounting.CalledStationID',
'AcctSessionID' => '@TP@accounting.AcctSessionID',
'FramedIPAddress' => '@TP@accounting.FramedIPAddress',
);
# Perform query
$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,
accounting.AcctSessionTime
@TP@accounting.ID,
@TP@accounting.EventTimestamp,
@TP@accounting.AcctStatusType,
@TP@accounting.ServiceType,
@TP@accounting.FramedProtocol,
@TP@accounting.NASPortType,
@TP@accounting.NASPortID,
@TP@accounting.CallingStationID,
@TP@accounting.CalledStationID,
@TP@accounting.AcctSessionID,
@TP@accounting.FramedIPAddress,
@TP@accounting.AcctInputOctets / 1024 / 1024 +
@TP@accounting.AcctInputGigawords * 4096 AS AcctInput,
@TP@accounting.AcctOutputOctets / 1024 / 1024 +
@TP@accounting.AcctOutputGigawords * 4096 AS AcctOutput,
@TP@accounting.AcctTerminateCause,
@TP@accounting.AcctSessionTime / 60 AS AcctSessionTime
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.Username = accounting.Username
@TP@users.Username = @TP@accounting.Username
AND
users.ID = ".DBQuote($params[0])."
@TP@users.ID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......@@ -354,31 +420,21 @@ function getWiSPUserLogs($params) {
while ($row = $sth->fetchObject()) {
# Input
$acctInputMbyte = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$acctInputMbyte += ($row->acctinputgigawords * 4096);
$acctInput = 0;
if (isset($row->acctinput) && $row->acctinput > 0) {
$acctInput += $row->acctinput;
}
# Output
$acctOutputMbyte = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
$acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
$acctOutput += $row->acctoutput;
}
# Uptime
$acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += ($row->acctsessiontime / 60);
$acctSessionTime += $row->acctsessiontime;
}
ceil($acctSessionTime);
# Build array for this row
$item = array();
......@@ -397,10 +453,10 @@ function getWiSPUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte;
$item['AcctOutputMbyte'] = $acctOutputMbyte;
$item['AcctSessionTime'] = $acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype);
$item['AcctInput'] = $acctInput;
$item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# Push this row onto main array
array_push($resultArray,$item);
......
<?php
# WiSP User Topups functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -10,13 +26,13 @@ function createWiSPUserTopup($params) {
$timestamp = date('Y-m-d H:i:s');
# Perform query
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
$res = DBDo("INSERT INTO @TP@topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo'])
);
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -27,7 +43,7 @@ function createWiSPUserTopup($params) {
function updateWiSPUserTopup($params) {
# Perform query
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -36,7 +52,7 @@ function updateWiSPUserTopup($params) {
);
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -47,10 +63,10 @@ function updateWiSPUserTopup($params) {
function removeWiSPUserTopup($params) {
# Perform query
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return result
if (!is_numeric($res)) {
if ($res !== TRUE) {
return $res;
}
......@@ -61,7 +77,7 @@ function removeWiSPUserTopup($params) {
function getWiSPUserTopup($params) {
# Perform query
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return if error or no result
if (!is_object($res)) {
......@@ -93,11 +109,11 @@ function getWiSPUserTopups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'topups.ID',
'Type' => 'topups.Type',
'Value' => 'topups.Value',
'ValidFrom' => 'topups.ValidFrom',
'ValidTo' => 'topups.ValidTo'
'ID' => '@TP@topups.ID',
'Type' => '@TP@topups.Type',
'Value' => '@TP@topups.Value',
'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => '@TP@topups.ValidTo'
);
# Perform query
......@@ -105,7 +121,7 @@ function getWiSPUserTopups($params) {
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......
<?php
# WiSP Users functions
# Copyright (C) 2007-2011, 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
# 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.
include_once("include/db.php");
......@@ -8,29 +24,29 @@ function getWiSPUsers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'Username' => 'users.Username',
'Disabled' => 'users.Disabled',
'ID' => 'wisp_userdata.UserID',
'Firstname' => 'wisp_userdata.Firstname',
'Lastname' => 'wisp_userdata.Lastname',
'Email' => 'wisp_userdata.Email',
'Phone' => 'wisp_userdata.Phone'
'Username' => '@TP@users.Username',
'Disabled' => '@TP@users.Disabled',
'ID' => '@TP@wisp_userdata.UserID',
'Firstname' => '@TP@wisp_userdata.Firstname',
'Lastname' => '@TP@wisp_userdata.Lastname',
'Email' => '@TP@wisp_userdata.Email',
'Phone' => '@TP@wisp_userdata.Phone'
);
# Perform query
$res = DBSelectSearch("
SELECT
users.Username,
users.Disabled,
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Email,
wisp_userdata.Phone
@TP@users.Username,
@TP@users.Disabled,
@TP@wisp_userdata.UserID,
@TP@wisp_userdata.FirstName,
@TP@wisp_userdata.LastName,
@TP@wisp_userdata.Email,
@TP@wisp_userdata.Phone
FROM
users, wisp_userdata
@TP@users, @TP@wisp_userdata
WHERE
wisp_userdata.UserID = users.ID
@TP@wisp_userdata.UserID = @TP@users.ID
",$params[1],$filtersorts,$filtersorts
);
$sth = $res[0]; $numResults = $res[1];
......@@ -68,21 +84,22 @@ function getWiSPUser($params) {
# Query for userdata and username
$res = DBSelect("
SELECT
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Phone,
wisp_userdata.Email,
wisp_userdata.LocationID,
users.Username
FROM
wisp_userdata, users
WHERE
wisp_userdata.UserID = ?
AND
users.ID = wisp_userdata.UserID
",array($params[0])
SELECT
@TP@wisp_userdata.UserID,
@TP@wisp_userdata.FirstName,
@TP@wisp_userdata.LastName,
@TP@wisp_userdata.Phone,
@TP@wisp_userdata.Email,
@TP@wisp_userdata.LocationID,
@TP@users.Username,
@TP@users.Disabled
FROM
@TP@wisp_userdata, @TP@users
WHERE
@TP@wisp_userdata.UserID = ?
AND
@TP@users.ID = @TP@wisp_userdata.UserID
",array($params[0])
);
# Return if error
......@@ -97,24 +114,43 @@ function getWiSPUser($params) {
# Set userdata fields
$resultArray['ID'] = $row->userid;
$resultArray['Username'] = $row->username;
$resultArray['Firstname'] = $row->firstname;
$resultArray['Lastname'] = $row->lastname;
$resultArray['Phone'] = $row->phone;
$resultArray['Email'] = $row->email;
$resultArray['LocationID'] = $row->locationid;
$resultArray['Attributes'] = array();
$resultArray['Disabled'] = $row->disabled;
if (isset($row->firstname)) {
$resultArray['Firstname'] = $row->firstname;
} else {
$resultArray['Firstname'] = null;
}
if (isset($row->lastname)) {
$resultArray['Lastname'] = $row->lastname;
} else {
$resultArray['Lastname'] = null;
}
if (isset($row->phone)) {
$resultArray['Phone'] = $row->phone;
} else {
$resultArray['Phone'] = null;
}
if (isset($row->email)) {
$resultArray['Email'] = $row->email;
} else {
$resultArray['Email'] = null;
}
if (isset($row->locationid)) {
$resultArray['LocationID'] = $row->locationid;
} else {
$resultArray['LocationID'] = null;
}
# Query to get user password
# Password query
$res = DBSelect("
SELECT
user_attributes.Value
FROM
user_attributes
WHERE
user_attributes.Name = 'User-Password'
AND
user_attributes.UserID = ?
",array($params[0])
SELECT
Value
FROM
@TP@user_attributes
WHERE
Name = ?
AND @TP@user_attributes.UserID = ?
",array('User-Password',$params[0])
);
# Return if error
......@@ -122,22 +158,33 @@ function getWiSPUser($params) {
return $res;
}
# Set user password field
# Set password
$row = $res->fetchObject();
$resultArray['Password'] = $row->value;
if (isset($row->value)) {
$resultArray['Password'] = $row->value;
} else {
$resultArray['Password'] = null;
}
# Set number of results
$numResults = count($resultArray);
# Return results
return array($resultArray,$numResults);
}
# Query to get all other attributes
# Get wisp user attributes
function getWiSPUserAttributes($params) {
# Attributes query
$res = DBSelect("
SELECT
user_attributes.ID,
user_attributes.Name,
user_attributes.Operator,
user_attributes.Value
FROM
user_attributes
WHERE
user_attributes.UserID = ?
",array($params[0])
SELECT
ID, Name, Operator, Value
FROM
@TP@user_attributes
WHERE
@TP@user_attributes.UserID = ?",
array($params[0])
);
# Return if error
......@@ -145,21 +192,59 @@ function getWiSPUser($params) {
return $res;
}
# Array for multiple attributes
# Set attributes
$i = 0;
$attributes = array();
while ($row = $res->fetchObject()) {
$resultsArray['Attributes'][$i]['ID'] = $row->id;
$resultsArray['Attributes'][$i]['Name'] = $row->name;
$resultsArray['Attributes'][$i]['Operator'] = $row->operator;
$resultsArray['Attributes'][$i]['Value'] = $row->value;
$attributes[$i] = array();
$attributes[$i]['ID'] = $row->id;
$attributes[$i]['Name'] = $row->name;
$attributes[$i]['Operator'] = $row->operator;
$attributes[$i]['Value'] = $row->value;
$i++;
}
# Get number of results
$numResults = $res->rowCount();
# Set number of results
$numResults = count($attributes);
# Return results
return array($resultArray,$numResults);
return array($attributes,$numResults);
}
# Get wisp user groups
function getWiSPUserGroups($params) {
# Groups query
$res = DBSelect("
SELECT
@TP@groups.Name, @TP@groups.ID
FROM
@TP@users_to_groups, @TP@groups
WHERE
@TP@users_to_groups.GroupID = @TP@groups.ID
AND @TP@users_to_groups.UserID = ?",
array($params[0])
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Set groups
$i = 0;
$groups = array();
while ($row = $res->fetchObject()) {
$groups[$i]['ID'] = $row->id;
$groups[$i]['Name'] = $row->name;
$i++;
}
# Set number of results
$numResults = count($groups);
# Return results
return array($groups,$numResults);
}
# Remove wisp user
......@@ -169,30 +254,72 @@ function removeWiSPUser($params) {
DBBegin();
# Delete user information
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_userdata WHERE UserID = ?",array($params[0]));
# Delete user attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE UserID = ?",array($params[0]));
}
# Remove user from groups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE UserID = ?",array($params[0]));
}
# Delete user
# Get list of topups and delete summaries
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
$topupList = array();
$res = DBSelect("
SELECT
@TP@topups_summary.TopupID
FROM
@TP@topups_summary, topups
WHERE
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?",
array($params[0])
);
if (!is_object($res)) {
$res = FALSE;
} else {
while ($row = $res->fetchObject()) {
array_push($topupList,$row->topupid);
}
}
if ($res !== FALSE && sizeof($topupList) > 0) {
# Remove topup summaries
foreach ($topupList as $id) {
if ($res !== FALSE) {
$res = DBDo("
DELETE FROM
@TP@topups_summary
WHERE
TopupID = ?",
array($id)
);
}
}
}
}
# Commit and return if successful
# Remove topups
if ($res !== FALSE) {
DBCommit();
$res = DBDo("DELETE FROM @TP@topups WHERE UserID = ?",array($params[0]));
}
# Delete user
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
}
# Return result
if ($res !== TRUE) {
DBRollback();
return $res;
# Else rollback database
} else {
DBRollback();
DBCommit();
}
return NULL;
......@@ -206,18 +333,18 @@ function createWiSPUser($params) {
# Begin transaction
DBBegin();
# Perform first query
$res = "Username & Password required for single user. For adding multiple users an integer is required.";
$res = "Username required for single user. For adding multiple users an integer is required.";
# If we adding single user
if (empty($params[0]['Number']) && !empty($params[0]['Password']) && !empty($params[0]['Username'])) {
if (empty($params[0]['Number']) && !empty($params[0]['Username'])) {
# Insert username
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($params[0]['Username'],$params[0]['Disabled']));
# Continue with others if successful
if ($res !== FALSE) {
$userID = DBLastInsertID();
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array($userID,
......@@ -229,77 +356,93 @@ function createWiSPUser($params) {
# Link users ID to make user a wisp user
if ($res !== FALSE) {
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",array($userID));
$res = DBDo("INSERT INTO @TP@wisp_userdata (UserID) VALUES (?)",array($userID));
}
# Add personal information
if ($res !== FALSE && isset($params[0]['Firstname'])) {
$res = DBDo("UPDATE wisp_userdata SET FirstName = ? WHERE UserID = ?",array($params[0]['Firstname'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET FirstName = ? WHERE UserID = ?",array($params[0]['Firstname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Lastname'])) {
$res = DBDo("UPDATE wisp_userdata SET LastName = ? WHERE UserID = ?",array($params[0]['Lastname'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET LastName = ? WHERE UserID = ?",array($params[0]['Lastname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Phone'])) {
$res = DBDo("UPDATE wisp_userdata SET Phone = ? WHERE UserID = ?",array($params[0]['Phone'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET Phone = ? WHERE UserID = ?",array($params[0]['Phone'],$userID));
}
if ($res !== FALSE && isset($params[0]['Email'])) {
$res = DBDo("UPDATE wisp_userdata SET Email = ? WHERE UserID = ?",array($params[0]['Email'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET Email = ? WHERE UserID = ?",array($params[0]['Email'],$userID));
}
if ($res !== FALSE && isset($params[0]['LocationID'])) {
$res = DBDo("UPDATE wisp_userdata SET LocationID = ? WHERE UserID = ?",array($params[0]['LocationID'],$userID));
if ($res !== FALSE && !empty($params[0]['LocationID'])) {
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = ? WHERE UserID = ?",array($params[0]['LocationID'],$userID));
}
# Grab each attribute and add it's details to the database
if ($res !== FALSE && isset($params[0]['Attributes'])) {
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
# Default value without modifier
$attrValue = $attr['Value'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
case "Minutes":
$attrValue = $attr['Value'];
case "Hours":
$attrValue = $attr['Value'] * 60;
case "Days":
$attrValue = $attr['Value'] * 1440;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
case "Months":
$attrValue = $attr['Value'] * 44640;
case "MBytes":
$attrValue = $attr['Value'];
case "GBytes":
$attrValue = $attr['Value'] * 1000;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
# We only want to add attributes with all values
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
}
# Add attribute
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$userID,
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
# Add attribute
$res = DBDo("
INSERT INTO
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$userID,
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
}
}
}
# Link user to groups if any selected
if ($res !== FALSE && isset($params[0]['Groups'])) {
if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array();
# Filter out unique group ID's
......@@ -310,7 +453,7 @@ function createWiSPUser($params) {
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($userID,$groupID));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($userID,$groupID));
}
}
......@@ -340,11 +483,11 @@ function createWiSPUser($params) {
# Check if username used
$res = DBSelect("
SELECT
users.Username
@TP@users.Username
FROM
users
@TP@users
WHERE
users.Username = ?
@TP@users.Username = ?
",array($thisUsername)
);
......@@ -366,64 +509,80 @@ function createWiSPUser($params) {
# Insert users from array into database
foreach ($wispUser as $username => $password) {
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($username));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($username,$params[0]['Disabled']));
if ($res !== FALSE) {
$id = DBLastInsertID();
$res = DBDo("INSERT INTO user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)",
$res = DBDo("INSERT INTO @TP@user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)",
array($id,'User-Password','==',$password)
);
# Grab each attribute and add it's details to the database
if ($res !== FALSE && isset($params[0]['Attributes'])) {
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
# Default value without modifier
$attrValue = $attr['Value'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
case "Minutes":
$attrValue = $attr['Value'];
case "Hours":
$attrValue = $attr['Value'] * 60;
case "Days":
$attrValue = $attr['Value'] * 1440;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
case "Months":
$attrValue = $attr['Value'] * 44640;
case "MBytes":
$attrValue = $attr['Value'];
case "GBytes":
$attrValue = $attr['Value'] * 1000;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
# We only want to add attributes with all values
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
}
# Add attribute
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$id,
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
# Add attribute
$res = DBDo("
INSERT INTO
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$id,
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
}
}
}
# Link user to groups if any selected
if ($res !== FALSE && isset($params[0]['Groups'])) {
if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array();
# Filter out unique group ID's
......@@ -434,13 +593,13 @@ function createWiSPUser($params) {
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($id,$groupID));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($id,$groupID));
}
}
# Link to wisp users
if ($res !== FALSE) {
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",
$res = DBDo("INSERT INTO @TP@wisp_userdata (UserID) VALUES (?)",
array($id)
);
}
......@@ -492,11 +651,11 @@ function createWiSPUser($params) {
}
# Commit changes if all was successful, else rollback
if ($res !== FALSE) {
DBCommit();
if ($res !== TRUE) {
DBRollback();
return $res;
} else {
DBRollback();
DBCommit();
}
return NULL;
......@@ -506,40 +665,194 @@ function createWiSPUser($params) {
function updateWiSPUser($params) {
DBBegin();
$res = TRUE;
# Perform query
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
# If successful, continue
$res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
# Change password
if ($res !== FALSE) {
$res = DBDo("UPDATE user_attributes SET User-Password = ? WHERE UserID = ?",array($params[0]['Username'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@user_attributes SET Value = ? WHERE UserID = ? AND Name = ?",
array($params[0]['Password'],$params[0]['ID'],'User-Password'));
}
# If successful, continue
if ($res !== FALSE) {
$res = DBDo("
UPDATE
wisp_userdata
@TP@wisp_userdata
SET
FirstName = ?,
LastName = ?,
Phone = ?,
Email = ?,
LocationID = ?
Email = ?
WHERE
UserID = ?",
array($params[0]['Firstname'],
$params[0]['Lastname'],
$params[0]['Phone'],
$params[0]['Email'],
$params[0]['LocationID'],
$params[0]['ID'])
);
}
# If successful, add location if any
if ($res !== FALSE && !empty($params[0]['LocationID'])) {
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = ? WHERE UserID = ?",
array($params[0]['LocationID'],$params[0]['ID'])
);
}
# Process attributes being removed
if ($res !== FALSE && count($params[0]['RAttributes']) > 0) {
foreach ($params[0]['RAttributes'] as $attr) {
if ($res !== FALSE) {
# Perform query
$res = DBDo("DELETE FROM @TP@user_attributes WHERE ID = ?",array($attr));
}
}
}
# Process groups being removed
if ($res !== FALSE && count($params[0]['RGroups']) > 0) {
foreach ($params[0]['RGroups'] as $attr) {
if ($res !== FALSE) {
# Perform query
$res = DBDo("
DELETE FROM
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
array($params[0]['ID'],$attr)
);
}
}
}
# Grab each attribute and add it's details to the database
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
# We only want to add attributes with all values
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
# Check if we adding or updating
if ($res !== FALSE) {
# We adding an attribute..
if ($attr['ID'] < 0) {
$res = DBDo("
INSERT INTO
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$params[0]['ID'],
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
# We updating an attribute..
} else {
$res = DBDo("
UPDATE
@TP@user_attributes
SET
Name = ?,
Operator = ?,
Value = ?
WHERE
ID = ?",
array($attr['Name'],$attr['Operator'],$attrValue,$attr['ID'])
);
}
}
}
}
}
# Link user to groups if any selected
if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array();
# Filter out unique group ID's
foreach ($params[0]['Groups'] as $group) {
foreach ($group as $ID=>$value) {
$refinedGroups[$value] = $value;
}
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
if ($res !== FALSE) {
$res = DBSelect("
SELECT
ID
FROM
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
array($params[0]['ID'],$groupID)
);
}
if (is_object($res)) {
if ($res->rowCount() == 0) {
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['ID'],$groupID));
} else {
$res = TRUE;
}
}
}
}
# Commit changes if all was successful, else break
if ($res !== FALSE) {
DBCommit();
if ($res !== TRUE) {
DBRollback();
return $res;
} else {
DBRollback();
DBCommit();
}
return NULL;
......
<?php
# JSON 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
......@@ -153,5 +153,37 @@ class json_response {
}
}
function jsonSuccess($name = 'Result',$type = 'int',$value = 0) {
# Build response
$res = new json_response;
$res->addField($name,$type);
$res->parseHash(array(
$name => $value
));
# Export
echo json_encode($res->export());
}
function jsonError($code,$reason) {
# Build response
$res = new json_response;
$res->setStatus(-1);
$res->addField('ErrorCode','int');
$res->addField('ErrorReason','string');
$res->parseHash(array(
'ErrorCode' => $code,
'ErrorReason' => $reason
));
# Export
echo json_encode($res->export());
}
# vim: ts=4
<?php
# Web Admin UI Config
# 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
# 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
......@@ -74,9 +74,13 @@ function DBSelect($query,$args = array())
{
global $db;
# Replace table prefix template
$result = ReplacePrefix($query, $args);
$rawQuery = $result[0]; $rawArgs = $result[1];
# Try prepare, and catch exceptions
try {
$stmt = $db->prepare($query);
$stmt = $db->prepare($rawQuery);
} catch (PDOException $e) {
return $e->getMessage();
......@@ -84,7 +88,7 @@ function DBSelect($query,$args = array())
}
# Execute query
$res = $stmt->execute($args);
$res = $stmt->execute($rawArgs);
if ($res === FALSE) {
return $stmt->errorInfo();
}
......@@ -104,9 +108,13 @@ function DBDo($command,$args = array())
{
global $db;
# Replace table prefix template
$result = ReplacePrefix($command, $args);
$rawCommand = $result[0]; $rawArgs = $result[1];
# Try prepare, and catch exceptions
try {
$stmt = $db->prepare($command);
$stmt = $db->prepare($rawCommand);
} catch (PDOException $e) {
return $e->getMessage();
......@@ -114,7 +122,7 @@ function DBDo($command,$args = array())
}
# Execute query
$res = $stmt->execute($args);
$res = $stmt->execute($rawArgs);
if ($res === FALSE) {
return $stmt->errorInfo();
}
......@@ -134,7 +142,11 @@ function DBSelectNumResults($query,$args = array())
global $db;
$res = DBSelect("SELECT COUNT(*) AS num_results $query",$args);
# Replace table prefix template
$result = ReplacePrefix($query, $args);
$rawQuery = $result[0]; $rawArgs = $result[1];
$res = DBSelect("SELECT COUNT(*) AS num_results $rawQuery",$rawArgs);
if (!is_object($res)) {
return $res;
}
......@@ -373,6 +385,7 @@ function DBSelectSearch($query,$search,$filters,$sorts) {
# Select row count, pull out "SELECT .... " as we replace this in the NumResults query
$queryCount = $query; $queryCount = preg_replace("/^\s*SELECT\s.*\sFROM/is","FROM",$queryCount);
$numResults = DBSelectNumResults("$queryCount $sqlWhere");
if (!isset($numResults)) {
return array(NULL,"Backend database query 1 failed");
......@@ -457,4 +470,32 @@ function DBRollback()
$db = connect_db();
## @fn ReplacePrefix($query,$args)
# Return raw query and args based on table prefix
#
# @param query Query string
# @param args Array of arguments
#
# @return string rawQuery, array rawArgs
function ReplacePrefix($query, $args = array())
{
global $DB_TABLE_PREFIX;
# Fetch table prefix from config
$table_prefix = isset($DB_TABLE_PREFIX) ? $DB_TABLE_PREFIX : "";
# Replace query
$rawQuery = preg_replace('/\@TP\@/', $table_prefix, $query);
# Replace args
$rawArgs = array();
foreach ($args as $argItem) {
$rawArgItem = preg_replace('/\@TP\@/', $table_prefix, $argItem);
array_push($rawArgs, $rawArgItem);
}
return array($rawQuery, $rawArgs);
}
# vim: ts=4
<?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
# Utility functions
# Copyright (C) 2010-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
# 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.
## @fn isBoolean($param)
# Check if a variable is boolean
#
# @param var Variable to check
#
# @return 1, 0 or -1 on unknown
function isBoolean($param) {
# Check if we're set
if (!isset($param)) {
return -1;
}
# If it's already bool, just return it
if (is_bool($param)) {
return $param;
}
# If it's a string..
if (is_string($param)) {
# Nuke whitespaces
trim($param);
# Allow true, on, set, enabled, 1, false, off, unset, disabled, 0
if (preg_match('/^(?:true|on|set|enabled|1)$/i', $param)) {
return 1;
}
if (preg_match('/^(?:false|off|unset|disabled|0)$/i', $param)) {
return 0;
}
}
# Invalid or unknown
return -1;
}
# vim: ts=4
?>
<html>
<head>
<style type="text/css">
#loading {
position:absolute;
left:45%;
top:40%;
padding:2px;
z-index:20001;
height:auto;
}
#loading-msg {
font: normal 10px arial,tahoma,sans-serif;
}
</style>
</head>
<body>
<div id="loading">
<div class="loading-indicator">
Loading: <span id="loading-msg"></span>
</div>
<div>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Stylesheets...';</script>
<link rel="stylesheet" type="text/css" href="resources/extjs/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="icons.css" />
<link rel="stylesheet" type="text/css" href="resources/extjs/css/examples.css" />
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Core API...';</script>
<script type="text/javascript" src="js/extjs/ext-base.js"></script>
<script type="text/javascript" src="js/extjs/ext-all.js"></script>
<!--
Our own libraries
-->
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Libraries...';</script>
<script type="text/javascript" src="js/custom/util.js"></script>
<script type="text/javascript" src="js/custom/sprintf.js"></script>
<script type="text/javascript" src="js/custom/regexes.js"></script>
<script type="text/javascript" src="js/custom/vtypes.js"></script>
<script type="text/javascript" src="js/custom/menu/EditableItem.js"></script>
<script type="text/javascript" src="js/custom/menu/RangeMenu.js"></script>
<script type="text/javascript" src="js/custom/GridFilters.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/Filter.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/StringFilter.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/DateFilter.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/ListFilter.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/NumericFilter.js"></script>
<script type="text/javascript" src="js/custom/GridFilters/BooleanFilter.js"></script>
<script type="text/javascript" src="js/custom/ProgressFormPanel.js"></script>
<script type="text/javascript" src="js/custom/common.js"></script>
<script type="text/javascript" src="js/custom/generic.js"></script>
<!--
Main application
-->
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Configuration...';</script>
<script type="text/javascript" src="js/app/config.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Menus...';</script>
<script type="text/javascript" src="js/app/menus.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Windows...';</script>
<script type="text/javascript" src="js/app/windows/WiSPUsers.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPUserLogs.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocations.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocationMembers.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPResellers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUsers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserLogs.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealms.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealmAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupMembers.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Layout...';</script>
<script type="text/javascript" src="js/app/main-layout.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Starting...';</script>
<script type="text/javascript" src="js/app/main.js"></script>
</body>
</html>
<!-- Index.html - load all our code
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
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. -->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
#loading-mask{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
z-index:20000;
background-color:white;
}
#loading{
position:absolute;
left:45%;
top:40%;
padding:2px;
z-index:20001;
height:auto;
}
#loading a {
color:#225588;
}
#loading .loading-indicator{
background:white;
color:#444;
font:bold 13px tahoma,arial,helvetica;
padding:10px;
margin:0;
height:auto;
}
#loading-msg {
font: normal 10px arial,tahoma,sans-serif;
}
</style>
</head>
<body>
<div id="loading-mask" style=""></div>
<div id="loading">
<div class="loading-indicator">
<img src="awitef/resources/extjs/images/extanim32.gif" width="32" height="32" style="margin-right:8px;float:left;vertical-align:top;"/>
SMRadius WebGUI - <a href="http://smradius.org">smradius.org</a><br /><span id="loading-msg">Loading styles and images...</span>
</div>
</div>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading stylesheets...';</script>
<link rel="stylesheet" type="text/css" href="awitef/resources/extjs/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="awitef/resources/custom/css/silk-icons.css" />
<link rel="stylesheet" type="text/css" href="icons.css" />
<link rel="stylesheet" type="text/css" href="awitef/resources/extjs/css/examples.css" />
<link rel="stylesheet" type="text/css" href="awitef/js/custom/GridFilters/icons/style.css" />
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading core API...';</script>
<script type="text/javascript" src="awitef/js/extjs/ext-base.js"></script>
<script type="text/javascript" src="awitef/js/extjs/ext-all.js"></script>
<!--
Our own libraries
-->
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading libraries...';</script>
<script type="text/javascript" src="awitef/js/custom/util.js"></script>
<script type="text/javascript" src="awitef/js/custom/sprintf.js"></script>
<script type="text/javascript" src="awitef/js/custom/regexes.js"></script>
<script type="text/javascript" src="awitef/js/custom/vtypes.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/GridFilters.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/menu/EditableItem.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/menu/RangeMenu.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/Filter.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/StringFilter.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/DateFilter.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/ListFilter.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/NumericFilter.js"></script>
<script type="text/javascript" src="awitef/js/custom/GridFilters/filter/BooleanFilter.js"></script>
<script type="text/javascript" src="awitef/js/custom/ProgressFormPanel.js"></script>
<script type="text/javascript" src="awitef/js/custom/StatusBar.js"></script>
<script type="text/javascript" src="awitef/js/custom/common.js"></script>
<script type="text/javascript" src="awitef/js/custom/generic.js"></script>
<!--
Main application
-->
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading configuration...';</script>
<script type="text/javascript" src="js/app/config.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading menus...';</script>
<script type="text/javascript" src="js/app/menus.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading windows...';</script>
<script type="text/javascript" src="js/app/windows/WiSPUsers.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPUserLogs.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocations.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPLocationMembers.js"></script>
<script type="text/javascript" src="js/app/windows/WiSPResellers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUsers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserLogs.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminUserTopups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealms.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealmAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminRealmMembers.js"></script>
<script type="text/javascript" src="js/app/windows/AdminClients.js"></script>
<script type="text/javascript" src="js/app/windows/AdminClientAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminClientRealms.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroups.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupAttributes.js"></script>
<script type="text/javascript" src="js/app/windows/AdminGroupMembers.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Loading layout...';</script>
<script type="text/javascript" src="js/app/main-layout.js"></script>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Starting...';</script>
<script type="text/javascript" src="js/app/main.js"></script>
</body>
</html>
/*
Webgui Global Config
Copyright (C) 2007-2011, 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
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.
*/
var globalConfig = {
soap: {
username: 'admin',
......
/*
Webgui Main Layout
Copyright (C) 2007-2011, 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
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.
*/
// Main viewport
function initViewport() {
......@@ -40,11 +59,29 @@ function initViewport() {
// mainWindow
// ]
},
{
id: 'main-statusbar',
xtype: 'statusbar',
xtype: 'panel',
region: 'south',
border: true
border: true,
height: 30,
bbar: new Ext.ux.StatusBar({
id: 'my-status',
// defaults to use when the status is cleared:
defaultText: 'Default status text',
defaultIconCls: 'default-icon',
// values to set initially:
text: 'Ready',
iconCls: 'ready-icon'
// any standard Toolbar items:
// items: [{
// text: 'A Button'
// }, '-', 'Plain Text']
})
}
/*
{
......
/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
// Turn off the loading icon
document.getElementById('loading').style.visibility = 'hidden';
// this seems to save window states
// Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
// Enable tips
Ext.QuickTips.init();
// Turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';
// Range menu items, used on GridFilter
Ext.menu.RangeMenu.prototype.icons = {
gt: 'resources/extjs/images/greater_then.png',
lt: 'resources/extjs/images/less_then.png',
eq: 'resources/extjs/images/equals.png'
};
Ext.grid.filter.StringFilter.prototype.icon = 'resources/extjs/images/find.png';
// Fire everything up
initViewport();
});
/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
// Enable tips
Ext.QuickTips.init();
// Turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';
// Turn off the loading icon
var hideMask = function () {
Ext.get('loading').remove();
Ext.fly('loading-mask').fadeOut({
remove: true,
callback: function() {
// Fire everything up
initViewport();
}
});
}
hideMask.defer(250);
});
/*
Webgui Menus
Copyright (C) 2007-2011, 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
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.
*/
var radiusMenu = new Ext.menu.Menu({
items: [
{
text: 'Users',
iconCls: 'silk-user',
handler: function() {
showAdminUserWindow();
}
......@@ -10,6 +30,7 @@ var radiusMenu = new Ext.menu.Menu({
{
text: 'Groups',
iconCls: 'silk-group',
handler: function() {
showAdminGroupWindow();
}
......@@ -17,11 +38,20 @@ var radiusMenu = new Ext.menu.Menu({
{
text: 'Realms',
iconCls: 'silk-world',
handler: function() {
showAdminRealmWindow();
}
}
},
{
text: 'Clients',
iconCls: 'silk-server',
handler: function() {
showAdminClientWindow();
}
}
]
});
......@@ -31,20 +61,22 @@ var wispMenu = new Ext.menu.Menu({
{
text: 'Users',
iconCls: 'silk-user',
handler: function() {
showWiSPUserWindow();
}
},
{
text: 'Resellers',
handler: function() {
showWiSPResellersWindow();
}
},
// {
// text: 'Resellers',
// handler: function() {
// showWiSPResellersWindow();
// }
// },
{
text: 'Locations',
iconCls: 'silk-map',
handler: function() {
showWiSPLocationWindow();
}
......
/*
Admin Client Attributes
Copyright (C) 2007-2011, 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
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.
*/
function showAdminClientAttributesWindow(clientID) {
var AdminClientAttributesWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "Attributes",
iconCls: 'silk-table',
width: 600,
height: 335,
minWidth: 600,
minHeight: 335
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add attribute',
iconCls:'silk-table_add',
handler: function() {
showAdminClientAttributeAddEditWindow(AdminClientAttributesWindow,clientID);
}
},
'-',
{
text:'Edit',
tooltip:'Edit attribute',
iconCls:'silk-table_edit',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientAttributesWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientAttributeAddEditWindow(AdminClientAttributesWindow,clientID,selectedItem.data.ID);
} else {
AdminClientAttributesWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No attribute selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientAttributesWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Remove',
tooltip:'Remove attribute',
iconCls:'silk-table_delete',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientAttributesWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientAttributeRemoveWindow(AdminClientAttributesWindow,selectedItem.data.ID);
} else {
AdminClientAttributesWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No attribute selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientAttributesWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
dataIndex: 'ID'
},
{
header: "Name",
sortable: true,
dataIndex: 'Name'
},
{
header: "Operator",
sortable: true,
dataIndex: 'Operator'
},
{
header: "Value",
sortable: true,
dataIndex: 'Value'
},
{
header: "Disabled",
sortable: true,
dataIndex: 'Disabled'
}
]),
autoExpandColumn: 'Name'
},
// Store config
{
baseParams: {
ID: clientID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientAttributes',
SOAPFunction: 'getAdminClientAttributes',
SOAPParams: 'ID,__search'
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'string', dataIndex: 'Name'},
{type: 'string', dataIndex: 'Operator'},
{type: 'string', dataIndex: 'Value'},
{type: 'boolean', dataIndex: 'Disabled'}
]
}
);
AdminClientAttributesWindow.show();
}
// Display edit/add form
function showAdminClientAttributeAddEditWindow(AdminClientAttributesWindow,clientID,attrID) {
var submitAjaxConfig;
var icon;
// We doing an update
if (attrID) {
icon = 'silk-table_edit';
submitAjaxConfig = {
params: {
ID: attrID,
SOAPFunction: 'updateAdminClientAttribute',
SOAPParams:
'0:ID,'+
'0:Name,'+
'0:Operator,'+
'0:Value,'+
'0:Disabled:boolean'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientAttributesWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
// We doing an Add
} else {
icon = 'silk-table_add';
submitAjaxConfig = {
params: {
ClientID: clientID,
SOAPFunction: 'addAdminClientAttribute',
SOAPParams:
'0:ClientID,'+
'0:Name,'+
'0:Operator,'+
'0:Value,'+
'0:Disabled:boolean'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientAttributesWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
}
// Create window
var adminClientAttributesFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "Attribute Information",
iconCls: icon,
width: 310,
height: 200,
minWidth: 310,
minHeight: 200
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientAttributes'
},
items: [
{
fieldLabel: 'Name',
name: 'Name',
allowBlank: false
},
{
xtype: 'combo',
fieldLabel: 'Operator',
name: 'Operator',
allowBlank: false,
width: 157,
store: [
[ '=', '=' ],
[ ':=', ':=' ],
[ '==', '==' ],
[ '+=', '+=' ],
[ '!=', '!=' ],
[ '<', '<' ],
[ '>', '>' ],
[ '<=', '<=' ],
[ '>=', '>=' ],
[ '=~', '=~' ],
[ '!~', '!~' ],
[ '=*', '=*' ],
[ '!*', '!*' ],
[ '||==', '||==' ]
],
displayField: 'Operator',
valueField: 'Operator',
hiddenName: 'Operator',
forceSelection: false,
triggerAction: 'all',
editable: true
},
{
fieldLabel: "Value",
name: "Value",
allowBlank: false
},
{
xtype: 'checkbox',
fieldLabel: 'Disabled',
name: 'Disabled'
}
]
},
// Submit button config
submitAjaxConfig
);
adminClientAttributesFormWindow.show();
if (attrID) {
Ext.getCmp(adminClientAttributesFormWindow.formPanelID).load({
params: {
ID: attrID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientAttributes',
SOAPFunction: 'getAdminClientAttribute',
SOAPParams: 'ID'
}
});
}
}
// Display remove form
function showAdminClientAttributeRemoveWindow(AdminClientAttributesWindow,id) {
// Mask AdminClientAttributesWindow window
AdminClientAttributesWindow.getEl().mask();
// Display remove confirm window
Ext.Msg.show({
title: "Confirm removal",
msg: "Are you very sure you wish to remove this attribute?",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.YESNO,
modal: false,
fn: function(buttonId,text) {
// Check if user clicked on 'yes' button
if (buttonId == 'yes') {
// Do ajax request
uxAjaxRequest(AdminClientAttributesWindow,{
params: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientAttributes',
SOAPFunction: 'removeAdminClientAttribute',
SOAPParams: 'ID'
},
customSuccess: function() {
var store = Ext.getCmp(AdminClientAttributesWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
});
// Unmask if user answered no
} else {
AdminClientAttributesWindow.getEl().unmask();
}
}
});
}
// vim: ts=4
/*
Admin Client Realms
Copyright (C) 2007-2011, 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
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.
*/
function showAdminClientRealmsWindow(clientID) {
var AdminClientRealmsWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "Realms",
iconCls: 'silk-world',
width: 400,
height: 335,
minWidth: 400,
minHeight: 335
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add realm',
iconCls: 'silk-world_add',
handler: function() {
showAdminClientRealmAddWindow(AdminClientRealmsWindow,clientID);
}
},
'-',
{
text:'Remove',
tooltip:'Remove realm',
iconCls: 'silk-world_delete',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientRealmsWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientRealmRemoveWindow(AdminClientRealmsWindow,selectedItem.data.ID);
} else {
AdminClientRealmsWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No realm selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientRealmsWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
dataIndex: 'ID'
},
{
header: "Name",
sortable: true,
dataIndex: 'Name'
}
]),
autoExpandColumn: 'Name'
},
// Store config
{
baseParams: {
ID: clientID,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientRealms',
SOAPFunction: 'getAdminClientRealms',
SOAPParams: 'ID,__search'
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'string', dataIndex: 'Name'}
]
}
);
AdminClientRealmsWindow.show();
}
// Display edit/add form
function showAdminClientRealmAddWindow(AdminClientRealmsWindow,clientID,id) {
var submitAjaxConfig;
var icon;
// We doing an update
if (id) {
icon = 'silk-world_edit',
submitAjaxConfig = {
params: {
ID: id,
SOAPFunction: 'updateAdminRealm',
SOAPParams:
'0:ID,'+
'0:RealmID'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientRealmsWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
// We doing an Add
} else {
icon = 'silk-world_add',
submitAjaxConfig = {
params: {
ClientID: clientID,
SOAPFunction: 'addAdminClientRealm',
SOAPParams:
'0:ClientID,'+
'0:RealmID'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientRealmsWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
}
// Create window
var adminRealmFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "Realm Information",
iconCls: icon,
width: 310,
height: 113,
minWidth: 310,
minHeight: 113
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminRealms'
},
items: [
{
xtype: 'combo',
//id: 'combo',
fieldLabel: 'Realm',
name: 'Realm',
allowBlank: false,
width: 160,
store: new Ext.ux.JsonStore({
sortInfo: { field: "Name", direction: "ASC" },
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientRealms',
SOAPFunction: 'getAdminRealms',
SOAPParams: '__null,__search'
}
}),
displayField: 'Name',
valueField: 'ID',
hiddenName: 'RealmID',
forceSelection: true,
triggerAction: 'all',
editable: false
}
]
},
// Submit button config
submitAjaxConfig
);
adminRealmFormWindow.show();
if (id) {
Ext.getCmp(adminRealmFormWindow.formPanelID).load({
params: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminRealms',
SOAPFunction: 'getAdminRealm',
SOAPParams: 'ID'
}
});
}
}
// Display remove form
function showAdminClientRealmRemoveWindow(AdminClientRealmsWindow,id) {
// Mask AdminClientRealmsWindow window
AdminClientRealmsWindow.getEl().mask();
// Display remove confirm window
Ext.Msg.show({
title: "Confirm removal",
msg: "Are you very sure you wish to unlink this realm?",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.YESNO,
modal: false,
fn: function(buttonId,text) {
// Check if user clicked on 'yes' button
if (buttonId == 'yes') {
// Do ajax request
uxAjaxRequest(AdminClientRealmsWindow,{
params: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClientRealms',
SOAPFunction: 'removeAdminClientRealm',
SOAPParams: 'ID'
},
customSuccess: function() {
var store = Ext.getCmp(AdminClientRealmsWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
});
// Unmask if user answered no
} else {
AdminClientRealmsWindow.getEl().unmask();
}
}
});
}
// vim: ts=4
/*
Admin Clients
Copyright (C) 2007-2011, 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
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.
*/
function showAdminClientWindow() {
var AdminClientWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: "Clients",
width: 600,
height: 335,
minWidth: 600,
minHeight: 335
},
// Grid config
{
// Inline toolbars
tbar: [
{
text:'Add',
tooltip:'Add client',
iconCls:'silk-server_add',
handler: function() {
showAdminClientAddEditWindow(AdminClientWindow);
}
},
'-',
{
text:'Edit',
tooltip:'Edit client',
iconCls:'silk-server_edit',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientAddEditWindow(AdminClientWindow,selectedItem.data.ID);
} else {
AdminClientWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No client selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientWindow.getEl().unmask();
}
});
}
}
},
{
text:'Remove',
tooltip:'Remove client',
iconCls:'silk-server_delete',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientRemoveWindow(AdminClientWindow,selectedItem.data.ID);
} else {
AdminClientWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No client selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Attributes',
tooltip:'Client attributes',
iconCls:'silk-table',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientAttributesWindow(selectedItem.data.ID);
} else {
AdminClientWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No client selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientWindow.getEl().unmask();
}
});
}
}
},
'-',
{
text:'Realms',
tooltip:'Realms',
iconCls:'silk-world',
handler: function() {
var selectedItem = Ext.getCmp(AdminClientWindow.gridPanelID).getSelectionModel().getSelected();
// Check if we have selected item
if (selectedItem) {
// If so display window
showAdminClientRealmsWindow(selectedItem.data.ID);
} else {
AdminClientWindow.getEl().mask();
// Display error
Ext.Msg.show({
title: "Nothing selected",
msg: "No client selected",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.CANCEL,
modal: false,
fn: function() {
AdminClientWindow.getEl().unmask();
}
});
}
}
}
],
// Column model
colModel: new Ext.grid.ColumnModel([
{
id: 'ID',
header: "ID",
sortable: true,
dataIndex: 'ID'
},
{
header: "Name",
sortable: true,
dataIndex: 'Name'
},
{
header: "AccessList",
sortable: true,
dataIndex: 'AccessList'
}
]),
autoExpandColumn: 'Name'
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClients',
SOAPFunction: 'getAdminClients',
SOAPParams: '__null,__search'
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{type: 'string', dataIndex: 'Name'},
{type: 'string', dataIndex: 'AccessList'}
]
}
);
AdminClientWindow.show();
}
// Display edit/add form
function showAdminClientAddEditWindow(AdminClientWindow,id) {
var submitAjaxConfig;
var icon;
// We doing an update
if (id) {
icon = 'silk-server_edit';
submitAjaxConfig = {
params: {
ID: id,
SOAPFunction: 'updateAdminClient',
SOAPParams:
'0:ID,'+
'0:Name,'+
'0:AccessList'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
// We doing an Add
} else {
icon = 'silk-server_add';
submitAjaxConfig = {
params: {
SOAPFunction: 'createAdminClient',
SOAPParams:
'0:Name,'+
'0:AccessList'
},
onSuccess: function() {
var store = Ext.getCmp(AdminClientWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
};
}
// Create window
var adminClientFormWindow = new Ext.ux.GenericFormWindow(
// Window config
{
title: "Client Information",
iconCls: icon,
width: 310,
height: 143,
minWidth: 310,
minHeight: 143
},
// Form panel config
{
labelWidth: 85,
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClients'
},
items: [
{
fieldLabel: 'Name',
name: 'Name',
allowBlank: false
},
{
fieldLabel: 'AccessList',
name: 'AccessList',
allowBlank: true
}
]
},
// Submit button config
submitAjaxConfig
);
adminClientFormWindow.show();
if (id) {
Ext.getCmp(adminClientFormWindow.formPanelID).load({
params: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClients',
SOAPFunction: 'getAdminClient',
SOAPParams: 'ID'
}
});
}
}
// Display remove form
function showAdminClientRemoveWindow(AdminClientWindow,id) {
// Mask AdminClientWindow window
AdminClientWindow.getEl().mask();
// Display remove confirm window
Ext.Msg.show({
title: "Confirm removal",
msg: "Are you very sure you wish to remove this client?",
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.YESNO,
modal: false,
fn: function(buttonId,text) {
// Check if user clicked on 'yes' button
if (buttonId == 'yes') {
// Do ajax request
uxAjaxRequest(AdminClientWindow,{
params: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminClients',
SOAPFunction: 'removeAdminClient',
SOAPParams: 'ID'
},
customSuccess: function() {
var store = Ext.getCmp(AdminClientWindow.gridPanelID).getStore();
store.load({
params: {
limit: 25
}
});
}
});
// Unmask if user answered no
} else {
AdminClientWindow.getEl().unmask();
}
}
});
}
// vim: ts=4