rajven пре 3 година
родитељ
комит
09caf65e85
1 измењених фајлова са 63 додато и 63 уклоњено
  1. 63 63
      html/inc/common.php

+ 63 - 63
html/inc/common.php

@@ -82,7 +82,7 @@ function fbytes($traff)
     if (!empty($traff) and $traff > 0) {
 	$KB = get_const('KB');
 	//IEC
-	if ($KB == 1024) {
+	if ($KB === 1024) {
     	    $index = min(((int) log($traff, $KB)), count($units_IEC) - 1);
     	    $result = round($traff / pow($KB, $index), 3) . ' ' . $units_IEC[$index] . 'B';
 	    } else {
@@ -127,7 +127,7 @@ function checkValidIp($cidr)
         $return = TRUE;
     }
 
-    if ($return == TRUE) {
+    if ($return === TRUE) {
         $parts = explode("/", $cidr);
         $ip = $parts[0];
         if (empty($parts[1])) { $parts[1]="32"; }
@@ -687,8 +687,8 @@ function get_l3_interfaces($db, $device_id)
     $lan='';
     $t_l3int = mysqli_query($db, "SELECT name,interface_type FROM device_l3_interfaces WHERE device_id=$device_id ORDER BY name");
     while (list ($f_name,$f_type) = mysqli_fetch_array($t_l3int)) {
-        if ($f_type==0) { $lan=$lan." ".$f_name; }
-        if ($f_type==1) { $wan=$wan." ".$f_name; }
+        if ($f_type===0) { $lan=$lan." ".$f_name; }
+        if ($f_type===1) { $wan=$wan." ".$f_name; }
         }
     $wan=trim($wan);
     $lan=trim($lan);
@@ -762,7 +762,7 @@ function print_snmp_select($qa_name, $qa_value)
 function print_dhcp_select($qa_name, $qa_value)
 {
     print "<select name=\"$qa_name\">\n";
-    if (! isset($qa_value) or strlen($qa_value) == 0) {
+    if (! isset($qa_value) or strlen($qa_value) === 0) {
         $qa_value = 'all';
     }
     print_select_item(WEB_select_item_events,'all',$qa_value);
@@ -791,7 +791,7 @@ function print_dhcp_acl_select($qa_name)
 function print_enabled_select($qa_name, $qa_value)
 {
     print "<select name=\"$qa_name\">\n";
-    if (! isset($qa_value) or strlen($qa_value) == 0) { $qa_value = 0; }
+    if (! isset($qa_value) or strlen($qa_value) === 0) { $qa_value = 0; }
     print_select_item(WEB_select_item_every,0,$qa_value);
     print_select_item(WEB_select_item_disabled,1,$qa_value);
     print_select_item(WEB_select_item_enabled,2,$qa_value);
@@ -830,7 +830,7 @@ function get_vendor_name($db, $v_id)
 
 function get_qa($qa_value)
 {
-    if ($qa_value == 1) { return "Да"; }
+    if ($qa_value === 1) { return "Да"; }
     return "Нет";
 }
 
@@ -844,7 +844,7 @@ function print_action_select($action_name, $action_value)
 
 function get_action($action_value)
 {
-    if ($action_value == 1) { return "Разрешить"; }
+    if ($action_value === 1) { return "Разрешить"; }
     return "Запретить";
 }
 
@@ -1132,7 +1132,7 @@ function print_auth_detail($db, $auth_id)
     if (empty($name)) { $name = $auth['comments']; } else { $name.=" (".$auth['comments'].")"; }
     if (empty($name)) { $name = $auth['ip']; } else { $name.=" [".$auth['ip']."]"; }
     $name.=" last: [".$auth['last_found']."] ";
-    if ($auth['deleted'] ==1) { $name.=" <font color='red'>DELETED!!!</font>"; }
+    if ($auth['deleted'] ===1) { $name.=" <font color='red'>DELETED!!!</font>"; }
     print "<a href=\"/admin/users/editauth.php?id=$auth_id\">" . $name . "</a><br>";
 }
 
@@ -1426,7 +1426,7 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
         if (isset($dhcp_hostname) and !empty($dhcp_hostname)) { $auth['dhcp_hostname'] = $dhcp_hostname; }
         $auth['dhcp_action'] = $action;
         $auth['dhcp_time'] = GetNowTimeString();
-        if ($action == 'add') { $auth['last_found'] = GetNowTimeString();  }
+        if ($action === 'add') { $auth['last_found'] = GetNowTimeString();  }
         update_record($db, "User_auth", "id=" . $auth_record['id'], $auth);
         return $auth_record['id'];
 	}
@@ -1446,7 +1446,7 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
             $auth['dhcp_action'] = $action;
             $auth['dhcp_time'] = GetNowTimeString();
             if (!empty($dhcp_hostname)) { $auth['dhcp_hostname'] = $dhcp_hostname; }
-            if ($action == 'add') { $auth['last_found'] = GetNowTimeString(); }
+            if ($action === 'add') { $auth['last_found'] = GetNowTimeString(); }
             LOG_INFO($db, "for ip: $ip mac not found! Use empty record...");
             update_record($db, "User_auth", "id=" . $auth_record['id'], $auth);
             return $auth_record['id'];
@@ -1476,7 +1476,7 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
         $auth['dhcp_time'] = GetNowTimeString();
         $auth['save_traf'] = $save_traf *1;
         if (!empty($dhcp_hostname)) { $auth['dhcp_hostname'] = $dhcp_hostname; }
-        if ($action == 'add') { $auth['last_found'] = GetNowTimeString(); }
+        if ($action === 'add') { $auth['last_found'] = GetNowTimeString(); }
         update_record($db, "User_auth", "id=$resurrection_id", $auth);
     } else {
         // not found ->create new record
@@ -1509,7 +1509,7 @@ function get_auth($db, $current_auth)
     if (! isset($current_auth)) {
         return;
     }
-    if ($current_auth == 0) {
+    if ($current_auth === 0) {
         return;
     }
     $t_login = mysqli_query($db, "SELECT U.login,A.ip FROM User_list as U, User_auth as A WHERE A.user_id=U.id and A.id=$current_auth");
@@ -1536,7 +1536,7 @@ function get_auth_mac($db, $current_auth)
     if (! isset($current_auth)) {
         return;
     }
-    if ($current_auth == 0) {
+    if ($current_auth === 0) {
         return;
     }
     $t_login = mysqli_query($db, "SELECT U.login,A.mac FROM User_list as U, User_auth as A WHERE A.user_id=U.id and A.id=$current_auth");
@@ -1728,7 +1728,7 @@ function get_mac_port_table($ip, $port_index, $community, $version, $oid, $index
             $key = trim($key);
             $value = intval(trim(str_replace('INTEGER:', '', $value)));
             $value = $index_map[$value];
-            if ($value == $port_index) {
+            if ($value === $port_index) {
                 $pattern = '/\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';
                 $result = preg_match($pattern, $key, $matches);
                 if ($result) {
@@ -1815,7 +1815,7 @@ function get_fdb_port_table($ip, $port_index, $community, $version)
         }
 
     // maybe cisco?!
-    if (! isset($fdb_port_table) or ! $fdb_port_table or count($fdb_port_table) == 0) {
+    if (! isset($fdb_port_table) or ! $fdb_port_table or count($fdb_port_table) === 0) {
         $vlan_table = walk_snmp($ip, $community, $version, CISCO_VLAN_OID);
         if (! $vlan_table) {
             return;
@@ -1829,7 +1829,7 @@ function get_fdb_port_table($ip, $port_index, $community, $version)
                 $vlan_id = preg_replace('/^\./', '', $matches[0]);
                 if ($vlan_id > 1000 and $vlan_id < 1009) { continue; }
                 $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community . '@' . $vlan_id, $version, MAC_TABLE_OID2,$ifindex_map);
-                if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) == 0) {
+                if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) === 0) {
                     $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID,$ifindex_map);
                 }
                 foreach ($fdb_vlan_table as $mac => $port) {
@@ -1903,7 +1903,7 @@ function get_fdb_table($ip, $community, $version)
         }
 
     // maybe cisco?!
-    if (! isset($fdb_table) or ! $fdb_table or count($fdb_table) == 0) {
+    if (! isset($fdb_table) or ! $fdb_table or count($fdb_table) === 0) {
         $vlan_table = walk_snmp($ip, $community, $version, CISCO_VLAN_OID);
         if (! $vlan_table) {
             return;
@@ -1915,8 +1915,8 @@ function get_fdb_table($ip, $community, $version)
             if (!empty($result)) {
                 $vlan_id = preg_replace('/^\./', '', $matches[0]);
                 if ($vlan_id > 1000 and $vlan_id < 1009) { continue; }
-                $fdb_vlan_table = get_mac_table($ip, $community . '@' . $vlan_id, $version, MAC_TABLE_OID2);
-                if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) == 0) {
+                $fdb_vlan_table = get_mac_table($ip, $community.'@'.$vlan_id, $version, MAC_TABLE_OID2);
+                if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) === 0) {
                     $fdb_vlan_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID);
                 }
                 foreach ($fdb_vlan_table as $mac => $port) {
@@ -2007,10 +2007,10 @@ function walk_snmp($ip, $community, $version, $oid)
 {
     snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
 
-    if ($version == 2) {
+    if ($version === 2) {
         $result = snmp2_real_walk($ip, $community, $oid);
     }
-    if ($version == 1) {
+    if ($version === 1) {
         $result = snmprealwalk($ip, $community, $oid);
     }
     return $result;
@@ -2052,7 +2052,7 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
 
     $status = '';
     // eltex
-    if ($vendor_id == 2) {
+    if ($vendor_id === 2) {
         $sfp_vendor = parse_snmp_value(get_snmp($ip, $community, $version, ELTEX_SFP_VENDOR . "." . $port));
         if (isset($sfp_vendor)) {
             $sfp_status_temp = ELTEX_SFP_STATUS . "." . $port . ".5";
@@ -2081,7 +2081,7 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
         return;
     }
     // cisco
-    if ($vendor_id == 16) {
+    if ($vendor_id === 16) {
         // get interface names
         $port_name = parse_snmp_value(get_snmp($ip, $community, $version, IFMIB_IFNAME . "." . $port));
         if (empty($port_name)) {
@@ -2144,7 +2144,7 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
     }
 
     // huawei
-    if ($vendor_id == 3) {
+    if ($vendor_id === 3) {
         
         
         // get interface names
@@ -2166,8 +2166,8 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
                 $result = parse_snmp_value(get_snmp($ip, $community, $version, HUAWEI_SFP_SPEED . "." . $module_id));
                 if (isset($result)) {
                     list ($sfp_speed, $spf_lenght, $sfp_type) = explode('-', $result);
-                    if ($sfp_type == 0) { $sfp_type = 'MultiMode'; }
-                    if ($sfp_type == 1) { $sfp_type = 'SingleMode'; }
+                    if ($sfp_type === 0) { $sfp_type = 'MultiMode'; }
+                    if ($sfp_type === 1) { $sfp_type = 'SingleMode'; }
                 }
 
                 $volt = parse_snmp_value(get_snmp($ip, $community, $version, HUAWEI_SFP_VOLT . "." . $module_id));
@@ -2222,7 +2222,7 @@ function get_port_vlan($port, $port_index, $ip, $community, $version, $fdb_by_sn
     }
     // if (!is_up($ip)) { return; }
 
-    if ($fdb_by_snmp == 1) { $port = $port_index; }
+    if ($fdb_by_snmp === 1) { $port = $port_index; }
 
     $port_oid = PORT_VLAN_OID . $port;
     $port_vlan = get_snmp($ip, $community, $version, $port_oid);
@@ -2251,23 +2251,23 @@ function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
     // default poe oid
     $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port;
 
-    if ($vendor_id == 3) {
+    if ($vendor_id === 3) {
         $poe_status = HUAWEI_POE_OID . "." . $port;
     }
 
-    if ($vendor_id == 8) {
+    if ($vendor_id === 8) {
         $poe_status = ALLIED_POE_OID . "." . $port;
     }
 
-    if ($vendor_id == 15) {
+    if ($vendor_id === 15) {
         $poe_status = HP_POE_OID . "." . $port;
     }
 
-    if ($vendor_id == 9) {
+    if ($vendor_id === 9) {
         $poe_status = MIKROTIK_POE_OID . "." . $port;
     }
 
-    if ($vendor_id == 10) {
+    if ($vendor_id === 10) {
         $poe_status = NETGEAR_POE_OID . "." . $port;
     }
 
@@ -2275,8 +2275,8 @@ function get_port_poe_state($vendor_id, $port, $ip, $community, $version)
     $c_state = get_snmp($ip, $community, $version, $poe_status);
     if (!empty($c_state)) {
         $p_state = parse_snmp_value($c_state);
-        if ($vendor_id == 9) {
-            if ($p_state == 1) { return 2; }
+        if ($vendor_id === 9) {
+            if ($p_state === 1) { return 2; }
             if ($p_state > 1) { return 1; }
         }
         return $p_state;
@@ -2302,16 +2302,16 @@ function set_port_poe_state($vendor_id, $port, $ip, $community, $version, $state
     // if (!is_up($ip)) { return; }
     // default poe oid
     $poe_status = PETH_PSE_PORT_ADMIN_ENABLE . "." . $port;
-    if ($vendor_id == 3) {
+    if ($vendor_id === 3) {
         $poe_status = HUAWEI_POE_OID . "." . $port;
     }
-    if ($vendor_id == 8) {
+    if ($vendor_id === 8) {
         $poe_status = ALLIED_POE_OID . "." . $port;
     }
-    if ($vendor_id == 15) {
+    if ($vendor_id === 15) {
         $poe_status = HP_POE_OID . "." . $port;
     }
-    if ($vendor_id == 10) {
+    if ($vendor_id === 10) {
         $poe_status = NETGEAR_POE_OID . "." . $port;
     }
 
@@ -2348,42 +2348,42 @@ function get_port_poe_detail($vendor_id, $port, $ip, $community, $version)
     $poe_class = '.1.3.6.1.2.1.105.1.1.1.10.1.' . $port;
 
     // eltex
-    if ($vendor_id == 2) {
+    if ($vendor_id === 2) {
         $poe_power = '.1.3.6.1.4.1.89.108.1.1.5.1.' . $port;
         $poe_current = '.1.3.6.1.4.1.89.108.1.1.4.1.' . $port;
         $poe_volt = '.1.3.6.1.4.1.89.108.1.1.3.1.' . $port;
     }
 
     // huawei
-    if ($vendor_id == 3) {
+    if ($vendor_id === 3) {
         $poe_power = '.1.3.6.1.4.1.2011.5.25.195.3.1.10.' . $port;
         $poe_current = '.1.3.6.1.4.1.4526.11.15.1.1.1.3.1.' . $port;
         $poe_volt = '.1.3.6.1.4.1.2011.5.25.195.3.1.14.' . $port;
     }
 
     // AT
-    if ($vendor_id == 8) {
+    if ($vendor_id === 8) {
         $poe_power = '.1.3.6.1.4.1.89.108.1.1.5.1.' . $port;
         $poe_current = '.1.3.6.1.4.1.89.108.1.1.4.1.' . $port;
         $poe_volt = '.1.3.6.1.4.1.89.108.1.1.3.1.' . $port;
     }
 
     // mikrotik
-    if ($vendor_id == 9) {
+    if ($vendor_id === 9) {
         $poe_power = MIKROTIK_POE_USAGE . '.' . $port;
         $poe_current = MIKROTIK_POE_CURRENT . '.' . $port;
         $poe_volt = MIKROTIK_POE_VOLT . '.' . $port;
     }
 
     // netgear
-    if ($vendor_id == 10) {
+    if ($vendor_id === 10) {
         $poe_power = '.1.3.6.1.4.1.4526.11.15.1.1.1.2.1.' . $port;
         $poe_current = '.1.3.6.1.4.1.4526.11.15.1.1.1.3.1.' . $port;
         $poe_volt = '.1.3.6.1.4.1.4526.11.15.1.1.1.4.1.' . $port;
     }
 
     // HP
-    if ($vendor_id == 15) {
+    if ($vendor_id === 15) {
         $poe_power = '.1.3.6.1.4.1.25506.2.14.1.1.4.1.' . $port;
         $poe_volt = '.1.3.6.1.4.1.25506.2.14.1.1.3.1.' . $port;
     }
@@ -2392,7 +2392,7 @@ function get_port_poe_detail($vendor_id, $port, $ip, $community, $version)
         $c_power = get_snmp($ip, $community, $version, $poe_power);
         if (isset($c_power)) {
             $p_power = parse_snmp_value($c_power);
-            if ($vendor_id == 9) {
+            if ($vendor_id === 9) {
                 $p_power = round($p_power / 10, 2);
             } else {
                 $p_power = round($p_power / 1000, 2);
@@ -2415,13 +2415,13 @@ function get_port_poe_detail($vendor_id, $port, $ip, $community, $version)
         $c_volt = get_snmp($ip, $community, $version, $poe_volt);
         if (isset($c_volt)) {
             $p_volt = parse_snmp_value($c_volt);
-            if ($vendor_id == 2 or $vendor_id == 8) {
+            if ($vendor_id === 2 or $vendor_id === 8) {
                 $p_volt = round($p_volt / 1000, 2);
             }
-            if ($vendor_id == 9) {
+            if ($vendor_id === 9) {
                 $p_volt = round($p_volt / 10, 2);
             }
-            if ($vendor_id == 15) {
+            if ($vendor_id === 15) {
                 $p_volt = round($p_volt / 100, 2);
             }
             if ($p_volt > 0 and $p_power > 0) {
@@ -2446,10 +2446,10 @@ function get_port_poe_detail($vendor_id, $port, $ip, $community, $version)
 function get_snmp($ip, $community, $version, $oid)
 {
     snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
-    if ($version == 2) {
+    if ($version === 2) {
         $result = snmp2_get($ip, $community, $oid);
     }
-    if ($version == 1) {
+    if ($version === 1) {
         $result = snmpget($ip, $community, $oid);
     }
     return $result;
@@ -2457,10 +2457,10 @@ function get_snmp($ip, $community, $version, $oid)
 
 function set_snmp($ip, $community, $version, $oid, $field, $value)
 {
-    if ($version == 2) {
+    if ($version === 2) {
         $result = snmp2_set($ip, $community, $oid, $field, $value);
     }
-    if ($version == 1) {
+    if ($version === 1) {
         $result = snmpset($ip, $community, $oid, $field, $value);
     }
     return $result;
@@ -2482,7 +2482,7 @@ function set_port_state($vendor_id, $port, $ip, $community, $version, $state)
         $version = '2';
     }
     $port_status = PORT_ADMIN_STATUS_OID . $port;
-    if ($state == 1) {
+    if ($state === 1) {
         // enable port
         $c_state = set_snmp($ip, $community, $version, $port_status, 'i', 1);
         return $c_state;
@@ -2501,7 +2501,7 @@ function set_port_for_group($db, $group_id, $place_id, $state)
     // get auth list for group
     while (list ($a_id, $a_name, $a_ip) = mysqli_fetch_array($auth_list)) {
         // get device and port for auth
-        if ($place_id == 0) {
+        if ($place_id === 0) {
             $place_filter = '';
         } else {
             $place_filter = 'D.building_id=' . $place_id . ' and ';
@@ -2512,7 +2512,7 @@ function set_port_for_group($db, $group_id, $place_id, $state)
         if (! isset($d_id)) {
             continue;
         }
-        if ($state == 1) {
+        if ($state === 1) {
             $mode = 'enable';
             run_sql($db, "Update User_auth set nagios_handler='restart-port' WHERE id=$a_id and nagios_handler='manual-mode'");
         } else {
@@ -2564,7 +2564,7 @@ function get_port_state_detail($port, $ip, $community, $version)
     $p_state = parse_snmp_value($c_state);
     $c_admin = get_snmp($ip, $community, $version, $admin);
     $p_admin = parse_snmp_value ($c_admin);
-    if ($p_state == 1) { $c_speed = get_snmp($ip, $community, $version, $speed); } else { $c_speed = 'INT:0'; }
+    if ($p_state === 1) { $c_speed = get_snmp($ip, $community, $version, $speed); } else { $c_speed = 'INT:0'; }
     $p_speed = parse_snmp_value($c_speed);
     $c_errors = get_snmp($ip, $community, $version, $errors);
     $p_errors = parse_snmp_value($c_errors);
@@ -2590,7 +2590,7 @@ function dec_to_hex($mac)
     $mac_array = explode('.', $mac);
     for ($i = 0; $i < count($mac_array); $i ++) {
         $hex_i = dechex($mac_array[$i]);
-        if (strlen($hex_i) == 1) {
+        if (strlen($hex_i) === 1) {
             $hex_i = "0" . $hex_i;
         }
         $mac_array[$i] = $hex_i;
@@ -2928,7 +2928,7 @@ function update_record($db, $table, $filter, $newvalue)
         $changed_log = $changed_log . " $key => $value (old: $old[$key]),";
         $run_sql = $run_sql . " `" . $key . "`='" . mysqli_real_escape_string($db, $value) . "',";
     }
-    if ($run_sql == '') { return; }
+    if (empty($run_sql)) { return; }
 
     if ($network_changed) { $run_sql = $run_sql . " `changed`='1',"; }
 
@@ -3016,7 +3016,7 @@ function insert_record($db, $table, $newvalue)
         $value = trim($value);
         $value_list = $value_list . "'" . mysqli_real_escape_string($db, $value) . "',";
     }
-    if ($value_list == '') {
+    if (empty($value_list)) {
         return;
     }
     $changed_log = substr_replace($changed_log, "", - 1);
@@ -3114,7 +3114,7 @@ print "<option value=$value>$description</option>";
 }
 
 function print_select_item_ext ($description,$value,$current,$disabled) {
-if ($value == $current) { print "<option value=$value selected>$description</option>"; } 
+if ($value === $current) { print "<option value=$value selected>$description</option>"; } 
     else {
     if (!$disabled) { print "<option value=$value>$description</option>"; } else { print "<option disabled value=$value>$description</option>"; }
     }
@@ -3343,8 +3343,8 @@ return NULL;
 $config["org_name"]= get_option($db_link, 32);
 
 $config["KB"]= get_option($db_link, 1);
-if ($config["KB"] == 0) { $config["KB"]=1000; }
-if ($config["KB"] == 1) { $config["KB"]=1024; }
+if ($config["KB"] === 0) { $config["KB"]=1000; }
+if ($config["KB"] === 1) { $config["KB"]=1024; }
 
 $config["debug"]= get_option($db_link, 34);
 $config["log_level"]= get_option($db_link, 53);