import_ip.pl 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use FindBin '$Bin';
  6. use lib "$Bin/";
  7. use Data::Dumper;
  8. use Rstat::config;
  9. use Rstat::main;
  10. use Rstat::mysql;
  11. use Rstat::net_utils;
  12. use strict;
  13. use warnings;
  14. use Getopt::Long;
  15. use Proc::Daemon;
  16. use Cwd;
  17. use IO::Socket::UNIX qw( SOCK_STREAM );
  18. use Net::Netmask;
  19. use File::Spec::Functions;
  20. use File::Copy qw(move);
  21. use Text::Iconv;
  22. my $iplist_file = "iplist.txt";
  23. open(IPLIST,$iplist_file) || die("Error open $iplist_file: $!");
  24. while (my $logline = <IPLIST>) {
  25. next unless defined $logline;
  26. chomp($logline);
  27. my ($ip,$mac,$comment) = split (/\;/, $logline);
  28. my $auth_network = $office_networks->match_string($ip);
  29. if (!$auth_network) {
  30. log_error("Unknown network in dhcp request! IP: $ip");
  31. next;
  32. }
  33. log_info("Check for new auth...");
  34. my $auth_id=resurrection_auth($dbh,$ip,$mac,'add');
  35. if ($comment) {
  36. my $auth;
  37. $auth->{comments}=$comment;
  38. update_record($dbh,'User_auth',$auth,'id='.$auth_id);
  39. }
  40. }
  41. close IPLIST;
  42. exit;