Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opentrafficshaper
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
Yuriy
opentrafficshaper
Commits
47b6d585
Commit
47b6d585
authored
11 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Added POST support to users add action
parent
599255fd
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
opentrafficshaper/plugins/webserver/pages/users.pm
+96
-9
96 additions, 9 deletions
opentrafficshaper/plugins/webserver/pages/users.pm
with
96 additions
and
9 deletions
opentrafficshaper/plugins/webserver/pages/users.pm
+
96
−
9
View file @
47b6d585
...
@@ -31,6 +31,11 @@ our (@ISA,@EXPORT,@EXPORT_OK);
...
@@ -31,6 +31,11 @@ our (@ISA,@EXPORT,@EXPORT_OK);
use
DateTime
;
use
DateTime
;
use
HTML::
Entities
;
use
HTTP::
Status
qw( :constants )
;
use
opentrafficshaper::
utils
;
# Sidebar menu options for this module
# Sidebar menu options for this module
...
@@ -48,12 +53,13 @@ my $menu = {
...
@@ -48,12 +53,13 @@ my $menu = {
# Default page/action
# Default page/action
sub
default
sub
default
{
{
my
(
$globals
,
$module
,
$daction
,
$request
)
=
@_
;
my
(
$
kernel
,
$
globals
,
$module
,
$daction
,
$request
)
=
@_
;
# If we not passed default by the main app, just return
# If we not passed default by the main app, just return
return
if
(
$daction
ne
"
default
");
return
if
(
$daction
ne
"
default
");
# Build content
# Build content
my
$content
=
"";
my
$content
=
"";
...
@@ -120,40 +126,121 @@ EOF
...
@@ -120,40 +126,121 @@ EOF
EOF
EOF
return
(
200
,
$content
,
$menu
);
return
(
HTTP_OK
,
$content
,
$menu
);
}
}
# Add action
# Add action
sub
add
sub
add
{
{
my
(
$globals
,
$module
,
$daction
,
$request
)
=
@_
;
my
(
$kernel
,
$globals
,
$module
,
$daction
,
$request
)
=
@_
;
# Errors to display
my
@errors
;
# Form items
my
$params
=
{
'
inputUsername
'
=>
undef
,
'
inputIP
'
=>
undef
,
'
inputLimitTx
'
=>
undef
,
'
inputLimitRx
'
=>
undef
,
};
# If this is a form try parse it
if
(
$request
->
method
eq
"
POST
")
{
# Parse form data
$params
=
parseFormContent
(
$request
->
content
);
# If user pressed cancel, redirect
if
(
defined
(
$params
->
{'
cancel
'}))
{
# Redirects to default page
return
(
HTTP_TEMPORARY_REDIRECT
,'
users
');
}
# Check POST data
my
$username
;
if
(
!
defined
(
$username
=
isUsername
(
$params
->
{'
inputUsername
'})))
{
push
(
@errors
,"
Username is not valid
");
}
my
$ipAddress
;
if
(
!
defined
(
$ipAddress
=
isIP
(
$params
->
{'
inputIP
'})))
{
push
(
@errors
,"
IP address is not valid
");
}
my
$trafficLimitTx
;
if
(
!
defined
(
$trafficLimitTx
=
isNumber
(
$params
->
{'
inputLimitTx
'})))
{
push
(
@errors
,"
Download limit is not valid
");
}
my
$trafficLimitRx
;
if
(
!
defined
(
$trafficLimitRx
=
isNumber
(
$params
->
{'
inputLimitRx
'})))
{
push
(
@errors
,"
Upload limit is not valid
");
}
# If there are no errors we need to push this update
if
(
!
@errors
)
{
# Build user
my
$user
=
{
'
Username
'
=>
$username
,
'
IP
'
=>
$ipAddress
,
'
GroupID
'
=>
1
,
'
ClassID
'
=>
1
,
'
TrafficLimitTx
'
=>
$trafficLimitTx
,
'
TrafficLimitRx
'
=>
$trafficLimitRx
,
'
TrafficLimitTxBurst
'
=>
$trafficLimitTx
,
'
TrafficLimitRxBurst
'
=>
$trafficLimitRx
,
'
Status
'
=>
"
new
",
'
Source
'
=>
"
plugin.webserver.users
",
};
# Throw the change at the config manager
$kernel
->
post
("
configmanager
"
=>
"
process_change
"
=>
$user
);
print
STDERR
"
[WEBSERVER/USERS/ADD] User:
$username
, IP:
$ipAddress
, Group: 1, Class: 2,
"
.
"
Limits:
"
.
prettyUndef
(
$trafficLimitTx
)
.
"
/
"
.
prettyUndef
(
$trafficLimitRx
)
.
"
, Burst:
"
.
prettyUndef
(
$trafficLimitTx
)
.
"
/
"
.
prettyUndef
(
$trafficLimitRx
)
.
"
\n
";
return
(
HTTP_TEMPORARY_REDIRECT
,'
users
');
}
}
# Sanitize params if we need to
foreach
my
$item
(
keys
%
{
$params
})
{
$params
->
{
$item
}
=
defined
(
$params
->
{
$item
})
?
encode_entities
(
$params
->
{
$item
})
:
"";
}
# Build content
# Build content
my
$content
=
"";
my
$content
=
"";
#
H
eader
#
Form h
eader
$content
.=
<<EOF;
$content
.=
<<EOF;
<form class="form-horizontal" method="post">
<form class="form-horizontal" method="post">
<legend>Add Manual User</legend>
<legend>Add Manual User</legend>
EOF
# Spit out errors if we have any
if
(
@errors
>
0
)
{
foreach
my
$error
(
@errors
)
{
$content
.=
'
<div class="alert alert-error">
'
.
$error
.
'
</div>
';
}
}
# Header
$content
.=
<<EOF;
<div class="control-group">
<div class="control-group">
<label class="control-label" for="inputUsername">Username</label>
<label class="control-label" for="inputUsername">Username</label>
<div class="controls">
<div class="controls">
<input name="inputUsername" type="text" placeholder="Username">
<input name="inputUsername" type="text" placeholder="Username"
value="$params->{'inputUsername'}" /
>
</div>
</div>
</div>
</div>
<div class="control-group">
<div class="control-group">
<label class="control-label" for="inputIP">IP Address</label>
<label class="control-label" for="inputIP">IP Address</label>
<div class="controls">
<div class="controls">
<input name="inputIP" type="text" placeholder="IP Address">
<input name="inputIP" type="text" placeholder="IP Address"
value="$params->{'inputIP'}" /
>
</div>
</div>
</div>
</div>
<div class="control-group">
<div class="control-group">
<label class="control-label" for="inputLimitTx">Download Limit</label>
<label class="control-label" for="inputLimitTx">Download Limit</label>
<div class="controls">
<div class="controls">
<div class="input-append">
<div class="input-append">
<input name="inputLimitTx" type="text" class="span5"
id="appendedInput"
placeholder="TX Limit">
<input name="inputLimitTx" type="text" class="span5" placeholder="TX Limit"
value="$params->{'inputLimitTx'}" /
>
<span class="add-on">Kbps<span>
<span class="add-on">Kbps<span>
</div>
</div>
</div>
</div>
...
@@ -162,7 +249,7 @@ sub add
...
@@ -162,7 +249,7 @@ sub add
<label class="control-label" for="inputLimitRx">Upload Limit</label>
<label class="control-label" for="inputLimitRx">Upload Limit</label>
<div class="controls">
<div class="controls">
<div class="input-append">
<div class="input-append">
<input name="inputLimitRx" type="text" class="span5"
id="appendedInput"
placeholder="RX Limit">
<input name="inputLimitRx" type="text" class="span5" placeholder="RX Limit"
value="$params->{'inputLimitRx'}" /
>
<span class="add-on">Kbps<span>
<span class="add-on">Kbps<span>
</div>
</div>
</div>
</div>
...
@@ -170,7 +257,7 @@ sub add
...
@@ -170,7 +257,7 @@ sub add
<div class="control-group">
<div class="control-group">
<div class="controls">
<div class="controls">
<button type="submit" class="btn btn-primary">Add</button>
<button type="submit" class="btn btn-primary">Add</button>
<button type="submit" class="btn">Cancel</button>
<button
name="cancel"
type="submit" class="btn">Cancel</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
...
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