Commit 9d62568a authored by Gary Allan's avatar Gary Allan
Browse files

Bugfix: class.Scan.php. Check for correct IPv4/IPv6 ping path. #60

Refactor: Sync functions/classes/* with phpipam master.
parent 5a776dc4
...@@ -153,7 +153,7 @@ abstract class DB { ...@@ -153,7 +153,7 @@ abstract class DB {
$this->pdo = new \PDO($dsn, $this->username, $this->password); $this->pdo = new \PDO($dsn, $this->username, $this->password);
} }
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->setErrMode(\PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) { } catch (\PDOException $e) {
throw new Exception ("Could not connect to database! ".$e->getMessage()); throw new Exception ("Could not connect to database! ".$e->getMessage());
...@@ -162,6 +162,14 @@ abstract class DB { ...@@ -162,6 +162,14 @@ abstract class DB {
@$this->pdo->query('SET NAMES \'' . $this->charset . '\';'); @$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
} }
/**
* Set PDO error mode
* @param mixed $mode
*/
public function setErrMode($mode = \PDO::ERRMODE_EXCEPTION) {
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, $mode);
}
/** /**
* makeDsn function. * makeDsn function.
* *
......
...@@ -114,16 +114,23 @@ class Scan extends Common_functions { ...@@ -114,16 +114,23 @@ class Scan extends Common_functions {
$this->Database = $database; $this->Database = $database;
# initialize Result # initialize Result
$this->Result = new Result (); $this->Result = new Result ();
# fetch settings # fetch settings
$this->settings = is_null($this->settings) ? $this->get_settings() : (object) $this->settings; $settings = is_null($this->settings) ? $this->get_settings() : (object) $this->settings;
$config = Config::ValueOf('config');
$this->ping_type = $config['method'];
$this->ping_path = ($this->ping_type == "ping") ? $config['pingpath'] : '';
$this->fping_path = ($this->ping_type == "fping") ? $config['pingpath'] : '';
# set type # set type
$this->reset_scan_method ($this->settings->scanPingType); $this->reset_scan_method ($this->ping_type);
# set OS type # set OS type
$this->set_os_type (); $this->set_os_type ();
# set php exec # set php exec
$this->set_php_exec (); $this->set_php_exec ();
# Log object # Log object
$this->Log = new Logging ($this->Database, $this->settings); $this->Log = new Logging ($this->Database, $settings);
if ($errmsg = php_feature_missing(null, ['exec'])) if ($errmsg = php_feature_missing(null, ['exec']))
$this->Result->show("danger", $errmsg, true); $this->Result->show("danger", $errmsg, true);
...@@ -268,17 +275,17 @@ class Scan extends Common_functions { ...@@ -268,17 +275,17 @@ class Scan extends Common_functions {
* @return void * @return void
*/ */
protected function ping_address_method_ping ($address) { protected function ping_address_method_ping ($address) {
# verify ping path
$this->ping_verify_path ($this->settings->scanPingPath);
# if ipv6 append 6 # if ipv6 append 6
if ($this->identify_address ($address)=="IPv6") { $this->settings->scanPingPath = $this->settings->scanPingPath."6"; } $ping_path = ($this->identify_address ($address)=="IPv6") ? $this->ping_path."6" : $this->ping_path;
# verify ping path
$this->ping_verify_path ($ping_path);
# set ping command based on OS type # set ping command based on OS type
if ($this->os_type == "FreeBSD") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; } if ($this->os_type == "FreeBSD") { $cmd = $ping_path." -c $this->icmp_count -W ".($this->icmp_timeout*1000)." $address 1>/dev/null 2>&1"; }
elseif($this->os_type == "Linux") { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -W $this->icmp_timeout $address 1>/dev/null 2>&1"; } elseif($this->os_type == "Linux") { $cmd = $ping_path." -c $this->icmp_count -W $this->icmp_timeout $address 1>/dev/null 2>&1"; }
elseif($this->os_type == "Windows") { $cmd = $this->settings->scanPingPath." -n $this->icmp_count -w ".($this->icmp_timeout*1000)." $address"; } elseif($this->os_type == "Windows") { $cmd = $ping_path." -n $this->icmp_count -w ".($this->icmp_timeout*1000)." $address"; }
else { $cmd = $this->settings->scanPingPath." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; } else { $cmd = $ping_path." -c $this->icmp_count -n $address 1>/dev/null 2>&1"; }
# for IPv6 remove wait # for IPv6 remove wait
if ($this->identify_address ($address)=="IPv6") { if ($this->identify_address ($address)=="IPv6") {
...@@ -374,14 +381,14 @@ class Scan extends Common_functions { ...@@ -374,14 +381,14 @@ class Scan extends Common_functions {
* @return void * @return void
*/ */
public function ping_address_method_fping ($address) { public function ping_address_method_fping ($address) {
# verify ping path
$this->ping_verify_path ($this->settings->scanFPingPath);
# if ipv6 append 6 # if ipv6 append 6
if ($this->identify_address ($address)=="IPv6") { $this->settings->scanFPingPath = $this->settings->scanFPingPath."6"; } $fping_path = ($this->identify_address ($address)=="IPv6") ? $this->fping_path."6" : $this->fping_path;
# verify ping path
$this->ping_verify_path ($fping_path);
# set command # set command
$cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." $address"; $cmd = $fping_path." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." $address";
# execute command, return $retval # execute command, return $retval
exec($cmd, $output, $retval); exec($cmd, $output, $retval);
...@@ -427,10 +434,14 @@ class Scan extends Common_functions { ...@@ -427,10 +434,14 @@ class Scan extends Common_functions {
* @return void * @return void
*/ */
public function ping_address_method_fping_subnet ($subnet_cidr, $return_result = false) { public function ping_address_method_fping_subnet ($subnet_cidr, $return_result = false) {
# if ipv6 append 6
$fping_path = ($this->identify_address ($address)=="IPv6") ? $this->fping_path."6" : $this->fping_path;
# verify ping path # verify ping path
$this->ping_verify_path ($this->settings->scanFPingPath); $this->ping_verify_path ($fping_path);
# set command # set command
$cmd = $this->settings->scanFPingPath." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." -Ag $subnet_cidr"; $cmd = $fping_path." -c $this->icmp_count -t ".($this->icmp_timeout*1000)." -Ag $subnet_cidr";
# execute command, return $retval # execute command, return $retval
exec($cmd, $output, $retval); exec($cmd, $output, $retval);
......
File mode changed from 100755 to 100644
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment