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 3712 additions and 619 deletions
......@@ -8,7 +8,11 @@
#group=
# Filename to store pid of parent process
#pid_file=/var/run/smradiusd.pid
#pid_file=/var/run/smradius/smradiusd.pid
# Cache file
#cache_file=/var/run/smradius/cache
# Uncommenting the below option will prevent awradiusd going into the background
#background=no
......@@ -16,8 +20,8 @@
# Preforking configuration
#
# min_server - Minimum servers to keep around
# min_spare_servers - Minimum spare servers to keep around ready to
# handle requests
# min_spare_servers - Minimum spare servers to keep around ready to
# handle requests
# max_spare_servers - Maximum spare servers to have around doing nothing
# max_servers - Maximum servers alltogether
# max_requests - Maximum number of requests each child will serve
......@@ -40,14 +44,14 @@
# 1 - Warnings and errors
# 2 - Notices, warnings, errors
# 3 - Info, notices, warnings, errors
# 4 - Debugging
# 4 - Debugging
#log_level=2
# File to log to instead of stdout
#log_file=/var/log/smradiusd.log
# Things to log in extreme detail
# modules - Log detailed module running information
# modules - Log detailed module running information
#
# There is no default for this configuration option. Options can be
# separated by commas. ie. modules
......@@ -61,18 +65,56 @@
#timeout=120
# cidr_allow/cidr_deny
# Comma, whitespace or semi-colon separated. Contains a CIDR block to
# compare the clients IP to. If cidr_allow or cidr_deny options are
# given, the incoming client must match a cidr_allow and not match a
# Comma, whitespace or semi-colon separated. Contains a CIDR block to
# compare the clients IP to. If cidr_allow or cidr_deny options are
# given, the incoming client must match a cidr_allow and not match a
# cidr_deny or the client connection will be closed.
#cidr_allow=0.0.0.0/0
#cidr_deny=
# Event timestamp timezone, in "Continent/City" format
# Defaults to "GMT"
event_timezone=GMT
# SMTP server to use when sending email
#smtp_server=127.0.0.1
[radius]
# Use packet timestamp, if unset, the default is to use the server
# timestamp at the moment the packet is received.
#
# WARNING!!!!
# Not all routers keep time, it may occur that some routers depend on
# getting date & time apon reboot from an ntp server. The problem
# will arise when the router cannot get the date and time before the
# first user logs in .. BAM, you'll have sessions with a period key
# in current month but an event timestamp in 1970.
#
# Defaults to "no"
#use_packet_timestamp=yes
# Radius server abuse prevention
#
# Abuse prevention will drop packets which flood the radius server,
# or are duplicated in a short timeframe. You probably want this if
# you are not being fed by a radius proxy.
#
# Defaults to "no"
#use_abuse_prevention=yes
# How fast can a NAS spam the same type of request
#
# Access-Request defaults to 10s
#access_request_abuse_threshold=10
#
# Accounting-Request defaults to 5s
#accounting_request_abuse_threshold=5
[database]
#DSN=DBI:SQLite:dbname=sitemanager.sqlite
DSN=DBI:mysql:database=sitemanager;host=localhost
#DSN=DBI:SQLite:dbname=smradius.sqlite
DSN=DBI:mysql:database=smradius;host=localhost
Username=root
Password=
......@@ -91,6 +133,7 @@ load=<<EOT
dicts/dictionary
dicts/dictionary.microsoft
dicts/dictionary.mikrotik
dicts/dictionary.wispr
EOT
......@@ -108,151 +151,404 @@ EOT
[system]
plugins=<<EOT
modules=<<EOT
mod_config_sql
mod_config_sql_topups
EOT
[features]
plugins=<<EOT
modules=<<EOT
mod_feature_capping
mod_feature_validity
mod_feature_fup
mod_feature_user_stats
mod_feature_update_user_stats_sql
EOT
[accounting]
plugins=<<EOT
modules=<<EOT
mod_accounting_sql
EOT
# MOD_CONFIG_SQL
[mod_config_sql]
get_config_realm_id_query=<<EOT
SELECT
ID
FROM
@TP@realms
WHERE
Name = ?
EOT
get_config_realm_attributes_query=<<EOT
SELECT
Name,
Operator,
Value
FROM
@TP@realm_attributes
WHERE
RealmID = ?
EOT
get_config_accesslist_query=<<EOT
SELECT
@TP@clients.AccessList,
@TP@clients.ID
FROM
@TP@clients,
@TP@clients_to_realms
WHERE
@TP@clients.ID = @TP@clients_to_realms.ClientID
AND @TP@clients_to_realms.RealmID = ?
EOT
get_config_client_attributes_query=<<EOT
SELECT
Name,
Operator,
Value
FROM
@TP@client_attributes
WHERE
ClientID = ?
EOT
# MOD_CONFIG_SQL_TOPUPS
[mod_config_sql_topups]
get_topups_summary_query=<<EOT
SELECT
@TP@topups_summary.Balance,
@TP@topups.Type,
@TP@topups.ID
FROM
@TP@topups_summary,
@TP@topups,
@TP@users
WHERE
@TP@topups.ID = @TP@topups_summary.TopupID
AND @TP@topups.UserID = @TP@users.ID
AND @TP@topups_summary.PeriodKey = ?
AND @TP@topups.Depleted = 0
AND @TP@users.Username = ?
EOT
get_topups_query=<<EOT
SELECT
@TP@topups.ID,
@TP@topups.Type,
@TP@topups.Value
FROM
@TP@topups,
@TP@users
WHERE
@TP@topups.UserID = @TP@users.ID
AND @TP@topups.ValidFrom = ?
AND @TP@topups.ValidTo >= ?
AND @TP@topups.Depleted = 0
AND @TP@users.Username = ?
EOT
topups_add_query=<<EOT
INSERT INTO @TP@topups (
UserID,
Timestamp,
ValidFrom,
ValidTo,
Type,
Value,
Depleted
) VALUES (
%{user.ID},
%{query.Timestamp},
%{query.ValidFrom},
%{query.ValidTo},
%{query.Type},
%{query.Value},
%{query.Depleted}
)
EOT
# MOD_ACCOUNTING_SQL
[mod_accounting_sql]
accounting_start_query=<<EOT
INSERT INTO @TP@accounting
(
Username,
ServiceType,
FramedProtocol,
NASPort,
NASPortType,
CallingStationID,
CalledStationID,
NASPortID,
AcctSessionID,
FramedIPAddress,
AcctAuthentic,
EventTimestamp,
AcctStatusType,
NASIdentifier,
NASIPAddress,
AcctDelayTime
)
VALUES
(
%{request.User-Name},
%{request.Service-Type},
%{request.Framed-Protocol},
%{request.NAS-Port},
%{request.NAS-Port-Type},
%{request.Calling-Station-Id},
%{request.Called-Station-Id},
%{request.NAS-Port-Id},
%{request.Acct-Session-Id},
%{request.Framed-IP-Address},
%{request.Acct-Authentic},
%{request.Timestamp},
%{request.Acct-Status-Type},
%{request.NAS-Identifier},
%{request.NAS-IP-Address},
%{request.Acct-Delay-Time}
)
INSERT INTO
@TP@accounting
(
Username,
ServiceType,
FramedProtocol,
NASPort,
NASPortType,
CallingStationID,
CalledStationID,
NASPortID,
AcctSessionID,
FramedIPAddress,
AcctAuthentic,
EventTimestamp,
AcctStatusType,
NASIdentifier,
NASIPAddress,
AcctDelayTime,
AcctSessionTime,
AcctInputOctets,
AcctInputGigawords,
AcctInputPackets,
AcctOutputOctets,
AcctOutputGigawords,
AcctOutputPackets,
PeriodKey
)
VALUES
(
%{user.Username},
%{request.Service-Type},
%{request.Framed-Protocol},
%{request.NAS-Port},
%{request.NAS-Port-Type},
%{request.Calling-Station-Id},
%{request.Called-Station-Id},
%{request.NAS-Port-Id},
%{request.Acct-Session-Id},
%{request.Framed-IP-Address},
%{request.Acct-Authentic},
%{request.Timestamp},
%{request.Acct-Status-Type},
%{request.NAS-Identifier},
%{request.NAS-IP-Address},
%{request.Acct-Delay-Time},
%{request.Acct-Session-Time},
%{request.Acct-Input-Octets},
%{request.Acct-Input-Gigawords},
%{request.Acct-Input-Packets},
%{request.Acct-Output-Octets},
%{request.Acct-Output-Gigawords},
%{request.Acct-Output-Packets},
%{query.PeriodKey}
)
EOT
accounting_update_get_records_query=<<EOT
SELECT
SUM(AcctInputOctets) AS AcctInputOctets,
SUM(AcctInputPackets) AS AcctInputPackets,
SUM(AcctOutputOctets) AS AcctOutputOctets,
SUM(AcctOutputPackets) AS AcctOutputPackets,
SUM(AcctInputGigawords) AS AcctInputGigawords,
SUM(AcctOutputGigawords) AS AcctOutputGigawords,
SUM(AcctSessionTime) AS AcctSessionTime,
PeriodKey
FROM
@TP@accounting
WHERE
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPort = %{request.NAS-Port}
GROUP BY
PeriodKey
ORDER BY
ID ASC
EOT
accounting_update_query=<<EOT
UPDATE @TP@accounting
SET
AcctSessionTime = %{request.Acct-Session-Time},
AcctInputOctets = %{request.Acct-Input-Octets},
AcctInputGigawords = %{request.Acct-Input-Gigawords},
AcctInputPackets = %{request.Acct-Input-Packets},
AcctOutputOctets = %{request.Acct-Output-Octets},
AcctOutputGigawords = %{request.Acct-Output-Gigawords},
AcctOutputPackets = %{request.Acct-Output-Packets},
AcctStatusType = %{request.Acct-Status-Type}
WHERE
UserName = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
UPDATE
@TP@accounting
SET
AcctSessionTime = %{query.Acct-Session-Time},
AcctInputOctets = %{query.Acct-Input-Octets},
AcctInputGigawords = %{query.Acct-Input-Gigawords},
AcctInputPackets = %{query.Acct-Input-Packets},
AcctOutputOctets = %{query.Acct-Output-Octets},
AcctOutputGigawords = %{query.Acct-Output-Gigawords},
AcctOutputPackets = %{query.Acct-Output-Packets},
AcctStatusType = %{request.Acct-Status-Type}
WHERE
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPort = %{request.NAS-Port}
AND PeriodKey = %{query.PeriodKey}
EOT
accounting_stop_query=<<EOT
UPDATE @TP@accounting
SET
AcctSessionTime = %{request.Acct-Session-Time},
AcctInputOctets = %{request.Acct-Input-Octets},
AcctInputGigawords = %{request.Acct-Input-Gigawords},
AcctInputPackets = %{request.Acct-Input-Packets},
AcctOutputOctets = %{request.Acct-Output-Octets},
AcctOutputGigawords = %{request.Acct-Output-Gigawords},
AcctOutputPackets = %{request.Acct-Output-Packets},
AcctStatusType = %{request.Acct-Status-Type},
AcctTerminateCause = %{request.Acct-Terminate-Cause}
WHERE
UserName = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
accounting_stop_status_query=<<EOT
UPDATE
@TP@accounting
SET
AcctStatusType = %{request.Acct-Status-Type},
AcctTerminateCause = %{request.Acct-Terminate-Cause}
WHERE
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPort = %{request.NAS-Port}
EOT
accounting_usage_query=<<EOT
SELECT
SUM(AcctInputOctets) AS InputOctets,
SUM(AcctOutputOctets) AS OutputOctets,
SUM(AcctInputGigawords) AS InputGigawords,
SUM(AcctOutputGigawords) AS OutputGigawords,
SUM(AcctSessionTime) AS SessionTime
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
SELECT
SUM(AcctInputOctets) AS AcctInputOctets,
SUM(AcctOutputOctets) AS AcctOutputOctets,
SUM(AcctInputGigawords) AS AcctInputGigawords,
SUM(AcctOutputGigawords) AS AcctOutputGigawords,
SUM(AcctSessionTime) AS AcctSessionTime
FROM
@TP@accounting
WHERE
Username = %{user.Username}
AND PeriodKey = %{query.PeriodKey}
EOT
accounting_select_duplicates_query=<<EOT
SELECT
ID
FROM
@TP@accounting
WHERE
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPort = %{request.NAS-Port}
AND PeriodKey = %{query.PeriodKey}
ORDER BY
ID DESC
LIMIT 99 OFFSET 1
EOT
accounting_delete_duplicates_query=<<EOT
DELETE FROM
@TP@accounting
WHERE
ID = %{query.DuplicateID}
EOT
# This is how long we going to cache the usage query for
# Default: 300 (seconds)
#
# You can use "no", "0", "false" to disable, specify a number > 1, or use
# "yes", "1", "true" to enable with the default value
accounting_usage_cache_time=300
# MOD_USERDB_SQL
[mod_userdb_sql]
userdb_find_query=<<EOT
SELECT
ID
FROM
@TP@users
WHERE
UserName = %{request.User-Name}
SELECT
ID, Disabled
FROM
@TP@users
WHERE
Username = %{user.Username}
EOT
userdb_get_group_attributes_query=<<EOT
SELECT
group_attributes.Name, group_attributes.Operator, group_attributes.Value
FROM
@TP@group_attributes, @TP@users_to_groups
WHERE
users_to_groups.UserID = %{userdb.id}
AND group_attributes.GroupID = users_to_groups.GroupID
SELECT
group_attributes.Name, group_attributes.Operator, group_attributes.Value
FROM
@TP@group_attributes, @TP@users_to_groups
WHERE
users_to_groups.UserID = %{user.ID}
AND group_attributes.GroupID = users_to_groups.GroupID
AND group_attributes.Disabled = 0
EOT
userdb_get_user_attributes_query=<<EOT
SELECT
Name, Operator, Value
FROM
@TP@user_attributes
WHERE
UserID = %{userdb.id}
SELECT
Name, Operator, Value
FROM
@TP@user_attributes
WHERE
UserID = %{user.ID}
AND Disabled = 0
EOT
users_data_set_query=<<EOT
INSERT INTO
@TP@users_data (UserID, LastUpdated, Name, Value)
VALUES
(
%{user.ID},
%{query.LastUpdated},
%{query.Name},
%{query.Value}
)
EOT
users_data_update_query=<<EOT
UPDATE
@TP@users_data
SET
LastUpdated = %{query.LastUpdated},
Value = %{query.Value}
WHERE
UserID = %{user.ID}
AND Name = %{query.Name}
EOT
users_data_get_query=<<EOT
SELECT
LastUpdated, Name, Value
FROM
@TP@users_data
WHERE
UserID = %{user.ID}
AND Name = %{query.Name}
EOT
users_data_delete_query=<<EOT
DELETE FROM
@TP@users_data
WHERE
UserID = %{user.ID}
AND Name = %{query.Name}
EOT
# This is how long we going to cache the data query for
# Default: 300 (seconds)
#
# You can use "no", "0", "false" to disable, specify a number > 1, or use
# "yes", "1", "true" to enable with the default value
userdb_data_cache_time=300
# MOD_FEATURE_UPDATE_USER_STATS_SQL
[mod_feature_update_user_stats_sql]
update_user_stats_query=<<EOT
UPDATE
@TP@users
SET
PeriodKey = %{query.PeriodKey},
TotalTraffic = %{query.TotalTraffic},
TotalUptime = %{query.TotalUptime},
NASIdentifier = %{request.NAS-Identifier},
LastAcctUpdate = now()
WHERE
Username = %{user.Username}
EOT
# MOD_FEATURE_CAPPING
[mod_feature_capping]
# Enable Mikrotik-specific return vattributes
#enable_mikrotik=1
# Enable caveat for SMRadius-Capping-Traffic-Limit having the meaning of 0 and -undef- swapped up to v1.0.x
#caveat_captrafzero=1
<?php
# Tool Tip Data
# Copyright (C) 2007-2009, AllWorldIT
#
# Test harness for module loading
# Copyright (C) 2014-2016, 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.
$tooltips['user_attributes_name'] = "Please refer to the manual for a list of allowed attribute names";
?>
use Test::More;
use strict;
use warnings;
require_ok("smradius::daemon");
require_ok("smradius::client");
done_testing();
use strict;
use warnings;
use AWITPT::Util;
use Data::Dumper;
use Date::Parse;
use POSIX qw(:sys_wait_h);
use Test::Most;
use Test::Most::Exception 'throw_failure';
#
# Check that database tests are enabled
#
# We need DBTESTS enabled to run this
if (!$ENV{'DBTESTS'}) {
plan skip_all => 'DBTESTS not set in ENV';
done_testing();
exit 0;
}
#
# Load database handling libraries
#
require_ok('AWITPT::DB::DBILayer');
require_ok('AWITPT::DB::DBLayer');
use AWITPT::DB::DBLayer;
#
# Load our server and client
#
require_ok("smradius::daemon");
require_ok("smradius::client");
#
# Daemon help
#
can_ok("smradius::daemon","displayHelp");
#
# Try connect to database
#
my $dbh = AWITPT::DB::DBILayer->new({
'Username' => 'root',
'DSN' => 'DBI:mysql:database=smradiustest;host=localhost',
});
# If we cannot connect, just bail out
if ($dbh->connect()) {
BAIL_OUT("ERROR: Failed to connect to database for testing purposes: ".$dbh->error());
}
AWITPT::DB::DBLayer::setHandle($dbh);
#
# Make sure DB is clean
#
my $sth;
$sth = DBDo("DELETE FROM topups");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'topups");
$sth = DBDo("DELETE FROM accounting");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'accounting");
$sth = DBDo("DELETE FROM user_attributes");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'user_attributes");
$sth = DBDo("DELETE FROM client_attributes");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'client_attributes");
$sth = DBDo("DELETE FROM users");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'users'");
$sth = DBDo("DELETE FROM clients_to_realms");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'clients_to_realms'");
$sth = DBDo("DELETE FROM clients");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'clients'");
$sth = DBDo("DELETE FROM realms");
is(AWITPT::DB::DBLayer::error(),"","Clean table 'realms'");
#
# Run server and client
#
our $child;
if ($child = fork()) {
# CHLD handler
local $SIG{CHLD} = sub {
warn "SIGCHLD TRIGGER";
waitpid($child,-1);
};
# Install signal handlers to cleanup if we get a TERM or INT
local $SIG{TERM} = local $SIG{INT} = \&cleanup;
# Wait before starting
sleep(2);
# Setup failure handler
set_failure_handler( sub { my @params = @_; cleanup(); throw_failure } );
my $res;
#
# Make sure basic test without any config does not authenticate users
#
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser1',
'User-Password=test123',
);
is(ref($res),"","smradclient ref should return ''");
is($res,1,"smradclient result should be 1");
#
# Create test case data
#
my $client1_ID = testDBInsert("Create client 'localhost'",
"INSERT INTO clients (Name,AccessList,Disabled) VALUES ('localhost','127.0.0.0/8',0)"
);
my $client1attr1_ID = testDBInsert("Create client 'localhost' secret",
"INSERT INTO client_attributes (ClientID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$client1_ID,'SMRadius-Config-Secret',':=','secret123'
);
# Blank realm
my $realm1_ID = testDBInsert("Create realm ''",
"INSERT INTO realms (Name,Disabled) VALUES ('',0)"
);
my $clientTOrealm1_ID = testDBInsert("Link client 'localhost' to realm ''",
"INSERT INTO clients_to_realms (ClientID,RealmID,Disabled) VALUES (?,?,0)",$client1_ID,$realm1_ID
);
#
# Check we get an Access-Accept for a bare user using a blank realm
#
my $user1_ID = testDBInsert("Create user 'testuser1'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser1',0)"
);
my $user1attr1_ID = testDBInsert("Create user 'testuser1' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user1_ID,'User-Password','==','test123'
);
my $user1attr2_ID = testDBInsert("Create user 'testuser1' attribute 'Framed-IP-Address'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user1_ID,'Framed-IP-Address',':=','10.0.0.1'
);
my $user1attr3_ID = testDBInsert("Create user 'testuser1' vendor attribute '[14988:Mikrotik-Rate-Limit]'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user1_ID,'[14988:Mikrotik-Rate-Limit]',':=','1024k/512k'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser1',
'User-Password=test123',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Accept","Check our return is 'Access-Accept' for bare user blank '' realm");
# Test the normal attribute and vendor attribute
is($res->{'response'}->{'attributes'}->{'Framed-IP-Address'},"10.0.0.1","Check that attribute 'Framed-IP-Address' is".
" returned");
is($res->{'response'}->{'vattributes'}->{'14988'}->{'Mikrotik-Rate-Limit'}->[0],"1024k/512k","Check that the vendor attribute".
"'14988:Mikrotik-Rate-Limit' is returned");
# Add filter attributes
my $user1attr4_ID = testDBInsert("Create user 'testuser1' filter attribute for 'Framed-IP-Address'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user1_ID,'SMRadius-Config-Filter-Reply-Attribute',':=','Framed-IP-Address'
);
my $user1attr5_ID = testDBInsert("Create user 'testuser1' filter vattribute for 'Mikrotik-Rate-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user1_ID,'SMRadius-Config-Filter-Reply-VAttribute',':=','Mikrotik-Rate-Limit'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser1',
'User-Password=test123',
);
is(ref($res),"HASH","smradclient should return a HASH");
# We shouldn't....
isnt($res->{'response'}->{'attributes'}->{'Framed-IP-Address'},"10.0.0.1","Check that attribute 'Framed-IP-Address' is".
" returned");
#
# Modify data for the default realm
#
testDBDelete("Delete blank realm '' link to client",
"DELETE FROM clients_to_realms WHERE ID = ?",$clientTOrealm1_ID
);
testDBDelete("Delete blank realm '' for realm '<DEFAULT>' test",
"DELETE FROM realms WHERE ID = ?",$realm1_ID
);
my $realm1b_ID = testDBInsert("Create default realm '<DEFAULT>'",
"INSERT INTO realms (Name,Disabled) VALUES ('<DEFAULT>',0)"
);
my $clientTOrealm1b_ID = testDBInsert("Link client 'localhost' to realm '<DEFAULT>'",
"INSERT INTO clients_to_realms (ClientID,RealmID,Disabled) VALUES (?,?,0)",$client1_ID,$realm1b_ID
);
#
# Check we get an Access-Accept for a bare user using the default realm
#
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser1',
'User-Password=test123',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Accept","Check our return is 'Access-Accept' for bare user on <DEFAULT> realm");
#
# Check we get a Access-Reject for a traffic topup user
#
my $user2_ID = testDBInsert("Create user 'testuser2'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser2',0)"
);
my $user2attr1_ID = testDBInsert("Create user 'testuser2' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user2_ID,'User-Password','==','test123'
);
my $user2attr2_ID = testDBInsert("Create user 'testuser2' attribute 'SMRadius-Capping-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user2_ID,'SMRadius-Capping-Traffic-Limit',':=','0'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser2',
'User-Password=test123',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Reject","Check our return is 'Access-Reject' for a traffic topup user");
#
# Check we get a Access-Reject for a uptime topup user
#
my $user2b_ID = testDBInsert("Create user 'testuser2b'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser2b',0)"
);
my $user2battr1_ID = testDBInsert("Create user 'testuser2b' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user2b_ID,'User-Password','==','test123'
);
my $user2battr3_ID = testDBInsert("Create user 'testuser2b' attribute 'SMRadius-Capping-Uptime-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user2b_ID,'SMRadius-Capping-Uptime-Limit',':=','0'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser2b',
'User-Password=test123',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Reject","Check our return is 'Access-Reject' for a uptime topup user");
#
# Test accounting START packet
#
my $session1_ID = "09d15244";
my $session1_Timestamp = time();
my $session1_Timestamp_str = DateTime->from_epoch(epoch => $session1_Timestamp,time_zone => 'UTC')
->strftime('%Y-%m-%d %H:%M:%S');
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"acct",
"secret123",
'NAS-IP-Address=10.0.0.3',
'Acct-Delay-Time=11',
'NAS-Identifier=Test-NAS1',
'Acct-Status-Type=Start',
'Event-Timestamp='.$session1_Timestamp,
'Framed-IP-Address=10.0.1.3',
'Acct-Session-Id='.$session1_ID,
'NAS-Port-Id=test iface name1',
'Called-Station-Id=testservice1',
'Calling-Station-Id=00:00:0C:EE:47:AA',
'User-Name=testuser1',
'NAS-Port-Type=Ethernet',
'NAS-Port=45355555',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
testDBResults("Check accounting record is created correctly",'accounting',{'AcctSessionID' => $session1_ID},
{
'NASIPAddress' => '10.0.0.3',
'AcctDelayTime' => '11',
'NASIdentifier' => 'Test-NAS1',
'AcctStatusType' => 1,
'EventTimestamp' => sub{ _timestampCheck(shift,$session1_Timestamp_str) },
'FramedIPAddress' => '10.0.1.3',
'AcctSessionId' => $session1_ID,
'NASPortId' => 'test iface name1',
'CalledStationId' => 'testservice1',
'CallingStationId' => '00:00:0C:EE:47:AA',
'Username' => 'testuser1',
'NASPortType' => 15,
'NASPort' => '45355555',
'FramedProtocol' => 1,
'ServiceType' => 2,
'AcctOutputPackets' => undef,
'AcctOutputGigawords' => undef,
'AcctOutputOctets' => undef,
'AcctInputPackets' => undef,
'AcctInputGigawords' => undef,
'AcctInputOctets' => undef,
'AcctSessionTime' => undef,
}
);
#
# Test accounting ALIVE packet
#
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"acct",
"secret123",
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=800000',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=810000000',
'Acct-Input-Packets=777777',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=123456789',
'Acct-Session-Time=999',
'User-Name=testuser1',
'Acct-Session-Id='.$session1_ID,
'NAS-IP-Address=10.0.0.3',
'NAS-Port=45355555',
);
is(ref($res),"HASH","smradclient should return a HASH");
testDBResults("Check accounting record is updated correctly",'accounting',{'AcctSessionID' => $session1_ID},
{
'NASIPAddress' => '10.0.0.3',
'AcctDelayTime' => '11',
'NASIdentifier' => 'Test-NAS1',
'AcctStatusType' => 3,
'EventTimestamp' => sub{ _timestampCheck(shift,$session1_Timestamp_str) },
'FramedIPAddress' => '10.0.1.3',
'AcctSessionId' => $session1_ID,
'NASPortId' => 'test iface name1',
'CalledStationId' => 'testservice1',
'CallingStationId' => '00:00:0C:EE:47:AA',
'Username' => 'testuser1',
'NASPortType' => 15,
'NASPort' => '45355555',
'FramedProtocol' => 1,
'ServiceType' => 2,
'AcctOutputPackets' => '800000',
'AcctOutputGigawords' => '0',
'AcctOutputOctets' => '810000000',
'AcctInputPackets' => '777777',
'AcctInputGigawords' => '0',
'AcctInputOctets' => '123456789',
'AcctSessionTime' => '999',
}
);
#
# Test accounting STOP packet
#
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"acct",
"secret123",
'Acct-Status-Type=Stop',
'Acct-Output-Packets=999999',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=888888888',
'Acct-Input-Packets=1111111',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=222222222',
'Acct-Session-Time=3998',
'Acct-Terminate-Cause=Session-Timeout',
'User-Name=testuser1',
'Acct-Session-Id='.$session1_ID,
'NAS-IP-Address=10.0.0.3',
'NAS-Port=45355555',
);
is(ref($res),"HASH","smradclient should return a HASH");
testDBResults("Check accounting record is stopped correctly",'accounting',{'AcctSessionID' => $session1_ID},
{
'NASIPAddress' => '10.0.0.3',
'AcctDelayTime' => '11',
'NASIdentifier' => 'Test-NAS1',
'AcctStatusType' => 2,
'EventTimestamp' => sub{ _timestampCheck(shift,$session1_Timestamp_str) },
'FramedIPAddress' => '10.0.1.3',
'AcctSessionId' => $session1_ID,
'NASPortId' => 'test iface name1',
'CalledStationId' => 'testservice1',
'CallingStationId' => '00:00:0C:EE:47:AA',
'Username' => 'testuser1',
'NASPortType' => 15,
'NASPort' => '45355555',
'FramedProtocol' => 1,
'ServiceType' => 2,
'AcctOutputPackets' => '999999',
'AcctOutputGigawords' => '0',
'AcctOutputOctets' => '888888888',
'AcctInputPackets' => '1111111',
'AcctInputGigawords' => '0',
'AcctInputOctets' => '222222222',
'AcctSessionTime' => '3998',
'AcctTerminateCause' => '5',
}
);
#
# Test missing accounting START packet
#
my $session2_ID = "817a0f1b";
my $session2_Timestamp = time();
my $session2_Timestamp_str = DateTime->from_epoch(epoch => $session2_Timestamp,time_zone => 'UTC')
->strftime('%Y-%m-%d %H:%M:%S');
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"acct",
"secret123",
'User-Name=testuser2',
'NAS-IP-Address=10.0.0.1',
'Acct-Delay-Time=12',
'NAS-Identifier=Test-NAS2',
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=786933',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=708163705',
'Acct-Input-Packets=670235',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=102600046',
'Acct-Session-Time=800',
'Event-Timestamp='.$session2_Timestamp,
'Framed-IP-Address=10.0.1.1',
'Acct-Session-Id='.$session2_ID,
'NAS-Port-Id=wlan1',
'Called-Station-Id=testservice2',
'Calling-Station-Id=00:00:0C:EE:47:BF',
'NAS-Port-Type=Ethernet',
'NAS-Port=15729175',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
testDBResults("Check missing accounting record is created correctly",'accounting',{'AcctSessionID' => $session2_ID},
{
'Username' => 'testuser2',
'NASIPAddress' => '10.0.0.1',
'AcctDelayTime' => '12',
'NASIdentifier' => 'Test-NAS2',
'AcctStatusType' => 3,
'AcctOutputPackets' => '786933',
'AcctOutputGigawords' => '0',
'AcctOutputOctets' => '708163705',
'AcctInputPackets' => '670235',
'AcctInputGigawords' => '0',
'AcctInputOctets' => '102600046',
'AcctSessionTime' => '800',
'EventTimestamp' => sub{ _timestampCheck(shift,$session2_Timestamp_str) },
'FramedIPAddress' => '10.0.1.1',
'AcctSessionId' => $session2_ID,
'NASPortId' => 'wlan1',
'CalledStationId' => 'testservice2',
'CallingStationId' => '00:00:0C:EE:47:BF',
'NASPortType' => 15,
'NASPort' => '15729175',
'FramedProtocol' => 1,
'ServiceType' => 2,
}
);
#
# Check we get a Access-Accept for a traffic autotopup user
#
my $topuptest1_amount = 100;
my $user3_ID = testDBInsert("Create user 'testuser3'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser3',0)"
);
my $user3attr1_ID = testDBInsert("Create user 'testuser3' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3_ID,'User-Password','==','test456'
);
my $user3attr2_ID = testDBInsert("Create user 'testuser3' attribute 'SMRadius-AutoTopup-Traffic-Enabled'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3_ID,'SMRadius-AutoTopup-Traffic-Enabled',':=','yes'
);
my $user3attr3_ID = testDBInsert("Create user 'testuser3' attribute 'SMRadius-AutoTopup-Traffic-Amount'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3_ID,'SMRadius-AutoTopup-Traffic-Amount',':=',$topuptest1_amount
);
my $user3attr4_ID = testDBInsert("Create user 'testuser3' attribute 'SMRadius-AutoTopup-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3_ID,'SMRadius-AutoTopup-Traffic-Limit',':=','500'
);
my $user3attr5_ID = testDBInsert("Create user 'testuser3' attribute 'SMRadius-Capping-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3_ID,'SMRadius-Capping-Traffic-Limit',':=','0'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser3',
'User-Password=test456',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Accept","Check our return is 'Access-Accept' for a traffic autotopup user");
# Get the time now
my $topuptest1_now = time();
my $topuptest1 = DateTime->from_epoch( 'epoch' => $topuptest1_now, 'time_zone' => 'UTC');
# Use truncate to set all values after 'month' to their default values
my $topuptest1_thisMonth = $topuptest1->clone()->truncate( to => "month" );
# This month, in string form
my $topuptest1_thisMonth_str = $topuptest1_thisMonth->strftime("%Y-%m-%d %H:%M:%S");
# Next month..
my $topuptest1_nextMonth = $topuptest1_thisMonth->clone()->add( months => 1 );
my $topuptest1_nextMonth_str = $topuptest1_nextMonth->strftime("%Y-%m-%d %H:%M:%S");
testDBResults("Check autotopup is added correctly",'topups',{'UserID' => $user3_ID},
{
'UserID' => $user3_ID,
'Timestamp' => sub { return _timestampCheck(shift,$topuptest1_now) },
'Type' => 5,
'ValidFrom' => $topuptest1_thisMonth_str,
'ValidTo' => $topuptest1_nextMonth_str,
'Value' => $topuptest1_amount,
'Depleted' => 0,
'SMAdminDepletedOn' => undef,
}
);
#
# Check we get a Access-Accept for a uptime autotopup user
#
my $topuptest1b_amount = 100;
my $user3b_ID = testDBInsert("Create user 'testuser3b'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser3b',0)"
);
my $user3battr1_ID = testDBInsert("Create user 'testuser3b' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3b_ID,'User-Password','==','test456'
);
my $user3battr2_ID = testDBInsert("Create user 'testuser3b' attribute 'SMRadius-AutoTopup-Uptime-Enabled'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3b_ID,'SMRadius-AutoTopup-Uptime-Enabled',':=','yes'
);
my $user3battr3_ID = testDBInsert("Create user 'testuser3b' attribute 'SMRadius-AutoTopup-Uptime-Amount'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3b_ID,'SMRadius-AutoTopup-Uptime-Amount',':=',$topuptest1b_amount
);
my $user3battr4_ID = testDBInsert("Create user 'testuser3b' attribute 'SMRadius-AutoTopup-Uptime-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3b_ID,'SMRadius-AutoTopup-Uptime-Limit',':=','500'
);
my $user3battr5_ID = testDBInsert("Create user 'testuser3b' attribute 'SMRadius-Capping-Uptime-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user3b_ID,'SMRadius-Capping-Uptime-Limit',':=','0'
);
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"auth",
"secret123",
'User-Name=testuser3b',
'User-Password=test456',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'response'}->{'code'},"Access-Accept","Check our return is 'Access-Accept' for a uptime autotopup user");
# Get the time now
my $topuptest1b_now = time();
my $topuptest1b = DateTime->from_epoch( 'epoch' => $topuptest1b_now, 'time_zone' => 'UTC');
# Use truncate to set all values after 'month' to their default values
my $topuptest1b_thisMonth = $topuptest1b->clone()->truncate( to => "month" );
# This month, in string form
my $topuptest1b_thisMonth_str = $topuptest1b_thisMonth->strftime("%Y-%m-%d %H:%M:%S");
# Next month..
my $topuptest1b_nextMonth = $topuptest1b_thisMonth->clone()->add( months => 1 );
my $topuptest1b_nextMonth_str = $topuptest1b_nextMonth->strftime("%Y-%m-%d %H:%M:%S");
testDBResults("Check autotopup is added correctly",'topups',{'UserID' => $user3b_ID},
{
'UserID' => $user3b_ID,
'Timestamp' => sub { return _timestampCheck(shift,$topuptest1b_now) },
'Type' => 6,
'ValidFrom' => $topuptest1b_thisMonth_str,
'ValidTo' => $topuptest1b_nextMonth_str,
'Value' => $topuptest1b_amount,
'Depleted' => 0,
'SMAdminDepletedOn' => undef,
}
);
#
# Check that if we send an accounting ALIVE we update the auto-topups
#
my $topuptest2_amount = 100;
my $user4_ID = testDBInsert("Create user 'testuser4'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser4',0)"
);
my $user4attr1_ID = testDBInsert("Create user 'testuser4' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'User-Password','==','test456'
);
my $user4attr2_ID = testDBInsert("Create user 'testuser4' attribute 'SMRadius-AutoTopup-Traffic-Enabled'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'SMRadius-AutoTopup-Traffic-Enabled',':=','yes'
);
my $user4attr3_ID = testDBInsert("Create user 'testuser4' attribute 'SMRadius-AutoTopup-Traffic-Amount'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'SMRadius-AutoTopup-Traffic-Amount',':=',$topuptest2_amount
);
my $user4attr4_ID = testDBInsert("Create user 'testuser4' attribute 'SMRadius-AutoTopup-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'SMRadius-AutoTopup-Traffic-Limit',':=','500'
);
my $user4attr5_ID = testDBInsert("Create user 'testuser4' attribute 'SMRadius-Capping-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'SMRadius-Capping-Traffic-Limit',':=','0'
);
my $user4attr6_ID = testDBInsert("Create user 'testuser4' attribute 'SMRadius-AutoTopup-Traffic-Notify'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user4_ID,'SMRadius-AutoTopup-Traffic-Notify',':=','root@localhost'
);
my $session3_ID = "9c5f24a";
my $session3_Timestamp = time();
$res = smradius::client->run(
"--raddb","dicts",
"127.0.0.1",
"acct",
"secret123",
'User-Name=testuser4',
'NAS-IP-Address=10.0.0.1',
'Acct-Delay-Time=12',
'NAS-Identifier=Test-NAS2',
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=786933',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=708163705',
'Acct-Input-Packets=670235',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=102600046',
'Acct-Session-Time=800',
'Event-Timestamp='.$session3_Timestamp,
'Framed-IP-Address=10.0.1.1',
'Acct-Session-Id='.$session3_ID,
'NAS-Port-Id=wlan1',
'Called-Station-Id=testservice2',
'Calling-Station-Id=00:00:0C:EE:47:BF',
'NAS-Port-Type=Ethernet',
'NAS-Port=15729175',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
# Get the time now
my $topuptest2_now = time();
my $topuptest2 = DateTime->from_epoch( 'epoch' => $topuptest2_now, 'time_zone' => 'UTC');
# Use truncate to set all values after 'month' to their default values
my $topuptest2_thisMonth = $topuptest2->clone()->truncate( to => "month" );
# This month, in string form
my $topuptest2_thisMonth_str = $topuptest2_thisMonth->strftime("%Y-%m-%d %H:%M:%S");
# Next month..
my $topuptest2_nextMonth = $topuptest2_thisMonth->clone()->add( months => 1 );
my $topuptest2_nextMonth_str = $topuptest2_nextMonth->strftime("%Y-%m-%d %H:%M:%S");
testDBResults("Check autotopup is added correctly after acct_log",'topups',{'UserID' => $user4_ID},
{
'UserID' => $user4_ID,
'Timestamp' => sub { return _timestampCheck(shift,$topuptest2_now) },
'Type' => 5,
'ValidFrom' => $topuptest2_thisMonth_str,
'ValidTo' => $topuptest2_nextMonth_str,
'Value' => $topuptest2_amount,
'Depleted' => 0,
'SMAdminDepletedOn' => undef,
}
);
#
# Check that if we send an accounting ALIVE we do not trigger FUP
#
my $user5_ID = testDBInsert("Create user 'testuser5'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser5',0)"
);
my $user5attr1_ID = testDBInsert("Create user 'testuser5' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user5_ID,'User-Password','==','test456'
);
my $user5attr2_ID = testDBInsert("Create user 'testuser5' attribute 'SMRadius-FUP-Period'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user5_ID,'SMRadius-FUP-Period',':=','1'
);
my $user5attr3_ID = testDBInsert("Create user 'testuser5' attribute 'SMRadius-FUP-Traffic-Threshold'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user5_ID,'SMRadius-FUP-Traffic-Threshold',':=',800
);
# Add an attribute so we can check the FUP match results
my $user5attr4_ID = testDBInsert("Create user 'testuser5' attribute 'SMRadius-Evaluate'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user5_ID,'SMRadius-Evaluate','||+=',"SMRadius_FUP > 0 ? [14988:Mikrotik-Rate-Limit] = 1638k/8m : [14988:Mikrotik-Rate-Limit] = 1k/1m"
);
my $session4_ID = "a8abc40";
my $session4_Timestamp = time();
$res = smradius::client->run(
"--raddb","dicts",
"--listen","127.0.0.1:1700",
"127.0.0.1",
"acct",
"secret123",
'User-Name=testuser5',
'NAS-IP-Address=10.0.0.1',
'Acct-Delay-Time=12',
'NAS-Identifier=Test-NAS2',
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=786933',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=708163705',
'Acct-Input-Packets=670235',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=102600046',
'Acct-Session-Time=800',
'Event-Timestamp='.$session4_Timestamp,
'Framed-IP-Address=10.0.1.1',
'Acct-Session-Id='.$session4_ID,
'NAS-Port-Id=wlan1',
'Called-Station-Id=testservice2',
'Calling-Station-Id=00:00:0C:EE:47:BF',
'NAS-Port-Type=Ethernet',
'NAS-Port=15729175',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'listen'}->{'response'}->{'code'},"CoA-Request","Check that the packet we got back is infact a ".
"CoA-Request");
is($res->{'listen'}->{'response'}->{'vattributes'}->{'14988'}->{'Mikrotik-Rate-Limit'}->[0],"1k/1m","Check that the vendor attribute".
"'14988:Mikrotik-Rate-Limit' is returned on the negative side of the IF");
testDBResults("Check FUP state was added to the user stats table as 0",'users_data',
{'UserID' => $user5_ID, 'Name' => "mod_feature_fup/State"},
{'Value' => "0"},
1, # Disable order
);
#
# Check that if we send an accounting ALIVE with a usage amount that exceeds FUP, that we trigger it
#
my $user6_ID = testDBInsert("Create user 'testuser6'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser6',0)"
);
my $user6attr1_ID = testDBInsert("Create user 'testuser6' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user6_ID,'User-Password','==','test456'
);
my $user6attr2_ID = testDBInsert("Create user 'testuser6' attribute 'SMRadius-FUP-Period'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user6_ID,'SMRadius-FUP-Period',':=','1'
);
my $user6attr3_ID = testDBInsert("Create user 'testuser6' attribute 'SMRadius-FUP-Traffic-Threshold'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user6_ID,'SMRadius-FUP-Traffic-Threshold',':=',800
);
# Add an attribute so we can check the FUP match results
my $user6attr4_ID = testDBInsert("Create user 'testuser6' attribute 'SMRadius-Evaluate'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user6_ID,'SMRadius-Evaluate','||+=',"SMRadius_FUP > 0 ? [14988:Mikrotik-Rate-Limit] = 1638k/8m : [14988:Mikrotik-Rate-Limit] = 1k/1m"
);
my $session5_ID = "582dc00";
my $session5_Timestamp = time();
$res = smradius::client->run(
"--raddb","dicts",
"--listen","127.0.0.1:1700",
"127.0.0.1",
"acct",
"secret123",
'User-Name=testuser6',
'NAS-IP-Address=10.0.0.1',
'Acct-Delay-Time=12',
'NAS-Identifier=Test-NAS2',
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=786933',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=808163705',
'Acct-Input-Packets=670235',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=202600046',
'Acct-Session-Time=800',
'Event-Timestamp='.$session5_Timestamp,
'Framed-IP-Address=10.0.1.1',
'Acct-Session-Id='.$session5_ID,
'NAS-Port-Id=wlan1',
'Called-Station-Id=testservice2',
'Calling-Station-Id=00:00:0C:EE:47:BF',
'NAS-Port-Type=Ethernet',
'NAS-Port=15729175',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'listen'}->{'response'}->{'code'},"CoA-Request","Check that the packet we got back is infact a ".
"CoA-Request");
is($res->{'listen'}->{'response'}->{'vattributes'}->{'14988'}->{'Mikrotik-Rate-Limit'}->[0],"1638k/8m","Check that the ".
"vendor attribute '14988:Mikrotik-Rate-Limit' is returned on the success side of the FUP check");
testDBResults("Check FUP state was added to the user stats table as 1",'users_data',
{'UserID' => $user6_ID, 'Name' => "mod_feature_fup/State"},
{'Value' => "1"},
1, # Disable order
);
#
# Check that if we send an accounting ALIVE with a usage amount that exceeds capping, that we trigger a POD
#
my $user7_ID = testDBInsert("Create user 'testuser7'",
"INSERT INTO users (UserName,Disabled) VALUES ('testuser7',0)"
);
my $user7attr1_ID = testDBInsert("Create user 'testuser7' attribute 'User-Password'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user7_ID,'User-Password','==','test456'
);
# Add an attribute so we can check the capping does a POD
my $user7attr4_ID = testDBInsert("Create user 'testuser7' attribute 'SMRadius-Capping-Traffic-Limit'",
"INSERT INTO user_attributes (UserID,Name,Operator,Value,Disabled) VALUES (?,?,?,?,0)",
$user7_ID,'SMRadius-Capping-Traffic-Limit',':=','1'
);
my $session6_ID = "5209dac0";
my $session6_Timestamp = time();
$res = smradius::client->run(
"--raddb","dicts",
"--listen","127.0.0.1:1700",
"127.0.0.1",
"acct",
"secret123",
'User-Name=testuser7',
'NAS-IP-Address=10.0.0.1',
'Acct-Delay-Time=12',
'NAS-Identifier=Test-NAS2',
'Acct-Status-Type=Interim-Update',
'Acct-Output-Packets=786933',
'Acct-Output-Gigawords=0',
'Acct-Output-Octets=808163705',
'Acct-Input-Packets=670235',
'Acct-Input-Gigawords=0',
'Acct-Input-Octets=202600046',
'Acct-Session-Time=800',
'Event-Timestamp='.$session6_Timestamp,
'Framed-IP-Address=10.0.1.1',
'Acct-Session-Id='.$session6_ID,
'NAS-Port-Id=wlan1',
'Called-Station-Id=testservice2',
'Calling-Station-Id=00:00:0C:EE:47:BF',
'NAS-Port-Type=Ethernet',
'NAS-Port=15729175',
'Framed-Protocol=PPP',
'Service-Type=Framed-User',
);
is(ref($res),"HASH","smradclient should return a HASH");
is($res->{'listen'}->{'response'}->{'code'},"Disconnect-Request","Check that the packet we got back is infact a ".
"Disconnect-Request");
sleep(5);
} else {
smradius::daemon->run(
"--fg",
"--debug",
"--config", "smradiusd.conf.test",
);
sleep 4;
exit 0;
}
cleanup();
done_testing();
# Cleanup function
sub cleanup
{
if ($child) {
# Kill the child if it exists
if (kill(0,$child)) {
kill('TERM',$child);
}
# Wait for it to be reaped
waitpid($child,-1);
}
}
# Function to quickly and easily insert data into the DB and generate 2 tests out of it
sub testDBInsert
{
my ($name,@params) = @_;
# Do the work...
DBDo(@params);
# Make sure we got no error
is(AWITPT::DB::DBLayer::error(),"",$name);
# Grab the last insert ID
my $id = DBLastInsertID();
# Make sure its > 0
is($id > 0,1,"$name, insert ID > 0");
return $id;
}
# Function to quickly and easily delete data from the DB
sub testDBDelete
{
my ($name,@params) = @_;
# Do the work...
DBDo(@params);
# Make sure we got no error
is(AWITPT::DB::DBLayer::error(),"",$name);
return 1;
}
# Test DB select results
sub testDBResults
{
my ($name,$table,$where,$resultCheck,$disableOrder) = @_;
# Build column list
my $columnList_str = join(',',keys %{$resultCheck});
# Create where criteria
my @whereLines = ();
my @whereData = ();
foreach my $columnName (keys %{$where}) {
# Add template placeholders
push(@whereLines,"$columnName = ?");
# Add data for template placeholders
push(@whereData,$where->{$columnName});
}
my $whereLines_str = join(' AND ',@whereLines);
# Check if we're not disabling ordering
my $extraSQL = "";
if (!defined($disableOrder)) {
$extraSQL = "ORDER BY ID DESC";
}
my $sqlQuery = "
SELECT
$columnList_str
FROM
$table
WHERE
$whereLines_str
$extraSQL
";
# Do select
my $sth = DBSelect($sqlQuery,@whereData);
# Make sure we got no error
is(AWITPT::DB::DBLayer::error(),"","Errors on DBSelect ($sqlQuery interpolated with ".join(', ',$extraSQL).": $name");
# We should get one result...
my $row = hashifyLCtoMC($sth->fetchrow_hashref(),keys %{$resultCheck});
is(defined($row),1,"DBSelect row defined: $name");
# Loop through results and check if they match
foreach my $resultName (keys %{$resultCheck}) {
# Check if the result is a code-based subroutine
if (ref(my $result = $resultCheck->{$resultName}) eq "CODE") {
is($resultCheck->{$resultName}($row->{$resultName}),1,"$name: $resultName sub{} check");
} else {
is($row->{$resultName},$resultCheck->{$resultName},"$name: $resultName check");
}
}
}
sub _timestampCheck
{
my ($testVal,$rightVal) = @_;
# Make sure testVal is defined
return "_timestampCheck: NO \$testVal" if (!defined($testVal));
# Make sure $testVal_time is returned form str2time
my $testVal_time = str2time($testVal,'UTC');
# Check if $rightVal is defined
my $rightVal_time;
if (!defined($rightVal)) {
$rightVal_time = time();
} elsif ($rightVal =~ /^\d+$/) {
$rightVal_time = $rightVal;
} else {
$rightVal_time = str2time($rightVal,'UTC');
}
# Make sure rightVal_time is defined
return "_timestampCheck: NO \$rightVal_time" if (!defined($rightVal_time));
# Grab the absolute difference
my $diff = abs($testVal_time - $rightVal_time);
return ($diff < 10) // "TIME DEVIATION: $diff";
}
#!/bin/bash
git submodule update --recursive --init
pushd 3rdparty/awitpt
git checkout v1.0.x
git pull
popd
pushd webgui/awitef
git checkout v0.0.x
git pull
popd
<?php
# Requires / Includes
include_once("functions/AdminUsers.php");
include_once("functions/AdminGroups.php");
include_once("functions/AdminRealms.php");
include_once("functions/AdminLocations.php");
define('RES_OK',0);
define('RES_ERR',-1);
class json_response {
private $_fields = array();
private $_id;
private $_results;
private $_datasetSize;
private $_status = RES_OK;
## @method setID($id)
# Set ID column
#
# @param id ID column name
public function setID($id) {
$this->_id = $id;
}
## @method setStatus($status)
# Set response status
#
# @param status Either RES_OK (default) or RES_ERROR
public function setStatus($status) {
$this->_status = $status;
}
## @method addField($name,$type)
# Add a field to our return results
#
# @param name Field name
# @param type Field type, 'int', 'string', 'float', 'boolean', 'date'
public function addField($name,$type) {
# Build field
$field = array(
'name' => $name,
'type' => $type
);
# Set ISO date format
if ($field['type'] == "date") {
$field['dateFormat'] = "Y-m-d";
}
# Add field to list
array_push($this->_fields,$field);
}
## @method setDatasetSize($size)
# Set how many records are returned in the dataset
#
# @param size Dataset size
public function setDatasetSize($size) {
$this->_datasetSize = $size;
}
## @method parseArrayRef($array)
# Parse in the array of results and fix it up
#
# @param arrayref Array ref containing the results
public function parseArray($array) {
$this->_results = array();
# Loop with array items
foreach ($array as $aitem) {
$item = array();
# Loop with fields we want
foreach ($this->_fields as $field) {
# FIXME - typecast?
$item[$field['name']] = $aitem[$field['name']];
}
array_push($this->_results,$item);
}
}
## @method parseHash($hashref)
# Parse in the hash of results and fix it up
#
# @param hashref Hash ref containing the results
public function parseHash($hash) {
$this->_results = array();
foreach ($this->_fields as $field) {
# FIXME - typecast?
$this_results[$field['name']] = $hash[$field['name']];
}
}
## @method export
# Export response into something we return
#
# @return JSON hash
# @li result - Result code/status
# @li data - Ref containing results
# @li metaData - Metadata containing info about the results being returned
# Metadata contains properties..
# - root: root element, which is always 'data'
# - fields: Optional field description, arrayref of hash refs, name = 'name', type 'type' and 'dateFormat' = 'Y-m-d'
# - id: Optional ID field name
# - totalProperty: Optional property name containing the number of records, always 'datasetSize'
# @li datasetSize Optional, number of records we're rturning
public function export() {
# Build result
$ret = array(
'result' => $this->_status,
# Additional stuff for other things to make life easier
'success' => $this->_status == RES_OK ? 1 : 0,
'metaData' => array(
'successProperty' => 'success'
)
);
# If we have results, add them
if (isset($this->_results)) {
$ret['data'] = $this->_results;
$ret['metaData']['root'] = 'data';
# If we have fields, set them up
if (isset($this->_fields)) {
$ret['metaData']['fields'] = $this->_fields;
}
}
# Check if we have an ID set
if (isset($this->_id)) {
$ret['metaData']['totalProperty'] = 'datasetSize';
$ret['datasetSize'] = $this->_datasetSize;
}
return $ret;
}
}
# Ajax to PHP
# 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.
# Requires / Includes
include_once("include/ajax/json.php");
include_once("include/ajax/functions/AdminUsers.php");
include_once("include/ajax/functions/AdminUserAttributes.php");
include_once("include/ajax/functions/AdminUserGroups.php");
include_once("include/ajax/functions/AdminUserLogs.php");
include_once("include/ajax/functions/AdminUserTopups.php");
include_once("include/ajax/functions/AdminGroups.php");
include_once("include/ajax/functions/AdminGroupAttributes.php");
include_once("include/ajax/functions/AdminGroupMembers.php");
include_once("include/ajax/functions/AdminRealms.php");
include_once("include/ajax/functions/AdminRealmAttributes.php");
include_once("include/ajax/functions/AdminRealmMembers.php");
include_once("include/ajax/functions/AdminClients.php");
include_once("include/ajax/functions/AdminClientAttributes.php");
include_once("include/ajax/functions/AdminClientRealms.php");
include_once("include/ajax/functions/WiSPUsers.php");
include_once("include/ajax/functions/WiSPLocations.php");
include_once("include/ajax/functions/WiSPLocationMembers.php");
include_once("include/ajax/functions/WiSPUserLogs.php");
include_once("include/ajax/functions/WiSPUserTopups.php");
include_once("include/radiuscodes.php");
define('RES_OK',0);
define('RES_ERR',-1);
/*
......@@ -172,7 +65,8 @@
);
echo json_encode($res);
*/
echo json_encode($msg);
// echo json_encode($msg);
jsonError(-1,$msg);
exit;
}
......@@ -239,8 +133,8 @@
# Build hash and push into param list
$search = array(
'Filter' => isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '',
'Start' => $_REQUEST['start'],
'Limit' => $_REQUEST['limit'],
'Start' => isset($_REQUEST['start']) ? $_REQUEST['start'] : NULL,
'Limit' => isset($_REQUEST['limit']) ? $_REQUEST['limit'] : NULL,
'Sort' => isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '',
'SortDirection' => isset($_REQUEST['dir']) ? $_REQUEST['dir'] : '',
);
......@@ -259,14 +153,14 @@
if (count($items) > 1) {
$array_pos = $items[0];
$array_item = $items[1];
$array_type = $items[2];
# Initialize array
if (!isset($soapParams[$array_pos])) {
$soapParams[$array_pos] = array();
}
# Check if we have an explicit type
if (isset($array_type)) {
if (isset($items[2])) {
$array_type = $items[2];
# Check type
if ($array_type == "boolean") {
# Checkboxes/booleans are undefined if false
......@@ -280,7 +174,7 @@
ajaxException("Unknown AJAX=>SOAP type: '$array_type'");
}
} else {
$item_value = $_REQUEST[$array_item];
$item_value = isset($_REQUEST[$array_item]) ? $_REQUEST[$array_item] : NULL;
}
# Set item
$soapParams[$array_pos][$array_item] = $item_value;
......@@ -291,18 +185,36 @@
}
}
switch ($function) {
case "getWiSPResellers":
$rawData = array (
# addAdminClientRealm.js functions
case "addAdminClientRealm":
array(
'ID' => 10,
'Name' => 'TestReseller1'
)
);
$res = addAdminClientRealm($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
$numResults = 1;
break;
case "removeAdminClientRealm":
$res = removeAdminClientRealm($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminClientRealms":
$res = getAdminClientRealms($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
......@@ -312,197 +224,1111 @@
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
# AdminClients.js functions
case "updateAdminClient":
$res = updateAdminClient($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createAdminClient":
$res = createAdminClient($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeAdminClient":
$res = removeAdminClient($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getLocations":
case "getAdminClients":
$rawData = getAdminLocations($soapParams);
$res = getAdminClients($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
$res->addField('AccessList','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminRealms":
case "getAdminClient":
$rawData = getAdminClient($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('AccessList','string');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
$rawData = getAdminRealms($soapParams);
# AdminClientAttributes.js functions
case "addAdminClientAttribute":
$res = addAdminClientAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "updateAdminClientAttribute":
$res = updateAdminClientAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminClientAttribute":
$rawData = getAdminClientAttribute($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "getAdminGroups":
case "getAdminClientAttributes":
$rawData = getAdminGroups($soapParams);
$res = getAdminClientAttributes($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Priority','int');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->addField('Comment','string');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminUsers":
case "removeAdminClientAttribute":
$res = removeAdminClientAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# Logs Summary
case "getWiSPUserLogsSummary":
$res = getWiSPUserLogsSummary($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->addField('uptimeCap','int');
$res->addField('trafficCap','int');
$res->addField('trafficUsage','int');
$res->addField('uptimeUsage','int');
$res->addField('trafficTopups','int');
$res->addField('uptimeTopups','int');
$res->addField('TotalTrafficTopups','int');
$res->addField('TotalUptimeTopups','int');
$res->addField('AllTrafficTopups','array');
$res->addField('AllUptimeTopups','array');
$res->parseHash($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminUserLogsSummary":
$rawData = getAdminUsers($soapParams);
$res = getAdminUserLogsSummary($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->addField('uptimeCap','int');
$res->addField('trafficCap','int');
$res->addField('trafficUsage','int');
$res->addField('uptimeUsage','int');
$res->addField('trafficTopups','int');
$res->addField('uptimeTopups','int');
$res->addField('TotalTrafficTopups','int');
$res->addField('TotalUptimeTopups','int');
$res->addField('AllTrafficTopups','array');
$res->addField('AllUptimeTopups','array');
$res->parseHash($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
# AdminUserTopups.js functions
case "getAdminUserTopups":
$res = getAdminUserTopups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
$res->addField('Timestamp','date');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','string');
$res->addField('ValidTo','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "createAdminUserTopup":
case "getWiSPUsers":
$res = createAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
$rawData = array (
break;
array(
'ID' => 10,
'AgentID' => 5,
'AgentName' => 'joe agent',
'Username' => 'johnsmith',
'UsageCap' => 1000,
'ClassID' => 7,
'ClassDesc' => 'ClassTest',
'RealmDesc' => 'My Realm',
'Service' => 'My Service',
'AgentDisabled' => FALSE,
'Disabled' => FALSE,
'AgentRef' => 'Reseller ref'
)
);
case "updateAdminUserTopup":
$numResults = 1;
$res = updateAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminUserTopup":
$rawData = getAdminUserTopup($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','date');
$res->addField('ValidTo','date');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "removeAdminUserTopup":
$res = removeAdminUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# WiSPUserTopups.js functions
case "getWiSPUserTopups":
$res = getWiSPUserTopups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Timestamp','date');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','string');
$res->addField('ValidTo','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "createWiSPUserTopup":
$res = createWiSPUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "updateWiSPUserTopup":
$res = updateWiSPUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getWiSPUserTopup":
$rawData = getWiSPUserTopup($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Type','int');
$res->addField('Value','int');
$res->addField('ValidFrom','date');
$res->addField('ValidTo','date');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "removeWiSPUserTopup":
$res = removeWiSPUserTopup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# AdminGroupMembers.js functions
case "getAdminGroupMembers":
$res = getAdminGroupMembers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('AgentID','int');
$res->addField('AgentName','string');
$res->addField('Username','string');
$res->addField('UsageCap','int');
$res->addField('ClassID','int');
$res->addField('ClassDesc','string');
$res->addField('RealmDesc','string');
$res->addField('Service','string');
$res->addField('AgentDisabled','boolean');
$res->addField('Disabled','boolean');
$res->addField('AgentRef','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPUserLogs":
case "removeAdminGroupMember":
$rawData = array (
$res = removeAdminGroupMember($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
array(
'ID' => 10,
'Username' => 'johnsmith',
'Status' => 1,
'Timestamp' => '10/03/2009',
'AcctSessionID' => '24234',
'AcctSessionTime' => '10:30',
'NASIPAddress' => '192.168.1.254',
'NASPortType' => '2',
'NASPort' => '3128',
'CalledStationID' => '282282',
'CallingStationID' => '2782872',
'NASTransmitRate' => '2000',
'NASReceiveRate' => '4000',
'FramedIPAddress' => '192.168.1.30',
'AcctInputMbyte' => '1241',
'AcctOutputMbyte' => '229',
'LastAcctUpdate' => '1282893',
'ConnectTermReason' => 'Failboat'
)
);
break;
$numResults = 1;
# AdminRealmMembers.js functions
case "getAdminRealmMembers":
$res = getAdminRealmMembers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','int');
$res->addField('Status','string');
$res->addField('Timestamp','string');
$res->addField('AcctSessionID','int');
$res->addField('AcctSessionTime','int');
$res->addField('NASIPAddress','string');
$res->addField('NASPortType','string');
$res->addField('NASPort','string');
$res->addField('CalledStationID','boolean');
$res->addField('CallingStationID','boolean');
$res->addField('NASTransmitRate','string');
$res->addField('NASReceiveRate','string');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "removeAdminRealmMember":
$res = removeAdminRealmMember($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# AdminUserLogs.js functions
case "getAdminUserLogs":
$res = getAdminUserLogs($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('EventTimestamp','string');
$res->addField('AcctStatusType','int');
$res->addField('ServiceType','int');
$res->addField('FramedProtocol','int');
$res->addField('NASPortType','int');
$res->addField('NASPortID','string');
$res->addField('CallingStationID','string');
$res->addField('CalledStationID','string');
$res->addField('AcctSessionID','string');
$res->addField('FramedIPAddress','string');
$res->addField('AcctInputMbyte','string');
$res->addField('AcctOutputMbyte','string');
$res->addField('LastAcctUpdate','string');
$res->addField('AcctInput','float');
$res->addField('AcctOutput','float');
$res->addField('AcctSessionTime','int');
$res->addField('ConnectTermReason','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
}
# addAdminUserGroup.js functions
case "addAdminUserGroup":
exit;
$res = addAdminUserGroup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# Connect via soap
$soap = new SoapClient(null,
array(
'location' => "http://localhost:1080/?Auth=$authType",
'uri' => $module,
'login' => $username,
'password' => $password
)
);
# Try soap call
try {
$soapRes = $soap->__call($function,$soapParams);
} catch (Exception $e) {
# Build msg string
if (is_soap_fault($e)) {
header("$SERVER_PROTOCOL 500 Internal Server Error");
$msg = "SOAP Fault: ".$e->faultstring;
if (!empty($e->detail)) {
$msg .= " (".$e->detail.")";
case "removeAdminUserGroup":
$res = removeAdminUserGroup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
} else {
header("$SERVER_PROTOCOL 400 Bad Request");
$msg = "Fault: ".$e->getMessage();
}
ajaxException($msg);
}
break;
case "getAdminUserGroups":
$res = getAdminUserGroups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
# AdminRealmAttributes.js functions
case "addAdminRealmAttribute":
$res = addAdminRealmAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "updateAdminRealmAttribute":
$res = updateAdminRealmAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminRealmAttribute":
$rawData = getAdminRealmAttribute($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "getAdminRealmAttributes":
$res = getAdminRealmAttributes($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "removeAdminRealmAttribute":
$res = removeAdminRealmAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# AdminGroupAttributes.js functions
case "addAdminGroupAttribute":
$res = addAdminGroupAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "updateAdminGroupAttribute":
$res = updateAdminGroupAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminGroupAttribute":
$rawData = getAdminGroupAttribute($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "getAdminGroupAttributes":
$res = getAdminGroupAttributes($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "removeAdminGroupAttribute":
$res = removeAdminGroupAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# AdminUserAttributes.js functions
case "addAdminUserAttribute":
$res = addAdminUserAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "updateAdminUserAttribute":
$res = updateAdminUserAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminUserAttribute":
$rawData = getAdminUserAttribute($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "getAdminUserAttributes":
$res = getAdminUserAttributes($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "removeAdminUserAttribute":
$res = removeAdminUserAttribute($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# WiSPUsers.js functions
case "updateWiSPUser":
$res = updateWiSPUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createWiSPUser":
$res = createWiSPUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeWiSPUser":
$res = removeWiSPUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getWiSPUsers":
$res = getWiSPUsers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->addField('Firstname','string');
$res->addField('Lastname','string');
$res->addField('Email','string');
$res->addField('Phone','int');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPUser":
$res = getWiSPUser($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->addField('Password','string');
$res->addField('Firstname','string');
$res->addField('Lastname','string');
$res->addField('Phone','string');
$res->addField('Email','string');
$res->addField('LocationID','int');
$res->parseHash($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPUserAttributes":
$res = getWiSPUserAttributes($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Operator','string');
$res->addField('Value','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPUserGroups":
$res = getWiSPUserGroups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
# WiSPUserLogs.js functions
case "getWiSPUserLogs":
$res = getWiSPUserLogs($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('EventTimestamp','string');
$res->addField('AcctStatusType','int');
$res->addField('ServiceType','int');
$res->addField('FramedProtocol','int');
$res->addField('NASPortType','int');
$res->addField('NASPortID','string');
$res->addField('CallingStationID','string');
$res->addField('CalledStationID','string');
$res->addField('AcctSessionID','string');
$res->addField('FramedIPAddress','string');
$res->addField('AcctInput','float');
$res->addField('AcctOutput','float');
$res->addField('AcctSessionTime','int');
$res->addField('ConnectTermReason','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
# WiSPLocationMembers.js functions
case "getWiSPLocationMembers":
$res = getWiSPLocationMembers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "removeWiSPLocationMember":
$res = removeWiSPLocationMember($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
# WiSPLocations.js functions
case "updateWiSPLocation":
$res = updateWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createWiSPLocation":
$res = createWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeWiSPLocation":
$res = removeWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getWiSPLocations":
$res = getWiSPLocations($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPLocation":
$rawData = getWiSPLocation($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminUsers.js functions
case "updateAdminUser":
$res = updateAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createAdminUser":
$res = createAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeAdminUser":
$res = removeAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminUsers":
$res = getAdminUsers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminUser":
$rawData = getAdminUser($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminRealms.js functions
case "updateAdminRealm":
$res = updateAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createAdminRealm":
$res = createAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeAdminRealm":
$res = removeAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminRealms":
$res = getAdminRealms($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminRealm":
$rawData = getAdminRealm($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminGroups.js functions
case "updateAdminGroup":
$res = updateAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "createAdminGroup":
$res = createAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "removeAdminGroup":
$res = removeAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
} else {
jsonSuccess();
}
break;
case "getAdminGroups":
$res = getAdminGroups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Priority','int');
$res->addField('Disabled','boolean');
$res->addField('Comment','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminGroup":
$rawData = getAdminGroup($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Priority','int');
$res->addField('Disabled','boolean');
$res->addField('Comment','string');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
case "getWiSPResellers":
$rawData = array (
array(
'ID' => 10,
'Name' => 'TestReseller1'
)
);
$numResults = 1;
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getAdminRealms":
$res = getAdminRealms($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
}
exit;
echo json_encode($soapRes);
# vim: ts=4
awitef @ e81e0f67
Subproject commit e81e0f67579cbfda8090563f11cf9c5ccda453b2
body .x-panel {
margin-bottom:20px;
}
.icon-grid {
background-image:url(resources/extjs/icons/fam/grid.png) !important;
}
#button-grid .x-panel-body {
border:1px solid #99bbe8;
border-top:0 none;
}
.add {
background-image:url(resources/extjs/icons/fam/add.gif) !important;
}
.option {
background-image:url(resources/extjs/icons/fam/plugin.gif) !important;
}
.remove {
background-image:url(resources/extjs/icons/fam/delete.gif) !important;
}
.save {
background-image:url(resources/extjs/icons/save.gif) !important;
}
<?php
include_once("include/db.php");
# Return list of users
function getAdminGroups($params) {
$db = connect_db();
$sql = "SELECT ID, Name, Priority, Disabled, Comment FROM groups";
$res = $db->query($sql);
$resultArray = array();
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Priority'] = $row->priority;
$item['Disabled'] = $row->disabled;
$item['Comment'] = $row->comment;
# push this row onto array
array_push($resultArray,$item);
}
# get number of rows
$sql = "SELECT count(*) FROM groups";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
return array($numResults,$resultArray);
}
?>
<?php
include_once("include/db.php");
# Return list of users
function getAdminLocations($params) {
$db = connect_db();
$sql = "SELECT ID, Name FROM wisp_locations";
$res = $db->query($sql);
$resultArray = array();
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
# push this row onto array
array_push($resultArray,$item);
}
# get number of rows
$sql = "SELECT count(*) FROM wisp_locations";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
return array($numResults,$resultArray);
}
?>
<?php
include_once("include/db.php");
# Return list of users
function getAdminRealms($params) {
$db = connect_db();
$sql = "SELECT ID, Name, Disabled FROM realms";
$res = $db->query($sql);
$resultArray = array();
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Disabled'] = $row->disabled;
# push this row onto array
array_push($resultArray,$item);
}
# get number of rows
$sql = "SELECT count(*) FROM realms";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
return array($numResults,$resultArray);
}
?>
<?php
include_once("include/db.php");
# Return list of users
function getAdminUsers($params) {
$db = connect_db();
$sql = "SELECT ID, Username, Disabled FROM users";
$res = $db->query($sql);
$resultArray = array();
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Username'] = $row->username;
$item['Disabled'] = $row->disabled;
# push this row onto array
array_push($resultArray,$item);
}
# get number of rows
$sql = "SELECT count(*) FROM users";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
return array($numResults,$resultArray);
}
?>
<?php
# Admin Client Attributes 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 client attribute
function addAdminClientAttribute($params) {
# Perform query
$res = DBDo("
INSERT INTO
@TP@client_attributes (ClientID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['ClientID'],
$params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'])
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Remove client attribute
function removeAdminClientAttribute($params) {
# Perform query
$res = DBDo("DELETE FROM @TP@client_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Edit client attribute
function updateAdminClientAttribute($params) {
# Perform query
$res = DBDo("UPDATE @TP@client_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'],
$params[0]['ID'])
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return specific attribute row
function getAdminClientAttribute($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@client_attributes 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['Name'] = $row->name;
$resultArray['Operator'] = $row->operator;
$resultArray['Value'] = $row->value;
$resultArray['Disabled'] = $row->disabled;
# Return results
return $resultArray;
}
# Return list of attributes
function getAdminClientAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@client_attributes.ID',
'Name' => '@TP@client_attributes.Name',
'Operator' => '@TP@client_attributes.Operator',
'Value' => '@TP@client_attributes.Value',
'Disabled' => '@TP@client_attributes.Disabled'
);
# Perform query
$res = DBSelectSearch("
SELECT
ID, Name, Operator, Value, Disabled
FROM
@TP@client_attributes
WHERE
ClientID = ".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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Operator'] = $row->operator;
$item['Value'] = $row->value;
$item['Disabled'] = $row->disabled;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# vim: ts=4
<?php
# Admin Client Realms 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");
# Link client to realm
function addAdminClientRealm($params) {
# Perform query
$res = DBDo("INSERT INTO @TP@clients_to_realms (ClientID,RealmID) VALUES (?,?)",array($params[0]['ClientID'],$params[0]['RealmID']));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Unlink client from realm
function removeAdminClientRealm($params) {
# Perform query
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return list of realms
function getAdminClientRealms($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@clients_to_realms.ID',
'Name' => '@TP@realms.Name'
);
# Perform query
$res = DBSelectSearch("
SELECT
@TP@clients_to_realms.ID, @TP@realms.Name
FROM
@TP@clients_to_realms, @TP@realms
WHERE
@TP@clients_to_realms.RealmID = @TP@realms.ID
AND @TP@clients_to_realms.ClientID = ".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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = htmlspecialchars($row->name);
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# vim: ts=4
<?php
# Admin Clients 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 clients
function getAdminClients($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@clients.ID',
'Name' => '@TP@clients.Name',
'AccessList' => '@TP@clients.AccessList'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, AccessList FROM @TP@clients",$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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['AccessList'] = $row->accesslist;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific client row
function getAdminClient($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, AccessList FROM @TP@clients 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['Name'] = $row->name;
$resultArray['AccessList'] = $row->accesslist;
# Return results
return $resultArray;
}
# Remove admin client
function removeAdminClient($params) {
# Begin transaction
DBBegin();
# Perform query
$res = DBDo("DELETE FROM @TP@client_attributes WHERE ClientID = ?",array($params[0]));
# Remove client from realms
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ClientID = ?",array($params[0]));
}
# Perform next query if successful
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@clients WHERE ID = ?",array($params[0]));
}
# Return result
if ($res !== TRUE) {
DBRollback();
return $res;
} else {
DBCommit();
}
return NULL;
}
# Add admin client
function createAdminClient($params) {
# Perform query
$res = DBDo("INSERT INTO @TP@clients (Name,AccessList) VALUES (?,?)",array($params[0]['Name'],$params[0]['AccessList']));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Edit admin client
function updateAdminClient($params) {
# Perform query
$res = DBDo("UPDATE @TP@clients SET Name = ?, AccessList = ? WHERE ID = ?",
array($params[0]['Name'],$params[0]['AccessList'],$params[0]['ID']));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# vim: ts=4
<?php
# Admin Group Attributes 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");
include_once("include/util.php");
# Add group attribute
function addAdminGroupAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
$res = DBDo("
INSERT INTO
@TP@group_attributes (GroupID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['GroupID'],
$params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$disabled)
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Remove group attribute
function removeAdminGroupAttribute($params) {
$res = DBDo("DELETE FROM @TP@group_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Edit group attribute
function updateAdminGroupAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
$res = DBDo("UPDATE @TP@group_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$disabled,
$params[0]['ID'])
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return specific attribute row
function getAdminGroupAttribute($params) {
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@group_attributes WHERE ID = ?",array($params[0]));
if (!is_object($res)) {
return $res;
}
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Name'] = $row->name;
$resultArray['Operator'] = $row->operator;
$resultArray['Value'] = $row->value;
$resultArray['Disabled'] = $row->disabled;
return $resultArray;
}
# Return list of attributes
function getAdminGroupAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@group_attributes.ID',
'Name' => '@TP@group_attributes.Name',
'Operator' => '@TP@group_attributes.Operator',
'Value' => '@TP@group_attributes.Value',
'Disabled' => '@TP@group_attributes.Disabled'
);
# Fetch attributes
$res = DBSelectSearch("
SELECT
ID, Name, Operator, Value, Disabled
FROM
@TP@group_attributes
WHERE
GroupID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
$resultArray = array();
# Loop through rows
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Operator'] = $row->operator;
$item['Value'] = $row->value;
$item['Disabled'] = $row->disabled;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# vim: ts=4
<?php
# Admin Group 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 member
function removeAdminGroupMember($params) {
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return list of members
function getAdminGroupMembers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@users_to_groups.ID',
'Username' => '@TP@group_attributes.Username',
'Disabled' => '@TP@group_attributes.Disabled'
);
# Fetch members
$res = DBSelectSearch("
SELECT
@TP@users_to_groups.ID, @TP@users.Username, @TP@users.Disabled
FROM
@TP@users_to_groups, @TP@users
WHERE
@TP@users.ID = @TP@users_to_groups.UserID
AND
@TP@users_to_groups.GroupID = ".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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Username'] = $row->username;
$item['Disabled'] = $row->disabled;
# Push this row onto array
array_push($resultArray,$item);
}
return array($resultArray,$numResults);
}
# vim: ts=4
<?php
# Admin Groups 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 list of groups
function getAdminGroups($params) {
global $db;
$sql = "SELECT ID, Name, Priority, Disabled, Comment FROM groups";
$res = $db->query($sql);
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@groups.ID',
'Name' => '@TP@groups.Name',
'Priority' => '@TP@groups.Priority',
'Disabled' => '@TP@groups.Disabled',
'Comment' => '@TP@groups.Comment'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, Priority, Disabled, Comment FROM @TP@groups",$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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Priority'] = $row->priority;
$item['Disabled'] = $row->disabled;
$item['Comment'] = $row->comment;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific group row
function getAdminGroup($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Priority, Disabled, Comment FROM @TP@groups 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['Name'] = $row->name;
$resultArray['Priority'] = $row->priority;
$resultArray['Disabled'] = $row->disabled;
$resultArray['Comment'] = $row->comment;
# Return results
return $resultArray;
}
# Remove admin group
function removeAdminGroup($params) {
# Begin transaction
DBBegin();
# Unlink users from group
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE GroupID = ?",array($params[0]));
# Delete group attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@group_attributes WHERE GroupID = ?",array($params[0]));
}
# Delete group
if ($res !== FALSE) {
$res = DBDo("DELETE FROM @TP@groups WHERE ID = ?",array($params[0]));
}
# Return result
if ($res !== TRUE) {
DBRollback();
return $res;
} else {
DBCommit();
}
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
return NULL;
}
# Add admin group
function createAdminGroup($params) {
# Perform query
$res = DBDo("INSERT INTO @TP@groups (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Priority'] = $row->priority;
$item['Disabled'] = $row->disabled;
$item['Comment'] = $row->comment;
# Edit admin group
function updateAdminGroup($params) {
# push this row onto array
array_push($resultArray,$item);
}
# Perform query
$res = DBDo("UPDATE @TP@groups SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# get number of rows
$sql = "SELECT count(*) FROM groups";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
# Return result
if ($res !== TRUE) {
return $res;
}
return array($numResults,$resultArray);
return NULL;
}
?>
# vim: ts=4
<?php
include_once("include/db.php");
# Return list of users
function getAdminLocations($params) {
global $db;
$sql = "SELECT ID, Name FROM wisp_locations";
$res = $db->query($sql);
$resultArray = array();
# loop through rows
while ($row = $res->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
# push this row onto array
array_push($resultArray,$item);
}
# get number of rows
$sql = "SELECT count(*) FROM wisp_locations";
$res = $db->query($sql);
$numResults = $res->fetchColumn();
return array($numResults,$resultArray);
}
?>
<?php
# Admin Realm Attributes 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 realm attribute
function addAdminRealmAttribute($params) {
# Perform query
$res = DBDo("
INSERT INTO
@TP@realm_attributes (RealmID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['RealmID'],
$params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'])
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Remove realm attribute
function removeAdminRealmAttribute($params) {
# Perform query
$res = DBDo("DELETE FROM @TP@realm_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Edit realm attribute
function updateAdminRealmAttribute($params) {
# Perform query
$res = DBDo("UPDATE @TP@realm_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'],
$params[0]['ID'])
);
# Return result
if ($res !== TRUE) {
return $res;
}
return NULL;
}
# Return specific attribute row
function getAdminRealmAttribute($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@realm_attributes 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['Name'] = $row->name;
$resultArray['Operator'] = $row->operator;
$resultArray['Value'] = $row->value;
$resultArray['Disabled'] = $row->disabled;
# Return results
return $resultArray;
}
# Return list of attributes
function getAdminRealmAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@realm_attributes.ID',
'Name' => '@TP@realm_attributes.Name',
'Operator' => '@TP@realm_attributes.Operator',
'Value' => '@TP@realm_attributes.Value',
'Disabled' => '@TP@realm_attributes.Disabled'
);
# Perform query
$res = DBSelectSearch("
SELECT
ID, Name, Operator, Value, Disabled
FROM
@TP@realm_attributes
WHERE
RealmID = ".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();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Operator'] = $row->operator;
$item['Value'] = $row->value;
$item['Disabled'] = $row->disabled;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# vim: ts=4
<?php
# Database Interface
# Copyright (C) 2007-2009, AllWorldIT
# Admin Realm 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
......@@ -16,52 +16,63 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
require_once('includes/config.php');
include_once("include/db.php");
# Remove realm member
function removeAdminRealmMember($params) {
# Connect to DB
function connect_db()
{
global $DB_DSN;
global $DB_USER;
global $DB_PASS;
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ID = ?",array($params[0]));
try {
$dbh = new PDO($DB_DSN, $DB_USER, $DB_PASS, array(
PDO::ATTR_PERSISTENT => false
));
$dbh->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
} catch (PDOException $e) {
die("Error connecting to Policyd v2 DB: " . $e->getMessage());
# Return result
if ($res !== TRUE) {
return $res;
}
return $dbh;
return NULL;
}
# Return list of members
function getAdminRealmMembers($params) {
# Connect to postfix DB
function connect_postfix_db()
{
global $DB_POSTFIX_DSN;
global $DB_POSTFIX_USER;
global $DB_POSTFIX_PASS;
# Filters and sorts are the same here
$filtersorts = array(
'ID' => '@TP@clients_to_realms.ID',
'Name' => '@TP@realm_attributes.Name'
);
try {
$dbh = new PDO($DB_POSTFIX_DSN, $DB_POSTFIX_USER, $DB_POSTFIX_PASS, array(
PDO::ATTR_PERSISTENT => false
));
# Fetch members
$res = DBSelectSearch("
SELECT
@TP@clients_to_realms.ID, @TP@clients.Name
FROM
@TP@clients_to_realms, @TP@clients
WHERE
@TP@clients.ID = @TP@clients_to_realms.ClientID
AND
@TP@clients_to_realms.RealmID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$dbh->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
$sth = $res[0]; $numResults = $res[1];
} catch (PDOException $e) {
die("Error connecting to Postfix DB: " . $e->getMessage());
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
return $dbh;
}
# Loop through rows
$resultArray = array();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
# Push this row onto array
array_push($resultArray,$item);
}
return array($resultArray,$numResults);
}
# vim: ts=4
?>