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
70f406e9
Commit
70f406e9
authored
15 years ago
by
Robert Anderson
Browse files
Options
Downloads
Patches
Plain Diff
Added multi-user add
parent
068c1ec0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
webgui/include/ajax/functions/WiSPUsers.php
+163
-92
163 additions, 92 deletions
webgui/include/ajax/functions/WiSPUsers.php
webgui/js/app/windows/WiSPUsers.js
+6
-7
6 additions, 7 deletions
webgui/js/app/windows/WiSPUsers.js
with
169 additions
and
99 deletions
webgui/include/ajax/functions/WiSPUsers.php
+
163
−
92
View file @
70f406e9
...
...
@@ -195,113 +195,184 @@ function createWiSPUser($params) {
global
$db
;
DBBegin
();
# Insert username
$res
=
DBDo
(
"INSERT INTO users (Username) VALUES (?)"
,
array
(
$params
[
0
][
'Username'
]));
# Continue with others if successful
if
(
$res
!==
FALSE
)
{
$userID
=
DBLastInsertID
();
$res
=
DBDo
(
"
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)"
,
array
(
$userID
,
'User-Password'
,
'=='
,
$params
[
0
][
'Password'
])
);
}
# Link users ID to make user a wisp user
if
(
$res
!==
FALSE
)
{
$res
=
DBDo
(
"INSERT INTO wisp_userdata (UserID) VALUES (?)"
,
array
(
$userID
));
}
$res
=
"Username & Password required for single user. For adding multiple users an integer is required."
;
# If we adding single user
if
(
empty
(
$params
[
0
][
'Number'
])
&&
!
empty
(
$params
[
0
][
'Password'
])
&&
!
empty
(
$params
[
0
][
'Username'
]))
{
# Insert username
$res
=
DBDo
(
"INSERT INTO users (Username) VALUES (?)"
,
array
(
$params
[
0
][
'Username'
]));
# Continue with others if successful
if
(
$res
!==
FALSE
)
{
$userID
=
DBLastInsertID
();
$res
=
DBDo
(
"
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)"
,
array
(
$userID
,
'User-Password'
,
'=='
,
$params
[
0
][
'Password'
])
);
}
# Add personal information
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Firstname'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET FirstName = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Firstname'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Lastname'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET LastName = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Lastname'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Phone'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET Phone = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Phone'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Email'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET Email = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Email'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'LocationID'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET LocationID = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'LocationID'
],
$userID
));
}
# Link users ID to make user a wisp user
if
(
$res
!==
FALSE
)
{
$res
=
DBDo
(
"INSERT INTO wisp_userdata (UserID) VALUES (?)"
,
array
(
$userID
));
}
# Add personal information
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Firstname'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET FirstName = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Firstname'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Lastname'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET LastName = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Lastname'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Phone'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET Phone = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Phone'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Email'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET Email = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'Email'
],
$userID
));
}
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'LocationID'
]))
{
$res
=
DBDo
(
"UPDATE wisp_userdata SET LocationID = ? WHERE UserID = ?"
,
array
(
$params
[
0
][
'LocationID'
],
$userID
));
}
# Grab each attribute and add it's details to the database
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Attributes'
]))
{
foreach
(
$params
[
0
][
'Attributes'
]
as
$attr
)
{
# Default value without modifier
$attrValue
=
$attr
[
'Value'
];
if
(
$attr
[
'Name'
]
==
'SMRadius-Capping-Traffic-Limit'
||
$attr
[
'Name'
]
==
'SMRadius-Capping-Uptime-Limit'
)
{
# If modifier is set we need to work out attribute value
if
(
isset
(
$attr
[
'Modifier'
]))
{
switch
(
$attr
[
'Modifier'
])
{
case
"Seconds"
:
$attrValue
=
$attr
[
'Value'
]
/
60
;
case
"Minutes"
:
$attrValue
=
$attr
[
'Value'
];
case
"Hours"
:
$attrValue
=
$attr
[
'Value'
]
*
60
;
case
"Days"
:
$attrValue
=
$attr
[
'Value'
]
*
1440
;
case
"Weeks"
:
$attrValue
=
$attr
[
'Value'
]
*
10080
;
case
"Months"
:
$attrValue
=
$attr
[
'Value'
]
*
44640
;
case
"MBytes"
:
$attrValue
=
$attr
[
'Value'
];
case
"GBytes"
:
$attrValue
=
$attr
[
'Value'
]
*
1024
;
case
"TBytes"
:
$attrValue
=
$attr
[
'Value'
]
*
1048576
;
# Grab each attribute and add it's details to the database
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Attributes'
]))
{
foreach
(
$params
[
0
][
'Attributes'
]
as
$attr
)
{
# Default value without modifier
$attrValue
=
$attr
[
'Value'
];
if
(
$attr
[
'Name'
]
==
'SMRadius-Capping-Traffic-Limit'
||
$attr
[
'Name'
]
==
'SMRadius-Capping-Uptime-Limit'
)
{
# If modifier is set we need to work out attribute value
if
(
isset
(
$attr
[
'Modifier'
]))
{
switch
(
$attr
[
'Modifier'
])
{
case
"Seconds"
:
$attrValue
=
$attr
[
'Value'
]
/
60
;
case
"Minutes"
:
$attrValue
=
$attr
[
'Value'
];
case
"Hours"
:
$attrValue
=
$attr
[
'Value'
]
*
60
;
case
"Days"
:
$attrValue
=
$attr
[
'Value'
]
*
1440
;
case
"Weeks"
:
$attrValue
=
$attr
[
'Value'
]
*
10080
;
case
"Months"
:
$attrValue
=
$attr
[
'Value'
]
*
44640
;
case
"MBytes"
:
$attrValue
=
$attr
[
'Value'
];
case
"GBytes"
:
$attrValue
=
$attr
[
'Value'
]
*
1024
;
case
"TBytes"
:
$attrValue
=
$attr
[
'Value'
]
*
1048576
;
}
}
}
# Add attribute
$res
=
DBDo
(
"
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)"
,
array
(
$userID
,
$attr
[
'Name'
],
$attr
[
'Operator'
],
$attrValue
)
);
}
}
# Add attribute
$res
=
DBDo
(
"
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)"
,
array
(
$userID
,
$attr
[
'Name'
],
$attr
[
'Operator'
],
$attrValue
)
);
# Link user to groups if any selected
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Groups'
]))
{
$refinedGroups
=
array
();
# Filter out unique group ID's
foreach
(
$params
[
0
][
'Groups'
]
as
$group
)
{
foreach
(
$group
as
$ID
=>
$value
)
{
$refinedGroups
[
$value
]
=
$value
;
}
}
# Loop through groups
foreach
(
$refinedGroups
as
$groupID
)
{
$res
=
DBDo
(
"INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)"
,
array
(
$userID
,
$groupID
));
}
}
}
# Link user to groups if any selected
if
(
$res
!==
FALSE
&&
isset
(
$params
[
0
][
'Groups'
]))
{
$refinedGroups
=
array
();
# We adding multiple users
}
elseif
(
!
empty
(
$params
[
0
][
'Number'
])
&&
$params
[
0
][
'Number'
]
>
1
)
{
$wispUser
=
array
();
# Loop for number of chosen numbers
for
(
$i
=
0
;
$i
<
$params
[
0
][
'Number'
];
$i
++
)
{
# Check for duplicates and add
$usernameReserved
=
1
;
$characters
=
'abcdefghijklmnopqrstuvwxyz0123456789'
;
while
(
$usernameReserved
==
1
)
{
# Generate random username
$string
=
''
;
for
(
$c
=
0
;
$c
<
7
;
$c
++
)
{
$string
.
=
$characters
[
rand
(
0
,
strlen
(
$characters
)
-
1
)];
}
$thisUsername
=
$string
;
# Add prefix to string
if
(
!
empty
(
$params
[
0
][
'Prefix'
]))
{
$thisUsername
=
$params
[
0
][
'Prefix'
]
.
$string
;
}
# Check if username used
$res
=
DBSelect
(
"
SELECT
users.Username
FROM
users
WHERE
users.Username = ?
"
,
array
(
$thisUsername
)
);
# If there are no rows we may continue
if
(
$res
->
rowCount
()
==
0
&&
!
defined
(
$wispUser
[
$thisUsername
]))
{
$usernameReserved
=
0
;
# Generate random username
$string
=
''
;
for
(
$c
=
0
;
$c
<
7
;
$c
++
)
{
$string
.
=
$characters
[
rand
(
0
,
strlen
(
$characters
)
-
1
)];
}
# Filter out unique group ID's
foreach
(
$params
[
0
][
'Groups'
]
as
$group
)
{
foreach
(
$group
as
$ID
=>
$value
)
{
$refinedGroups
[
$value
]
=
$value
;
# Add username and password onto array
$wispUser
[
$thisUsername
]
=
$string
;
}
}
}
# Loop through groups
foreach
(
$refinedGroups
as
$groupID
)
{
$res
=
DBDo
(
"INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)"
,
array
(
$userID
,
$groupID
));
# Insert users from array into database
foreach
(
$wispUser
as
$username
=>
$password
)
{
$res
=
DBDo
(
"INSERT INTO users (Username) VALUES (?)"
,
array
(
$username
));
if
(
$res
!==
FALSE
)
{
$id
=
DBLastInsertID
();
$res
=
DBDo
(
"INSERT INTO user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)"
,
array
(
$id
,
'User-Password'
,
'=='
,
$password
)
);
# Link to wisp users
if
(
$res
!==
FALSE
)
{
$res
=
DBDo
(
"INSERT INTO wisp_userdata (UserID) VALUES (?)"
,
array
(
$id
)
);
}
}
}
}
# Commit changes if all was successful, else
brea
k
# Commit changes if all was successful, else
rollbac
k
if
(
$res
!==
FALSE
)
{
DBCommit
();
return
$res
;
...
...
This diff is collapsed.
Click to expand it.
webgui/js/app/windows/WiSPUsers.js
+
6
−
7
View file @
70f406e9
...
...
@@ -271,7 +271,9 @@ function showWiSPUserAddEditWindow(id) {
'
0:Email,
'
+
'
0:LocationID,
'
+
'
0:Attributes,
'
+
'
0:Groups
'
'
0:Groups,
'
+
'
0:Number,
'
+
'
0:Prefix
'
},
hook
:
function
()
{
...
...
@@ -556,14 +558,14 @@ function showWiSPUserAddEditWindow(id) {
name
:
'
Username
'
,
vtype
:
'
usernamePart
'
,
maskRe
:
usernamePartRe
,
allowBlank
:
fals
e
,
allowBlank
:
tru
e
,
},
{
fieldLabel
:
'
Password
'
,
name
:
'
Password
'
,
vtype
:
'
usernamePart
'
,
maskRe
:
usernamePartRe
,
allowBlank
:
fals
e
,
allowBlank
:
tru
e
,
},
{
xtype
:
'
tabpanel
'
,
...
...
@@ -658,15 +660,12 @@ function showWiSPUserAddEditWindow(id) {
{
fieldLabel
:
'
Prefix
'
,
name
:
'
Prefix
'
,
vtype
:
'
usernamePart
'
,
maskRe
:
usernamePartRe
,
allowBlank
:
true
,
},
{
fieldLabel
:
'
Number
'
,
name
:
'
Number
'
,
vtype
:
'
usernamePart
'
,
maskRe
:
usernamePartRe
,
vtype
:
'
number
'
,
allowBlank
:
true
,
},
]
...
...
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