@@ -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 |
@@ -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) { |
@@ -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 |
@@ -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) { |
@@ -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 |
@@ -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,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 |
@@ -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); |
@@ -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 |
@@ -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 | ?> |
@@ -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 |