@@ -114,16 +114,23 @@ public function __construct (Database_PDO $database, $settings = null) {
114114 $ this ->Database = $ database ;
115115 # initialize Result
116116 $ this ->Result = new Result ();
117+
117118 # fetch settings
118- $ this ->settings = is_null ($ this ->settings ) ? $ this ->get_settings () : (object ) $ this ->settings ;
119+ $ settings = is_null ($ this ->settings ) ? $ this ->get_settings () : (object ) $ this ->settings ;
120+ $ config = Config::ValueOf ('config ' );
121+
122+ $ this ->ping_type = $ config ['method ' ];
123+ $ this ->ping_path = ($ this ->ping_type == "ping " ) ? $ config ['pingpath ' ] : '' ;
124+ $ this ->fping_path = ($ this ->ping_type == "fping " ) ? $ config ['pingpath ' ] : '' ;
125+
119126 # set type
120- $ this ->reset_scan_method ($ this ->settings -> scanPingType );
127+ $ this ->reset_scan_method ($ this ->ping_type );
121128 # set OS type
122129 $ this ->set_os_type ();
123130 # set php exec
124131 $ this ->set_php_exec ();
125132 # Log object
126- $ this ->Log = new Logging ($ this ->Database , $ this -> settings );
133+ $ this ->Log = new Logging ($ this ->Database , $ settings );
127134
128135 if ($ errmsg = php_feature_missing (null , ['exec ' ]))
129136 $ this ->Result ->show ("danger " , $ errmsg , true );
@@ -268,17 +275,17 @@ public function ping_address ($address, $count=1, $timeout = 1) {
268275 * @return void
269276 */
270277 protected function ping_address_method_ping ($ address ) {
271- # verify ping path
272- $ this ->ping_verify_path ($ this ->settings ->scanPingPath );
273-
274278 # if ipv6 append 6
275- if ($ this ->identify_address ($ address )=="IPv6 " ) { $ this ->settings ->scanPingPath = $ this ->settings ->scanPingPath ."6 " ; }
279+ $ ping_path = ($ this ->identify_address ($ address )=="IPv6 " ) ? $ this ->ping_path ."6 " : $ this ->ping_path ;
280+
281+ # verify ping path
282+ $ this ->ping_verify_path ($ ping_path );
276283
277284 # set ping command based on OS type
278- if ($ this ->os_type == "FreeBSD " ) { $ cmd = $ this -> settings -> scanPingPath ." -c $ this ->icmp_count -W " .($ this ->icmp_timeout *1000 )." $ address 1>/dev/null 2>&1 " ; }
279- elseif ($ this ->os_type == "Linux " ) { $ cmd = $ this -> settings -> scanPingPath ." -c $ this ->icmp_count -W $ this ->icmp_timeout $ address 1>/dev/null 2>&1 " ; }
280- elseif ($ this ->os_type == "Windows " ) { $ cmd = $ this -> settings -> scanPingPath ." -n $ this ->icmp_count -w " .($ this ->icmp_timeout *1000 )." $ address " ; }
281- else { $ cmd = $ this -> settings -> scanPingPath ." -c $ this ->icmp_count -n $ address 1>/dev/null 2>&1 " ; }
285+ if ($ this ->os_type == "FreeBSD " ) { $ cmd = $ ping_path ." -c $ this ->icmp_count -W " .($ this ->icmp_timeout *1000 )." $ address 1>/dev/null 2>&1 " ; }
286+ elseif ($ this ->os_type == "Linux " ) { $ cmd = $ ping_path ." -c $ this ->icmp_count -W $ this ->icmp_timeout $ address 1>/dev/null 2>&1 " ; }
287+ elseif ($ this ->os_type == "Windows " ) { $ cmd = $ ping_path ." -n $ this ->icmp_count -w " .($ this ->icmp_timeout *1000 )." $ address " ; }
288+ else { $ cmd = $ ping_path ." -c $ this ->icmp_count -n $ address 1>/dev/null 2>&1 " ; }
282289
283290 # for IPv6 remove wait
284291 if ($ this ->identify_address ($ address )=="IPv6 " ) {
@@ -374,14 +381,14 @@ protected function ping_address_method_pear ($address) {
374381 * @return void
375382 */
376383 public function ping_address_method_fping ($ address ) {
377- # verify ping path
378- $ this ->ping_verify_path ($ this ->settings ->scanFPingPath );
379-
380384 # if ipv6 append 6
381- if ($ this ->identify_address ($ address )=="IPv6 " ) { $ this ->settings ->scanFPingPath = $ this ->settings ->scanFPingPath ."6 " ; }
385+ $ fping_path = ($ this ->identify_address ($ address )=="IPv6 " ) ? $ this ->fping_path ."6 " : $ this ->fping_path ;
386+
387+ # verify ping path
388+ $ this ->ping_verify_path ($ fping_path );
382389
383390 # set command
384- $ cmd = $ this -> settings -> scanFPingPath ." -c $ this ->icmp_count -t " .($ this ->icmp_timeout *1000 )." $ address " ;
391+ $ cmd = $ fping_path ." -c $ this ->icmp_count -t " .($ this ->icmp_timeout *1000 )." $ address " ;
385392 # execute command, return $retval
386393 exec ($ cmd , $ output , $ retval );
387394
@@ -427,10 +434,14 @@ private function save_fping_rtt ($line) {
427434 * @return void
428435 */
429436 public function ping_address_method_fping_subnet ($ subnet_cidr , $ return_result = false ) {
437+ # if ipv6 append 6
438+ $ fping_path = ($ this ->identify_address ($ address )=="IPv6 " ) ? $ this ->fping_path ."6 " : $ this ->fping_path ;
439+
430440 # verify ping path
431- $ this ->ping_verify_path ($ this ->settings ->scanFPingPath );
441+ $ this ->ping_verify_path ($ fping_path );
442+
432443 # set command
433- $ cmd = $ this -> settings -> scanFPingPath ." -c $ this ->icmp_count -t " .($ this ->icmp_timeout *1000 )." -Ag $ subnet_cidr " ;
444+ $ cmd = $ fping_path ." -c $ this ->icmp_count -t " .($ this ->icmp_timeout *1000 )." -Ag $ subnet_cidr " ;
434445 # execute command, return $retval
435446 exec ($ cmd , $ output , $ retval );
436447
0 commit comments