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 1776 additions and 915 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");
# Add new topup
function createAdminUserTopup($params) {
global $db;
# Get today's date
$timestamp = date('Y-m-d H:i:s');
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
# Perform query
$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'])
);
if (!is_numeric($res)) {
# Return result
if ($res !== TRUE) {
return $res;
}
......@@ -22,9 +41,9 @@ function createAdminUserTopup($params) {
# Edit topup
function updateAdminUserTopup($params) {
global $db;
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
# Perform query
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -32,7 +51,8 @@ function updateAdminUserTopup($params) {
$params[0]['ID'])
);
if (!is_numeric($res)) {
# Return result
if ($res !== TRUE) {
return $res;
}
......@@ -41,64 +61,75 @@ function updateAdminUserTopup($params) {
# Delete user topup
function removeAdminUserTopup($params) {
global $db;
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
if (!is_numeric($res)) {
# 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 ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return specific topup row
function getAdminUserTopup($params) {
global $db;
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
# Perform query
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Type'] = $row->type;
$resultArray['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$resultArray['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$resultArray['ValidTo'] = $value;
# Return results
return $resultArray;
}
# Return list of topups
function getAdminUserTopups($params) {
global $db;
# 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
$res = DBSelectSearch("
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......@@ -107,38 +138,38 @@ function getAdminUserTopups($params) {
Timestamp
DESC
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Array for this row
$item = array();
$item['ID'] = $row->id;
$item['Timestamp'] = $row->timestamp;
$item['Type'] = $row->type;
$item['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$item['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$item['ValidTo'] = $value;
# push this row onto array
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
......
<?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");
# Return list of users
function getAdminUsers($params) {
global $db;
# 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',
);
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM users",$params[1],$filtersorts,$filtersorts);
# Perform query
$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
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Array for this row
$item = array();
$item['ID'] = $row->id;
$item['Username'] = $row->username;
$item['Disabled'] = $row->disabled;
# push this row onto array
# Push this row onto main array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific group row
# Return specific user
function getAdminUser($params) {
global $db;
# Perform query
$res = DBSelect("SELECT ID, Username, Disabled FROM @TP@users WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Username, Disabled FROM users WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Username'] = $row->username;
$resultArray['Disabled'] = $row->disabled;
$res = DBSelect("SELECT Value FROM user_attributes WHERE Name = ? AND UserID = ?",
array('User-Password',$params[0])
);
if (!is_object($res)) {
return $res;
}
$row = $res->fetchObject();
$resultArray['Password'] = $row->value;
# Return results
return $resultArray;
}
# Remove admin group
# Remove admin user
function removeAdminUser($params) {
global $db;
# Begin transaction
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;
}
# Add admin group
# Add admin user
function createAdminUser($params) {
global $db;
DBBegin();
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
if ($res !== FALSE) {
$lastInsertID = DBLastInsertID();
if (isset($lastInsertID)) {
$res = DBDo("INSERT INTO user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)",
array($lastInsertID,'User-Password','==',$params[0]['Password'])
);
} else {
$res = 0;
}
}
# Perform query
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($params[0]['Username'],$params[0]['Disabled']));
# Commit and return if successful
if ($res !== FALSE) {
DBCommit();
# Return result
if ($res !== TRUE) {
return $res;
# Else rollback database
} else {
DBRollback();
}
return NULL;
}
# Edit admin group
# Edit admin user
function updateAdminUser($params) {
global $db;
DBBegin();
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
if ($res !== FALSE) {
$res = DBDo("UPDATE user_attributes SET Value = ? WHERE Name = ? AND UserID = ?",
array($params[0]['Password'],'User-Password',$params[0]['ID'])
);
}
# Perform query
$res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
# Commit and return if successful
if ($res !== FALSE) {
DBCommit();
# Return result
if ($res !== TRUE) {
return $res;
# Else rollback database
} else {
DBRollback();
}
return NULL;
......
<?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");
# Remove group attribute
# Remove location member
function removeWiSPLocationMember($params) {
global $db;
$res = DBDo("UPDATE wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
if (!is_numeric($res)) {
# Perform query
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return list of attributes
# Return list of location members
function getWiSPLocationMembers($params) {
global $db;
# 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];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Build array for this row
$item = array();
$item['ID'] = $row->id;
$item['Username'] = $row->username;
# push this row onto array
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
......
<?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");
# Return list of locations
function getWiSPLocations($params) {
global $db;
# 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'
);
$res = DBSelectSearch("SELECT ID, Name FROM wisp_locations",$params[1],$filtersorts,$filtersorts);
# Perform query
$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
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Build array for this row
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
# push this row onto array
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific location row
function getWiSPLocation($params) {
global $db;
# Perform query
$res = DBSelect("SELECT ID, Name FROM @TP@wisp_locations WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name FROM wisp_locations WHERE ID = ?",array($params[0]));
# Return if error or nothing to return
if (!is_object($res)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Name'] = $row->name;
# Return results
return $resultArray;
}
# Remove admin group
# Remove wisp location
function removeWiSPLocation($params) {
global $db;
# Begin transaction
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;
}
# Add admin group
# Add wisp location
function createWiSPLocation($params) {
global $db;
$res = DBDo("INSERT INTO wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
if (!is_numeric($res)) {
# Perform query
$res = DBDo("INSERT INTO @TP@wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Edit admin group
# Edit wisp location
function updateWiSPLocation($params) {
global $db;
$res = DBDo("UPDATE wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
if (!is_numeric($res)) {
# Perform query
$res = DBDo("UPDATE @TP@wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# Return result
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");
# Return list of users
# Return user logs summary
function getWiSPUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect("
SELECT
@TP@group_attributes.Name,
@TP@group_attributes.Value
FROM
@TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE
@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'])
);
# 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
$trafficCap = -1;
$uptimeCap = -1;
while ($row = $res->fetchObject()) {
if ($row->name == 'SMRadius-Capping-Traffic-Limit') {
$trafficCap = (int)$row->value;
}
if ($row->name == 'SMRadius-Capping-Uptime-Limit') {
$uptimeCap = (int)$row->value;
}
}
# 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
$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
@TP@topups_summary.Balance,
@TP@topups.ID,
@TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM
@TP@topups_summary,
@TP@topups
WHERE
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?
AND @TP@topups_summary.PeriodKey = ?
AND @TP@topups_summary.Depleted = 0
ORDER BY
@TP@topups.Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Store summary topups
$topups = array();
$i = 0;
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$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
ID, Value, Type, ValidTo
FROM
@TP@topups
WHERE
UserID = ?
AND ValidFrom = ?
AND ValidTo >= ?
AND Depleted = 0
ORDER BY
Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Store normal topups
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$i++;
}
$res = DBSelect("
SELECT
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
@TP@accounting, @TP@users
WHERE
@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)) {
return $res;
}
# Set total traffic and uptime used
$row = $res->fetchObject();
# 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;
}
# Excess usage
$excessTraffic = 0;
if ($trafficCap == -1) {
$excessTraffic = $resultArray['trafficUsage'];
} else {
$excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
}
$excessUptime = 0;
if ($uptimeCap == -1) {
$excessUptime = $resultArray['uptimeUsage'];
} else {
$excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
}
# 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'];
}
}
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'];
}
}
}
# Return results
return array($resultArray, 1);
}
# Return list of user logs
function getWiSPUserLogs($params) {
global $db;
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'accounting.ID',
'EventTimestamp' => 'accounting.EventTimestamp',
'AcctStatusType' => 'accounting.AcctStatusType',
'ServiceType' => 'accounting.ServiceType',
'FramedProtocol' => 'accounting.FramedProtocol',
'NASPortType' => 'accounting.NASPortType',
'NASPortID' => 'accounting.NASPortID',
'CallingStationID' => 'accounting.CallingStationID',
'CalledStationID' => 'accounting.CalledStationID',
'AcctSessionID' => 'accounting.AcctSessionID',
'FramedIPAddress' => 'accounting.FramedIPAddress',
'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
FROM
accounting, users
WHERE
users.Username = accounting.Username
SELECT
@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
@TP@accounting, @TP@users
WHERE
@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];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
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;
$acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
$acctOutput += $row->acctoutput;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
# Uptime
$acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += $row->acctsessiontime;
}
# Build array for this row
$item = array();
$item['ID'] = $row->id;
# Convert to ISO format
# Convert to ISO format
$date = new DateTime($row->eventtimestamp);
$value = $date->format("Y-m-d H:i:s");
$item['EventTimestamp'] = $value;
$item['AcctStatusType'] = $row->acctstatustype;
$item['ServiceType'] = $row->servicetype;
$item['FramedProtocol'] = $row->framedprotocol;
......@@ -98,14 +453,16 @@ function getWiSPUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte;
$item['AcctOutputMbyte'] = $acctOutputMbyte;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype);
$item['AcctInput'] = $acctInput;
$item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# push this row onto array
# Push this row onto main array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
......
<?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");
# Add new topup
function createWiSPUserTopup($params) {
global $db;
# Current datetime
$timestamp = date('Y-m-d H:i:s');
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
# Perform query
$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'])
);
if (!is_numeric($res)) {
# Return result
if ($res !== TRUE) {
return $res;
}
......@@ -22,9 +41,9 @@ function createWiSPUserTopup($params) {
# Edit topup
function updateWiSPUserTopup($params) {
global $db;
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
# Perform query
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -32,7 +51,8 @@ function updateWiSPUserTopup($params) {
$params[0]['ID'])
);
if (!is_numeric($res)) {
# Return result
if ($res !== TRUE) {
return $res;
}
......@@ -41,64 +61,67 @@ function updateWiSPUserTopup($params) {
# Delete user topup
function removeWiSPUserTopup($params) {
global $db;
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
if (!is_numeric($res)) {
# Perform query
$res = DBDo("DELETE FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return specific topup row
function getWiSPUserTopup($params) {
global $db;
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
# Perform query
$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)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Type'] = $row->type;
$resultArray['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$resultArray['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$resultArray['ValidTo'] = $value;
# Return results
return $resultArray;
}
# Return list of topups
function getWiSPUserTopups($params) {
global $db;
# 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
$res = DBSelectSearch("
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......@@ -107,38 +130,38 @@ function getWiSPUserTopups($params) {
Timestamp
DESC
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Array for this row
$item = array();
$item['ID'] = $row->id;
$item['Timestamp'] = $row->timestamp;
$item['Type'] = $row->type;
$item['Value'] = $row->value;
# Convert to ISO format
$date = new DateTime($row->validfrom);
$value = $date->format("Y-m-d");
$item['ValidFrom'] = $value;
# Convert to ISO format
$date = new DateTime($row->validto);
$value = $date->format("Y-m-d");
$item['ValidTo'] = $value;
# push this row onto array
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
......
<?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");
# Return list of wisp users
function getWiSPUsers($params) {
global $db;
# 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];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
# loop through rows
while ($row = $sth->fetchObject()) {
# Array for this row
$item = array();
$item['ID'] = $row->userid;
......@@ -54,137 +71,255 @@ function getWiSPUsers($params) {
$item['Email'] = $row->email;
$item['Phone'] = $row->phone;
# push this row onto array
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific wisp user row
function getWiSPUser($params) {
global $db;
# Query for userdata and username
$res = DBSelect("
SELECT
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Phone,
wisp_userdata.Email,
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
if (!is_object($res)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
# 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['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
if (!is_object($res)) {
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
if (!is_object($res)) {
return $res;
}
# Set attributes
$i = 0;
# Array for multiple attributes
$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++;
}
$numResults = $res->rowCount();
return array($resultArray,$numResults);
# Set number of results
$numResults = count($attributes);
# Return results
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
function removeWiSPUser($params) {
global $db;
# Begin transaction
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;
......@@ -192,21 +327,24 @@ function removeWiSPUser($params) {
# Add wisp user
function createWiSPUser($params) {
global $db;
# We need this to send notification
global $adminEmails;
# Begin transaction
DBBegin();
$res = "Username & Password required for single user. For adding multiple users an integer is required.";
# Perform first query
$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,
......@@ -218,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'] * 1024;
case "TBytes":
$attrValue = $attr['Value'] * 1048576;
# 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
......@@ -299,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));
}
}
......@@ -329,16 +483,16 @@ 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)
);
# If there are no rows we may continue
if ($res->rowCount() == 0 && !defined($wispUser[$thisUsername])) {
if ($res->rowCount() == 0 && !isset($wispUser[$thisUsername])) {
$usernameReserved = 0;
# Generate random username
......@@ -355,29 +509,153 @@ 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 && 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;
}
}
}
# 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 && 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) {
$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)
);
}
}
}
# Email userlist to admin
if ($res !== FALSE && isset($adminEmails)) {
// multiple recipients
$to = $adminEmails;
// subject
$subject = count($wispUser).' WiSP users added';
// html
$html = '';
foreach ($wispUser as $key => $val) {
$html .= '<tr><td>'.$key.'</td><td>'.$val.'</td></tr>';
}
// message
$message = '
<html>
<head>
<title>User List</title>
</head>
<body>
<table cellspacing="10">
<tr>
<th>Username</th><th>Password</th>
</tr>'.$html.'
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: SMRadius';
// Mail it
$res = mail($to, $subject, $message, $headers);
}
}
# Commit changes if all was successful, else rollback
if ($res !== FALSE) {
DBCommit();
if ($res !== TRUE) {
DBRollback();
return $res;
} else {
DBRollback();
DBCommit();
}
return NULL;
......@@ -385,38 +663,196 @@ function createWiSPUser($params) {
# Edit wisp user
function updateWiSPUser($params) {
global $db;
DBBegin();
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
$res = TRUE;
# Perform query
$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) {
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) {
DBDo("
UPDATE
wisp_userdata
SET
FirstName = ?,
LastName = ?,
Phone = ?,
Email = ?
WHERE
UserID = ?",
array($params[0]['Firstname'],
$params[0]['Lastname'],
$params[0]['Phone'],
$params[0]['Email'],
$params[0]['ID'])
$res = DBDo("
UPDATE
@TP@wisp_userdata
SET
FirstName = ?,
LastName = ?,
Phone = ?,
Email = ?
WHERE
UserID = ?",
array($params[0]['Firstname'],
$params[0]['Lastname'],
$params[0]['Phone'],
$params[0]['Email'],
$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
......@@ -32,6 +32,12 @@ $DB_PASS="root";
$DB_TABLE_PREFIX="";
# Email address/addresses to receive notifications
# Seperated by commas, eg. "admin@example.org,admin@example.net"
# $adminEmails="admin@example.org";
#
# THE BELOW SECTION IS UNSUPPORTED AND MEANT FOR THE ORIGINAL SPONSOR OF V2
#
......
<?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/app/util.js"></script>
<script type="text/javascript" src="js/app/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/app/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',
......
// FIXME
function storeLoadException(requestConfig, storeObj, xmlEr, except) {
printStr = 'An exception occured while trying to load data.<br /><br /><br />';
printStr += '<b>Exception:</b> '+except.toString()+'<br />';
// add http status description
printStr += '<b>Service:</b> '+storeObj.url+'<br />';
printStr += '<b>Status:</b> '+xmlEr.status+' - '+xmlEr.statusText+'<br />';
if (xmlEr.response && xmlEr.response.errors) {
// If this is a return object with errors, display them...
printStr += '<b>Response:</b>';
for (var i = 0; i < xmlEr.response.errors.length; i++) {
printStr += xmlEr.response.errors[i] + '<br />';
}
} else {
// add response text
printStr += '<b>Response:</b><br />'+xmlEr.responseText;
}
Ext.Msg.show({
title: "Exception occured: ",
msg: printStr,
icon: Ext.MessageBox.ERROR
});
}
// Generic jason store
Ext.ux.JsonStore = function(config) {
config = Ext.apply({
url: 'ajax.php',
remoteSort: true
}, config);
var store = new Ext.data.JsonStore(config);
Ext.data.JsonStore.superclass.constructor.call(this, config);
}
Ext.extend(Ext.ux.JsonStore, Ext.data.JsonStore, {
});
// Create a generic window and specify the window, form and submission ajax configuration
Ext.ux.GenericFormWindow = function(windowConfig,formConfig,submitAjaxConfig) {
// Form configuration
formConfig = Ext.apply({
xtype: 'progressformpanel',
id: 'formpanel',
// AJAX connector
url: 'ajax.php',
// Space stuff a bit so it looks better
bodyStyle: 'padding: 5px',
// Default form item is text field
defaultType: 'textfield',
// Button uses formBind = true, this is undocumented
// we may need to define an event to call 'clientvalidation'
monitorValid: true,
// Buttons for the form
buttons: [
{
text: 'Save',
formBind: true,
handler: function() {
var panel = this.ownerCt;
var win = panel.ownerCt;
var ajaxParams;
if (submitAjaxConfig.params) {
ajaxParams = submitAjaxConfig.params;
if (submitAjaxConfig.hook) {
var extraParams = submitAjaxConfig.hook();
}
ajaxParams = Ext.apply(ajaxParams,extraParams);
} else {
ajaxParams = submitAjaxConfig;
}
// Submit panel
panel.submit({
params: ajaxParams,
// Close window on success
success: function() {
win.close();
}
});
}
},{
text: 'Cancel',
handler: function() {
var panel = this.ownerCt;
var win = panel.ownerCt;
win.close();
}
}
]
}, formConfig);
// Add any extra buttons we may have
if (formConfig.extrabuttons) {
// Loop and add
for (i = 0; i < formConfig.extrabuttons.length; i += 1) {
formConfig.buttons.push(formConfig.extrabuttons[i]);
}
}
// Apply our own window configuration
windowConfig = Ext.apply({
layout: 'fit',
items: [
new Ext.ux.ProgressFormPanel(formConfig)
]
}, windowConfig);
Ext.Window.superclass.constructor.call(this, windowConfig);
}
Ext.extend(Ext.ux.GenericFormWindow, Ext.Window, {
// Override functions here
});
// Generic grid window
Ext.ux.GenericGridWindow = function(windowConfig,gridConfig,storeConfig,filtersConfig) {
// Setup data store
storeConfig = Ext.apply({
autoLoad: false,
}, storeConfig);
var store = new Ext.ux.JsonStore(storeConfig);
store.on('loadexception', storeLoadException);
// Setup filters for the grid
var filters = new Ext.grid.GridFilters(filtersConfig);
// Grid configuration
gridConfig = Ext.apply({
xtype: 'gridpanel',
id: 'gridpanel',
plain: true,
height: 300,
// Link store
store: store,
// Plugins
plugins: filters,
// View configuration
viewConfig: {
forceFit: true
},
// Set row selection model
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
// Inline buttons
buttons: [
{
text:'Close',
handler: function() {
var grid = this.ownerCt;
var win = grid.ownerCt;
win.close();
}
}
],
buttonAlign:'center',
// Bottom bar
bbar: new Ext.PagingToolbar({
pageSize: 25,
store: store,
displayInfo: true,
displayMsg: 'Displaying items {0} - {1} of {2}',
emptyMsg: "No data to display",
plugins: filters
})
}, gridConfig);
// Apply our own window configuration
windowConfig = Ext.apply({
items: [
new Ext.grid.GridPanel(gridConfig)
]
}, windowConfig);
// If we have additional items, push them onto the item list
if (windowConfig.uxItems) {
for (i = 0; i < windowConfig.uxItems.length; i += 1) {
windowConfig.items.push(windowConfig.uxItems[i]);
}
}
Ext.Window.superclass.constructor.call(this, windowConfig);
}
Ext.extend(Ext.ux.GenericGridWindow, Ext.Window, {
// Override functions here
show: function() {
Ext.ux.GenericGridWindow.superclass.show.call(this,arguments);
// Load initial records
this.getComponent('gridpanel').store.load({
params: {
start: 0,
limit: 25
}
});
}
});
// Generic ajax request
uxAjaxRequest = function(parent,config) {
config = Ext.apply({
url: 'ajax.php',
success: function(response,options) {
if (parent) {
parent.getEl().unmask();
}
},
// Failure function
failure: function(response,options) {
Ext.Msg.show({
title: "Exception occured:",
msg: response.responseText,
icon: Ext.MessageBox.ERROR,
fn: function() {
if (parent) {
parent.getEl().unmask();
}
}
});
}
}, config);
Ext.Ajax.request(config);
}
/*
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();
}
......
/**
* sprintf() for JavaScript v.0.4
*
* Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
* Thanks to David Baird (unit test and patch).
*
* 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., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }
function sprintf () {
var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
while (f) {
if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
else if (m = /^\x25{2}/.exec(f)) o.push('%');
else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
throw("Expecting number but found " + typeof(a));
switch (m[7]) {
case 'b': a = a.toString(2); break;
case 'c': a = String.fromCharCode(a); break;
case 'd': a = parseInt(a); break;
case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
case 'o': a = a.toString(8); break;
case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
case 'u': a = Math.abs(a); break;
case 'x': a = a.toString(16); break;
case 'X': a = a.toString(16).toUpperCase(); break;
}
a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
x = m[5] - String(a).length;
p = m[5] ? str_repeat(c, x) : '';
o.push(m[4] ? a + p : p + a);
}
else throw ("Huh ?!");
f = f.substring(m[0].length);
}
return o.join('');
}
/* Generate a random password */
function getRandomPass(len) {
var keylist="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"
var ret=''
for (i = 0; i < len; i++)
ret += keylist.charAt( Math.floor(Math.random() * keylist.length) )
return ret
}