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
63db313c
Commit
63db313c
authored
Jul 29, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ids) add multi toggle for multiple items at once
parent
558b3033
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
26 deletions
+57
-26
SettingsController.php
...c/app/controllers/OPNsense/IDS/Api/SettingsController.php
+57
-26
No files found.
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php
View file @
63db313c
...
@@ -249,19 +249,21 @@ class SettingsController extends ApiControllerBase
...
@@ -249,19 +249,21 @@ class SettingsController extends ApiControllerBase
/**
/**
* toggle usage of rule file or set enabled / disabled depending on parameters
* toggle usage of rule file or set enabled / disabled depending on parameters
* @param $filename
(target) rule file name
* @param $filename
s (target) rule file name, or list of filenames separated by a comma
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status 0/1 or error
* @return array status 0/1 or error
* @throws \Exception
* @throws \Exception
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Validation\Exception
*/
*/
public
function
toggleInstalledRulesetAction
(
$filename
,
$enabled
=
null
)
public
function
toggleInstalledRulesetAction
(
$filename
s
,
$enabled
=
null
)
{
{
$update_count
=
0
;
$result
=
array
(
"status"
=>
"none"
);
$result
=
array
(
"status"
=>
"none"
);
if
(
$this
->
request
->
isPost
())
{
if
(
$this
->
request
->
isPost
())
{
$backend
=
new
Backend
();
$backend
=
new
Backend
();
$response
=
$backend
->
configdRun
(
"ids list installablerulesets"
);
$response
=
$backend
->
configdRun
(
"ids list installablerulesets"
);
$data
=
json_decode
(
$response
,
true
);
$data
=
json_decode
(
$response
,
true
);
foreach
(
explode
(
","
,
$filenames
)
as
$filename
)
{
if
(
$data
!=
null
&&
array_key_exists
(
"items"
,
$data
)
&&
array_key_exists
(
$filename
,
$data
[
'items'
]))
{
if
(
$data
!=
null
&&
array_key_exists
(
"items"
,
$data
)
&&
array_key_exists
(
$filename
,
$data
[
'items'
]))
{
$node
=
$this
->
getModel
()
->
getFileNode
(
$filename
);
$node
=
$this
->
getModel
()
->
getFileNode
(
$filename
);
if
(
$enabled
==
"0"
||
$enabled
==
"1"
)
{
if
(
$enabled
==
"0"
||
$enabled
==
"1"
)
{
...
@@ -271,36 +273,65 @@ class SettingsController extends ApiControllerBase
...
@@ -271,36 +273,65 @@ class SettingsController extends ApiControllerBase
}
else
{
}
else
{
$node
->
enabled
=
"1"
;
$node
->
enabled
=
"1"
;
}
}
// only update result state if all items until now are ok
if
(
$result
[
'status'
]
!=
'error'
)
{
$result
[
'status'
]
=
$node
->
enabled
;
$result
[
'status'
]
=
$node
->
enabled
;
$this
->
getModel
()
->
serializeToConfig
();
}
Config
::
getInstance
()
->
save
()
;
$update_count
++
;
}
else
{
}
else
{
$result
[
'status'
]
=
"error"
;
$result
[
'status'
]
=
"error"
;
}
}
}
}
if
(
$update_count
>
0
)
{
$this
->
getModel
()
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
}
}
return
$result
;
return
$result
;
}
}
/**
/**
* toggle rule enable status
* toggle rule enable status
* @param $sid
* @param $sids
* @return array
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array empty
*/
*/
public
function
toggleRuleAction
(
$sid
)
public
function
toggleRuleAction
(
$sid
s
,
$enabled
=
null
)
{
{
if
(
$this
->
request
->
isPost
())
{
$update_count
=
0
;
foreach
(
explode
(
","
,
$sids
)
as
$sid
)
{
$ruleinfo
=
$this
->
getRuleInfoAction
(
$sid
);
$ruleinfo
=
$this
->
getRuleInfoAction
(
$sid
);
if
(
count
(
$ruleinfo
)
>
0
)
{
if
(
count
(
$ruleinfo
)
>
0
)
{
if
(
$ruleinfo
[
'enabled_default'
]
!=
$ruleinfo
[
'enabled'
])
{
if
(
$enabled
==
null
)
{
// toggle state
if
(
$ruleinfo
[
'enabled'
]
==
1
)
{
$new_state
=
0
;
}
else
{
$new_state
=
1
;
}
}
elseif
(
$enabled
==
1
)
{
$new_state
=
1
;
}
else
{
$new_state
=
0
;
}
if
(
$ruleinfo
[
'enabled_default'
]
==
$new_state
)
{
// if we're switching back to default, remove alter rule
// if we're switching back to default, remove alter rule
$this
->
getModel
()
->
removeRule
(
$sid
)
;
$this
->
getModel
()
->
removeRule
(
$sid
)
;
}
elseif
(
$ruleinfo
[
'enabled'
]
==
1
)
{
}
elseif
(
$new_state
==
1
)
{
$this
->
getModel
()
->
disableRule
(
$sid
)
;
$this
->
getModel
()
->
enableRule
(
$sid
)
;
}
else
{
}
else
{
$this
->
getModel
()
->
enableRule
(
$sid
)
;
$this
->
getModel
()
->
disableRule
(
$sid
);
}
$update_count
++
;
}
}
}
if
(
$update_count
>
0
)
{
$this
->
getModel
()
->
serializeToConfig
();
$this
->
getModel
()
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
Config
::
getInstance
()
->
save
();
}
}
}
return
array
();
return
array
();
}
}
...
...
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