Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
372281b3
Commit
372281b3
authored
Jul 01, 2015
by
Jos Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(proxy) add settings controller for remote blacklists
parent
e489669d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
194 additions
and
1 deletion
+194
-1
SettingsController.php
...app/controllers/OPNsense/Proxy/Api/SettingsController.php
+194
-1
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php
View file @
372281b3
<?php
<?php
/**
/**
* Copyright (C) 2015 Deciso B.V.
* Copyright (C) 2015
J. Schellevis -
Deciso B.V.
*
*
* All rights reserved.
* All rights reserved.
*
*
...
@@ -31,6 +31,7 @@ namespace OPNsense\Proxy\Api;
...
@@ -31,6 +31,7 @@ namespace OPNsense\Proxy\Api;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Proxy\Proxy
;
use
\OPNsense\Proxy\Proxy
;
use
\OPNsense\Core\Config
;
use
\OPNsense\Core\Config
;
use
\OPNsense\Base\UIModelGrid
;
/**
/**
* Class SettingsController
* Class SettingsController
...
@@ -89,4 +90,196 @@ class SettingsController extends ApiControllerBase
...
@@ -89,4 +90,196 @@ class SettingsController extends ApiControllerBase
return
$result
;
return
$result
;
}
}
/**
*
* search remote blacklists
* @return array
*/
public
function
searchRemoteBlacklistsAction
()
{
$this
->
sessionClose
();
// fetch query parameters
$itemsPerPage
=
$this
->
request
->
getPost
(
'rowCount'
,
'int'
,
9999
);
$currentPage
=
$this
->
request
->
getPost
(
'current'
,
'int'
,
1
);
$sortBy
=
array
(
"filename"
);
$sortDescending
=
false
;
if
(
$this
->
request
->
hasPost
(
'sort'
)
&&
is_array
(
$this
->
request
->
getPost
(
"sort"
)))
{
$sortBy
=
array_keys
(
$this
->
request
->
getPost
(
"sort"
));
if
(
$this
->
request
->
getPost
(
"sort"
)[
$sortBy
[
0
]]
==
"desc"
)
{
$sortDescending
=
true
;
}
}
$searchPhrase
=
$this
->
request
->
getPost
(
'searchPhrase'
,
'string'
,
''
);
// create model and fetch query resuls
$fields
=
array
(
"enabled"
,
"filename"
,
"url"
,
"description"
);
$mdlProxy
=
new
Proxy
();
$grid
=
new
UIModelGrid
(
$mdlProxy
->
forward
->
acl
->
remoteACLs
->
blacklists
->
blacklist
);
return
$grid
->
fetch
(
$fields
,
$itemsPerPage
,
$currentPage
,
$sortBy
,
$sortDescending
,
$searchPhrase
);
}
/**
* retrieve remote blacklist settings or return defaults
* @param $uuid item unique id
* @return array
*/
public
function
getRemoteBlacklistAction
(
$uuid
=
null
)
{
$mdlProxy
=
new
Proxy
();
if
(
$uuid
!=
null
)
{
$node
=
$mdlProxy
->
getNodeByReference
(
'forward.acl.remoteACLs.blacklists.blacklist.'
.
$uuid
);
if
(
$node
!=
null
)
{
// return node
return
array
(
"blacklist"
=>
$node
->
getNodes
());
}
}
else
{
// generate new node, but don't save to disc
$node
=
$mdlProxy
->
forward
->
acl
->
remoteACLs
->
blacklists
->
blacklist
->
add
();
return
array
(
"blacklist"
=>
$node
->
getNodes
());
}
return
array
();
}
public
function
setRemoteBlacklistAction
(
$uuid
)
{
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
"blacklist"
))
{
$mdlProxy
=
new
Proxy
();
if
(
$uuid
!=
null
)
{
$node
=
$mdlProxy
->
getNodeByReference
(
'forward.acl.remoteACLs.blacklists.blacklist.'
.
$uuid
);
if
(
$node
!=
null
)
{
$result
=
array
(
"result"
=>
"failed"
,
"validations"
=>
array
());
$blacklistInfo
=
$this
->
request
->
getPost
(
"blacklist"
);
$node
->
setNodes
(
$blacklistInfo
);
$valMsgs
=
$mdlProxy
->
performValidation
();
foreach
(
$valMsgs
as
$field
=>
$msg
)
{
$fieldnm
=
str_replace
(
$node
->
__reference
,
"blacklist"
,
$msg
->
getField
());
if
(
$fieldnm
!=
$msg
->
getField
())
{
// only collect validation errors for the item we're currently editing.
$result
[
"validations"
][
$fieldnm
]
=
$msg
->
getMessage
();
}
}
if
(
count
(
$result
[
'validations'
])
==
0
)
{
// we've already performed a validation, prevent issues
// from other items in the model reflecting back to us.
$mdlProxy
->
serializeToConfig
(
$disable_validation
=
true
);
// save config if validated correctly
Config
::
getInstance
()
->
save
();
$result
=
array
(
"result"
=>
"saved"
);
}
return
$result
;
}
}
}
return
array
(
"result"
=>
"failed"
);
}
/**
* add new blacklist and set with attributes from post
* @return array
*/
public
function
addRemoteBlacklistAction
()
{
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
"blacklist"
))
{
$result
=
array
(
"result"
=>
"failed"
,
"validations"
=>
array
());
$mdlProxy
=
new
Proxy
();
$node
=
$mdlProxy
->
forward
->
acl
->
remoteACLs
->
blacklists
->
blacklist
->
Add
();
$node
->
setNodes
(
$this
->
request
->
getPost
(
"blacklist"
));
$valMsgs
=
$mdlProxy
->
performValidation
();
foreach
(
$valMsgs
as
$field
=>
$msg
)
{
$fieldnm
=
str_replace
(
$node
->
__reference
,
"blacklist"
,
$msg
->
getField
());
if
(
$fieldnm
!=
$msg
->
getField
())
{
// only collect validation errors for the item we're currently editing.
$result
[
"validations"
][
$fieldnm
]
=
$msg
->
getMessage
();
}
}
if
(
count
(
$result
[
'validations'
])
==
0
)
{
// we've already performed a validation, prevent issues from
// other items in the model reflecting back to us.
$mdlProxy
->
serializeToConfig
(
$disable_validation
=
true
);
// save config if validated correctly
Config
::
getInstance
()
->
save
();
$result
=
array
(
"result"
=>
"saved"
);
}
return
$result
;
}
return
$result
;
}
/**
* delete blacklist by uuid
* @param $uuid item unique id
* @return array status
*/
public
function
delRemoteBlacklistAction
(
$uuid
)
{
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
$mdlProxy
=
new
Proxy
();
if
(
$uuid
!=
null
)
{
if
(
$mdlProxy
->
forward
->
acl
->
remoteACLs
->
blacklists
->
blacklist
->
del
(
$uuid
))
{
// if item is removed, serialize to config and save
$mdlProxy
->
serializeToConfig
(
$disable_validation
=
true
);
Config
::
getInstance
()
->
save
();
$result
[
'result'
]
=
'deleted'
;
}
else
{
$result
[
'result'
]
=
'not found'
;
}
}
}
return
$result
;
}
/**
* toggle blacklist by uuid (enable/disable)
* @param $uuid item unique id
* @return array status
*/
public
function
toggleRemoteBlacklistAction
(
$uuid
)
{
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
$mdlProxy
=
new
Proxy
();
if
(
$uuid
!=
null
)
{
$node
=
$mdlProxy
->
getNodeByReference
(
'forward.acl.remoteACLs.blacklists.blacklist.'
.
$uuid
);
if
(
$node
!=
null
)
{
if
(
$node
->
enabled
->
__toString
()
==
"1"
)
{
$result
[
'result'
]
=
"Disabled"
;
$node
->
enabled
=
"0"
;
}
else
{
$result
[
'result'
]
=
"Enabled"
;
$node
->
enabled
=
"1"
;
}
// if item has toggled, serialize to config and save
$mdlProxy
->
serializeToConfig
(
$disable_validation
=
true
);
Config
::
getInstance
()
->
save
();
}
}
}
return
$result
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment