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
b6d26dee
Commit
b6d26dee
authored
Nov 19, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(IDS) add rule action to API
parent
8cb86cc7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
3 deletions
+50
-3
SettingsController.php
...c/app/controllers/OPNsense/IDS/Api/SettingsController.php
+50
-3
No files found.
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php
View file @
b6d26dee
...
@@ -122,6 +122,7 @@ class SettingsController extends ApiControllerBase
...
@@ -122,6 +122,7 @@ class SettingsController extends ApiControllerBase
foreach
(
$result
[
'rows'
]
as
&
$row
)
{
foreach
(
$result
[
'rows'
]
as
&
$row
)
{
$row
[
'enabled_default'
]
=
$row
[
'enabled'
];
$row
[
'enabled_default'
]
=
$row
[
'enabled'
];
$row
[
'enabled'
]
=
$this
->
getModel
()
->
getRuleStatus
(
$row
[
'sid'
],
$row
[
'enabled'
]);
$row
[
'enabled'
]
=
$this
->
getModel
()
->
getRuleStatus
(
$row
[
'sid'
],
$row
[
'enabled'
]);
$row
[
'action'
]
=
$this
->
getModel
()
->
getRuleAction
(
$row
[
'sid'
],
$row
[
'action'
],
true
);
}
}
$result
[
'rowCount'
]
=
count
(
$result
[
'rows'
]);
$result
[
'rowCount'
]
=
count
(
$result
[
'rows'
]);
...
@@ -155,7 +156,9 @@ class SettingsController extends ApiControllerBase
...
@@ -155,7 +156,9 @@ class SettingsController extends ApiControllerBase
$row
=
$data
[
'rows'
][
0
];
$row
=
$data
[
'rows'
][
0
];
// set current enable status (default + registered offset)
// set current enable status (default + registered offset)
$row
[
'enabled_default'
]
=
$row
[
'enabled'
];
$row
[
'enabled_default'
]
=
$row
[
'enabled'
];
$row
[
'action_default'
]
=
$row
[
'action'
];
$row
[
'enabled'
]
=
$this
->
getModel
()
->
getRuleStatus
(
$row
[
'sid'
],
$row
[
'enabled'
]);
$row
[
'enabled'
]
=
$this
->
getModel
()
->
getRuleStatus
(
$row
[
'sid'
],
$row
[
'enabled'
]);
$row
[
'action'
]
=
$this
->
getModel
()
->
getRuleAction
(
$row
[
'sid'
],
$row
[
'action'
]);
//
//
if
(
isset
(
$row
[
'reference'
])
&&
$row
[
'reference'
]
!=
''
)
{
if
(
isset
(
$row
[
'reference'
])
&&
$row
[
'reference'
]
!=
''
)
{
// browser friendly reference data
// browser friendly reference data
...
@@ -297,8 +300,8 @@ class SettingsController extends ApiControllerBase
...
@@ -297,8 +300,8 @@ class SettingsController extends ApiControllerBase
/**
/**
* toggle rule enable status
* toggle rule enable status
* @param
$sids
* @param
string $sids unique id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @param
string|int
$enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array empty
* @return array empty
*/
*/
public
function
toggleRuleAction
(
$sids
,
$enabled
=
null
)
public
function
toggleRuleAction
(
$sids
,
$enabled
=
null
)
...
@@ -321,7 +324,10 @@ class SettingsController extends ApiControllerBase
...
@@ -321,7 +324,10 @@ class SettingsController extends ApiControllerBase
$new_state
=
0
;
$new_state
=
0
;
}
}
if
(
$ruleinfo
[
'enabled_default'
]
==
$new_state
)
{
if
(
$ruleinfo
[
'enabled_default'
]
==
$new_state
&&
array_key_exists
(
$ruleinfo
[
'action_default'
],
$ruleinfo
[
'action'
])
&&
$ruleinfo
[
'action'
][
$ruleinfo
[
'action_default'
]][
'selected'
]
==
1
)
{
// 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
(
$new_state
==
1
)
{
}
elseif
(
$new_state
==
1
)
{
...
@@ -340,6 +346,47 @@ class SettingsController extends ApiControllerBase
...
@@ -340,6 +346,47 @@ class SettingsController extends ApiControllerBase
return
array
();
return
array
();
}
}
/**
* set rule action
* @param $sid item unique id
* @return array
*/
public
function
setRuleAction
(
$sid
)
{
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
"action"
))
{
$ruleinfo
=
$this
->
getRuleInfoAction
(
$sid
);
$newAction
=
$this
->
request
->
getPost
(
"action"
,
"striptags"
,
null
);
if
(
count
(
$ruleinfo
)
>
0
)
{
$mdlIDS
=
$this
->
getModel
();
if
(
$ruleinfo
[
'enabled_default'
]
==
$ruleinfo
[
'enabled'
]
&&
$ruleinfo
[
'action_default'
]
==
$newAction
)
{
// if we're switching back to default, remove alter rule
$mdlIDS
->
removeRule
(
$sid
);
}
else
{
$mdlIDS
->
setAction
(
$sid
,
$newAction
);
}
// perform validation
$valMsgs
=
$mdlIDS
->
performValidation
();
foreach
(
$valMsgs
as
$field
=>
$msg
)
{
if
(
!
array_key_exists
(
"validations"
,
$result
))
{
$result
[
"validations"
]
=
array
();
}
$result
[
"validations"
][
"ids."
.
$msg
->
getField
()]
=
$msg
->
getMessage
();
}
// serialize model to config and save
if
(
$valMsgs
->
count
()
==
0
)
{
$mdlIDS
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
$result
[
"result"
]
=
"saved"
;
}
}
}
return
$result
;
}
/**
/**
* retrieve IDS settings
* retrieve IDS settings
* @return array IDS settings
* @return array IDS settings
...
...
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