@@ -72,7 +72,9 @@ |
||
72 | 72 | function get_string_between($string, $start, $end){ |
73 | 73 | $string = " ".$string; |
74 | 74 | $ini = strpos($string,$start); |
75 | - if ($ini == 0) return ""; |
|
75 | + if ($ini == 0) { |
|
76 | + return ""; |
|
77 | + } |
|
76 | 78 | $ini += strlen($start); |
77 | 79 | $len = strpos($string,$end,$ini) - $ini; |
78 | 80 | return substr($string,$ini,$len); |
@@ -7,50 +7,50 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // only from cli |
10 | -if (php_sapi_name() != "cli") { die("Cli only!"); } |
|
10 | +if (php_sapi_name () != "cli") { die("Cli only!"); } |
|
11 | 11 | |
12 | 12 | |
13 | 13 | // search for all translated words and put them to array |
14 | -$untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && grep -r '_(' * ")); |
|
14 | +$untranslated = explode ("\n", shell_exec ("cd ".dirname (__FILE__)."/../../ && grep -r '_(' * ")); |
|
15 | 15 | // loop and search |
16 | 16 | foreach ($untranslated as $u) { |
17 | 17 | // find string |
18 | - $str = get_string_between($u, "_('", "')"); |
|
18 | + $str = get_string_between ($u, "_('", "')"); |
|
19 | 19 | // remove "" and ' |
20 | - $str = trim($str, "',\""); |
|
20 | + $str = trim ($str, "',\""); |
|
21 | 21 | // search for invalud content and remove |
22 | - if (substr($str, 0, 1)!="$") { |
|
22 | + if (substr ($str, 0, 1) != "$") { |
|
23 | 23 | $all_translations[] = $str; |
24 | 24 | } |
25 | 25 | |
26 | 26 | // find string |
27 | - $str = get_string_between($u, '_("', '")'); |
|
27 | + $str = get_string_between ($u, '_("', '")'); |
|
28 | 28 | // remove "" and ' |
29 | - $str = trim($str, "',\""); |
|
29 | + $str = trim ($str, "',\""); |
|
30 | 30 | // search for invalud content and remove |
31 | - if (substr($str, 0, 1)!="$") { |
|
31 | + if (substr ($str, 0, 1) != "$") { |
|
32 | 32 | $all_translations[] = $str; |
33 | 33 | } |
34 | 34 | } |
35 | 35 | //unique |
36 | -$all_translations = array_unique($all_translations); |
|
36 | +$all_translations = array_unique ($all_translations); |
|
37 | 37 | |
38 | 38 | |
39 | 39 | // search all existing translations |
40 | -$untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && more functions/locale/en/LC_MESSAGES/phpipam.po")); |
|
40 | +$untranslated = explode ("\n", shell_exec ("cd ".dirname (__FILE__)."/../../ && more functions/locale/en/LC_MESSAGES/phpipam.po")); |
|
41 | 41 | // loop and create |
42 | 42 | foreach ($untranslated as $u) { |
43 | 43 | // search for string |
44 | - if (substr($u, 0, 7)=='msgid "') { |
|
45 | - $u = str_replace("msgid ", "", $u); |
|
46 | - $u = trim($u, '"'); |
|
44 | + if (substr ($u, 0, 7) == 'msgid "') { |
|
45 | + $u = str_replace ("msgid ", "", $u); |
|
46 | + $u = trim ($u, '"'); |
|
47 | 47 | $translated[] = $u; |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | // remove existing from unique |
52 | 52 | foreach ($all_translations as $tr) { |
53 | - if (!in_array($tr, $translated)) { |
|
53 | + if (!in_array ($tr, $translated)) { |
|
54 | 54 | $new[] = $tr; |
55 | 55 | } |
56 | 56 | } |
@@ -61,20 +61,20 @@ discard block |
||
61 | 61 | $text[] = "msgstr \"\"\n"; |
62 | 62 | } |
63 | 63 | // join text |
64 | -$text = implode("\n",$text); |
|
64 | +$text = implode ("\n", $text); |
|
65 | 65 | |
66 | 66 | |
67 | 67 | // output changes |
68 | -print_r($text); |
|
68 | +print_r ($text); |
|
69 | 69 | |
70 | 70 | |
71 | 71 | // returns string between 2 separators |
72 | -function get_string_between($string, $start, $end){ |
|
72 | +function get_string_between ($string, $start, $end) { |
|
73 | 73 | $string = " ".$string; |
74 | - $ini = strpos($string,$start); |
|
74 | + $ini = strpos ($string, $start); |
|
75 | 75 | if ($ini == 0) return ""; |
76 | - $ini += strlen($start); |
|
77 | - $len = strpos($string,$end,$ini) - $ini; |
|
78 | - return substr($string,$ini,$len); |
|
76 | + $ini += strlen ($start); |
|
77 | + $len = strpos ($string, $end, $ini) - $ini; |
|
78 | + return substr ($string, $ini, $len); |
|
79 | 79 | } |
80 | 80 | ?> |
81 | 81 | \ No newline at end of file |
@@ -54,7 +54,7 @@ |
||
54 | 54 | Make sure BASE directive is set for your installation. This is used to properly detect phpIPAM directory. It must be set in config.php and in .htaccess |
55 | 55 | |
56 | 56 | <div class="well" style="padding:5px;margin-top:5px;"> |
57 | - Detected BASE: <?php print str_replace("upgrade/", "", $_SERVER['REQUEST_URI']); ?> |
|
57 | + Detected BASE: <?php print str_replace ("upgrade/", "", $_SERVER['REQUEST_URI']); ?> |
|
58 | 58 | </div> |
59 | 59 | |
60 | 60 | <h4>2.) Enable mod_rewrite</h4> |
@@ -270,7 +270,9 @@ discard block |
||
270 | 270 | if(strpos($key, " ")>0) { $key = str_replace(" ", "_", $key); } |
271 | 271 | |
272 | 272 | // if key is numeric append item |
273 | - if(is_numeric($key)) $key = "item".$key; |
|
273 | + if(is_numeric($key)) { |
|
274 | + $key = "item".$key; |
|
275 | + } |
|
274 | 276 | |
275 | 277 | // if array add child |
276 | 278 | if (is_array($value)) { |
@@ -300,8 +302,9 @@ discard block |
||
300 | 302 | * @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0> |
301 | 303 | */ |
302 | 304 | public function xml_to_array ( $xmlObject, $out = array () ) { |
303 | - foreach ( (array) $xmlObject as $index => $node ) |
|
304 | - $out[$index] = ( is_object ( $node ) ) ? $this->xml_to_array ( $node ) : $node; |
|
305 | + foreach ( (array) $xmlObject as $index => $node ) { |
|
306 | + $out[$index] = ( is_object ( $node ) ) ? $this->xml_to_array ( $node ) : $node; |
|
307 | + } |
|
305 | 308 | |
306 | 309 | return $out; |
307 | 310 | } |
@@ -315,14 +318,18 @@ discard block |
||
315 | 318 | */ |
316 | 319 | private function object_to_array ($obj) { |
317 | 320 | // object to array |
318 | - if(is_object($obj)) $obj = (array) $obj; |
|
321 | + if(is_object($obj)) { |
|
322 | + $obj = (array) $obj; |
|
323 | + } |
|
319 | 324 | if(is_array($obj)) { |
320 | 325 | $new = array(); |
321 | 326 | foreach($obj as $key => $val) { |
322 | 327 | $new[$key] = $this->object_to_array($val); |
323 | 328 | } |
324 | 329 | } |
325 | - else $new = $obj; |
|
330 | + else { |
|
331 | + $new = $obj; |
|
332 | + } |
|
326 | 333 | return $new; |
327 | 334 | } |
328 | 335 |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @access public |
55 | 55 | */ |
56 | - public function __construct() { |
|
56 | + public function __construct () { |
|
57 | 57 | # set error codes |
58 | 58 | $this->set_error_codes (); |
59 | 59 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | // set header |
110 | 110 | $this->set_header (); |
111 | 111 | // throw exception |
112 | - throw new Exception($exception); |
|
112 | + throw new Exception ($exception); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | */ |
122 | 122 | private function set_header () { |
123 | 123 | // wrong code |
124 | - if(!isset($this->exception)) { header("HTTP/1.1 500 Invalid result code"); } |
|
125 | - else { header("HTTP/1.1 ".$this->result['code']." ".$this->errors[$this->result['code']]); } |
|
124 | + if (!isset($this->exception)) { header ("HTTP/1.1 500 Invalid result code"); } |
|
125 | + else { header ("HTTP/1.1 ".$this->result['code']." ".$this->errors[$this->result['code']]); } |
|
126 | 126 | |
127 | 127 | // 401 - add location |
128 | - if ($this->result['code']==401) { |
|
128 | + if ($this->result['code'] == 401) { |
|
129 | 129 | $this->set_location_header ("/api/".$_REQUEST['app_id']."/user/"); |
130 | 130 | } |
131 | 131 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function formulate_result ($result) { |
141 | 141 | // make sure result is array |
142 | - $this->result = is_null($this->result) ? (array) $result : $this->result; |
|
142 | + $this->result = is_null ($this->result) ? (array) $result : $this->result; |
|
143 | 143 | |
144 | 144 | // get requested content type |
145 | 145 | $this->get_request_content_type (); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | // set cache header |
150 | 150 | $this->set_cache_header (); |
151 | 151 | // set result header if not already set with $result['success']=false |
152 | - $this->exception===true ? : $this->set_success_header (); |
|
152 | + $this->exception === true ? : $this->set_success_header (); |
|
153 | 153 | |
154 | 154 | // return result |
155 | 155 | return $this->create_result (); |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function validate_content_type () { |
165 | 165 | // not set, presume json |
166 | - if( !isset($_SERVER['CONTENT_TYPE']) ) {} |
|
166 | + if (!isset($_SERVER['CONTENT_TYPE'])) {} |
|
167 | 167 | // post |
168 | - elseif($_SERVER['CONTENT_TYPE']=="application/x-www-form-urlencoded") {} |
|
168 | + elseif ($_SERVER['CONTENT_TYPE'] == "application/x-www-form-urlencoded") {} |
|
169 | 169 | // set, verify |
170 | - elseif (!($_SERVER['CONTENT_TYPE']=="application/xml" || $_SERVER['CONTENT_TYPE']=="application/json")) { |
|
170 | + elseif (!($_SERVER['CONTENT_TYPE'] == "application/xml" || $_SERVER['CONTENT_TYPE'] == "application/json")) { |
|
171 | 171 | $this->throw_exception (415, "Invalid Content type ".$_SERVER['CONTENT_TYPE']); |
172 | 172 | } |
173 | 173 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | */ |
181 | 181 | private function get_request_content_type () { |
182 | - $this->result_type = $_SERVER['CONTENT_TYPE']=="application/xml" ? "xml" : "json"; |
|
182 | + $this->result_type = $_SERVER['CONTENT_TYPE'] == "application/xml" ? "xml" : "json"; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | private function set_content_type_header () { |
192 | 192 | // content_type |
193 | - $this->result_type == "xml" ? header('Content-Type: application/xml') : header('Content-Type: application/json'); |
|
193 | + $this->result_type == "xml" ? header ('Content-Type: application/xml') : header ('Content-Type: application/json'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | */ |
202 | 202 | private function set_cache_header ($seconds = NULL) { |
203 | 203 | // none |
204 | - if($seconds===NULL) { |
|
205 | - header("Cache-Control: no-cache"); |
|
206 | - header("Pragma: no-cache"); |
|
204 | + if ($seconds === NULL) { |
|
205 | + header ("Cache-Control: no-cache"); |
|
206 | + header ("Pragma: no-cache"); |
|
207 | 207 | } |
208 | 208 | // cache |
209 | 209 | else { |
210 | - header("Cache-Control: $seconds"); |
|
210 | + header ("Cache-Control: $seconds"); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | private function set_success_header () { |
221 | 221 | // check fo location |
222 | - if(isset($this->result['location'])) { |
|
222 | + if (isset($this->result['location'])) { |
|
223 | 223 | $this->set_location_header ($this->result['location']); |
224 | 224 | } |
225 | 225 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @return void |
240 | 240 | */ |
241 | 241 | private function set_location_header ($location) { |
242 | - header("Location: ".$location); |
|
242 | + header ("Location: ".$location); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | // reset |
268 | 268 | $this->result['code'] = $tmp['code']; |
269 | 269 | $this->result['success'] = $tmp['success']; |
270 | - if(isset($tmp['message'])) { $this->result['message'] = $tmp['message']; } |
|
271 | - if(isset($tmp['data'])) { $this->result['data'] = $tmp['data']; } |
|
272 | - if(isset($tmp['ip'])) { $this->result['ip'] = $tmp['ip']; } |
|
270 | + if (isset($tmp['message'])) { $this->result['message'] = $tmp['message']; } |
|
271 | + if (isset($tmp['data'])) { $this->result['data'] = $tmp['data']; } |
|
272 | + if (isset($tmp['ip'])) { $this->result['ip'] = $tmp['ip']; } |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -280,15 +280,15 @@ discard block |
||
280 | 280 | */ |
281 | 281 | private function create_xml () { |
282 | 282 | // convert whole object to array |
283 | - $this->result = $this->object_to_array($this->result); |
|
283 | + $this->result = $this->object_to_array ($this->result); |
|
284 | 284 | |
285 | 285 | // new SimpleXMLElement object |
286 | - $xml = new SimpleXMLElement('<'.$_GET['controller'].'/>'); |
|
286 | + $xml = new SimpleXMLElement ('<'.$_GET['controller'].'/>'); |
|
287 | 287 | // generate xml from result |
288 | - $this->array_to_xml($xml, $this->result); |
|
288 | + $this->array_to_xml ($xml, $this->result); |
|
289 | 289 | |
290 | 290 | // return XML result |
291 | - return $xml->asXML(); |
|
291 | + return $xml->asXML (); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -299,23 +299,23 @@ discard block |
||
299 | 299 | * @param array $data |
300 | 300 | * @return void |
301 | 301 | */ |
302 | - private function array_to_xml(SimpleXMLElement $object, array $data) { |
|
302 | + private function array_to_xml (SimpleXMLElement $object, array $data) { |
|
303 | 303 | // loop through values |
304 | 304 | foreach ($data as $key => $value) { |
305 | 305 | // if spaces exist in key replace them with underscores |
306 | - if(strpos($key, " ")>0) { $key = str_replace(" ", "_", $key); } |
|
306 | + if (strpos ($key, " ") > 0) { $key = str_replace (" ", "_", $key); } |
|
307 | 307 | |
308 | 308 | // if key is numeric append item |
309 | - if(is_numeric($key)) $key = "item".$key; |
|
309 | + if (is_numeric ($key)) $key = "item".$key; |
|
310 | 310 | |
311 | 311 | // if array add child |
312 | - if (is_array($value)) { |
|
313 | - $new_object = $object->addChild($key); |
|
314 | - $this->array_to_xml($new_object, $value); |
|
312 | + if (is_array ($value)) { |
|
313 | + $new_object = $object->addChild ($key); |
|
314 | + $this->array_to_xml ($new_object, $value); |
|
315 | 315 | } |
316 | 316 | // else write value |
317 | 317 | else { |
318 | - $object->addChild($key, $value); |
|
318 | + $object->addChild ($key, $value); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | } |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | * @license http://creativecommons.org/licenses/by/3.0/ |
336 | 336 | * @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0> |
337 | 337 | */ |
338 | - public function xml_to_array ( $xmlObject, $out = array () ) { |
|
339 | - foreach ( (array) $xmlObject as $index => $node ) |
|
340 | - $out[$index] = ( is_object ( $node ) ) ? $this->xml_to_array ( $node ) : $node; |
|
338 | + public function xml_to_array ($xmlObject, $out = array ()) { |
|
339 | + foreach ((array) $xmlObject as $index => $node) |
|
340 | + $out[$index] = (is_object ($node)) ? $this->xml_to_array ($node) : $node; |
|
341 | 341 | |
342 | 342 | return $out; |
343 | 343 | } |
@@ -351,11 +351,11 @@ discard block |
||
351 | 351 | */ |
352 | 352 | private function object_to_array ($obj) { |
353 | 353 | // object to array |
354 | - if(is_object($obj)) $obj = (array) $obj; |
|
355 | - if(is_array($obj)) { |
|
356 | - $new = array(); |
|
357 | - foreach($obj as $key => $val) { |
|
358 | - $new[$key] = $this->object_to_array($val); |
|
354 | + if (is_object ($obj)) $obj = (array) $obj; |
|
355 | + if (is_array ($obj)) { |
|
356 | + $new = array (); |
|
357 | + foreach ($obj as $key => $val) { |
|
358 | + $new[$key] = $this->object_to_array ($val); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | else $new = $obj; |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return void |
370 | 370 | */ |
371 | 371 | private function create_json () { |
372 | - return json_encode((array) $this->result); |
|
372 | + return json_encode ((array) $this->result); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | $this->remap_keys (); |
217 | 217 | |
218 | 218 | // first free |
219 | - if($this->_params->id=="first_free") { |
|
219 | + if($this->_params->id=="first_free") { |
|
220 | 220 | $this->_params->ip_addr = $this->Addresses->get_first_available_address ($this->_params->subnetId, $this->Subnets); |
221 | 221 | // null |
222 | 222 | if ($this->_params->ip_addr==false) { $this->Response->throw_exception(404, 'No free addresses found'); } |
223 | - else { $this->_params->ip_addr = $this->Addresses->transform_address ($this->_params->ip_addr, "dotted"); } |
|
223 | + else { $this->_params->ip_addr = $this->Addresses->transform_address ($this->_params->ip_addr, "dotted"); } |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // validate ip address - format, proper subnet, subnet/broadcast check |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | } |
241 | 241 | else { |
242 | 242 | //set result |
243 | - if($this->_params->id=="first_free") { |
|
243 | + if($this->_params->id=="first_free") { |
|
244 | 244 | return array("code"=>201, "data"=>"Address created", "location"=>"/api/".$this->_params->app_id."/addresses/".$this->Addresses->lastId."/", "ip"=>$this->Addresses->transform_address ($this->_params->ip_addr, "dotted")); |
245 | 245 | } |
246 | 246 | else { |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | # execute update |
316 | 316 | if(!$this->Addresses->modify_address ($values)) |
317 | 317 | { $this->Response->throw_exception(500, "Failed to delete address"); } |
318 | - else { |
|
318 | + else { |
|
319 | 319 | //set result |
320 | 320 | return array("code"=>200, "data"=>"Address deleted"); |
321 | 321 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | * |
7 | 7 | */ |
8 | -class Addresses_controller extends Common_api_functions { |
|
8 | +class Addresses_controller extends Common_api_functions { |
|
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param class $Tools |
106 | 106 | * @param mixed $params // post/get values |
107 | 107 | */ |
108 | - public function __construct($Database, $Tools, $params, $Response) { |
|
108 | + public function __construct ($Database, $Tools, $params, $Response) { |
|
109 | 109 | $this->Database = $Database; |
110 | - $this->Tools = $Tools; |
|
110 | + $this->Tools = $Tools; |
|
111 | 111 | $this->_params = $params; |
112 | 112 | $this->Response = $Response; |
113 | 113 | // init required objects |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | $this->validate_options_request (); |
133 | 133 | |
134 | 134 | // methods |
135 | - $result = array(); |
|
136 | - $result['methods'] = array( |
|
137 | - array("href"=>"/api/".$this->_params->app_id."/addresses/", "methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))), |
|
138 | - array("href"=>"/api/".$this->_params->app_id."/addresses/{id}/","methods"=>array(array("rel"=>"read", "method"=>"GET"), |
|
139 | - array("rel"=>"create", "method"=>"POST"), |
|
140 | - array("rel"=>"update", "method"=>"PATCH"), |
|
141 | - array("rel"=>"delete", "method"=>"DELETE"))), |
|
135 | + $result = array (); |
|
136 | + $result['methods'] = array ( |
|
137 | + array ("href"=>"/api/".$this->_params->app_id."/addresses/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))), |
|
138 | + array ("href"=>"/api/".$this->_params->app_id."/addresses/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"), |
|
139 | + array ("rel"=>"create", "method"=>"POST"), |
|
140 | + array ("rel"=>"update", "method"=>"PATCH"), |
|
141 | + array ("rel"=>"delete", "method"=>"DELETE"))), |
|
142 | 142 | ); |
143 | 143 | # result |
144 | - return array("code"=>200, "data"=>$result); |
|
144 | + return array ("code"=>200, "data"=>$result); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -165,24 +165,24 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function GET () { |
167 | 167 | // subnet Id > read all addresses in subnet |
168 | - if($this->_params->id=="custom_fields") { |
|
168 | + if ($this->_params->id == "custom_fields") { |
|
169 | 169 | // check result |
170 | - if(sizeof($this->custom_fields)==0) { $this->Response->throw_exception(404, 'No custom fields defined'); } |
|
171 | - else { return array("code"=>200, "data"=>$this->custom_fields); } |
|
170 | + if (sizeof ($this->custom_fields) == 0) { $this->Response->throw_exception (404, 'No custom fields defined'); } |
|
171 | + else { return array ("code"=>200, "data"=>$this->custom_fields); } |
|
172 | 172 | } |
173 | 173 | // tags |
174 | - elseif($this->_params->id=="tags") { |
|
174 | + elseif ($this->_params->id == "tags") { |
|
175 | 175 | // validate |
176 | 176 | $this->validate_tag (); |
177 | 177 | // all addresses with tag |
178 | - if (@$this->_params->id3=="addresses") { |
|
178 | + if (@$this->_params->id3 == "addresses") { |
|
179 | 179 | // fetch |
180 | 180 | $result = $this->Tools->fetch_multiple_objects ("ipaddresses", "state", $this->_params->id2); |
181 | 181 | |
182 | 182 | // filter by subnetId |
183 | - if ($result!==false) { |
|
184 | - if(isset($this->_params->subnetId)) { |
|
185 | - if (is_numeric($this->_params->subnetId)) { |
|
183 | + if ($result !== false) { |
|
184 | + if (isset($this->_params->subnetId)) { |
|
185 | + if (is_numeric ($this->_params->subnetId)) { |
|
186 | 186 | // filter |
187 | 187 | foreach ($result as $k=>$v) { |
188 | 188 | if ($v->subnetId != $this->_params->subnetId) { |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | } |
191 | 191 | } |
192 | 192 | // any left |
193 | - if (sizeof($result)==0) { |
|
193 | + if (sizeof ($result) == 0) { |
|
194 | 194 | $result = false; |
195 | 195 | } |
196 | 196 | } |
@@ -198,34 +198,34 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | // result |
201 | - if($result===false) { $this->Response->throw_exception(404, 'No addresses found'); } |
|
202 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "addresses", true, false)); } |
|
201 | + if ($result === false) { $this->Response->throw_exception (404, 'No addresses found'); } |
|
202 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "addresses", true, false)); } |
|
203 | 203 | } |
204 | 204 | // tags |
205 | 205 | else { |
206 | 206 | // fetch all by tag |
207 | - if(isset($this->_params->id2)) { |
|
207 | + if (isset($this->_params->id2)) { |
|
208 | 208 | // numeric |
209 | - if(is_numeric($this->_params->id2)) { $result = $this->Tools->fetch_object ("ipTags", "id", $this->_params->id2); } |
|
209 | + if (is_numeric ($this->_params->id2)) { $result = $this->Tools->fetch_object ("ipTags", "id", $this->_params->id2); } |
|
210 | 210 | // type |
211 | - else { $result = $this->Tools->fetch_multiple_objects ("ipTags", "type", $this->_params->id2); } |
|
211 | + else { $result = $this->Tools->fetch_multiple_objects ("ipTags", "type", $this->_params->id2); } |
|
212 | 212 | } |
213 | 213 | // all tags |
214 | - else { $result = $this->Tools->fetch_all_objects ("ipTags"); } |
|
214 | + else { $result = $this->Tools->fetch_all_objects ("ipTags"); } |
|
215 | 215 | |
216 | 216 | // result |
217 | - if($result===false) { $this->Response->throw_exception(404, 'Tag not found'); } |
|
218 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "addresses/tags", true, false)); } |
|
217 | + if ($result === false) { $this->Response->throw_exception (404, 'Tag not found'); } |
|
218 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "addresses/tags", true, false)); } |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | // id not set |
222 | 222 | elseif (!isset($this->_params->id)) { |
223 | - { $this->Response->throw_exception(400, 'Address ID is required'); } |
|
223 | + { $this->Response->throw_exception (400, 'Address ID is required'); } |
|
224 | 224 | } |
225 | 225 | // id |
226 | - elseif (is_numeric($this->_params->id)) { |
|
226 | + elseif (is_numeric ($this->_params->id)) { |
|
227 | 227 | // ping |
228 | - if(@$this->_params->id2=="ping") { |
|
228 | + if (@$this->_params->id2 == "ping") { |
|
229 | 229 | # scan class |
230 | 230 | $Scan = new Scan ($this->Database); |
231 | 231 | $Scan->ping_set_exit (false); |
@@ -233,35 +233,35 @@ discard block |
||
233 | 233 | $this->validate_address_id (); |
234 | 234 | |
235 | 235 | // set result |
236 | - $result = array(); |
|
236 | + $result = array (); |
|
237 | 237 | $result['scan_type'] = $Scan->icmp_type; |
238 | 238 | $result['exit_code'] = $Scan->ping_address ($this->old_address->ip_addr); |
239 | 239 | |
240 | 240 | // success |
241 | - if($result['exit_code']==0) { $Scan->ping_update_lastseen ($this->_params->id); return array("code"=>200, "data"=>$result); } |
|
242 | - else { $this->Response->throw_exception(404, "Address offline. Exit code: ".$result['exit_code']."( ".$Scan->ping_exit_explain ($result['exit_code'])." )"); } |
|
241 | + if ($result['exit_code'] == 0) { $Scan->ping_update_lastseen ($this->_params->id); return array ("code"=>200, "data"=>$result); } |
|
242 | + else { $this->Response->throw_exception (404, "Address offline. Exit code: ".$result['exit_code']."( ".$Scan->ping_exit_explain ($result['exit_code'])." )"); } |
|
243 | 243 | } |
244 | 244 | else { |
245 | 245 | // fetch |
246 | 246 | $result = $this->Addresses->fetch_address ("id", $this->_params->id); |
247 | 247 | // check result |
248 | - if($result==false) { $this->Response->throw_exception(404, "Invalid Id"); } |
|
249 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, $this->_params->controller, true, true)); } |
|
248 | + if ($result == false) { $this->Response->throw_exception (404, "Invalid Id"); } |
|
249 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, $this->_params->controller, true, true)); } |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | // ip address ? |
253 | - elseif (@$this->_params->id=="search") { |
|
253 | + elseif (@$this->_params->id == "search") { |
|
254 | 254 | // validate |
255 | - if(!$this->Addresses->validate_address ($this->_params->id2)) |
|
256 | - { $this->Response->throw_exception(404, 'Invalid address'); } |
|
255 | + if (!$this->Addresses->validate_address ($this->_params->id2)) |
|
256 | + { $this->Response->throw_exception (404, 'Invalid address'); } |
|
257 | 257 | // search |
258 | 258 | $result = $this->Tools->fetch_multiple_objects ("ipaddresses", "ip_addr", $this->Subnets->transform_address ($this->_params->id2, "decimal")); |
259 | 259 | // check result |
260 | - if($result===false) { $this->Response->throw_exception(404, 'Address not found'); } |
|
261 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, $this->_params->controller, true, true)); } |
|
260 | + if ($result === false) { $this->Response->throw_exception (404, 'Address not found'); } |
|
261 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, $this->_params->controller, true, true)); } |
|
262 | 262 | } |
263 | 263 | // false |
264 | - else { $this->Response->throw_exception(400, "Invalid Id"); } |
|
264 | + else { $this->Response->throw_exception (400, "Invalid Id"); } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -297,11 +297,11 @@ discard block |
||
297 | 297 | $this->remap_keys (); |
298 | 298 | |
299 | 299 | // first free |
300 | - if($this->_params->id=="first_free") { |
|
300 | + if ($this->_params->id == "first_free") { |
|
301 | 301 | $this->_params->ip_addr = $this->Addresses->get_first_available_address ($this->_params->subnetId, $this->Subnets); |
302 | 302 | // null |
303 | - if ($this->_params->ip_addr==false) { $this->Response->throw_exception(404, 'No free addresses found'); } |
|
304 | - else { $this->_params->ip_addr = $this->Addresses->transform_address ($this->_params->ip_addr, "dotted"); } |
|
303 | + if ($this->_params->ip_addr == false) { $this->Response->throw_exception (404, 'No free addresses found'); } |
|
304 | + else { $this->_params->ip_addr = $this->Addresses->transform_address ($this->_params->ip_addr, "dotted"); } |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // validate ip address - format, proper subnet, subnet/broadcast check |
@@ -311,21 +311,21 @@ discard block |
||
311 | 311 | $values = $this->validate_keys (); |
312 | 312 | |
313 | 313 | // transform address to decimal format |
314 | - $values['ip_addr'] = $this->Addresses->transform_address($values['ip_addr'] ,"decimal"); |
|
314 | + $values['ip_addr'] = $this->Addresses->transform_address ($values['ip_addr'], "decimal"); |
|
315 | 315 | // set action |
316 | 316 | $values['action'] = "add"; |
317 | 317 | |
318 | 318 | # execute |
319 | - if(!$this->Addresses->modify_address ($values)) { |
|
320 | - $this->Response->throw_exception(500, "Failed to create address"); |
|
319 | + if (!$this->Addresses->modify_address ($values)) { |
|
320 | + $this->Response->throw_exception (500, "Failed to create address"); |
|
321 | 321 | } |
322 | 322 | else { |
323 | 323 | //set result |
324 | - if($this->_params->id=="first_free") { |
|
325 | - return array("code"=>201, "data"=>"Address created", "location"=>"/api/".$this->_params->app_id."/addresses/".$this->Addresses->lastId."/", "ip"=>$this->Addresses->transform_address ($this->_params->ip_addr, "dotted")); |
|
324 | + if ($this->_params->id == "first_free") { |
|
325 | + return array ("code"=>201, "data"=>"Address created", "location"=>"/api/".$this->_params->app_id."/addresses/".$this->Addresses->lastId."/", "ip"=>$this->Addresses->transform_address ($this->_params->ip_addr, "dotted")); |
|
326 | 326 | } |
327 | 327 | else { |
328 | - return array("code"=>201, "data"=>"Address created", "location"=>"/api/".$this->_params->app_id."/addresses/".$this->Addresses->lastId."/"); |
|
328 | + return array ("code"=>201, "data"=>"Address created", "location"=>"/api/".$this->_params->app_id."/addresses/".$this->Addresses->lastId."/"); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | } |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | $this->remap_keys (); |
349 | 349 | |
350 | 350 | // we dont allow address or subnet change |
351 | - if(isset($this->_params->ip_addr)) { $this->Response->throw_exception(400, "IP address cannot be changed"); } |
|
352 | - if(isset($this->_params->subnetId)) { $this->Response->throw_exception(400, "Subnet cannot be changed"); } |
|
351 | + if (isset($this->_params->ip_addr)) { $this->Response->throw_exception (400, "IP address cannot be changed"); } |
|
352 | + if (isset($this->_params->subnetId)) { $this->Response->throw_exception (400, "Subnet cannot be changed"); } |
|
353 | 353 | |
354 | 354 | // validations |
355 | 355 | $this->validate_update_parameters (); |
@@ -363,12 +363,12 @@ discard block |
||
363 | 363 | $this->init_object ("Admin", $this->Database); |
364 | 364 | |
365 | 365 | # execute |
366 | - if(!$this->Admin->object_modify ("ipaddresses", "edit", "id", $values)) { |
|
367 | - $this->Response->throw_exception(500, "Failed to update address"); |
|
366 | + if (!$this->Admin->object_modify ("ipaddresses", "edit", "id", $values)) { |
|
367 | + $this->Response->throw_exception (500, "Failed to update address"); |
|
368 | 368 | } |
369 | 369 | else { |
370 | 370 | //set result |
371 | - return array("code"=>200, "data"=>"Address updated"); |
|
371 | + return array ("code"=>200, "data"=>"Address updated"); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -390,16 +390,16 @@ discard block |
||
390 | 390 | $this->validate_address_id (); |
391 | 391 | |
392 | 392 | // set variables for delete |
393 | - $values = array(); |
|
394 | - $values["id"] = $this->_params->id; |
|
393 | + $values = array (); |
|
394 | + $values["id"] = $this->_params->id; |
|
395 | 395 | $values["action"] = "delete"; |
396 | 396 | |
397 | 397 | # execute update |
398 | - if(!$this->Addresses->modify_address ($values)) |
|
399 | - { $this->Response->throw_exception(500, "Failed to delete address"); } |
|
398 | + if (!$this->Addresses->modify_address ($values)) |
|
399 | + { $this->Response->throw_exception (500, "Failed to delete address"); } |
|
400 | 400 | else { |
401 | 401 | //set result |
402 | - return array("code"=>200, "data"=>"Address deleted"); |
|
402 | + return array ("code"=>200, "data"=>"Address deleted"); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @return void |
422 | 422 | */ |
423 | 423 | private function validate_address_id () { |
424 | - if(!$this->old_address = $this->Addresses->fetch_address ("id", $this->_params->id)){ $this->Response->throw_exception(404, "Address does not exist"); } |
|
424 | + if (!$this->old_address = $this->Addresses->fetch_address ("id", $this->_params->id)) { $this->Response->throw_exception (404, "Address does not exist"); } |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,9 +432,9 @@ discard block |
||
432 | 432 | */ |
433 | 433 | private function validate_tag () { |
434 | 434 | // numeric |
435 | - if(!is_numeric(@$this->_params->id2)) { $this->Response->throw_exception(400, 'Invalid tag identifier'); } |
|
435 | + if (!is_numeric (@$this->_params->id2)) { $this->Response->throw_exception (400, 'Invalid tag identifier'); } |
|
436 | 436 | // check db |
437 | - if (!$this->Tools->fetch_object ("ipTags", "id", $this->_params->id2)) { $this->Response->throw_exception(404, "Address tag does not exist"); } |
|
437 | + if (!$this->Tools->fetch_object ("ipTags", "id", $this->_params->id2)) { $this->Response->throw_exception (404, "Address tag does not exist"); } |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -445,10 +445,10 @@ discard block |
||
445 | 445 | */ |
446 | 446 | private function validate_subnet () { |
447 | 447 | // numberic |
448 | - if(!is_numeric($this->_params->subnetId)) { $this->Response->throw_exception(400, "Subnet Id must be numeric"); } |
|
448 | + if (!is_numeric ($this->_params->subnetId)) { $this->Response->throw_exception (400, "Subnet Id must be numeric"); } |
|
449 | 449 | // check subnet |
450 | - if(is_null($res = $this->Subnets->fetch_subnet ("id", $this->_params->subnetId))) { $this->Response->throw_exception(400, "Invalid subnet Id"); } |
|
451 | - else { $this->subnet_details = $res; } |
|
450 | + if (is_null ($res = $this->Subnets->fetch_subnet ("id", $this->_params->subnetId))) { $this->Response->throw_exception (400, "Invalid subnet Id"); } |
|
451 | + else { $this->subnet_details = $res; } |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | $this->validate_subnet (); |
463 | 463 | |
464 | 464 | // validate overlapping |
465 | - if($this->Addresses->address_exists ($this->_params->ip_addr, $this->_params->subnetId)) { $this->Response->throw_exception(400, "IP address already exists"); } |
|
465 | + if ($this->Addresses->address_exists ($this->_params->ip_addr, $this->_params->subnetId)) { $this->Response->throw_exception (400, "IP address already exists"); } |
|
466 | 466 | |
467 | 467 | // fetch subnet |
468 | 468 | $subnet = $this->subnet_details; |
@@ -470,14 +470,14 @@ discard block |
||
470 | 470 | $subnet = $this->Subnets->transform_to_dotted ($subnet->subnet)."/".$subnet->mask; |
471 | 471 | |
472 | 472 | // validate address, that it is inside subnet, not subnet/broadcast |
473 | - $this->Addresses->verify_address( $this->_params->ip_addr, $subnet, false, true ); |
|
473 | + $this->Addresses->verify_address ($this->_params->ip_addr, $subnet, false, true); |
|
474 | 474 | |
475 | 475 | // validate device |
476 | - if(isset($this->_params->switch)) { |
|
477 | - if($this->Tools->fetch_object("devices", "vlanId", $this->_params->switch)===false) { $this->Response->throw_exception(400, "Device does not exist"); } } |
|
476 | + if (isset($this->_params->switch)) { |
|
477 | + if ($this->Tools->fetch_object ("devices", "vlanId", $this->_params->switch) === false) { $this->Response->throw_exception (400, "Device does not exist"); } } |
|
478 | 478 | // validate state |
479 | - if(isset($this->_params->state)) { |
|
480 | - if($this->Tools->fetch_object("ipTags", "id", $this->_params->state)===false) { $this->Response->throw_exception(400, "Tag does not exist"); } } |
|
479 | + if (isset($this->_params->state)) { |
|
480 | + if ($this->Tools->fetch_object ("ipTags", "id", $this->_params->state) === false) { $this->Response->throw_exception (400, "Tag does not exist"); } } |
|
481 | 481 | else { $this->_params->state = 2; } |
482 | 482 | } |
483 | 483 | |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | $this->validate_address_id (); |
493 | 493 | |
494 | 494 | // validate device |
495 | - if(isset($this->_params->switch)) { |
|
496 | - if($this->Tools->fetch_object("devices", "vlanId", $this->_params->switch)===false) { $this->Response->throw_exception(400, "Device does not exist"); } } |
|
495 | + if (isset($this->_params->switch)) { |
|
496 | + if ($this->Tools->fetch_object ("devices", "vlanId", $this->_params->switch) === false) { $this->Response->throw_exception (400, "Device does not exist"); } } |
|
497 | 497 | // validate state |
498 | - if(isset($this->_params->state)) { |
|
499 | - if($this->Tools->fetch_object("ipTags", "id", $this->_params->state)===false) { $this->Response->throw_exception(400, "Tag does not exist"); } } |
|
498 | + if (isset($this->_params->state)) { |
|
499 | + if ($this->Tools->fetch_object ("ipTags", "id", $this->_params->state) === false) { $this->Response->throw_exception (400, "Tag does not exist"); } } |
|
500 | 500 | else { $this->_params->state = 2; } |
501 | 501 | } |
502 | 502 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | # execute update |
190 | 190 | if(!$this->Sections->modify_section ("add", $values)) |
191 | 191 | { $this->Response->throw_exception(500, "Section create failed"); } |
192 | - else { |
|
192 | + else { |
|
193 | 193 | //set result |
194 | 194 | return array("code"=>201, "data"=>"Section created", "location"=>"/api/".$this->_params->app_id."/sections/".$this->Sections->lastInsertId."/"); |
195 | 195 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | # execute update |
219 | 219 | if(!$this->Sections->modify_section ("edit", $values)) |
220 | 220 | { $this->Response->throw_exception(500, "Section update failed"); } |
221 | - else { |
|
221 | + else { |
|
222 | 222 | //set result |
223 | 223 | return array("code"=>200, "data"=>NULL); |
224 | 224 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | # execute update |
248 | 248 | if(!$this->Sections->modify_section ("delete", $values)) |
249 | 249 | { $this->Response->throw_exception(500, "Section delete failed"); } |
250 | - else { |
|
250 | + else { |
|
251 | 251 | //set result |
252 | 252 | return array("code"=>200, "data"=>NULL); |
253 | 253 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | * @param mixed $params |
75 | 75 | * @param mixed $Response |
76 | 76 | */ |
77 | - public function __construct($Database, $Tools, $params, $Response) { |
|
77 | + public function __construct ($Database, $Tools, $params, $Response) { |
|
78 | 78 | $this->Database = $Database; |
79 | 79 | $this->Response = $Response; |
80 | - $this->Tools = $Tools; |
|
80 | + $this->Tools = $Tools; |
|
81 | 81 | $this->_params = $params; |
82 | 82 | # sections |
83 | 83 | // init required objects |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | $this->validate_options_request (); |
102 | 102 | |
103 | 103 | // methods |
104 | - $result = array(); |
|
105 | - $result['methods'] = array( |
|
106 | - array("href"=>"/api/".$this->_params->app_id."/sections/", "methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))), |
|
107 | - array("href"=>"/api/".$this->_params->app_id."/sections/{id}/", "methods"=>array(array("rel"=>"read", "method"=>"GET"), |
|
108 | - array("rel"=>"create", "method"=>"POST"), |
|
109 | - array("rel"=>"update", "method"=>"PATCH"), |
|
110 | - array("rel"=>"delete", "method"=>"DELETE"))), |
|
104 | + $result = array (); |
|
105 | + $result['methods'] = array ( |
|
106 | + array ("href"=>"/api/".$this->_params->app_id."/sections/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))), |
|
107 | + array ("href"=>"/api/".$this->_params->app_id."/sections/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"), |
|
108 | + array ("rel"=>"create", "method"=>"POST"), |
|
109 | + array ("rel"=>"update", "method"=>"PATCH"), |
|
110 | + array ("rel"=>"delete", "method"=>"DELETE"))), |
|
111 | 111 | ); |
112 | 112 | # result |
113 | - return array("code"=>200, "data"=>$result); |
|
113 | + return array ("code"=>200, "data"=>$result); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function GET () { |
135 | 135 | // fetch subnets in section |
136 | - if(@$this->_params->id2=="subnets" && is_numeric($this->_params->id)) { |
|
136 | + if (@$this->_params->id2 == "subnets" && is_numeric ($this->_params->id)) { |
|
137 | 137 | // we dont need id2 anymore |
138 | 138 | unset($this->_params->id2); |
139 | 139 | //validate section |
@@ -143,54 +143,54 @@ discard block |
||
143 | 143 | //fetch |
144 | 144 | $result = $this->Subnets->fetch_section_subnets ($this->_params->id); |
145 | 145 | // add gateway |
146 | - if($result!=false) { |
|
146 | + if ($result != false) { |
|
147 | 147 | foreach ($result as $k=>$r) { |
148 | 148 | //gw |
149 | 149 | $gateway = $this->read_subnet_gateway ($r->id); |
150 | - if ( $gateway!== false) { |
|
150 | + if ($gateway !== false) { |
|
151 | 151 | $result[$k]->gatewayId = $gateway->id; |
152 | 152 | } |
153 | 153 | //nameservers |
154 | 154 | $ns = $this->read_subnet_nameserver ($r->nameserverId); |
155 | - if ($ns!==false) { |
|
155 | + if ($ns !== false) { |
|
156 | 156 | $result[$k]->nameservers = $ns; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | } |
160 | 160 | // check result |
161 | - if(sizeof($result)==0) { return array("code"=>200, "data"=>NULL); } |
|
162 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
161 | + if (sizeof ($result) == 0) { return array ("code"=>200, "data"=>NULL); } |
|
162 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
163 | 163 | } |
164 | 164 | // verify ID |
165 | - elseif(isset($this->_params->id)) { |
|
165 | + elseif (isset($this->_params->id)) { |
|
166 | 166 | # fetch by id |
167 | - if(is_numeric($this->_params->id)) { |
|
167 | + if (is_numeric ($this->_params->id)) { |
|
168 | 168 | $result = $this->Sections->fetch_section ("id", $this->_params->id); |
169 | 169 | // check result |
170 | - if(sizeof($result)==0) { $this->Response->throw_exception(404, NULL); } |
|
171 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
170 | + if (sizeof ($result) == 0) { $this->Response->throw_exception (404, NULL); } |
|
171 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
172 | 172 | } |
173 | 173 | # return custom fields |
174 | - elseif($this->_params->id=="custom_fields") { |
|
174 | + elseif ($this->_params->id == "custom_fields") { |
|
175 | 175 | // check result |
176 | - if(sizeof($this->custom_fields)==0) { $this->Response->throw_exception(404, 'No custom fields defined'); } |
|
177 | - else { return array("code"=>200, "data"=>$result); } |
|
176 | + if (sizeof ($this->custom_fields) == 0) { $this->Response->throw_exception (404, 'No custom fields defined'); } |
|
177 | + else { return array ("code"=>200, "data"=>$result); } |
|
178 | 178 | } |
179 | 179 | # fetch by name |
180 | 180 | else { |
181 | 181 | $result = $this->Sections->fetch_section ("name", $this->_params->id); |
182 | 182 | // check result |
183 | - if(sizeof($result)==0) { $this->Response->throw_exception(404, $this->Response->errors[404]); } |
|
184 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
183 | + if (sizeof ($result) == 0) { $this->Response->throw_exception (404, $this->Response->errors[404]); } |
|
184 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | # all sections |
188 | 188 | else { |
189 | 189 | // all sections |
190 | - $result = $this->Sections->fetch_all_sections(); |
|
190 | + $result = $this->Sections->fetch_all_sections (); |
|
191 | 191 | // check result |
192 | - if($result===false) { return array("code"=>204, NULL); } |
|
193 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
192 | + if ($result === false) { return array ("code"=>204, NULL); } |
|
193 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
@@ -225,22 +225,22 @@ discard block |
||
225 | 225 | unset($values['editDate']); |
226 | 226 | |
227 | 227 | # validate mandatory parameters |
228 | - if(strlen($this->_params->name)<3) { $this->Response->throw_exception(400, 'Name is mandatory or too short (mininum 3 characters)'); } |
|
228 | + if (strlen ($this->_params->name) < 3) { $this->Response->throw_exception (400, 'Name is mandatory or too short (mininum 3 characters)'); } |
|
229 | 229 | |
230 | 230 | # verify masterSection |
231 | - if(isset($this->_params->masterSection)) { |
|
231 | + if (isset($this->_params->masterSection)) { |
|
232 | 232 | $masterSection = $this->Sections->fetch_section ("id", $this->_params->masterSection); |
233 | 233 | // checks |
234 | - if(sizeof($masterSection)==0) { $this->Response->throw_exception(400, 'Invalid masterSection id '.$this->_params->masterSection); } |
|
235 | - elseif($masterSection->masterSection!="0") { $this->Response->throw_exception(400, 'Only 1 level of nesting is permitted for sections'); } |
|
234 | + if (sizeof ($masterSection) == 0) { $this->Response->throw_exception (400, 'Invalid masterSection id '.$this->_params->masterSection); } |
|
235 | + elseif ($masterSection->masterSection != "0") { $this->Response->throw_exception (400, 'Only 1 level of nesting is permitted for sections'); } |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | # execute update |
239 | - if(!$this->Sections->modify_section ("add", $values)) |
|
240 | - { $this->Response->throw_exception(500, "Section create failed"); } |
|
239 | + if (!$this->Sections->modify_section ("add", $values)) |
|
240 | + { $this->Response->throw_exception (500, "Section create failed"); } |
|
241 | 241 | else { |
242 | 242 | //set result |
243 | - return array("code"=>201, "data"=>"Section created", "location"=>"/api/".$this->_params->app_id."/sections/".$this->Sections->lastInsertId."/"); |
|
243 | + return array ("code"=>201, "data"=>"Section created", "location"=>"/api/".$this->_params->app_id."/sections/".$this->Sections->lastInsertId."/"); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -256,20 +256,20 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function PATCH () { |
258 | 258 | # Check for id |
259 | - if(!isset($this->_params->id)) { $this->Response->throw_exception(400, "Section Id required"); } |
|
259 | + if (!isset($this->_params->id)) { $this->Response->throw_exception (400, "Section Id required"); } |
|
260 | 260 | # check that section exists |
261 | - if(sizeof($this->Sections->fetch_section ("id", $this->_params->id))==0) |
|
262 | - { $this->Response->throw_exception(404, "Section does not exist"); } |
|
261 | + if (sizeof ($this->Sections->fetch_section ("id", $this->_params->id)) == 0) |
|
262 | + { $this->Response->throw_exception (404, "Section does not exist"); } |
|
263 | 263 | |
264 | 264 | # validate and prepare keys |
265 | 265 | $values = $this->validate_keys (); |
266 | 266 | |
267 | 267 | # execute update |
268 | - if(!$this->Sections->modify_section ("edit", $values)) |
|
269 | - { $this->Response->throw_exception(500, "Section update failed"); } |
|
268 | + if (!$this->Sections->modify_section ("edit", $values)) |
|
269 | + { $this->Response->throw_exception (500, "Section update failed"); } |
|
270 | 270 | else { |
271 | 271 | //set result |
272 | - return array("code"=>200, "data"=>NULL); |
|
272 | + return array ("code"=>200, "data"=>NULL); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -285,21 +285,21 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function DELETE () { |
287 | 287 | # Check for id |
288 | - if(!isset($this->_params->id)) { $this->Response->throw_exception(400, "Section Id required"); } |
|
288 | + if (!isset($this->_params->id)) { $this->Response->throw_exception (400, "Section Id required"); } |
|
289 | 289 | # check that section exists |
290 | - if(sizeof($this->Sections->fetch_section ("id", $this->_params->id))==0) |
|
291 | - { $this->Response->throw_exception(404, "Section does not exist"); } |
|
290 | + if (sizeof ($this->Sections->fetch_section ("id", $this->_params->id)) == 0) |
|
291 | + { $this->Response->throw_exception (404, "Section does not exist"); } |
|
292 | 292 | |
293 | 293 | # set variables for update |
294 | - $values = array(); |
|
294 | + $values = array (); |
|
295 | 295 | $values["id"] = $this->_params->id; |
296 | 296 | |
297 | 297 | # execute update |
298 | - if(!$this->Sections->modify_section ("delete", $values)) |
|
299 | - { $this->Response->throw_exception(500, "Section delete failed"); } |
|
298 | + if (!$this->Sections->modify_section ("delete", $values)) |
|
299 | + { $this->Response->throw_exception (500, "Section delete failed"); } |
|
300 | 300 | else { |
301 | 301 | //set result |
302 | - return array("code"=>200, "data"=>NULL); |
|
302 | + return array ("code"=>200, "data"=>NULL); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 |
@@ -244,10 +244,12 @@ |
||
244 | 244 | $result->links[$m] = new stdClass (); |
245 | 245 | $result->links[$m]->rel = $link; |
246 | 246 | // self ? |
247 | - if ($link=="self") |
|
248 | - $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/"; |
|
249 | - else |
|
250 | - $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/$link/"; |
|
247 | + if ($link=="self") { |
|
248 | + $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/"; |
|
249 | + } |
|
250 | + else { |
|
251 | + $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/$link/"; |
|
252 | + } |
|
251 | 253 | $result->links[$m]->methods = $method; |
252 | 254 | // next |
253 | 255 | $m++; |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function init_object ($Object_name, $Database) { |
104 | 104 | // admin fix |
105 | - if($Object_name=="Admin") { $this->$Object_name = new $Object_name ($Database, false); } |
|
105 | + if ($Object_name == "Admin") { $this->$Object_name = new $Object_name ($Database, false); } |
|
106 | 106 | // User fix |
107 | - elseif($Object_name=="User") { $this->$Object_name = new $Object_name ($Database, true); $this->$Object_name->user = null; } |
|
107 | + elseif ($Object_name == "User") { $this->$Object_name = new $Object_name ($Database, true); $this->$Object_name->user = null; } |
|
108 | 108 | // default |
109 | - else { $this->$Object_name = new $Object_name ($Database); } |
|
109 | + else { $this->$Object_name = new $Object_name ($Database); } |
|
110 | 110 | // set exit method |
111 | 111 | $this->$Object_name->Result->exit_method = "exception"; |
112 | 112 | // set API flag |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | */ |
123 | 123 | protected function set_valid_keys ($controller) { |
124 | 124 | # array of controller keys |
125 | - $this->controller_keys = array("app_id", "controller"); |
|
125 | + $this->controller_keys = array ("app_id", "controller"); |
|
126 | 126 | |
127 | 127 | # array of all valid keys - fetch from SCHEMA |
128 | 128 | $this->valid_keys = $this->Tools->fetch_standard_fields ($controller); |
129 | 129 | |
130 | 130 | # add custom fields |
131 | - $custom_fields = $this->Tools->fetch_custom_fields($controller); |
|
132 | - if(sizeof($custom_fields)>0) { |
|
133 | - foreach($custom_fields as $cf) { |
|
131 | + $custom_fields = $this->Tools->fetch_custom_fields ($controller); |
|
132 | + if (sizeof ($custom_fields) > 0) { |
|
133 | + foreach ($custom_fields as $cf) { |
|
134 | 134 | $this->custom_keys[] = $cf['name']; |
135 | 135 | } |
136 | 136 | } |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | $this->custom_fields = $custom_fields; |
140 | 140 | |
141 | 141 | # merge all |
142 | - $this->valid_keys = array_merge($this->controller_keys, $this->valid_keys); |
|
143 | - if(isset($this->custom_keys)) { |
|
144 | - $this->valid_keys = array_merge($this->valid_keys, $this->custom_keys); |
|
142 | + $this->valid_keys = array_merge ($this->controller_keys, $this->valid_keys); |
|
143 | + if (isset($this->custom_keys)) { |
|
144 | + $this->valid_keys = array_merge ($this->valid_keys, $this->custom_keys); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | # set items to remove |
148 | - $this->remove_keys = array("editDate"); |
|
148 | + $this->remove_keys = array ("editDate"); |
|
149 | 149 | # remove update time |
150 | - foreach($this->valid_keys as $k=>$v) { |
|
151 | - if(in_array($v, $this->remove_keys)) { |
|
150 | + foreach ($this->valid_keys as $k=>$v) { |
|
151 | + if (in_array ($v, $this->remove_keys)) { |
|
152 | 152 | unset($this->valid_keys[$k]); |
153 | 153 | } |
154 | 154 | } |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function prepare_result ($result, $controller = null, $links = true, $transform_address = true) { |
169 | 169 | // empty controller |
170 | - $controller = is_null($controller) ? $this->_params->controller : $controller; |
|
170 | + $controller = is_null ($controller) ? $this->_params->controller : $controller; |
|
171 | 171 | |
172 | 172 | // links |
173 | - if($links) { |
|
173 | + if ($links) { |
|
174 | 174 | // explicitly set to no |
175 | - if(@$this->_params->links!="false") |
|
175 | + if (@$this->_params->links != "false") |
|
176 | 176 | { $result = $this->add_links ($result, $controller); } |
177 | 177 | } |
178 | 178 | // filter |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { $result = $this->filter_result ($result); } |
181 | 181 | } |
182 | 182 | // transform address |
183 | - if($transform_address) { $result = $this->transform_address ($result); } |
|
183 | + if ($transform_address) { $result = $this->transform_address ($result); } |
|
184 | 184 | |
185 | 185 | // remove subnets and addresses if needed |
186 | 186 | $result = $this->remove_folders ($result); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $this->validate_filter_by ($result); |
210 | 210 | |
211 | 211 | // filter - array |
212 | - if (is_array($result)) { |
|
212 | + if (is_array ($result)) { |
|
213 | 213 | foreach ($result as $m=>$r) { |
214 | 214 | foreach ($r as $k=>$v) { |
215 | 215 | if ($k == $this->_params->filter_by) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | # null? |
237 | - if (sizeof($result)==0) { $this->Response->throw_exception(404, 'No results (filter applied)'); } |
|
237 | + if (sizeof ($result) == 0) { $this->Response->throw_exception (404, 'No results (filter applied)'); } |
|
238 | 238 | |
239 | 239 | # result |
240 | 240 | return $result; |
@@ -249,17 +249,17 @@ discard block |
||
249 | 249 | */ |
250 | 250 | protected function validate_filter_by ($result) { |
251 | 251 | // validate filter |
252 | - if (is_array($result)) { $result_tmp = $result[0]; } |
|
253 | - else { $result_tmp = $result; } |
|
252 | + if (is_array ($result)) { $result_tmp = $result[0]; } |
|
253 | + else { $result_tmp = $result; } |
|
254 | 254 | |
255 | 255 | $error = true; |
256 | 256 | foreach ($result_tmp as $k=>$v) { |
257 | - if ($k==$this->_params->filter_by) { |
|
257 | + if ($k == $this->_params->filter_by) { |
|
258 | 258 | $error = false; |
259 | 259 | } |
260 | 260 | } |
261 | 261 | // die |
262 | - if ($error) { $this->Response->throw_exception(400, 'Invalid filter value'); } |
|
262 | + if ($error) { $this->Response->throw_exception (400, 'Invalid filter value'); } |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -270,26 +270,26 @@ discard block |
||
270 | 270 | * @param mixed $controller |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - protected function add_links ($result, $controller=null) { |
|
273 | + protected function add_links ($result, $controller = null) { |
|
274 | 274 | // lower controller |
275 | - $controller = strtolower($controller); |
|
275 | + $controller = strtolower ($controller); |
|
276 | 276 | |
277 | 277 | // multiple options |
278 | - if(is_array($result)) { |
|
279 | - foreach($result as $k=>$r) { |
|
278 | + if (is_array ($result)) { |
|
279 | + foreach ($result as $k=>$r) { |
|
280 | 280 | // fix for Vlans and vrfs |
281 | - if($controller=="vlans") { $r->id = $r->vlanId; } |
|
282 | - if($controller=="tools/vlans") { $r->id = $r->vlanId; } |
|
283 | - if($controller=="vrfs") { $r->id = $r->vrfId; } |
|
284 | - if($this->_params->id=="deviceTypes") { $r->id = $r->tid; } |
|
281 | + if ($controller == "vlans") { $r->id = $r->vlanId; } |
|
282 | + if ($controller == "tools/vlans") { $r->id = $r->vlanId; } |
|
283 | + if ($controller == "vrfs") { $r->id = $r->vrfId; } |
|
284 | + if ($this->_params->id == "deviceTypes") { $r->id = $r->tid; } |
|
285 | 285 | |
286 | - $m=0; |
|
286 | + $m = 0; |
|
287 | 287 | // custom links |
288 | 288 | $custom_links = $this->define_links ($controller); |
289 | - if($custom_links!==false) { |
|
290 | - foreach($this->define_links ($controller) as $link=>$method) { |
|
289 | + if ($custom_links !== false) { |
|
290 | + foreach ($this->define_links ($controller) as $link=>$method) { |
|
291 | 291 | // self only ! |
292 | - if ($link=="self") { |
|
292 | + if ($link == "self") { |
|
293 | 293 | $result[$k]->links[$m] = new stdClass (); |
294 | 294 | $result[$k]->links[$m]->rel = $link; |
295 | 295 | $result[$k]->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$r->id."/"; |
@@ -298,27 +298,27 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | // remove id for vlans |
301 | - if($controller=="vlans") { unset($r->id); } |
|
302 | - if($controller=="vrfs") { unset($r->id); } |
|
301 | + if ($controller == "vlans") { unset($r->id); } |
|
302 | + if ($controller == "vrfs") { unset($r->id); } |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | // single item |
306 | 306 | else { |
307 | 307 | // fix for Vlans and Vrfs |
308 | - if($controller=="vlans") { $result->id = $result->vlanId; } |
|
309 | - if($controller=="tools/vlans") { $result->id = $result->vlanId; } |
|
310 | - if($controller=="vrfs") { $result->id = $result->vrfId; } |
|
311 | - if($this->_params->id=="deviceTypes") { $result->id = $result->tid; } |
|
308 | + if ($controller == "vlans") { $result->id = $result->vlanId; } |
|
309 | + if ($controller == "tools/vlans") { $result->id = $result->vlanId; } |
|
310 | + if ($controller == "vrfs") { $result->id = $result->vrfId; } |
|
311 | + if ($this->_params->id == "deviceTypes") { $result->id = $result->tid; } |
|
312 | 312 | |
313 | - $m=0; |
|
313 | + $m = 0; |
|
314 | 314 | // custom links |
315 | 315 | $custom_links = $this->define_links ($controller); |
316 | - if($custom_links!==false) { |
|
317 | - foreach($this->define_links ($controller) as $link=>$method) { |
|
316 | + if ($custom_links !== false) { |
|
317 | + foreach ($this->define_links ($controller) as $link=>$method) { |
|
318 | 318 | $result->links[$m] = new stdClass (); |
319 | 319 | $result->links[$m]->rel = $link; |
320 | 320 | // self ? |
321 | - if ($link=="self") |
|
321 | + if ($link == "self") |
|
322 | 322 | $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/"; |
323 | 323 | else |
324 | 324 | $result->links[$m]->href = "/api/".$this->_params->app_id."/$controller/".$result->id."/$link/"; |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | // remove id for vlans |
332 | - if($controller=="vlans") { unset($result->id); } |
|
333 | - if($controller=="vrfs") { unset($result->id); } |
|
332 | + if ($controller == "vlans") { unset($result->id); } |
|
333 | + if ($controller == "vrfs") { unset($result->id); } |
|
334 | 334 | } |
335 | 335 | # return |
336 | 336 | return $result; |
@@ -345,17 +345,17 @@ discard block |
||
345 | 345 | */ |
346 | 346 | private function define_links ($controller) { |
347 | 347 | // init |
348 | - $result = array(); |
|
348 | + $result = array (); |
|
349 | 349 | // sections |
350 | - if($controller=="sections") { |
|
351 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
352 | - $result["subnets"] = array ("GET"); |
|
350 | + if ($controller == "sections") { |
|
351 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
352 | + $result["subnets"] = array ("GET"); |
|
353 | 353 | // return |
354 | 354 | return $result; |
355 | 355 | } |
356 | 356 | // subnets |
357 | - elseif($controller=="subnets") { |
|
358 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
357 | + elseif ($controller == "subnets") { |
|
358 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
359 | 359 | $result["addresses"] = array ("GET"); |
360 | 360 | $result["usage"] = array ("GET"); |
361 | 361 | $result["first_free"] = array ("GET"); |
@@ -368,86 +368,86 @@ discard block |
||
368 | 368 | return $result; |
369 | 369 | } |
370 | 370 | // addresses |
371 | - elseif($controller=="addresses") { |
|
372 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
371 | + elseif ($controller == "addresses") { |
|
372 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
373 | 373 | $result["ping"] = array ("GET"); |
374 | 374 | // return |
375 | 375 | return $result; |
376 | 376 | } |
377 | 377 | // tags |
378 | - elseif($controller=="addresses/tags") { |
|
379 | - $result["self"] = array ("GET"); |
|
380 | - $result["addresses"] = array ("GET"); |
|
378 | + elseif ($controller == "addresses/tags") { |
|
379 | + $result["self"] = array ("GET"); |
|
380 | + $result["addresses"] = array ("GET"); |
|
381 | 381 | // return |
382 | 382 | return $result; |
383 | 383 | } |
384 | 384 | // tools - devices |
385 | - elseif($controller=="tools/devices") { |
|
386 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
387 | - $result["addresses"] = array ("GET"); |
|
385 | + elseif ($controller == "tools/devices") { |
|
386 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
387 | + $result["addresses"] = array ("GET"); |
|
388 | 388 | // return |
389 | 389 | return $result; |
390 | 390 | } |
391 | 391 | // tools - devices |
392 | - elseif($controller=="tools/devicetypes") { |
|
393 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
394 | - $result["devices"] = array ("GET"); |
|
392 | + elseif ($controller == "tools/devicetypes") { |
|
393 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
394 | + $result["devices"] = array ("GET"); |
|
395 | 395 | // return |
396 | 396 | return $result; |
397 | 397 | } |
398 | 398 | // tools - tags |
399 | - elseif($controller=="tools/iptags") { |
|
400 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
401 | - $result["addresses"] = array ("GET"); |
|
399 | + elseif ($controller == "tools/iptags") { |
|
400 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
401 | + $result["addresses"] = array ("GET"); |
|
402 | 402 | // return |
403 | 403 | return $result; |
404 | 404 | } |
405 | 405 | // tools - tags |
406 | - elseif($controller=="tools/vlans") { |
|
407 | - $result["self"] = array ("GET"); |
|
408 | - $result["subnets"] = array ("GET"); |
|
406 | + elseif ($controller == "tools/vlans") { |
|
407 | + $result["self"] = array ("GET"); |
|
408 | + $result["subnets"] = array ("GET"); |
|
409 | 409 | // return |
410 | 410 | return $result; |
411 | 411 | } |
412 | 412 | // tools - tags |
413 | - elseif($controller=="tools/vrf") { |
|
414 | - $result["self"] = array ("GET"); |
|
415 | - $result["subnets"] = array ("GET"); |
|
413 | + elseif ($controller == "tools/vrf") { |
|
414 | + $result["self"] = array ("GET"); |
|
415 | + $result["subnets"] = array ("GET"); |
|
416 | 416 | // return |
417 | 417 | return $result; |
418 | 418 | } |
419 | 419 | // tags |
420 | - elseif($controller=="iptags") { |
|
421 | - $result["self"] = array ("GET"); |
|
422 | - $result["addresses"] = array ("GET"); |
|
420 | + elseif ($controller == "iptags") { |
|
421 | + $result["self"] = array ("GET"); |
|
422 | + $result["addresses"] = array ("GET"); |
|
423 | 423 | // return |
424 | 424 | return $result; |
425 | 425 | } |
426 | 426 | // tags |
427 | - elseif($controller=="devices") { |
|
428 | - $result["self"] = array ("GET"); |
|
429 | - $result["addresses"] = array ("GET"); |
|
427 | + elseif ($controller == "devices") { |
|
428 | + $result["self"] = array ("GET"); |
|
429 | + $result["addresses"] = array ("GET"); |
|
430 | 430 | // return |
431 | 431 | return $result; |
432 | 432 | } |
433 | 433 | // vlan domains |
434 | - elseif($controller=="l2domains") { |
|
435 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
436 | - $result["vlans"] = array ("GET"); |
|
434 | + elseif ($controller == "l2domains") { |
|
435 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
436 | + $result["vlans"] = array ("GET"); |
|
437 | 437 | // return |
438 | 438 | return $result; |
439 | 439 | } |
440 | 440 | // vlans |
441 | - elseif($controller=="vlans") { |
|
442 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
443 | - $result["subnets"] = array ("GET"); |
|
441 | + elseif ($controller == "vlans") { |
|
442 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
443 | + $result["subnets"] = array ("GET"); |
|
444 | 444 | // return |
445 | 445 | return $result; |
446 | 446 | } |
447 | 447 | // vrfs |
448 | - elseif($controller=="vrfs") { |
|
449 | - $result["self"] = array ("GET","POST","DELETE","PATCH"); |
|
450 | - $result["subnets"] = array ("GET"); |
|
448 | + elseif ($controller == "vrfs") { |
|
449 | + $result["self"] = array ("GET", "POST", "DELETE", "PATCH"); |
|
450 | + $result["subnets"] = array ("GET"); |
|
451 | 451 | // return |
452 | 452 | return $result; |
453 | 453 | } |
@@ -465,22 +465,22 @@ discard block |
||
465 | 465 | */ |
466 | 466 | protected function transform_address ($result) { |
467 | 467 | // multiple options |
468 | - if (is_array($result)) { |
|
469 | - foreach($result as $k=>$r) { |
|
468 | + if (is_array ($result)) { |
|
469 | + foreach ($result as $k=>$r) { |
|
470 | 470 | // remove IP |
471 | - if (isset($r->ip)) { unset($r->ip); } |
|
471 | + if (isset($r->ip)) { unset($r->ip); } |
|
472 | 472 | // transform |
473 | - if (isset($r->subnet)) { $r->subnet = $this->Subnets->transform_address ($r->subnet, "dotted"); } |
|
474 | - elseif (isset($r->ip_addr)) { $r->ip_addr = $this->Subnets->transform_address ($r->ip_addr, "dotted"); } |
|
473 | + if (isset($r->subnet)) { $r->subnet = $this->Subnets->transform_address ($r->subnet, "dotted"); } |
|
474 | + elseif (isset($r->ip_addr)) { $r->ip_addr = $this->Subnets->transform_address ($r->ip_addr, "dotted"); } |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | // single item |
478 | 478 | else { |
479 | 479 | // remove IP |
480 | - if (isset($result->ip)) { unset($result->ip); } |
|
480 | + if (isset($result->ip)) { unset($result->ip); } |
|
481 | 481 | // transform |
482 | - if (isset($result->subnet)) { $result->subnet = $this->Subnets->transform_address ($result->subnet, "dotted"); } |
|
483 | - elseif (isset($result->ip_addr)) { $result->ip_addr = $this->Subnets->transform_address ($result->ip_addr, "dotted"); } |
|
482 | + if (isset($result->subnet)) { $result->subnet = $this->Subnets->transform_address ($result->subnet, "dotted"); } |
|
483 | + elseif (isset($result->ip_addr)) { $result->ip_addr = $this->Subnets->transform_address ($result->ip_addr, "dotted"); } |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | # return |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | */ |
496 | 496 | protected function validate_keys () { |
497 | 497 | // init values |
498 | - $values = array(); |
|
498 | + $values = array (); |
|
499 | 499 | // loop |
500 | - foreach($this->_params as $pk=>$pv) { |
|
501 | - if(!in_array($pk, $this->valid_keys)) { $this->Response->throw_exception(400, 'Invalid request key '.$pk); } |
|
500 | + foreach ($this->_params as $pk=>$pv) { |
|
501 | + if (!in_array ($pk, $this->valid_keys)) { $this->Response->throw_exception (400, 'Invalid request key '.$pk); } |
|
502 | 502 | // set parameters |
503 | 503 | else { |
504 | - if(!in_array($pk, $this->controller_keys)) { |
|
504 | + if (!in_array ($pk, $this->controller_keys)) { |
|
505 | 505 | $values[$pk] = $pv; |
506 | 506 | } |
507 | 507 | } |
@@ -519,9 +519,9 @@ discard block |
||
519 | 519 | * @return void |
520 | 520 | */ |
521 | 521 | protected function validate_options_request () { |
522 | - foreach($this->_params as $key=>$val) { |
|
523 | - if(!in_array($key, array("app_id", "controller", "id"))) { |
|
524 | - { $this->Response->throw_exception(400, 'Invalid request key parameter '.$key); } |
|
522 | + foreach ($this->_params as $key=>$val) { |
|
523 | + if (!in_array ($key, array ("app_id", "controller", "id"))) { |
|
524 | + { $this->Response->throw_exception (400, 'Invalid request key parameter '.$key); } |
|
525 | 525 | } |
526 | 526 | } |
527 | 527 | } |
@@ -535,24 +535,24 @@ discard block |
||
535 | 535 | */ |
536 | 536 | protected function remove_folders ($result) { |
537 | 537 | // must be subnets |
538 | - if($this->_params->controller!="subnets") { |
|
538 | + if ($this->_params->controller != "subnets") { |
|
539 | 539 | return $result; |
540 | 540 | } |
541 | 541 | else { |
542 | 542 | // multiple options |
543 | - if (is_array($result)) { |
|
544 | - foreach($result as $k=>$r) { |
|
543 | + if (is_array ($result)) { |
|
544 | + foreach ($result as $k=>$r) { |
|
545 | 545 | // remove |
546 | - if($r->isFolder=="1") { unset($r); } |
|
546 | + if ($r->isFolder == "1") { unset($r); } |
|
547 | 547 | } } |
548 | 548 | // single item |
549 | 549 | else { |
550 | 550 | // remove |
551 | - if($result->isFolder=="1") { unset($result); } |
|
551 | + if ($result->isFolder == "1") { unset($result); } |
|
552 | 552 | } |
553 | 553 | # return |
554 | - if($result===false) { $this->Response->throw_exception(404, "No subnets found"); } |
|
555 | - else { return $result; } |
|
554 | + if ($result === false) { $this->Response->throw_exception (404, "No subnets found"); } |
|
555 | + else { return $result; } |
|
556 | 556 | } } |
557 | 557 | |
558 | 558 | /** |
@@ -564,24 +564,24 @@ discard block |
||
564 | 564 | */ |
565 | 565 | protected function remove_subnets ($result) { |
566 | 566 | // must be subnets |
567 | - if($this->_params->controller!="folders") { |
|
567 | + if ($this->_params->controller != "folders") { |
|
568 | 568 | return $result; |
569 | 569 | } |
570 | 570 | else { |
571 | 571 | // multiple options |
572 | - if (is_array($result)) { |
|
573 | - foreach($result as $k=>$r) { |
|
572 | + if (is_array ($result)) { |
|
573 | + foreach ($result as $k=>$r) { |
|
574 | 574 | // remove |
575 | - if($r->isFolder!="1") { unset($r); } |
|
575 | + if ($r->isFolder != "1") { unset($r); } |
|
576 | 576 | } } |
577 | 577 | // single item |
578 | 578 | else { |
579 | 579 | // remove |
580 | - if($result->isFolder!="1") { unset($result); } |
|
580 | + if ($result->isFolder != "1") { unset($result); } |
|
581 | 581 | } |
582 | 582 | # return |
583 | - if($result===NULL) { $this->Response->throw_exception(404, "No folders found"); } |
|
584 | - else { return $result; } |
|
583 | + if ($result === NULL) { $this->Response->throw_exception (404, "No folders found"); } |
|
584 | + else { return $result; } |
|
585 | 585 | } } |
586 | 586 | |
587 | 587 | |
@@ -597,17 +597,17 @@ discard block |
||
597 | 597 | */ |
598 | 598 | protected function remap_keys ($result = null, $controller = null) { |
599 | 599 | // define keys array |
600 | - $this->keys = array("switch"=>"deviceId", "state"=>"tag", "ip_addr"=>"ip", "dns_name"=>"hostname"); |
|
600 | + $this->keys = array ("switch"=>"deviceId", "state"=>"tag", "ip_addr"=>"ip", "dns_name"=>"hostname"); |
|
601 | 601 | |
602 | 602 | // exceptions |
603 | - if($controller=="vlans") { $this->keys['vlanId'] = "id"; } |
|
604 | - if($controller=="vrfs") { $this->keys['vrfId'] = "id"; } |
|
605 | - if($this->_params->controller=="tools" && $this->_params->id=="deviceTypes") { $this->keys['tid'] = "id"; } |
|
603 | + if ($controller == "vlans") { $this->keys['vlanId'] = "id"; } |
|
604 | + if ($controller == "vrfs") { $this->keys['vrfId'] = "id"; } |
|
605 | + if ($this->_params->controller == "tools" && $this->_params->id == "deviceTypes") { $this->keys['tid'] = "id"; } |
|
606 | 606 | |
607 | 607 | // POST / PATCH |
608 | - if ($_SERVER['REQUEST_METHOD']=="POST" || $_SERVER['REQUEST_METHOD']=="PATCH") { return $this->remap_update_keys (); } |
|
608 | + if ($_SERVER['REQUEST_METHOD'] == "POST" || $_SERVER['REQUEST_METHOD'] == "PATCH") { return $this->remap_update_keys (); } |
|
609 | 609 | // GET |
610 | - elseif ($_SERVER['REQUEST_METHOD']=="GET") { return $this->remap_result_keys ($result); } |
|
610 | + elseif ($_SERVER['REQUEST_METHOD'] == "GET") { return $this->remap_result_keys ($result); } |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -618,9 +618,9 @@ discard block |
||
618 | 618 | */ |
619 | 619 | private function remap_update_keys () { |
620 | 620 | // loop |
621 | - foreach($this->keys as $k=>$v) { |
|
621 | + foreach ($this->keys as $k=>$v) { |
|
622 | 622 | // match |
623 | - if(array_key_exists($v, $this->_params)) { |
|
623 | + if (array_key_exists ($v, $this->_params)) { |
|
624 | 624 | // replace |
625 | 625 | $this->_params->$k = $this->_params->$v; |
626 | 626 | // remove |
@@ -638,12 +638,12 @@ discard block |
||
638 | 638 | */ |
639 | 639 | private function remap_result_keys ($result) { |
640 | 640 | # single |
641 | - if(!is_array($result)) { |
|
641 | + if (!is_array ($result)) { |
|
642 | 642 | // params |
643 | 643 | $result_remapped = new StdClass (); |
644 | 644 | // search and replace |
645 | - foreach($result as $k=>$v) { |
|
646 | - if(array_key_exists($k, $this->keys)) { |
|
645 | + foreach ($result as $k=>$v) { |
|
646 | + if (array_key_exists ($k, $this->keys)) { |
|
647 | 647 | // replace |
648 | 648 | $key = $this->keys[$k]; |
649 | 649 | $result_remapped->$key = $v; |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | # array |
657 | 657 | else { |
658 | 658 | // create a new array for the remapped data |
659 | - $result_remapped = array(); |
|
659 | + $result_remapped = array (); |
|
660 | 660 | |
661 | 661 | // loop |
662 | 662 | foreach ($result as $m=>$r) { |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | $result_remapped[$m] = new StdClass (); |
665 | 665 | |
666 | 666 | // search and replace |
667 | - foreach($r as $k=>$v) { |
|
668 | - if(array_key_exists($k, $this->keys)) { |
|
667 | + foreach ($r as $k=>$v) { |
|
668 | + if (array_key_exists ($k, $this->keys)) { |
|
669 | 669 | // replace |
670 | 670 | $key_val = $this->keys[$k]; |
671 | 671 | $result_remapped[$m]->$key_val = $v; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | # execute update |
164 | 164 | if(!$this->Admin->object_modify ("vrf", "add", "vrfId", $values)) |
165 | 165 | { $this->Response->throw_exception(500, "VRF creation failed"); } |
166 | - else { |
|
166 | + else { |
|
167 | 167 | //set result |
168 | 168 | return array("code"=>201, "data"=>"VRF created", "location"=>"/api/".$this->_params->app_id."/vrfs/".$this->Admin->lastId."/"); |
169 | 169 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | # execute update |
196 | 196 | if(!$this->Admin->object_modify ("vrf", "edit", "vrfId", $values)) |
197 | 197 | { $this->Response->throw_exception(500, "Vrf edit failed"); } |
198 | - else { |
|
198 | + else { |
|
199 | 199 | //set result |
200 | 200 | return array("code"=>200, "data"=>"VRF updated"); |
201 | 201 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | # execute delete |
223 | 223 | if(!$this->Admin->object_modify ("vrf", "delete", "vrfId", $values)) |
224 | 224 | { $this->Response->throw_exception(500, "Vrf delete failed"); } |
225 | - else { |
|
225 | + else { |
|
226 | 226 | // delete all references |
227 | 227 | $this->Admin->remove_object_references ("subnets", "vrfId", $this->_params->id); |
228 | 228 |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @param mixed $params // post/get values |
68 | 68 | * @param class $Response |
69 | 69 | */ |
70 | - public function __construct($Database, $Tools, $params, $Response) { |
|
70 | + public function __construct ($Database, $Tools, $params, $Response) { |
|
71 | 71 | $this->Database = $Database; |
72 | - $this->Tools = $Tools; |
|
72 | + $this->Tools = $Tools; |
|
73 | 73 | $this->_params = $params; |
74 | 74 | $this->Response = $Response; |
75 | 75 | // init required objects |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | $this->validate_options_request (); |
96 | 96 | |
97 | 97 | // methods |
98 | - $result['methods'] = array( |
|
99 | - array("href"=>"/api/".$this->_params->app_id."/vrfs/", "methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))), |
|
100 | - array("href"=>"/api/".$this->_params->app_id."/vrfs/{id}/", "methods"=>array(array("rel"=>"read", "method"=>"GET"), |
|
101 | - array("rel"=>"create", "method"=>"POST"), |
|
102 | - array("rel"=>"update", "method"=>"PATCH"), |
|
103 | - array("rel"=>"delete", "method"=>"DELETE"))), |
|
98 | + $result['methods'] = array ( |
|
99 | + array ("href"=>"/api/".$this->_params->app_id."/vrfs/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))), |
|
100 | + array ("href"=>"/api/".$this->_params->app_id."/vrfs/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"), |
|
101 | + array ("rel"=>"create", "method"=>"POST"), |
|
102 | + array ("rel"=>"update", "method"=>"PATCH"), |
|
103 | + array ("rel"=>"delete", "method"=>"DELETE"))), |
|
104 | 104 | ); |
105 | 105 | # result |
106 | - return array("code"=>200, "data"=>$result); |
|
106 | + return array ("code"=>200, "data"=>$result); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | if (!isset($this->_params->id)) { |
129 | 129 | $result = $this->Tools->fetch_all_objects ("vrf", 'vrfId'); |
130 | 130 | // check result |
131 | - if($result===false) { $this->Response->throw_exception(404, 'No vrfs configured'); } |
|
132 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
131 | + if ($result === false) { $this->Response->throw_exception (404, 'No vrfs configured'); } |
|
132 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
133 | 133 | } |
134 | 134 | // subnets |
135 | 135 | elseif (isset($this->_params->id2)) { |
@@ -140,22 +140,22 @@ discard block |
||
140 | 140 | // fetch |
141 | 141 | $result = $this->Tools->fetch_multiple_objects ("subnets", "vrfId", $this->_params->id, 'subnet', true); |
142 | 142 | // add gateway if present |
143 | - if($result!=false) { |
|
143 | + if ($result != false) { |
|
144 | 144 | foreach ($result as $k=>$r) { |
145 | 145 | $gateway = $this->read_subnet_gateway ($r->id); |
146 | - if ( $gateway!== false) { |
|
146 | + if ($gateway !== false) { |
|
147 | 147 | $result[$k]->gatewayId = $gateway->id; |
148 | 148 | } |
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | 152 | // check result |
153 | - if($result===false) { $this->Response->throw_exception(404, 'No subnets belonging to this vrf'); } |
|
154 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
153 | + if ($result === false) { $this->Response->throw_exception (404, 'No subnets belonging to this vrf'); } |
|
154 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
155 | 155 | } |
156 | 156 | // error |
157 | 157 | else { |
158 | - { $this->Response->throw_exception(400, "Invalid identifier"); } |
|
158 | + { $this->Response->throw_exception (400, "Invalid identifier"); } |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | // by id |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | // fetch |
166 | 166 | $result = $this->Tools->fetch_object ("vrf", "vrfId", $this->_params->id); |
167 | 167 | // check result |
168 | - if($result==NULL) { $this->Response->throw_exception(404, "VRF not found"); } |
|
169 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
168 | + if ($result == NULL) { $this->Response->throw_exception (404, "VRF not found"); } |
|
169 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | $this->validate_vrf_edit (); |
203 | 203 | |
204 | 204 | # execute update |
205 | - if(!$this->Admin->object_modify ("vrf", "add", "vrfId", $values)) |
|
206 | - { $this->Response->throw_exception(500, "VRF creation failed"); } |
|
205 | + if (!$this->Admin->object_modify ("vrf", "add", "vrfId", $values)) |
|
206 | + { $this->Response->throw_exception (500, "VRF creation failed"); } |
|
207 | 207 | else { |
208 | 208 | //set result |
209 | - return array("code"=>201, "data"=>"VRF created", "location"=>"/api/".$this->_params->app_id."/vrfs/".$this->Admin->lastId."/"); |
|
209 | + return array ("code"=>201, "data"=>"VRF created", "location"=>"/api/".$this->_params->app_id."/vrfs/".$this->Admin->lastId."/"); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | $values = $this->validate_keys (); |
235 | 235 | |
236 | 236 | # execute update |
237 | - if(!$this->Admin->object_modify ("vrf", "edit", "vrfId", $values)) |
|
238 | - { $this->Response->throw_exception(500, "Vrf edit failed"); } |
|
237 | + if (!$this->Admin->object_modify ("vrf", "edit", "vrfId", $values)) |
|
238 | + { $this->Response->throw_exception (500, "Vrf edit failed"); } |
|
239 | 239 | else { |
240 | 240 | //set result |
241 | - return array("code"=>200, "data"=>"VRF updated"); |
|
241 | + return array ("code"=>200, "data"=>"VRF updated"); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
@@ -258,18 +258,18 @@ discard block |
||
258 | 258 | $this->validate_vrf (); |
259 | 259 | |
260 | 260 | # set variables for update |
261 | - $values = array(); |
|
261 | + $values = array (); |
|
262 | 262 | $values["vrfId"] = $this->_params->id; |
263 | 263 | |
264 | 264 | # execute delete |
265 | - if(!$this->Admin->object_modify ("vrf", "delete", "vrfId", $values)) |
|
266 | - { $this->Response->throw_exception(500, "Vrf delete failed"); } |
|
265 | + if (!$this->Admin->object_modify ("vrf", "delete", "vrfId", $values)) |
|
266 | + { $this->Response->throw_exception (500, "Vrf delete failed"); } |
|
267 | 267 | else { |
268 | 268 | // delete all references |
269 | 269 | $this->Admin->remove_object_references ("subnets", "vrfId", $this->_params->id); |
270 | 270 | |
271 | 271 | // set result |
272 | - return array("code"=>200, "data"=>"VRF deleted"); |
|
272 | + return array ("code"=>200, "data"=>"VRF deleted"); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -294,11 +294,11 @@ discard block |
||
294 | 294 | */ |
295 | 295 | private function validate_vrf () { |
296 | 296 | // validate id |
297 | - if(!isset($this->_params->id)) { $this->Response->throw_exception(400, "Vrf Id is required"); } |
|
297 | + if (!isset($this->_params->id)) { $this->Response->throw_exception (400, "Vrf Id is required"); } |
|
298 | 298 | // validate number |
299 | - if(!is_numeric($this->_params->id)) { $this->Response->throw_exception(400, "Vrf Id must be numeric"); } |
|
299 | + if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Vrf Id must be numeric"); } |
|
300 | 300 | // check that it exists |
301 | - if($this->Tools->fetch_object ("vrf", "vrfId", $this->_params->id) === false ) { $this->Response->throw_exception(400, "Invalid VRF id"); } |
|
301 | + if ($this->Tools->fetch_object ("vrf", "vrfId", $this->_params->id) === false) { $this->Response->throw_exception (400, "Invalid VRF id"); } |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -310,20 +310,20 @@ discard block |
||
310 | 310 | */ |
311 | 311 | private function validate_vrf_edit () { |
312 | 312 | // check for POST method |
313 | - if($_SERVER['REQUEST_METHOD']=="POST") { |
|
313 | + if ($_SERVER['REQUEST_METHOD'] == "POST") { |
|
314 | 314 | // check name |
315 | - if(strlen($this->_params->name)==0) { $this->Response->throw_exception(400, "VRF name is required"); } |
|
315 | + if (strlen ($this->_params->name) == 0) { $this->Response->throw_exception (400, "VRF name is required"); } |
|
316 | 316 | // check that it exists |
317 | - if($this->Tools->fetch_object ("vrf", "name", $this->_params->name) !== false ) { $this->Response->throw_exception(400, "VRF with that name already exists"); } |
|
317 | + if ($this->Tools->fetch_object ("vrf", "name", $this->_params->name) !== false) { $this->Response->throw_exception (400, "VRF with that name already exists"); } |
|
318 | 318 | } |
319 | 319 | // update check |
320 | 320 | else { |
321 | 321 | // old values |
322 | 322 | $vrf_old = $this->Tools->fetch_object ("vrf", "vrfId", $this->_params->id); |
323 | 323 | |
324 | - if(isset($this->_params->name)) { |
|
324 | + if (isset($this->_params->name)) { |
|
325 | 325 | if ($this->_params->name != $vrf_old->name) { |
326 | - if($this->Tools->fetch_object ("vrf", "name", $this->_params->name)) { $this->Response->throw_exception(400, "VRF with that name already exists"); } |
|
326 | + if ($this->Tools->fetch_object ("vrf", "name", $this->_params->name)) { $this->Response->throw_exception (400, "VRF with that name already exists"); } |
|
327 | 327 | } |
328 | 328 | } |
329 | 329 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | # execute update |
249 | 249 | if(!$this->Subnets->modify_subnet ("edit", $values)) |
250 | 250 | { $this->Response->throw_exception(500, 'Subnet update failed'); } |
251 | - else { |
|
251 | + else { |
|
252 | 252 | return array("code"=>200, "data"=>"Subnet updated"); |
253 | 253 | } |
254 | 254 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | # execute update |
289 | 289 | if(!$this->Subnets->modify_subnet ("delete", $values)) |
290 | 290 | { $this->Response->throw_exception(500, "Failed to delete subnet"); } |
291 | - else { |
|
291 | + else { |
|
292 | 292 | //set result |
293 | 293 | return array("code"=>200, "data"=>"Subnet deleted"); |
294 | 294 | } |
@@ -413,7 +413,8 @@ discard block |
||
413 | 413 | # fetch all addresses and calculate usage |
414 | 414 | if($slaves) { |
415 | 415 | $addresses = $this->Addresses->fetch_subnet_addresses_recursive ($this->_params->id, false); |
416 | - } else { |
|
416 | + } |
|
417 | + else { |
|
417 | 418 | $addresses = $this->Addresses->fetch_subnet_addresses ($this->_params->id); |
418 | 419 | } |
419 | 420 | // calculate |
@@ -726,7 +727,7 @@ discard block |
||
726 | 727 | $this->settings = $this->Tools->fetch_object ("settings", "id", 1); |
727 | 728 | |
728 | 729 | # get master subnet details for folder overrides |
729 | - if($this->_params->masterSubnetId!=0) { |
|
730 | + if($this->_params->masterSubnetId!=0) { |
|
730 | 731 | $master_section = $this->Subnets->fetch_subnet(null, $this->_params->masterSubnetId); |
731 | 732 | if($master_section->isFolder==1) { $parent_is_folder = true; } |
732 | 733 | else { $parent_is_folder = false; } |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | * @param class $Tools |
82 | 82 | * @param mixed $params // post/get values |
83 | 83 | */ |
84 | - public function __construct($Database, $Tools, $params, $Response) { |
|
84 | + public function __construct ($Database, $Tools, $params, $Response) { |
|
85 | 85 | $this->Database = $Database; |
86 | - $this->Tools = $Tools; |
|
86 | + $this->Tools = $Tools; |
|
87 | 87 | $this->_params = $params; |
88 | 88 | $this->Response = $Response; |
89 | 89 | // init required objects |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | $this->validate_options_request (); |
109 | 109 | |
110 | 110 | // methods |
111 | - $result = array(); |
|
112 | - $result['methods'] = array( |
|
113 | - array("href"=>"/api/".$this->_params->app_id."/subnets/", "methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))), |
|
114 | - array("href"=>"/api/".$this->_params->app_id."/subnets/{id}/", "methods"=>array(array("rel"=>"read", "method"=>"GET"), |
|
115 | - array("rel"=>"create", "method"=>"POST"), |
|
116 | - array("rel"=>"update", "method"=>"PATCH"), |
|
117 | - array("rel"=>"delete", "method"=>"DELETE"))), |
|
111 | + $result = array (); |
|
112 | + $result['methods'] = array ( |
|
113 | + array ("href"=>"/api/".$this->_params->app_id."/subnets/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))), |
|
114 | + array ("href"=>"/api/".$this->_params->app_id."/subnets/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"), |
|
115 | + array ("rel"=>"create", "method"=>"POST"), |
|
116 | + array ("rel"=>"update", "method"=>"PATCH"), |
|
117 | + array ("rel"=>"delete", "method"=>"DELETE"))), |
|
118 | 118 | ); |
119 | 119 | # result |
120 | - return array("code"=>200, "data"=>$result); |
|
120 | + return array ("code"=>200, "data"=>$result); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function POST () { |
137 | 137 | # add required parameters |
138 | - if(!isset($this->_params->isFolder)) { $this->_params->isFolder = "0"; } |
|
139 | - elseif($this->_params->isFolder==1) { unset($this->_params->subnet, $this->_params->mask); } |
|
138 | + if (!isset($this->_params->isFolder)) { $this->_params->isFolder = "0"; } |
|
139 | + elseif ($this->_params->isFolder == 1) { unset($this->_params->subnet, $this->_params->mask); } |
|
140 | 140 | |
141 | 141 | # validate parameters |
142 | 142 | $this->validate_create_parameters (); |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | $values = $this->validate_keys (); |
146 | 146 | |
147 | 147 | # transform subnet to decimal format |
148 | - $values['subnet'] = $this->Addresses->transform_address($values['subnet'] ,"decimal"); |
|
148 | + $values['subnet'] = $this->Addresses->transform_address ($values['subnet'], "decimal"); |
|
149 | 149 | |
150 | 150 | # execute |
151 | - if(!$this->Subnets->modify_subnet ("add", $values)) { |
|
152 | - $this->Response->throw_exception(500, "Failed to create subnet"); |
|
151 | + if (!$this->Subnets->modify_subnet ("add", $values)) { |
|
152 | + $this->Response->throw_exception (500, "Failed to create subnet"); |
|
153 | 153 | } |
154 | 154 | else { |
155 | 155 | //set result |
156 | - return array("code"=>201, "data"=>"Subnet created", "location"=>"/api/".$this->_params->app_id."/subnets/".$this->Subnets->lastInsertId."/"); |
|
156 | + return array ("code"=>201, "data"=>"Subnet created", "location"=>"/api/".$this->_params->app_id."/subnets/".$this->Subnets->lastInsertId."/"); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | public function GET () { |
181 | 181 | // cidr check |
182 | 182 | // check if id2 is set ? |
183 | - if(isset($this->_params->id2)) { |
|
183 | + if (isset($this->_params->id2)) { |
|
184 | 184 | // is IP address provided |
185 | - if($this->_params->id=="cidr") { |
|
185 | + if ($this->_params->id == "cidr") { |
|
186 | 186 | $result = $this->read_search_subnet (); |
187 | 187 | // check result |
188 | - if($result==NULL) { $this->Response->throw_exception(404, "No subnets found"); } |
|
189 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
188 | + if ($result == NULL) { $this->Response->throw_exception (404, "No subnets found"); } |
|
189 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
190 | 190 | } |
191 | 191 | else { |
192 | 192 | // validate id |
@@ -194,48 +194,48 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // addresses in subnet |
197 | - if($this->_params->id2=="addresses") { |
|
197 | + if ($this->_params->id2 == "addresses") { |
|
198 | 198 | $result = $this->read_subnet_addresses (); |
199 | 199 | // check result |
200 | - if($result===false) { $this->Response->throw_exception(404, "No addresses found"); } |
|
201 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "addresses", true, true)); } |
|
200 | + if ($result === false) { $this->Response->throw_exception (404, "No addresses found"); } |
|
201 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "addresses", true, true)); } |
|
202 | 202 | } |
203 | 203 | // slaves |
204 | - elseif($this->_params->id2=="slaves") { |
|
204 | + elseif ($this->_params->id2 == "slaves") { |
|
205 | 205 | $result = $this->read_subnet_slaves (); |
206 | 206 | // check result |
207 | - if($result==NULL) { $this->Response->throw_exception(404, "No slaves"); } |
|
208 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
207 | + if ($result == NULL) { $this->Response->throw_exception (404, "No slaves"); } |
|
208 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
209 | 209 | } |
210 | 210 | // slaves-recursive |
211 | - elseif ($this->_params->id2=="slaves_recursive") { |
|
211 | + elseif ($this->_params->id2 == "slaves_recursive") { |
|
212 | 212 | $result = $this->read_subnet_slaves_recursive (); |
213 | 213 | // check result |
214 | - if($result==NULL) { $this->Response->throw_exception(404, "No slaves"); } |
|
215 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
214 | + if ($result == NULL) { $this->Response->throw_exception (404, "No slaves"); } |
|
215 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); } |
|
216 | 216 | } |
217 | 217 | // usage |
218 | - elseif ($this->_params->id2=="usage") { return array("code"=>200, "data"=>$this->subnet_usage ()); } |
|
218 | + elseif ($this->_params->id2 == "usage") { return array ("code"=>200, "data"=>$this->subnet_usage ()); } |
|
219 | 219 | // first available address |
220 | - elseif ($this->_params->id2=="first_free") { return array("code"=>200, "data"=>$this->subnet_first_free ()); } |
|
220 | + elseif ($this->_params->id2 == "first_free") { return array ("code"=>200, "data"=>$this->subnet_first_free ()); } |
|
221 | 221 | // fail |
222 | - else { $this->Response->throw_exception(400, 'Invalid request'); } |
|
222 | + else { $this->Response->throw_exception (400, 'Invalid request'); } |
|
223 | 223 | } |
224 | 224 | // custom fields |
225 | - elseif ($this->_params->id=="custom_fields") { |
|
225 | + elseif ($this->_params->id == "custom_fields") { |
|
226 | 226 | // check result |
227 | - if(sizeof($this->custom_fields)==0) { $this->Response->throw_exception(404, 'No custom fields defined'); } |
|
228 | - else { return array("code"=>200, "data"=>$this->custom_fields); } |
|
227 | + if (sizeof ($this->custom_fields) == 0) { $this->Response->throw_exception (404, 'No custom fields defined'); } |
|
228 | + else { return array ("code"=>200, "data"=>$this->custom_fields); } |
|
229 | 229 | } |
230 | 230 | // id |
231 | - elseif (is_numeric($this->_params->id)) { |
|
231 | + elseif (is_numeric ($this->_params->id)) { |
|
232 | 232 | $result = $this->read_subnet (); |
233 | 233 | // check result |
234 | - if($result==NULL) { $this->Response->throw_exception(404, "Invalid Id"); } |
|
235 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
234 | + if ($result == NULL) { $this->Response->throw_exception (404, "Invalid Id"); } |
|
235 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); } |
|
236 | 236 | } |
237 | 237 | // false |
238 | - else { $this->Response->throw_exception(404, 'Invalid Id'); } |
|
238 | + else { $this->Response->throw_exception (404, 'Invalid Id'); } |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | |
@@ -275,26 +275,26 @@ discard block |
||
275 | 275 | $this->validate_subnet_id (); |
276 | 276 | |
277 | 277 | // check if id2 is set > additional methods |
278 | - if(isset($this->_params->id2)) { |
|
278 | + if (isset($this->_params->id2)) { |
|
279 | 279 | // resize |
280 | - if($this->_params->id2=="resize") { return $this->subnet_resize (); } |
|
280 | + if ($this->_params->id2 == "resize") { return $this->subnet_resize (); } |
|
281 | 281 | // split |
282 | - elseif($this->_params->id2=="split") { return $this->subnet_split (); } |
|
282 | + elseif ($this->_params->id2 == "split") { return $this->subnet_split (); } |
|
283 | 283 | // error |
284 | - else { $this->Response->throw_exception(400, 'Invalid parameters'); } |
|
284 | + else { $this->Response->throw_exception (400, 'Invalid parameters'); } |
|
285 | 285 | } |
286 | 286 | // ok, normal update |
287 | 287 | else { |
288 | 288 | // new section |
289 | - if(isset($this->_params->sectionId)) { $this->validate_section (); } |
|
289 | + if (isset($this->_params->sectionId)) { $this->validate_section (); } |
|
290 | 290 | |
291 | 291 | // validate vlan and vrf |
292 | 292 | $this->validate_vlan (); |
293 | 293 | $this->validate_vrf (); |
294 | 294 | |
295 | 295 | // if subnet is provided die |
296 | - if(isset($this->_params->subnet)) { $this->Response->throw_exception(400, 'Subnet cannot be changed'); } |
|
297 | - if(isset($this->_params->mask)) { $this->Response->throw_exception(400, 'To change mask use resize method'); } |
|
296 | + if (isset($this->_params->subnet)) { $this->Response->throw_exception (400, 'Subnet cannot be changed'); } |
|
297 | + if (isset($this->_params->mask)) { $this->Response->throw_exception (400, 'To change mask use resize method'); } |
|
298 | 298 | |
299 | 299 | # check for valid keys |
300 | 300 | $values = $this->validate_keys (); |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | $values["id"] = $this->_params->id; |
303 | 303 | |
304 | 304 | # execute update |
305 | - if(!$this->Subnets->modify_subnet ("edit", $values)) |
|
306 | - { $this->Response->throw_exception(500, 'Subnet update failed'); } |
|
305 | + if (!$this->Subnets->modify_subnet ("edit", $values)) |
|
306 | + { $this->Response->throw_exception (500, 'Subnet update failed'); } |
|
307 | 307 | else { |
308 | - return array("code"=>200, "data"=>"Subnet updated"); |
|
308 | + return array ("code"=>200, "data"=>"Subnet updated"); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | } |
@@ -330,24 +330,24 @@ discard block |
||
330 | 330 | $this->validate_subnet_id (); |
331 | 331 | |
332 | 332 | // check if id2 is set > additional methods |
333 | - if(isset($this->_params->id2)) { |
|
333 | + if (isset($this->_params->id2)) { |
|
334 | 334 | // truncate |
335 | - if($this->_params->id2=="truncate") { return $this->subnet_truncate (); } |
|
335 | + if ($this->_params->id2 == "truncate") { return $this->subnet_truncate (); } |
|
336 | 336 | // error |
337 | - else { $this->Response->throw_exception(400, 'Invalid parameters'); } |
|
337 | + else { $this->Response->throw_exception (400, 'Invalid parameters'); } |
|
338 | 338 | } |
339 | 339 | // ok, delete subnet |
340 | 340 | else { |
341 | 341 | # set variables for delete |
342 | - $values = array(); |
|
342 | + $values = array (); |
|
343 | 343 | $values["id"] = $this->_params->id; |
344 | 344 | |
345 | 345 | # execute update |
346 | - if(!$this->Subnets->modify_subnet ("delete", $values)) |
|
347 | - { $this->Response->throw_exception(500, "Failed to delete subnet"); } |
|
346 | + if (!$this->Subnets->modify_subnet ("delete", $values)) |
|
347 | + { $this->Response->throw_exception (500, "Failed to delete subnet"); } |
|
348 | 348 | else { |
349 | 349 | //set result |
350 | - return array("code"=>200, "data"=>"Subnet deleted"); |
|
350 | + return array ("code"=>200, "data"=>"Subnet deleted"); |
|
351 | 351 | } |
352 | 352 | } |
353 | 353 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | // ok, try to truncate |
371 | 371 | $this->Subnets->modify_subnet ("truncate", (array) $this->_params); |
372 | 372 | //set result |
373 | - return array("code"=>200, "data"=>"Subnet truncated"); |
|
373 | + return array ("code"=>200, "data"=>"Subnet truncated"); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $this->validate_subnet_id (); |
391 | 391 | |
392 | 392 | // validate input parmeters |
393 | - if(!isset($this->_params->mask)) { $this->Response->throw_exception(400, "Subnet mask not provided"); } |
|
393 | + if (!isset($this->_params->mask)) { $this->Response->throw_exception (400, "Subnet mask not provided"); } |
|
394 | 394 | |
395 | 395 | // fetch old subnet |
396 | 396 | $old_subnet = $this->Subnets->fetch_subnet ("id", $this->_params->id); |
@@ -403,19 +403,19 @@ discard block |
||
403 | 403 | $subnet_new = $old_subnet->subnet; |
404 | 404 | } |
405 | 405 | else { |
406 | - $new_boundaries = $this->Subnets->get_network_boundaries ($this->Subnets->transform_address($old_subnet->subnet, "dotted"), $this->_params->mask); |
|
407 | - $subnet_new = $this->Subnets->transform_address($new_boundaries['network'], "decimal"); |
|
406 | + $new_boundaries = $this->Subnets->get_network_boundaries ($this->Subnets->transform_address ($old_subnet->subnet, "dotted"), $this->_params->mask); |
|
407 | + $subnet_new = $this->Subnets->transform_address ($new_boundaries['network'], "decimal"); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | # set update values |
411 | - $values = array("id"=>$this->_params->id, |
|
411 | + $values = array ("id"=>$this->_params->id, |
|
412 | 412 | "subnet"=>$subnet_new, |
413 | 413 | "mask"=>$this->_params->mask |
414 | 414 | ); |
415 | 415 | $this->Subnets->modify_subnet ("resize", $values); |
416 | 416 | |
417 | 417 | //set result |
418 | - return array("code"=>200, "data"=>"Subnet truncated"); |
|
418 | + return array ("code"=>200, "data"=>"Subnet truncated"); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | |
@@ -436,9 +436,9 @@ discard block |
||
436 | 436 | $this->validate_subnet_id (); |
437 | 437 | |
438 | 438 | // validate input parmeters |
439 | - if(!is_numeric($this->_params->number)) { $this->Response->throw_exception(400, "Invalid number of new subnets"); } |
|
440 | - if(!isset($this->_params->group)) { $this->_params->group = "yes"; } |
|
441 | - if(!isset($this->_params->strict)) { $this->_params->strict = "yes"; } |
|
439 | + if (!is_numeric ($this->_params->number)) { $this->Response->throw_exception (400, "Invalid number of new subnets"); } |
|
440 | + if (!isset($this->_params->group)) { $this->_params->group = "yes"; } |
|
441 | + if (!isset($this->_params->strict)) { $this->_params->strict = "yes"; } |
|
442 | 442 | |
443 | 443 | // fetch old subnet |
444 | 444 | $subnet_old = $this->Subnets->fetch_subnet ("id", $this->_params->id); |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | $this->Subnets->subnet_split ($subnet_old, $this->_params->number, $this->_params->prefix, $this->_params->group, $this->_params->strict); |
447 | 447 | |
448 | 448 | //set result |
449 | - return array("code"=>200, "data"=>"Subnet splitted"); |
|
449 | + return array ("code"=>200, "data"=>"Subnet splitted"); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -461,20 +461,20 @@ discard block |
||
461 | 461 | */ |
462 | 462 | private function subnet_usage () { |
463 | 463 | # check that section exists |
464 | - if(sizeof($subnet = $this->Subnets->fetch_subnet ("id", $this->_params->id))==0) |
|
465 | - { $this->Response->throw_exception(400, "Subnet does not exist"); } |
|
464 | + if (sizeof ($subnet = $this->Subnets->fetch_subnet ("id", $this->_params->id)) == 0) |
|
465 | + { $this->Response->throw_exception (400, "Subnet does not exist"); } |
|
466 | 466 | |
467 | 467 | # set slaves |
468 | 468 | $slaves = $this->Subnets->has_slaves ($this->_params->id) ? true : false; |
469 | 469 | |
470 | 470 | # fetch all addresses and calculate usage |
471 | - if($slaves) { |
|
471 | + if ($slaves) { |
|
472 | 472 | $addresses = $this->Addresses->fetch_subnet_addresses_recursive ($this->_params->id, false); |
473 | 473 | } else { |
474 | 474 | $addresses = $this->Addresses->fetch_subnet_addresses ($this->_params->id); |
475 | 475 | } |
476 | 476 | // calculate |
477 | - $subnet_usage = $this->Subnets->calculate_subnet_usage (gmp_strval(sizeof($addresses)), $subnet->mask, $subnet->subnet, $subnet->isFull ); //Calculate free/used etc |
|
477 | + $subnet_usage = $this->Subnets->calculate_subnet_usage (gmp_strval (sizeof ($addresses)), $subnet->mask, $subnet->subnet, $subnet->isFull); //Calculate free/used etc |
|
478 | 478 | |
479 | 479 | # return |
480 | 480 | return $subnet_usage; |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | // fetch |
497 | 497 | $first = $this->Addresses->get_first_available_address ($this->_params->id, $this->Subnets); |
498 | 498 | // available? |
499 | - if($first===false) { $first = null; } |
|
500 | - else { $first = $this->Addresses->transform_to_dotted($first); } |
|
499 | + if ($first === false) { $first = null; } |
|
500 | + else { $first = $this->Addresses->transform_to_dotted ($first); } |
|
501 | 501 | |
502 | 502 | # return |
503 | 503 | return $first; |
@@ -518,25 +518,25 @@ discard block |
||
518 | 518 | */ |
519 | 519 | private function read_subnet ($subnetId = null) { |
520 | 520 | // null |
521 | - $subnetId = is_null($subnetId) ? $this->_params->id : $subnetId; |
|
521 | + $subnetId = is_null ($subnetId) ? $this->_params->id : $subnetId; |
|
522 | 522 | // fetch |
523 | 523 | $result = $this->Subnets->fetch_subnet ("id", $subnetId); |
524 | 524 | // add nameservers |
525 | - if($result!==false) { |
|
526 | - $ns = $this->read_subnet_nameserver($result->nameserverId); |
|
527 | - if ($ns!==false) { |
|
525 | + if ($result !== false) { |
|
526 | + $ns = $this->read_subnet_nameserver ($result->nameserverId); |
|
527 | + if ($ns !== false) { |
|
528 | 528 | $result->nameservers = $ns; |
529 | 529 | } |
530 | 530 | } |
531 | 531 | // fetch gateway |
532 | - if(sizeof($result)>0) { |
|
532 | + if (sizeof ($result) > 0) { |
|
533 | 533 | $gateway = $this->read_subnet_gateway (); |
534 | - if ( $gateway!== false) { |
|
534 | + if ($gateway !== false) { |
|
535 | 535 | $result->gatewayId = $gateway->id; |
536 | 536 | } |
537 | 537 | } |
538 | 538 | # result |
539 | - return sizeof($result)==0 ? false : $result; |
|
539 | + return sizeof ($result) == 0 ? false : $result; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | // fetch |
550 | 550 | $result = $this->Addresses->fetch_subnet_addresses ($this->_params->id); |
551 | 551 | # result |
552 | - return sizeof($result)==0 ? false : $result; |
|
552 | + return sizeof ($result) == 0 ? false : $result; |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | // fetch |
584 | 584 | $result = $this->Subnets->fetch_subnet_slaves ($this->_params->id); |
585 | 585 | # result |
586 | - return $result===false ? NULL : $result; |
|
586 | + return $result === false ? NULL : $result; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -596,11 +596,11 @@ discard block |
||
596 | 596 | // get array of ids |
597 | 597 | $this->Subnets->fetch_subnet_slaves_recursive ($this->_params->id); |
598 | 598 | // fetch all; |
599 | - foreach($this->Subnets->slaves as $s) { |
|
599 | + foreach ($this->Subnets->slaves as $s) { |
|
600 | 600 | $result[] = $this->read_subnet ($s); |
601 | 601 | } |
602 | 602 | # result |
603 | - return $result===false ? NULL : $result; |
|
603 | + return $result === false ? NULL : $result; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
@@ -615,9 +615,9 @@ discard block |
||
615 | 615 | // check |
616 | 616 | $subnet = $this->Tools->fetch_multiple_objects ("subnets", "subnet", $this->_params->id2); |
617 | 617 | // validate mask |
618 | - if($subnet!==false) { |
|
619 | - foreach($subnet as $s) { |
|
620 | - if($s->mask == $this->_params->id3) { |
|
618 | + if ($subnet !== false) { |
|
619 | + foreach ($subnet as $s) { |
|
620 | + if ($s->mask == $this->_params->id3) { |
|
621 | 621 | $result[] = $s; |
622 | 622 | } |
623 | 623 | } |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | */ |
644 | 644 | private function validate_create_parameters () { |
645 | 645 | # make sure subnet is in dotted format for checks |
646 | - $this->_params->subnet = $this->Addresses->transform_address($this->_params->subnet ,"dotted"); |
|
646 | + $this->_params->subnet = $this->Addresses->transform_address ($this->_params->subnet, "dotted"); |
|
647 | 647 | |
648 | 648 | # cidr check |
649 | 649 | $this->validate_cidr (); |
@@ -671,10 +671,10 @@ discard block |
||
671 | 671 | */ |
672 | 672 | private function validate_cidr () { |
673 | 673 | // not for folder |
674 | - if($this->_params->isFolder!=1) { |
|
674 | + if ($this->_params->isFolder != 1) { |
|
675 | 675 | // check |
676 | - if(strlen($err = $this->Subnets->verify_cidr_address($this->_params->subnet."/".$this->_params->mask))>1) |
|
677 | - { $this->Response->throw_exception(400, $err); } |
|
676 | + if (strlen ($err = $this->Subnets->verify_cidr_address ($this->_params->subnet."/".$this->_params->mask)) > 1) |
|
677 | + { $this->Response->throw_exception (400, $err); } |
|
678 | 678 | } |
679 | 679 | } |
680 | 680 | |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | */ |
687 | 687 | private function validate_network () { |
688 | 688 | // not for folder |
689 | - if($this->_params->isFolder!=1) { |
|
690 | - if(!$this->Addresses->is_network ($this->_params->subnet, $this->_params->mask)) { $this->Response->throw_exception(400, "Address is not subnet"); } |
|
689 | + if ($this->_params->isFolder != 1) { |
|
690 | + if (!$this->Addresses->is_network ($this->_params->subnet, $this->_params->mask)) { $this->Response->throw_exception (400, "Address is not subnet"); } |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
@@ -699,16 +699,16 @@ discard block |
||
699 | 699 | */ |
700 | 700 | private function validate_master_subnet () { |
701 | 701 | // set 0 if not set |
702 | - if(!isset($this->_params->masterSubnetId) || $this->_params->masterSubnetId=="0") { $this->_params->masterSubnetId = 0; } |
|
702 | + if (!isset($this->_params->masterSubnetId) || $this->_params->masterSubnetId == "0") { $this->_params->masterSubnetId = 0; } |
|
703 | 703 | else { |
704 | 704 | // validate subnet |
705 | - if(sizeof($this->Subnets->fetch_subnet ("id", $this->_params->masterSubnetId))==0) { $this->Response->throw_exception(400, "Master Subnet does not exist (id=".$this->_params->masterSubnetId.")"); } |
|
705 | + if (sizeof ($this->Subnets->fetch_subnet ("id", $this->_params->masterSubnetId)) == 0) { $this->Response->throw_exception (400, "Master Subnet does not exist (id=".$this->_params->masterSubnetId.")"); } |
|
706 | 706 | // check that it is inside subnet |
707 | 707 | else { |
708 | 708 | // not fr folders |
709 | - if(@$this->_params->isFolder!=1) { |
|
710 | - if(!$this->Subnets->verify_subnet_nesting ($this->_params->masterSubnetId, $this->_params->subnet."/".$this->_params->mask)) |
|
711 | - { $this->Response->throw_exception(400, "Subnet is not within boundaries of its master subnet"); } |
|
709 | + if (@$this->_params->isFolder != 1) { |
|
710 | + if (!$this->Subnets->verify_subnet_nesting ($this->_params->masterSubnetId, $this->_params->subnet."/".$this->_params->mask)) |
|
711 | + { $this->Response->throw_exception (400, "Subnet is not within boundaries of its master subnet"); } |
|
712 | 712 | } |
713 | 713 | } |
714 | 714 | } |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | */ |
723 | 723 | private function validate_section () { |
724 | 724 | // Section Id must be present and numeric |
725 | - if(!isset($this->_params->sectionId)) { $this->Response->throw_exception(400, "Invalid Section (".$this->_params->sectionId.")"); } |
|
726 | - elseif(!is_numeric($this->_params->sectionId)) { $this->Response->throw_exception(400, "Section Id must be numeric (".$this->_params->sectionId.")"); } |
|
725 | + if (!isset($this->_params->sectionId)) { $this->Response->throw_exception (400, "Invalid Section (".$this->_params->sectionId.")"); } |
|
726 | + elseif (!is_numeric ($this->_params->sectionId)) { $this->Response->throw_exception (400, "Section Id must be numeric (".$this->_params->sectionId.")"); } |
|
727 | 727 | else { |
728 | - if($this->Tools->fetch_object("sections", "id", $this->_params->sectionId)===false) { $this->Response->throw_exception(400, "Section id (".$this->_params->sectionId.") does not exist"); } |
|
728 | + if ($this->Tools->fetch_object ("sections", "id", $this->_params->sectionId) === false) { $this->Response->throw_exception (400, "Section id (".$this->_params->sectionId.") does not exist"); } |
|
729 | 729 | } |
730 | 730 | } |
731 | 731 | |
@@ -737,9 +737,9 @@ discard block |
||
737 | 737 | */ |
738 | 738 | private function validate_subnet_id () { |
739 | 739 | // numberic |
740 | - if(!is_numeric($this->_params->id)) { $this->Response->throw_exception(400, "Subnet Id must be numeric (".$this->_params->id.")"); } |
|
740 | + if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Subnet Id must be numeric (".$this->_params->id.")"); } |
|
741 | 741 | // check subnet |
742 | - if(is_null($this->Subnets->fetch_subnet ("id", $this->_params->id))) { $this->Response->throw_exception(400, "Invalid subnet Id (".$this->_params->id.")"); } |
|
742 | + if (is_null ($this->Subnets->fetch_subnet ("id", $this->_params->id))) { $this->Response->throw_exception (400, "Invalid subnet Id (".$this->_params->id.")"); } |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | /** |
@@ -750,11 +750,11 @@ discard block |
||
750 | 750 | */ |
751 | 751 | private function validate_folder () { |
752 | 752 | // only fo folders |
753 | - if(@$this->_params->isFolder==1) { |
|
753 | + if (@$this->_params->isFolder == 1) { |
|
754 | 754 | // if parent is set it must be a folder! |
755 | - if($this->_params->masterSubnetId!=0) { |
|
755 | + if ($this->_params->masterSubnetId != 0) { |
|
756 | 756 | $parent = $this->Subnets->fetch_subnet ("id", $this->_params->masterSubnetId); |
757 | - if($parent->isFolder!=1) { $this->Response->throw_exception(400, "Parent is not a folder"); } |
|
757 | + if ($parent->isFolder != 1) { $this->Response->throw_exception (400, "Parent is not a folder"); } |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | } |
@@ -768,40 +768,40 @@ discard block |
||
768 | 768 | private function validate_overlapping () { |
769 | 769 | // section details |
770 | 770 | $section = $this->Tools->fetch_object ("sections", "id", $this->_params->sectionId); |
771 | - if($section===false) { $this->Response->throw_exception(400, "Invalid section Id"); } |
|
771 | + if ($section === false) { $this->Response->throw_exception (400, "Invalid section Id"); } |
|
772 | 772 | // settings |
773 | 773 | $this->settings = $this->Tools->fetch_object ("settings", "id", 1); |
774 | 774 | |
775 | 775 | # get master subnet details for folder overrides |
776 | - if($this->_params->masterSubnetId!=0) { |
|
777 | - $master_section = $this->Subnets->fetch_subnet(null, $this->_params->masterSubnetId); |
|
778 | - if($master_section->isFolder==1) { $parent_is_folder = true; } |
|
779 | - else { $parent_is_folder = false; } |
|
776 | + if ($this->_params->masterSubnetId != 0) { |
|
777 | + $master_section = $this->Subnets->fetch_subnet (null, $this->_params->masterSubnetId); |
|
778 | + if ($master_section->isFolder == 1) { $parent_is_folder = true; } |
|
779 | + else { $parent_is_folder = false; } |
|
780 | 780 | } |
781 | - else { $parent_is_folder = false; } |
|
781 | + else { $parent_is_folder = false; } |
|
782 | 782 | |
783 | 783 | // create cidr address |
784 | - $cidr = $this->Addresses->transform_address($this->_params->subnet,"dotted")."/".$this->_params->mask; |
|
784 | + $cidr = $this->Addresses->transform_address ($this->_params->subnet, "dotted")."/".$this->_params->mask; |
|
785 | 785 | |
786 | 786 | // root subnet |
787 | - if($this->_params->masterSubnetId==0) { |
|
787 | + if ($this->_params->masterSubnetId == 0) { |
|
788 | 788 | // check overlapping |
789 | - if($section->strictMode==1 && !$parent_is_folder) { |
|
789 | + if ($section->strictMode == 1 && !$parent_is_folder) { |
|
790 | 790 | /* verify that no overlapping occurs if we are adding root subnet only check for overlapping if vrf is empty or not exists! */ |
791 | 791 | $overlap = $this->Subnets->verify_subnet_overlapping ($this->_params->sectionId, $cidr, $this->_params->vrfId); |
792 | - if($overlap!==false) { $this->Response->throw_exception(400, $overlap); } |
|
792 | + if ($overlap !== false) { $this->Response->throw_exception (400, $overlap); } |
|
793 | 793 | } |
794 | 794 | } |
795 | 795 | // not root |
796 | 796 | else { |
797 | 797 | //disable checks for folders and if strict check enabled |
798 | - if($section->strictMode==1 && !$parent_is_folder ) { |
|
798 | + if ($section->strictMode == 1 && !$parent_is_folder) { |
|
799 | 799 | //verify that nested subnet is inside root subnet |
800 | - if (!$this->Subnets->verify_subnet_nesting($this->_params->masterSubnetId, $cidr)) { $this->Response->throw_exception(400, "Nested subnet not in root subnet"); } |
|
800 | + if (!$this->Subnets->verify_subnet_nesting ($this->_params->masterSubnetId, $cidr)) { $this->Response->throw_exception (400, "Nested subnet not in root subnet"); } |
|
801 | 801 | |
802 | 802 | //nested? |
803 | - $overlap = $this->Subnets->verify_nested_subnet_overlapping($this->_params->sectionId, $cidr, $this->_params->vrfId, $this->_params->masterSubnetId); |
|
804 | - if($overlap!==false) { $this->Response->throw_exception(400, $overlap); } |
|
803 | + $overlap = $this->Subnets->verify_nested_subnet_overlapping ($this->_params->sectionId, $cidr, $this->_params->vrfId, $this->_params->masterSubnetId); |
|
804 | + if ($overlap !== false) { $this->Response->throw_exception (400, $overlap); } |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | } |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | * @return void |
814 | 814 | */ |
815 | 815 | private function validate_vlan () { |
816 | - if(isset($this->_params->vlanId)) { |
|
817 | - if($this->Tools->fetch_object("vlans", "vlanId", $this->_params->vlanId)===false) { $this->Response->throw_exception(400, "Vlan does not exist"); } |
|
816 | + if (isset($this->_params->vlanId)) { |
|
817 | + if ($this->Tools->fetch_object ("vlans", "vlanId", $this->_params->vlanId) === false) { $this->Response->throw_exception (400, "Vlan does not exist"); } |
|
818 | 818 | } |
819 | 819 | } |
820 | 820 | |
@@ -825,8 +825,8 @@ discard block |
||
825 | 825 | * @return void |
826 | 826 | */ |
827 | 827 | private function validate_vrf () { |
828 | - if(isset($this->_params->vrfId)) { |
|
829 | - if($this->Tools->fetch_object("vrf", "vrfId", $this->_params->vrfId)===false) { $this->Response->throw_exception(400, "VRF does not exist"); } |
|
828 | + if (isset($this->_params->vrfId)) { |
|
829 | + if ($this->Tools->fetch_object ("vrf", "vrfId", $this->_params->vrfId) === false) { $this->Response->throw_exception (400, "VRF does not exist"); } |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | # execute update |
269 | 269 | if(!$this->Admin->object_modify ($this->_params->id, "add", "", $values)) |
270 | 270 | { $this->Response->throw_exception(500, $this->_params->id." object creation failed"); } |
271 | - else { |
|
271 | + else { |
|
272 | 272 | //set result |
273 | 273 | return array("code"=>201, "data"=>$this->_params->id." object created", "location"=>"/api/".$this->_params->app_id."/tools/".$this->_params->id."/".$this->Admin->lastId."/"); |
274 | 274 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | # execute update |
326 | 326 | if(!$this->Admin->object_modify ($table_name, "edit", $this->sort_key, $values)) |
327 | 327 | { $this->Response->throw_exception(500, $table_name." object edit failed"); } |
328 | - else { |
|
328 | + else { |
|
329 | 329 | //set result |
330 | 330 | return array("code"=>200, "data"=>$table_name." object updated"); |
331 | 331 | } |
@@ -355,14 +355,15 @@ discard block |
||
355 | 355 | # execute delete |
356 | 356 | if(!$this->Admin->object_modify ($this->_params->id, "delete", $this->sort_key, $values)) |
357 | 357 | { $this->Response->throw_exception(500, $this->_params->id." object delete failed"); } |
358 | - else { |
|
358 | + else { |
|
359 | 359 | // set update field |
360 | 360 | if ($this->_params->id == "devices") { $update_field = "switch"; } |
361 | 361 | elseif ($this->_params->id == "ipTags") { $update_field = "state"; } |
362 | 362 | |
363 | 363 | // delete all references |
364 | - if (isset($update_field)) |
|
365 | - $this->Admin->remove_object_references ("ipaddresses", $update_field, $this->_params->id2); |
|
364 | + if (isset($update_field)) { |
|
365 | + $this->Admin->remove_object_references ("ipaddresses", $update_field, $this->_params->id2); |
|
366 | + } |
|
366 | 367 | |
367 | 368 | // set result |
368 | 369 | return array("code"=>200, "data"=>$this->_params->id." object deleted"); |
@@ -388,8 +389,10 @@ discard block |
||
388 | 389 | */ |
389 | 390 | private function validate_subcontroller () { |
390 | 391 | // not options |
391 | - if($this->_params->controller !== "options") |
|
392 | - if (!in_array($this->_params->id, @$this->subcontrollers)) { $this->Response->throw_exception(400, "Invalid subcontroller"); } |
|
392 | + if($this->_params->controller !== "options") { |
|
393 | + if (!in_array($this->_params->id, @$this->subcontrollers)) { $this->Response->throw_exception(400, "Invalid subcontroller"); |
|
394 | + } |
|
395 | + } |
|
393 | 396 | } |
394 | 397 | |
395 | 398 | /** |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @param mixed $params // post/get values |
91 | 91 | * @param class $Response |
92 | 92 | */ |
93 | - public function __construct($Database, $Tools, $params, $Response) { |
|
93 | + public function __construct ($Database, $Tools, $params, $Response) { |
|
94 | 94 | $this->Database = $Database; |
95 | 95 | $this->Response = $Response; |
96 | - $this->Tools = $Tools; |
|
96 | + $this->Tools = $Tools; |
|
97 | 97 | $this->_params = $params; |
98 | 98 | // init required objects |
99 | 99 | $this->init_object ("Admin", $Database); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return void |
124 | 124 | */ |
125 | 125 | private function define_tools_controllers () { |
126 | - $this->subcontrollers = array("ipTags"=>"tags", |
|
126 | + $this->subcontrollers = array ("ipTags"=>"tags", |
|
127 | 127 | "devices"=>"devices", |
128 | 128 | "deviceTypes"=>"devicetypes", |
129 | 129 | "vlans"=>"vlans", |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | * @return void |
141 | 141 | */ |
142 | 142 | private function define_available_identifiers () { |
143 | - $this->identifiers = array( |
|
144 | - "ipTags"=>array("id2", "id3"), |
|
145 | - "devices"=>array("id2", "id3"), |
|
146 | - "deviceTypes"=>array("id2", "id3"), |
|
147 | - "vlans"=>array("id2", "id3"), |
|
148 | - "vrf"=>array("id2", "id3"), |
|
149 | - "nameservers"=>array("id2"), |
|
150 | - "scanAgents"=>array("id2") |
|
143 | + $this->identifiers = array ( |
|
144 | + "ipTags"=>array ("id2", "id3"), |
|
145 | + "devices"=>array ("id2", "id3"), |
|
146 | + "deviceTypes"=>array ("id2", "id3"), |
|
147 | + "vlans"=>array ("id2", "id3"), |
|
148 | + "vrf"=>array ("id2", "id3"), |
|
149 | + "nameservers"=>array ("id2"), |
|
150 | + "scanAgents"=>array ("id2") |
|
151 | 151 | ); |
152 | 152 | } |
153 | 153 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | */ |
160 | 160 | private function define_sort_key () { |
161 | 161 | // deviceTypes |
162 | - if ($this->_params->id == "deviceTypes") { $this->sort_key = "tid"; } |
|
163 | - elseif ($this->_params->id == "vlans") { $this->sort_key = "vlanId"; } |
|
164 | - elseif ($this->_params->id == "vrf") { $this->sort_key = "vrfId"; } |
|
165 | - else { $this->sort_key = "id"; } |
|
162 | + if ($this->_params->id == "deviceTypes") { $this->sort_key = "tid"; } |
|
163 | + elseif ($this->_params->id == "vlans") { $this->sort_key = "vlanId"; } |
|
164 | + elseif ($this->_params->id == "vrf") { $this->sort_key = "vrfId"; } |
|
165 | + else { $this->sort_key = "id"; } |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | $app = $this->Tools->fetch_object ("api", "app_id", $this->_params->app_id); |
186 | 186 | |
187 | 187 | // controllers |
188 | - $controllers = array( |
|
189 | - array("rel"=>"sections", "href"=>"/api/".$_GET['app_id']."/sections/"), |
|
190 | - array("rel"=>"subnets", "href"=>"/api/".$_GET['app_id']."/subnets/"), |
|
191 | - array("rel"=>"folders", "href"=>"/api/".$_GET['app_id']."/folders/"), |
|
192 | - array("rel"=>"addresses", "href"=>"/api/".$_GET['app_id']."/addresses/"), |
|
193 | - array("rel"=>"vlans", "href"=>"/api/".$_GET['app_id']."/vlans/"), |
|
194 | - array("rel"=>"vrfs", "href"=>"/api/".$_GET['app_id']."/vrfs/"), |
|
195 | - array("rel"=>"nameservers", "href"=>"/api/".$_GET['app_id']."/nameservers/"), |
|
196 | - array("rel"=>"scanAgents", "href"=>"/api/".$_GET['app_id']."/scanagents/"), |
|
197 | - array("rel"=>"tools", "href"=>"/api/".$_GET['app_id']."/tools/") |
|
188 | + $controllers = array ( |
|
189 | + array ("rel"=>"sections", "href"=>"/api/".$_GET['app_id']."/sections/"), |
|
190 | + array ("rel"=>"subnets", "href"=>"/api/".$_GET['app_id']."/subnets/"), |
|
191 | + array ("rel"=>"folders", "href"=>"/api/".$_GET['app_id']."/folders/"), |
|
192 | + array ("rel"=>"addresses", "href"=>"/api/".$_GET['app_id']."/addresses/"), |
|
193 | + array ("rel"=>"vlans", "href"=>"/api/".$_GET['app_id']."/vlans/"), |
|
194 | + array ("rel"=>"vrfs", "href"=>"/api/".$_GET['app_id']."/vrfs/"), |
|
195 | + array ("rel"=>"nameservers", "href"=>"/api/".$_GET['app_id']."/nameservers/"), |
|
196 | + array ("rel"=>"scanAgents", "href"=>"/api/".$_GET['app_id']."/scanagents/"), |
|
197 | + array ("rel"=>"tools", "href"=>"/api/".$_GET['app_id']."/tools/") |
|
198 | 198 | ); |
199 | 199 | # Response |
200 | - return array("code"=>200, "data"=>array("permissions"=>$this->Subnets->parse_permissions($app->app_permissions), "controllers"=>$controllers)); |
|
200 | + return array ("code"=>200, "data"=>array ("permissions"=>$this->Subnets->parse_permissions ($app->app_permissions), "controllers"=>$controllers)); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -225,47 +225,47 @@ discard block |
||
225 | 225 | |
226 | 226 | # all ? |
227 | 227 | if (!isset($this->_params->id2)) { |
228 | - $result = $this->Tools->fetch_all_objects ($this->_params->id, $this->sort_key); |
|
228 | + $result = $this->Tools->fetch_all_objects ($this->_params->id, $this->sort_key); |
|
229 | 229 | // result |
230 | - if($result===false) { $this->Response->throw_exception(404, 'No objects found'); } |
|
231 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, false)); } |
|
230 | + if ($result === false) { $this->Response->throw_exception (404, 'No objects found'); } |
|
231 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, false)); } |
|
232 | 232 | } |
233 | 233 | # by parameter |
234 | 234 | elseif (isset($this->_params->id3)) { |
235 | 235 | // devices (for deviceTypes) |
236 | - if ($this->_params->id == "deviceTypes" && $this->_params->id3=="devices") { |
|
236 | + if ($this->_params->id == "deviceTypes" && $this->_params->id3 == "devices") { |
|
237 | 237 | // fetch |
238 | 238 | $result = $this->Tools->fetch_multiple_objects ("devices", "type", $this->_params->id2, "id", true); |
239 | 239 | } |
240 | 240 | // vlans |
241 | - elseif ($this->_params->id == "vlans" && $this->_params->id3=="subnets") { |
|
241 | + elseif ($this->_params->id == "vlans" && $this->_params->id3 == "subnets") { |
|
242 | 242 | // fetch |
243 | 243 | $result = $this->Tools->fetch_multiple_objects ("subnets", "vlanId", $this->_params->id2, "id", true); |
244 | 244 | // add gateway |
245 | - if($result!=false) { |
|
245 | + if ($result != false) { |
|
246 | 246 | foreach ($result as $k=>$r) { |
247 | 247 | //gateway |
248 | 248 | $gateway = $this->read_subnet_gateway ($r->id); |
249 | - if ( $gateway!== false) { |
|
249 | + if ($gateway !== false) { |
|
250 | 250 | $result[$k]->gatewayId = $gateway->id; |
251 | 251 | } |
252 | 252 | //nameservers |
253 | 253 | $ns = $this->read_subnet_nameserver (); |
254 | - if ($ns!==false) { |
|
254 | + if ($ns !== false) { |
|
255 | 255 | $result[$k]->nameservers = $ns; |
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | // vrfs |
261 | - elseif ($this->_params->id == "vrf" && $this->_params->id3=="subnets") { |
|
261 | + elseif ($this->_params->id == "vrf" && $this->_params->id3 == "subnets") { |
|
262 | 262 | // fetch |
263 | 263 | $result = $this->Tools->fetch_multiple_objects ("subnets", "vrfId", $this->_params->id2, "id", true); |
264 | 264 | // add gateway |
265 | - if($result!=false) { |
|
265 | + if ($result != false) { |
|
266 | 266 | foreach ($result as $k=>$r) { |
267 | 267 | $gateway = $this->read_subnet_gateway ($r->id); |
268 | - if ( $gateway!== false) { |
|
268 | + if ($gateway !== false) { |
|
269 | 269 | $result[$k]->gatewayId = $gateway->id; |
270 | 270 | } |
271 | 271 | } |
@@ -274,28 +274,28 @@ discard block |
||
274 | 274 | else { |
275 | 275 | $field = string; |
276 | 276 | // id3 can only be addresses |
277 | - if ($this->_params->id3 != "addresses") { $this->Response->throw_exception(400, 'Invalid parameter'); } |
|
277 | + if ($this->_params->id3 != "addresses") { $this->Response->throw_exception (400, 'Invalid parameter'); } |
|
278 | 278 | // define identifier |
279 | - if ($this->_params->id == "ipTags") { $field = "state"; } |
|
280 | - elseif ($this->_params->id == "devices"){ $field = "switch"; } |
|
281 | - else { $this->Response->throw_exception(400, 'Invalid parameter'); } |
|
279 | + if ($this->_params->id == "ipTags") { $field = "state"; } |
|
280 | + elseif ($this->_params->id == "devices") { $field = "switch"; } |
|
281 | + else { $this->Response->throw_exception (400, 'Invalid parameter'); } |
|
282 | 282 | // fetch |
283 | 283 | $result = $this->Tools->fetch_multiple_objects ("ipaddresses", $field, $this->_params->id2, $this->sort_key, true); |
284 | 284 | } |
285 | 285 | // result |
286 | - if($result===false) { $this->Response->throw_exception(404, 'No objects found'); } |
|
287 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, true)); } |
|
286 | + if ($result === false) { $this->Response->throw_exception (404, 'No objects found'); } |
|
287 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, true)); } |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | # by id |
291 | 291 | else { |
292 | 292 | // numeric |
293 | - if(!is_numeric($this->_params->id2)) { $this->Response->throw_exception(404, 'Identifier must be numeric'); } |
|
293 | + if (!is_numeric ($this->_params->id2)) { $this->Response->throw_exception (404, 'Identifier must be numeric'); } |
|
294 | 294 | |
295 | 295 | $result = $this->Tools->fetch_object ($this->_params->id, $this->sort_key, $this->_params->id2); |
296 | 296 | // result |
297 | - if($result===false) { $this->Response->throw_exception(404, 'No objects found'); } |
|
298 | - else { return array("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, false)); } |
|
297 | + if ($result === false) { $this->Response->throw_exception (404, 'No objects found'); } |
|
298 | + else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "tools/".$this->_params->id, true, false)); } |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | */ |
317 | 317 | public function POST () { |
318 | 318 | # vlans, vrfs |
319 | - if ($this->_params->id=="vlans" || $this->_params->id=="vrf") |
|
320 | - { $this->Response->throw_exception(400, 'Please use '.$this->_params->id.' controller'); } |
|
319 | + if ($this->_params->id == "vlans" || $this->_params->id == "vrf") |
|
320 | + { $this->Response->throw_exception (400, 'Please use '.$this->_params->id.' controller'); } |
|
321 | 321 | |
322 | 322 | # check for valid keys |
323 | 323 | $values = $this->validate_keys (); |
@@ -326,14 +326,14 @@ discard block |
||
326 | 326 | $this->validate_post_patch (); |
327 | 327 | |
328 | 328 | # only 1 parameter ? |
329 | - if (sizeof($values)==1) { $this->Response->throw_exception(400, 'No parameters'); } |
|
329 | + if (sizeof ($values) == 1) { $this->Response->throw_exception (400, 'No parameters'); } |
|
330 | 330 | |
331 | 331 | # execute update |
332 | - if(!$this->Admin->object_modify ($this->_params->id, "add", "", $values)) |
|
333 | - { $this->Response->throw_exception(500, $this->_params->id." object creation failed"); } |
|
332 | + if (!$this->Admin->object_modify ($this->_params->id, "add", "", $values)) |
|
333 | + { $this->Response->throw_exception (500, $this->_params->id." object creation failed"); } |
|
334 | 334 | else { |
335 | 335 | //set result |
336 | - return array("code"=>201, "data"=>$this->_params->id." object created", "location"=>"/api/".$this->_params->app_id."/tools/".$this->_params->id."/".$this->Admin->lastId."/"); |
|
336 | + return array ("code"=>201, "data"=>$this->_params->id." object created", "location"=>"/api/".$this->_params->app_id."/tools/".$this->_params->id."/".$this->Admin->lastId."/"); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | } |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | */ |
366 | 366 | public function PATCH () { |
367 | 367 | # vlans, vrfs |
368 | - if ($this->_params->id=="vlans" || $this->_params->id=="vrf") |
|
369 | - { $this->Response->throw_exception(400, 'Please use '.$this->_params->id.' controller'); } |
|
368 | + if ($this->_params->id == "vlans" || $this->_params->id == "vrf") |
|
369 | + { $this->Response->throw_exception (400, 'Please use '.$this->_params->id.' controller'); } |
|
370 | 370 | |
371 | 371 | # verify object |
372 | 372 | $this->validate_tools_object (); |
@@ -383,14 +383,14 @@ discard block |
||
383 | 383 | $values = $this->validate_keys (); |
384 | 384 | |
385 | 385 | # only 1 parameter ? |
386 | - if (sizeof($values)==1) { $this->Response->throw_exception(400, 'No parameters'); } |
|
386 | + if (sizeof ($values) == 1) { $this->Response->throw_exception (400, 'No parameters'); } |
|
387 | 387 | |
388 | 388 | # execute update |
389 | - if(!$this->Admin->object_modify ($table_name, "edit", $this->sort_key, $values)) |
|
390 | - { $this->Response->throw_exception(500, $table_name." object edit failed"); } |
|
389 | + if (!$this->Admin->object_modify ($table_name, "edit", $this->sort_key, $values)) |
|
390 | + { $this->Response->throw_exception (500, $table_name." object edit failed"); } |
|
391 | 391 | else { |
392 | 392 | //set result |
393 | - return array("code"=>200, "data"=>$table_name." object updated"); |
|
393 | + return array ("code"=>200, "data"=>$table_name." object updated"); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -406,30 +406,30 @@ discard block |
||
406 | 406 | */ |
407 | 407 | public function DELETE () { |
408 | 408 | # vlans, vrfs |
409 | - if ($this->_params->id=="vlans" || $this->_params->id=="vrf") |
|
410 | - { $this->Response->throw_exception(400, 'Please use '.$this->_params->id.' controller'); } |
|
409 | + if ($this->_params->id == "vlans" || $this->_params->id == "vrf") |
|
410 | + { $this->Response->throw_exception (400, 'Please use '.$this->_params->id.' controller'); } |
|
411 | 411 | |
412 | 412 | # verify object |
413 | 413 | $this->validate_tools_object (); |
414 | 414 | |
415 | 415 | # set variables for delete |
416 | - $values = array(); |
|
416 | + $values = array (); |
|
417 | 417 | $values[$this->sort_key] = $this->_params->id2; |
418 | 418 | |
419 | 419 | # execute delete |
420 | - if(!$this->Admin->object_modify ($this->_params->id, "delete", $this->sort_key, $values)) |
|
421 | - { $this->Response->throw_exception(500, $this->_params->id." object delete failed"); } |
|
420 | + if (!$this->Admin->object_modify ($this->_params->id, "delete", $this->sort_key, $values)) |
|
421 | + { $this->Response->throw_exception (500, $this->_params->id." object delete failed"); } |
|
422 | 422 | else { |
423 | 423 | // set update field |
424 | - if ($this->_params->id == "devices") { $update_field = "switch"; } |
|
425 | - elseif ($this->_params->id == "ipTags") { $update_field = "state"; } |
|
424 | + if ($this->_params->id == "devices") { $update_field = "switch"; } |
|
425 | + elseif ($this->_params->id == "ipTags") { $update_field = "state"; } |
|
426 | 426 | |
427 | 427 | // delete all references |
428 | 428 | if (isset($update_field)) |
429 | 429 | $this->Admin->remove_object_references ("ipaddresses", $update_field, $this->_params->id2); |
430 | 430 | |
431 | 431 | // set result |
432 | - return array("code"=>200, "data"=>$this->_params->id." object deleted"); |
|
432 | + return array ("code"=>200, "data"=>$this->_params->id." object deleted"); |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | |
@@ -452,8 +452,8 @@ discard block |
||
452 | 452 | */ |
453 | 453 | private function validate_subcontroller () { |
454 | 454 | // not options |
455 | - if($this->_params->controller !== "options") |
|
456 | - if (!in_array($this->_params->id, @$this->subcontrollers)) { $this->Response->throw_exception(400, "Invalid subcontroller"); } |
|
455 | + if ($this->_params->controller !== "options") |
|
456 | + if (!in_array ($this->_params->id, @$this->subcontrollers)) { $this->Response->throw_exception (400, "Invalid subcontroller"); } |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | private function validate_subcontroller_identifier () { |
466 | 466 | // id3 |
467 | 467 | if (isset($this->_params->id3)) { |
468 | - if(!in_array("id3", $this->identifiers[$this->_params->id])) { $this->Response->throw_exception(400, "Invalid subcontroller identifier"); } |
|
468 | + if (!in_array ("id3", $this->identifiers[$this->_params->id])) { $this->Response->throw_exception (400, "Invalid subcontroller identifier"); } |
|
469 | 469 | } |
470 | 470 | // id2 |
471 | 471 | if (isset($this->_params->id2)) { |
472 | - if(!in_array("id2", $this->identifiers[$this->_params->id])) { $this->Response->throw_exception(400, "Invalid subcontroller identifier"); } |
|
472 | + if (!in_array ("id2", $this->identifiers[$this->_params->id])) { $this->Response->throw_exception (400, "Invalid subcontroller identifier"); } |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return void |
481 | 481 | */ |
482 | 482 | private function rewrite_subcontroller () { |
483 | - $this->_params->id = array_search($this->_params->id, $this->subcontrollers); |
|
483 | + $this->_params->id = array_search ($this->_params->id, $this->subcontrollers); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,8 +490,8 @@ discard block |
||
490 | 490 | * @return void |
491 | 491 | */ |
492 | 492 | private function validate_tools_object () { |
493 | - if ($this->Tools->fetch_object ($this->_params->id, $this->sort_key, $this->_params->id2)===false) |
|
494 | - { $this->Response->throw_exception(400, "Invalid identifier"); } |
|
493 | + if ($this->Tools->fetch_object ($this->_params->id, $this->sort_key, $this->_params->id2) === false) |
|
494 | + { $this->Response->throw_exception (400, "Invalid identifier"); } |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -514,10 +514,10 @@ discard block |
||
514 | 514 | private function validate_device_type () { |
515 | 515 | if ($this->_params->id == "devices" && isset($this->_params->type)) { |
516 | 516 | // numeric |
517 | - if (!is_numeric($this->_params->type)) { $this->Response->throw_exception(400, "Invalid devicetype identifier"); } |
|
517 | + if (!is_numeric ($this->_params->type)) { $this->Response->throw_exception (400, "Invalid devicetype identifier"); } |
|
518 | 518 | // check |
519 | - if ($this->Tools->fetch_object ("deviceTypes", "tid", $this->_params->type)===false) |
|
520 | - { $this->Response->throw_exception(400, "Device type does not exist"); } |
|
519 | + if ($this->Tools->fetch_object ("deviceTypes", "tid", $this->_params->type) === false) |
|
520 | + { $this->Response->throw_exception (400, "Device type does not exist"); } |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | private function validate_ip () { |
531 | 531 | if (isset($this->_params->ip_addr)) { |
532 | 532 | // check |
533 | - if(strlen($err = $this->Subnets->verify_cidr_address($this->_params->ip_addr."/32"))>1) |
|
534 | - { $this->Response->throw_exception(400, $err); } |
|
533 | + if (strlen ($err = $this->Subnets->verify_cidr_address ($this->_params->ip_addr."/32")) > 1) |
|
534 | + { $this->Response->throw_exception (400, $err); } |
|
535 | 535 | |
536 | 536 | } |
537 | 537 | } |