@@ -23,103 +23,103 @@ |
||
23 | 23 | */ |
24 | 24 | class NetworkRule extends PluginTemplate |
25 | 25 | { |
26 | - /** @var string $description Description of plugin */ |
|
27 | - public $description='Network functions to use into rules'; |
|
26 | + /** @var string $description Description of plugin */ |
|
27 | + public $description='Network functions to use into rules'; |
|
28 | 28 | |
29 | - /** @var array[] $functions Functions of this plugin for rule eval. |
|
30 | - * If no functions are declared, set to empty array |
|
31 | - * $functions[<name>]['function'] : Name of the function to be called in this class |
|
32 | - * $functions[<name>]['params'] : Description of input parameters of function. |
|
33 | - * $functions[<name>]['description'] : Description. Can be multiline. |
|
34 | - */ |
|
35 | - public $functions=array( |
|
36 | - 'inNetwork' => array( // The name of the function in rules |
|
37 | - 'function' => 'isInNetwork', // Name of the function |
|
38 | - 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
39 | - 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
29 | + /** @var array[] $functions Functions of this plugin for rule eval. |
|
30 | + * If no functions are declared, set to empty array |
|
31 | + * $functions[<name>]['function'] : Name of the function to be called in this class |
|
32 | + * $functions[<name>]['params'] : Description of input parameters of function. |
|
33 | + * $functions[<name>]['description'] : Description. Can be multiline. |
|
34 | + */ |
|
35 | + public $functions=array( |
|
36 | + 'inNetwork' => array( // The name of the function in rules |
|
37 | + 'function' => 'isInNetwork', // Name of the function |
|
38 | + 'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description |
|
39 | + 'description' => 'Test if IP is in network, ex : __inNetwork(192.168.123.5,192.168.123.0,24) returns true |
|
40 | 40 | Does not work with IPV6' // Description (can be multiline). |
41 | - ), |
|
42 | - 'test' => array( // The name of the function in rules |
|
43 | - 'function' => 'testParam', // Name of the function |
|
44 | - 'params' => '<boolean to return as string>', // parameters description |
|
45 | - 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
46 | - ) |
|
47 | - ); |
|
41 | + ), |
|
42 | + 'test' => array( // The name of the function in rules |
|
43 | + 'function' => 'testParam', // Name of the function |
|
44 | + 'params' => '<boolean to return as string>', // parameters description |
|
45 | + 'description' => 'Returns value passed as argument' // Description (can be multiline). |
|
46 | + ) |
|
47 | + ); |
|
48 | 48 | |
49 | - /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
50 | - public $catchAllTraps=false; |
|
49 | + /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin NOT IMPLEMENTED */ |
|
50 | + public $catchAllTraps=false; |
|
51 | 51 | |
52 | - /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
53 | - public $processTraps=false; |
|
52 | + /** @var boolean $processTraps Set to true if plugins can handle traps NOT IMPLEMENTED */ |
|
53 | + public $processTraps=false; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Constructor. Can throw exceptions on error, but no logging at this point. |
|
57 | - * @throws \Exception |
|
58 | - * @return \Trapdirector\Plugins\NetworkRule |
|
59 | - */ |
|
60 | - function __construct() |
|
61 | - { |
|
62 | - $this->name=basename(__FILE__,'.php'); |
|
63 | - return $this; |
|
64 | - } |
|
55 | + /** |
|
56 | + * Constructor. Can throw exceptions on error, but no logging at this point. |
|
57 | + * @throws \Exception |
|
58 | + * @return \Trapdirector\Plugins\NetworkRule |
|
59 | + */ |
|
60 | + function __construct() |
|
61 | + { |
|
62 | + $this->name=basename(__FILE__,'.php'); |
|
63 | + return $this; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Function called by trapdirector if found in rules |
|
68 | - * Parameters check has to be done in function. |
|
69 | - * @param array $params Function parameters |
|
70 | - * @throws Exception |
|
71 | - * @return bool Evaluation |
|
72 | - */ |
|
73 | - public function isInNetwork(array $params) : bool |
|
74 | - { |
|
75 | - // Check param numbers and thrown exception if not correct. |
|
76 | - if (count($params)!=3) |
|
77 | - { |
|
78 | - throw new Exception('Invalid number of parameters : ' . count($params)); |
|
79 | - } |
|
66 | + /** |
|
67 | + * Function called by trapdirector if found in rules |
|
68 | + * Parameters check has to be done in function. |
|
69 | + * @param array $params Function parameters |
|
70 | + * @throws Exception |
|
71 | + * @return bool Evaluation |
|
72 | + */ |
|
73 | + public function isInNetwork(array $params) : bool |
|
74 | + { |
|
75 | + // Check param numbers and thrown exception if not correct. |
|
76 | + if (count($params)!=3) |
|
77 | + { |
|
78 | + throw new Exception('Invalid number of parameters : ' . count($params)); |
|
79 | + } |
|
80 | 80 | |
81 | - $ip = $params[0]; |
|
82 | - $net = $params[1]; |
|
83 | - $masq = $params[2]; |
|
81 | + $ip = $params[0]; |
|
82 | + $net = $params[1]; |
|
83 | + $masq = $params[2]; |
|
84 | 84 | |
85 | 85 | |
86 | - $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
86 | + $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG); |
|
87 | 87 | |
88 | - $ip2 = ip2long($ip); |
|
89 | - $net2 = ip2long($net); |
|
88 | + $ip2 = ip2long($ip); |
|
89 | + $net2 = ip2long($net); |
|
90 | 90 | |
91 | - if ($ip2 === false ) |
|
92 | - { |
|
93 | - $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
94 | - throw new Exception('Invalid IP'); |
|
95 | - } |
|
96 | - if ($net2 === false) |
|
97 | - { |
|
98 | - $this->log('Invalid network',WARN); |
|
99 | - throw new Exception('Invalid net'); |
|
100 | - } |
|
101 | - if ($masq<1 || $masq > 32) |
|
102 | - { |
|
103 | - $this->log('Invalid masq',WARN); |
|
104 | - throw new Exception('Invalid net masq'); |
|
105 | - } |
|
106 | - // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
91 | + if ($ip2 === false ) |
|
92 | + { |
|
93 | + $this->log('Invalid IP : #' . $ip.'#',WARN); |
|
94 | + throw new Exception('Invalid IP'); |
|
95 | + } |
|
96 | + if ($net2 === false) |
|
97 | + { |
|
98 | + $this->log('Invalid network',WARN); |
|
99 | + throw new Exception('Invalid net'); |
|
100 | + } |
|
101 | + if ($masq<1 || $masq > 32) |
|
102 | + { |
|
103 | + $this->log('Invalid masq',WARN); |
|
104 | + throw new Exception('Invalid net masq'); |
|
105 | + } |
|
106 | + // $range is in IP/CIDR format eg 127.0.0.1/24 |
|
107 | 107 | |
108 | - $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
109 | - $masq = ~ $masq; |
|
110 | - return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
108 | + $masq = pow( 2, ( 32 - $masq ) ) - 1; |
|
109 | + $masq = ~ $masq; |
|
110 | + return ( ( $ip2 & $masq ) == ( $net2 & $masq ) ); |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - public function testParam(array $param) |
|
115 | - { |
|
116 | - if (count($param)!=1) |
|
117 | - { |
|
118 | - throw new Exception('Invalid number of parameters : ' . count($param)); |
|
119 | - } |
|
120 | - if ($param[0] == 'true') return true; |
|
121 | - return false; |
|
122 | - } |
|
114 | + public function testParam(array $param) |
|
115 | + { |
|
116 | + if (count($param)!=1) |
|
117 | + { |
|
118 | + throw new Exception('Invalid number of parameters : ' . count($param)); |
|
119 | + } |
|
120 | + if ($param[0] == 'true') return true; |
|
121 | + return false; |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 |