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
c0ffb4ea
Commit
c0ffb4ea
authored
Jun 23, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ids) add api calls
parent
8e24c804
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
4 deletions
+150
-4
ServiceController.php
...vc/app/controllers/OPNsense/IDS/Api/ServiceController.php
+100
-4
SettingsController.php
...c/app/controllers/OPNsense/IDS/Api/SettingsController.php
+50
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/ServiceController.php
View file @
c0ffb4ea
...
...
@@ -30,6 +30,7 @@ namespace OPNsense\IDS\Api;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Core\Backend
;
use
\OPNsense\IDS\IDS
;
/**
* Class ServiceController
...
...
@@ -37,19 +38,114 @@ use \OPNsense\Core\Backend;
*/
class
ServiceController
extends
ApiControllerBase
{
/**
* start ids service
* @return array
*/
public
function
startAction
()
{
if
(
$this
->
request
->
isPost
())
{
$backend
=
new
Backend
();
$response
=
trim
(
$backend
->
configdRun
(
"ids start"
));
return
array
(
"response"
=>
$response
);
}
else
{
return
array
(
"response"
=>
array
());
}
}
/**
*
* stop ids service
* @return array
*/
public
function
stopAction
()
{
if
(
$this
->
request
->
isPost
())
{
$backend
=
new
Backend
();
$response
=
trim
(
$backend
->
configdRun
(
"ids stop"
));
return
array
(
"response"
=>
$response
);
}
else
{
return
array
(
"response"
=>
array
());
}
}
/**
* restart ids service
* @return array
*/
public
function
restartAction
()
{
if
(
$this
->
request
->
isPost
())
{
$backend
=
new
Backend
();
$response
=
$backend
->
configdRun
(
"ids restart"
);
return
array
(
"response"
=>
$response
);
}
else
{
return
array
(
"response"
=>
array
());
}
}
/**
* retrieve status of squid proxy
* @return array
* @throws \Exception
*/
public
function
statusAction
()
{
$backend
=
new
Backend
();
$mdlIDS
=
new
IDS
();
$response
=
$backend
->
configdRun
(
"ids status"
);
if
(
strpos
(
$response
,
"not running"
)
>
0
)
{
if
((
string
)
$mdlIDS
->
general
->
enabled
==
1
)
{
$status
=
"stopped"
;
}
else
{
$status
=
"disabled"
;
}
}
elseif
(
strpos
(
$response
,
"is running"
)
>
0
)
{
$status
=
"running"
;
}
elseif
((
string
)
$mdlIDS
->
general
->
enabled
==
0
)
{
$status
=
"disabled"
;
}
else
{
$status
=
"unkown"
;
}
return
array
(
"status"
=>
$status
);
}
/**
* reconfigure IDS
*/
public
function
reconfigureAction
()
{
$status
=
"failed"
;
if
(
$this
->
request
->
isPost
())
{
// close session for long running action
$this
->
sessionClose
();
$mdlIDS
=
new
IDS
();
$runStatus
=
$this
->
statusAction
();
if
(
$runStatus
[
'status'
]
==
"running"
&&
(
string
)
$mdlIDS
->
general
->
enabled
==
0
)
{
$this
->
stopAction
();
}
$backend
=
new
Backend
();
$bckresult
=
trim
(
$backend
->
configdRun
(
"template reload OPNsense.IDS"
));
return
array
(
"status"
=>
"failed"
);
if
(
$bckresult
==
"OK"
)
{
$bckresult
=
trim
(
$backend
->
configdRun
(
"ids install rules"
));
if
(
$bckresult
==
"OK"
)
{
if
(
$runStatus
[
'status'
]
==
'running'
)
{
$status
=
$this
->
restartAction
()[
'response'
];
}
else
{
return
array
(
"status"
=>
"failed"
);
$status
=
$this
->
startAction
()[
'response'
];
}
}
else
{
$status
=
"error installing ids rules ("
.
$bckresult
.
")"
;
}
}
else
{
$status
=
"error generating ids template ("
.
$bckresult
.
")"
;
}
}
return
array
(
"status"
=>
$status
);
}
}
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api/SettingsController.php
View file @
c0ffb4ea
...
...
@@ -222,4 +222,54 @@ class SettingsController extends ApiControllerBase
}
return
array
();
}
/**
* retrieve IDS settings
* @return array IDS settings
*/
public
function
getAction
()
{
// define list of configurable settings
$settingsNodes
=
array
(
'general'
);
$result
=
array
();
if
(
$this
->
request
->
isGet
())
{
$mdlIDS
=
new
IDS
();
$result
[
'ids'
]
=
array
();
foreach
(
$settingsNodes
as
$key
)
{
$result
[
'ids'
][
$key
]
=
$mdlIDS
->
$key
->
getNodes
();
}
}
return
$result
;
}
/**
* update IDS settings
* @return array status
*/
public
function
setAction
()
{
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
// load model and update with provided data
$mdlIDS
=
new
IDS
();
$mdlIDS
->
setNodes
(
$this
->
request
->
getPost
(
"ids"
));
// 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
;
}
}
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