Private GIT

Skip to content
Snippets Groups Projects
Unverified Commit 2c1ff67b authored by Gary Allan's avatar Gary Allan
Browse files

PSR12 format pingCheck and discoveryCheck

No code changes
parent 0b96d507
Branches
No related tags found
No related merge requests found
......@@ -44,7 +44,9 @@ if(@$config['discovery_check_method'])
$Scan->reset_scan_method($config['discovery_check_method']);
# Check if scanning has been disabled
if($Scan->icmp_type=="none") { $Result->show("danger", _('Scanning disabled').' (scanPingType=None)', true, true); }
if ($Scan->icmp_type == "none") {
$Result->show("danger", _('Scanning disabled') . ' (scanPingType=None)', true, true);
}
// set ping statuses
$statuses = explode(";", $Scan->settings->pingStatus);
......@@ -63,16 +65,24 @@ $hostnames = array(); // Array with detected hostnames
// script can only be run from cli
if(php_sapi_name()!="cli") { die("This script can only be run from cli!"); }
if (php_sapi_name() != "cli") {
die("This script can only be run from cli!");
}
// test to see if threading is available
if(!PingThread::available($errmsg)) { die("Threading is required for scanning subnets - Error: $errmsg\n"); }
if (!PingThread::available($errmsg)) {
die("Threading is required for scanning subnets - Error: $errmsg\n");
}
// verify ping path
if ($Scan->icmp_type == "ping") {
if(!file_exists($Scan->settings->scanPingPath)) { die("Invalid ping path!"); }
if (!file_exists($Scan->settings->scanPingPath)) {
die("Invalid ping path!");
}
}
// verify fping path
if ($Scan->icmp_type == "fping") {
if(!file_exists($Scan->settings->scanFPingPath)){ die("Invalid fping path!"); }
if (!file_exists($Scan->settings->scanFPingPath)) {
die("Invalid fping path!");
}
}
......@@ -105,12 +115,18 @@ if ($scan_subnets!==false) {
}
if($Scan->get_debugging()==true) { print_r($scan_subnets); }
if($scan_subnets===false || !count($scan_subnets)) { die("No subnets are marked for new hosts checking\n"); }
if ($Scan->get_debugging() == true) {
print_r($scan_subnets);
}
if ($scan_subnets === false || !count($scan_subnets)) {
die("No subnets are marked for new hosts checking\n");
}
//scan
if($Scan->get_debugging()==true) { print "Using $Scan->icmp_type\n--------------------\n\n"; }
if ($Scan->get_debugging() == true) {
print "Using $Scan->icmp_type\n--------------------\n\n";
}
$z = 0; //addresses array index
......@@ -221,7 +237,10 @@ else {
# print change
if($Scan->get_debugging()==true) { print "\nDiscovered addresses:\n----------\n"; print_r($scan_subnets); }
if ($Scan->get_debugging() == true) {
print "\nDiscovered addresses:\n----------\n";
print_r($scan_subnets);
}
......@@ -283,7 +302,9 @@ if($discovered>0 && $config['discovery_check_send_mail']) {
}
}
# none?
if(!isset($recepients)) { die(); }
if (!isset($recepients)) {
die();
}
# fake user object, needed for create_link
$User = new FakeUser($Scan->settings->prettyLinks);
......
......@@ -54,7 +54,9 @@ if(@$config['ping_check_method'])
$Scan->reset_scan_method($config['ping_check_method']);
# Check if scanning has been disabled
if($Scan->icmp_type=="none") { $Result->show("danger", _('Scanning disabled').' (scanPingType=None)', true, true); }
if ($Scan->icmp_type == "none") {
$Result->show("danger", _('Scanning disabled') . ' (scanPingType=None)', true, true);
}
// set ping statuses
$statuses = explode(";", $Scan->settings->pingStatus);
......@@ -72,23 +74,35 @@ $nowdate = date ("Y-m-d H:i:s");
// script can only be run from cli
if(php_sapi_name()!="cli") { die("This script can only be run from cli!"); }
if (php_sapi_name() != "cli") {
die("This script can only be run from cli!");
}
// test to see if threading is available
if(!PingThread::available($errmsg)) { die("Threading is required for scanning subnets - Error: $errmsg\n"); }
if (!PingThread::available($errmsg)) {
die("Threading is required for scanning subnets - Error: $errmsg\n");
}
// verify ping path
if ($Scan->icmp_type == "ping") {
if(!file_exists($Scan->settings->scanPingPath)) { die("Invalid ping path!"); }
if (!file_exists($Scan->settings->scanPingPath)) {
die("Invalid ping path!");
}
}
// verify fping path
if ($Scan->icmp_type == "fping") {
if(!file_exists($Scan->settings->scanFPingPath)){ die("Invalid fping path!"); }
if (!file_exists($Scan->settings->scanFPingPath)) {
die("Invalid fping path!");
}
}
//first fetch all subnets to be scanned
$scan_subnets = $Subnets->fetch_all_subnets_for_pingCheck(1);
if($Scan->get_debugging()==true) { print_r($scan_subnets); }
if($scan_subnets===false) { die("No subnets are marked for checking status updates\n"); }
if ($Scan->get_debugging() == true) {
print_r($scan_subnets);
}
if ($scan_subnets === false) {
die("No subnets are marked for checking status updates\n");
}
//fetch all addresses that need to be checked
foreach ($scan_subnets as $s) {
......@@ -125,8 +139,7 @@ foreach($scan_subnets as $s) {
"nsid" => $s->nsid
);
$addresses[$s->id][$a->id] = $a->ip_addr;
}
else {
} else {
$addresses[] = array(
"id" => $a->id,
"ip_addr" => $a->ip_addr,
......@@ -149,9 +162,14 @@ foreach($scan_subnets as $s) {
}
if($Scan->get_debugging()==true) { print "Using $Scan->icmp_type\n--------------------\n\n";print_r($addresses); }
if ($Scan->get_debugging() == true) {
print "Using $Scan->icmp_type\n--------------------\n\n";
print_r($addresses);
}
//if none die
if(!isset($addresses)) { die("No addresses to check"); }
if (!isset($addresses)) {
die("No addresses to check");
}
/* scan */
......@@ -317,7 +335,9 @@ else {
// loop
foreach ($address_change as $k => $change) {
// null old - set to epoch time
if (strtotime($change['lastSeenOld'])===false) { $change['lastSeenOld'] = date("Y-m-d H:i:s", 0); }
if (strtotime($change['lastSeenOld']) === false) {
$change['lastSeenOld'] = date("Y-m-d H:i:s", 0);
}
// set general diffs
$deviceDiff = $now - strtotime($change['lastSeenOld']); // now - device last seen
......@@ -344,8 +364,7 @@ foreach ($address_change as $k=>$change) {
if ($address_change[$k]['state'] != 1 && $Scan->settings->updateTags == 1 && $Tools->address_types[$address_change[$k]['state']]['updateTag'] == 1) {
$Scan->update_address_tag($address_change[$k]['id'], 1, $address_change[$k]['state'], $change['lastSeenOld']);
}
}
else {
} else {
// already reported, check tag
if ($address_change[$k]['state'] != 1 && $Scan->settings->updateTags == 1 && $Tools->address_types[$address_change[$k]['state']]['updateTag'] == 1) {
$Scan->update_address_tag($address_change[$k]['id'], 1, $address_change[$k]['state'], $change['lastSeenOld']);
......@@ -363,8 +382,7 @@ foreach ($address_change as $k=>$change) {
if ($address_change[$k]['state'] != 2 && $Scan->settings->updateTags == 1 && $Tools->address_types[$address_change[$k]['state']]['updateTag'] == 1) {
$Scan->update_address_tag($address_change[$k]['id'], 2, $address_change[$k]['state'], $change['lastSeenOld']);
}
}
else {
} else {
// update tag if not already offline
// tags have different indexes than script exit code is - 1=offline, 2=online
if ($address_change[$k]['state'] != 1 && $Scan->settings->updateTags == 1 && $Tools->address_types[$address_change[$k]['state']]['updateTag'] == 1) {
......@@ -381,7 +399,10 @@ $Scan->ping_update_scanagent_checktime (1, $nowdate);
# print change
if($Scan->get_debugging()==true) { print "\nAddress changes:\n----------\n"; print_r($address_change); }
if ($Scan->get_debugging() == true) {
print "\nAddress changes:\n----------\n";
print_r($address_change);
}
# all done, mail diff?
if (sizeof($address_change) > 0 && $config['ping_check_send_mail']) {
......@@ -409,7 +430,9 @@ if(sizeof($address_change)>0 && $config['ping_check_send_mail']) {
}
}
# none?
if(!isset($recepients)) { die(); }
if (!isset($recepients)) {
die();
}
# fake user object, needed for create_link
$User = new FakeUser($Scan->settings->prettyLinks);
......@@ -446,8 +469,7 @@ if(sizeof($address_change)>0 && $config['ping_check_send_mail']) {
if ($change['oldStatus'] == 0) {
$oldStatus = "<font style='color:#04B486'>Online</font>";
$newStatus = "<font style='color:#DF0101'>Offline</font>";
}
else {
} else {
$oldStatus = "<font style='color:#DF0101'>Offline</font>";
$newStatus = "<font style='color:#04B486'>Online</font>";
}
......@@ -481,7 +503,6 @@ if(sizeof($address_change)>0 && $config['ping_check_send_mail']) {
//plain content
$content_plain[] = "\t * " . $Subnets->transform_to_dotted($change['ip_addr']) . " (" . $Subnets->transform_to_dotted($subnet->subnet) . "/" . $subnet->mask . ")\r\n \t " . strip_tags($oldStatus) . " => " . strip_tags($newStatus);
}
$content[] = "</table>";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment