Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shail
smradius
Commits
e8751614
Commit
e8751614
authored
15 years ago
by
Robert Anderson
Browse files
Options
Downloads
Patches
Plain Diff
Added initial support for adding multiple users at once
parent
cf89b870
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webui/wisp-multiuser-add.php
+249
-0
249 additions, 0 deletions
webui/wisp-multiuser-add.php
with
249 additions
and
0 deletions
webui/wisp-multiuser-add.php
0 → 100644
+
249
−
0
View file @
e8751614
<?php
# Policy add
# Copyright (C) 2008, LinuxRulz
#
# 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
(
"includes/header.php"
);
include_once
(
"includes/footer.php"
);
include_once
(
"includes/db.php"
);
$db
=
connect_db
();
printHeader
(
array
(
));
if
(
!
isset
(
$_POST
[
'frmaction'
]))
{
?>
<p
class=
"pageheader"
>
Add WiSP Users
</p>
<!-- Add user input fields -->
<form
method=
"post"
action=
"wisp-multiuser-add.php"
>
<div>
<input
type=
"hidden"
name=
"frmaction"
value=
"insert"
/>
</div>
<table
class=
"entry"
>
<tr>
<td
class=
"textcenter"
colspan=
"2"
>
Add multiple users
</td>
</tr>
<tr>
<td><div></div><td>
</tr>
<tr>
<td
class=
"entrytitle"
>
Number of users
</td>
<td><input
type=
"text"
name=
"num_users"
/></td>
</tr>
<tr>
<td
class=
"entrytitle"
>
Login Prefix
</td>
<td><input
type=
"text"
name=
"login_prefix"
/></td>
</tr>
<tr>
<td
class=
"entrytitle"
>
Uptime Limit
</td>
<td><input
type=
"text"
name=
"session_timeout"
/></td>
</tr>
<tr>
<td
class=
"entrytitle"
>
Data Limit
</td>
<td><input
type=
"text"
name=
"data_limit"
/></td>
</tr>
<tr>
<td
class=
"entrytitle"
>
Time Limit
</td>
<td><input
type=
"text"
name=
"time_limit"
/></td>
</tr>
<tr>
<td
class=
"textcenter"
colspan=
"2"
><input
type=
"submit"
value=
"Submit"
/></td>
</tr>
</table>
</form>
<?php
}
if
(
$_POST
[
'frmaction'
]
==
"insert"
)
{
?>
<p
class=
"pageheader"
>
Add WiSP Users
</p>
<?php
# Perform checks on input
if
(
isset
(
$_POST
[
'num_users'
])
&&
isset
(
$_POST
[
'session_timeout'
])
&&
isset
(
$_POST
[
'data_limit'
])
&&
isset
(
$_POST
[
'time_limit'
]))
{
$db
->
beginTransaction
();
$numberOfUsers
=
(
int
)
$_POST
[
'num_users'
];
$sessionTimeout
=
(
int
)
$_POST
[
'session_timeout'
];
$dataLimit
=
(
int
)
$_POST
[
'data_limit'
];
$timeLimit
=
(
int
)
$_POST
[
'time_limit'
];
$loginNamePrefix
=
$_POST
[
'login_prefix'
];
for
(
$counter
=
0
;
$counter
<=
$numberOfUsers
;
$counter
+=
1
)
{
# Check if user already exists
$checkUsernameDuplicates
=
0
;
do
{
# Generate random username
$randomString
=
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
));
# If there is no login name prefix
if
(
empty
(
$loginNamePrefix
))
{
$userName
=
$randomString
;
$lookForUser
=
$db
->
query
(
"SELECT ID FROM ${DB_TABLE_PREFIX}users WHERE Username LIKE '%
$userName
%'"
);
$lookForUserRow
=
$lookForUser
->
fetchObject
();
# If the user was found
if
(
$lookForUserRow
)
{
$checkUsernameDuplicates
=
1
;
}
else
{
$checkUsernameDuplicates
=
0
;
}
# If there is a login name prefix
}
else
{
$userName
=
$loginNamePrefix
.
"_"
.
$randomString
;
$lookForUser
=
$db
->
query
(
"SELECT ID FROM ${DB_TABLE_PREFIX}users WHERE Username LIKE '%
$userName
%'"
);
$lookForUserRow
=
$lookForUser
->
fetchObject
();
# If the user was found
if
(
$lookForUserRow
)
{
$checkUsernameDuplicates
=
1
;
}
else
{
$checkUsernameDuplicates
=
0
;
}
}
}
while
(
$checkUsernameDuplicates
>
0
);
#Insert user into users table
$userInsert
=
$db
->
prepare
(
"INSERT INTO
${DB_TABLE_PREFIX}users (Username)
VALUES
(?)
"
);
$userInsertExec
=
$userInsert
->
execute
(
array
(
$userName
));
$failed
=
0
;
# After a user add is successful, continue with inserting the other data
if
(
$userInsertExec
)
{
# Get user ID to insert into other tables
$getUserID
=
$db
->
query
(
"SELECT ID FROM ${DB_TABLE_PREFIX}users WHERE Username = '
$userName
'"
);
$resultRow
=
$getUserID
->
fetchObject
();
$userID
=
$resultRow
->
id
;
# Inset UserID into userdata table
$userDataStatement
=
$db
->
prepare
(
" INSERT INTO
${DB_TABLE_PREFIX}userdata (UserID)
VALUES
(?)
"
);
$userDataResult
=
$userDataStatement
->
execute
(
array
(
$userID
));
# Generate a password
$userPassword
=
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
))
.
chr
(
rand
(
97
,
122
));
# Insert password into user_attributes table
$userPasswordStatement
=
$db
->
prepare
(
" INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
(
$userID
,'User-Password','==',?)
"
);
$userPasswordResult
=
$userPasswordStatement
->
execute
(
array
(
$userPassword
));
# Insert data limit into user_attributes table
$userDataStatement
=
$db
->
prepare
(
" INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
(
$userID
,'SMRadius-Capping-Traffic-Limit',':=',?)
"
);
$userDataResult
=
$userDataStatement
->
execute
(
array
(
$dataLimit
,));
# Insert time limit into user_attributes table
$userTimeStatement
=
$db
->
prepare
(
" INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
(
$userID
,'SMRadius-Capping-Time-Limit',':=',?)
"
);
$userTimeResult
=
$userTimeStatement
->
execute
(
array
(
$timeLimit
,));
# Insert timeout into user_attributes table
$userTimeOutStatement
=
$db
->
prepare
(
" INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
(
$userID
,'Session-Timeout','+=',?)
"
);
$userTimeOutResult
=
$userTimeOutStatement
->
execute
(
array
(
$sessionTimeout
,));
# If one was not successful, rollback
}
else
{
$db
->
rollback
;
print_r
(
$db
->
errorInfo
());
$failed
=
1
;
break
;
}
}
if
(
$failed
==
0
)
{
$db
->
commit
();
?>
<div
class=
"notice"
>
Users added
</div>
<?php
}
}
else
{
?>
<div
class=
"warning"
>
One or more fields have been left empty
</div>
<?php
}
}
printFooter
();
# vim: ts=4
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment