Răsfoiți Sursa

small fixes in utils

Roman Dmitriev 3 luni în urmă
părinte
comite
d1817dc3bc

+ 13 - 2
scripts/utils/bind/print-dns-zones.pl

@@ -51,7 +51,18 @@ my $named_conf=$named_root.'/etc/bind/named.dynamic';
 
 
 my %zones;
 my %zones;
 
 
-my $sSQL="SELECT id,ou_id,ip,dns_name,dhcp_hostname,dns_ptr_only FROM user_auth WHERE deleted=0 AND ip>'' AND (dns_name>'' OR dhcp_hostname>'') AND dns_name NOT LIKE '%.' ORDER by ip_int;";
+my $sSQL = "
+    SELECT id, ou_id, ip, dns_name, dhcp_hostname, dns_ptr_only
+    FROM user_auth
+    WHERE deleted = 0
+      AND ip IS NOT NULL
+      AND (
+            (dns_name IS NOT NULL AND dns_name != '' AND dns_name NOT LIKE '%.')
+            OR
+            (dhcp_hostname IS NOT NULL AND dhcp_hostname != '')
+          )
+    ORDER BY ip_int
+";
 my @authlist_ref = get_records_sql($dbh,$sSQL);
 my @authlist_ref = get_records_sql($dbh,$sSQL);
 foreach my $row (@authlist_ref) {
 foreach my $row (@authlist_ref) {
 next if (!$row);
 next if (!$row);
@@ -77,7 +88,7 @@ next if (!$office_networks->match_string($ip));
 my $default_name=$dns_name;
 my $default_name=$dns_name;
 $zones{$domain_name}{A}{$default_name}=$ip;
 $zones{$domain_name}{A}{$default_name}=$ip;
 
 
-my @dns_aliases=get_records_sql($dbh,"SELECT * FROM user_auth_alias WHERE auth_id=$row->{id} AND alias>'' AND alias NOT LIKE '%.' ORDER BY alias");
+my @dns_aliases = get_records_sql( $dbh, "SELECT * FROM user_auth_alias WHERE auth_id = ? AND alias IS NOT NULL AND alias != '' AND alias NOT LIKE '%.' ORDER BY alias", $row->{id});
 foreach my $alias (@dns_aliases) {
 foreach my $alias (@dns_aliases) {
         my $dns_alias = trim($alias->{alias});
         my $dns_alias = trim($alias->{alias});
 #        $dns_alias =~s/$domain_name//i;
 #        $dns_alias =~s/$domain_name//i;

+ 0 - 72
scripts/utils/import/import_ips.pl

@@ -1,72 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Copyright (C) Roman Dmitiriev, rnd@rajven.ru
-#
-
-#Import ip to user
-use utf8;
-use warnings;
-use Encode;
-use open qw(:std :encoding(UTF-8));
-no warnings 'utf8';
-
-use FindBin '$Bin';
-use lib "/opt/Eye/scripts";
-use Data::Dumper;
-use eyelib::config;
-use eyelib::main;
-use eyelib::database;
-use eyelib::net_utils;
-use strict;
-use warnings;
-
-sub add_auth {
-my $db = shift;
-my $comment = shift;
-my $ip = shift;
-my $user_id = shift;
-
-my $ip_aton=StrToIp($ip);
-my $record=get_record_sql($db,'SELECT id FROM User_auth WHERE `deleted`=0 AND `ip_int`='.$ip_aton);
-if ($record->{id}) { return $record->{id}; }
-my $user_record=get_record_sql($db,"SELECT * FROM User_list WHERE id=$user_id");
-my $new_record;
-$new_record->{ip_int}=$ip_aton;
-$new_record->{ip}=$ip;
-$new_record->{user_id}=$user_id;
-$new_record->{save_traf}="$save_detail";
-$new_record->{deleted}="0";
-$new_record->{created_by}='manual';
-$new_record->{ou_id}=$user_record->{ou_id};
-$new_record->{filter_group_id}=$user_record->{filter_group_id};
-$new_record->{queue_id}=$user_record->{queue_id};
-$new_record->{enabled}="$user_record->{enabled}";
-$new_record->{comments}=$comment;
-
-my $cur_auth_id=insert_record($db,'User_auth',$new_record);
-return $cur_auth_id;
-}
-
-
-my $user_id =$ARGV[0];
-
-exit if (!$user_id);
-
-print "Stage 0: Read ip list for user_id: $user_id\n";
-
-binmode(STDOUT,':utf8');
-
-if (-e "1") {
-    my @nSQL=read_file("1");
-    foreach my $row (@nSQL) {
-        my ($user_name,$auth_ip) = split(/[\,|\;|\s]/,$row);
-        next if (!$auth_ip);
-        print "Add: $user_name $auth_ip";
-        my $ret = add_auth($dbh,$user_name,$auth_ip,$user_id);
-        if ($ret) { print "...OK\n"; } else { print "...Fail\n"; }
-        }
-    }
-print "Done!\n";
-
-exit;

+ 20 - 7
scripts/utils/oxidized/print_devices_oxi.pl

@@ -21,10 +21,23 @@ use eyelib::main;
 use eyelib::database;
 use eyelib::database;
 use eyelib::common;
 use eyelib::common;
 
 
-my @router_list = get_records_sql($dbh,"SELECT D.*, DM.model_name, B.name AS building_name FROM devices D
-LEFT JOIN device_models DM ON D.device_model_id = DM.id
-LEFT JOIN building B ON D.building_id = B.id
-WHERE D.deleted = 0 and device_type<=2 ORDER BY building_name,ip");
+my @router_list = get_records_sql($dbh, "
+    SELECT
+        D.*,
+        DM.model_name,
+        B.name AS building_name
+    FROM devices D
+    LEFT JOIN device_models DM ON D.device_model_id = DM.id
+    LEFT JOIN building B ON D.building_id = B.id
+    WHERE
+        D.deleted = 0
+        AND D.device_type <= 2
+        AND D.protocol >= 0
+    ORDER BY
+        (building_name IS NULL),
+        building_name,
+        ip
+");
 
 
 foreach my $device (@router_list) {
 foreach my $device (@router_list) {
 next if (!$device->{password} or !$device->{login});
 next if (!$device->{password} or !$device->{login});
@@ -33,9 +46,9 @@ next if ($device->{protocol} eq '-1');
 $device = netdev_set_auth($device);
 $device = netdev_set_auth($device);
 my $oxi_model = 'dcnos';
 my $oxi_model = 'dcnos';
 my $comware_cmdline = '';
 my $comware_cmdline = '';
-my $vendor = get_record_sql($dbh,"SELECT * FROM vendors WHERE id=".$device->{vendor_id});
-my $model = get_record_sql($dbh,"SELECT * FROM device_models WHERE id=".$device->{device_model_id});
-my $building = get_record_sql($dbh,"SELECT * FROM building WHERE id=".$device->{building_id});
+my $vendor = get_record_sql($dbh,"SELECT * FROM vendors WHERE id=?", $device->{vendor_id});
+my $model = get_record_sql($dbh,"SELECT * FROM device_models WHERE id=?", $device->{device_model_id});
+my $building = get_record_sql($dbh,"SELECT * FROM building WHERE id=?", $device->{building_id});
 if ($vendor->{name} =~/zyxel/i) { $oxi_model = 'zynoscli'; }
 if ($vendor->{name} =~/zyxel/i) { $oxi_model = 'zynoscli'; }
 if ($vendor->{name} =~/snr/i) { $oxi_model = 'dcnos'; }
 if ($vendor->{name} =~/snr/i) { $oxi_model = 'dcnos'; }
 if ($vendor->{name} =~/huawei/i) { $oxi_model = 'vrp'; }
 if ($vendor->{name} =~/huawei/i) { $oxi_model = 'vrp'; }

+ 1 - 1
scripts/utils/reaply_rules.pl

@@ -36,7 +36,7 @@ my $group_id = $ARGV[0];
 
 
 exit if (!$group_id);
 exit if (!$group_id);
 
 
-my $group = get_record_sql($dbh,"SELECT * FROM ou WHERE id=$group_id");
+my $group = get_record_sql($dbh,"SELECT * FROM ou WHERE id=?",$group_id);
 
 
 print "Analyzed rules for group id: $group_id name: $group->{ou_name}\n";
 print "Analyzed rules for group id: $group_id name: $group->{ou_name}\n";