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
834a23d0
Commit
834a23d0
authored
Jun 30, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ids) add ruleset to model and ui
parent
410493eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
2 deletions
+159
-2
SettingsController.php
...c/app/controllers/OPNsense/IDS/Api/SettingsController.php
+65
-2
IDS.php
src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php
+25
-0
IDS.xml
src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml
+12
-0
index.volt
src/opnsense/mvc/app/views/OPNsense/IDS/index.volt
+57
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php
View file @
834a23d0
...
...
@@ -210,6 +210,69 @@ class SettingsController extends ApiControllerBase
}
}
/**
* list all installable rules including current status
* @return array|mixed
* @throws \Exception
*/
public
function
listInstallableRulesetsAction
()
{
$backend
=
new
Backend
();
$response
=
$backend
->
configdRun
(
"ids list installablerulesets"
);
$data
=
json_decode
(
$response
,
true
);
if
(
$data
!=
null
&&
array_key_exists
(
"items"
,
$data
))
{
$result
=
array
(
"items"
=>
array
());
foreach
(
$data
[
'items'
]
as
$filename
=>
$fileinfo
)
{
$item
=
array
();
$item
[
'description'
]
=
$fileinfo
[
'description'
];
$item
[
'filename'
]
=
$fileinfo
[
'filename'
];
// retrieve status from model
$item
[
'enabled'
]
=
(
string
)
$this
->
getModel
()
->
getFileNode
(
$fileinfo
[
'filename'
])
->
enabled
;
$result
[
'rows'
][]
=
$item
;
}
$result
[
'rowCount'
]
=
count
(
$result
[
'rows'
]);
$result
[
'total'
]
=
count
(
$result
[
'rows'
]);
$result
[
'current'
]
=
1
;
return
$result
;
}
else
{
return
array
();
}
}
/**
* toggle usage of rule file or set enabled / disabled depending on parameters
* @param $filename (target) rule file name
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status 0/1 or error
* @throws \Exception
* @throws \Phalcon\Validation\Exception
*/
public
function
toggleInstalledRulesetAction
(
$filename
,
$enabled
=
null
)
{
$result
=
array
(
"status"
=>
"none"
);
if
(
$this
->
request
->
isPost
())
{
$backend
=
new
Backend
();
$response
=
$backend
->
configdRun
(
"ids list installablerulesets"
);
$data
=
json_decode
(
$response
,
true
);
if
(
$data
!=
null
&&
array_key_exists
(
"items"
,
$data
)
&&
array_key_exists
(
$filename
,
$data
[
'items'
]))
{
$node
=
$this
->
getModel
()
->
getFileNode
(
$filename
);
if
(
$enabled
==
"0"
||
$enabled
==
"1"
)
{
$node
->
enabled
=
(
string
)
$enabled
;
}
elseif
((
string
)
$node
->
enabled
==
"1"
)
{
$node
->
enabled
=
"0"
;
}
else
{
$node
->
enabled
=
"1"
;
}
$result
[
'status'
]
=
$node
->
enabled
;
$this
->
getModel
()
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
}
else
{
$result
[
'status'
]
=
"error"
;
}
}
return
$result
;
}
/**
* toggle rule enable status
* @param $sid
...
...
@@ -243,7 +306,7 @@ class SettingsController extends ApiControllerBase
$settingsNodes
=
array
(
'general'
);
$result
=
array
();
if
(
$this
->
request
->
isGet
())
{
$mdlIDS
=
new
IDS
();
$mdlIDS
=
$this
->
getModel
();
$result
[
'ids'
]
=
array
();
foreach
(
$settingsNodes
as
$key
)
{
$result
[
'ids'
][
$key
]
=
$mdlIDS
->
$key
->
getNodes
();
...
...
@@ -261,7 +324,7 @@ class SettingsController extends ApiControllerBase
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
// load model and update with provided data
$mdlIDS
=
new
IDS
();
$mdlIDS
=
$this
->
getModel
();
$mdlIDS
->
setNodes
(
$this
->
request
->
getPost
(
"ids"
));
// perform validation
...
...
src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php
View file @
834a23d0
...
...
@@ -32,8 +32,14 @@ use OPNsense\Base\BaseModel;
class
IDS
extends
BaseModel
{
/**
* @var array internal list of all sid's in this object
*/
private
$sid_list
=
array
();
/**
* update internal cache of sid's
*/
private
function
updateSIDlist
()
{
if
(
count
(
$this
->
sid_list
)
==
0
)
{
...
...
@@ -111,4 +117,23 @@ class IDS extends BaseModel
}
}
/**
* retrieve (rule) file entry from config or add a new one
* @param string $filename list of filename to merge into config
* @return BaseField number of appended items
*/
public
function
getFileNode
(
$filename
)
{
foreach
(
$this
->
files
->
file
->
__items
as
$NodeKey
=>
$NodeValue
)
{
if
(
$filename
==
$NodeValue
->
filename
)
{
return
$NodeValue
;
}
}
// add a new node
$node
=
$this
->
files
->
file
->
Add
();
$node
->
filename
=
$filename
;
return
$node
;
}
}
src/opnsense/mvc/app/models/OPNsense/IDS/IDS.xml
View file @
834a23d0
...
...
@@ -16,6 +16,18 @@
</enabled>
</rule>
</rules>
<files>
<file
type=
"ArrayField"
>
<filename
type=
"TextField"
>
<Required>
Y
</Required>
<Mask>
/^(.){1,255}$/
</Mask>
</filename>
<enabled
type=
"BooleanField"
>
<default>
0
</default>
<Required>
Y
</Required>
</enabled>
</file>
</files>
<general>
<enabled
type=
"BooleanField"
>
<default>
0
</default>
...
...
src/opnsense/mvc/app/views/OPNsense/IDS/index.volt
View file @
834a23d0
...
...
@@ -97,6 +97,9 @@ POSSIBILITY OF SUCH DAMAGE.
return request;
}
/**
* grid installed rules
*/
$("#grid-installedrules").UIBootgrid(
{ search:'/api/ids/settings/searchinstalledrules',
get:'/api/ids/settings/getRuleInfo/',
...
...
@@ -120,6 +123,9 @@ POSSIBILITY OF SUCH DAMAGE.
}
);
/**
* grid query alerts
*/
$("#grid-alerts").UIBootgrid(
{ search:'/api/ids/service/queryAlerts',
get:'/api/ids/service/getAlertInfo/',
...
...
@@ -135,6 +141,29 @@ POSSIBILITY OF SUCH DAMAGE.
}
});
/**
* grid for installable rule files
*/
$("#grid-rule-files").UIBootgrid(
{ search:'/api/ids/settings/listInstallableRulesets',
toggle:'/api/ids/settings/toggleInstalledRuleset/',
options:{
multiSelect:false,
selection:false,
navigation:0,
formatters:{
rowtoggle: function (column, row) {
if (parseInt(row[column.id], 2) == 1) {
var toggle = "<span style=\"cursor: pointer;\" class=\"fa fa-check-square-o command-toggle\" data-value=\"1\" data-row-id=\"" + row.filename + "\"></span>";
} else {
var toggle = "<span style=\"cursor: pointer;\" class=\"fa fa-square-o command-toggle\" data-value=\"0\" data-row-id=\"" + row.filename + "\"></span>";
}
return toggle;
}
}
}
});
/*************************************************************************************************************
* Commands
*************************************************************************************************************/
...
...
@@ -174,6 +203,34 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="tab-content content-box tab-content">
<div id="settings" class="tab-pane fade in active">
{{ partial("layout_partials/base_form",['fields':formGeneralSettings,'id':'frm_GeneralSettings'])}}
<!-- add installable rule files -->
<table class="table table-striped table-condensed table-responsive">
<colgroup>
<col class="col-md-3"/>
<col class="col-md-9"/>
</colgroup>
<tbody>
<tr>
<td><div class="control-label">
<i class="fa fa-info-circle text-muted"></i>
<b>rulesets</b>
</div>
</td>
<td>
<table id="grid-rule-files" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogRule">
<thead>
<tr>
<th data-column-id="enabled" data-formatter="rowtoggle" data-sortable="false" data-width="10em">enabled</th>
<th data-column-id="filename" data-type="string" data-visible="true" data-identifier="true">filename</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<div id="rules" class="tab-pane fade in">
<div class="bootgrid-header container-fluid">
...
...
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