@@ -48,8 +48,7 @@ discard block |
||
48 | 48 | # database object |
49 | 49 | $Database = new Database_PDO; |
50 | 50 | # try to fetch settings |
51 | - try { $settings = $Database->getObject("settings", 1); } |
|
52 | - catch (Exception $e) { $settings = false; } |
|
51 | + try { $settings = $Database->getObject("settings", 1); } catch (Exception $e) { $settings = false; } |
|
53 | 52 | if ($settings!==false) { |
54 | 53 | define(SETTINGS, json_encode($settings)); |
55 | 54 | } |
@@ -70,8 +69,9 @@ discard block |
||
70 | 69 | # set normal link array |
71 | 70 | $el = array("page", "section", "subnetId", "sPage", "ipaddrid"); |
72 | 71 | // override for search |
73 | - if ($l0=="tools" && $l1=="search") |
|
74 | - $el = array("page", "section", "addresses", "subnets", "vlans", "ip"); |
|
72 | + if ($l0=="tools" && $l1=="search") { |
|
73 | + $el = array("page", "section", "addresses", "subnets", "vlans", "ip"); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | # set rewrite |
77 | 77 | if($User->settings->prettyLinks=="Yes") { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | $subnet_addresses = $Addresses->fetch_subnet_addresses ($s->id); |
91 | 91 | //set array for fping |
92 | - if($Scan->icmp_type=="fping") { |
|
92 | + if($Scan->icmp_type=="fping") { |
|
93 | 93 | $subnets[] = array("id"=>$s->id, "cidr"=>$Subnets->transform_to_dotted($s->subnet)."/".$s->mask); |
94 | 94 | } |
95 | 95 | //save addresses |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | //ignore excludePing |
99 | 99 | if($a->excludePing!=1) { |
100 | 100 | //create different array for fping |
101 | - if($Scan->icmp_type=="fping") { |
|
101 | + if($Scan->icmp_type=="fping") { |
|
102 | 102 | $addresses2[$s->id][$a->id] = array("id"=>$a->id, "ip_addr"=>$a->ip_addr, "description"=>$a->description, "dns_name"=>$a->dns_name, "subnetId"=>$a->subnetId, "lastSeenOld"=>$a->lastSeen, "lastSeen"=>$a->lastSeen); //used for status check |
103 | 103 | $addresses[$s->id][$a->id] = $a->ip_addr; //used for alive check |
104 | 104 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | // now offline, and diff > offline period, do checks |
270 | 270 | elseif($change['lastSeenNew']==NULL && $deviceDiff >= (int) $statuses[1]) { |
271 | 271 | // if not already reported |
272 | - if ($deviceDiff <= ((int) $statuses[1] + $agentDiff)) { |
|
272 | + if ($deviceDiff <= ((int) $statuses[1] + $agentDiff)) { |
|
273 | 273 | $address_change[$k]['oldStatus'] = 0; |
274 | 274 | $address_change[$k]['newStatus'] = 2; |
275 | 275 | } |
@@ -367,7 +367,8 @@ discard block |
||
367 | 367 | //ago |
368 | 368 | if(is_null($change['lastSeen']) || $change['lastSeen']=="0000-00-00 00:00:00") { |
369 | 369 | $ago = "never"; |
370 | - } else { |
|
370 | + } |
|
371 | + else { |
|
371 | 372 | $timeDiff = $now - strtotime($change['lastSeen']); |
372 | 373 | $ago = $change['lastSeen']." (".$Result->sec2hms($timeDiff)." ago)"; |
373 | 374 | } |
@@ -41,8 +41,7 @@ discard block |
||
41 | 41 | # set debugging |
42 | 42 | $this->set_db_params (); |
43 | 43 | # Log object |
44 | - try { $this->Database->connect(); } |
|
45 | - catch ( Exception $e ) {} |
|
44 | + try { $this->Database->connect(); } catch ( Exception $e ) {} |
|
46 | 45 | } |
47 | 46 | |
48 | 47 | |
@@ -109,8 +108,7 @@ discard block |
||
109 | 108 | # set query |
110 | 109 | $query = "drop database if exists `". $this->db['name'] ."`;"; |
111 | 110 | # execute |
112 | - try { $this->Database_root->runQuery($query); } |
|
113 | - catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
111 | + try { $this->Database_root->runQuery($query); } catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
114 | 112 | } |
115 | 113 | |
116 | 114 | /** |
@@ -123,8 +121,7 @@ discard block |
||
123 | 121 | # set query |
124 | 122 | $query = "create database `". $this->db['name'] ."`;"; |
125 | 123 | # execute |
126 | - try { $this->Database_root->runQuery($query); } |
|
127 | - catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
124 | + try { $this->Database_root->runQuery($query); } catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
128 | 125 | } |
129 | 126 | |
130 | 127 | /** |
@@ -137,8 +134,7 @@ discard block |
||
137 | 134 | # set query |
138 | 135 | $query = 'grant ALL on `'. $this->db['name'] .'`.* to '. $this->db['user'] .'@localhost identified by "'. $this->db['pass'] .'";'; |
139 | 136 | # execute |
140 | - try { $this->Database_root->runQuery($query); } |
|
141 | - catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
137 | + try { $this->Database_root->runQuery($query); } catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), true);} |
|
142 | 138 | } |
143 | 139 | |
144 | 140 | /** |
@@ -158,14 +154,11 @@ discard block |
||
158 | 154 | foreach($queries as $q) { |
159 | 155 | //length check |
160 | 156 | if (strlen($q)>0) { |
161 | - try { $this->Database_root->runQuery($q.";"); } |
|
162 | - catch (Exception $e) { |
|
157 | + try { $this->Database_root->runQuery($q.";"); } catch (Exception $e) { |
|
163 | 158 | //unlock tables |
164 | - try { $this->Database_root->runQuery("UNLOCK TABLES;"); } |
|
165 | - catch (Exception $e) {} |
|
159 | + try { $this->Database_root->runQuery("UNLOCK TABLES;"); } catch (Exception $e) {} |
|
166 | 160 | //drop database |
167 | - try { $this->Database_root->runQuery("drop database if exists `". $this->db['name'] ."`;"); } |
|
168 | - catch (Exception $e) { |
|
161 | + try { $this->Database_root->runQuery("drop database if exists `". $this->db['name'] ."`;"); } catch (Exception $e) { |
|
169 | 162 | $this->Result->show("danger", 'Cannot drop database: '.$e->getMessage(), true); |
170 | 163 | } |
171 | 164 | //print error |
@@ -201,8 +194,7 @@ discard block |
||
201 | 194 | */ |
202 | 195 | public function check_db_connection ($redirect = false) { |
203 | 196 | # try to connect |
204 | - try { $res = $this->Database->connect(); } |
|
205 | - catch (Exception $e) { |
|
197 | + try { $res = $this->Database->connect(); } catch (Exception $e) { |
|
206 | 198 | $this->exception = $e->getMessage(); |
207 | 199 | # redirect ? |
208 | 200 | if($redirect == true) { $this->redirect_to_install (); } |
@@ -223,10 +215,21 @@ discard block |
||
223 | 215 | # set query |
224 | 216 | $query = "SELECT COUNT(*) AS `cnt` FROM information_schema.tables WHERE table_schema = '".$this->db['name']."' AND table_name = '$table';"; |
225 | 217 | # try to fetch count |
226 | - try { $table = $this->Database->getObjectQuery($query); } |
|
227 | - catch (Exception $e) { if($redirect === true) $this->redirect_to_install (); else return false; } |
|
218 | + try { $table = $this->Database->getObjectQuery($query); } catch (Exception $e) { if($redirect === true) { |
|
219 | + $this->redirect_to_install (); |
|
220 | + } |
|
221 | + else { |
|
222 | + return false; |
|
223 | + } |
|
224 | + } |
|
228 | 225 | # redirect if it is not existing |
229 | - if($table->cnt!=1) { if($redirect === true) $this->redirect_to_install (); else return false; } |
|
226 | + if($table->cnt!=1) { if($redirect === true) { |
|
227 | + $this->redirect_to_install (); |
|
228 | + } |
|
229 | + else { |
|
230 | + return false; |
|
231 | + } |
|
232 | + } |
|
230 | 233 | # ok |
231 | 234 | return true; |
232 | 235 | } |
@@ -303,8 +306,7 @@ discard block |
||
303 | 306 | * @return void |
304 | 307 | */ |
305 | 308 | public function postauth_update_admin_pass ($adminpass) { |
306 | - try { $this->Database->updateObject("users", array("password"=>$adminpass, "passChange"=>"No","username"=>"Admin"), "username"); } |
|
307 | - catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), false); } |
|
309 | + try { $this->Database->updateObject("users", array("password"=>$adminpass, "passChange"=>"No","username"=>"Admin"), "username"); } catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), false); } |
|
308 | 310 | return true; |
309 | 311 | } |
310 | 312 | |
@@ -317,8 +319,7 @@ discard block |
||
317 | 319 | * @return void |
318 | 320 | */ |
319 | 321 | private function postauth_update_settings ($siteTitle, $siteURL) { |
320 | - try { $this->Database->updateObject("settings", array("siteTitle"=>$siteTitle, "siteURL"=>$siteURL,"id"=>1), "id"); } |
|
321 | - catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), false); } |
|
322 | + try { $this->Database->updateObject("settings", array("siteTitle"=>$siteTitle, "siteURL"=>$siteURL,"id"=>1), "id"); } catch (Exception $e) { $this->Result->show("danger", $e->getMessage(), false); } |
|
322 | 323 | return true; |
323 | 324 | } |
324 | 325 | |
@@ -378,8 +379,7 @@ discard block |
||
378 | 379 | # execute all queries |
379 | 380 | foreach($queries as $query) { |
380 | 381 | if (strlen($query)>5) { |
381 | - try { $this->Database->runQuery($query); } |
|
382 | - catch (Exception $e) { |
|
382 | + try { $this->Database->runQuery($query); } catch (Exception $e) { |
|
383 | 383 | $this->Log = new Logging ($this->Database); |
384 | 384 | # write log |
385 | 385 | $this->Log->write( "Database upgrade", $e->getMessage()."<br>query: ".$query, 2 ); |
@@ -35,7 +35,7 @@ |
||
35 | 35 | $this->die = $die; |
36 | 36 | |
37 | 37 | # API - throw exception |
38 | - if($this->exit_method == "exception") { |
|
38 | + if($this->exit_method == "exception") { |
|
39 | 39 | # ok, just return success |
40 | 40 | if ($class=="success") { return true; } |
41 | 41 | else { return $this->throw_exception ($text); } |
@@ -330,11 +330,10 @@ discard block |
||
330 | 330 | |
331 | 331 | function GetLastError() |
332 | 332 | { |
333 | - if (0 < $this->_last_error_code) |
|
334 | - { |
|
333 | + if (0 < $this->_last_error_code) { |
|
335 | 334 | return $this->_last_error_message.' ('.$this->_last_error_code.')'; |
336 | - } else |
|
337 | - { |
|
335 | + } |
|
336 | + else { |
|
338 | 337 | return ''; |
339 | 338 | } |
340 | 339 | } |
@@ -387,8 +386,7 @@ discard block |
||
387 | 386 | function SetUsername($username = '') |
388 | 387 | { |
389 | 388 | $temp_username = $username; |
390 | - if (false === strpos($temp_username, '@')) |
|
391 | - { |
|
389 | + if (false === strpos($temp_username, '@')) { |
|
392 | 390 | $temp_username .= $this->_radius_suffix; |
393 | 391 | } |
394 | 392 | |
@@ -403,8 +401,7 @@ discard block |
||
403 | 401 | $encrypted_password = ''; |
404 | 402 | $padded_password = $password; |
405 | 403 | |
406 | - if (0 != (strlen($password) % 16)) |
|
407 | - { |
|
404 | + if (0 != (strlen($password) % 16)) { |
|
408 | 405 | $padded_password .= str_repeat(chr(0), (16 - strlen($password) % 16)); |
409 | 406 | } |
410 | 407 | |
@@ -432,11 +429,10 @@ discard block |
||
432 | 429 | |
433 | 430 | function SetNasIPAddress($nas_ip_address = '') |
434 | 431 | { |
435 | - if (0 < strlen($nas_ip_address)) |
|
436 | - { |
|
432 | + if (0 < strlen($nas_ip_address)) { |
|
437 | 433 | $this->_nas_ip_address = gethostbyname($nas_ip_address); |
438 | - } else |
|
439 | - { |
|
434 | + } |
|
435 | + else { |
|
440 | 436 | $this->_nas_ip_address = gethostbyname(isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'); |
441 | 437 | } |
442 | 438 | $this->SetAttribute(4, $this->_nas_ip_address); |
@@ -452,8 +448,7 @@ discard block |
||
452 | 448 | |
453 | 449 | function SetUdpTimeout($udp_timeout = 5) |
454 | 450 | { |
455 | - if (intval($udp_timeout) > 0) |
|
456 | - { |
|
451 | + if (intval($udp_timeout) > 0) { |
|
457 | 452 | $this->_udp_timeout = intval($udp_timeout); |
458 | 453 | } |
459 | 454 | } |
@@ -468,8 +463,7 @@ discard block |
||
468 | 463 | |
469 | 464 | function SetAuthenticationPort($authentication_port) |
470 | 465 | { |
471 | - if ((intval($authentication_port) > 0) && (intval($authentication_port) < 65536)) |
|
472 | - { |
|
466 | + if ((intval($authentication_port) > 0) && (intval($authentication_port) < 65536)) { |
|
473 | 467 | $this->_authentication_port = intval($authentication_port); |
474 | 468 | } |
475 | 469 | } |
@@ -477,8 +471,7 @@ discard block |
||
477 | 471 | |
478 | 472 | function SetAccountingPort($accounting_port) |
479 | 473 | { |
480 | - if ((intval($accounting_port) > 0) && (intval($accounting_port) < 65536)) |
|
481 | - { |
|
474 | + if ((intval($accounting_port) > 0) && (intval($accounting_port) < 65536)) { |
|
482 | 475 | $this->_accounting_port = intval($accounting_port); |
483 | 476 | } |
484 | 477 | } |
@@ -499,21 +492,19 @@ discard block |
||
499 | 492 | function GetReadableReceivedAttributes() |
500 | 493 | { |
501 | 494 | $readable_attributes = ''; |
502 | - if (isset($this->_attributes_received)) |
|
503 | - { |
|
495 | + if (isset($this->_attributes_received)) { |
|
504 | 496 | foreach ($this->_attributes_received as $one_received_attribute) |
505 | 497 | { |
506 | 498 | $attributes_info = $this->GetAttributesInfo($one_received_attribute[0]); |
507 | 499 | $readable_attributes .= $attributes_info[0].": "; |
508 | - if (26 == $one_received_attribute[0]) |
|
509 | - { |
|
500 | + if (26 == $one_received_attribute[0]) { |
|
510 | 501 | $vendor_array = $this->DecodeVendorSpecificContent($one_received_attribute[1]); |
511 | 502 | foreach ($vendor_array as $vendor_one) |
512 | 503 | { |
513 | 504 | $readable_attributes .= 'Vendor-Id: '.$vendor_one[0].", Vendor-type: ".$vendor_one[1].", Attribute-specific: ".$vendor_one[2]; |
514 | 505 | } |
515 | - } else |
|
516 | - { |
|
506 | + } |
|
507 | + else { |
|
517 | 508 | $readable_attributes .= $one_received_attribute[1]; |
518 | 509 | } |
519 | 510 | $readable_attributes .= "<br />\n"; |
@@ -528,8 +519,7 @@ discard block |
||
528 | 519 | $attribute_value = NULL; |
529 | 520 | foreach ($this->_attributes_received as $one_received_attribute) |
530 | 521 | { |
531 | - if (intval($attribute_type) == $one_received_attribute[0]) |
|
532 | - { |
|
522 | + if (intval($attribute_type) == $one_received_attribute[0]) { |
|
533 | 523 | $attribute_value = $one_received_attribute[1]; |
534 | 524 | break; |
535 | 525 | } |
@@ -540,11 +530,10 @@ discard block |
||
540 | 530 | |
541 | 531 | function GetRadiusPacketInfo($info_index) |
542 | 532 | { |
543 | - if (isset($this->_radius_packet_info[intval($info_index)])) |
|
544 | - { |
|
533 | + if (isset($this->_radius_packet_info[intval($info_index)])) { |
|
545 | 534 | return $this->_radius_packet_info[intval($info_index)]; |
546 | - } else |
|
547 | - { |
|
535 | + } |
|
536 | + else { |
|
548 | 537 | return ''; |
549 | 538 | } |
550 | 539 | } |
@@ -552,11 +541,10 @@ discard block |
||
552 | 541 | |
553 | 542 | function GetAttributesInfo($info_index) |
554 | 543 | { |
555 | - if (isset($this->_attributes_info[intval($info_index)])) |
|
556 | - { |
|
544 | + if (isset($this->_attributes_info[intval($info_index)])) { |
|
557 | 545 | return $this->_attributes_info[intval($info_index)]; |
558 | - } else |
|
559 | - { |
|
546 | + } |
|
547 | + else { |
|
560 | 548 | return array('', ''); |
561 | 549 | } |
562 | 550 | } |
@@ -564,8 +552,7 @@ discard block |
||
564 | 552 | |
565 | 553 | function DebugInfo($debug_info) |
566 | 554 | { |
567 | - if ($this->_debug_mode) |
|
568 | - { |
|
555 | + if ($this->_debug_mode) { |
|
569 | 556 | //save debugging |
570 | 557 | $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
571 | 558 | } |
@@ -577,8 +564,7 @@ discard block |
||
577 | 564 | $attribute_index = -1; |
578 | 565 | for ($attributes_loop = 0; $attributes_loop < count($this->_attributes_to_send); $attributes_loop++) |
579 | 566 | { |
580 | - if ($type == ord(substr($this->_attributes_to_send[$attributes_loop], 0, 1))) |
|
581 | - { |
|
567 | + if ($type == ord(substr($this->_attributes_to_send[$attributes_loop], 0, 1))) { |
|
582 | 568 | $attribute_index = $attributes_loop; |
583 | 569 | break; |
584 | 570 | } |
@@ -586,10 +572,8 @@ discard block |
||
586 | 572 | |
587 | 573 | $temp_attribute = NULL; |
588 | 574 | |
589 | - if (isset($this->_attributes_info[$type])) |
|
590 | - { |
|
591 | - switch ($this->_attributes_info[$type][1]) |
|
592 | - { |
|
575 | + if (isset($this->_attributes_info[$type])) { |
|
576 | + switch ($this->_attributes_info[$type][1]) { |
|
593 | 577 | case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). |
594 | 578 | $temp_attribute = chr($type).chr(2 + strlen($value)).$value; |
595 | 579 | break; |
@@ -611,12 +595,11 @@ discard block |
||
611 | 595 | } |
612 | 596 | } |
613 | 597 | |
614 | - if ($attribute_index > -1) |
|
615 | - { |
|
598 | + if ($attribute_index > -1) { |
|
616 | 599 | $this->_attributes_to_send[$attribute_index] = $temp_attribute; |
617 | 600 | $additional_debug = 'Modified'; |
618 | - } else |
|
619 | - { |
|
601 | + } |
|
602 | + else { |
|
620 | 603 | $this->_attributes_to_send[] = $temp_attribute; |
621 | 604 | $additional_debug = 'Added'; |
622 | 605 | } |
@@ -629,10 +612,8 @@ discard block |
||
629 | 612 | { |
630 | 613 | $attribute_value = NULL; |
631 | 614 | |
632 | - if (isset($this->_attributes_info[$attribute_format])) |
|
633 | - { |
|
634 | - switch ($this->_attributes_info[$attribute_format][1]) |
|
635 | - { |
|
615 | + if (isset($this->_attributes_info[$attribute_format])) { |
|
616 | + switch ($this->_attributes_info[$attribute_format][1]) { |
|
636 | 617 | case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). |
637 | 618 | $attribute_value = $attribute_raw_value; |
638 | 619 | break; |
@@ -690,26 +671,22 @@ discard block |
||
690 | 671 | |
691 | 672 | $this->SetPacketCodeToSend(1); // Access-Request |
692 | 673 | |
693 | - if (0 < strlen($username)) |
|
694 | - { |
|
674 | + if (0 < strlen($username)) { |
|
695 | 675 | $this->SetUsername($username); |
696 | 676 | } |
697 | 677 | |
698 | - if (0 < strlen($password)) |
|
699 | - { |
|
678 | + if (0 < strlen($password)) { |
|
700 | 679 | $this->SetPassword($password); |
701 | 680 | } |
702 | 681 | |
703 | - if ($state !== NULL) |
|
704 | - { |
|
682 | + if ($state !== NULL) { |
|
705 | 683 | $this->SetAttribute(24, $state); |
706 | - } else |
|
707 | - { |
|
684 | + } |
|
685 | + else { |
|
708 | 686 | $this->SetAttribute(6, 1); // 1=Login |
709 | 687 | } |
710 | 688 | |
711 | - if (intval($udp_timeout) > 0) |
|
712 | - { |
|
689 | + if (intval($udp_timeout) > 0) { |
|
713 | 690 | $this->SetUdpTimeout($udp_timeout); |
714 | 691 | } |
715 | 692 | |
@@ -732,23 +709,21 @@ discard block |
||
732 | 709 | |
733 | 710 | $_socket_to_server = socket_create(AF_INET, SOCK_DGRAM, 17); // UDP packet = 17 |
734 | 711 | |
735 | - if ($_socket_to_server === FALSE) |
|
736 | - { |
|
712 | + if ($_socket_to_server === FALSE) { |
|
737 | 713 | $this->_last_error_code = socket_last_error(); |
738 | 714 | $this->_last_error_message = socket_strerror($this->_last_error_code); |
739 | - } elseif (FALSE === socket_connect($_socket_to_server, $this->_ip_radius_server, $this->_authentication_port)) |
|
740 | - { |
|
715 | + } |
|
716 | + elseif (FALSE === socket_connect($_socket_to_server, $this->_ip_radius_server, $this->_authentication_port)) { |
|
741 | 717 | $this->_last_error_code = socket_last_error(); |
742 | 718 | $this->_last_error_message = socket_strerror($this->_last_error_code); |
743 | - } elseif (FALSE === socket_write($_socket_to_server, $packet_data, $packet_length)) |
|
744 | - { |
|
719 | + } |
|
720 | + elseif (FALSE === socket_write($_socket_to_server, $packet_data, $packet_length)) { |
|
745 | 721 | $this->_last_error_code = socket_last_error(); |
746 | 722 | $this->_last_error_message = socket_strerror($this->_last_error_code); |
747 | - } else |
|
748 | - { |
|
723 | + } |
|
724 | + else { |
|
749 | 725 | $this->DebugInfo('<b>Packet type '.$this->_radius_packet_to_send.' ('.$this->GetRadiusPacketInfo($this->_radius_packet_to_send).')'.' sent</b>'); |
750 | - if ($this->_debug_mode) |
|
751 | - { |
|
726 | + if ($this->_debug_mode) { |
|
752 | 727 | $readable_attributes = ''; |
753 | 728 | foreach ($this->_attributes_to_send as $one_attribute_to_send) |
754 | 729 | { |
@@ -762,10 +737,8 @@ discard block |
||
762 | 737 | |
763 | 738 | $received_packet = chr(0); |
764 | 739 | |
765 | - if (!(FALSE === socket_select($read_socket_array, $write_socket_array, $except_socket_array, $this->_udp_timeout))) |
|
766 | - { |
|
767 | - if (in_array($_socket_to_server, $read_socket_array)) |
|
768 | - { |
|
740 | + if (!(FALSE === socket_select($read_socket_array, $write_socket_array, $except_socket_array, $this->_udp_timeout))) { |
|
741 | + if (in_array($_socket_to_server, $read_socket_array)) { |
|
769 | 742 | if (FALSE === ($received_packet = @socket_read($_socket_to_server, 1024))) { |
770 | 743 | // @ used, than no error is displayed if the connection is closed by the remote host |
771 | 744 | { |
@@ -773,13 +746,13 @@ discard block |
||
773 | 746 | } |
774 | 747 | $this->_last_error_code = socket_last_error(); |
775 | 748 | $this->_last_error_message = socket_strerror($this->_last_error_code); |
776 | - } else |
|
777 | - { |
|
749 | + } |
|
750 | + else { |
|
778 | 751 | socket_close($_socket_to_server); |
779 | 752 | } |
780 | 753 | } |
781 | - } else |
|
782 | - { |
|
754 | + } |
|
755 | + else { |
|
783 | 756 | socket_close($_socket_to_server); |
784 | 757 | } |
785 | 758 | } |
@@ -788,8 +761,7 @@ discard block |
||
788 | 761 | |
789 | 762 | $this->DebugInfo('<b>Packet type '.$this->_radius_packet_received.' ('.$this->GetRadiusPacketInfo($this->_radius_packet_received).')'.' received</b>'); |
790 | 763 | |
791 | - if ($this->_radius_packet_received > 0) |
|
792 | - { |
|
764 | + if ($this->_radius_packet_received > 0) { |
|
793 | 765 | $this->_identifier_received = intval(ord(substr($received_packet, 1, 1))); |
794 | 766 | $packet_length = (intval(ord(substr($received_packet, 2, 1))) * 256) + (intval(ord(substr($received_packet, 3, 1)))); |
795 | 767 | $this->_response_authenticator = substr($received_packet, 4, 16); |
@@ -804,15 +776,14 @@ discard block |
||
804 | 776 | $attribute_value = $this->DecodeAttribute($attribute_raw_value, $attribute_type); |
805 | 777 | |
806 | 778 | $attribute_info = $this->GetAttributesInfo($attribute_type); |
807 | - if (26 == $attribute_type) |
|
808 | - { |
|
779 | + if (26 == $attribute_type) { |
|
809 | 780 | $vendor_array = $this->DecodeVendorSpecificContent($attribute_value); |
810 | 781 | foreach ($vendor_array as $vendor_one) |
811 | 782 | { |
812 | 783 | $this->DebugInfo('Attribute '.$attribute_type.' ('.$attribute_info[0].'), length '.($attribute_length - 2).', format '.$attribute_info[1].', Vendor-Id: '.$vendor_one[0].", Vendor-type: ".$vendor_one[1].", Attribute-specific: ".$vendor_one[2]); |
813 | 784 | } |
814 | - } else |
|
815 | - { |
|
785 | + } |
|
786 | + else { |
|
816 | 787 | $this->DebugInfo('Attribute '.$attribute_type.' ('.$attribute_info[0].'), length '.($attribute_length - 2).', format '.$attribute_info[1].', value <em>'.$attribute_value.'</em>'); |
817 | 788 | } |
818 | 789 |
@@ -133,10 +133,13 @@ discard block |
||
133 | 133 | public function isAlive() { |
134 | 134 | $pid = pcntl_waitpid( $this->pid, $status, WNOHANG ); |
135 | 135 | |
136 | - if ($pid === 0) { // child is still alive |
|
136 | + if ($pid === 0) { |
|
137 | +// child is still alive |
|
137 | 138 | return true; |
138 | - } else { |
|
139 | - if (pcntl_wifexited($status) && $this->exitCode == -1) { // normal exit |
|
139 | + } |
|
140 | + else { |
|
141 | + if (pcntl_wifexited($status) && $this->exitCode == -1) { |
|
142 | +// normal exit |
|
140 | 143 | $this->exitCode = pcntl_wexitstatus($status); |
141 | 144 | } |
142 | 145 | return false; |
@@ -196,12 +199,17 @@ discard block |
||
196 | 199 | $results = null; |
197 | 200 | $pid = pcntl_fork(); |
198 | 201 | |
199 | - if( $pid == -1 ) { //error forking, no child is created |
|
202 | + if( $pid == -1 ) { |
|
203 | +//error forking, no child is created |
|
200 | 204 | throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK ); |
201 | - }else if ( $pid ) {// parent |
|
205 | + } |
|
206 | + else if ( $pid ) { |
|
207 | +// parent |
|
202 | 208 | $this->pid = $pid; |
203 | 209 | |
204 | - } else { // child |
|
210 | + } |
|
211 | + else { |
|
212 | +// child |
|
205 | 213 | $this->pid = posix_getpid();//pid (child) |
206 | 214 | $this->ppid = posix_getppid();//pid (parent) |
207 | 215 | |
@@ -209,13 +217,15 @@ discard block |
||
209 | 217 | $array_args = func_get_args(); |
210 | 218 | if ( !empty( $array_args ) ) { |
211 | 219 | $results = call_user_func_array( $this->runnable, $array_args ); |
212 | - }else{ |
|
220 | + } |
|
221 | + else { |
|
213 | 222 | $results = call_user_func( $this->runnable ); |
214 | 223 | } |
215 | 224 | |
216 | 225 | $pipe = "/tmp/pipe_".$this->pid;//pid is known by parent |
217 | 226 | |
218 | - if(!file_exists($pipe)) {//child talks to parent using this pipe |
|
227 | + if(!file_exists($pipe)) { |
|
228 | +//child talks to parent using this pipe |
|
219 | 229 | umask(0); |
220 | 230 | posix_mkfifo($pipe, 0600); |
221 | 231 | } |
@@ -87,8 +87,9 @@ discard block |
||
87 | 87 | //set smtp |
88 | 88 | $this->Php_mailer->isSMTP(); |
89 | 89 | //tls, ssl? |
90 | - if ($this->mail_settings->msecure != 'none') |
|
91 | - $this->Php_mailer->SMTPSecure = $this->mail_settings->msecure == 'ssl' ? 'ssl' : 'tls'; |
|
90 | + if ($this->mail_settings->msecure != 'none') { |
|
91 | + $this->Php_mailer->SMTPSecure = $this->mail_settings->msecure == 'ssl' ? 'ssl' : 'tls'; |
|
92 | + } |
|
92 | 93 | //server |
93 | 94 | $this->Php_mailer->Host = $this->mail_settings->mserver; |
94 | 95 | $this->Php_mailer->Port = $this->mail_settings->mport; |
@@ -109,7 +110,8 @@ discard block |
||
109 | 110 | $this->Php_mailer->SMTPAuth = true; |
110 | 111 | $this->Php_mailer->Username = $this->mail_settings->muser; |
111 | 112 | $this->Php_mailer->Password = $this->mail_settings->mpass; |
112 | - } else { |
|
113 | + } |
|
114 | + else { |
|
113 | 115 | $this->Php_mailer->SMTPAuth = false; |
114 | 116 | } |
115 | 117 | } |
@@ -50,7 +50,8 @@ discard block |
||
50 | 50 | $firewallZoneSettings = json_decode($this->settings->firewallZoneSettings,true); |
51 | 51 | if ($firewallZoneSettings['padding'] == 'on') { |
52 | 52 | return str_pad(dechex($zone),$firewallZoneSettings['zoneLength'],"0",STR_PAD_LEFT); |
53 | - } else { |
|
53 | + } |
|
54 | + else { |
|
54 | 55 | return dechex($zone); |
55 | 56 | } |
56 | 57 | |
@@ -70,9 +71,11 @@ discard block |
||
70 | 71 | # execute based on action |
71 | 72 | if($firewallZoneSettings['zoneGenerator'] == 0 || $firewallZoneSettings['zoneGenerator'] == 1 ) { |
72 | 73 | return $this->generate_numeric_zone_name ($firewallZoneSettings['zoneLength'],$firewallZoneSettings['zoneGenerator']); |
73 | - } elseif($firewallZoneSettings['zoneGenerator'] == 2 ) { |
|
74 | + } |
|
75 | + elseif($firewallZoneSettings['zoneGenerator'] == 2 ) { |
|
74 | 76 | return $this->validate_text_zone_name ($values); |
75 | - } else { |
|
77 | + } |
|
78 | + else { |
|
76 | 79 | return $this->Result->show("danger", _("Invalid generator ID"), true); |
77 | 80 | } |
78 | 81 | } |
@@ -89,8 +92,7 @@ discard block |
||
89 | 92 | private function generate_numeric_zone_name ($zoneLength,$zoneGenerator) { |
90 | 93 | |
91 | 94 | # execute |
92 | - try { $maxZone = $this->Database->getObjectsQuery('SELECT MAX(CAST(zone as UNSIGNED)) as zone FROM firewallZones WHERE generator NOT LIKE 2;');} |
|
93 | - catch (Exception $e) { |
|
95 | + try { $maxZone = $this->Database->getObjectsQuery('SELECT MAX(CAST(zone as UNSIGNED)) as zone FROM firewallZones WHERE generator NOT LIKE 2;');} catch (Exception $e) { |
|
94 | 96 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
95 | 97 | return false; |
96 | 98 | } |
@@ -102,17 +104,19 @@ discard block |
||
102 | 104 | if(strlen($zoneName) > $zoneLength) { |
103 | 105 | return $this->Result->show("danger", _("Maximum zone name length reached! Consider to change your settings in order to generate larger zone names."), true); |
104 | 106 | } |
105 | - } elseif($zoneGenerator == 1) { |
|
107 | + } |
|
108 | + elseif($zoneGenerator == 1) { |
|
106 | 109 | # the highest convertable integer value for dechex() is 4294967295! |
107 | 110 | if($zoneName > 4294967295) { |
108 | 111 | return $this->Result->show("danger", _("The maximum convertable vlaue is reached. Consider to switch to decimal or text mode and change the zone name length value."), true); |
109 | 112 | } |
110 | - if(strlen(dechex($zoneName)) > $zoneLength){ |
|
113 | + if(strlen(dechex($zoneName)) > $zoneLength) { |
|
111 | 114 | return $this->Result->show("danger", _("Maximum zone name length reached! Consider to change your settings in order to generate larger zone names."), true); |
112 | 115 | } |
113 | 116 | } |
114 | 117 | |
115 | - } else { |
|
118 | + } |
|
119 | + else { |
|
116 | 120 | # set the initial zone name to "1" |
117 | 121 | $zoneName = 1; |
118 | 122 | } |
@@ -133,17 +137,17 @@ discard block |
||
133 | 137 | # get settings |
134 | 138 | $firewallZoneSettings = json_decode($this->settings->firewallZoneSettings,true); |
135 | 139 | |
136 | - if($values[1]){ |
|
140 | + if($values[1]) { |
|
137 | 141 | $query = 'SELECT zone FROM firewallZones WHERE zone = ? AND id NOT LIKE ?;'; |
138 | 142 | $params = $values; |
139 | - } else { |
|
143 | + } |
|
144 | + else { |
|
140 | 145 | $query = 'SELECT zone FROM firewallZones WHERE zone = ?;'; |
141 | 146 | $params = $values[0]; |
142 | 147 | } |
143 | 148 | |
144 | 149 | # execute |
145 | - try { $uniqueZone = $this->Database->getObjectsQuery($query,$params);} |
|
146 | - catch (Exception $e) { |
|
150 | + try { $uniqueZone = $this->Database->getObjectsQuery($query,$params);} catch (Exception $e) { |
|
147 | 151 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
148 | 152 | return false; |
149 | 153 | } |
@@ -152,7 +156,8 @@ discard block |
||
152 | 156 | |
153 | 157 | $this->Result->show("danger", _("Error: The zone name ".$zone." is not unique!"), false); |
154 | 158 | |
155 | - } else { |
|
159 | + } |
|
160 | + else { |
|
156 | 161 | # set the initial zone name to "1" |
157 | 162 | $zoneName = $values[0]; |
158 | 163 | } |
@@ -213,11 +218,11 @@ discard block |
||
213 | 218 | # modify the zone output values |
214 | 219 | foreach ($mappings as $key => $val) { |
215 | 220 | # transform the zone name from decimal to hex |
216 | - if($mappings[$key]->generator == 1 ){ |
|
221 | + if($mappings[$key]->generator == 1 ) { |
|
217 | 222 | $mappings[$key]->zone = dechex($mappings[$key]->zone); |
218 | 223 | } |
219 | 224 | # add some padding if it is activated and the zone generatore is not text |
220 | - if($mappings[$key]->padding == 1 && $mappings[$key]->generator != 2){ |
|
225 | + if($mappings[$key]->padding == 1 && $mappings[$key]->generator != 2) { |
|
221 | 226 | # remove leading zeros (padding) and raise the value in case of any zone name length changes |
222 | 227 | # add some padding to reach the maximum zone name lenght |
223 | 228 | $mappings[$key]->zone = str_pad(ltrim($mappings[$key]->zone,0),$mappings[$key]->length,"0",STR_PAD_LEFT); |
@@ -287,11 +292,11 @@ discard block |
||
287 | 292 | # modify the zone output values |
288 | 293 | foreach ($mapping as $key => $val) { |
289 | 294 | # transform the zone name from decimal to hex |
290 | - if($mapping[$key]->generator == 1 ){ |
|
295 | + if($mapping[$key]->generator == 1 ) { |
|
291 | 296 | $mapping[$key]->zone = dechex($mapping[$key]->zone); |
292 | 297 | } |
293 | 298 | # add some padding if it is activated and the zone generatore is not text |
294 | - if($mapping[$key]->padding == 1 && $mapping[$key]->generator != 2){ |
|
299 | + if($mapping[$key]->padding == 1 && $mapping[$key]->generator != 2) { |
|
295 | 300 | # remove leading zeros (padding) and raise the value in case of any zone name length changes |
296 | 301 | # add some padding to reach the maximum zone name lenght |
297 | 302 | $mapping[$key]->zone = str_pad(ltrim($mapping[$key]->zone,0),$mapping[$key]->length,"0",STR_PAD_LEFT); |
@@ -365,11 +370,11 @@ discard block |
||
365 | 370 | # modify the zone output values |
366 | 371 | foreach ($info as $key => $val) { |
367 | 372 | # transform the zone name from decimal to hex |
368 | - if($info[$key]->generator == 1 ){ |
|
373 | + if($info[$key]->generator == 1 ) { |
|
369 | 374 | $info[$key]->zone = dechex($info[$key]->zone); |
370 | 375 | } |
371 | 376 | # add some padding if it is activated and the zone generatore is not text |
372 | - if($info[$key]->padding == 1 && $info[$key]->generator != 2){ |
|
377 | + if($info[$key]->padding == 1 && $info[$key]->generator != 2) { |
|
373 | 378 | # remove leading zeros (padding) and raise the value in case of any zone name length changes |
374 | 379 | # add some padding to reach the maximum zone name lenght |
375 | 380 | $info[$key]->zone = str_pad(ltrim($info[$key]->zone,0),$info[$key]->length,"0",STR_PAD_LEFT); |
@@ -416,11 +421,11 @@ discard block |
||
416 | 421 | # modify the zone output values |
417 | 422 | foreach ($zones as $key => $val) { |
418 | 423 | # transform the zone name from decimal to hex |
419 | - if($zones[$key]->generator == 1 ){ |
|
424 | + if($zones[$key]->generator == 1 ) { |
|
420 | 425 | $zones[$key]->zone = dechex($zones[$key]->zone); |
421 | 426 | } |
422 | 427 | # add some padding if it is activated and the zone generatore is not text |
423 | - if($zones[$key]->padding == 1 && $zones[$key]->generator != 2){ |
|
428 | + if($zones[$key]->padding == 1 && $zones[$key]->generator != 2) { |
|
424 | 429 | # remove leading zeros (padding) and raise the value in case of any zone name length changes |
425 | 430 | # add some padding to reach the maximum zone name lenght |
426 | 431 | $zones[$key]->zone = str_pad(ltrim($zones[$key]->zone,0),$zones[$key]->length,"0",STR_PAD_LEFT); |
@@ -476,11 +481,11 @@ discard block |
||
476 | 481 | # modify the zone output values |
477 | 482 | foreach ($zone as $key => $val) { |
478 | 483 | # transform the zone name from decimal to hex |
479 | - if($zone[$key]->generator == 1 ){ |
|
484 | + if($zone[$key]->generator == 1 ) { |
|
480 | 485 | $zone[$key]->zone = dechex($zone[$key]->zone); |
481 | 486 | } |
482 | 487 | # add some padding if it is activated and the zone generatore is not text |
483 | - if($zone[$key]->padding == 1 && $zone[$key]->generator != 2){ |
|
488 | + if($zone[$key]->padding == 1 && $zone[$key]->generator != 2) { |
|
484 | 489 | # remove leading zeros (padding) and raise the value in case of any zone name length changes |
485 | 490 | # add some padding to reach the maximum zone name lenght |
486 | 491 | $zone[$key]->zone = str_pad(ltrim($zone[$key]->zone,0),$zone[$key]->length,"0",STR_PAD_LEFT); |
@@ -545,7 +550,8 @@ discard block |
||
545 | 550 | |
546 | 551 | if (!$network->subnetIsFolder) { |
547 | 552 | print '<td>'.$this->Subnets->transform_to_dotted($network->subnet).'/'.$network->subnetMask.$network->subnetDescription.'</td>'; |
548 | - } else{ |
|
553 | + } |
|
554 | + else { |
|
549 | 555 | print '<td>Folder '.$network->subnetDescription.'</td>'; |
550 | 556 | } |
551 | 557 | print '<td>'.$network->vlan.$network->vlanName.'</td>'; |
@@ -597,7 +603,8 @@ discard block |
||
597 | 603 | |
598 | 604 | if ($network->subnetIsFolder == 1 ) { |
599 | 605 | print 'Folder: '.$network->subnetDescription; |
600 | - } else { |
|
606 | + } |
|
607 | + else { |
|
601 | 608 | # display network information with or without description |
602 | 609 | if ($network->subnetDescription) { print $this->Subnets->transform_to_dotted($network->subnet).'/'.$network->subnetMask.' ('.$network->subnetDescription.')</td>'; } |
603 | 610 | else { print $this->Subnets->transform_to_dotted($network->subnet).'/'.$network->subnetMask.'</td>'; } |
@@ -626,7 +633,8 @@ discard block |
||
626 | 633 | if(!sizeof($networkInformation)>0 ) { |
627 | 634 | # return dummy value |
628 | 635 | return 'success'; |
629 | - } else { |
|
636 | + } |
|
637 | + else { |
|
630 | 638 | $this->Result->show("danger","<strong>"._('Error').":</strong><br>"._("This network is already bound to this or another zone.<br>The binding must be unique."), false); |
631 | 639 | return false; |
632 | 640 | } |
@@ -659,7 +667,8 @@ discard block |
||
659 | 667 | |
660 | 668 | # throw exception |
661 | 669 | catch (Exception $e) {$this->Result->show("danger", _("Database error: ").$e->getMessage());} |
662 | - } else { |
|
670 | + } |
|
671 | + else { |
|
663 | 672 | $this->Result->show("danger","<strong>"._('Error').":</strong><br>"._("This network is already bound to this or another zone.<br>The binding must be unique."), false); |
664 | 673 | return false; |
665 | 674 | } |
@@ -686,7 +695,8 @@ discard block |
||
686 | 695 | # return dummy value or false |
687 | 696 | if ($deleteRow) { |
688 | 697 | return 'success'; |
689 | - } else { |
|
698 | + } |
|
699 | + else { |
|
690 | 700 | return false; |
691 | 701 | } |
692 | 702 | } |
@@ -738,16 +748,14 @@ discard block |
||
738 | 748 | $values['length'] = $firewallZoneSettings['zoneLength']; |
739 | 749 | |
740 | 750 | # execute insert |
741 | - try { $this->Database->insertObject("firewallZones", $values); } |
|
742 | - catch (Exception $e) { |
|
751 | + try { $this->Database->insertObject("firewallZones", $values); } catch (Exception $e) { |
|
743 | 752 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
744 | 753 | $this->Log->write( "Firewall zone created", "Failed to add new firewall zone<hr>".$e->getMessage(), 2, $this->User->username); |
745 | 754 | return false; |
746 | 755 | } |
747 | 756 | |
748 | 757 | # fetch the highest inserted id, matching the zone name |
749 | - try { $lastId=$this->Database->getObjectsQuery("SELECT MAX(id) AS id FROM firewallZones WHERE zone = ? ;", $values['zone']);} |
|
750 | - catch (Exception $e) { |
|
758 | + try { $lastId=$this->Database->getObjectsQuery("SELECT MAX(id) AS id FROM firewallZones WHERE zone = ? ;", $values['zone']);} catch (Exception $e) { |
|
751 | 759 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
752 | 760 | return false; |
753 | 761 | } |
@@ -756,8 +764,7 @@ discard block |
||
756 | 764 | foreach ($network as $subnetId) { |
757 | 765 | $values = array('zoneId' => $lastId[0]->id, 'subnetId' => $subnetId); |
758 | 766 | # add the network bindings if there are any |
759 | - try { $this->Database->insertObject("firewallZoneSubnet", $values); } |
|
760 | - catch (Exception $e) { |
|
767 | + try { $this->Database->insertObject("firewallZoneSubnet", $values); } catch (Exception $e) { |
|
761 | 768 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
762 | 769 | return false; |
763 | 770 | } |
@@ -779,8 +786,7 @@ discard block |
||
779 | 786 | */ |
780 | 787 | private function zone_edit ($values) { |
781 | 788 | # execute |
782 | - try { $this->Database->updateObject("firewallZones", $values, "id"); } |
|
783 | - catch (Exception $e) { |
|
789 | + try { $this->Database->updateObject("firewallZones", $values, "id"); } catch (Exception $e) { |
|
784 | 790 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
785 | 791 | $this->Log->write( "Firewall zone edited", "Failed to edit firewall zone<hr>".$e->getMessage(), 2, $this->User->username); |
786 | 792 | return false; |
@@ -803,16 +809,14 @@ discard block |
||
803 | 809 | $old_zone = $this->get_zone($id); |
804 | 810 | |
805 | 811 | # delete mappings |
806 | - try { $this->Database->deleteRow("firewallZoneMapping", "zoneId", $id); } |
|
807 | - catch (Exception $e) { |
|
812 | + try { $this->Database->deleteRow("firewallZoneMapping", "zoneId", $id); } catch (Exception $e) { |
|
808 | 813 | $this->Log->write( "Firewall zone and mappings delete", "Failed to delete firewall zone mappfings of $old_zone->zone<hr>".$e->getMessage(), 2, $this->User->username); |
809 | 814 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
810 | 815 | return false; |
811 | 816 | } |
812 | 817 | |
813 | 818 | # delete zone |
814 | - try { $this->Database->deleteRow("firewallZones", "id", $id); } |
|
815 | - catch (Exception $e) { |
|
819 | + try { $this->Database->deleteRow("firewallZones", "id", $id); } catch (Exception $e) { |
|
816 | 820 | $this->Log->write( "Firewall zone delete", "Failed to delete firewall zone $old_zone->zone<hr>".$e->getMessage(), 2, $this->User->username); |
817 | 821 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
818 | 822 | return false; |
@@ -859,8 +863,7 @@ discard block |
||
859 | 863 | $firewallZoneSettings = json_decode($this->settings->firewallZoneSettings,true); |
860 | 864 | |
861 | 865 | # execute |
862 | - try { $this->Database->insertObject("firewallZoneMapping", $values); } |
|
863 | - catch (Exception $e) { |
|
866 | + try { $this->Database->insertObject("firewallZoneMapping", $values); } catch (Exception $e) { |
|
864 | 867 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
865 | 868 | $this->Log->write( "Firewall zone mapping created", "Failed to add new firewall zone mapping<hr>".$e->getMessage(), 2, $this->User->username); |
866 | 869 | return false; |
@@ -880,8 +883,7 @@ discard block |
||
880 | 883 | */ |
881 | 884 | private function mapping_edit ($values) { |
882 | 885 | # execute |
883 | - try { $this->Database->updateObject("firewallZoneMapping", $values, "id"); } |
|
884 | - catch (Exception $e) { |
|
886 | + try { $this->Database->updateObject("firewallZoneMapping", $values, "id"); } catch (Exception $e) { |
|
885 | 887 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
886 | 888 | $this->Log->write( "Firewall zone mapping edited", "Failed to edit firewall zone mapping<hr>".$e->getMessage(), 2, $this->User->username); |
887 | 889 | return false; |
@@ -904,8 +906,7 @@ discard block |
||
904 | 906 | $old_mapping = $this->get_zone_mapping($id); |
905 | 907 | |
906 | 908 | # delete mapping |
907 | - try { $this->Database->deleteRow("firewallZoneMapping", "id", $id); } |
|
908 | - catch (Exception $e) { |
|
909 | + try { $this->Database->deleteRow("firewallZoneMapping", "id", $id); } catch (Exception $e) { |
|
909 | 910 | $this->Log->write( "Firewall zone mapping delete", "Failed to delete firewall zone mapping $old_zone->zone<hr>".$e->getMessage(), 2, $this->User->username); |
910 | 911 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
911 | 912 | return false; |
@@ -944,7 +945,8 @@ discard block |
||
944 | 945 | # check if the subnet is v4 or v6 |
945 | 946 | if (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
946 | 947 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][0]; |
947 | - } elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
948 | + } |
|
949 | + elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
948 | 950 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][1]; |
949 | 951 | } |
950 | 952 | break; |
@@ -959,10 +961,12 @@ discard block |
||
959 | 961 | # check if the subnet is v4 or v6 |
960 | 962 | if (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
961 | 963 | $firewallAddressObject = $firewallAddressObject.$this->Subnets->transform_to_dotted($zone->subnet).'-'.$zone->mask; |
962 | - } elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
964 | + } |
|
965 | + elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
963 | 966 | $firewallAddressObject = $firewallAddressObject.str_replace(':',$firewallZoneSettings['separator'],$this->Subnets->transform_to_dotted($zone->subnet)).'-'.$zone->mask; |
964 | 967 | } |
965 | - } elseif ($firewallZoneSettings['subnetPatternValues'][$firewallZoneSettings['subnetPattern']] == 'description' ) { |
|
968 | + } |
|
969 | + elseif ($firewallZoneSettings['subnetPatternValues'][$firewallZoneSettings['subnetPattern']] == 'description' ) { |
|
966 | 970 | $firewallAddressObject = $firewallAddressObject.str_replace(' ',$firewallZoneSettings['separator'],strtolower($zone->subnetDescription)); |
967 | 971 | } |
968 | 972 | |
@@ -973,8 +977,7 @@ discard block |
||
973 | 977 | if ($zone->firewallAddressObject != $firewallAddressObject ) { |
974 | 978 | # update field in database |
975 | 979 | $values = array('id' => $id , 'firewallAddressObject' => $firewallAddressObject); |
976 | - try { $this->Database->updateObject("subnets", $values, "id"); } |
|
977 | - catch (Exception $e) { |
|
980 | + try { $this->Database->updateObject("subnets", $values, "id"); } catch (Exception $e) { |
|
978 | 981 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
979 | 982 | return false; |
980 | 983 | } |
@@ -1018,7 +1021,8 @@ discard block |
||
1018 | 1021 | # check if the subnet is v4 or v6 |
1019 | 1022 | if (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
1020 | 1023 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][0]; |
1021 | - } elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1024 | + } |
|
1025 | + elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1022 | 1026 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][1]; |
1023 | 1027 | } |
1024 | 1028 | break; |
@@ -1072,7 +1076,8 @@ discard block |
||
1072 | 1076 | # check if the subnet is v4 or v6 |
1073 | 1077 | if (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
1074 | 1078 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][0]; |
1075 | - } elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1079 | + } |
|
1080 | + elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1076 | 1081 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][1]; |
1077 | 1082 | } |
1078 | 1083 | break; |
@@ -1092,8 +1097,7 @@ discard block |
||
1092 | 1097 | if ($address_old->firewallAddressObject != $firewallAddressObject) { |
1093 | 1098 | # update field in database |
1094 | 1099 | $values = array('id' => $IPId , 'subnetId' => $subnetId, 'firewallAddressObject' => $firewallAddressObject); |
1095 | - try { $this->Database->updateObject("ipaddresses", $values, "id", "subnetId"); } |
|
1096 | - catch (Exception $e) { |
|
1100 | + try { $this->Database->updateObject("ipaddresses", $values, "id", "subnetId"); } catch (Exception $e) { |
|
1097 | 1101 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
1098 | 1102 | return false; |
1099 | 1103 | } |
@@ -1127,8 +1131,7 @@ discard block |
||
1127 | 1131 | # fetch zone informations |
1128 | 1132 | $zone = $this->get_zone_subnet_info($subnetId); |
1129 | 1133 | |
1130 | - try { $ipaddresses = $this->Database->getObjectsQuery('SELECT id, dns_name FROM ipaddresses WHERE subnetId = ? ',$subnetId); } |
|
1131 | - catch (Exception $e) { |
|
1134 | + try { $ipaddresses = $this->Database->getObjectsQuery('SELECT id, dns_name FROM ipaddresses WHERE subnetId = ? ',$subnetId); } catch (Exception $e) { |
|
1132 | 1135 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
1133 | 1136 | return false; |
1134 | 1137 | } |
@@ -1149,7 +1152,8 @@ discard block |
||
1149 | 1152 | # check if the subnet is v4 or v6 |
1150 | 1153 | if (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
1151 | 1154 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][0]; |
1152 | - } elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1155 | + } |
|
1156 | + elseif (filter_var($this->Subnets->transform_to_dotted($zone->subnet), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
1153 | 1157 | $firewallAddressObject = $firewallAddressObject.$firewallZoneSettings['ipType'][1]; |
1154 | 1158 | } |
1155 | 1159 | break; |
@@ -1169,8 +1173,7 @@ discard block |
||
1169 | 1173 | if ($address_old->firewallAddressObject != $firewallAddressObject) { |
1170 | 1174 | # update field in database |
1171 | 1175 | $values = array('id' => $ipaddress->id , 'subnetId' => $subnetId, 'firewallAddressObject' => $firewallAddressObject); |
1172 | - try { $this->Database->updateObject("ipaddresses", $values, "id", "subnetId"); } |
|
1173 | - catch (Exception $e) { |
|
1176 | + try { $this->Database->updateObject("ipaddresses", $values, "id", "subnetId"); } catch (Exception $e) { |
|
1174 | 1177 | $this->Result->show("danger", _("Error: ").$e->getMessage(), false); |
1175 | 1178 | return false; |
1176 | 1179 | } |
@@ -312,9 +312,15 @@ discard block |
||
312 | 312 | * @return void |
313 | 313 | */ |
314 | 314 | public function __construct($username = null, $password = null, $charset = null, $ssl = null) { |
315 | - if (isset($username)) $this->username = $username; |
|
316 | - if (isset($password)) $this->password = $password; |
|
317 | - if (isset($charset)) $this->charset = $charset; |
|
315 | + if (isset($username)) { |
|
316 | + $this->username = $username; |
|
317 | + } |
|
318 | + if (isset($password)) { |
|
319 | + $this->password = $password; |
|
320 | + } |
|
321 | + if (isset($charset)) { |
|
322 | + $this->charset = $charset; |
|
323 | + } |
|
318 | 324 | # ssl |
319 | 325 | if ($ssl) { |
320 | 326 | $this->ssl = $ssl; |
@@ -332,9 +338,11 @@ discard block |
||
332 | 338 | public static function toDate($date = null) { |
333 | 339 | if (is_int($date)) { |
334 | 340 | return date('Y-m-d H:i:s', $date); |
335 | - } else if (is_string($date)) { |
|
341 | + } |
|
342 | + else if (is_string($date)) { |
|
336 | 343 | return date('Y-m-d H:i:s', strtotime($date)); |
337 | - } else { |
|
344 | + } |
|
345 | + else { |
|
338 | 346 | return date('Y-m-d H:i:s'); |
339 | 347 | } |
340 | 348 | } |
@@ -419,12 +427,15 @@ discard block |
||
419 | 427 | if ($len>1) { |
420 | 428 | if ($str[0] == "'" && $str[$len-1] == "'") { |
421 | 429 | return substr($str, 1, -1); |
422 | - } else if ($str[0] == "'") { |
|
430 | + } |
|
431 | + else if ($str[0] == "'") { |
|
423 | 432 | return substr($str, 1); |
424 | - } else if ($str[$len-1] == "'") { |
|
433 | + } |
|
434 | + else if ($str[$len-1] == "'") { |
|
425 | 435 | return substr($str, 0, -1); |
426 | 436 | } |
427 | - } else if ($len>0) { |
|
437 | + } |
|
438 | + else if ($len>0) { |
|
428 | 439 | if ($str[0] == "'") { |
429 | 440 | return ''; |
430 | 441 | } |
@@ -463,7 +474,9 @@ discard block |
||
463 | 474 | * @return void |
464 | 475 | */ |
465 | 476 | public function runQuery($query, $values = array()) { |
466 | - if (!$this->isConnected()) $this->connect(); |
|
477 | + if (!$this->isConnected()) { |
|
478 | + $this->connect(); |
|
479 | + } |
|
467 | 480 | |
468 | 481 | $statement = $this->pdo->prepare($query); |
469 | 482 | //debuq |
@@ -480,7 +493,9 @@ discard block |
||
480 | 493 | * @return void |
481 | 494 | */ |
482 | 495 | public function escape($str) { |
483 | - if (!$this->isConnected()) $this->connect(); |
|
496 | + if (!$this->isConnected()) { |
|
497 | + $this->connect(); |
|
498 | + } |
|
484 | 499 | |
485 | 500 | return $this->unquote_outer($this->pdo->quote((string)$str)); |
486 | 501 | } |
@@ -493,7 +508,9 @@ discard block |
||
493 | 508 | * @return void |
494 | 509 | */ |
495 | 510 | public function numObjects($tableName) { |
496 | - if (!$this->isConnected()) $this->connect(); |
|
511 | + if (!$this->isConnected()) { |
|
512 | + $this->connect(); |
|
513 | + } |
|
497 | 514 | |
498 | 515 | $tableName = $this->escape($tableName); |
499 | 516 | $statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;'); |
@@ -515,7 +532,9 @@ discard block |
||
515 | 532 | * @return void |
516 | 533 | */ |
517 | 534 | public function numObjectsFilter($tableName, $method, $value) { |
518 | - if (!$this->isConnected()) $this->connect(); |
|
535 | + if (!$this->isConnected()) { |
|
536 | + $this->connect(); |
|
537 | + } |
|
519 | 538 | |
520 | 539 | $tableName = $this->escape($tableName); |
521 | 540 | $statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'`=?;'); |
@@ -540,7 +559,9 @@ discard block |
||
540 | 559 | * @return void |
541 | 560 | */ |
542 | 561 | public function updateObject($tableName, $obj, $primarykey = 'id', $primarykey2 = null) { |
543 | - if (!$this->isConnected()) $this->connect(); |
|
562 | + if (!$this->isConnected()) { |
|
563 | + $this->connect(); |
|
564 | + } |
|
544 | 565 | |
545 | 566 | $obj = (array)$obj; |
546 | 567 | |
@@ -575,10 +596,12 @@ discard block |
||
575 | 596 | $preparedParamStr = implode(',', $preparedParamArr); |
576 | 597 | |
577 | 598 | //primary key 2? |
578 | - if(!is_null($primarykey2)) |
|
579 | - $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;'); |
|
580 | - else |
|
581 | - $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;'); |
|
599 | + if(!is_null($primarykey2)) { |
|
600 | + $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;'); |
|
601 | + } |
|
602 | + else { |
|
603 | + $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;'); |
|
604 | + } |
|
582 | 605 | |
583 | 606 | //merge the parameters and values |
584 | 607 | $paramValues = array_merge(array_values($obj), $objId); |
@@ -627,7 +650,9 @@ discard block |
||
627 | 650 | * @return void |
628 | 651 | */ |
629 | 652 | public function insertObject($tableName, $obj, $raw = false, $replace = false) { |
630 | - if (!$this->isConnected()) $this->connect(); |
|
653 | + if (!$this->isConnected()) { |
|
654 | + $this->connect(); |
|
655 | + } |
|
631 | 656 | |
632 | 657 | $obj = (array)$obj; |
633 | 658 | |
@@ -654,7 +679,8 @@ discard block |
||
654 | 679 | |
655 | 680 | if ($replace) { |
656 | 681 | $statement = $this->pdo->prepare('REPLACE INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');'); |
657 | - } else { |
|
682 | + } |
|
683 | + else { |
|
658 | 684 | $statement = $this->pdo->prepare('INSERT INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');'); |
659 | 685 | } |
660 | 686 | |
@@ -697,7 +723,9 @@ discard block |
||
697 | 723 | * @return void |
698 | 724 | */ |
699 | 725 | public function getObjects($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') { |
700 | - if (!$this->isConnected()) $this->connect(); |
|
726 | + if (!$this->isConnected()) { |
|
727 | + $this->connect(); |
|
728 | + } |
|
701 | 729 | |
702 | 730 | $sortStr = ''; |
703 | 731 | if (!$sortAsc) { |
@@ -711,7 +739,8 @@ discard block |
||
711 | 739 | if ($numRecords === null) { |
712 | 740 | //get all (no limit) |
713 | 741 | $statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';'); |
714 | - } else { |
|
742 | + } |
|
743 | + else { |
|
715 | 744 | //get a limited range of objects |
716 | 745 | $statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';'); |
717 | 746 | } |
@@ -738,7 +767,9 @@ discard block |
||
738 | 767 | * @return void |
739 | 768 | */ |
740 | 769 | public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) { |
741 | - if (!$this->isConnected()) $this->connect(); |
|
770 | + if (!$this->isConnected()) { |
|
771 | + $this->connect(); |
|
772 | + } |
|
742 | 773 | |
743 | 774 | $statement = $this->pdo->prepare($query); |
744 | 775 | |
@@ -770,7 +801,9 @@ discard block |
||
770 | 801 | * @return void |
771 | 802 | */ |
772 | 803 | public function getObjectsQuery($query = null, $values = array(), $class = 'stdClass') { |
773 | - if (!$this->isConnected()) $this->connect(); |
|
804 | + if (!$this->isConnected()) { |
|
805 | + $this->connect(); |
|
806 | + } |
|
774 | 807 | |
775 | 808 | $statement = $this->pdo->prepare($query); |
776 | 809 | |
@@ -799,7 +832,9 @@ discard block |
||
799 | 832 | * @return void |
800 | 833 | */ |
801 | 834 | public function getObject($tableName, $id = null, $class = 'stdClass') { |
802 | - if (!$this->isConnected()) $this->connect(); |
|
835 | + if (!$this->isConnected()) { |
|
836 | + $this->connect(); |
|
837 | + } |
|
803 | 838 | $id = intval($id); |
804 | 839 | |
805 | 840 | //has a custom query been provided? |
@@ -809,7 +844,8 @@ discard block |
||
809 | 844 | if ($id !== null) { |
810 | 845 | $statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;'); |
811 | 846 | $statement->bindParam(1, $id, \PDO::PARAM_INT); |
812 | - } else { |
|
847 | + } |
|
848 | + else { |
|
813 | 849 | $statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` LIMIT 1;'); |
814 | 850 | } |
815 | 851 | |
@@ -822,7 +858,8 @@ discard block |
||
822 | 858 | |
823 | 859 | if ($resultObj === false) { |
824 | 860 | return null; |
825 | - } else { |
|
861 | + } |
|
862 | + else { |
|
826 | 863 | return $resultObj; |
827 | 864 | } |
828 | 865 | } |
@@ -837,7 +874,9 @@ discard block |
||
837 | 874 | * @return void |
838 | 875 | */ |
839 | 876 | public function getObjectQuery($query = null, $values = array(), $class = 'stdClass') { |
840 | - if (!$this->isConnected()) $this->connect(); |
|
877 | + if (!$this->isConnected()) { |
|
878 | + $this->connect(); |
|
879 | + } |
|
841 | 880 | |
842 | 881 | $statement = $this->pdo->prepare($query); |
843 | 882 | //debuq |
@@ -848,7 +887,8 @@ discard block |
||
848 | 887 | |
849 | 888 | if ($resultObj === false) { |
850 | 889 | return null; |
851 | - } else { |
|
890 | + } |
|
891 | + else { |
|
852 | 892 | return $resultObj; |
853 | 893 | } |
854 | 894 | } |
@@ -868,7 +908,8 @@ discard block |
||
868 | 908 | if (is_object($obj)) { |
869 | 909 | $obj = (array)$obj; |
870 | 910 | return reset($obj); |
871 | - } else { |
|
911 | + } |
|
912 | + else { |
|
872 | 913 | return null; |
873 | 914 | } |
874 | 915 | } |
@@ -975,10 +1016,12 @@ discard block |
||
975 | 1016 | $field = $this->escape($field); |
976 | 1017 | |
977 | 1018 | //multiple |
978 | - if(!is_null($field2)) |
|
979 | - return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2)); |
|
980 | - else |
|
981 | - return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value)); |
|
1019 | + if(!is_null($field2)) { |
|
1020 | + return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2)); |
|
1021 | + } |
|
1022 | + else { |
|
1023 | + return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value)); |
|
1024 | + } |
|
982 | 1025 | } |
983 | 1026 | |
984 | 1027 | /** |