Преглед на файлове

the netflow is saved in the router's subdirectory

root преди 1 година
родител
ревизия
50e6e7e
променени са 5 файла, в които са добавени 27 реда и са изтрити 13 реда
  1. 5 1
      html/admin/devices/edit_l3int.php
  2. 11 8
      scripts/eye-statd.pl
  3. 7 4
      scripts/eyelib/database.pm
  4. 1 0
      scripts/sync_mikrotik.pl
  5. 3 0
      scripts/updates/upgrade.pl

+ 5 - 1
html/admin/devices/edit_l3int.php

@@ -40,6 +40,7 @@ if (isset($_POST["s_create"])) {
         $new = NULL;
         list($new['name'],$new['snmpin'],$new['interface_type']) = explode(";", trim($_POST["s_create_name"]));
         $new['device_id'] = $id;
+        $new['name']=preg_replace('/\"/','',$new['name']);
         LOG_INFO($db_link, "Create new l3_interface ".$new['name']);
         insert_record($db_link, "device_l3_interfaces", $new);
     }
@@ -74,7 +75,10 @@ print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login'
 $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; }
+foreach ($int_list as $row) { 
+    $row['name'] = preg_replace('/\"/','',$row['name']);
+    $int_by_name[$row['name']]=$row;
+}
 $fixed = 0;
 
 //fixing snmp index if not exists by interface name

+ 11 - 8
scripts/eye-statd.pl

@@ -433,7 +433,7 @@ my $hdb=init_db();
 
 #saved packet by users
 my @detail_traffic = ();
-my @saved_netflow = ();
+my %saved_netflow = ();
 
 my %routers_found;
 
@@ -447,7 +447,7 @@ my ($auth_id,$l_src_ip,$l_dst_ip,$user_ip,$router_id);
 $router_id = $traf_record->{device_id};
 
 if ($traf_record->{save}) {
-    push(@saved_netflow,join(';',$traf_record->{starttime},$traf_record->{device_id},$traf_record->{proto},$traf_record->{snmp_in},$traf_record->{snmp_out},$traf_record->{src_ip},$traf_record->{dst_ip},$traf_record->{xsrc_ip},$traf_record->{xdst_ip},$traf_record->{src_port},$traf_record->{dst_port},$traf_record->{octets},$traf_record->{pkts}));
+    push(@{$saved_netflow{$traf_record->{device_id}}},join(';',$traf_record->{starttime},$traf_record->{proto},$traf_record->{snmp_in},$traf_record->{snmp_out},$traf_record->{src_ip},$traf_record->{dst_ip},$traf_record->{xsrc_ip},$traf_record->{xdst_ip},$traf_record->{src_port},$traf_record->{dst_port},$traf_record->{octets},$traf_record->{pkts}));
     }
 
 $routers_found{$router_id} = 1;
@@ -525,12 +525,13 @@ my ($sec,$min,$hour,$day,$month,$year) = (localtime($last_time))[0,1,2,3,4,5];
 
 #save netflow
 $save_path=~s/\/$//;
-my $netflow_file_path = $save_path.'/'.sprintf "%04d/%02d/%02d/%02d/",$year+1900,$month+1,$day,$hour;
+foreach my $dev_id (keys %saved_netflow) {
+my $netflow_file_path = $save_path.'/'.$dev_id.'/'.sprintf "%04d/%02d/%02d/%02d/",$year+1900,$month+1,$day,$hour;
 my $nmin = int($min/10)*10;
 my $netflow_file_name = $netflow_file_path.sprintf "%04d%02d%02d-%02d%02d.csv",$year+1900,$month+1,$day,$hour,$nmin;
-if (scalar @saved_netflow) {
-    use File::Path::Tiny;
-    File::Path::Tiny::mk($netflow_file_path);
+if ($saved_netflow{$dev_id} and scalar @{$saved_netflow{$dev_id}}) {
+    use File::Path;
+    make_path($netflow_file_path);
     if ( -e $netflow_file_name) {
         open (ND,">>$netflow_file_name") || die("Error open file $netflow_file_name!!! die...");
         binmode(ND,':utf8');
@@ -539,13 +540,15 @@ if (scalar @saved_netflow) {
         binmode(ND,':utf8');
         print ND join(';',"time","device_id","proto","snmp_in","snmp_out","src_ip","dst_ip","xsrc_ip","xdst_ip","src_port","dst_port","octets","pkts")."\n";
         }
-    foreach my $row (@saved_netflow) {
+    foreach my $row (@{$saved_netflow{$dev_id}}) {
         next if (!$row);
         print ND $row."\n";
         }
     close ND;
-    @saved_netflow=();
+    @{$saved_netflow{$dev_id}}=();
     }
+}
+undef %saved_netflow;
 
 #save statistics
 

+ 7 - 4
scripts/eyelib/database.pm

@@ -2064,10 +2064,13 @@ do_sql($db,"DELETE FROM `ad_comp_cache` WHERE last_found<=$clean_str");
 
 #---------------------------------------------------------------------------------------------------------------
 
-$dbh=init_db();
-init_option($dbh);
-clean_variables($dbh);
-Set_Variable($dbh);
+#skip init for upgrade
+if ($MY_NAME!~/upgrade.pl/) {
+    $dbh=init_db();
+    init_option($dbh);
+    clean_variables($dbh);
+    Set_Variable($dbh);
+    }
 
 1;
 }

+ 1 - 0
scripts/sync_mikrotik.pl

@@ -105,6 +105,7 @@ my @wan_int=();
 
 my @l3_int = get_records_sql($dbh,'SELECT * FROM device_l3_interfaces WHERE device_id='.$gate->{'id'});
 foreach my $l3 (@l3_int) {
+$l3->{'name'}=~s/\"//g;
 if ($l3->{'interface_type'} eq '0') { push(@lan_int,$l3->{'name'}); }
 if ($l3->{'interface_type'} eq '1') { push(@wan_int,$l3->{'name'}); }
 }

+ 3 - 0
scripts/updates/upgrade.pl

@@ -41,6 +41,9 @@ my $r_index = 0;
 my %old_releases_h = map {$_ => $r_index++ } @old_releases;
 my $eye_release = $old_releases[@old_releases - 1];
 
+$dbh=init_db();
+init_option($dbh);
+
 if (!$config_ref{version}) { $config_ref{version}='2.4.12'; }
 
 if ($ARGV[0]) {