@@ -355,30 +355,45 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | |
358 | + /** |
|
359 | + * @param integer $packet_code |
|
360 | + */ |
|
358 | 361 | function SetPacketCodeToSend($packet_code) |
359 | 362 | { |
360 | 363 | $this->_radius_packet_to_send = $packet_code; |
361 | 364 | } |
362 | 365 | |
363 | 366 | |
367 | + /** |
|
368 | + * @param boolean $debug_mode |
|
369 | + */ |
|
364 | 370 | function SetDebugMode($debug_mode) |
365 | 371 | { |
366 | 372 | $this->_debug_mode = (TRUE === $debug_mode); |
367 | 373 | } |
368 | 374 | |
369 | 375 | |
376 | + /** |
|
377 | + * @param string $ip_radius_server |
|
378 | + */ |
|
370 | 379 | function SetIpRadiusServer($ip_radius_server) |
371 | 380 | { |
372 | 381 | $this->_ip_radius_server = gethostbyname($ip_radius_server); |
373 | 382 | } |
374 | 383 | |
375 | 384 | |
385 | + /** |
|
386 | + * @param string $shared_secret |
|
387 | + */ |
|
376 | 388 | function SetSharedSecret($shared_secret) |
377 | 389 | { |
378 | 390 | $this->_shared_secret = $shared_secret; |
379 | 391 | } |
380 | 392 | |
381 | 393 | |
394 | + /** |
|
395 | + * @param string $radius_suffix |
|
396 | + */ |
|
382 | 397 | function SetRadiusSuffix($radius_suffix) |
383 | 398 | { |
384 | 399 | $this->_radius_suffix = $radius_suffix; |
@@ -468,6 +483,9 @@ discard block |
||
468 | 483 | } |
469 | 484 | |
470 | 485 | |
486 | + /** |
|
487 | + * @param integer $authentication_port |
|
488 | + */ |
|
471 | 489 | function SetAuthenticationPort($authentication_port) |
472 | 490 | { |
473 | 491 | if ((intval($authentication_port) > 0) && (intval($authentication_port) < 65536)) |
@@ -477,6 +495,9 @@ discard block |
||
477 | 495 | } |
478 | 496 | |
479 | 497 | |
498 | + /** |
|
499 | + * @param integer $accounting_port |
|
500 | + */ |
|
480 | 501 | function SetAccountingPort($accounting_port) |
481 | 502 | { |
482 | 503 | if ((intval($accounting_port) > 0) && (intval($accounting_port) < 65536)) |
@@ -541,6 +562,9 @@ discard block |
||
541 | 562 | } |
542 | 563 | |
543 | 564 | |
565 | + /** |
|
566 | + * @param integer $info_index |
|
567 | + */ |
|
544 | 568 | function GetRadiusPacketInfo($info_index) |
545 | 569 | { |
546 | 570 | if (isset($this->_radius_packet_info[intval($info_index)])) |
@@ -567,6 +591,9 @@ discard block |
||
567 | 591 | } |
568 | 592 | |
569 | 593 | |
594 | + /** |
|
595 | + * @param string $debug_info |
|
596 | + */ |
|
570 | 597 | function DebugInfo($debug_info) |
571 | 598 | { |
572 | 599 | if ($this->_debug_mode) |
@@ -577,6 +604,9 @@ discard block |
||
577 | 604 | } |
578 | 605 | |
579 | 606 | |
607 | + /** |
|
608 | + * @param integer $type |
|
609 | + */ |
|
580 | 610 | function SetAttribute($type, $value) |
581 | 611 | { |
582 | 612 | $attribute_index = -1; |
@@ -631,6 +661,10 @@ discard block |
||
631 | 661 | } |
632 | 662 | |
633 | 663 | |
664 | + /** |
|
665 | + * @param string $attribute_raw_value |
|
666 | + * @param integer $attribute_format |
|
667 | + */ |
|
634 | 668 | function DecodeAttribute($attribute_raw_value, $attribute_format) |
635 | 669 | { |
636 | 670 | $attribute_value = NULL; |
@@ -571,8 +571,8 @@ |
||
571 | 571 | { |
572 | 572 | if ($this->_debug_mode) |
573 | 573 | { |
574 | - //save debugging |
|
575 | - $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
574 | + //save debugging |
|
575 | + $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 |
@@ -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 |
@@ -182,32 +182,32 @@ discard block |
||
182 | 182 | *********************************************************************/ |
183 | 183 | class Radius |
184 | 184 | { |
185 | - var $_ip_radius_server; // Radius server IP address |
|
186 | - var $_shared_secret; // Shared secret with the radius server |
|
187 | - var $_radius_suffix; // Radius suffix (default is ''); |
|
188 | - var $_udp_timeout; // Timeout of the UDP connection in seconds (default value is 5) |
|
189 | - var $_authentication_port; // Authentication port (default value is 1812) |
|
190 | - var $_accounting_port; // Accouting port (default value is 1813) |
|
191 | - var $_nas_ip_address; // NAS IP address |
|
192 | - var $_nas_port; // NAS port |
|
193 | - var $_encrypted_password; // Encrypted password, as described in the RFC 2865 |
|
194 | - var $_user_ip_address; // Remote IP address of the user |
|
195 | - var $_request_authenticator; // Request-Authenticator, 16 octets random number |
|
185 | + var $_ip_radius_server; // Radius server IP address |
|
186 | + var $_shared_secret; // Shared secret with the radius server |
|
187 | + var $_radius_suffix; // Radius suffix (default is ''); |
|
188 | + var $_udp_timeout; // Timeout of the UDP connection in seconds (default value is 5) |
|
189 | + var $_authentication_port; // Authentication port (default value is 1812) |
|
190 | + var $_accounting_port; // Accouting port (default value is 1813) |
|
191 | + var $_nas_ip_address; // NAS IP address |
|
192 | + var $_nas_port; // NAS port |
|
193 | + var $_encrypted_password; // Encrypted password, as described in the RFC 2865 |
|
194 | + var $_user_ip_address; // Remote IP address of the user |
|
195 | + var $_request_authenticator; // Request-Authenticator, 16 octets random number |
|
196 | 196 | var $_response_authenticator; // Request-Authenticator, 16 octets random number |
197 | - var $_username; // Username to sent to the Radius server |
|
198 | - var $_password; // Password to sent to the Radius server (clear password, must be encrypted) |
|
199 | - var $_identifier_to_send; // Identifier field for the packet to be sent |
|
200 | - var $_identifier_received; // Identifier field for the received packet |
|
201 | - var $_radius_packet_to_send; // Radius packet code (1=Access-Request, 2=Access-Accept, 3=Access-Reject, 4=Accounting-Request, 5=Accounting-Response, 11=Access-Challenge, 12=Status-Server (experimental), 13=Status-Client (experimental), 255=Reserved |
|
197 | + var $_username; // Username to sent to the Radius server |
|
198 | + var $_password; // Password to sent to the Radius server (clear password, must be encrypted) |
|
199 | + var $_identifier_to_send; // Identifier field for the packet to be sent |
|
200 | + var $_identifier_received; // Identifier field for the received packet |
|
201 | + var $_radius_packet_to_send; // Radius packet code (1=Access-Request, 2=Access-Accept, 3=Access-Reject, 4=Accounting-Request, 5=Accounting-Response, 11=Access-Challenge, 12=Status-Server (experimental), 13=Status-Client (experimental), 255=Reserved |
|
202 | 202 | var $_radius_packet_received; // Radius packet code (1=Access-Request, 2=Access-Accept, 3=Access-Reject, 4=Accounting-Request, 5=Accounting-Response, 11=Access-Challenge, 12=Status-Server (experimental), 13=Status-Client (experimental), 255=Reserved |
203 | - var $_attributes_to_send; // Radius attributes to send |
|
204 | - var $_attributes_received; // Radius attributes received |
|
205 | - var $_socket_to_server; // Socket connection |
|
206 | - var $_debug_mode; // Debug mode flag |
|
207 | - var $_attributes_info; // Attributes info array |
|
208 | - var $_radius_packet_info; // Radius packet codes info array |
|
209 | - var $_last_error_code; // Last error code |
|
210 | - var $_last_error_message; // Last error message |
|
203 | + var $_attributes_to_send; // Radius attributes to send |
|
204 | + var $_attributes_received; // Radius attributes received |
|
205 | + var $_socket_to_server; // Socket connection |
|
206 | + var $_debug_mode; // Debug mode flag |
|
207 | + var $_attributes_info; // Attributes info array |
|
208 | + var $_radius_packet_info; // Radius packet codes info array |
|
209 | + var $_last_error_code; // Last error code |
|
210 | + var $_last_error_message; // Last error message |
|
211 | 211 | |
212 | 212 | |
213 | 213 | /********************************************************************* |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param integer accounting port |
228 | 228 | * @return NULL |
229 | 229 | *********************************************************************/ |
230 | - public function Radius($ip_radius_server = '127.0.0.1', $shared_secret = '', $radius_suffix = '', $udp_timeout = 5, $authentication_port = 1812, $accounting_port = 1813) |
|
230 | + public function Radius ($ip_radius_server = '127.0.0.1', $shared_secret = '', $radius_suffix = '', $udp_timeout = 5, $authentication_port = 1812, $accounting_port = 1813) |
|
231 | 231 | { |
232 | 232 | $this->_radius_packet_info[1] = 'Access-Request'; |
233 | 233 | $this->_radius_packet_info[2] = 'Access-Accept'; |
@@ -239,96 +239,96 @@ discard block |
||
239 | 239 | $this->_radius_packet_info[13] = 'Status-Client (experimental)'; |
240 | 240 | $this->_radius_packet_info[255] = 'Reserved'; |
241 | 241 | |
242 | - $this->_attributes_info[1] = array('User-Name', 'S'); |
|
243 | - $this->_attributes_info[2] = array('User-Password', 'S'); |
|
244 | - $this->_attributes_info[3] = array('CHAP-Password', 'S'); // Type (1) / Length (1) / CHAP Ident (1) / String |
|
245 | - $this->_attributes_info[4] = array('NAS-IP-Address', 'A'); |
|
246 | - $this->_attributes_info[5] = array('NAS-Port', 'I'); |
|
247 | - $this->_attributes_info[6] = array('Service-Type', 'I'); |
|
248 | - $this->_attributes_info[7] = array('Framed-Protocol', 'I'); |
|
249 | - $this->_attributes_info[8] = array('Framed-IP-Address', 'A'); |
|
250 | - $this->_attributes_info[9] = array('Framed-IP-Netmask', 'A'); |
|
251 | - $this->_attributes_info[10] = array('Framed-Routing', 'I'); |
|
252 | - $this->_attributes_info[11] = array('Filter-Id', 'T'); |
|
253 | - $this->_attributes_info[12] = array('Framed-MTU', 'I'); |
|
254 | - $this->_attributes_info[13] = array('Framed-Compression', 'I'); |
|
255 | - $this->_attributes_info[14] = array('Login-IP-Host', 'A'); |
|
256 | - $this->_attributes_info[15] = array('Login-service', 'I'); |
|
257 | - $this->_attributes_info[16] = array('Login-TCP-Port', 'I'); |
|
258 | - $this->_attributes_info[17] = array('(unassigned)', ''); |
|
259 | - $this->_attributes_info[18] = array('Reply-Message', 'T'); |
|
260 | - $this->_attributes_info[19] = array('Callback-Number', 'S'); |
|
261 | - $this->_attributes_info[20] = array('Callback-Id', 'S'); |
|
262 | - $this->_attributes_info[21] = array('(unassigned)', ''); |
|
263 | - $this->_attributes_info[22] = array('Framed-Route', 'T'); |
|
264 | - $this->_attributes_info[23] = array('Framed-IPX-Network', 'I'); |
|
265 | - $this->_attributes_info[24] = array('State', 'S'); |
|
266 | - $this->_attributes_info[25] = array('Class', 'S'); |
|
267 | - $this->_attributes_info[26] = array('Vendor-Specific', 'S'); // Type (1) / Length (1) / Vendor-Id (4) / Vendor type (1) / Vendor length (1) / Attribute-Specific... |
|
268 | - $this->_attributes_info[27] = array('Session-Timeout', 'I'); |
|
269 | - $this->_attributes_info[28] = array('Idle-Timeout', 'I'); |
|
270 | - $this->_attributes_info[29] = array('Termination-Action', 'I'); |
|
271 | - $this->_attributes_info[30] = array('Called-Station-Id', 'S'); |
|
272 | - $this->_attributes_info[31] = array('Calling-Station-Id', 'S'); |
|
273 | - $this->_attributes_info[32] = array('NAS-Identifier', 'S'); |
|
274 | - $this->_attributes_info[33] = array('Proxy-State', 'S'); |
|
275 | - $this->_attributes_info[34] = array('Login-LAT-Service', 'S'); |
|
276 | - $this->_attributes_info[35] = array('Login-LAT-Node', 'S'); |
|
277 | - $this->_attributes_info[36] = array('Login-LAT-Group', 'S'); |
|
278 | - $this->_attributes_info[37] = array('Framed-AppleTalk-Link', 'I'); |
|
279 | - $this->_attributes_info[38] = array('Framed-AppleTalk-Network', 'I'); |
|
280 | - $this->_attributes_info[39] = array('Framed-AppleTalk-Zone', 'S'); |
|
281 | - $this->_attributes_info[60] = array('CHAP-Challenge', 'S'); |
|
282 | - $this->_attributes_info[61] = array('NAS-Port-Type', 'I'); |
|
283 | - $this->_attributes_info[62] = array('Port-Limit', 'I'); |
|
284 | - $this->_attributes_info[63] = array('Login-LAT-Port', 'S'); |
|
285 | - $this->_attributes_info[76] = array('Prompt', 'I'); |
|
242 | + $this->_attributes_info[1] = array ('User-Name', 'S'); |
|
243 | + $this->_attributes_info[2] = array ('User-Password', 'S'); |
|
244 | + $this->_attributes_info[3] = array ('CHAP-Password', 'S'); // Type (1) / Length (1) / CHAP Ident (1) / String |
|
245 | + $this->_attributes_info[4] = array ('NAS-IP-Address', 'A'); |
|
246 | + $this->_attributes_info[5] = array ('NAS-Port', 'I'); |
|
247 | + $this->_attributes_info[6] = array ('Service-Type', 'I'); |
|
248 | + $this->_attributes_info[7] = array ('Framed-Protocol', 'I'); |
|
249 | + $this->_attributes_info[8] = array ('Framed-IP-Address', 'A'); |
|
250 | + $this->_attributes_info[9] = array ('Framed-IP-Netmask', 'A'); |
|
251 | + $this->_attributes_info[10] = array ('Framed-Routing', 'I'); |
|
252 | + $this->_attributes_info[11] = array ('Filter-Id', 'T'); |
|
253 | + $this->_attributes_info[12] = array ('Framed-MTU', 'I'); |
|
254 | + $this->_attributes_info[13] = array ('Framed-Compression', 'I'); |
|
255 | + $this->_attributes_info[14] = array ('Login-IP-Host', 'A'); |
|
256 | + $this->_attributes_info[15] = array ('Login-service', 'I'); |
|
257 | + $this->_attributes_info[16] = array ('Login-TCP-Port', 'I'); |
|
258 | + $this->_attributes_info[17] = array ('(unassigned)', ''); |
|
259 | + $this->_attributes_info[18] = array ('Reply-Message', 'T'); |
|
260 | + $this->_attributes_info[19] = array ('Callback-Number', 'S'); |
|
261 | + $this->_attributes_info[20] = array ('Callback-Id', 'S'); |
|
262 | + $this->_attributes_info[21] = array ('(unassigned)', ''); |
|
263 | + $this->_attributes_info[22] = array ('Framed-Route', 'T'); |
|
264 | + $this->_attributes_info[23] = array ('Framed-IPX-Network', 'I'); |
|
265 | + $this->_attributes_info[24] = array ('State', 'S'); |
|
266 | + $this->_attributes_info[25] = array ('Class', 'S'); |
|
267 | + $this->_attributes_info[26] = array ('Vendor-Specific', 'S'); // Type (1) / Length (1) / Vendor-Id (4) / Vendor type (1) / Vendor length (1) / Attribute-Specific... |
|
268 | + $this->_attributes_info[27] = array ('Session-Timeout', 'I'); |
|
269 | + $this->_attributes_info[28] = array ('Idle-Timeout', 'I'); |
|
270 | + $this->_attributes_info[29] = array ('Termination-Action', 'I'); |
|
271 | + $this->_attributes_info[30] = array ('Called-Station-Id', 'S'); |
|
272 | + $this->_attributes_info[31] = array ('Calling-Station-Id', 'S'); |
|
273 | + $this->_attributes_info[32] = array ('NAS-Identifier', 'S'); |
|
274 | + $this->_attributes_info[33] = array ('Proxy-State', 'S'); |
|
275 | + $this->_attributes_info[34] = array ('Login-LAT-Service', 'S'); |
|
276 | + $this->_attributes_info[35] = array ('Login-LAT-Node', 'S'); |
|
277 | + $this->_attributes_info[36] = array ('Login-LAT-Group', 'S'); |
|
278 | + $this->_attributes_info[37] = array ('Framed-AppleTalk-Link', 'I'); |
|
279 | + $this->_attributes_info[38] = array ('Framed-AppleTalk-Network', 'I'); |
|
280 | + $this->_attributes_info[39] = array ('Framed-AppleTalk-Zone', 'S'); |
|
281 | + $this->_attributes_info[60] = array ('CHAP-Challenge', 'S'); |
|
282 | + $this->_attributes_info[61] = array ('NAS-Port-Type', 'I'); |
|
283 | + $this->_attributes_info[62] = array ('Port-Limit', 'I'); |
|
284 | + $this->_attributes_info[63] = array ('Login-LAT-Port', 'S'); |
|
285 | + $this->_attributes_info[76] = array ('Prompt', 'I'); |
|
286 | 286 | |
287 | 287 | $this->_identifier_to_send = 0; |
288 | 288 | $this->_user_ip_address = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'); |
289 | 289 | |
290 | - $this->GenerateRequestAuthenticator(); |
|
291 | - $this->SetIpRadiusServer($ip_radius_server); |
|
292 | - $this->SetSharedSecret($shared_secret); |
|
293 | - $this->SetAuthenticationPort($authentication_port); |
|
294 | - $this->SetAccountingPort($accounting_port); |
|
295 | - $this->SetRadiusSuffix($radius_suffix); |
|
296 | - $this->SetUdpTimeout($udp_timeout); |
|
297 | - $this->SetUsername(); |
|
298 | - $this->SetPassword(); |
|
299 | - $this->SetNasIpAddress(); |
|
300 | - $this->SetNasPort(); |
|
301 | - |
|
302 | - $this->ClearLastError(); |
|
303 | - $this->ClearDataToSend(); |
|
304 | - $this->ClearDataReceived(); |
|
290 | + $this->GenerateRequestAuthenticator (); |
|
291 | + $this->SetIpRadiusServer ($ip_radius_server); |
|
292 | + $this->SetSharedSecret ($shared_secret); |
|
293 | + $this->SetAuthenticationPort ($authentication_port); |
|
294 | + $this->SetAccountingPort ($accounting_port); |
|
295 | + $this->SetRadiusSuffix ($radius_suffix); |
|
296 | + $this->SetUdpTimeout ($udp_timeout); |
|
297 | + $this->SetUsername (); |
|
298 | + $this->SetPassword (); |
|
299 | + $this->SetNasIpAddress (); |
|
300 | + $this->SetNasPort (); |
|
301 | + |
|
302 | + $this->ClearLastError (); |
|
303 | + $this->ClearDataToSend (); |
|
304 | + $this->ClearDataReceived (); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | |
308 | - function GetNextIdentifier() |
|
308 | + function GetNextIdentifier () |
|
309 | 309 | { |
310 | 310 | $this->_identifier_to_send = (($this->_identifier_to_send + 1) % 256); |
311 | 311 | return $this->_identifier_to_send; |
312 | 312 | } |
313 | 313 | |
314 | 314 | |
315 | - function GenerateRequestAuthenticator() |
|
315 | + function GenerateRequestAuthenticator () |
|
316 | 316 | { |
317 | 317 | $this->_request_authenticator = ''; |
318 | 318 | for ($ra_loop = 0; $ra_loop <= 15; $ra_loop++) |
319 | 319 | { |
320 | - $this->_request_authenticator .= chr(rand(1, 255)); |
|
320 | + $this->_request_authenticator .= chr (rand (1, 255)); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | |
325 | - function GetRequestAuthenticator() |
|
325 | + function GetRequestAuthenticator () |
|
326 | 326 | { |
327 | 327 | return $this->_request_authenticator; |
328 | 328 | } |
329 | 329 | |
330 | 330 | |
331 | - function GetLastError() |
|
331 | + function GetLastError () |
|
332 | 332 | { |
333 | 333 | if (0 < $this->_last_error_code) |
334 | 334 | { |
@@ -340,174 +340,174 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | |
343 | - function ClearDataToSend() |
|
343 | + function ClearDataToSend () |
|
344 | 344 | { |
345 | 345 | $this->_radius_packet_to_send = 0; |
346 | 346 | $this->_attributes_to_send = NULL; |
347 | 347 | } |
348 | 348 | |
349 | 349 | |
350 | - function ClearDataReceived() |
|
350 | + function ClearDataReceived () |
|
351 | 351 | { |
352 | 352 | $this->_radius_packet_received = 0; |
353 | 353 | $this->_attributes_received = NULL; |
354 | 354 | } |
355 | 355 | |
356 | 356 | |
357 | - function SetPacketCodeToSend($packet_code) |
|
357 | + function SetPacketCodeToSend ($packet_code) |
|
358 | 358 | { |
359 | 359 | $this->_radius_packet_to_send = $packet_code; |
360 | 360 | } |
361 | 361 | |
362 | 362 | |
363 | - function SetDebugMode($debug_mode) |
|
363 | + function SetDebugMode ($debug_mode) |
|
364 | 364 | { |
365 | 365 | $this->_debug_mode = (TRUE === $debug_mode); |
366 | 366 | } |
367 | 367 | |
368 | 368 | |
369 | - function SetIpRadiusServer($ip_radius_server) |
|
369 | + function SetIpRadiusServer ($ip_radius_server) |
|
370 | 370 | { |
371 | - $this->_ip_radius_server = gethostbyname($ip_radius_server); |
|
371 | + $this->_ip_radius_server = gethostbyname ($ip_radius_server); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | |
375 | - function SetSharedSecret($shared_secret) |
|
375 | + function SetSharedSecret ($shared_secret) |
|
376 | 376 | { |
377 | 377 | $this->_shared_secret = $shared_secret; |
378 | 378 | } |
379 | 379 | |
380 | 380 | |
381 | - function SetRadiusSuffix($radius_suffix) |
|
381 | + function SetRadiusSuffix ($radius_suffix) |
|
382 | 382 | { |
383 | 383 | $this->_radius_suffix = $radius_suffix; |
384 | 384 | } |
385 | 385 | |
386 | 386 | |
387 | - function SetUsername($username = '') |
|
387 | + function SetUsername ($username = '') |
|
388 | 388 | { |
389 | 389 | $temp_username = $username; |
390 | - if (false === strpos($temp_username, '@')) |
|
390 | + if (false === strpos ($temp_username, '@')) |
|
391 | 391 | { |
392 | 392 | $temp_username .= $this->_radius_suffix; |
393 | 393 | } |
394 | 394 | |
395 | 395 | $this->_username = $temp_username; |
396 | - $this->SetAttribute(1, $this->_username); |
|
396 | + $this->SetAttribute (1, $this->_username); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | |
400 | - function SetPassword($password = '') |
|
400 | + function SetPassword ($password = '') |
|
401 | 401 | { |
402 | 402 | $this->_password = $password; |
403 | 403 | $encrypted_password = ''; |
404 | 404 | $padded_password = $password; |
405 | 405 | |
406 | - if (0 != (strlen($password) % 16)) |
|
406 | + if (0 != (strlen ($password) % 16)) |
|
407 | 407 | { |
408 | - $padded_password .= str_repeat(chr(0), (16 - strlen($password) % 16)); |
|
408 | + $padded_password .= str_repeat (chr (0), (16 - strlen ($password) % 16)); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | $previous_result = $this->_request_authenticator; |
412 | 412 | |
413 | - for ($full_loop = 0; $full_loop < (strlen($padded_password) / 16); $full_loop++) |
|
413 | + for ($full_loop = 0; $full_loop < (strlen ($padded_password) / 16); $full_loop++) |
|
414 | 414 | { |
415 | - $xor_value = md5($this->_shared_secret.$previous_result); |
|
415 | + $xor_value = md5 ($this->_shared_secret.$previous_result); |
|
416 | 416 | |
417 | 417 | $previous_result = ''; |
418 | 418 | for ($xor_loop = 0; $xor_loop <= 15; $xor_loop++) |
419 | 419 | { |
420 | - $value1 = ord(substr($padded_password, ($full_loop * 16) + $xor_loop, 1)); |
|
421 | - $value2 = hexdec(substr($xor_value, 2 * $xor_loop, 2)); |
|
422 | - $xor_result = $value1^$value2; |
|
423 | - $previous_result .= chr($xor_result); |
|
420 | + $value1 = ord (substr ($padded_password, ($full_loop * 16) + $xor_loop, 1)); |
|
421 | + $value2 = hexdec (substr ($xor_value, 2 * $xor_loop, 2)); |
|
422 | + $xor_result = $value1 ^ $value2; |
|
423 | + $previous_result .= chr ($xor_result); |
|
424 | 424 | } |
425 | 425 | $encrypted_password .= $previous_result; |
426 | 426 | } |
427 | 427 | |
428 | 428 | $this->_encrypted_password = $encrypted_password; |
429 | - $this->SetAttribute(2, $this->_encrypted_password); |
|
429 | + $this->SetAttribute (2, $this->_encrypted_password); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | |
433 | - function SetNasIPAddress($nas_ip_address = '') |
|
433 | + function SetNasIPAddress ($nas_ip_address = '') |
|
434 | 434 | { |
435 | - if (0 < strlen($nas_ip_address)) |
|
435 | + if (0 < strlen ($nas_ip_address)) |
|
436 | 436 | { |
437 | - $this->_nas_ip_address = gethostbyname($nas_ip_address); |
|
437 | + $this->_nas_ip_address = gethostbyname ($nas_ip_address); |
|
438 | 438 | } else |
439 | 439 | { |
440 | - $this->_nas_ip_address = gethostbyname(isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'); |
|
440 | + $this->_nas_ip_address = gethostbyname (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'); |
|
441 | 441 | } |
442 | - $this->SetAttribute(4, $this->_nas_ip_address); |
|
442 | + $this->SetAttribute (4, $this->_nas_ip_address); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | |
446 | - function SetNasPort($nas_port = 0) |
|
446 | + function SetNasPort ($nas_port = 0) |
|
447 | 447 | { |
448 | - $this->_nas_port = intval($nas_port); |
|
449 | - $this->SetAttribute(5, $this->_nas_port); |
|
448 | + $this->_nas_port = intval ($nas_port); |
|
449 | + $this->SetAttribute (5, $this->_nas_port); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
453 | - function SetUdpTimeout($udp_timeout = 5) |
|
453 | + function SetUdpTimeout ($udp_timeout = 5) |
|
454 | 454 | { |
455 | - if (intval($udp_timeout) > 0) |
|
455 | + if (intval ($udp_timeout) > 0) |
|
456 | 456 | { |
457 | - $this->_udp_timeout = intval($udp_timeout); |
|
457 | + $this->_udp_timeout = intval ($udp_timeout); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | 461 | |
462 | - function ClearLastError() |
|
462 | + function ClearLastError () |
|
463 | 463 | { |
464 | 464 | $this->_last_error_code = 0; |
465 | 465 | $this->_last_error_message = ''; |
466 | 466 | } |
467 | 467 | |
468 | 468 | |
469 | - function SetAuthenticationPort($authentication_port) |
|
469 | + function SetAuthenticationPort ($authentication_port) |
|
470 | 470 | { |
471 | - if ((intval($authentication_port) > 0) && (intval($authentication_port) < 65536)) |
|
471 | + if ((intval ($authentication_port) > 0) && (intval ($authentication_port) < 65536)) |
|
472 | 472 | { |
473 | - $this->_authentication_port = intval($authentication_port); |
|
473 | + $this->_authentication_port = intval ($authentication_port); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | 477 | |
478 | - function SetAccountingPort($accounting_port) |
|
478 | + function SetAccountingPort ($accounting_port) |
|
479 | 479 | { |
480 | - if ((intval($accounting_port) > 0) && (intval($accounting_port) < 65536)) |
|
480 | + if ((intval ($accounting_port) > 0) && (intval ($accounting_port) < 65536)) |
|
481 | 481 | { |
482 | - $this->_accounting_port = intval($accounting_port); |
|
482 | + $this->_accounting_port = intval ($accounting_port); |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
486 | 486 | |
487 | - function GetReceivedPacket() |
|
487 | + function GetReceivedPacket () |
|
488 | 488 | { |
489 | 489 | return $this->_radius_packet_received; |
490 | 490 | } |
491 | 491 | |
492 | 492 | |
493 | - function GetReceivedAttributes() |
|
493 | + function GetReceivedAttributes () |
|
494 | 494 | { |
495 | 495 | return $this->_attributes_received; |
496 | 496 | } |
497 | 497 | |
498 | 498 | |
499 | - function GetReadableReceivedAttributes() |
|
499 | + function GetReadableReceivedAttributes () |
|
500 | 500 | { |
501 | 501 | $readable_attributes = ''; |
502 | 502 | if (isset($this->_attributes_received)) |
503 | 503 | { |
504 | 504 | foreach ($this->_attributes_received as $one_received_attribute) |
505 | 505 | { |
506 | - $attributes_info = $this->GetAttributesInfo($one_received_attribute[0]); |
|
506 | + $attributes_info = $this->GetAttributesInfo ($one_received_attribute[0]); |
|
507 | 507 | $readable_attributes .= $attributes_info[0].": "; |
508 | 508 | if (26 == $one_received_attribute[0]) |
509 | 509 | { |
510 | - $vendor_array = $this->DecodeVendorSpecificContent($one_received_attribute[1]); |
|
510 | + $vendor_array = $this->DecodeVendorSpecificContent ($one_received_attribute[1]); |
|
511 | 511 | foreach ($vendor_array as $vendor_one) |
512 | 512 | { |
513 | 513 | $readable_attributes .= 'Vendor-Id: '.$vendor_one[0].", Vendor-type: ".$vendor_one[1].", Attribute-specific: ".$vendor_one[2]; |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | |
526 | - function GetAttribute($attribute_type) |
|
526 | + function GetAttribute ($attribute_type) |
|
527 | 527 | { |
528 | 528 | $attribute_value = NULL; |
529 | 529 | foreach ($this->_attributes_received as $one_received_attribute) |
530 | 530 | { |
531 | - if (intval($attribute_type) == $one_received_attribute[0]) |
|
531 | + if (intval ($attribute_type) == $one_received_attribute[0]) |
|
532 | 532 | { |
533 | 533 | $attribute_value = $one_received_attribute[1]; |
534 | 534 | break; |
@@ -538,11 +538,11 @@ discard block |
||
538 | 538 | } |
539 | 539 | |
540 | 540 | |
541 | - function GetRadiusPacketInfo($info_index) |
|
541 | + function GetRadiusPacketInfo ($info_index) |
|
542 | 542 | { |
543 | - if (isset($this->_radius_packet_info[intval($info_index)])) |
|
543 | + if (isset($this->_radius_packet_info[intval ($info_index)])) |
|
544 | 544 | { |
545 | - return $this->_radius_packet_info[intval($info_index)]; |
|
545 | + return $this->_radius_packet_info[intval ($info_index)]; |
|
546 | 546 | } else |
547 | 547 | { |
548 | 548 | return ''; |
@@ -550,34 +550,34 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | |
553 | - function GetAttributesInfo($info_index) |
|
553 | + function GetAttributesInfo ($info_index) |
|
554 | 554 | { |
555 | - if (isset($this->_attributes_info[intval($info_index)])) |
|
555 | + if (isset($this->_attributes_info[intval ($info_index)])) |
|
556 | 556 | { |
557 | - return $this->_attributes_info[intval($info_index)]; |
|
557 | + return $this->_attributes_info[intval ($info_index)]; |
|
558 | 558 | } else |
559 | 559 | { |
560 | - return array('', ''); |
|
560 | + return array ('', ''); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | |
564 | 564 | |
565 | - function DebugInfo($debug_info) |
|
565 | + function DebugInfo ($debug_info) |
|
566 | 566 | { |
567 | 567 | if ($this->_debug_mode) |
568 | 568 | { |
569 | 569 | //save debugging |
570 | - $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
570 | + $this->debug_text[] = date ('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
571 | 571 | } |
572 | 572 | } |
573 | 573 | |
574 | 574 | |
575 | - function SetAttribute($type, $value) |
|
575 | + function SetAttribute ($type, $value) |
|
576 | 576 | { |
577 | 577 | $attribute_index = -1; |
578 | - for ($attributes_loop = 0; $attributes_loop < count($this->_attributes_to_send); $attributes_loop++) |
|
578 | + for ($attributes_loop = 0; $attributes_loop < count ($this->_attributes_to_send); $attributes_loop++) |
|
579 | 579 | { |
580 | - if ($type == ord(substr($this->_attributes_to_send[$attributes_loop], 0, 1))) |
|
580 | + if ($type == ord (substr ($this->_attributes_to_send[$attributes_loop], 0, 1))) |
|
581 | 581 | { |
582 | 582 | $attribute_index = $attributes_loop; |
583 | 583 | break; |
@@ -591,17 +591,17 @@ discard block |
||
591 | 591 | switch ($this->_attributes_info[$type][1]) |
592 | 592 | { |
593 | 593 | case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). |
594 | - $temp_attribute = chr($type).chr(2 + strlen($value)).$value; |
|
594 | + $temp_attribute = chr ($type).chr (2 + strlen ($value)).$value; |
|
595 | 595 | break; |
596 | 596 | case 'S': // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). |
597 | - $temp_attribute = chr($type).chr(2 + strlen($value)).$value; |
|
597 | + $temp_attribute = chr ($type).chr (2 + strlen ($value)).$value; |
|
598 | 598 | break; |
599 | 599 | case 'A': // Address, 32 bit value, most significant octet first. |
600 | - $ip_array = explode(".", $value); |
|
601 | - $temp_attribute = chr($type).chr(6).chr($ip_array[0]).chr($ip_array[1]).chr($ip_array[2]).chr($ip_array[3]); |
|
600 | + $ip_array = explode (".", $value); |
|
601 | + $temp_attribute = chr ($type).chr (6).chr ($ip_array[0]).chr ($ip_array[1]).chr ($ip_array[2]).chr ($ip_array[3]); |
|
602 | 602 | break; |
603 | 603 | case 'I': // Integer, 32 bit unsigned value, most significant octet first. |
604 | - $temp_attribute = chr($type).chr(6).chr(($value / (256 * 256 * 256)) % 256).chr(($value / (256 * 256)) % 256).chr(($value / (256)) % 256).chr($value % 256); |
|
604 | + $temp_attribute = chr ($type).chr (6).chr (($value / (256 * 256 * 256)) % 256).chr (($value / (256 * 256)) % 256).chr (($value / (256)) % 256).chr ($value % 256); |
|
605 | 605 | break; |
606 | 606 | case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) |
607 | 607 | $temp_attribute = NULL; |
@@ -620,12 +620,12 @@ discard block |
||
620 | 620 | $this->_attributes_to_send[] = $temp_attribute; |
621 | 621 | $additional_debug = 'Added'; |
622 | 622 | } |
623 | - $attribute_info = $this->GetAttributesInfo($type); |
|
624 | - $this->DebugInfo($additional_debug.' Attribute '.$type.' ('.$attribute_info[0].'), format '.$attribute_info[1].', value <em>'.$value.'</em>'); |
|
623 | + $attribute_info = $this->GetAttributesInfo ($type); |
|
624 | + $this->DebugInfo ($additional_debug.' Attribute '.$type.' ('.$attribute_info[0].'), format '.$attribute_info[1].', value <em>'.$value.'</em>'); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | |
628 | - function DecodeAttribute($attribute_raw_value, $attribute_format) |
|
628 | + function DecodeAttribute ($attribute_raw_value, $attribute_format) |
|
629 | 629 | { |
630 | 630 | $attribute_value = NULL; |
631 | 631 | |
@@ -640,10 +640,10 @@ discard block |
||
640 | 640 | $attribute_value = $attribute_raw_value; |
641 | 641 | break; |
642 | 642 | case 'A': // Address, 32 bit value, most significant octet first. |
643 | - $attribute_value = ord(substr($attribute_raw_value, 0, 1)).'.'.ord(substr($attribute_raw_value, 1, 1)).'.'.ord(substr($attribute_raw_value, 2, 1)).'.'.ord(substr($attribute_raw_value, 3, 1)); |
|
643 | + $attribute_value = ord (substr ($attribute_raw_value, 0, 1)).'.'.ord (substr ($attribute_raw_value, 1, 1)).'.'.ord (substr ($attribute_raw_value, 2, 1)).'.'.ord (substr ($attribute_raw_value, 3, 1)); |
|
644 | 644 | break; |
645 | 645 | case 'I': // Integer, 32 bit unsigned value, most significant octet first. |
646 | - $attribute_value = (ord(substr($attribute_raw_value, 0, 1)) * 256 * 256 * 256) + (ord(substr($attribute_raw_value, 1, 1)) * 256 * 256) + (ord(substr($attribute_raw_value, 2, 1)) * 256) + ord(substr($attribute_raw_value, 3, 1)); |
|
646 | + $attribute_value = (ord (substr ($attribute_raw_value, 0, 1)) * 256 * 256 * 256) + (ord (substr ($attribute_raw_value, 1, 1)) * 256 * 256) + (ord (substr ($attribute_raw_value, 2, 1)) * 256) + ord (substr ($attribute_raw_value, 3, 1)); |
|
647 | 647 | break; |
648 | 648 | case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) |
649 | 649 | $attribute_value = NULL; |
@@ -659,18 +659,18 @@ discard block |
||
659 | 659 | /********************************************************************* |
660 | 660 | * Array returned: array(array(Vendor-Id1, Vendor type1, Attribute-Specific1), ..., array(Vendor-IdN, Vendor typeN, Attribute-SpecificN) |
661 | 661 | *********************************************************************/ |
662 | - function DecodeVendorSpecificContent($vendor_specific_raw_value) |
|
662 | + function DecodeVendorSpecificContent ($vendor_specific_raw_value) |
|
663 | 663 | { |
664 | - $result = array(); |
|
664 | + $result = array (); |
|
665 | 665 | $offset_in_raw = 0; |
666 | - $vendor_id = (ord(substr($vendor_specific_raw_value, 0, 1)) * 256 * 256 * 256) + (ord(substr($vendor_specific_raw_value, 1, 1)) * 256 * 256) + (ord(substr($vendor_specific_raw_value, 2, 1)) * 256) + ord(substr($vendor_specific_raw_value, 3, 1)); |
|
666 | + $vendor_id = (ord (substr ($vendor_specific_raw_value, 0, 1)) * 256 * 256 * 256) + (ord (substr ($vendor_specific_raw_value, 1, 1)) * 256 * 256) + (ord (substr ($vendor_specific_raw_value, 2, 1)) * 256) + ord (substr ($vendor_specific_raw_value, 3, 1)); |
|
667 | 667 | $offset_in_raw += 4; |
668 | - while ($offset_in_raw < strlen($vendor_specific_raw_value)) |
|
668 | + while ($offset_in_raw < strlen ($vendor_specific_raw_value)) |
|
669 | 669 | { |
670 | - $vendor_type = (ord(substr($vendor_specific_raw_value, 0 + $offset_in_raw, 1))); |
|
671 | - $vendor_length = (ord(substr($vendor_specific_raw_value, 1 + $offset_in_raw, 1))); |
|
672 | - $attribute_specific = substr($vendor_specific_raw_value, 2 + $offset_in_raw, $vendor_length); |
|
673 | - $result[] = array($vendor_id, $vendor_type, $attribute_specific); |
|
670 | + $vendor_type = (ord (substr ($vendor_specific_raw_value, 0 + $offset_in_raw, 1))); |
|
671 | + $vendor_length = (ord (substr ($vendor_specific_raw_value, 1 + $offset_in_raw, 1))); |
|
672 | + $attribute_specific = substr ($vendor_specific_raw_value, 2 + $offset_in_raw, $vendor_length); |
|
673 | + $result[] = array ($vendor_id, $vendor_type, $attribute_specific); |
|
674 | 674 | $offset_in_raw += ($vendor_length); |
675 | 675 | } |
676 | 676 | |
@@ -683,140 +683,140 @@ discard block |
||
683 | 683 | * |
684 | 684 | * Return TRUE if Access-Request is accepted, FALSE otherwise |
685 | 685 | */ |
686 | - function AccessRequest($username = '', $password = '', $udp_timeout = 0, $state = NULL) |
|
686 | + function AccessRequest ($username = '', $password = '', $udp_timeout = 0, $state = NULL) |
|
687 | 687 | { |
688 | - $this->ClearDataReceived(); |
|
689 | - $this->ClearLastError(); |
|
688 | + $this->ClearDataReceived (); |
|
689 | + $this->ClearLastError (); |
|
690 | 690 | |
691 | - $this->SetPacketCodeToSend(1); // Access-Request |
|
691 | + $this->SetPacketCodeToSend (1); // Access-Request |
|
692 | 692 | |
693 | - if (0 < strlen($username)) |
|
693 | + if (0 < strlen ($username)) |
|
694 | 694 | { |
695 | - $this->SetUsername($username); |
|
695 | + $this->SetUsername ($username); |
|
696 | 696 | } |
697 | 697 | |
698 | - if (0 < strlen($password)) |
|
698 | + if (0 < strlen ($password)) |
|
699 | 699 | { |
700 | - $this->SetPassword($password); |
|
700 | + $this->SetPassword ($password); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | if ($state !== NULL) |
704 | 704 | { |
705 | - $this->SetAttribute(24, $state); |
|
705 | + $this->SetAttribute (24, $state); |
|
706 | 706 | } else |
707 | 707 | { |
708 | - $this->SetAttribute(6, 1); // 1=Login |
|
708 | + $this->SetAttribute (6, 1); // 1=Login |
|
709 | 709 | } |
710 | 710 | |
711 | - if (intval($udp_timeout) > 0) |
|
711 | + if (intval ($udp_timeout) > 0) |
|
712 | 712 | { |
713 | - $this->SetUdpTimeout($udp_timeout); |
|
713 | + $this->SetUdpTimeout ($udp_timeout); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | $attributes_content = ''; |
717 | - for ($attributes_loop = 0; $attributes_loop < count($this->_attributes_to_send); $attributes_loop++) |
|
717 | + for ($attributes_loop = 0; $attributes_loop < count ($this->_attributes_to_send); $attributes_loop++) |
|
718 | 718 | { |
719 | 719 | $attributes_content .= $this->_attributes_to_send[$attributes_loop]; |
720 | 720 | } |
721 | 721 | |
722 | 722 | $packet_length = 4; // Radius packet code + Identifier + Length high + Length low |
723 | - $packet_length += strlen($this->_request_authenticator); // Request-Authenticator |
|
724 | - $packet_length += strlen($attributes_content); // Attributes |
|
723 | + $packet_length += strlen ($this->_request_authenticator); // Request-Authenticator |
|
724 | + $packet_length += strlen ($attributes_content); // Attributes |
|
725 | 725 | |
726 | - $packet_data = chr($this->_radius_packet_to_send); |
|
727 | - $packet_data .= chr($this->GetNextIdentifier()); |
|
728 | - $packet_data .= chr(intval($packet_length / 256)); |
|
729 | - $packet_data .= chr(intval($packet_length % 256)); |
|
726 | + $packet_data = chr ($this->_radius_packet_to_send); |
|
727 | + $packet_data .= chr ($this->GetNextIdentifier ()); |
|
728 | + $packet_data .= chr (intval ($packet_length / 256)); |
|
729 | + $packet_data .= chr (intval ($packet_length % 256)); |
|
730 | 730 | $packet_data .= $this->_request_authenticator; |
731 | 731 | $packet_data .= $attributes_content; |
732 | 732 | |
733 | - $_socket_to_server = socket_create(AF_INET, SOCK_DGRAM, 17); // UDP packet = 17 |
|
733 | + $_socket_to_server = socket_create (AF_INET, SOCK_DGRAM, 17); // UDP packet = 17 |
|
734 | 734 | |
735 | 735 | if ($_socket_to_server === FALSE) |
736 | 736 | { |
737 | - $this->_last_error_code = socket_last_error(); |
|
738 | - $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)) |
|
737 | + $this->_last_error_code = socket_last_error (); |
|
738 | + $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 | 740 | { |
741 | - $this->_last_error_code = socket_last_error(); |
|
742 | - $this->_last_error_message = socket_strerror($this->_last_error_code); |
|
743 | - } elseif (FALSE === socket_write($_socket_to_server, $packet_data, $packet_length)) |
|
741 | + $this->_last_error_code = socket_last_error (); |
|
742 | + $this->_last_error_message = socket_strerror ($this->_last_error_code); |
|
743 | + } elseif (FALSE === socket_write ($_socket_to_server, $packet_data, $packet_length)) |
|
744 | 744 | { |
745 | - $this->_last_error_code = socket_last_error(); |
|
746 | - $this->_last_error_message = socket_strerror($this->_last_error_code); |
|
745 | + $this->_last_error_code = socket_last_error (); |
|
746 | + $this->_last_error_message = socket_strerror ($this->_last_error_code); |
|
747 | 747 | } else |
748 | 748 | { |
749 | - $this->DebugInfo('<b>Packet type '.$this->_radius_packet_to_send.' ('.$this->GetRadiusPacketInfo($this->_radius_packet_to_send).')'.' sent</b>'); |
|
749 | + $this->DebugInfo ('<b>Packet type '.$this->_radius_packet_to_send.' ('.$this->GetRadiusPacketInfo ($this->_radius_packet_to_send).')'.' sent</b>'); |
|
750 | 750 | if ($this->_debug_mode) |
751 | 751 | { |
752 | 752 | $readable_attributes = ''; |
753 | 753 | foreach ($this->_attributes_to_send as $one_attribute_to_send) |
754 | 754 | { |
755 | - $attribute_info = $this->GetAttributesInfo(ord(substr($one_attribute_to_send, 0, 1))); |
|
756 | - $this->DebugInfo('Attribute '.ord(substr($one_attribute_to_send, 0, 1)).' ('.$attribute_info[0].'), length '.(ord(substr($one_attribute_to_send, 1, 1)) - 2).', format '.$attribute_info[1].', value <em>'.$this->DecodeAttribute(substr($one_attribute_to_send, 2), ord(substr($one_attribute_to_send, 0, 1))).'</em>'); |
|
755 | + $attribute_info = $this->GetAttributesInfo (ord (substr ($one_attribute_to_send, 0, 1))); |
|
756 | + $this->DebugInfo ('Attribute '.ord (substr ($one_attribute_to_send, 0, 1)).' ('.$attribute_info[0].'), length '.(ord (substr ($one_attribute_to_send, 1, 1)) - 2).', format '.$attribute_info[1].', value <em>'.$this->DecodeAttribute (substr ($one_attribute_to_send, 2), ord (substr ($one_attribute_to_send, 0, 1))).'</em>'); |
|
757 | 757 | } |
758 | 758 | } |
759 | - $read_socket_array = array($_socket_to_server); |
|
759 | + $read_socket_array = array ($_socket_to_server); |
|
760 | 760 | $write_socket_array = NULL; |
761 | 761 | $except_socket_array = NULL; |
762 | 762 | |
763 | - $received_packet = chr(0); |
|
763 | + $received_packet = chr (0); |
|
764 | 764 | |
765 | - if (!(FALSE === socket_select($read_socket_array, $write_socket_array, $except_socket_array, $this->_udp_timeout))) |
|
765 | + if (!(FALSE === socket_select ($read_socket_array, $write_socket_array, $except_socket_array, $this->_udp_timeout))) |
|
766 | 766 | { |
767 | - if (in_array($_socket_to_server, $read_socket_array)) |
|
767 | + if (in_array ($_socket_to_server, $read_socket_array)) |
|
768 | 768 | { |
769 | - if (FALSE === ($received_packet = @socket_read($_socket_to_server, 1024))) { |
|
769 | + if (FALSE === ($received_packet = @socket_read ($_socket_to_server, 1024))) { |
|
770 | 770 | // @ used, than no error is displayed if the connection is closed by the remote host |
771 | 771 | { |
772 | - $received_packet = chr(0); |
|
772 | + $received_packet = chr (0); |
|
773 | 773 | } |
774 | - $this->_last_error_code = socket_last_error(); |
|
775 | - $this->_last_error_message = socket_strerror($this->_last_error_code); |
|
774 | + $this->_last_error_code = socket_last_error (); |
|
775 | + $this->_last_error_message = socket_strerror ($this->_last_error_code); |
|
776 | 776 | } else |
777 | 777 | { |
778 | - socket_close($_socket_to_server); |
|
778 | + socket_close ($_socket_to_server); |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | } else |
782 | 782 | { |
783 | - socket_close($_socket_to_server); |
|
783 | + socket_close ($_socket_to_server); |
|
784 | 784 | } |
785 | 785 | } |
786 | 786 | |
787 | - $this->_radius_packet_received = intval(ord(substr($received_packet, 0, 1))); |
|
787 | + $this->_radius_packet_received = intval (ord (substr ($received_packet, 0, 1))); |
|
788 | 788 | |
789 | - $this->DebugInfo('<b>Packet type '.$this->_radius_packet_received.' ('.$this->GetRadiusPacketInfo($this->_radius_packet_received).')'.' received</b>'); |
|
789 | + $this->DebugInfo ('<b>Packet type '.$this->_radius_packet_received.' ('.$this->GetRadiusPacketInfo ($this->_radius_packet_received).')'.' received</b>'); |
|
790 | 790 | |
791 | 791 | if ($this->_radius_packet_received > 0) |
792 | 792 | { |
793 | - $this->_identifier_received = intval(ord(substr($received_packet, 1, 1))); |
|
794 | - $packet_length = (intval(ord(substr($received_packet, 2, 1))) * 256) + (intval(ord(substr($received_packet, 3, 1)))); |
|
795 | - $this->_response_authenticator = substr($received_packet, 4, 16); |
|
796 | - $attributes_content = substr($received_packet, 20, ($packet_length - 4 - 16)); |
|
797 | - while (strlen($attributes_content) > 2) |
|
793 | + $this->_identifier_received = intval (ord (substr ($received_packet, 1, 1))); |
|
794 | + $packet_length = (intval (ord (substr ($received_packet, 2, 1))) * 256) + (intval (ord (substr ($received_packet, 3, 1)))); |
|
795 | + $this->_response_authenticator = substr ($received_packet, 4, 16); |
|
796 | + $attributes_content = substr ($received_packet, 20, ($packet_length - 4 - 16)); |
|
797 | + while (strlen ($attributes_content) > 2) |
|
798 | 798 | { |
799 | - $attribute_type = intval(ord(substr($attributes_content, 0, 1))); |
|
800 | - $attribute_length = intval(ord(substr($attributes_content, 1, 1))); |
|
801 | - $attribute_raw_value = substr($attributes_content, 2, $attribute_length - 2); |
|
802 | - $attributes_content = substr($attributes_content, $attribute_length); |
|
799 | + $attribute_type = intval (ord (substr ($attributes_content, 0, 1))); |
|
800 | + $attribute_length = intval (ord (substr ($attributes_content, 1, 1))); |
|
801 | + $attribute_raw_value = substr ($attributes_content, 2, $attribute_length - 2); |
|
802 | + $attributes_content = substr ($attributes_content, $attribute_length); |
|
803 | 803 | |
804 | - $attribute_value = $this->DecodeAttribute($attribute_raw_value, $attribute_type); |
|
804 | + $attribute_value = $this->DecodeAttribute ($attribute_raw_value, $attribute_type); |
|
805 | 805 | |
806 | - $attribute_info = $this->GetAttributesInfo($attribute_type); |
|
806 | + $attribute_info = $this->GetAttributesInfo ($attribute_type); |
|
807 | 807 | if (26 == $attribute_type) |
808 | 808 | { |
809 | - $vendor_array = $this->DecodeVendorSpecificContent($attribute_value); |
|
809 | + $vendor_array = $this->DecodeVendorSpecificContent ($attribute_value); |
|
810 | 810 | foreach ($vendor_array as $vendor_one) |
811 | 811 | { |
812 | - $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]); |
|
812 | + $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 | 813 | } |
814 | 814 | } else |
815 | 815 | { |
816 | - $this->DebugInfo('Attribute '.$attribute_type.' ('.$attribute_info[0].'), length '.($attribute_length - 2).', format '.$attribute_info[1].', value <em>'.$attribute_value.'</em>'); |
|
816 | + $this->DebugInfo ('Attribute '.$attribute_type.' ('.$attribute_info[0].'), length '.($attribute_length - 2).', format '.$attribute_info[1].', value <em>'.$attribute_value.'</em>'); |
|
817 | 817 | } |
818 | 818 | |
819 | - $this->_attributes_received[] = array($attribute_type, $attribute_value); |
|
819 | + $this->_attributes_received[] = array ($attribute_type, $attribute_value); |
|
820 | 820 | } |
821 | 821 | } |
822 | 822 |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @access public |
73 | 73 | * @param string $text (default: "No value provided") |
74 | - * @return void |
|
74 | + * @return string |
|
75 | 75 | */ |
76 | 76 | public function show_cli_message ($text="No value provided") { |
77 | 77 | // array - join |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * Show GUI result |
96 | 96 | * |
97 | 97 | * @access public |
98 | - * @param mixed $class |
|
99 | - * @param mixed $text |
|
100 | - * @param mixed $popup |
|
101 | - * @param mixed $popup2 |
|
102 | - * @return void |
|
98 | + * @param string $class |
|
99 | + * @param string $text |
|
100 | + * @param boolean $popup |
|
101 | + * @param boolean $popup2 |
|
102 | + * @return string |
|
103 | 103 | */ |
104 | 104 | public function show_message ($class, $text, $popup, $popup2) { |
105 | 105 | // format if array |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * Exists with exception for API |
145 | 145 | * |
146 | 146 | * @access public |
147 | - * @param mixed $content |
|
147 | + * @param string $content |
|
148 | 148 | * @return void |
149 | 149 | */ |
150 | 150 | public function throw_exception ($content) { |
@@ -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); } |
@@ -13,176 +13,176 @@ |
||
13 | 13 | |
14 | 14 | class Result extends Common_functions { |
15 | 15 | |
16 | - /** |
|
17 | - * what to do when failed - result shows result, exception throws exception (for API) |
|
18 | - * |
|
19 | - * (default value: "result") |
|
20 | - * |
|
21 | - * @var string |
|
22 | - * @access public |
|
23 | - */ |
|
24 | - public $exit_method = "result"; |
|
25 | - |
|
26 | - /** |
|
27 | - * Die flag |
|
28 | - * |
|
29 | - * (default value: false) |
|
30 | - * |
|
31 | - * @var bool |
|
32 | - * @access public |
|
33 | - */ |
|
34 | - public $die = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * Show result |
|
38 | - * |
|
39 | - * @access public |
|
40 | - * @param string $class (default: "muted") result class - danger, success, warning, info |
|
41 | - * @param string $text (default: "No value provided") text to display |
|
42 | - * @param bool $die (default: false) controls stop of php execution |
|
43 | - * @param bool $popup (default: false) print result as popup |
|
44 | - * @param bool $inline (default: false) return, not print |
|
45 | - * @param bool $popup2 (default: false) close for JS for popup2 |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function show($class="muted", $text="No value provided", $die=false, $popup=false, $inline = false, $popup2 = false) { |
|
49 | - |
|
50 | - # set die |
|
51 | - $this->die = $die; |
|
52 | - |
|
53 | - # API - throw exception |
|
54 | - if($this->exit_method == "exception") { |
|
55 | - # ok, just return success |
|
56 | - if ($class=="success") { return true; } |
|
57 | - else { return $this->throw_exception ($text); } |
|
58 | - } |
|
59 | - else { |
|
60 | - # cli or GUI |
|
61 | - if (php_sapi_name()=="cli") { print $this->show_cli_message ($text); } |
|
62 | - else { |
|
63 | - # return or print |
|
64 | - if ($inline) { return $this->show_message ($class, $text, $popup, $popup2); } |
|
65 | - else { print $this->show_message ($class, $text, $popup, $popup2); } |
|
66 | - } |
|
67 | - |
|
68 | - # die |
|
69 | - if($this->die===true) {die(); } |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Alias for show method for backwards compatibility |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @param string $text (default: "No value provided") |
|
78 | - * @param bool $die (default: false) |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function show_cli ($text="No value provided", $die=false) { |
|
82 | - $this->show(false, $text, $die, false, false, false); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Shows result for cli functions |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @param string $text (default: "No value provided") |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function show_cli_message ($text="No value provided") { |
|
93 | - // array - join |
|
94 | - if (is_array($text) && sizeof($text)>0) { |
|
95 | - // 1 element |
|
96 | - if(sizeof( $text )==1) { |
|
97 | - $text = $text[0]; |
|
98 | - } |
|
99 | - // multiple - format |
|
100 | - else { |
|
101 | - foreach( $text as $l ) { $out[] = "\t* $l"; } |
|
102 | - // join |
|
103 | - $text = implode("\n", $out); |
|
104 | - } |
|
105 | - } |
|
106 | ||
107 | - return $text."\n"; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Show GUI result |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param mixed $class |
|
115 | - * @param mixed $text |
|
116 | - * @param mixed $popup |
|
117 | - * @param mixed $popup2 |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function show_message ($class, $text, $popup, $popup2) { |
|
121 | - // to array if object |
|
122 | - if (is_object($text)) { $text = (array) $text; } |
|
123 | - // format if array |
|
124 | - if(is_array($text)) { |
|
125 | - // single value |
|
126 | - if(sizeof( $text )==1) { |
|
127 | - $out = $text; |
|
128 | - } |
|
129 | - // multiple values |
|
130 | - else { |
|
131 | - $out[] = "<ul>"; |
|
132 | - foreach( $text as $l ) { $out[] = "<li>$l</li>"; } |
|
133 | - $out[] = "</ul>"; |
|
134 | - } |
|
135 | - // join |
|
136 | - $text = implode("\n", $out); |
|
137 | - } |
|
138 | - |
|
139 | - # print popup or normal |
|
140 | - if($popup===false) { |
|
141 | - return "<div class='alert alert-".$class."'>".$text."</div>"; |
|
142 | - } |
|
143 | - else { |
|
144 | - // set close class for JS |
|
145 | - $pclass = $popup2===false ? "hidePopups" : "hidePopup2"; |
|
146 | - // change danger to error for popup |
|
147 | - $htext = $class==="danger" ? "error" : $class; |
|
148 | - |
|
149 | - $out[] = '<div class="pHeader">'._(ucwords($htext)).'</div>'; |
|
150 | - $out[] = '<div class="pContent">'; |
|
151 | - $out[] = '<div class="alert alert-'.$class.'">'.$text.'</div>'; |
|
152 | - $out[] = '</div>'; |
|
153 | - $out[] = '<div class="pFooter"><button class="btn btn-sm btn-default '.$pclass.'">'._('Close').'</button></div>'; |
|
154 | - |
|
155 | - // return |
|
156 | - return implode("\n", $out); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Exists with exception for API |
|
162 | - * |
|
163 | - * @access public |
|
164 | - * @param mixed $content |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function throw_exception ($content) { |
|
168 | - // include Exceptions class for API |
|
169 | - include_once( dirname(__FILE__) . '../../../api/controllers/Responses.php' ); |
|
170 | - // initialize exceptions |
|
171 | - $Exceptions = new Responses (); |
|
172 | - // throw error |
|
173 | - $Exceptions->throw_exception(500, $content); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * __destruct function |
|
178 | - * |
|
179 | - * @access public |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public function __destruct() { |
|
183 | - // exit if required |
|
184 | - if ($this->die === true) { die(); } |
|
185 | - } |
|
16 | + /** |
|
17 | + * what to do when failed - result shows result, exception throws exception (for API) |
|
18 | + * |
|
19 | + * (default value: "result") |
|
20 | + * |
|
21 | + * @var string |
|
22 | + * @access public |
|
23 | + */ |
|
24 | + public $exit_method = "result"; |
|
25 | + |
|
26 | + /** |
|
27 | + * Die flag |
|
28 | + * |
|
29 | + * (default value: false) |
|
30 | + * |
|
31 | + * @var bool |
|
32 | + * @access public |
|
33 | + */ |
|
34 | + public $die = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * Show result |
|
38 | + * |
|
39 | + * @access public |
|
40 | + * @param string $class (default: "muted") result class - danger, success, warning, info |
|
41 | + * @param string $text (default: "No value provided") text to display |
|
42 | + * @param bool $die (default: false) controls stop of php execution |
|
43 | + * @param bool $popup (default: false) print result as popup |
|
44 | + * @param bool $inline (default: false) return, not print |
|
45 | + * @param bool $popup2 (default: false) close for JS for popup2 |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function show($class="muted", $text="No value provided", $die=false, $popup=false, $inline = false, $popup2 = false) { |
|
49 | + |
|
50 | + # set die |
|
51 | + $this->die = $die; |
|
52 | + |
|
53 | + # API - throw exception |
|
54 | + if($this->exit_method == "exception") { |
|
55 | + # ok, just return success |
|
56 | + if ($class=="success") { return true; } |
|
57 | + else { return $this->throw_exception ($text); } |
|
58 | + } |
|
59 | + else { |
|
60 | + # cli or GUI |
|
61 | + if (php_sapi_name()=="cli") { print $this->show_cli_message ($text); } |
|
62 | + else { |
|
63 | + # return or print |
|
64 | + if ($inline) { return $this->show_message ($class, $text, $popup, $popup2); } |
|
65 | + else { print $this->show_message ($class, $text, $popup, $popup2); } |
|
66 | + } |
|
67 | + |
|
68 | + # die |
|
69 | + if($this->die===true) {die(); } |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Alias for show method for backwards compatibility |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @param string $text (default: "No value provided") |
|
78 | + * @param bool $die (default: false) |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function show_cli ($text="No value provided", $die=false) { |
|
82 | + $this->show(false, $text, $die, false, false, false); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Shows result for cli functions |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @param string $text (default: "No value provided") |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function show_cli_message ($text="No value provided") { |
|
93 | + // array - join |
|
94 | + if (is_array($text) && sizeof($text)>0) { |
|
95 | + // 1 element |
|
96 | + if(sizeof( $text )==1) { |
|
97 | + $text = $text[0]; |
|
98 | + } |
|
99 | + // multiple - format |
|
100 | + else { |
|
101 | + foreach( $text as $l ) { $out[] = "\t* $l"; } |
|
102 | + // join |
|
103 | + $text = implode("\n", $out); |
|
104 | + } |
|
105 | + } |
|
106 | ||
107 | + return $text."\n"; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Show GUI result |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param mixed $class |
|
115 | + * @param mixed $text |
|
116 | + * @param mixed $popup |
|
117 | + * @param mixed $popup2 |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function show_message ($class, $text, $popup, $popup2) { |
|
121 | + // to array if object |
|
122 | + if (is_object($text)) { $text = (array) $text; } |
|
123 | + // format if array |
|
124 | + if(is_array($text)) { |
|
125 | + // single value |
|
126 | + if(sizeof( $text )==1) { |
|
127 | + $out = $text; |
|
128 | + } |
|
129 | + // multiple values |
|
130 | + else { |
|
131 | + $out[] = "<ul>"; |
|
132 | + foreach( $text as $l ) { $out[] = "<li>$l</li>"; } |
|
133 | + $out[] = "</ul>"; |
|
134 | + } |
|
135 | + // join |
|
136 | + $text = implode("\n", $out); |
|
137 | + } |
|
138 | + |
|
139 | + # print popup or normal |
|
140 | + if($popup===false) { |
|
141 | + return "<div class='alert alert-".$class."'>".$text."</div>"; |
|
142 | + } |
|
143 | + else { |
|
144 | + // set close class for JS |
|
145 | + $pclass = $popup2===false ? "hidePopups" : "hidePopup2"; |
|
146 | + // change danger to error for popup |
|
147 | + $htext = $class==="danger" ? "error" : $class; |
|
148 | + |
|
149 | + $out[] = '<div class="pHeader">'._(ucwords($htext)).'</div>'; |
|
150 | + $out[] = '<div class="pContent">'; |
|
151 | + $out[] = '<div class="alert alert-'.$class.'">'.$text.'</div>'; |
|
152 | + $out[] = '</div>'; |
|
153 | + $out[] = '<div class="pFooter"><button class="btn btn-sm btn-default '.$pclass.'">'._('Close').'</button></div>'; |
|
154 | + |
|
155 | + // return |
|
156 | + return implode("\n", $out); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Exists with exception for API |
|
162 | + * |
|
163 | + * @access public |
|
164 | + * @param mixed $content |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function throw_exception ($content) { |
|
168 | + // include Exceptions class for API |
|
169 | + include_once( dirname(__FILE__) . '../../../api/controllers/Responses.php' ); |
|
170 | + // initialize exceptions |
|
171 | + $Exceptions = new Responses (); |
|
172 | + // throw error |
|
173 | + $Exceptions->throw_exception(500, $content); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * __destruct function |
|
178 | + * |
|
179 | + * @access public |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public function __destruct() { |
|
183 | + // exit if required |
|
184 | + if ($this->die === true) { die(); } |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | ?> |
189 | 189 | \ No newline at end of file |
@@ -45,28 +45,28 @@ discard block |
||
45 | 45 | * @param bool $popup2 (default: false) close for JS for popup2 |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function show($class="muted", $text="No value provided", $die=false, $popup=false, $inline = false, $popup2 = false) { |
|
48 | + public function show ($class = "muted", $text = "No value provided", $die = false, $popup = false, $inline = false, $popup2 = false) { |
|
49 | 49 | |
50 | 50 | # set die |
51 | 51 | $this->die = $die; |
52 | 52 | |
53 | 53 | # API - throw exception |
54 | - if($this->exit_method == "exception") { |
|
54 | + if ($this->exit_method == "exception") { |
|
55 | 55 | # ok, just return success |
56 | - if ($class=="success") { return true; } |
|
57 | - else { return $this->throw_exception ($text); } |
|
56 | + if ($class == "success") { return true; } |
|
57 | + else { return $this->throw_exception ($text); } |
|
58 | 58 | } |
59 | 59 | else { |
60 | 60 | # cli or GUI |
61 | - if (php_sapi_name()=="cli") { print $this->show_cli_message ($text); } |
|
61 | + if (php_sapi_name () == "cli") { print $this->show_cli_message ($text); } |
|
62 | 62 | else { |
63 | 63 | # return or print |
64 | - if ($inline) { return $this->show_message ($class, $text, $popup, $popup2); } |
|
65 | - else { print $this->show_message ($class, $text, $popup, $popup2); } |
|
64 | + if ($inline) { return $this->show_message ($class, $text, $popup, $popup2); } |
|
65 | + else { print $this->show_message ($class, $text, $popup, $popup2); } |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | # die |
69 | - if($this->die===true) {die(); } |
|
69 | + if ($this->die === true) {die(); } |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param bool $die (default: false) |
79 | 79 | * @return void |
80 | 80 | */ |
81 | - public function show_cli ($text="No value provided", $die=false) { |
|
82 | - $this->show(false, $text, $die, false, false, false); |
|
81 | + public function show_cli ($text = "No value provided", $die = false) { |
|
82 | + $this->show (false, $text, $die, false, false, false); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | * @param string $text (default: "No value provided") |
90 | 90 | * @return void |
91 | 91 | */ |
92 | - public function show_cli_message ($text="No value provided") { |
|
92 | + public function show_cli_message ($text = "No value provided") { |
|
93 | 93 | // array - join |
94 | - if (is_array($text) && sizeof($text)>0) { |
|
94 | + if (is_array ($text) && sizeof ($text) > 0) { |
|
95 | 95 | // 1 element |
96 | - if(sizeof( $text )==1) { |
|
96 | + if (sizeof ($text) == 1) { |
|
97 | 97 | $text = $text[0]; |
98 | 98 | } |
99 | 99 | // multiple - format |
100 | 100 | else { |
101 | - foreach( $text as $l ) { $out[] = "\t* $l"; } |
|
101 | + foreach ($text as $l) { $out[] = "\t* $l"; } |
|
102 | 102 | // join |
103 | - $text = implode("\n", $out); |
|
103 | + $text = implode ("\n", $out); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -119,41 +119,41 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function show_message ($class, $text, $popup, $popup2) { |
121 | 121 | // to array if object |
122 | - if (is_object($text)) { $text = (array) $text; } |
|
122 | + if (is_object ($text)) { $text = (array) $text; } |
|
123 | 123 | // format if array |
124 | - if(is_array($text)) { |
|
124 | + if (is_array ($text)) { |
|
125 | 125 | // single value |
126 | - if(sizeof( $text )==1) { |
|
126 | + if (sizeof ($text) == 1) { |
|
127 | 127 | $out = $text; |
128 | 128 | } |
129 | 129 | // multiple values |
130 | 130 | else { |
131 | 131 | $out[] = "<ul>"; |
132 | - foreach( $text as $l ) { $out[] = "<li>$l</li>"; } |
|
132 | + foreach ($text as $l) { $out[] = "<li>$l</li>"; } |
|
133 | 133 | $out[] = "</ul>"; |
134 | 134 | } |
135 | 135 | // join |
136 | - $text = implode("\n", $out); |
|
136 | + $text = implode ("\n", $out); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | # print popup or normal |
140 | - if($popup===false) { |
|
140 | + if ($popup === false) { |
|
141 | 141 | return "<div class='alert alert-".$class."'>".$text."</div>"; |
142 | 142 | } |
143 | 143 | else { |
144 | 144 | // set close class for JS |
145 | - $pclass = $popup2===false ? "hidePopups" : "hidePopup2"; |
|
145 | + $pclass = $popup2 === false ? "hidePopups" : "hidePopup2"; |
|
146 | 146 | // change danger to error for popup |
147 | - $htext = $class==="danger" ? "error" : $class; |
|
147 | + $htext = $class === "danger" ? "error" : $class; |
|
148 | 148 | |
149 | - $out[] = '<div class="pHeader">'._(ucwords($htext)).'</div>'; |
|
149 | + $out[] = '<div class="pHeader">'._ (ucwords ($htext)).'</div>'; |
|
150 | 150 | $out[] = '<div class="pContent">'; |
151 | 151 | $out[] = '<div class="alert alert-'.$class.'">'.$text.'</div>'; |
152 | 152 | $out[] = '</div>'; |
153 | - $out[] = '<div class="pFooter"><button class="btn btn-sm btn-default '.$pclass.'">'._('Close').'</button></div>'; |
|
153 | + $out[] = '<div class="pFooter"><button class="btn btn-sm btn-default '.$pclass.'">'._ ('Close').'</button></div>'; |
|
154 | 154 | |
155 | 155 | // return |
156 | - return implode("\n", $out); |
|
156 | + return implode ("\n", $out); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function throw_exception ($content) { |
168 | 168 | // include Exceptions class for API |
169 | - include_once( dirname(__FILE__) . '../../../api/controllers/Responses.php' ); |
|
169 | + include_once(dirname (__FILE__).'../../../api/controllers/Responses.php'); |
|
170 | 170 | // initialize exceptions |
171 | 171 | $Exceptions = new Responses (); |
172 | 172 | // throw error |
173 | - $Exceptions->throw_exception(500, $content); |
|
173 | + $Exceptions->throw_exception (500, $content); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * @access public |
180 | 180 | * @return void |
181 | 181 | */ |
182 | - public function __destruct() { |
|
182 | + public function __destruct () { |
|
183 | 183 | // exit if required |
184 | - if ($this->die === true) { die(); } |
|
184 | + if ($this->die === true) { die(); } |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * Returns all possible ping types / apps |
63 | 63 | * |
64 | 64 | * @access public |
65 | - * @return array |
|
65 | + * @return string[] |
|
66 | 66 | */ |
67 | 67 | public function ping_fetch_types () { |
68 | 68 | return array("ping", "pear", "fping"); |
@@ -152,7 +152,6 @@ discard block |
||
152 | 152 | * @param mixed $address |
153 | 153 | * @param int $count (default: 1) |
154 | 154 | * @param int $timeout (default: 1) |
155 | - * @param bool $exit (default: false) |
|
156 | 155 | * @return void |
157 | 156 | */ |
158 | 157 | public function ping_address ($address, $count=1, $timeout = 1) { |
@@ -178,7 +177,7 @@ discard block |
||
178 | 177 | * |
179 | 178 | * @access protected |
180 | 179 | * @param ip $address |
181 | - * @return void |
|
180 | + * @return null|integer |
|
182 | 181 | */ |
183 | 182 | protected function ping_address_method_ping ($address) { |
184 | 183 | # verify ping path |
@@ -276,8 +275,7 @@ discard block |
||
276 | 275 | * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
277 | 276 | * |
278 | 277 | * @access public |
279 | - * @param mixed $subnet //CIDR |
|
280 | - * @return void |
|
278 | + * @return null|integer |
|
281 | 279 | */ |
282 | 280 | public function ping_address_method_fping ($address) { |
283 | 281 | # verify ping path |
@@ -329,7 +327,7 @@ discard block |
||
329 | 327 | * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
330 | 328 | * |
331 | 329 | * @access public |
332 | - * @param mixed $subnet //CIDR |
|
330 | + * @param mixed $subnet_cidr //CIDR |
|
333 | 331 | * @return void |
334 | 332 | */ |
335 | 333 | public function ping_address_method_fping_subnet ($subnet_cidr, $return_result = false) { |
@@ -377,8 +375,8 @@ discard block |
||
377 | 375 | * Explains invalid error codes |
378 | 376 | * |
379 | 377 | * @access public |
380 | - * @param mixed $code |
|
381 | - * @return void |
|
378 | + * @param null|integer $code |
|
379 | + * @return string|false |
|
382 | 380 | */ |
383 | 381 | public function ping_exit_explain ($code) { |
384 | 382 | # fetch explain codes |
@@ -396,7 +394,7 @@ discard block |
||
396 | 394 | * extend if needed for future scripts |
397 | 395 | * |
398 | 396 | * @access public |
399 | - * @return void |
|
397 | + * @return string[] |
|
400 | 398 | */ |
401 | 399 | public function ping_set_exit_code_explains () { |
402 | 400 | $explain_codes[0] = "SUCCESS"; |
@@ -523,6 +521,7 @@ discard block |
||
523 | 521 | * |
524 | 522 | * @access public |
525 | 523 | * @param mixed $subnetId |
524 | + * @param boolean $die |
|
526 | 525 | * @return void |
527 | 526 | */ |
528 | 527 | public function prepare_addresses_to_discover_subnetId ($subnetId, $die) { |
@@ -431,8 +431,7 @@ discard block |
||
431 | 431 | # set datetime |
432 | 432 | $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; |
433 | 433 | # execute |
434 | - try { $this->Database->updateObject("ipaddresses", array("id"=>$id, "lastSeen"=>$datetime), "id"); } |
|
435 | - catch (Exception $e) { |
|
434 | + try { $this->Database->updateObject("ipaddresses", array("id"=>$id, "lastSeen"=>$datetime), "id"); } catch (Exception $e) { |
|
436 | 435 | !$this->debugging ? : $this->Result->show("danger", $e->getMessage(), false); |
437 | 436 | # log |
438 | 437 | !$this->debugging ? : $this->Log->write ("status_update", _('Failed to update address status'), 0 ); |
@@ -452,8 +451,7 @@ discard block |
||
452 | 451 | if ($date === false) { $date = date("Y-m-d H:i:s"); } |
453 | 452 | else { $date = $date; } |
454 | 453 | # execute |
455 | - try { $this->Database->updateObject("scanAgents", array("id"=>$id, "last_access"=>date("Y-m-d H:i:s")), "id"); } |
|
456 | - catch (Exception $e) { |
|
454 | + try { $this->Database->updateObject("scanAgents", array("id"=>$id, "last_access"=>date("Y-m-d H:i:s")), "id"); } catch (Exception $e) { |
|
457 | 455 | } |
458 | 456 | } |
459 | 457 | |
@@ -477,7 +475,7 @@ discard block |
||
477 | 475 | //failed |
478 | 476 | if (!$conn) {} |
479 | 477 | //success |
480 | - else { |
|
478 | + else { |
|
481 | 479 | $retval = 0; //set return as port if alive |
482 | 480 | fclose($conn); |
483 | 481 | break; //end foreach if success |
@@ -531,14 +529,16 @@ discard block |
||
531 | 529 | |
532 | 530 | //subnet ID is provided, fetch subnet |
533 | 531 | $subnet = $Subnets->fetch_subnet(null, $subnetId); |
534 | - if($subnet===false) { |
|
532 | + if($subnet===false) { |
|
535 | 533 | if ($die) { die(json_encode(array("status"=>1, "error"=>"Invalid subnet ID provided"))); } |
536 | 534 | else { return array(); } |
537 | 535 | } |
538 | 536 | |
539 | 537 | // we should support only up to 4094 hosts! |
540 | - if($Subnets->get_max_hosts ($subnet->mask, "IPv4")>4094 && php_sapi_name()!="cli") |
|
541 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); } |
|
538 | + if($Subnets->get_max_hosts ($subnet->mask, "IPv4")>4094 && php_sapi_name()!="cli") { |
|
539 | + if ($die) { die(json_encode(array("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); |
|
540 | + } |
|
541 | + } |
|
542 | 542 | else { return array(); } |
543 | 543 | |
544 | 544 | # set array of addresses to scan, exclude existing! |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $ip = $this->remove_existing_subnet_addresses ($ip, $subnetId); |
549 | 549 | |
550 | 550 | //none to scan? |
551 | - if(sizeof($ip)==0) { |
|
551 | + if(sizeof($ip)==0) { |
|
552 | 552 | if ($die) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
553 | 553 | else { return array(); } |
554 | 554 | } |
@@ -6,276 +6,276 @@ discard block |
||
6 | 6 | |
7 | 7 | class Scan extends Common_functions { |
8 | 8 | |
9 | - /** |
|
10 | - * (array of objects) to store addresses, address ID is array index |
|
11 | - * |
|
12 | - * @var mixed |
|
13 | - * @access public |
|
14 | - */ |
|
15 | - public $addresses; |
|
16 | - |
|
17 | - /** |
|
18 | - * php executable file |
|
19 | - * |
|
20 | - * (default value: null) |
|
21 | - * |
|
22 | - * @var mixed |
|
23 | - * @access public |
|
24 | - */ |
|
25 | - public $php_exec = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * debugging flag |
|
29 | - * |
|
30 | - * (default value: false) |
|
31 | - * |
|
32 | - * @var bool |
|
33 | - * @access public |
|
34 | - */ |
|
35 | - public $debugging = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * default icmp type |
|
39 | - * |
|
40 | - * (default value: "ping") |
|
41 | - * |
|
42 | - * @var string |
|
43 | - * @access public |
|
44 | - */ |
|
45 | - public $icmp_type = "ping"; |
|
46 | - |
|
47 | - /** |
|
48 | - * icmp timeout |
|
49 | - * |
|
50 | - * (default value: 1) |
|
51 | - * |
|
52 | - * @var int |
|
53 | - * @access protected |
|
54 | - */ |
|
55 | - protected $icmp_timeout = 1; |
|
56 | - |
|
57 | - /** |
|
58 | - * icmp retries |
|
59 | - * |
|
60 | - * (default value: 1) |
|
61 | - * |
|
62 | - * @var int |
|
63 | - * @access protected |
|
64 | - */ |
|
65 | - protected $icmp_count = 1; |
|
66 | - |
|
67 | - /** |
|
68 | - * exit or return icmp status |
|
69 | - * |
|
70 | - * (default value: false) |
|
71 | - * |
|
72 | - * @var bool |
|
73 | - * @access protected |
|
74 | - */ |
|
75 | - protected $icmp_exit = false; |
|
76 | - |
|
77 | - /** |
|
78 | - * Result |
|
79 | - * |
|
80 | - * @var mixed |
|
81 | - * @access public |
|
82 | - */ |
|
83 | - public $Result; |
|
84 | - |
|
85 | - /** |
|
86 | - * Database |
|
87 | - * |
|
88 | - * @var mixed |
|
89 | - * @access protected |
|
90 | - */ |
|
91 | - protected $Database; |
|
92 | - |
|
93 | - /** |
|
94 | - * Subnets |
|
95 | - * |
|
96 | - * @var mixed |
|
97 | - * @access protected |
|
98 | - */ |
|
99 | - protected $Subnets; |
|
100 | - |
|
101 | - /** |
|
102 | - * Addresses |
|
103 | - * |
|
104 | - * @var mixed |
|
105 | - * @access protected |
|
106 | - */ |
|
107 | - protected $Addresses; |
|
108 | - |
|
109 | - /** |
|
110 | - * Log |
|
111 | - * |
|
112 | - * @var mixed |
|
113 | - * @access public |
|
114 | - */ |
|
115 | - public $Log; |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * __construct function |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param Database_PDO $database |
|
126 | - * @param mixed $settings (default: null) |
|
127 | - */ |
|
128 | - public function __construct (Database_PDO $database, $settings = null) { |
|
129 | - # Save database object |
|
130 | - $this->Database = $database; |
|
131 | - # initialize Result |
|
132 | - $this->Result = new Result (); |
|
133 | - # debugging |
|
134 | - $this->set_debugging(); |
|
135 | - # fetch settings |
|
136 | - is_null($this->settings) ? $this->get_settings() : (object) $this->settings; |
|
137 | - # set type |
|
138 | - $this->reset_scan_method ($this->settings->scanPingType); |
|
139 | - # set php exec |
|
140 | - $this->set_php_exec (); |
|
141 | - # Log object |
|
142 | - $this->Log = new Logging ($this->Database, $this->settings); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns all possible ping types / apps |
|
147 | - * |
|
148 | - * @access public |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function ping_fetch_types () { |
|
152 | - return array("ping", "pear", "fping"); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * This functin resets the scan method, for cron scripts |
|
157 | - * |
|
158 | - * @access public |
|
159 | - * @param mixed $method |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function reset_scan_method ($method) { |
|
163 | - // fetch possible methods |
|
164 | - $possible = $this->ping_fetch_types (); |
|
165 | - //check |
|
166 | - if(!in_array($method, $possible)) { |
|
167 | - //die or print? |
|
168 | - if($this->icmp_exit) { die(json_encode(array("status"=>1, "error"=>"Invalid scan method"))); } |
|
169 | - else { $this->Result->show("danger", "Invalid scan method", true); } |
|
170 | - } |
|
171 | - //ok |
|
172 | - else { |
|
173 | - $this->icmp_type = $method; |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Resets debugging |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @param bool $debug (default: false) |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function reset_debugging ($debug = false) { |
|
185 | - $this->debugging = $debug; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Sets php exec |
|
190 | - * |
|
191 | - * @access private |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - private function set_php_exec () { |
|
195 | - $this->php_exec = PHP_BINDIR."/php"; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Set weather the code should exit or return |
|
200 | - * |
|
201 | - * Default is return |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param bool $exit (default: false) |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public function ping_set_exit ($exit = false) { |
|
208 | - $this->icmp_exit = $exit; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @ping @icmp methods |
|
221 | - * -------------------------------- |
|
222 | - */ |
|
223 | - |
|
224 | - /** |
|
225 | - * Function that pings address and checks if it responds |
|
226 | - * |
|
227 | - * any script can be used by extension, important are results |
|
228 | - * |
|
229 | - * 0 = Alive |
|
230 | - * 1 = Offline |
|
231 | - * 2 = Offline |
|
232 | - * |
|
233 | - * all other codes can be explained in ping_exit_explain method |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param mixed $address |
|
237 | - * @param int $count (default: 1) |
|
238 | - * @param int $timeout (default: 1) |
|
239 | - * @param bool $exit (default: false) |
|
240 | - * @return void |
|
241 | - */ |
|
242 | - public function ping_address ($address, $count=1, $timeout = 1) { |
|
243 | - #set parameters |
|
244 | - $this->icmp_timeout = $timeout; |
|
245 | - $this->icmp_count = $count; |
|
246 | - |
|
247 | - # escape address |
|
248 | - $address = escapeshellarg($address); |
|
249 | - |
|
250 | - # make sure it is in right format |
|
251 | - $address = $this->transform_address ($address, "dotted"); |
|
252 | - # set method name variable |
|
253 | - $ping_method = "ping_address_method_".$this->icmp_type; |
|
254 | - # ping with selected method |
|
255 | - return $this->$ping_method ($address); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Ping selected address and return response |
|
260 | - * |
|
261 | - * timeout value: for miliseconds multiplyy by 1000 |
|
262 | - * |
|
263 | - * @access protected |
|
264 | - * @param ip $address |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function ping_address_method_ping ($address) { |
|
268 | - # verify ping path |
|
269 | - $this->ping_verify_path ($this->settings->scanPingPath); |
|
270 | - |
|
271 | - # if ipv6 append 6 |
|
272 | - if ($this->identify_address ($address)=="IPv6") { $this->settings->scanPingPath = $this->settings->scanPingPath."6"; } |
|
273 | - |
|
274 | - # set ping command based on OS type |
|
275 | - if (PHP_OS == "FreeBSD" || PHP_OS == "NetBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
276 | - elseif(PHP_OS == "Linux" || PHP_OS == "OpenBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -w $this->icmp_timeout $address 1>/dev/null 2>&1"; } |
|
277 | - elseif(PHP_OS == "WIN32" || PHP_OS == "Windows" || PHP_OS == "WINNT") { $cmd = $this->settings->scanPingPath." -n $this->icmp_count -I ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
278 | - else { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; } |
|
9 | + /** |
|
10 | + * (array of objects) to store addresses, address ID is array index |
|
11 | + * |
|
12 | + * @var mixed |
|
13 | + * @access public |
|
14 | + */ |
|
15 | + public $addresses; |
|
16 | + |
|
17 | + /** |
|
18 | + * php executable file |
|
19 | + * |
|
20 | + * (default value: null) |
|
21 | + * |
|
22 | + * @var mixed |
|
23 | + * @access public |
|
24 | + */ |
|
25 | + public $php_exec = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * debugging flag |
|
29 | + * |
|
30 | + * (default value: false) |
|
31 | + * |
|
32 | + * @var bool |
|
33 | + * @access public |
|
34 | + */ |
|
35 | + public $debugging = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * default icmp type |
|
39 | + * |
|
40 | + * (default value: "ping") |
|
41 | + * |
|
42 | + * @var string |
|
43 | + * @access public |
|
44 | + */ |
|
45 | + public $icmp_type = "ping"; |
|
46 | + |
|
47 | + /** |
|
48 | + * icmp timeout |
|
49 | + * |
|
50 | + * (default value: 1) |
|
51 | + * |
|
52 | + * @var int |
|
53 | + * @access protected |
|
54 | + */ |
|
55 | + protected $icmp_timeout = 1; |
|
56 | + |
|
57 | + /** |
|
58 | + * icmp retries |
|
59 | + * |
|
60 | + * (default value: 1) |
|
61 | + * |
|
62 | + * @var int |
|
63 | + * @access protected |
|
64 | + */ |
|
65 | + protected $icmp_count = 1; |
|
66 | + |
|
67 | + /** |
|
68 | + * exit or return icmp status |
|
69 | + * |
|
70 | + * (default value: false) |
|
71 | + * |
|
72 | + * @var bool |
|
73 | + * @access protected |
|
74 | + */ |
|
75 | + protected $icmp_exit = false; |
|
76 | + |
|
77 | + /** |
|
78 | + * Result |
|
79 | + * |
|
80 | + * @var mixed |
|
81 | + * @access public |
|
82 | + */ |
|
83 | + public $Result; |
|
84 | + |
|
85 | + /** |
|
86 | + * Database |
|
87 | + * |
|
88 | + * @var mixed |
|
89 | + * @access protected |
|
90 | + */ |
|
91 | + protected $Database; |
|
92 | + |
|
93 | + /** |
|
94 | + * Subnets |
|
95 | + * |
|
96 | + * @var mixed |
|
97 | + * @access protected |
|
98 | + */ |
|
99 | + protected $Subnets; |
|
100 | + |
|
101 | + /** |
|
102 | + * Addresses |
|
103 | + * |
|
104 | + * @var mixed |
|
105 | + * @access protected |
|
106 | + */ |
|
107 | + protected $Addresses; |
|
108 | + |
|
109 | + /** |
|
110 | + * Log |
|
111 | + * |
|
112 | + * @var mixed |
|
113 | + * @access public |
|
114 | + */ |
|
115 | + public $Log; |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * __construct function |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param Database_PDO $database |
|
126 | + * @param mixed $settings (default: null) |
|
127 | + */ |
|
128 | + public function __construct (Database_PDO $database, $settings = null) { |
|
129 | + # Save database object |
|
130 | + $this->Database = $database; |
|
131 | + # initialize Result |
|
132 | + $this->Result = new Result (); |
|
133 | + # debugging |
|
134 | + $this->set_debugging(); |
|
135 | + # fetch settings |
|
136 | + is_null($this->settings) ? $this->get_settings() : (object) $this->settings; |
|
137 | + # set type |
|
138 | + $this->reset_scan_method ($this->settings->scanPingType); |
|
139 | + # set php exec |
|
140 | + $this->set_php_exec (); |
|
141 | + # Log object |
|
142 | + $this->Log = new Logging ($this->Database, $this->settings); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns all possible ping types / apps |
|
147 | + * |
|
148 | + * @access public |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function ping_fetch_types () { |
|
152 | + return array("ping", "pear", "fping"); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * This functin resets the scan method, for cron scripts |
|
157 | + * |
|
158 | + * @access public |
|
159 | + * @param mixed $method |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function reset_scan_method ($method) { |
|
163 | + // fetch possible methods |
|
164 | + $possible = $this->ping_fetch_types (); |
|
165 | + //check |
|
166 | + if(!in_array($method, $possible)) { |
|
167 | + //die or print? |
|
168 | + if($this->icmp_exit) { die(json_encode(array("status"=>1, "error"=>"Invalid scan method"))); } |
|
169 | + else { $this->Result->show("danger", "Invalid scan method", true); } |
|
170 | + } |
|
171 | + //ok |
|
172 | + else { |
|
173 | + $this->icmp_type = $method; |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Resets debugging |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @param bool $debug (default: false) |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function reset_debugging ($debug = false) { |
|
185 | + $this->debugging = $debug; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Sets php exec |
|
190 | + * |
|
191 | + * @access private |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + private function set_php_exec () { |
|
195 | + $this->php_exec = PHP_BINDIR."/php"; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Set weather the code should exit or return |
|
200 | + * |
|
201 | + * Default is return |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param bool $exit (default: false) |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public function ping_set_exit ($exit = false) { |
|
208 | + $this->icmp_exit = $exit; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @ping @icmp methods |
|
221 | + * -------------------------------- |
|
222 | + */ |
|
223 | + |
|
224 | + /** |
|
225 | + * Function that pings address and checks if it responds |
|
226 | + * |
|
227 | + * any script can be used by extension, important are results |
|
228 | + * |
|
229 | + * 0 = Alive |
|
230 | + * 1 = Offline |
|
231 | + * 2 = Offline |
|
232 | + * |
|
233 | + * all other codes can be explained in ping_exit_explain method |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param mixed $address |
|
237 | + * @param int $count (default: 1) |
|
238 | + * @param int $timeout (default: 1) |
|
239 | + * @param bool $exit (default: false) |
|
240 | + * @return void |
|
241 | + */ |
|
242 | + public function ping_address ($address, $count=1, $timeout = 1) { |
|
243 | + #set parameters |
|
244 | + $this->icmp_timeout = $timeout; |
|
245 | + $this->icmp_count = $count; |
|
246 | + |
|
247 | + # escape address |
|
248 | + $address = escapeshellarg($address); |
|
249 | + |
|
250 | + # make sure it is in right format |
|
251 | + $address = $this->transform_address ($address, "dotted"); |
|
252 | + # set method name variable |
|
253 | + $ping_method = "ping_address_method_".$this->icmp_type; |
|
254 | + # ping with selected method |
|
255 | + return $this->$ping_method ($address); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Ping selected address and return response |
|
260 | + * |
|
261 | + * timeout value: for miliseconds multiplyy by 1000 |
|
262 | + * |
|
263 | + * @access protected |
|
264 | + * @param ip $address |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function ping_address_method_ping ($address) { |
|
268 | + # verify ping path |
|
269 | + $this->ping_verify_path ($this->settings->scanPingPath); |
|
270 | + |
|
271 | + # if ipv6 append 6 |
|
272 | + if ($this->identify_address ($address)=="IPv6") { $this->settings->scanPingPath = $this->settings->scanPingPath."6"; } |
|
273 | + |
|
274 | + # set ping command based on OS type |
|
275 | + if (PHP_OS == "FreeBSD" || PHP_OS == "NetBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
276 | + elseif(PHP_OS == "Linux" || PHP_OS == "OpenBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -w $this->icmp_timeout $address 1>/dev/null 2>&1"; } |
|
277 | + elseif(PHP_OS == "WIN32" || PHP_OS == "Windows" || PHP_OS == "WINNT") { $cmd = $this->settings->scanPingPath." -n $this->icmp_count -I ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
278 | + else { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; } |
|
279 | 279 | |
280 | 280 | # for IPv6 remove wait |
281 | 281 | if ($this->identify_address ($address)=="IPv6") { |
@@ -284,471 +284,471 @@ discard block |
||
284 | 284 | $cmd = implode(" ", $cmd); |
285 | 285 | } |
286 | 286 | |
287 | - # execute command, return $retval |
|
288 | - exec($cmd, $output, $retval); |
|
289 | - |
|
290 | - # return result for web or cmd |
|
291 | - if($this->icmp_exit) { exit ($retval); } |
|
292 | - else { return $retval; } |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Ping selected address with PEAR ping package |
|
297 | - * |
|
298 | - * @access protected |
|
299 | - * @param ip $address |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - protected function ping_address_method_pear ($address) { |
|
303 | - # we need pear ping package |
|
304 | - require_once(dirname(__FILE__) . '/../../functions/PEAR/Net/Ping.php'); |
|
305 | - $ping = Net_Ping::factory(); |
|
306 | - |
|
307 | - # ipv6 not supported |
|
308 | - if ($this->identify_address ($address)=="IPv6") { |
|
309 | - //return result for web or cmd |
|
310 | - if($this->icmp_exit) { exit (255); } |
|
311 | - else { return 255; } |
|
312 | - } |
|
313 | - |
|
314 | - # check for errors |
|
315 | - if($ping->pear->isError($ping)) { |
|
316 | - if($this->icmp_exit) { exit ($ping->getMessage()); } |
|
317 | - else { return $ping->getMessage(); } |
|
318 | - } |
|
319 | - else { |
|
320 | - //set count and timeout |
|
321 | - $ping->setArgs(array('count' => $this->icmp_timeout, 'timeout' => $this->icmp_timeout)); |
|
322 | - //execute |
|
323 | - $ping_response = $ping->ping($address); |
|
324 | - //check response for error |
|
325 | - if($ping->pear->isError($ping_response)) { |
|
326 | - $result['code'] = 2; |
|
327 | - } |
|
328 | - else { |
|
329 | - //all good |
|
330 | - if($ping_response->_transmitted == $ping_response->_received) { |
|
331 | - $result['code'] = 0; |
|
332 | - $this->rtt = "RTT: ". strstr($ping_response->_round_trip['avg'], ".", true); |
|
333 | - } |
|
334 | - //ping loss |
|
335 | - elseif($ping_response->_received == 0) { |
|
336 | - $result['code'] = 1; |
|
337 | - } |
|
338 | - //failed |
|
339 | - else { |
|
340 | - $result['code'] = 3; |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - //return result for web or cmd |
|
346 | - if($this->icmp_exit) { exit ($result['code']); } |
|
347 | - else { return $result['code']; } |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Ping selected address with fping function |
|
352 | - * |
|
353 | - * Exit status is: |
|
354 | - * 0 if all the hosts are reachable, |
|
355 | - * 1 if some hosts were unreachable, |
|
356 | - * 2 if any IP addresses were not found, |
|
357 | - * 3 for invalid command line arguments, |
|
358 | - * 4 for a system call failure. |
|
359 | - * |
|
360 | - * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
|
361 | - * |
|
362 | - * @access public |
|
363 | - * @param mixed $subnet //CIDR |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function ping_address_method_fping ($address) { |
|
367 | - # verify ping path |
|
368 | - $this->ping_verify_path ($this->settings->scanFPingPath); |
|
369 | - |
|
370 | - # if ipv6 append 6 |
|
371 | - if ($this->identify_address ($address)=="IPv6") { $this->settings->scanFPingPath = $this->settings->scanFPingPath."6"; } |
|
372 | - |
|
373 | - # set command |
|
374 | - $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." $address"; |
|
375 | - # execute command, return $retval |
|
376 | - exec($cmd, $output, $retval); |
|
377 | - |
|
378 | - # save result |
|
379 | - if($retval==0) { |
|
380 | - $this->save_fping_rtt ($output[0]); |
|
381 | - } |
|
382 | - |
|
383 | - # return result for web or cmd |
|
384 | - if($this->icmp_exit) { exit ($retval); } |
|
385 | - else { return $retval; } |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Saves RTT for fping |
|
390 | - * |
|
391 | - * @access private |
|
392 | - * @param mixed $line |
|
393 | - * @return void |
|
394 | - */ |
|
395 | - private function save_fping_rtt ($line) { |
|
396 | - // 173.192.112.30 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 160/160/160 |
|
397 | - $tmp = explode(" ",$line); |
|
398 | - |
|
399 | - # save rtt |
|
400 | - @$this->rtt = "RTT: ".str_replace("(", "", $tmp[7]); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Ping selected address with fping function |
|
405 | - * |
|
406 | - * Exit status is: |
|
407 | - * 0 if all the hosts are reachable, |
|
408 | - * 1 if some hosts were unreachable, |
|
409 | - * 2 if any IP addresses were not found, |
|
410 | - * 3 for invalid command line arguments, |
|
411 | - * 4 for a system call failure. |
|
412 | - * |
|
413 | - * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
|
414 | - * |
|
415 | - * @access public |
|
416 | - * @param mixed $subnet //CIDR |
|
417 | - * @return void |
|
418 | - */ |
|
419 | - public function ping_address_method_fping_subnet ($subnet_cidr, $return_result = false) { |
|
420 | - # verify ping path |
|
421 | - $this->ping_verify_path ($this->settings->scanFPingPath); |
|
422 | - # set command |
|
423 | - $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." -Ag $subnet_cidr"; |
|
424 | - # execute command, return $retval |
|
425 | - exec($cmd, $output, $retval); |
|
426 | - |
|
427 | - # save result |
|
428 | - if(sizeof($output)>0) { |
|
429 | - foreach($output as $line) { |
|
430 | - $tmp = explode(" ",$line); |
|
431 | - $out[] = $tmp[0]; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - # save to var |
|
436 | - $this->fping_result = $out; |
|
437 | - |
|
438 | - # return result? |
|
439 | - if($return_result) { return $out; } |
|
440 | - |
|
441 | - # return result for web or cmd |
|
442 | - if($this->icmp_exit) { exit ($retval); } |
|
443 | - else { return $retval; } |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Verifies that ping file exists |
|
448 | - * |
|
449 | - * @access private |
|
450 | - * @param mixed $path |
|
451 | - * @return void |
|
452 | - */ |
|
453 | - private function ping_verify_path ($path) { |
|
454 | - if(!file_exists($path)) { |
|
455 | - if($this->icmp_exit) { exit ($this->ping_exit_explain(1000)); } |
|
456 | - else { return $this->Result->show("danger", _($this->ping_exit_explain(1000)), true); } |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Explains invalid error codes |
|
462 | - * |
|
463 | - * @access public |
|
464 | - * @param mixed $code |
|
465 | - * @return void |
|
466 | - */ |
|
467 | - public function ping_exit_explain ($code) { |
|
468 | - # fetch explain codes |
|
469 | - $explain_codes = $this->ping_set_exit_code_explains (); |
|
470 | - |
|
471 | - # return code |
|
472 | - return isset($explain_codes[$code]) ? $explain_codes[$code] : false; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * This function sets ping exit code and message mappings |
|
477 | - * |
|
478 | - * http://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+4.3-RELEASE&arch=default&format=ascii |
|
479 | - * |
|
480 | - * extend if needed for future scripts |
|
481 | - * |
|
482 | - * @access public |
|
483 | - * @return void |
|
484 | - */ |
|
485 | - public function ping_set_exit_code_explains () { |
|
486 | - $explain_codes[0] = "SUCCESS"; |
|
487 | - $explain_codes[1] = "OFFLINE"; |
|
488 | - $explain_codes[2] = "ERROR"; |
|
489 | - $explain_codes[3] = "UNKNOWN ERROR"; |
|
490 | - $explain_codes[64] = "EX_USAGE"; |
|
491 | - $explain_codes[65] = "EX_DATAERR"; |
|
492 | - $explain_codes[68] = "EX_NOHOST"; |
|
493 | - $explain_codes[70] = "EX_SOFTWARE"; |
|
494 | - $explain_codes[71] = "EX_OSERR"; |
|
495 | - $explain_codes[72] = "EX_OSFILE"; |
|
496 | - $explain_codes[73] = "EX_CANTCREAT"; |
|
497 | - $explain_codes[74] = "EX_IOERR"; |
|
498 | - $explain_codes[75] = "EX_TEMPFAIL"; |
|
499 | - $explain_codes[77] = "EX_NOPERM"; |
|
500 | - $explain_codes[255] = "EX_NOT_SUPPORTED"; |
|
501 | - $explain_codes[1000] = "Invalid ping path"; |
|
502 | - # return codes |
|
503 | - return $explain_codes; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Update lastseen field for specific IP address |
|
508 | - * |
|
509 | - * @access public |
|
510 | - * @param int $id |
|
511 | - * @param datetime $datetime |
|
512 | - * @return void |
|
513 | - */ |
|
514 | - public function ping_update_lastseen ($id, $datetime = null) { |
|
515 | - # set datetime |
|
516 | - $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; |
|
517 | - # execute |
|
518 | - try { $this->Database->updateObject("ipaddresses", array("id"=>$id, "lastSeen"=>$datetime), "id"); } |
|
519 | - catch (Exception $e) { |
|
520 | - !$this->debugging ? : $this->Result->show("danger", $e->getMessage(), false); |
|
521 | - # log |
|
522 | - !$this->debugging ? : $this->Log->write ("status_update", _('Failed to update address status'), 0 ); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Update last check time for agent |
|
528 | - * |
|
529 | - * @access public |
|
530 | - * @param int $id |
|
531 | - * @param datetime $date |
|
532 | - * @return void |
|
533 | - */ |
|
534 | - public function ping_update_scanagent_checktime ($id, $date = false) { |
|
535 | - # set time |
|
536 | - if ($date === false) { $date = date("Y-m-d H:i:s"); } |
|
537 | - else { $date = $date; } |
|
538 | - # execute |
|
539 | - try { $this->Database->updateObject("scanAgents", array("id"=>$id, "last_access"=>date("Y-m-d H:i:s")), "id"); } |
|
540 | - catch (Exception $e) { |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Opens socket connection on specified TCP ports, if at least one is available host is alive |
|
546 | - * |
|
547 | - * @access public |
|
548 | - * @param mixed $address |
|
549 | - * @param mixed $port |
|
550 | - * @return void |
|
551 | - */ |
|
552 | - public function telnet_address ($address, $port) { |
|
553 | - # set all ports |
|
554 | - $ports = explode(",", str_replace(";",",",$port)); |
|
555 | - # default response is dead |
|
556 | - $retval = 1; |
|
557 | - //try each port untill one is alive |
|
558 | - foreach($ports as $p) { |
|
559 | - // open socket |
|
560 | - $conn = @fsockopen($address, $p, $errno, $errstr, $this->icmp_timeout); |
|
561 | - //failed |
|
562 | - if (!$conn) {} |
|
563 | - //success |
|
564 | - else { |
|
565 | - $retval = 0; //set return as port if alive |
|
566 | - fclose($conn); |
|
567 | - break; //end foreach if success |
|
568 | - } |
|
569 | - } |
|
570 | - # exit with result |
|
571 | - exit($retval); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @prepare addresses methods |
|
584 | - * -------------------------------- |
|
585 | - */ |
|
586 | - |
|
587 | - /** |
|
588 | - * Returns all addresses to be scanned or updated |
|
589 | - * |
|
590 | - * @access public |
|
591 | - * @param mixed $type //discovery, update |
|
592 | - * @param mixed $subnet |
|
593 | - * @param bool $type |
|
594 | - * @return void |
|
595 | - */ |
|
596 | - public function prepare_addresses_to_scan ($type, $subnet, $die = true) { |
|
597 | - # discover new addresses |
|
598 | - if($type=="discovery") { return is_numeric($subnet) ? $this->prepare_addresses_to_discover_subnetId ($subnet, $die) : $this->prepare_addresses_to_discover_subnet ($subnet, $die); } |
|
599 | - # update addresses statuses |
|
600 | - elseif($type=="update") { return $this->prepare_addresses_to_update ($subnet); } |
|
601 | - # fail |
|
602 | - else { die(json_encode(array("status"=>1, "error"=>"Invalid scan type provided"))); } |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Returns array of all addresses to be scanned inside subnet defined with subnetId |
|
607 | - * |
|
608 | - * @access public |
|
609 | - * @param mixed $subnetId |
|
610 | - * @return void |
|
611 | - */ |
|
612 | - public function prepare_addresses_to_discover_subnetId ($subnetId, $die) { |
|
613 | - # initialize classes |
|
614 | - $Subnets = new Subnets ($this->Database); |
|
615 | - |
|
616 | - //subnet ID is provided, fetch subnet |
|
617 | - $subnet = $Subnets->fetch_subnet(null, $subnetId); |
|
618 | - if($subnet===false) { |
|
619 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Invalid subnet ID provided"))); } |
|
620 | - else { return array(); } |
|
621 | - } |
|
622 | - |
|
623 | - // we should support only up to 4094 hosts! |
|
624 | - if($Subnets->get_max_hosts ($subnet->mask, "IPv4")>4094 && php_sapi_name()!="cli") |
|
625 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); } |
|
626 | - else { return array(); } |
|
627 | - |
|
628 | - # set array of addresses to scan, exclude existing! |
|
629 | - $ip = $this->get_all_possible_subnet_addresses ($subnet->subnet, $subnet->mask); |
|
630 | - |
|
631 | - # remove existing |
|
632 | - $ip = $this->remove_existing_subnet_addresses ($ip, $subnetId); |
|
633 | - |
|
634 | - //none to scan? |
|
635 | - if(sizeof($ip)==0) { |
|
636 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
637 | - else { return array(); } |
|
638 | - } |
|
639 | - |
|
640 | - //return |
|
641 | - return $ip; |
|
642 | - } |
|
643 | - |
|
644 | - /** |
|
645 | - * Fetches all possible subnet addresses |
|
646 | - * |
|
647 | - * @access private |
|
648 | - * @param $subnet //subnet in decimal format |
|
649 | - * @param int $mask //subnet mask |
|
650 | - * @return void //array of ip addresses in decimal format |
|
651 | - */ |
|
652 | - private function get_all_possible_subnet_addresses ($subnet, $mask) { |
|
653 | - # initialize classes |
|
654 | - $Subnets = new Subnets ($this->Database); |
|
655 | - # make sure we have proper subnet format |
|
656 | - $subnet = $Subnets->transform_address($subnet, "decimal"); |
|
657 | - //fetch start and stop addresses |
|
658 | - $boundaries = (object) $Subnets->get_network_boundaries ($subnet, $mask); |
|
659 | - //create array |
|
660 | - if($mask==32) { |
|
661 | - $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
662 | - } |
|
663 | - elseif($mask==31) { |
|
664 | - $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
665 | - $ip[] = $Subnets->transform_to_decimal($boundaries->broadcast); |
|
666 | - } |
|
667 | - else { |
|
668 | - //set loop limits |
|
669 | - $start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network),1)); |
|
670 | - $stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast)); |
|
671 | - //loop |
|
672 | - for($m=$start; $m<$stop; $m++) { |
|
673 | - $ip[] = $m; |
|
674 | - } |
|
675 | - } |
|
676 | - //return |
|
677 | - return $ip; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Removes existing addresses from |
|
682 | - * |
|
683 | - * @access private |
|
684 | - * @param mixed $ip //array of ip addresses in decimal format |
|
685 | - * @param mixed $subnetId //id of subnet |
|
686 | - * @return void |
|
687 | - */ |
|
688 | - private function remove_existing_subnet_addresses ($ip, $subnetId) { |
|
689 | - # first fetch all addresses |
|
690 | - $Addresses = new Addresses ($this->Database); |
|
691 | - // get all existing IP addresses in subnet |
|
692 | - $addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
693 | - // if some exist remove them |
|
694 | - if(sizeof($addresses)>0 && sizeof(@$ip)>0) { |
|
695 | - foreach($addresses as $a) { |
|
696 | - $key = array_search($a->ip_addr, $ip); |
|
697 | - if($key !== false) { |
|
698 | - unset($ip[$key]); |
|
699 | - } |
|
700 | - } |
|
701 | - //reindex array for pinging |
|
702 | - $ip = array_values(@$ip); |
|
703 | - } |
|
704 | - //return |
|
705 | - return is_array(@$ip) ? $ip : array(); |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Returns array of all addresses in subnet |
|
710 | - * |
|
711 | - * @access public |
|
712 | - * @param mixed $subnet |
|
713 | - * @return void |
|
714 | - */ |
|
715 | - public function prepare_addresses_to_discover_subnet ($subnet) { |
|
716 | - //set subnet / mask |
|
717 | - $subnet_parsed = explode("/", $subnet); |
|
718 | - # result |
|
719 | - $ip = $this->get_all_possible_subnet_addresses ($subnet_parsed[0], $subnet_parsed[1]); |
|
720 | - //none to scan? |
|
721 | - if(sizeof($ip)==0) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
722 | - //result |
|
723 | - return $ip; |
|
724 | - } |
|
725 | - |
|
726 | - /** |
|
727 | - * Returns array of all addresses to be scanned |
|
728 | - * |
|
729 | - * @access public |
|
730 | - * @param mixed $subnetId |
|
731 | - * @return void |
|
732 | - */ |
|
733 | - public function prepare_addresses_to_update ($subnetId) { |
|
734 | - # first fetch all addresses |
|
735 | - $Addresses = new Addresses ($this->Database); |
|
736 | - // get all existing IP addresses in subnet |
|
737 | - $subnet_addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
738 | - //create array |
|
739 | - if(sizeof($subnet_addresses)>0) { |
|
740 | - foreach($subnet_addresses as $a) { |
|
741 | - $scan_addresses[$a->id] = $a->ip_addr; |
|
742 | - } |
|
743 | - //reindex |
|
744 | - $scan_addresses = array_values(@$scan_addresses); |
|
745 | - //return |
|
746 | - return $scan_addresses; |
|
747 | - } |
|
748 | - else { |
|
749 | - return array(); |
|
750 | - } |
|
751 | - } |
|
287 | + # execute command, return $retval |
|
288 | + exec($cmd, $output, $retval); |
|
289 | + |
|
290 | + # return result for web or cmd |
|
291 | + if($this->icmp_exit) { exit ($retval); } |
|
292 | + else { return $retval; } |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Ping selected address with PEAR ping package |
|
297 | + * |
|
298 | + * @access protected |
|
299 | + * @param ip $address |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + protected function ping_address_method_pear ($address) { |
|
303 | + # we need pear ping package |
|
304 | + require_once(dirname(__FILE__) . '/../../functions/PEAR/Net/Ping.php'); |
|
305 | + $ping = Net_Ping::factory(); |
|
306 | + |
|
307 | + # ipv6 not supported |
|
308 | + if ($this->identify_address ($address)=="IPv6") { |
|
309 | + //return result for web or cmd |
|
310 | + if($this->icmp_exit) { exit (255); } |
|
311 | + else { return 255; } |
|
312 | + } |
|
313 | + |
|
314 | + # check for errors |
|
315 | + if($ping->pear->isError($ping)) { |
|
316 | + if($this->icmp_exit) { exit ($ping->getMessage()); } |
|
317 | + else { return $ping->getMessage(); } |
|
318 | + } |
|
319 | + else { |
|
320 | + //set count and timeout |
|
321 | + $ping->setArgs(array('count' => $this->icmp_timeout, 'timeout' => $this->icmp_timeout)); |
|
322 | + //execute |
|
323 | + $ping_response = $ping->ping($address); |
|
324 | + //check response for error |
|
325 | + if($ping->pear->isError($ping_response)) { |
|
326 | + $result['code'] = 2; |
|
327 | + } |
|
328 | + else { |
|
329 | + //all good |
|
330 | + if($ping_response->_transmitted == $ping_response->_received) { |
|
331 | + $result['code'] = 0; |
|
332 | + $this->rtt = "RTT: ". strstr($ping_response->_round_trip['avg'], ".", true); |
|
333 | + } |
|
334 | + //ping loss |
|
335 | + elseif($ping_response->_received == 0) { |
|
336 | + $result['code'] = 1; |
|
337 | + } |
|
338 | + //failed |
|
339 | + else { |
|
340 | + $result['code'] = 3; |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + //return result for web or cmd |
|
346 | + if($this->icmp_exit) { exit ($result['code']); } |
|
347 | + else { return $result['code']; } |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Ping selected address with fping function |
|
352 | + * |
|
353 | + * Exit status is: |
|
354 | + * 0 if all the hosts are reachable, |
|
355 | + * 1 if some hosts were unreachable, |
|
356 | + * 2 if any IP addresses were not found, |
|
357 | + * 3 for invalid command line arguments, |
|
358 | + * 4 for a system call failure. |
|
359 | + * |
|
360 | + * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
|
361 | + * |
|
362 | + * @access public |
|
363 | + * @param mixed $subnet //CIDR |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function ping_address_method_fping ($address) { |
|
367 | + # verify ping path |
|
368 | + $this->ping_verify_path ($this->settings->scanFPingPath); |
|
369 | + |
|
370 | + # if ipv6 append 6 |
|
371 | + if ($this->identify_address ($address)=="IPv6") { $this->settings->scanFPingPath = $this->settings->scanFPingPath."6"; } |
|
372 | + |
|
373 | + # set command |
|
374 | + $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." $address"; |
|
375 | + # execute command, return $retval |
|
376 | + exec($cmd, $output, $retval); |
|
377 | + |
|
378 | + # save result |
|
379 | + if($retval==0) { |
|
380 | + $this->save_fping_rtt ($output[0]); |
|
381 | + } |
|
382 | + |
|
383 | + # return result for web or cmd |
|
384 | + if($this->icmp_exit) { exit ($retval); } |
|
385 | + else { return $retval; } |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Saves RTT for fping |
|
390 | + * |
|
391 | + * @access private |
|
392 | + * @param mixed $line |
|
393 | + * @return void |
|
394 | + */ |
|
395 | + private function save_fping_rtt ($line) { |
|
396 | + // 173.192.112.30 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 160/160/160 |
|
397 | + $tmp = explode(" ",$line); |
|
398 | + |
|
399 | + # save rtt |
|
400 | + @$this->rtt = "RTT: ".str_replace("(", "", $tmp[7]); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Ping selected address with fping function |
|
405 | + * |
|
406 | + * Exit status is: |
|
407 | + * 0 if all the hosts are reachable, |
|
408 | + * 1 if some hosts were unreachable, |
|
409 | + * 2 if any IP addresses were not found, |
|
410 | + * 3 for invalid command line arguments, |
|
411 | + * 4 for a system call failure. |
|
412 | + * |
|
413 | + * fping cannot be run from web, it needs root privileges to be able to open raw socket :/ |
|
414 | + * |
|
415 | + * @access public |
|
416 | + * @param mixed $subnet //CIDR |
|
417 | + * @return void |
|
418 | + */ |
|
419 | + public function ping_address_method_fping_subnet ($subnet_cidr, $return_result = false) { |
|
420 | + # verify ping path |
|
421 | + $this->ping_verify_path ($this->settings->scanFPingPath); |
|
422 | + # set command |
|
423 | + $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." -Ag $subnet_cidr"; |
|
424 | + # execute command, return $retval |
|
425 | + exec($cmd, $output, $retval); |
|
426 | + |
|
427 | + # save result |
|
428 | + if(sizeof($output)>0) { |
|
429 | + foreach($output as $line) { |
|
430 | + $tmp = explode(" ",$line); |
|
431 | + $out[] = $tmp[0]; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + # save to var |
|
436 | + $this->fping_result = $out; |
|
437 | + |
|
438 | + # return result? |
|
439 | + if($return_result) { return $out; } |
|
440 | + |
|
441 | + # return result for web or cmd |
|
442 | + if($this->icmp_exit) { exit ($retval); } |
|
443 | + else { return $retval; } |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Verifies that ping file exists |
|
448 | + * |
|
449 | + * @access private |
|
450 | + * @param mixed $path |
|
451 | + * @return void |
|
452 | + */ |
|
453 | + private function ping_verify_path ($path) { |
|
454 | + if(!file_exists($path)) { |
|
455 | + if($this->icmp_exit) { exit ($this->ping_exit_explain(1000)); } |
|
456 | + else { return $this->Result->show("danger", _($this->ping_exit_explain(1000)), true); } |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Explains invalid error codes |
|
462 | + * |
|
463 | + * @access public |
|
464 | + * @param mixed $code |
|
465 | + * @return void |
|
466 | + */ |
|
467 | + public function ping_exit_explain ($code) { |
|
468 | + # fetch explain codes |
|
469 | + $explain_codes = $this->ping_set_exit_code_explains (); |
|
470 | + |
|
471 | + # return code |
|
472 | + return isset($explain_codes[$code]) ? $explain_codes[$code] : false; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * This function sets ping exit code and message mappings |
|
477 | + * |
|
478 | + * http://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+4.3-RELEASE&arch=default&format=ascii |
|
479 | + * |
|
480 | + * extend if needed for future scripts |
|
481 | + * |
|
482 | + * @access public |
|
483 | + * @return void |
|
484 | + */ |
|
485 | + public function ping_set_exit_code_explains () { |
|
486 | + $explain_codes[0] = "SUCCESS"; |
|
487 | + $explain_codes[1] = "OFFLINE"; |
|
488 | + $explain_codes[2] = "ERROR"; |
|
489 | + $explain_codes[3] = "UNKNOWN ERROR"; |
|
490 | + $explain_codes[64] = "EX_USAGE"; |
|
491 | + $explain_codes[65] = "EX_DATAERR"; |
|
492 | + $explain_codes[68] = "EX_NOHOST"; |
|
493 | + $explain_codes[70] = "EX_SOFTWARE"; |
|
494 | + $explain_codes[71] = "EX_OSERR"; |
|
495 | + $explain_codes[72] = "EX_OSFILE"; |
|
496 | + $explain_codes[73] = "EX_CANTCREAT"; |
|
497 | + $explain_codes[74] = "EX_IOERR"; |
|
498 | + $explain_codes[75] = "EX_TEMPFAIL"; |
|
499 | + $explain_codes[77] = "EX_NOPERM"; |
|
500 | + $explain_codes[255] = "EX_NOT_SUPPORTED"; |
|
501 | + $explain_codes[1000] = "Invalid ping path"; |
|
502 | + # return codes |
|
503 | + return $explain_codes; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Update lastseen field for specific IP address |
|
508 | + * |
|
509 | + * @access public |
|
510 | + * @param int $id |
|
511 | + * @param datetime $datetime |
|
512 | + * @return void |
|
513 | + */ |
|
514 | + public function ping_update_lastseen ($id, $datetime = null) { |
|
515 | + # set datetime |
|
516 | + $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; |
|
517 | + # execute |
|
518 | + try { $this->Database->updateObject("ipaddresses", array("id"=>$id, "lastSeen"=>$datetime), "id"); } |
|
519 | + catch (Exception $e) { |
|
520 | + !$this->debugging ? : $this->Result->show("danger", $e->getMessage(), false); |
|
521 | + # log |
|
522 | + !$this->debugging ? : $this->Log->write ("status_update", _('Failed to update address status'), 0 ); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Update last check time for agent |
|
528 | + * |
|
529 | + * @access public |
|
530 | + * @param int $id |
|
531 | + * @param datetime $date |
|
532 | + * @return void |
|
533 | + */ |
|
534 | + public function ping_update_scanagent_checktime ($id, $date = false) { |
|
535 | + # set time |
|
536 | + if ($date === false) { $date = date("Y-m-d H:i:s"); } |
|
537 | + else { $date = $date; } |
|
538 | + # execute |
|
539 | + try { $this->Database->updateObject("scanAgents", array("id"=>$id, "last_access"=>date("Y-m-d H:i:s")), "id"); } |
|
540 | + catch (Exception $e) { |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Opens socket connection on specified TCP ports, if at least one is available host is alive |
|
546 | + * |
|
547 | + * @access public |
|
548 | + * @param mixed $address |
|
549 | + * @param mixed $port |
|
550 | + * @return void |
|
551 | + */ |
|
552 | + public function telnet_address ($address, $port) { |
|
553 | + # set all ports |
|
554 | + $ports = explode(",", str_replace(";",",",$port)); |
|
555 | + # default response is dead |
|
556 | + $retval = 1; |
|
557 | + //try each port untill one is alive |
|
558 | + foreach($ports as $p) { |
|
559 | + // open socket |
|
560 | + $conn = @fsockopen($address, $p, $errno, $errstr, $this->icmp_timeout); |
|
561 | + //failed |
|
562 | + if (!$conn) {} |
|
563 | + //success |
|
564 | + else { |
|
565 | + $retval = 0; //set return as port if alive |
|
566 | + fclose($conn); |
|
567 | + break; //end foreach if success |
|
568 | + } |
|
569 | + } |
|
570 | + # exit with result |
|
571 | + exit($retval); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @prepare addresses methods |
|
584 | + * -------------------------------- |
|
585 | + */ |
|
586 | + |
|
587 | + /** |
|
588 | + * Returns all addresses to be scanned or updated |
|
589 | + * |
|
590 | + * @access public |
|
591 | + * @param mixed $type //discovery, update |
|
592 | + * @param mixed $subnet |
|
593 | + * @param bool $type |
|
594 | + * @return void |
|
595 | + */ |
|
596 | + public function prepare_addresses_to_scan ($type, $subnet, $die = true) { |
|
597 | + # discover new addresses |
|
598 | + if($type=="discovery") { return is_numeric($subnet) ? $this->prepare_addresses_to_discover_subnetId ($subnet, $die) : $this->prepare_addresses_to_discover_subnet ($subnet, $die); } |
|
599 | + # update addresses statuses |
|
600 | + elseif($type=="update") { return $this->prepare_addresses_to_update ($subnet); } |
|
601 | + # fail |
|
602 | + else { die(json_encode(array("status"=>1, "error"=>"Invalid scan type provided"))); } |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Returns array of all addresses to be scanned inside subnet defined with subnetId |
|
607 | + * |
|
608 | + * @access public |
|
609 | + * @param mixed $subnetId |
|
610 | + * @return void |
|
611 | + */ |
|
612 | + public function prepare_addresses_to_discover_subnetId ($subnetId, $die) { |
|
613 | + # initialize classes |
|
614 | + $Subnets = new Subnets ($this->Database); |
|
615 | + |
|
616 | + //subnet ID is provided, fetch subnet |
|
617 | + $subnet = $Subnets->fetch_subnet(null, $subnetId); |
|
618 | + if($subnet===false) { |
|
619 | + if ($die) { die(json_encode(array("status"=>1, "error"=>"Invalid subnet ID provided"))); } |
|
620 | + else { return array(); } |
|
621 | + } |
|
622 | + |
|
623 | + // we should support only up to 4094 hosts! |
|
624 | + if($Subnets->get_max_hosts ($subnet->mask, "IPv4")>4094 && php_sapi_name()!="cli") |
|
625 | + if ($die) { die(json_encode(array("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); } |
|
626 | + else { return array(); } |
|
627 | + |
|
628 | + # set array of addresses to scan, exclude existing! |
|
629 | + $ip = $this->get_all_possible_subnet_addresses ($subnet->subnet, $subnet->mask); |
|
630 | + |
|
631 | + # remove existing |
|
632 | + $ip = $this->remove_existing_subnet_addresses ($ip, $subnetId); |
|
633 | + |
|
634 | + //none to scan? |
|
635 | + if(sizeof($ip)==0) { |
|
636 | + if ($die) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
637 | + else { return array(); } |
|
638 | + } |
|
639 | + |
|
640 | + //return |
|
641 | + return $ip; |
|
642 | + } |
|
643 | + |
|
644 | + /** |
|
645 | + * Fetches all possible subnet addresses |
|
646 | + * |
|
647 | + * @access private |
|
648 | + * @param $subnet //subnet in decimal format |
|
649 | + * @param int $mask //subnet mask |
|
650 | + * @return void //array of ip addresses in decimal format |
|
651 | + */ |
|
652 | + private function get_all_possible_subnet_addresses ($subnet, $mask) { |
|
653 | + # initialize classes |
|
654 | + $Subnets = new Subnets ($this->Database); |
|
655 | + # make sure we have proper subnet format |
|
656 | + $subnet = $Subnets->transform_address($subnet, "decimal"); |
|
657 | + //fetch start and stop addresses |
|
658 | + $boundaries = (object) $Subnets->get_network_boundaries ($subnet, $mask); |
|
659 | + //create array |
|
660 | + if($mask==32) { |
|
661 | + $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
662 | + } |
|
663 | + elseif($mask==31) { |
|
664 | + $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
665 | + $ip[] = $Subnets->transform_to_decimal($boundaries->broadcast); |
|
666 | + } |
|
667 | + else { |
|
668 | + //set loop limits |
|
669 | + $start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network),1)); |
|
670 | + $stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast)); |
|
671 | + //loop |
|
672 | + for($m=$start; $m<$stop; $m++) { |
|
673 | + $ip[] = $m; |
|
674 | + } |
|
675 | + } |
|
676 | + //return |
|
677 | + return $ip; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Removes existing addresses from |
|
682 | + * |
|
683 | + * @access private |
|
684 | + * @param mixed $ip //array of ip addresses in decimal format |
|
685 | + * @param mixed $subnetId //id of subnet |
|
686 | + * @return void |
|
687 | + */ |
|
688 | + private function remove_existing_subnet_addresses ($ip, $subnetId) { |
|
689 | + # first fetch all addresses |
|
690 | + $Addresses = new Addresses ($this->Database); |
|
691 | + // get all existing IP addresses in subnet |
|
692 | + $addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
693 | + // if some exist remove them |
|
694 | + if(sizeof($addresses)>0 && sizeof(@$ip)>0) { |
|
695 | + foreach($addresses as $a) { |
|
696 | + $key = array_search($a->ip_addr, $ip); |
|
697 | + if($key !== false) { |
|
698 | + unset($ip[$key]); |
|
699 | + } |
|
700 | + } |
|
701 | + //reindex array for pinging |
|
702 | + $ip = array_values(@$ip); |
|
703 | + } |
|
704 | + //return |
|
705 | + return is_array(@$ip) ? $ip : array(); |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Returns array of all addresses in subnet |
|
710 | + * |
|
711 | + * @access public |
|
712 | + * @param mixed $subnet |
|
713 | + * @return void |
|
714 | + */ |
|
715 | + public function prepare_addresses_to_discover_subnet ($subnet) { |
|
716 | + //set subnet / mask |
|
717 | + $subnet_parsed = explode("/", $subnet); |
|
718 | + # result |
|
719 | + $ip = $this->get_all_possible_subnet_addresses ($subnet_parsed[0], $subnet_parsed[1]); |
|
720 | + //none to scan? |
|
721 | + if(sizeof($ip)==0) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
722 | + //result |
|
723 | + return $ip; |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * Returns array of all addresses to be scanned |
|
728 | + * |
|
729 | + * @access public |
|
730 | + * @param mixed $subnetId |
|
731 | + * @return void |
|
732 | + */ |
|
733 | + public function prepare_addresses_to_update ($subnetId) { |
|
734 | + # first fetch all addresses |
|
735 | + $Addresses = new Addresses ($this->Database); |
|
736 | + // get all existing IP addresses in subnet |
|
737 | + $subnet_addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
738 | + //create array |
|
739 | + if(sizeof($subnet_addresses)>0) { |
|
740 | + foreach($subnet_addresses as $a) { |
|
741 | + $scan_addresses[$a->id] = $a->ip_addr; |
|
742 | + } |
|
743 | + //reindex |
|
744 | + $scan_addresses = array_values(@$scan_addresses); |
|
745 | + //return |
|
746 | + return $scan_addresses; |
|
747 | + } |
|
748 | + else { |
|
749 | + return array(); |
|
750 | + } |
|
751 | + } |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | |
@@ -769,25 +769,25 @@ discard block |
||
769 | 769 | function ping_address ($address) { |
770 | 770 | // $Database = new Database_PDO; |
771 | 771 | // $Scan = new Scan ($Database); |
772 | - global $Scan; |
|
773 | - //scan |
|
774 | - return $Scan->ping_address ($address); |
|
772 | + global $Scan; |
|
773 | + //scan |
|
774 | + return $Scan->ping_address ($address); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | /** |
778 | 778 | * Telnet address helper for CLI threading |
779 | 779 | */ |
780 | 780 | function telnet_address ($address, $port) { |
781 | - global $Scan; |
|
782 | - //scan |
|
783 | - return $Scan->telnet_address ($address, $port); |
|
781 | + global $Scan; |
|
782 | + //scan |
|
783 | + return $Scan->telnet_address ($address, $port); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
787 | 787 | * fping subnet helper for fping threading, all methods |
788 | 788 | */ |
789 | 789 | function fping_subnet ($subnet_cidr, $return = true) { |
790 | - global $Scan; |
|
791 | - //scan |
|
792 | - return $Scan->ping_address_method_fping_subnet ($subnet_cidr, $return); |
|
790 | + global $Scan; |
|
791 | + //scan |
|
792 | + return $Scan->ping_address_method_fping_subnet ($subnet_cidr, $return); |
|
793 | 793 | } |
794 | 794 | \ No newline at end of file |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | # initialize Result |
132 | 132 | $this->Result = new Result (); |
133 | 133 | # debugging |
134 | - $this->set_debugging(); |
|
134 | + $this->set_debugging (); |
|
135 | 135 | # fetch settings |
136 | - is_null($this->settings) ? $this->get_settings() : (object) $this->settings; |
|
136 | + is_null ($this->settings) ? $this->get_settings () : (object) $this->settings; |
|
137 | 137 | # set type |
138 | 138 | $this->reset_scan_method ($this->settings->scanPingType); |
139 | 139 | # set php exec |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return array |
150 | 150 | */ |
151 | 151 | public function ping_fetch_types () { |
152 | - return array("ping", "pear", "fping"); |
|
152 | + return array ("ping", "pear", "fping"); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | // fetch possible methods |
164 | 164 | $possible = $this->ping_fetch_types (); |
165 | 165 | //check |
166 | - if(!in_array($method, $possible)) { |
|
166 | + if (!in_array ($method, $possible)) { |
|
167 | 167 | //die or print? |
168 | - if($this->icmp_exit) { die(json_encode(array("status"=>1, "error"=>"Invalid scan method"))); } |
|
169 | - else { $this->Result->show("danger", "Invalid scan method", true); } |
|
168 | + if ($this->icmp_exit) { die(json_encode (array ("status"=>1, "error"=>"Invalid scan method"))); } |
|
169 | + else { $this->Result->show ("danger", "Invalid scan method", true); } |
|
170 | 170 | } |
171 | 171 | //ok |
172 | 172 | else { |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | * @param bool $exit (default: false) |
240 | 240 | * @return void |
241 | 241 | */ |
242 | - public function ping_address ($address, $count=1, $timeout = 1) { |
|
242 | + public function ping_address ($address, $count = 1, $timeout = 1) { |
|
243 | 243 | #set parameters |
244 | 244 | $this->icmp_timeout = $timeout; |
245 | 245 | $this->icmp_count = $count; |
246 | 246 | |
247 | 247 | # escape address |
248 | - $address = escapeshellarg($address); |
|
248 | + $address = escapeshellarg ($address); |
|
249 | 249 | |
250 | 250 | # make sure it is in right format |
251 | 251 | $address = $this->transform_address ($address, "dotted"); |
@@ -269,27 +269,27 @@ discard block |
||
269 | 269 | $this->ping_verify_path ($this->settings->scanPingPath); |
270 | 270 | |
271 | 271 | # if ipv6 append 6 |
272 | - if ($this->identify_address ($address)=="IPv6") { $this->settings->scanPingPath = $this->settings->scanPingPath."6"; } |
|
272 | + if ($this->identify_address ($address) == "IPv6") { $this->settings->scanPingPath = $this->settings->scanPingPath."6"; } |
|
273 | 273 | |
274 | 274 | # set ping command based on OS type |
275 | - if (PHP_OS == "FreeBSD" || PHP_OS == "NetBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
276 | - elseif(PHP_OS == "Linux" || PHP_OS == "OpenBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -w $this->icmp_timeout $address 1>/dev/null 2>&1"; } |
|
277 | - elseif(PHP_OS == "WIN32" || PHP_OS == "Windows" || PHP_OS == "WINNT") { $cmd = $this->settings->scanPingPath." -n $this->icmp_count -I ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } |
|
278 | - else { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; } |
|
275 | + if (PHP_OS == "FreeBSD" || PHP_OS == "NetBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W ".($this->icmp_timeout * 1000)." $address 1>/dev/null 2>&1"; } |
|
276 | + elseif (PHP_OS == "Linux" || PHP_OS == "OpenBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -w $this->icmp_timeout $address 1>/dev/null 2>&1"; } |
|
277 | + elseif (PHP_OS == "WIN32" || PHP_OS == "Windows" || PHP_OS == "WINNT") { $cmd = $this->settings->scanPingPath." -n $this->icmp_count -I ".($this->icmp_timeout * 1000)." $address 1>/dev/null 2>&1"; } |
|
278 | + else { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; } |
|
279 | 279 | |
280 | 280 | # for IPv6 remove wait |
281 | - if ($this->identify_address ($address)=="IPv6") { |
|
282 | - $cmd = explode(" ", $cmd); |
|
281 | + if ($this->identify_address ($address) == "IPv6") { |
|
282 | + $cmd = explode (" ", $cmd); |
|
283 | 283 | unset($cmd[3], $cmd[4]); |
284 | - $cmd = implode(" ", $cmd); |
|
284 | + $cmd = implode (" ", $cmd); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | # execute command, return $retval |
288 | - exec($cmd, $output, $retval); |
|
288 | + exec ($cmd, $output, $retval); |
|
289 | 289 | |
290 | 290 | # return result for web or cmd |
291 | - if($this->icmp_exit) { exit ($retval); } |
|
292 | - else { return $retval; } |
|
291 | + if ($this->icmp_exit) { exit ($retval); } |
|
292 | + else { return $retval; } |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -301,38 +301,38 @@ discard block |
||
301 | 301 | */ |
302 | 302 | protected function ping_address_method_pear ($address) { |
303 | 303 | # we need pear ping package |
304 | - require_once(dirname(__FILE__) . '/../../functions/PEAR/Net/Ping.php'); |
|
305 | - $ping = Net_Ping::factory(); |
|
304 | + require_once(dirname (__FILE__).'/../../functions/PEAR/Net/Ping.php'); |
|
305 | + $ping = Net_Ping::factory (); |
|
306 | 306 | |
307 | 307 | # ipv6 not supported |
308 | - if ($this->identify_address ($address)=="IPv6") { |
|
308 | + if ($this->identify_address ($address) == "IPv6") { |
|
309 | 309 | //return result for web or cmd |
310 | - if($this->icmp_exit) { exit (255); } |
|
311 | - else { return 255; } |
|
310 | + if ($this->icmp_exit) { exit (255); } |
|
311 | + else { return 255; } |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | # check for errors |
315 | - if($ping->pear->isError($ping)) { |
|
316 | - if($this->icmp_exit) { exit ($ping->getMessage()); } |
|
317 | - else { return $ping->getMessage(); } |
|
315 | + if ($ping->pear->isError ($ping)) { |
|
316 | + if ($this->icmp_exit) { exit ($ping->getMessage ()); } |
|
317 | + else { return $ping->getMessage (); } |
|
318 | 318 | } |
319 | 319 | else { |
320 | 320 | //set count and timeout |
321 | - $ping->setArgs(array('count' => $this->icmp_timeout, 'timeout' => $this->icmp_timeout)); |
|
321 | + $ping->setArgs (array ('count' => $this->icmp_timeout, 'timeout' => $this->icmp_timeout)); |
|
322 | 322 | //execute |
323 | - $ping_response = $ping->ping($address); |
|
323 | + $ping_response = $ping->ping ($address); |
|
324 | 324 | //check response for error |
325 | - if($ping->pear->isError($ping_response)) { |
|
325 | + if ($ping->pear->isError ($ping_response)) { |
|
326 | 326 | $result['code'] = 2; |
327 | 327 | } |
328 | 328 | else { |
329 | 329 | //all good |
330 | - if($ping_response->_transmitted == $ping_response->_received) { |
|
330 | + if ($ping_response->_transmitted == $ping_response->_received) { |
|
331 | 331 | $result['code'] = 0; |
332 | - $this->rtt = "RTT: ". strstr($ping_response->_round_trip['avg'], ".", true); |
|
332 | + $this->rtt = "RTT: ".strstr ($ping_response->_round_trip['avg'], ".", true); |
|
333 | 333 | } |
334 | 334 | //ping loss |
335 | - elseif($ping_response->_received == 0) { |
|
335 | + elseif ($ping_response->_received == 0) { |
|
336 | 336 | $result['code'] = 1; |
337 | 337 | } |
338 | 338 | //failed |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | //return result for web or cmd |
346 | - if($this->icmp_exit) { exit ($result['code']); } |
|
347 | - else { return $result['code']; } |
|
346 | + if ($this->icmp_exit) { exit ($result['code']); } |
|
347 | + else { return $result['code']; } |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -368,21 +368,21 @@ discard block |
||
368 | 368 | $this->ping_verify_path ($this->settings->scanFPingPath); |
369 | 369 | |
370 | 370 | # if ipv6 append 6 |
371 | - if ($this->identify_address ($address)=="IPv6") { $this->settings->scanFPingPath = $this->settings->scanFPingPath."6"; } |
|
371 | + if ($this->identify_address ($address) == "IPv6") { $this->settings->scanFPingPath = $this->settings->scanFPingPath."6"; } |
|
372 | 372 | |
373 | 373 | # set command |
374 | - $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." $address"; |
|
374 | + $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout * 1000)." $address"; |
|
375 | 375 | # execute command, return $retval |
376 | - exec($cmd, $output, $retval); |
|
376 | + exec ($cmd, $output, $retval); |
|
377 | 377 | |
378 | 378 | # save result |
379 | - if($retval==0) { |
|
379 | + if ($retval == 0) { |
|
380 | 380 | $this->save_fping_rtt ($output[0]); |
381 | 381 | } |
382 | 382 | |
383 | 383 | # return result for web or cmd |
384 | - if($this->icmp_exit) { exit ($retval); } |
|
385 | - else { return $retval; } |
|
384 | + if ($this->icmp_exit) { exit ($retval); } |
|
385 | + else { return $retval; } |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -394,10 +394,10 @@ discard block |
||
394 | 394 | */ |
395 | 395 | private function save_fping_rtt ($line) { |
396 | 396 | // 173.192.112.30 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 160/160/160 |
397 | - $tmp = explode(" ",$line); |
|
397 | + $tmp = explode (" ", $line); |
|
398 | 398 | |
399 | 399 | # save rtt |
400 | - @$this->rtt = "RTT: ".str_replace("(", "", $tmp[7]); |
|
400 | + @$this->rtt = "RTT: ".str_replace ("(", "", $tmp[7]); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | # verify ping path |
421 | 421 | $this->ping_verify_path ($this->settings->scanFPingPath); |
422 | 422 | # set command |
423 | - $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." -Ag $subnet_cidr"; |
|
423 | + $cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout * 1000)." -Ag $subnet_cidr"; |
|
424 | 424 | # execute command, return $retval |
425 | - exec($cmd, $output, $retval); |
|
425 | + exec ($cmd, $output, $retval); |
|
426 | 426 | |
427 | 427 | # save result |
428 | - if(sizeof($output)>0) { |
|
429 | - foreach($output as $line) { |
|
430 | - $tmp = explode(" ",$line); |
|
428 | + if (sizeof ($output) > 0) { |
|
429 | + foreach ($output as $line) { |
|
430 | + $tmp = explode (" ", $line); |
|
431 | 431 | $out[] = $tmp[0]; |
432 | 432 | } |
433 | 433 | } |
@@ -436,11 +436,11 @@ discard block |
||
436 | 436 | $this->fping_result = $out; |
437 | 437 | |
438 | 438 | # return result? |
439 | - if($return_result) { return $out; } |
|
439 | + if ($return_result) { return $out; } |
|
440 | 440 | |
441 | 441 | # return result for web or cmd |
442 | - if($this->icmp_exit) { exit ($retval); } |
|
443 | - else { return $retval; } |
|
442 | + if ($this->icmp_exit) { exit ($retval); } |
|
443 | + else { return $retval; } |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | * @return void |
452 | 452 | */ |
453 | 453 | private function ping_verify_path ($path) { |
454 | - if(!file_exists($path)) { |
|
455 | - if($this->icmp_exit) { exit ($this->ping_exit_explain(1000)); } |
|
456 | - else { return $this->Result->show("danger", _($this->ping_exit_explain(1000)), true); } |
|
454 | + if (!file_exists ($path)) { |
|
455 | + if ($this->icmp_exit) { exit ($this->ping_exit_explain (1000)); } |
|
456 | + else { return $this->Result->show ("danger", _ ($this->ping_exit_explain (1000)), true); } |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
@@ -513,13 +513,13 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public function ping_update_lastseen ($id, $datetime = null) { |
515 | 515 | # set datetime |
516 | - $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; |
|
516 | + $datetime = is_null ($datetime) ? date ("Y-m-d H:i:s") : $datetime; |
|
517 | 517 | # execute |
518 | - try { $this->Database->updateObject("ipaddresses", array("id"=>$id, "lastSeen"=>$datetime), "id"); } |
|
518 | + try { $this->Database->updateObject ("ipaddresses", array ("id"=>$id, "lastSeen"=>$datetime), "id"); } |
|
519 | 519 | catch (Exception $e) { |
520 | - !$this->debugging ? : $this->Result->show("danger", $e->getMessage(), false); |
|
520 | + !$this->debugging ? : $this->Result->show ("danger", $e->getMessage (), false); |
|
521 | 521 | # log |
522 | - !$this->debugging ? : $this->Log->write ("status_update", _('Failed to update address status'), 0 ); |
|
522 | + !$this->debugging ? : $this->Log->write ("status_update", _ ('Failed to update address status'), 0); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
@@ -533,10 +533,10 @@ discard block |
||
533 | 533 | */ |
534 | 534 | public function ping_update_scanagent_checktime ($id, $date = false) { |
535 | 535 | # set time |
536 | - if ($date === false) { $date = date("Y-m-d H:i:s"); } |
|
537 | - else { $date = $date; } |
|
536 | + if ($date === false) { $date = date ("Y-m-d H:i:s"); } |
|
537 | + else { $date = $date; } |
|
538 | 538 | # execute |
539 | - try { $this->Database->updateObject("scanAgents", array("id"=>$id, "last_access"=>date("Y-m-d H:i:s")), "id"); } |
|
539 | + try { $this->Database->updateObject ("scanAgents", array ("id"=>$id, "last_access"=>date ("Y-m-d H:i:s")), "id"); } |
|
540 | 540 | catch (Exception $e) { |
541 | 541 | } |
542 | 542 | } |
@@ -551,20 +551,20 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function telnet_address ($address, $port) { |
553 | 553 | # set all ports |
554 | - $ports = explode(",", str_replace(";",",",$port)); |
|
554 | + $ports = explode (",", str_replace (";", ",", $port)); |
|
555 | 555 | # default response is dead |
556 | 556 | $retval = 1; |
557 | 557 | //try each port untill one is alive |
558 | - foreach($ports as $p) { |
|
558 | + foreach ($ports as $p) { |
|
559 | 559 | // open socket |
560 | - $conn = @fsockopen($address, $p, $errno, $errstr, $this->icmp_timeout); |
|
560 | + $conn = @fsockopen ($address, $p, $errno, $errstr, $this->icmp_timeout); |
|
561 | 561 | //failed |
562 | 562 | if (!$conn) {} |
563 | 563 | //success |
564 | - else { |
|
565 | - $retval = 0; //set return as port if alive |
|
566 | - fclose($conn); |
|
567 | - break; //end foreach if success |
|
564 | + else { |
|
565 | + $retval = 0; //set return as port if alive |
|
566 | + fclose ($conn); |
|
567 | + break; //end foreach if success |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | # exit with result |
@@ -595,11 +595,11 @@ discard block |
||
595 | 595 | */ |
596 | 596 | public function prepare_addresses_to_scan ($type, $subnet, $die = true) { |
597 | 597 | # discover new addresses |
598 | - if($type=="discovery") { return is_numeric($subnet) ? $this->prepare_addresses_to_discover_subnetId ($subnet, $die) : $this->prepare_addresses_to_discover_subnet ($subnet, $die); } |
|
598 | + if ($type == "discovery") { return is_numeric ($subnet) ? $this->prepare_addresses_to_discover_subnetId ($subnet, $die) : $this->prepare_addresses_to_discover_subnet ($subnet, $die); } |
|
599 | 599 | # update addresses statuses |
600 | - elseif($type=="update") { return $this->prepare_addresses_to_update ($subnet); } |
|
600 | + elseif ($type == "update") { return $this->prepare_addresses_to_update ($subnet); } |
|
601 | 601 | # fail |
602 | - else { die(json_encode(array("status"=>1, "error"=>"Invalid scan type provided"))); } |
|
602 | + else { die(json_encode (array ("status"=>1, "error"=>"Invalid scan type provided"))); } |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -611,19 +611,19 @@ discard block |
||
611 | 611 | */ |
612 | 612 | public function prepare_addresses_to_discover_subnetId ($subnetId, $die) { |
613 | 613 | # initialize classes |
614 | - $Subnets = new Subnets ($this->Database); |
|
614 | + $Subnets = new Subnets ($this->Database); |
|
615 | 615 | |
616 | 616 | //subnet ID is provided, fetch subnet |
617 | - $subnet = $Subnets->fetch_subnet(null, $subnetId); |
|
618 | - if($subnet===false) { |
|
619 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Invalid subnet ID provided"))); } |
|
620 | - else { return array(); } |
|
617 | + $subnet = $Subnets->fetch_subnet (null, $subnetId); |
|
618 | + if ($subnet === false) { |
|
619 | + if ($die) { die(json_encode (array ("status"=>1, "error"=>"Invalid subnet ID provided"))); } |
|
620 | + else { return array (); } |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | // we should support only up to 4094 hosts! |
624 | - if($Subnets->get_max_hosts ($subnet->mask, "IPv4")>4094 && php_sapi_name()!="cli") |
|
625 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); } |
|
626 | - else { return array(); } |
|
624 | + if ($Subnets->get_max_hosts ($subnet->mask, "IPv4") > 4094 && php_sapi_name () != "cli") |
|
625 | + if ($die) { die(json_encode (array ("status"=>1, "error"=>"Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"))); } |
|
626 | + else { return array (); } |
|
627 | 627 | |
628 | 628 | # set array of addresses to scan, exclude existing! |
629 | 629 | $ip = $this->get_all_possible_subnet_addresses ($subnet->subnet, $subnet->mask); |
@@ -632,9 +632,9 @@ discard block |
||
632 | 632 | $ip = $this->remove_existing_subnet_addresses ($ip, $subnetId); |
633 | 633 | |
634 | 634 | //none to scan? |
635 | - if(sizeof($ip)==0) { |
|
636 | - if ($die) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
637 | - else { return array(); } |
|
635 | + if (sizeof ($ip) == 0) { |
|
636 | + if ($die) { die(json_encode (array ("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
637 | + else { return array (); } |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | //return |
@@ -653,23 +653,23 @@ discard block |
||
653 | 653 | # initialize classes |
654 | 654 | $Subnets = new Subnets ($this->Database); |
655 | 655 | # make sure we have proper subnet format |
656 | - $subnet = $Subnets->transform_address($subnet, "decimal"); |
|
656 | + $subnet = $Subnets->transform_address ($subnet, "decimal"); |
|
657 | 657 | //fetch start and stop addresses |
658 | 658 | $boundaries = (object) $Subnets->get_network_boundaries ($subnet, $mask); |
659 | 659 | //create array |
660 | - if($mask==32) { |
|
661 | - $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
660 | + if ($mask == 32) { |
|
661 | + $ip[] = $Subnets->transform_to_decimal ($boundaries->network); |
|
662 | 662 | } |
663 | - elseif($mask==31) { |
|
664 | - $ip[] = $Subnets->transform_to_decimal($boundaries->network); |
|
665 | - $ip[] = $Subnets->transform_to_decimal($boundaries->broadcast); |
|
663 | + elseif ($mask == 31) { |
|
664 | + $ip[] = $Subnets->transform_to_decimal ($boundaries->network); |
|
665 | + $ip[] = $Subnets->transform_to_decimal ($boundaries->broadcast); |
|
666 | 666 | } |
667 | 667 | else { |
668 | 668 | //set loop limits |
669 | - $start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network),1)); |
|
670 | - $stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast)); |
|
669 | + $start = gmp_strval (gmp_add ($Subnets->transform_to_decimal ($boundaries->network), 1)); |
|
670 | + $stop = gmp_strval ($Subnets->transform_to_decimal ($boundaries->broadcast)); |
|
671 | 671 | //loop |
672 | - for($m=$start; $m<$stop; $m++) { |
|
672 | + for ($m = $start; $m < $stop; $m++) { |
|
673 | 673 | $ip[] = $m; |
674 | 674 | } |
675 | 675 | } |
@@ -689,20 +689,20 @@ discard block |
||
689 | 689 | # first fetch all addresses |
690 | 690 | $Addresses = new Addresses ($this->Database); |
691 | 691 | // get all existing IP addresses in subnet |
692 | - $addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
692 | + $addresses = $Addresses->fetch_subnet_addresses ($subnetId); |
|
693 | 693 | // if some exist remove them |
694 | - if(sizeof($addresses)>0 && sizeof(@$ip)>0) { |
|
695 | - foreach($addresses as $a) { |
|
696 | - $key = array_search($a->ip_addr, $ip); |
|
697 | - if($key !== false) { |
|
694 | + if (sizeof ($addresses) > 0 && sizeof (@$ip) > 0) { |
|
695 | + foreach ($addresses as $a) { |
|
696 | + $key = array_search ($a->ip_addr, $ip); |
|
697 | + if ($key !== false) { |
|
698 | 698 | unset($ip[$key]); |
699 | 699 | } |
700 | 700 | } |
701 | 701 | //reindex array for pinging |
702 | - $ip = array_values(@$ip); |
|
702 | + $ip = array_values (@$ip); |
|
703 | 703 | } |
704 | 704 | //return |
705 | - return is_array(@$ip) ? $ip : array(); |
|
705 | + return is_array (@$ip) ? $ip : array (); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -714,11 +714,11 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function prepare_addresses_to_discover_subnet ($subnet) { |
716 | 716 | //set subnet / mask |
717 | - $subnet_parsed = explode("/", $subnet); |
|
717 | + $subnet_parsed = explode ("/", $subnet); |
|
718 | 718 | # result |
719 | 719 | $ip = $this->get_all_possible_subnet_addresses ($subnet_parsed[0], $subnet_parsed[1]); |
720 | 720 | //none to scan? |
721 | - if(sizeof($ip)==0) { die(json_encode(array("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
721 | + if (sizeof ($ip) == 0) { die(json_encode (array ("status"=>1, "error"=>"Didn't find any address to scan!"))); } |
|
722 | 722 | //result |
723 | 723 | return $ip; |
724 | 724 | } |
@@ -734,19 +734,19 @@ discard block |
||
734 | 734 | # first fetch all addresses |
735 | 735 | $Addresses = new Addresses ($this->Database); |
736 | 736 | // get all existing IP addresses in subnet |
737 | - $subnet_addresses = $Addresses->fetch_subnet_addresses($subnetId); |
|
737 | + $subnet_addresses = $Addresses->fetch_subnet_addresses ($subnetId); |
|
738 | 738 | //create array |
739 | - if(sizeof($subnet_addresses)>0) { |
|
740 | - foreach($subnet_addresses as $a) { |
|
739 | + if (sizeof ($subnet_addresses) > 0) { |
|
740 | + foreach ($subnet_addresses as $a) { |
|
741 | 741 | $scan_addresses[$a->id] = $a->ip_addr; |
742 | 742 | } |
743 | 743 | //reindex |
744 | - $scan_addresses = array_values(@$scan_addresses); |
|
744 | + $scan_addresses = array_values (@$scan_addresses); |
|
745 | 745 | //return |
746 | 746 | return $scan_addresses; |
747 | 747 | } |
748 | 748 | else { |
749 | - return array(); |
|
749 | + return array (); |
|
750 | 750 | } |
751 | 751 | } |
752 | 752 | } |
@@ -22,26 +22,26 @@ |
||
22 | 22 | |
23 | 23 | # print result |
24 | 24 | if( (!isset($errors['tableError'])) && (!isset($errors['fieldError'])) ) { |
25 | - print 'All tables and fields are installed properly'. "\n"; |
|
25 | + print 'All tables and fields are installed properly'. "\n"; |
|
26 | 26 | } |
27 | 27 | else { |
28 | - # missing tables |
|
29 | - if (isset($errors['tableError'])) { |
|
30 | - print 'Missing tables:'. "\n"; |
|
31 | - |
|
32 | - foreach ($errors['tableError'] as $table) { |
|
33 | - print " - ".$table."\n"; |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - # missing fields |
|
38 | - if (isset($errors['fieldError'])) { |
|
39 | - print "\n".'Missing fields'. "\n"; |
|
40 | - |
|
41 | - foreach ($errors['fieldError'] as $table=>$field) { |
|
42 | - print 'Table `'. $table .'`: missing field `'. $field .'`;'."\n"; |
|
43 | - } |
|
44 | - } |
|
28 | + # missing tables |
|
29 | + if (isset($errors['tableError'])) { |
|
30 | + print 'Missing tables:'. "\n"; |
|
31 | + |
|
32 | + foreach ($errors['tableError'] as $table) { |
|
33 | + print " - ".$table."\n"; |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + # missing fields |
|
38 | + if (isset($errors['fieldError'])) { |
|
39 | + print "\n".'Missing fields'. "\n"; |
|
40 | + |
|
41 | + foreach ($errors['fieldError'] as $table=>$field) { |
|
42 | + print 'Table `'. $table .'`: missing field `'. $field .'`;'."\n"; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | print "\n"; |
47 | 47 | ?> |
48 | 48 | \ No newline at end of file |
@@ -8,26 +8,26 @@ discard block |
||
8 | 8 | ****************************************/ |
9 | 9 | |
10 | 10 | # functions |
11 | -require_once( dirname(__FILE__) . '/../functions.php' ); |
|
11 | +require_once(dirname (__FILE__).'/../functions.php'); |
|
12 | 12 | |
13 | 13 | # Classes |
14 | 14 | $Database = new Database_PDO; |
15 | 15 | $Tools = new Tools ($Database); |
16 | 16 | |
17 | 17 | # title |
18 | -print "\n".'Database structure verification'. "\n--------------------\n"; |
|
18 | +print "\n".'Database structure verification'."\n--------------------\n"; |
|
19 | 19 | |
20 | 20 | # check for errors |
21 | -$errors = $Tools->verify_database(); |
|
21 | +$errors = $Tools->verify_database (); |
|
22 | 22 | |
23 | 23 | # print result |
24 | -if( (!isset($errors['tableError'])) && (!isset($errors['fieldError'])) ) { |
|
25 | - print 'All tables and fields are installed properly'. "\n"; |
|
24 | +if ((!isset($errors['tableError'])) && (!isset($errors['fieldError']))) { |
|
25 | + print 'All tables and fields are installed properly'."\n"; |
|
26 | 26 | } |
27 | 27 | else { |
28 | 28 | # missing tables |
29 | 29 | if (isset($errors['tableError'])) { |
30 | - print 'Missing tables:'. "\n"; |
|
30 | + print 'Missing tables:'."\n"; |
|
31 | 31 | |
32 | 32 | foreach ($errors['tableError'] as $table) { |
33 | 33 | print " - ".$table."\n"; |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | |
37 | 37 | # missing fields |
38 | 38 | if (isset($errors['fieldError'])) { |
39 | - print "\n".'Missing fields'. "\n"; |
|
39 | + print "\n".'Missing fields'."\n"; |
|
40 | 40 | |
41 | 41 | foreach ($errors['fieldError'] as $table=>$field) { |
42 | - print 'Table `'. $table .'`: missing field `'. $field .'`;'."\n"; |
|
42 | + print 'Table `'.$table.'`: missing field `'.$field.'`;'."\n"; |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | /* redirect */ |
10 | 10 | if($User->settings->version < VERSION) { |
11 | - header("Location: ".create_link("upgrade")); |
|
12 | - die(); |
|
11 | + header("Location: ".create_link("upgrade")); |
|
12 | + die(); |
|
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
7 | 7 | # use required functions |
8 | 8 | |
9 | 9 | /* redirect */ |
10 | -if($User->settings->version < VERSION) { |
|
11 | - header("Location: ".create_link("upgrade")); |
|
10 | +if ($User->settings->version < VERSION) { |
|
11 | + header ("Location: ".create_link ("upgrade")); |
|
12 | 12 | die(); |
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | \ No newline at end of file |
@@ -14,23 +14,23 @@ discard block |
||
14 | 14 | $untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && grep -r '_(' * ")); |
15 | 15 | // loop and search |
16 | 16 | foreach ($untranslated as $u) { |
17 | - // find string |
|
18 | - $str = get_string_between($u, "_('", "')"); |
|
19 | - // remove "" and ' |
|
20 | - $str = trim($str, "',\""); |
|
21 | - // search for invalud content and remove |
|
22 | - if (substr($str, 0, 1)!="$") { |
|
23 | - $all_translations[] = $str; |
|
24 | - } |
|
17 | + // find string |
|
18 | + $str = get_string_between($u, "_('", "')"); |
|
19 | + // remove "" and ' |
|
20 | + $str = trim($str, "',\""); |
|
21 | + // search for invalud content and remove |
|
22 | + if (substr($str, 0, 1)!="$") { |
|
23 | + $all_translations[] = $str; |
|
24 | + } |
|
25 | 25 | |
26 | - // find string |
|
27 | - $str = get_string_between($u, '_("', '")'); |
|
28 | - // remove "" and ' |
|
29 | - $str = trim($str, "',\""); |
|
30 | - // search for invalud content and remove |
|
31 | - if (substr($str, 0, 1)!="$") { |
|
32 | - $all_translations[] = $str; |
|
33 | - } |
|
26 | + // find string |
|
27 | + $str = get_string_between($u, '_("', '")'); |
|
28 | + // remove "" and ' |
|
29 | + $str = trim($str, "',\""); |
|
30 | + // search for invalud content and remove |
|
31 | + if (substr($str, 0, 1)!="$") { |
|
32 | + $all_translations[] = $str; |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | //unique |
36 | 36 | $all_translations = array_unique($all_translations); |
@@ -40,25 +40,25 @@ discard block |
||
40 | 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 | - // search for string |
|
44 | - if (substr($u, 0, 7)=='msgid "') { |
|
45 | - $u = str_replace("msgid ", "", $u); |
|
46 | - $u = trim($u, '"'); |
|
47 | - $translated[] = $u; |
|
48 | - } |
|
43 | + // search for string |
|
44 | + if (substr($u, 0, 7)=='msgid "') { |
|
45 | + $u = str_replace("msgid ", "", $u); |
|
46 | + $u = trim($u, '"'); |
|
47 | + $translated[] = $u; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // remove existing from unique |
52 | 52 | foreach ($all_translations as $tr) { |
53 | - if (!in_array($tr, $translated)) { |
|
54 | - $new[] = $tr; |
|
55 | - } |
|
53 | + if (!in_array($tr, $translated)) { |
|
54 | + $new[] = $tr; |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // format |
59 | 59 | foreach ($new as $tr) { |
60 | - $text[] = "msgid \"$tr\""; |
|
61 | - $text[] = "msgstr \"\"\n"; |
|
60 | + $text[] = "msgid \"$tr\""; |
|
61 | + $text[] = "msgstr \"\"\n"; |
|
62 | 62 | } |
63 | 63 | // join text |
64 | 64 | $text = implode("\n",$text); |
@@ -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 |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | /* settings */ |
16 | 16 | $resolve_config['emptyonly'] = true; # if true it will only update the ones without DNS entry! |
17 | 17 | $resolve_config['subnets'] = array(); # which subnets to check - by id |
18 | - # example -> array(1,3,5) will only update subnets with id 1,3,5 |
|
19 | - # you can get id's and descriptions with following MySQL query: |
|
20 | - # select `id`,`description` from `subnets`; |
|
18 | + # example -> array(1,3,5) will only update subnets with id 1,3,5 |
|
19 | + # you can get id's and descriptions with following MySQL query: |
|
20 | + # select `id`,`description` from `subnets`; |
|
21 | 21 | $resolve_config['verbose'] = true; # verbose response - prints results, cron will email it to you! |
22 | 22 | |
23 | 23 | # include required scripts |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | |
40 | 40 | # set subnet |
41 | 41 | if (isset($argv[1])) { |
42 | - $req_subnets = explode(",", $argv[1]); |
|
43 | - foreach ($req_subnets as $s) { |
|
44 | - if (!is_numeric($s)) { $Result->show_cli("Invalid subnetId provided - $s\n", true); } |
|
45 | - else { |
|
46 | - $resolve_config['subnets'][] = $s; |
|
47 | - } |
|
48 | - } |
|
42 | + $req_subnets = explode(",", $argv[1]); |
|
43 | + foreach ($req_subnets as $s) { |
|
44 | + if (!is_numeric($s)) { $Result->show_cli("Invalid subnetId provided - $s\n", true); } |
|
45 | + else { |
|
46 | + $resolve_config['subnets'][] = $s; |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -56,29 +56,29 @@ discard block |
||
56 | 56 | |
57 | 57 | # check all subnets |
58 | 58 | if(sizeof($resolve_config['subnets']) == 0) { |
59 | - # get ony ip's with empty DNS |
|
60 | - if($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | - else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
59 | + # get ony ip's with empty DNS |
|
60 | + if($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | + else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
62 | 62 | } |
63 | 63 | # check selected subnets |
64 | 64 | else { |
65 | - $query[] = "select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where "; |
|
66 | - //go through subnets |
|
67 | - $m=1; |
|
68 | - foreach($resolve_config['subnets'] as $k=>$subnetId) { |
|
69 | - // last |
|
70 | - if($m==sizeof($resolve_config['subnets'])) { $query[] = '`subnetId` = "'. $subnetId .'" '; } |
|
71 | - else { $query[] = '`subnetId` = "'. $subnetId .'" or '; } |
|
72 | - $m++; |
|
73 | - } |
|
74 | - # get ony ip's with empty DNS |
|
75 | - if($resolve_config['emptyonly'] == 1) { |
|
76 | - $query[] = ' and (`dns_name` = "" or `dns_name` is NULL ) '; |
|
77 | - } |
|
78 | - $query[] = 'order by `ip_addr` ASC;'; |
|
79 | - |
|
80 | - //join |
|
81 | - $query = implode("\n", $query); |
|
65 | + $query[] = "select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where "; |
|
66 | + //go through subnets |
|
67 | + $m=1; |
|
68 | + foreach($resolve_config['subnets'] as $k=>$subnetId) { |
|
69 | + // last |
|
70 | + if($m==sizeof($resolve_config['subnets'])) { $query[] = '`subnetId` = "'. $subnetId .'" '; } |
|
71 | + else { $query[] = '`subnetId` = "'. $subnetId .'" or '; } |
|
72 | + $m++; |
|
73 | + } |
|
74 | + # get ony ip's with empty DNS |
|
75 | + if($resolve_config['emptyonly'] == 1) { |
|
76 | + $query[] = ' and (`dns_name` = "" or `dns_name` is NULL ) '; |
|
77 | + } |
|
78 | + $query[] = 'order by `ip_addr` ASC;'; |
|
79 | + |
|
80 | + //join |
|
81 | + $query = implode("\n", $query); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | # fetch records |
@@ -86,31 +86,31 @@ discard block |
||
86 | 86 | |
87 | 87 | # try to update dns records |
88 | 88 | if (sizeof($ipaddresses)>0) { |
89 | - foreach($ipaddresses as $ip) { |
|
90 | - # fetch subnet |
|
91 | - $subnet = $Subnets->fetch_subnet ("id", $ip->subnetId); |
|
92 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
93 | - # try to resolve |
|
94 | - $hostname = $DNS->resolve_address ($ip->ip_addr, null, true, $nsid); |
|
95 | - |
|
96 | - # update if change |
|
97 | - if($hostname['class']=="resolved") { |
|
98 | - # values |
|
99 | - $values = array("dns_name"=>$hostname['name'], |
|
100 | - "id"=>$ip->id |
|
101 | - ); |
|
102 | - # execute |
|
103 | - if(!$Admin->object_modify("ipaddresses", "edit", "id", $values)) { $Result->show_cli("Failed to update address ".$Subnets->transform_to_dotted($ip->ip_addr)); } |
|
104 | - |
|
105 | - # set text |
|
106 | - $res[] = 'updated ip address '. $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname '. $hostname['name']; |
|
107 | - } |
|
108 | - } |
|
89 | + foreach($ipaddresses as $ip) { |
|
90 | + # fetch subnet |
|
91 | + $subnet = $Subnets->fetch_subnet ("id", $ip->subnetId); |
|
92 | + $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
93 | + # try to resolve |
|
94 | + $hostname = $DNS->resolve_address ($ip->ip_addr, null, true, $nsid); |
|
95 | + |
|
96 | + # update if change |
|
97 | + if($hostname['class']=="resolved") { |
|
98 | + # values |
|
99 | + $values = array("dns_name"=>$hostname['name'], |
|
100 | + "id"=>$ip->id |
|
101 | + ); |
|
102 | + # execute |
|
103 | + if(!$Admin->object_modify("ipaddresses", "edit", "id", $values)) { $Result->show_cli("Failed to update address ".$Subnets->transform_to_dotted($ip->ip_addr)); } |
|
104 | + |
|
105 | + # set text |
|
106 | + $res[] = 'updated ip address '. $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname '. $hostname['name']; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | 112 | # if verbose print result so it can be emailed via cron! |
113 | 113 | if($resolve_config['verbose'] == true && isset($res)) { |
114 | - print implode("\n", $res); |
|
114 | + print implode("\n", $res); |
|
115 | 115 | } |
116 | 116 | ?> |
117 | 117 | \ No newline at end of file |
@@ -13,35 +13,35 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | /* settings */ |
16 | -$resolve_config['emptyonly'] = true; # if true it will only update the ones without DNS entry! |
|
17 | -$resolve_config['subnets'] = array(); # which subnets to check - by id |
|
16 | +$resolve_config['emptyonly'] = true; # if true it will only update the ones without DNS entry! |
|
17 | +$resolve_config['subnets'] = array (); # which subnets to check - by id |
|
18 | 18 | # example -> array(1,3,5) will only update subnets with id 1,3,5 |
19 | 19 | # you can get id's and descriptions with following MySQL query: |
20 | 20 | # select `id`,`description` from `subnets`; |
21 | -$resolve_config['verbose'] = true; # verbose response - prints results, cron will email it to you! |
|
21 | +$resolve_config['verbose'] = true; # verbose response - prints results, cron will email it to you! |
|
22 | 22 | |
23 | 23 | # include required scripts |
24 | -require( dirname(__FILE__) . '/../functions.php' ); |
|
24 | +require(dirname (__FILE__).'/../functions.php'); |
|
25 | 25 | |
26 | 26 | # initialize objects |
27 | -$Database = new Database_PDO; |
|
28 | -$Admin = new Admin ($Database, false); |
|
27 | +$Database = new Database_PDO; |
|
28 | +$Admin = new Admin ($Database, false); |
|
29 | 29 | $Subnets = new Subnets ($Database); |
30 | -$DNS = new DNS ($Database); |
|
31 | -$Result = new Result(); |
|
30 | +$DNS = new DNS ($Database); |
|
31 | +$Result = new Result (); |
|
32 | 32 | |
33 | 33 | // set to 1 in case of errors |
34 | -ini_set('display_errors', 0); |
|
35 | -error_reporting(E_ERROR); |
|
34 | +ini_set ('display_errors', 0); |
|
35 | +error_reporting (E_ERROR); |
|
36 | 36 | |
37 | 37 | # cli required |
38 | -if( php_sapi_name()!="cli" ) { $Result->show_cli("cli only\n", true); } |
|
38 | +if (php_sapi_name () != "cli") { $Result->show_cli ("cli only\n", true); } |
|
39 | 39 | |
40 | 40 | # set subnet |
41 | 41 | if (isset($argv[1])) { |
42 | - $req_subnets = explode(",", $argv[1]); |
|
42 | + $req_subnets = explode (",", $argv[1]); |
|
43 | 43 | foreach ($req_subnets as $s) { |
44 | - if (!is_numeric($s)) { $Result->show_cli("Invalid subnetId provided - $s\n", true); } |
|
44 | + if (!is_numeric ($s)) { $Result->show_cli ("Invalid subnetId provided - $s\n", true); } |
|
45 | 45 | else { |
46 | 46 | $resolve_config['subnets'][] = $s; |
47 | 47 | } |
@@ -55,62 +55,62 @@ discard block |
||
55 | 55 | # |
56 | 56 | |
57 | 57 | # check all subnets |
58 | -if(sizeof($resolve_config['subnets']) == 0) { |
|
58 | +if (sizeof ($resolve_config['subnets']) == 0) { |
|
59 | 59 | # get ony ip's with empty DNS |
60 | - if($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | - else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
60 | + if ($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | + else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
62 | 62 | } |
63 | 63 | # check selected subnets |
64 | 64 | else { |
65 | 65 | $query[] = "select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where "; |
66 | 66 | //go through subnets |
67 | - $m=1; |
|
68 | - foreach($resolve_config['subnets'] as $k=>$subnetId) { |
|
67 | + $m = 1; |
|
68 | + foreach ($resolve_config['subnets'] as $k=>$subnetId) { |
|
69 | 69 | // last |
70 | - if($m==sizeof($resolve_config['subnets'])) { $query[] = '`subnetId` = "'. $subnetId .'" '; } |
|
71 | - else { $query[] = '`subnetId` = "'. $subnetId .'" or '; } |
|
70 | + if ($m == sizeof ($resolve_config['subnets'])) { $query[] = '`subnetId` = "'.$subnetId.'" '; } |
|
71 | + else { $query[] = '`subnetId` = "'.$subnetId.'" or '; } |
|
72 | 72 | $m++; |
73 | 73 | } |
74 | 74 | # get ony ip's with empty DNS |
75 | - if($resolve_config['emptyonly'] == 1) { |
|
75 | + if ($resolve_config['emptyonly'] == 1) { |
|
76 | 76 | $query[] = ' and (`dns_name` = "" or `dns_name` is NULL ) '; |
77 | 77 | } |
78 | 78 | $query[] = 'order by `ip_addr` ASC;'; |
79 | 79 | |
80 | 80 | //join |
81 | - $query = implode("\n", $query); |
|
81 | + $query = implode ("\n", $query); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | # fetch records |
85 | -$ipaddresses = $Database->getObjectsQuery($query); |
|
85 | +$ipaddresses = $Database->getObjectsQuery ($query); |
|
86 | 86 | |
87 | 87 | # try to update dns records |
88 | -if (sizeof($ipaddresses)>0) { |
|
89 | - foreach($ipaddresses as $ip) { |
|
88 | +if (sizeof ($ipaddresses) > 0) { |
|
89 | + foreach ($ipaddresses as $ip) { |
|
90 | 90 | # fetch subnet |
91 | 91 | $subnet = $Subnets->fetch_subnet ("id", $ip->subnetId); |
92 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
92 | + $nsid = $subnet === false ? false : $subnet->nameserverId; |
|
93 | 93 | # try to resolve |
94 | 94 | $hostname = $DNS->resolve_address ($ip->ip_addr, null, true, $nsid); |
95 | 95 | |
96 | 96 | # update if change |
97 | - if($hostname['class']=="resolved") { |
|
97 | + if ($hostname['class'] == "resolved") { |
|
98 | 98 | # values |
99 | - $values = array("dns_name"=>$hostname['name'], |
|
99 | + $values = array ("dns_name"=>$hostname['name'], |
|
100 | 100 | "id"=>$ip->id |
101 | 101 | ); |
102 | 102 | # execute |
103 | - if(!$Admin->object_modify("ipaddresses", "edit", "id", $values)) { $Result->show_cli("Failed to update address ".$Subnets->transform_to_dotted($ip->ip_addr)); } |
|
103 | + if (!$Admin->object_modify ("ipaddresses", "edit", "id", $values)) { $Result->show_cli ("Failed to update address ".$Subnets->transform_to_dotted ($ip->ip_addr)); } |
|
104 | 104 | |
105 | 105 | # set text |
106 | - $res[] = 'updated ip address '. $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname '. $hostname['name']; |
|
106 | + $res[] = 'updated ip address '.$Subnets->transform_to_dotted ($ip->ip_addr).' with hostname '.$hostname['name']; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | 112 | # if verbose print result so it can be emailed via cron! |
113 | -if($resolve_config['verbose'] == true && isset($res)) { |
|
114 | - print implode("\n", $res); |
|
113 | +if ($resolve_config['verbose'] == true && isset($res)) { |
|
114 | + print implode ("\n", $res); |
|
115 | 115 | } |
116 | 116 | ?> |
117 | 117 | \ No newline at end of file |
@@ -78,18 +78,18 @@ discard block |
||
78 | 78 | $addresses_tmp = array(); |
79 | 79 | // loop |
80 | 80 | foreach($scan_subnets as $s) { |
81 | - // if subnet has slaves dont check it |
|
82 | - if ($Subnets->has_slaves ($s->id) === false) { |
|
83 | - $addresses_tmp[$s->id] = $Scan-> prepare_addresses_to_scan ("discovery", $s->id, false); |
|
84 | - } |
|
81 | + // if subnet has slaves dont check it |
|
82 | + if ($Subnets->has_slaves ($s->id) === false) { |
|
83 | + $addresses_tmp[$s->id] = $Scan-> prepare_addresses_to_scan ("discovery", $s->id, false); |
|
84 | + } |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | //reindex |
88 | 88 | if(sizeof($addresses_tmp)>0) { |
89 | 89 | foreach($addresses_tmp as $s_id=>$a) { |
90 | - foreach($a as $ip) { |
|
91 | - $addresses[] = array("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
92 | - } |
|
90 | + foreach($a as $ip) { |
|
91 | + $addresses[] = array("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -110,101 +110,101 @@ discard block |
||
110 | 110 | |
111 | 111 | //different scan for fping |
112 | 112 | if($Scan->icmp_type=="fping") { |
113 | - //run per MAX_THREADS |
|
114 | - for ($m=0; $m<=$size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
115 | - // create threads |
|
116 | - $threads = array(); |
|
117 | - //fork processes |
|
118 | - for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_subnets; $i++) { |
|
119 | - //only if index exists! |
|
120 | - if(isset($scan_subnets[$z])) { |
|
121 | - //start new thread |
|
122 | - $threads[$z] = new Thread( 'fping_subnet' ); |
|
123 | - $threads[$z]->start_fping( $Subnets->transform_to_dotted($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask ); |
|
124 | - $z++; //next index |
|
125 | - } |
|
126 | - } |
|
127 | - // wait for all the threads to finish |
|
128 | - while( !empty( $threads ) ) { |
|
129 | - foreach($threads as $index => $thread) { |
|
130 | - $child_pipe = "/tmp/pipe_".$thread->getPid(); |
|
131 | - |
|
132 | - if (file_exists($child_pipe)) { |
|
133 | - $file_descriptor = fopen( $child_pipe, "r"); |
|
134 | - $child_response = ""; |
|
135 | - while (!feof($file_descriptor)) { |
|
136 | - $child_response .= fread($file_descriptor, 8192); |
|
137 | - } |
|
138 | - //we have the child data in the parent, but serialized: |
|
139 | - $child_response = unserialize( $child_response ); |
|
140 | - //store |
|
141 | - $scan_subnets[$index]->discovered = $child_response; |
|
142 | - //now, child is dead, and parent close the pipe |
|
143 | - unlink( $child_pipe ); |
|
144 | - unset($threads[$index]); |
|
145 | - } |
|
146 | - } |
|
147 | - usleep(200000); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - //fping finds all subnet addresses, we must remove existing ones ! |
|
152 | - foreach($scan_subnets as $sk=>$s) { |
|
153 | - if(isset($s->discovered)) { |
|
154 | - foreach($s->discovered as $rk=>$result) { |
|
155 | - if(!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { |
|
156 | - unset($scan_subnets[$sk]->discovered[$rk]); |
|
157 | - } |
|
158 | - } |
|
113 | + //run per MAX_THREADS |
|
114 | + for ($m=0; $m<=$size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
115 | + // create threads |
|
116 | + $threads = array(); |
|
117 | + //fork processes |
|
118 | + for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_subnets; $i++) { |
|
119 | + //only if index exists! |
|
120 | + if(isset($scan_subnets[$z])) { |
|
121 | + //start new thread |
|
122 | + $threads[$z] = new Thread( 'fping_subnet' ); |
|
123 | + $threads[$z]->start_fping( $Subnets->transform_to_dotted($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask ); |
|
124 | + $z++; //next index |
|
125 | + } |
|
126 | + } |
|
127 | + // wait for all the threads to finish |
|
128 | + while( !empty( $threads ) ) { |
|
129 | + foreach($threads as $index => $thread) { |
|
130 | + $child_pipe = "/tmp/pipe_".$thread->getPid(); |
|
131 | + |
|
132 | + if (file_exists($child_pipe)) { |
|
133 | + $file_descriptor = fopen( $child_pipe, "r"); |
|
134 | + $child_response = ""; |
|
135 | + while (!feof($file_descriptor)) { |
|
136 | + $child_response .= fread($file_descriptor, 8192); |
|
137 | + } |
|
138 | + //we have the child data in the parent, but serialized: |
|
139 | + $child_response = unserialize( $child_response ); |
|
140 | + //store |
|
141 | + $scan_subnets[$index]->discovered = $child_response; |
|
142 | + //now, child is dead, and parent close the pipe |
|
143 | + unlink( $child_pipe ); |
|
144 | + unset($threads[$index]); |
|
145 | + } |
|
146 | + } |
|
147 | + usleep(200000); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + //fping finds all subnet addresses, we must remove existing ones ! |
|
152 | + foreach($scan_subnets as $sk=>$s) { |
|
153 | + if(isset($s->discovered)) { |
|
154 | + foreach($s->discovered as $rk=>$result) { |
|
155 | + if(!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { |
|
156 | + unset($scan_subnets[$sk]->discovered[$rk]); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | //rekey |
160 | 160 | $scan_subnets[$sk]->discovered = array_values($scan_subnets[$sk]->discovered); |
161 | - } |
|
162 | - } |
|
161 | + } |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | //ping, pear |
165 | 165 | else { |
166 | - //run per MAX_THREADS |
|
166 | + //run per MAX_THREADS |
|
167 | 167 | for ($m=0; $m<=$size_addresses; $m += $Scan->settings->scanMaxThreads) { |
168 | 168 | // create threads |
169 | 169 | $threads = array(); |
170 | 170 | |
171 | 171 | //fork processes |
172 | 172 | for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_addresses; $i++) { |
173 | - //only if index exists! |
|
174 | - if(isset($addresses[$z])) { |
|
175 | - //start new thread |
|
176 | - $threads[$z] = new Thread( 'ping_address' ); |
|
177 | - $threads[$z]->start( $Subnets->transform_to_dotted($addresses[$z]['ip_addr']) ); |
|
178 | - $z++; //next index |
|
179 | - } |
|
173 | + //only if index exists! |
|
174 | + if(isset($addresses[$z])) { |
|
175 | + //start new thread |
|
176 | + $threads[$z] = new Thread( 'ping_address' ); |
|
177 | + $threads[$z]->start( $Subnets->transform_to_dotted($addresses[$z]['ip_addr']) ); |
|
178 | + $z++; //next index |
|
179 | + } |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // wait for all the threads to finish |
183 | 183 | while( !empty( $threads ) ) { |
184 | 184 | foreach( $threads as $index => $thread ) { |
185 | 185 | if( ! $thread->isAlive() ) { |
186 | - //unset dead hosts |
|
187 | - if($thread->getExitCode() != 0) { |
|
188 | - unset($addresses[$index]); |
|
189 | - } |
|
186 | + //unset dead hosts |
|
187 | + if($thread->getExitCode() != 0) { |
|
188 | + unset($addresses[$index]); |
|
189 | + } |
|
190 | 190 | //remove thread |
191 | 191 | unset( $threads[$index]); |
192 | 192 | } |
193 | 193 | } |
194 | 194 | usleep(200000); |
195 | 195 | } |
196 | - } |
|
197 | - |
|
198 | - //ok, we have all available addresses, rekey them |
|
199 | - foreach($addresses as $a) { |
|
200 | - $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted($a['ip_addr']); |
|
201 | - } |
|
202 | - //add to scan_subnets as result |
|
203 | - foreach($scan_subnets as $sk=>$s) { |
|
204 | - if(isset($add_tmp[$s->id])) { |
|
205 | - $scan_subnets[$sk]->discovered = $add_tmp[$s->id]; |
|
206 | - } |
|
207 | - } |
|
196 | + } |
|
197 | + |
|
198 | + //ok, we have all available addresses, rekey them |
|
199 | + foreach($addresses as $a) { |
|
200 | + $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted($a['ip_addr']); |
|
201 | + } |
|
202 | + //add to scan_subnets as result |
|
203 | + foreach($scan_subnets as $sk=>$s) { |
|
204 | + if(isset($add_tmp[$s->id])) { |
|
205 | + $scan_subnets[$sk]->discovered = $add_tmp[$s->id]; |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -226,31 +226,31 @@ discard block |
||
226 | 226 | $discovered = 0; //for mailing |
227 | 227 | |
228 | 228 | foreach($scan_subnets as $s) { |
229 | - if(sizeof(@$s->discovered)>0) { |
|
230 | - foreach($s->discovered as $ip) { |
|
231 | - // fetch subnet |
|
232 | - $subnet = $Subnets->fetch_subnet ("id", $s->id); |
|
233 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
234 | - // try to resolve hostname |
|
235 | - $hostname = $DNS->resolve_address ($ip, false, true, $nsid); |
|
236 | - |
|
237 | - //set update query |
|
238 | - $values = array("subnetId"=>$s->id, |
|
239 | - "ip_addr"=>$Subnets->transform_address($ip, "decimal"), |
|
240 | - "dns_name"=>$hostname['name'], |
|
241 | - "description"=>"-- autodiscovered --", |
|
242 | - "note"=>"This host was autodiscovered on ".$nowdate, |
|
243 | - "lastSeen"=>$nowdate, |
|
244 | - "state"=>"2", |
|
245 | - "action"=>"add" |
|
246 | - ); |
|
247 | - //insert |
|
248 | - $Addresses->modify_address($values); |
|
249 | - |
|
250 | - //set discovered |
|
251 | - $discovered++; |
|
252 | - } |
|
253 | - } |
|
229 | + if(sizeof(@$s->discovered)>0) { |
|
230 | + foreach($s->discovered as $ip) { |
|
231 | + // fetch subnet |
|
232 | + $subnet = $Subnets->fetch_subnet ("id", $s->id); |
|
233 | + $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
234 | + // try to resolve hostname |
|
235 | + $hostname = $DNS->resolve_address ($ip, false, true, $nsid); |
|
236 | + |
|
237 | + //set update query |
|
238 | + $values = array("subnetId"=>$s->id, |
|
239 | + "ip_addr"=>$Subnets->transform_address($ip, "decimal"), |
|
240 | + "dns_name"=>$hostname['name'], |
|
241 | + "description"=>"-- autodiscovered --", |
|
242 | + "note"=>"This host was autodiscovered on ".$nowdate, |
|
243 | + "lastSeen"=>$nowdate, |
|
244 | + "state"=>"2", |
|
245 | + "action"=>"add" |
|
246 | + ); |
|
247 | + //insert |
|
248 | + $Addresses->modify_address($values); |
|
249 | + |
|
250 | + //set discovered |
|
251 | + $discovered++; |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | # update scan time |
@@ -261,84 +261,84 @@ discard block |
||
261 | 261 | # send mail |
262 | 262 | if($discovered>0 && $send_mail) { |
263 | 263 | |
264 | - # check for recipients |
|
265 | - foreach($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | - if($admin->mailNotify=="Yes") { |
|
267 | - $recepients[] = array("name"=>$admin->real_name, "email"=>$admin->email); |
|
268 | - } |
|
269 | - } |
|
270 | - # none? |
|
271 | - if(!isset($recepients)) { die(); } |
|
272 | - |
|
273 | - # fetch mailer settings |
|
274 | - $mail_settings = $Admin->fetch_object("settingsMail", "id", 1); |
|
275 | - # fake user object, needed for create_link |
|
276 | - $User = new StdClass(); |
|
277 | - @$User->settings->prettyLinks = $Scan->settings->prettyLinks; |
|
278 | - |
|
279 | - # initialize mailer |
|
280 | - $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings); |
|
281 | - $phpipam_mail->initialize_mailer(); |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - // set subject |
|
286 | - $subject = "phpIPAM new addresses detected ".date("Y-m-d H:i:s"); |
|
287 | - |
|
288 | - //html |
|
289 | - $content[] = "<h3>phpIPAM found $discovered new hosts</h3>"; |
|
290 | - $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid gray;'>"; |
|
291 | - $content[] = "<tr>"; |
|
292 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>IP</th>"; |
|
293 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Subnet</th>"; |
|
294 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Section</th>"; |
|
295 | - $content[] = "</tr>"; |
|
296 | - //plain |
|
297 | - $content_plain[] = "phpIPAM found $discovered new hosts\r\n------------------------------"; |
|
298 | - //Changes |
|
299 | - foreach($scan_subnets as $s) { |
|
300 | - if(sizeof(@$s->discovered)>0) { |
|
301 | - foreach($s->discovered as $ip) { |
|
302 | - //set subnet |
|
303 | - $subnet = $Subnets->fetch_subnet(null, $s->id); |
|
304 | - //set section |
|
305 | - $section = $Admin->fetch_object("sections", "id", $s->sectionId); |
|
306 | - |
|
307 | - $content[] = "<tr>"; |
|
308 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'>$ip</td>"; |
|
309 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id,$subnet->id)."'>".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id)."'>$section->name $section->description</a></td>"; |
|
311 | - $content[] = "</tr>"; |
|
312 | - |
|
313 | - //plain content |
|
314 | - $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask.")"; |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - $content[] = "</table>"; |
|
319 | - |
|
320 | - |
|
321 | - # set content |
|
322 | - $content = $phpipam_mail->generate_message (implode("\r\n", $content)); |
|
323 | - $content_plain = implode("\r\n",$content_plain); |
|
324 | - |
|
325 | - # try to send |
|
326 | - try { |
|
327 | - $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
328 | - //add all admins to CC |
|
329 | - foreach($recepients as $admin) { |
|
330 | - $phpipam_mail->Php_mailer->addAddress(addslashes($admin['email']), addslashes($admin['name'])); |
|
331 | - } |
|
332 | - $phpipam_mail->Php_mailer->Subject = $subject; |
|
333 | - $phpipam_mail->Php_mailer->msgHTML($content); |
|
334 | - $phpipam_mail->Php_mailer->AltBody = $content_plain; |
|
335 | - //send |
|
336 | - $phpipam_mail->Php_mailer->send(); |
|
337 | - } catch (phpmailerException $e) { |
|
338 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
339 | - } catch (Exception $e) { |
|
340 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
341 | - } |
|
264 | + # check for recipients |
|
265 | + foreach($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | + if($admin->mailNotify=="Yes") { |
|
267 | + $recepients[] = array("name"=>$admin->real_name, "email"=>$admin->email); |
|
268 | + } |
|
269 | + } |
|
270 | + # none? |
|
271 | + if(!isset($recepients)) { die(); } |
|
272 | + |
|
273 | + # fetch mailer settings |
|
274 | + $mail_settings = $Admin->fetch_object("settingsMail", "id", 1); |
|
275 | + # fake user object, needed for create_link |
|
276 | + $User = new StdClass(); |
|
277 | + @$User->settings->prettyLinks = $Scan->settings->prettyLinks; |
|
278 | + |
|
279 | + # initialize mailer |
|
280 | + $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings); |
|
281 | + $phpipam_mail->initialize_mailer(); |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + // set subject |
|
286 | + $subject = "phpIPAM new addresses detected ".date("Y-m-d H:i:s"); |
|
287 | + |
|
288 | + //html |
|
289 | + $content[] = "<h3>phpIPAM found $discovered new hosts</h3>"; |
|
290 | + $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid gray;'>"; |
|
291 | + $content[] = "<tr>"; |
|
292 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>IP</th>"; |
|
293 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Subnet</th>"; |
|
294 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Section</th>"; |
|
295 | + $content[] = "</tr>"; |
|
296 | + //plain |
|
297 | + $content_plain[] = "phpIPAM found $discovered new hosts\r\n------------------------------"; |
|
298 | + //Changes |
|
299 | + foreach($scan_subnets as $s) { |
|
300 | + if(sizeof(@$s->discovered)>0) { |
|
301 | + foreach($s->discovered as $ip) { |
|
302 | + //set subnet |
|
303 | + $subnet = $Subnets->fetch_subnet(null, $s->id); |
|
304 | + //set section |
|
305 | + $section = $Admin->fetch_object("sections", "id", $s->sectionId); |
|
306 | + |
|
307 | + $content[] = "<tr>"; |
|
308 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'>$ip</td>"; |
|
309 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id,$subnet->id)."'>".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id)."'>$section->name $section->description</a></td>"; |
|
311 | + $content[] = "</tr>"; |
|
312 | + |
|
313 | + //plain content |
|
314 | + $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask.")"; |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + $content[] = "</table>"; |
|
319 | + |
|
320 | + |
|
321 | + # set content |
|
322 | + $content = $phpipam_mail->generate_message (implode("\r\n", $content)); |
|
323 | + $content_plain = implode("\r\n",$content_plain); |
|
324 | + |
|
325 | + # try to send |
|
326 | + try { |
|
327 | + $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
328 | + //add all admins to CC |
|
329 | + foreach($recepients as $admin) { |
|
330 | + $phpipam_mail->Php_mailer->addAddress(addslashes($admin['email']), addslashes($admin['name'])); |
|
331 | + } |
|
332 | + $phpipam_mail->Php_mailer->Subject = $subject; |
|
333 | + $phpipam_mail->Php_mailer->msgHTML($content); |
|
334 | + $phpipam_mail->Php_mailer->AltBody = $content_plain; |
|
335 | + //send |
|
336 | + $phpipam_mail->Php_mailer->send(); |
|
337 | + } catch (phpmailerException $e) { |
|
338 | + $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
339 | + } catch (Exception $e) { |
|
340 | + $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
341 | + } |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | ?> |
@@ -24,60 +24,60 @@ discard block |
||
24 | 24 | |
25 | 25 | |
26 | 26 | # include required scripts |
27 | -require( dirname(__FILE__) . '/../functions.php' ); |
|
28 | -require( dirname(__FILE__) . '/../../functions/classes/class.Thread.php'); |
|
27 | +require(dirname (__FILE__).'/../functions.php'); |
|
28 | +require(dirname (__FILE__).'/../../functions/classes/class.Thread.php'); |
|
29 | 29 | |
30 | 30 | # initialize objects |
31 | 31 | $Database = new Database_PDO; |
32 | -$Subnets = new Subnets ($Database); |
|
32 | +$Subnets = new Subnets ($Database); |
|
33 | 33 | $Addresses = new Addresses ($Database); |
34 | -$Tools = new Tools ($Database); |
|
35 | -$Scan = new Scan ($Database); |
|
36 | -$DNS = new DNS ($Database); |
|
37 | -$Result = new Result(); |
|
34 | +$Tools = new Tools ($Database); |
|
35 | +$Scan = new Scan ($Database); |
|
36 | +$DNS = new DNS ($Database); |
|
37 | +$Result = new Result (); |
|
38 | 38 | |
39 | 39 | // set exit flag to true |
40 | -$Scan->ping_set_exit(true); |
|
40 | +$Scan->ping_set_exit (true); |
|
41 | 41 | // set debugging |
42 | -$Scan->reset_debugging(false); |
|
42 | +$Scan->reset_debugging (false); |
|
43 | 43 | // change scan type? |
44 | 44 | //$Scan->reset_scan_method ("pear"); |
45 | 45 | // set ping statuses |
46 | -$statuses = explode(";", $Scan->settings->pingStatus); |
|
46 | +$statuses = explode (";", $Scan->settings->pingStatus); |
|
47 | 47 | // set mail override flag |
48 | 48 | $send_mail = true; |
49 | 49 | |
50 | 50 | // set now for whole script |
51 | -$now = time(); |
|
51 | +$now = time (); |
|
52 | 52 | $nowdate = date ("Y-m-d H:i:s"); |
53 | 53 | |
54 | 54 | |
55 | 55 | // response for mailing |
56 | -$address_change = array(); // Array with differences, can be used to email to admins |
|
56 | +$address_change = array (); // Array with differences, can be used to email to admins |
|
57 | 57 | |
58 | 58 | |
59 | 59 | // script can only be run from cli |
60 | -if(php_sapi_name()!="cli") { die("This script can only be run from cli!"); } |
|
60 | +if (php_sapi_name () != "cli") { die("This script can only be run from cli!"); } |
|
61 | 61 | // test to see if threading is available |
62 | -if(!Thread::available()) { die("Threading is required for scanning subnets. Please recompile PHP with pcntl extension"); } |
|
62 | +if (!Thread::available ()) { die("Threading is required for scanning subnets. Please recompile PHP with pcntl extension"); } |
|
63 | 63 | // verify ping path |
64 | -if ($Scan->icmp_type=="ping") { |
|
65 | -if(!file_exists($Scan->settings->scanPingPath)) { die("Invalid ping path!"); } |
|
64 | +if ($Scan->icmp_type == "ping") { |
|
65 | +if (!file_exists ($Scan->settings->scanPingPath)) { die("Invalid ping path!"); } |
|
66 | 66 | } |
67 | 67 | // verify fping path |
68 | -if ($Scan->icmp_type=="fping") { |
|
69 | -if(!file_exists($Scan->settings->scanFPingPath)){ die("Invalid fping path!"); } |
|
68 | +if ($Scan->icmp_type == "fping") { |
|
69 | +if (!file_exists ($Scan->settings->scanFPingPath)) { die("Invalid fping path!"); } |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
73 | 73 | //first fetch all subnets to be scanned |
74 | 74 | $scan_subnets = $Subnets->fetch_all_subnets_for_discoveryCheck (1); |
75 | 75 | //set addresses |
76 | -if ($scan_subnets!==false) { |
|
76 | +if ($scan_subnets !== false) { |
|
77 | 77 | // initial array |
78 | - $addresses_tmp = array(); |
|
78 | + $addresses_tmp = array (); |
|
79 | 79 | // loop |
80 | - foreach($scan_subnets as $s) { |
|
80 | + foreach ($scan_subnets as $s) { |
|
81 | 81 | // if subnet has slaves dont check it |
82 | 82 | if ($Subnets->has_slaves ($s->id) === false) { |
83 | 83 | $addresses_tmp[$s->id] = $Scan-> prepare_addresses_to_scan ("discovery", $s->id, false); |
@@ -85,123 +85,123 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | //reindex |
88 | - if(sizeof($addresses_tmp)>0) { |
|
89 | - foreach($addresses_tmp as $s_id=>$a) { |
|
90 | - foreach($a as $ip) { |
|
91 | - $addresses[] = array("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
88 | + if (sizeof ($addresses_tmp) > 0) { |
|
89 | + foreach ($addresses_tmp as $s_id=>$a) { |
|
90 | + foreach ($a as $ip) { |
|
91 | + $addresses[] = array ("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | |
98 | -if($Scan->debugging) { print_r($scan_subnets); } |
|
99 | -if($scan_subnets===false) { die("No subnets are marked for new hosts checking"); } |
|
98 | +if ($Scan->debugging) { print_r ($scan_subnets); } |
|
99 | +if ($scan_subnets === false) { die("No subnets are marked for new hosts checking"); } |
|
100 | 100 | |
101 | 101 | |
102 | 102 | //scan |
103 | -if($Scan->debugging) { print "Using $Scan->icmp_type\n--------------------\n\n"; } |
|
103 | +if ($Scan->debugging) { print "Using $Scan->icmp_type\n--------------------\n\n"; } |
|
104 | 104 | |
105 | 105 | |
106 | -$z = 0; //addresses array index |
|
106 | +$z = 0; //addresses array index |
|
107 | 107 | |
108 | -$size_subnets = max(array_keys($scan_subnets)); |
|
109 | -$size_addresses = max(array_keys($addresses)); |
|
108 | +$size_subnets = max (array_keys ($scan_subnets)); |
|
109 | +$size_addresses = max (array_keys ($addresses)); |
|
110 | 110 | |
111 | 111 | //different scan for fping |
112 | -if($Scan->icmp_type=="fping") { |
|
112 | +if ($Scan->icmp_type == "fping") { |
|
113 | 113 | //run per MAX_THREADS |
114 | - for ($m=0; $m<=$size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
114 | + for ($m = 0; $m <= $size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
115 | 115 | // create threads |
116 | - $threads = array(); |
|
116 | + $threads = array (); |
|
117 | 117 | //fork processes |
118 | 118 | for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_subnets; $i++) { |
119 | 119 | //only if index exists! |
120 | - if(isset($scan_subnets[$z])) { |
|
120 | + if (isset($scan_subnets[$z])) { |
|
121 | 121 | //start new thread |
122 | - $threads[$z] = new Thread( 'fping_subnet' ); |
|
123 | - $threads[$z]->start_fping( $Subnets->transform_to_dotted($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask ); |
|
124 | - $z++; //next index |
|
122 | + $threads[$z] = new Thread ('fping_subnet'); |
|
123 | + $threads[$z]->start_fping ($Subnets->transform_to_dotted ($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask); |
|
124 | + $z++; //next index |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | // wait for all the threads to finish |
128 | - while( !empty( $threads ) ) { |
|
129 | - foreach($threads as $index => $thread) { |
|
130 | - $child_pipe = "/tmp/pipe_".$thread->getPid(); |
|
128 | + while (!empty($threads)) { |
|
129 | + foreach ($threads as $index => $thread) { |
|
130 | + $child_pipe = "/tmp/pipe_".$thread->getPid (); |
|
131 | 131 | |
132 | - if (file_exists($child_pipe)) { |
|
133 | - $file_descriptor = fopen( $child_pipe, "r"); |
|
132 | + if (file_exists ($child_pipe)) { |
|
133 | + $file_descriptor = fopen ($child_pipe, "r"); |
|
134 | 134 | $child_response = ""; |
135 | - while (!feof($file_descriptor)) { |
|
136 | - $child_response .= fread($file_descriptor, 8192); |
|
135 | + while (!feof ($file_descriptor)) { |
|
136 | + $child_response .= fread ($file_descriptor, 8192); |
|
137 | 137 | } |
138 | 138 | //we have the child data in the parent, but serialized: |
139 | - $child_response = unserialize( $child_response ); |
|
139 | + $child_response = unserialize ($child_response); |
|
140 | 140 | //store |
141 | 141 | $scan_subnets[$index]->discovered = $child_response; |
142 | 142 | //now, child is dead, and parent close the pipe |
143 | - unlink( $child_pipe ); |
|
143 | + unlink ($child_pipe); |
|
144 | 144 | unset($threads[$index]); |
145 | 145 | } |
146 | 146 | } |
147 | - usleep(200000); |
|
147 | + usleep (200000); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | 151 | //fping finds all subnet addresses, we must remove existing ones ! |
152 | - foreach($scan_subnets as $sk=>$s) { |
|
153 | - if(isset($s->discovered)) { |
|
154 | - foreach($s->discovered as $rk=>$result) { |
|
155 | - if(!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { |
|
152 | + foreach ($scan_subnets as $sk=>$s) { |
|
153 | + if (isset($s->discovered)) { |
|
154 | + foreach ($s->discovered as $rk=>$result) { |
|
155 | + if (!in_array ($Subnets->transform_to_decimal ($result), $addresses_tmp[$s->id])) { |
|
156 | 156 | unset($scan_subnets[$sk]->discovered[$rk]); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | //rekey |
160 | - $scan_subnets[$sk]->discovered = array_values($scan_subnets[$sk]->discovered); |
|
160 | + $scan_subnets[$sk]->discovered = array_values ($scan_subnets[$sk]->discovered); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | 164 | //ping, pear |
165 | 165 | else { |
166 | 166 | //run per MAX_THREADS |
167 | - for ($m=0; $m<=$size_addresses; $m += $Scan->settings->scanMaxThreads) { |
|
167 | + for ($m = 0; $m <= $size_addresses; $m += $Scan->settings->scanMaxThreads) { |
|
168 | 168 | // create threads |
169 | - $threads = array(); |
|
169 | + $threads = array (); |
|
170 | 170 | |
171 | 171 | //fork processes |
172 | 172 | for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_addresses; $i++) { |
173 | 173 | //only if index exists! |
174 | - if(isset($addresses[$z])) { |
|
174 | + if (isset($addresses[$z])) { |
|
175 | 175 | //start new thread |
176 | - $threads[$z] = new Thread( 'ping_address' ); |
|
177 | - $threads[$z]->start( $Subnets->transform_to_dotted($addresses[$z]['ip_addr']) ); |
|
178 | - $z++; //next index |
|
176 | + $threads[$z] = new Thread ('ping_address'); |
|
177 | + $threads[$z]->start ($Subnets->transform_to_dotted ($addresses[$z]['ip_addr'])); |
|
178 | + $z++; //next index |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | // wait for all the threads to finish |
183 | - while( !empty( $threads ) ) { |
|
184 | - foreach( $threads as $index => $thread ) { |
|
185 | - if( ! $thread->isAlive() ) { |
|
183 | + while (!empty($threads)) { |
|
184 | + foreach ($threads as $index => $thread) { |
|
185 | + if (!$thread->isAlive ()) { |
|
186 | 186 | //unset dead hosts |
187 | - if($thread->getExitCode() != 0) { |
|
187 | + if ($thread->getExitCode () != 0) { |
|
188 | 188 | unset($addresses[$index]); |
189 | 189 | } |
190 | 190 | //remove thread |
191 | - unset( $threads[$index]); |
|
191 | + unset($threads[$index]); |
|
192 | 192 | } |
193 | 193 | } |
194 | - usleep(200000); |
|
194 | + usleep (200000); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | 198 | //ok, we have all available addresses, rekey them |
199 | - foreach($addresses as $a) { |
|
200 | - $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted($a['ip_addr']); |
|
199 | + foreach ($addresses as $a) { |
|
200 | + $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted ($a['ip_addr']); |
|
201 | 201 | } |
202 | 202 | //add to scan_subnets as result |
203 | - foreach($scan_subnets as $sk=>$s) { |
|
204 | - if(isset($add_tmp[$s->id])) { |
|
203 | + foreach ($scan_subnets as $sk=>$s) { |
|
204 | + if (isset($add_tmp[$s->id])) { |
|
205 | 205 | $scan_subnets[$sk]->discovered = $add_tmp[$s->id]; |
206 | 206 | } |
207 | 207 | } |
@@ -209,34 +209,34 @@ discard block |
||
209 | 209 | |
210 | 210 | |
211 | 211 | # print change |
212 | -if($Scan->debugging) { "\nDiscovered addresses:\n----------\n"; print_r($scan_subnets); } |
|
212 | +if ($Scan->debugging) { "\nDiscovered addresses:\n----------\n"; print_r ($scan_subnets); } |
|
213 | 213 | |
214 | 214 | |
215 | 215 | |
216 | 216 | # reinitialize objects |
217 | 217 | $Database = new Database_PDO; |
218 | -$Admin = new Admin ($Database, false); |
|
218 | +$Admin = new Admin ($Database, false); |
|
219 | 219 | $Addresses = new Addresses ($Database); |
220 | 220 | $Subnets = new Subnets ($Database); |
221 | -$DNS = new DNS ($Database); |
|
222 | -$Scan = new Scan ($Database); |
|
223 | -$Result = new Result(); |
|
221 | +$DNS = new DNS ($Database); |
|
222 | +$Scan = new Scan ($Database); |
|
223 | +$Result = new Result (); |
|
224 | 224 | |
225 | 225 | # insert to database |
226 | -$discovered = 0; //for mailing |
|
226 | +$discovered = 0; //for mailing |
|
227 | 227 | |
228 | -foreach($scan_subnets as $s) { |
|
229 | - if(sizeof(@$s->discovered)>0) { |
|
230 | - foreach($s->discovered as $ip) { |
|
228 | +foreach ($scan_subnets as $s) { |
|
229 | + if (sizeof (@$s->discovered) > 0) { |
|
230 | + foreach ($s->discovered as $ip) { |
|
231 | 231 | // fetch subnet |
232 | 232 | $subnet = $Subnets->fetch_subnet ("id", $s->id); |
233 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
233 | + $nsid = $subnet === false ? false : $subnet->nameserverId; |
|
234 | 234 | // try to resolve hostname |
235 | 235 | $hostname = $DNS->resolve_address ($ip, false, true, $nsid); |
236 | 236 | |
237 | 237 | //set update query |
238 | - $values = array("subnetId"=>$s->id, |
|
239 | - "ip_addr"=>$Subnets->transform_address($ip, "decimal"), |
|
238 | + $values = array ("subnetId"=>$s->id, |
|
239 | + "ip_addr"=>$Subnets->transform_address ($ip, "decimal"), |
|
240 | 240 | "dns_name"=>$hostname['name'], |
241 | 241 | "description"=>"-- autodiscovered --", |
242 | 242 | "note"=>"This host was autodiscovered on ".$nowdate, |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | "action"=>"add" |
246 | 246 | ); |
247 | 247 | //insert |
248 | - $Addresses->modify_address($values); |
|
248 | + $Addresses->modify_address ($values); |
|
249 | 249 | |
250 | 250 | //set discovered |
251 | 251 | $discovered++; |
@@ -259,31 +259,31 @@ discard block |
||
259 | 259 | |
260 | 260 | |
261 | 261 | # send mail |
262 | -if($discovered>0 && $send_mail) { |
|
262 | +if ($discovered > 0 && $send_mail) { |
|
263 | 263 | |
264 | 264 | # check for recipients |
265 | - foreach($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | - if($admin->mailNotify=="Yes") { |
|
267 | - $recepients[] = array("name"=>$admin->real_name, "email"=>$admin->email); |
|
265 | + foreach ($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | + if ($admin->mailNotify == "Yes") { |
|
267 | + $recepients[] = array ("name"=>$admin->real_name, "email"=>$admin->email); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | # none? |
271 | - if(!isset($recepients)) { die(); } |
|
271 | + if (!isset($recepients)) { die(); } |
|
272 | 272 | |
273 | 273 | # fetch mailer settings |
274 | - $mail_settings = $Admin->fetch_object("settingsMail", "id", 1); |
|
274 | + $mail_settings = $Admin->fetch_object ("settingsMail", "id", 1); |
|
275 | 275 | # fake user object, needed for create_link |
276 | - $User = new StdClass(); |
|
276 | + $User = new StdClass (); |
|
277 | 277 | @$User->settings->prettyLinks = $Scan->settings->prettyLinks; |
278 | 278 | |
279 | 279 | # initialize mailer |
280 | - $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings); |
|
281 | - $phpipam_mail->initialize_mailer(); |
|
280 | + $phpipam_mail = new phpipam_mail ($Scan->settings, $mail_settings); |
|
281 | + $phpipam_mail->initialize_mailer (); |
|
282 | 282 | |
283 | 283 | |
284 | 284 | |
285 | 285 | // set subject |
286 | - $subject = "phpIPAM new addresses detected ".date("Y-m-d H:i:s"); |
|
286 | + $subject = "phpIPAM new addresses detected ".date ("Y-m-d H:i:s"); |
|
287 | 287 | |
288 | 288 | //html |
289 | 289 | $content[] = "<h3>phpIPAM found $discovered new hosts</h3>"; |
@@ -296,22 +296,22 @@ discard block |
||
296 | 296 | //plain |
297 | 297 | $content_plain[] = "phpIPAM found $discovered new hosts\r\n------------------------------"; |
298 | 298 | //Changes |
299 | - foreach($scan_subnets as $s) { |
|
300 | - if(sizeof(@$s->discovered)>0) { |
|
301 | - foreach($s->discovered as $ip) { |
|
299 | + foreach ($scan_subnets as $s) { |
|
300 | + if (sizeof (@$s->discovered) > 0) { |
|
301 | + foreach ($s->discovered as $ip) { |
|
302 | 302 | //set subnet |
303 | - $subnet = $Subnets->fetch_subnet(null, $s->id); |
|
303 | + $subnet = $Subnets->fetch_subnet (null, $s->id); |
|
304 | 304 | //set section |
305 | - $section = $Admin->fetch_object("sections", "id", $s->sectionId); |
|
305 | + $section = $Admin->fetch_object ("sections", "id", $s->sectionId); |
|
306 | 306 | |
307 | 307 | $content[] = "<tr>"; |
308 | 308 | $content[] = " <td style='padding:3px 8px;border:1px solid silver;'>$ip</td>"; |
309 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id,$subnet->id)."'>".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id)."'>$section->name $section->description</a></td>"; |
|
309 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim ($Scan->settings->siteURL, "/")."".create_link ("subnets", $section->id, $subnet->id)."'>".$Subnets->transform_to_dotted ($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim ($Scan->settings->siteURL, "/")."".create_link ("subnets", $section->id)."'>$section->name $section->description</a></td>"; |
|
311 | 311 | $content[] = "</tr>"; |
312 | 312 | |
313 | 313 | //plain content |
314 | - $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask.")"; |
|
314 | + $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted ($subnet->subnet)."/".$subnet->mask.")"; |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | } |
@@ -319,25 +319,25 @@ discard block |
||
319 | 319 | |
320 | 320 | |
321 | 321 | # set content |
322 | - $content = $phpipam_mail->generate_message (implode("\r\n", $content)); |
|
323 | - $content_plain = implode("\r\n",$content_plain); |
|
322 | + $content = $phpipam_mail->generate_message (implode ("\r\n", $content)); |
|
323 | + $content_plain = implode ("\r\n", $content_plain); |
|
324 | 324 | |
325 | 325 | # try to send |
326 | 326 | try { |
327 | - $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
327 | + $phpipam_mail->Php_mailer->setFrom ($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
328 | 328 | //add all admins to CC |
329 | - foreach($recepients as $admin) { |
|
330 | - $phpipam_mail->Php_mailer->addAddress(addslashes($admin['email']), addslashes($admin['name'])); |
|
329 | + foreach ($recepients as $admin) { |
|
330 | + $phpipam_mail->Php_mailer->addAddress (addslashes ($admin['email']), addslashes ($admin['name'])); |
|
331 | 331 | } |
332 | 332 | $phpipam_mail->Php_mailer->Subject = $subject; |
333 | - $phpipam_mail->Php_mailer->msgHTML($content); |
|
333 | + $phpipam_mail->Php_mailer->msgHTML ($content); |
|
334 | 334 | $phpipam_mail->Php_mailer->AltBody = $content_plain; |
335 | 335 | //send |
336 | - $phpipam_mail->Php_mailer->send(); |
|
336 | + $phpipam_mail->Php_mailer->send (); |
|
337 | 337 | } catch (phpmailerException $e) { |
338 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
338 | + $Result->show_cli ("Mailer Error: ".$e->errorMessage (), true); |
|
339 | 339 | } catch (Exception $e) { |
340 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
340 | + $Result->show_cli ("Mailer Error: ".$e->errorMessage (), true); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 |
@@ -70,9 +70,9 @@ |
||
70 | 70 | elseif ($proxy_enabled == true && proxy_use_auth == true) { |
71 | 71 | stream_context_set_default( |
72 | 72 | array('http' => array( |
73 | - 'proxy' => "tcp://$proxy_server:$proxy_port", |
|
74 | - 'request_fulluri' => true, |
|
75 | - 'header' => "Proxy-Authorization: Basic $proxy_auth" |
|
73 | + 'proxy' => "tcp://$proxy_server:$proxy_port", |
|
74 | + 'request_fulluri' => true, |
|
75 | + 'header' => "Proxy-Authorization: Basic $proxy_auth" |
|
76 | 76 | ))); |
77 | 77 | } |
78 | 78 |
@@ -47,14 +47,16 @@ |
||
47 | 47 | * Also change |
48 | 48 | * RewriteBase / in .htaccess |
49 | 49 | ******************************/ |
50 | -if(!defined('BASE')) |
|
51 | -define('BASE', "/"); |
|
50 | +if(!defined('BASE')) { |
|
51 | + define('BASE', "/"); |
|
52 | +} |
|
52 | 53 | |
53 | 54 | /** |
54 | 55 | * Multicast unique mac requirement - section or vlan |
55 | 56 | */ |
56 | -if(!defined('MCUNIQUE')) |
|
57 | -define('MCUNIQUE', "section"); |
|
57 | +if(!defined('MCUNIQUE')) { |
|
58 | + define('MCUNIQUE', "section"); |
|
59 | +} |
|
58 | 60 | |
59 | 61 | |
60 | 62 | /* proxy connection details |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | |
19 | 19 | php 5.3.7 required |
20 | 20 | */ |
21 | -$db['ssl'] = false; # true/false, enable or disable SSL as a whole |
|
22 | -$db['ssl_key'] = "/path/to/cert.key"; # path to an SSL key file. Only makes sense combined with ssl_cert |
|
23 | -$db['ssl_cert'] = "/path/to/cert.crt"; # path to an SSL certificate file. Only makes sense combined with ssl_key |
|
24 | -$db['ssl_ca'] = "/path/to/ca.crt"; # path to a file containing SSL CA certs |
|
25 | -$db['ssl_capath'] = "/path/to/ca_certs"; # path to a directory containing CA certs |
|
21 | +$db['ssl'] = false; # true/false, enable or disable SSL as a whole |
|
22 | +$db['ssl_key'] = "/path/to/cert.key"; # path to an SSL key file. Only makes sense combined with ssl_cert |
|
23 | +$db['ssl_cert'] = "/path/to/cert.crt"; # path to an SSL certificate file. Only makes sense combined with ssl_key |
|
24 | +$db['ssl_ca'] = "/path/to/ca.crt"; # path to a file containing SSL CA certs |
|
25 | +$db['ssl_capath'] = "/path/to/ca_certs"; # path to a directory containing CA certs |
|
26 | 26 | $db['ssl_cipher'] = "DHE-RSA-AES256-SHA:AES128-SHA"; # one or more SSL Ciphers |
27 | 27 | |
28 | 28 | /** |
@@ -47,36 +47,36 @@ discard block |
||
47 | 47 | * Also change |
48 | 48 | * RewriteBase / in .htaccess |
49 | 49 | ******************************/ |
50 | -if(!defined('BASE')) |
|
51 | -define('BASE', "/"); |
|
50 | +if (!defined ('BASE')) |
|
51 | +define ('BASE', "/"); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Multicast unique mac requirement - section or vlan |
55 | 55 | */ |
56 | -if(!defined('MCUNIQUE')) |
|
57 | -define('MCUNIQUE', "section"); |
|
56 | +if (!defined ('MCUNIQUE')) |
|
57 | +define ('MCUNIQUE', "section"); |
|
58 | 58 | |
59 | 59 | |
60 | 60 | /* proxy connection details |
61 | 61 | ******************************/ |
62 | -$proxy_enabled = false; # Enable/Disable usage of the Proxy server |
|
63 | -$proxy_server = "myproxy.something.com"; # Proxy server FQDN or IP |
|
64 | -$proxy_port = "8080"; # Proxy server port |
|
65 | -$proxy_user = "USERNAME"; # Proxy Username |
|
66 | -$proxy_pass = "PASSWORD"; # Proxy Password |
|
67 | -$proxy_use_auth = false; # Enable/Disable Proxy authentication |
|
62 | +$proxy_enabled = false; # Enable/Disable usage of the Proxy server |
|
63 | +$proxy_server = "myproxy.something.com"; # Proxy server FQDN or IP |
|
64 | +$proxy_port = "8080"; # Proxy server port |
|
65 | +$proxy_user = "USERNAME"; # Proxy Username |
|
66 | +$proxy_pass = "PASSWORD"; # Proxy Password |
|
67 | +$proxy_use_auth = false; # Enable/Disable Proxy authentication |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * proxy to use for every internet access like update check |
71 | 71 | */ |
72 | -$proxy_auth = base64_encode("$proxy_user:$proxy_pass"); |
|
72 | +$proxy_auth = base64_encode ("$proxy_user:$proxy_pass"); |
|
73 | 73 | |
74 | 74 | if ($proxy_enabled == true && $proxy_use_auth == false) { |
75 | - stream_context_set_default(array('http' => array('proxy'=>'tcp://'.$proxy_server.':'.$proxy_port))); |
|
75 | + stream_context_set_default (array ('http' => array ('proxy'=>'tcp://'.$proxy_server.':'.$proxy_port))); |
|
76 | 76 | } |
77 | 77 | elseif ($proxy_enabled == true && $proxy_use_auth == true) { |
78 | - stream_context_set_default( |
|
79 | - array('http' => array( |
|
78 | + stream_context_set_default ( |
|
79 | + array ('http' => array ( |
|
80 | 80 | 'proxy' => "tcp://$proxy_server:$proxy_port", |
81 | 81 | 'request_fulluri' => true, |
82 | 82 | 'header' => "Proxy-Authorization: Basic $proxy_auth" |