Commit bd2ca802 authored by Ad Schellevis's avatar Ad Schellevis

(IDS) add ips rule actions to model

parent 708a1d01
...@@ -42,7 +42,12 @@ class IDS extends BaseModel ...@@ -42,7 +42,12 @@ class IDS extends BaseModel
private $sid_list = array(); private $sid_list = array();
/** /**
* update internal cache of sid's * @var array internal list of all known actions (key/value)
*/
private $action_list = array();
/**
* update internal cache of sid's and actions
*/ */
private function updateSIDlist() private function updateSIDlist()
{ {
...@@ -50,12 +55,14 @@ class IDS extends BaseModel ...@@ -50,12 +55,14 @@ class IDS extends BaseModel
foreach ($this->rules->rule->__items as $NodeKey => $NodeValue) { foreach ($this->rules->rule->__items as $NodeKey => $NodeValue) {
$this->sid_list[$NodeValue->sid->__toString()] = $NodeValue; $this->sid_list[$NodeValue->sid->__toString()] = $NodeValue;
} }
// list of known actions and defaults
$this->action_list = $this->rules->rule->getTemplateNode()->action->getNodeData();
} }
} }
/** /**
* get new or existing rule * get new or existing rule
* @param $sid * @param string $sid unique id
* @return mixed * @return mixed
*/ */
private function getRule($sid) private function getRule($sid)
...@@ -71,7 +78,7 @@ class IDS extends BaseModel ...@@ -71,7 +78,7 @@ class IDS extends BaseModel
/** /**
* enable rule * enable rule
* @param $sid * @param string $sid unique id
*/ */
public function enableRule($sid) public function enableRule($sid)
{ {
...@@ -81,7 +88,7 @@ class IDS extends BaseModel ...@@ -81,7 +88,7 @@ class IDS extends BaseModel
/** /**
* disable rule * disable rule
* @param $sid * @param string $sid unique id
*/ */
public function disableRule($sid) public function disableRule($sid)
{ {
...@@ -89,9 +96,19 @@ class IDS extends BaseModel ...@@ -89,9 +96,19 @@ class IDS extends BaseModel
$rule->enabled = "0"; $rule->enabled = "0";
} }
/**
* set new action for selected rule
* @param string $sid unique id
*/
public function setAction($sid, $action)
{
$rule = $this->getRule($sid);
$rule->action = $action;
}
/** /**
* remove rule by sid * remove rule by sid
* @param $sid * @param string $sid unique id
*/ */
public function removeRule($sid) public function removeRule($sid)
{ {
...@@ -107,8 +124,8 @@ class IDS extends BaseModel ...@@ -107,8 +124,8 @@ class IDS extends BaseModel
/** /**
* retrieve current altered rule status * retrieve current altered rule status
* @param $sid * @param string $sid unique id
* @param $default default value * @param string $default default value
* @return default, 0, 1 ( default, true, false) * @return default, 0, 1 ( default, true, false)
*/ */
public function getRuleStatus($sid, $default) public function getRuleStatus($sid, $default)
...@@ -119,7 +136,51 @@ class IDS extends BaseModel ...@@ -119,7 +136,51 @@ class IDS extends BaseModel
} else { } else {
return $default; return $default;
} }
}
/**
* retrieve current (altered) rule action
* @param string $sid unique id
* @param string $default default value
* @param bool $response_plain response as text ot model (select list)
* @return default, <action value> ( default, true, false)
*/
public function getRuleAction($sid, $default, $response_plain = false)
{
$this->updateSIDlist();
if (array_key_exists($sid, $this->sid_list)) {
if (!$response_plain) {
return $this->sid_list[$sid]->action->getNodeData();
} else {
$act = (string)$this->sid_list[$sid]->action;
if (array_key_exists($act, $this->action_list)) {
return $this->action_list[$act]['value'];
} else {
return $act;
}
}
} elseif (!$response_plain) {
// generate selection for new field
$default_types = $this->action_list ;
if ( array_key_exists($default, $default_types)) {
foreach ($default_types as $key => $value) {
if ($key == $default) {
$default_types[$key]['selected'] = 1;
} else {
$default_types[$key]['selected'] = 0;
}
}
}
// select default
return $default_types;
} else {
// return plaintext default
if (array_key_exists($default, $this->action_list)) {
return $this->action_list[$default]['value'];
} else {
return $default;
}
}
} }
/** /**
......
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
<default>1</default> <default>1</default>
<Required>Y</Required> <Required>Y</Required>
</enabled> </enabled>
<action type="OptionField">
<Required>Y</Required>
<default>alert</default>
<OptionValues>
<alert>Alert</alert>
<drop>Drop</drop>
</OptionValues>
</action>
</rule> </rule>
</rules> </rules>
<files> <files>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment