Sfoglia il codice sorgente

Update site for 2.7.0

root 1 anno fa
parent
commit
4de614f019

+ 11 - 0
docs/systemd/eye-statd.service

@@ -0,0 +1,11 @@
+[Unit]
+Description=EYE netflow collector
+After=network.target
+
+[Service]
+ExecStart=/opt/Eye/scripts/eye-statd.pl
+Restart=on-failure
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target

+ 41 - 8
html/admin/devices/edit_l3int.php

@@ -4,8 +4,9 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
-$device=get_record($db_link,'devices',"id=".$id);
+$device = get_record($db_link,'devices',"id=".$id);
 $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
+$int_list = getIpAdEntIfIndex($db_link,$device['ip'],$device['community'],$device['snmp_version']);
 
 if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
@@ -26,7 +27,6 @@ if (isset($_POST['s_save'])) {
         $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
         for ($j = 0; $j < $len_all; $j ++) {
             if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
-            $new['name'] = trim($_POST['s_name'][$j]);
             $new['interface_type'] = $_POST['s_type'][$j]*1;
             update_record($db_link, "device_l3_interfaces", "id='{$save_id}'", $new);
         }
@@ -37,10 +37,10 @@ if (isset($_POST['s_save'])) {
 
 if (isset($_POST["s_create"])) {
     if (!empty($_POST["s_create_name"])) {
-        $new['name'] = trim($_POST["s_create_name"]);
+        $new = NULL;
+        list($new['name'],$new['snmpin'],$new['interface_type']) = explode(";", trim($_POST["s_create_name"]));
         $new['device_id'] = $id;
-        $new['interface_type'] = 0;
-        LOG_INFO($db_link, "Create new l3_interface ".$new['name']." as local");
+        LOG_INFO($db_link, "Create new l3_interface ".$new['name']);
         insert_record($db_link, "device_l3_interfaces", $new);
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
@@ -72,18 +72,51 @@ print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login'
 </tr>
 <?php
 $t_l3_interface = get_records($db_link,'device_l3_interfaces',"device_id=$id ORDER BY name");
+
+$int_by_name = [];
+foreach ($int_list as $row) { $int_by_name[$row['name']]=$row; }
+$fixed = 0;
+
+//fixing snmp index if not exists by interface name
+foreach ( $t_l3_interface as $row ) {
+    $fix = NULL;
+    if (empty($row['snmpin']) and !empty($int_by_name[$row['name']])) {
+        $fix['snmpin']=$int_by_name[$row['name']]['index'];
+        if (!empty($fix)) {
+            update_record($db_link,'device_l3_interfaces','id='.$row['id'],$fix);
+            }
+        $fixed = 1;
+        }
+    }
+
+//updating interface name by snmp index
+foreach ( $t_l3_interface as $row ) {
+    $fix = NULL;
+    if (!empty($int_list[$row['snmpin']]) and $int_list[$row['snmpin']]['name'] !== $row['name']) {
+        $fix['name']=$int_list[$row['snmpin']]['name'];
+        if (!empty($fix)) {
+            update_record($db_link,'device_l3_interfaces','id='.$row['id'],$fix);
+            }
+        $fixed = 1;
+        }
+    }
+
+if ($fixed) {
+    $t_l3_interface = get_records($db_link,'device_l3_interfaces',"device_id=$id ORDER BY name");
+    }
+
 foreach ( $t_l3_interface as $row ) {
     print "<tr align=center>\n";
     print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
-    print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
-    print "<td class=\"data\"><input type=\"text\" name='s_name[]' value='{$row['name']}'></td>\n";
+    print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['snmpin']}</td>\n";
+    print "<td class=\"data\">".$row['name'].'/'.$int_list[$row['snmpin']]['ip']."</td>\n";
     print "<td class=\"data\">"; print_qa_l3int_select('s_type[]',$row['interface_type']); print "</td>\n";
     print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
     print "</tr>\n";
     }
 ?>
 <tr>
-<td colspan=4><?php print WEB_l3_interface_add; print "&nbsp:<input type=\"text\" name='s_create_name' value=''";?>
+<td colspan=4><?php print WEB_l3_interface_add; print_add_dev_interface($db_link, $id, $int_list, 's_create_name');?>
 </td>
 <td>
 <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">

+ 66 - 2
html/inc/common.php

@@ -499,6 +499,23 @@ function print_add_gw_subnets($db, $device_id, $gs_name)
     print "</select>\n";
 }
 
+function print_add_dev_interface($db, $device_id, $int_list, $int_name)
+{
+    print "&nbsp<select name=\"$int_name\" >\n";
+    $t_int = get_records_sql($db, "SELECT * FROM device_l3_interfaces WHERE device_id=".$device_id);
+    $int_exists=[];
+    foreach ($t_int as $interface) { $int_exists[$interface['snmpin']]=$interface; }
+    foreach ($int_list as $interface) {
+        if (!empty($int_exists[$interface['index']])) { continue; }
+        $value = $interface['name'].';'.$interface['index'].';'.$interface['type'];
+        if ($interface['type']==1) { $interface['type']=WEB_select_item_wan; }
+        if ($interface['type']==0) { $interface['type']=WEB_select_item_lan; }
+        $display_str = $interface['name'].'&nbsp|'.$interface['ip'].'|'.$interface['type'];
+        print_select_item($display_str, $value, 0);
+        }
+    print "</select>\n";
+}
+
 function print_ou_set($db, $ou_name, $ou_value)
 {
     print "<select name=\"$ou_name\">\n";
@@ -2396,7 +2413,7 @@ function get_ifmib_index_table($ip, $community, $version)
         }
     }
 
-    #return simple map snmp_port_index = snmp_port_index
+#return simple map snmp_port_index = snmp_port_index
     if (empty($ifmib_map)) {
         #ifindex
         $index_table = walk_snmp($ip, $community, $version, IFMIB_IFINDEX);
@@ -2465,6 +2482,37 @@ function get_mac_table($ip, $community, $version, $oid, $index_map)
     return $fdb_table;
 }
 
+#get ip interfaces
+function getIpAdEntIfIndex($db, $ip, $community = 'public', $version = '2')
+{
+if (!isset($ip)) { return; }
+#oid+ip = index
+$ip_table = walk_snmp($ip, $community, $version, ipAdEntIfIndex);
+#oid+index=name
+$int_table = walk_snmp($ip, $community, $version, ifDescr);
+$result = [];
+if (isset($ip_table) and gettype($ip_table) == 'array' and count($ip_table) > 0) {
+        foreach ($ip_table as $key => $value) {
+            if (empty($value)) { continue; }
+            if (empty($key)) { continue; }
+            $key = trim($key);
+            $interface_index = intval(trim(str_replace('INTEGER:', '', $value)));
+            if (empty($value)) { continue; }
+            $interface_name = $int_table[ifDescr . '.' .$interface_index];
+            $interface_name = trim(str_replace('STRING:', '', $interface_name));
+            $interface_ip = trim(str_replace(ipAdEntIfIndex.'.','',$key));
+            if (empty($interface_name)) { continue; }
+            $result[$interface_index]['ip']=$interface_ip;
+            $result[$interface_index]['index']=$interface_index;
+            $result[$interface_index]['name']=$interface_name;
+            //type: 0 - local, 1 - WAN
+            $result[$interface_index]['type'] = 1;
+            if (is_our_network($db,$interface_ip)) { $result[$interface_index]['type']=0; }
+        }
+    }
+return $result;
+}
+
 #get mac table by analyze all available tables
 function get_fdb_table($ip, $community, $version)
 {
@@ -4604,7 +4652,7 @@ function insert_record($db, $table, $newvalue)
     $field_list = '';
     $value_list = '';
     foreach ($newvalue as $key => $value) {
-        if (empty($value) and $value !== 0) {
+        if (empty($value) and $value != '0') {
             $value = '';
         }
         if (!preg_match('/password/i',$key)) {
@@ -5003,6 +5051,22 @@ function get_subnet_range($db, $subnet_id)
     return $subnet;
 }
 
+function int_between($value, $start, $end) {
+    return in_array($value, range($start, $end));
+}
+
+function is_gray_network($ip)
+{
+if (empty($ip)) { return 0; }
+$ip_aton = ip2long($ip);
+$gray_nets = array('10.0.0.0/8','192.168.0.0/16','172.16.0.0/12','100.64.0.0/10');
+foreach ($gray_nets as &$net) {
+    $net_cidr = cidrToRange($net);
+    if (int_between($ip_aton,ip2long($net_cidr[0]),ip2long($net_cidr[1]))) { return $net; }
+    }
+return 0;
+}
+
 function is_hotspot($db, $ip)
 {
     if (!isset($ip)) {

+ 7 - 0
html/inc/consts.php

@@ -2,6 +2,13 @@
 
 if (!defined("CONFIG"))die("Not defined");
 
+//intterfaces
+define("ifDescr",".1.3.6.1.2.1.2.2.1.2");
+
+//ipaddr
+define("ipAdEntIfIndex",".1.3.6.1.2.1.4.20.1.2");
+
+//pports
 define("PORT_STATUS_OID",".1.3.6.1.2.1.2.2.1.8");
 define("PORT_ADMIN_STATUS_OID",".1.3.6.1.2.1.2.2.1.7");
 define("PORT_SPEED_OID",".1.3.6.1.2.1.2.2.1.5");

+ 1 - 0
scripts/updates/2-7-0/device_l3_interfaces.sql

@@ -0,0 +1 @@
+ALTER TABLE `device_l3_interfaces` ADD `snmpin` INT NULL DEFAULT NULL AFTER `device_id`;

+ 1 - 0
scripts/updates/2-7-0/version.sql

@@ -0,0 +1 @@
+REPLACE INTO `version` (`version`) VALUES ('2.7.0');

+ 2 - 1
scripts/updates/upgrade.pl

@@ -35,12 +35,13 @@ my @old_releases = (
 '2.6.1',
 '2.6.2',
 '2.6.3',
+'2.7.0'
 );
 
 my $r_index = 0;
 my %old_releases_h = map {$_ => $r_index++ } @old_releases;
 
-my $eye_release = '2.6.3';
+my $eye_release = pop @old_releases;
 
 if (!$config_ref{version}) { $config_ref{version}='2.4.12'; }