upgrade-20200229.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use FindBin '$Bin';
  6. use lib "$Bin/";
  7. use strict;
  8. use DBI;
  9. use Time::Local;
  10. use Net::Patricia;
  11. use Data::Dumper;
  12. use Rstat::config;
  13. use Rstat::main;
  14. use Rstat::mysql;
  15. use Rstat::net_utils;
  16. @office_network_list=();
  17. @hotspot_network_list=();
  18. #office nets
  19. $office_networks = new Net::Patricia;
  20. my $ret=get_option($dbh,13);
  21. if (ref($ret) eq 'ARRAY') {
  22. foreach my $net (@$ret) {
  23. next if (!$net);
  24. push(@office_network_list,$net);
  25. }
  26. } else {
  27. push(@office_network_list,$ret);
  28. }
  29. #hotspot nets
  30. $hotspot_networks = new Net::Patricia;
  31. $ret=get_option($dbh,42);
  32. if (ref($ret) eq 'ARRAY') {
  33. foreach my $net (@$ret) {
  34. next if (!$net);
  35. push(@hotspot_network_list,$net);
  36. }
  37. } else {
  38. if ($ret) {
  39. push(@hotspot_network_list,$ret);
  40. }
  41. }
  42. foreach my $net (@office_network_list) {
  43. next if (!$net);
  44. my $dhcp=GetDhcpRange($net);
  45. my $start = StrToIp($dhcp->{first_ip})-1;
  46. my $stop = StrToIp($dhcp->{last_ip})+1;
  47. my $sSQL='INSERT INTO subnets (subnet,ip_int_start,ip_int_stop,office,hotspot) VALUES("'.$net.'",'."$start,$stop,1,0)";
  48. do_sql($dbh,$sSQL);
  49. }
  50. foreach my $net (@hotspot_network_list) {
  51. next if (!$net);
  52. my $dhcp=GetDhcpRange($net);
  53. my $start = StrToIp($dhcp->{first_ip})-1;
  54. my $stop = StrToIp($dhcp->{last_ip})+1;
  55. my $sSQL='INSERT INTO subnets (subnet,ip_int_start,ip_int_stop,office,hotspot) VALUES("'.$net.'",'."$start,$stop,0,1)";
  56. do_sql($dbh,$sSQL);
  57. }
  58. do_sql($dbh,'DELETE FROM config WHERE option_id=42 or option_id=13');
  59. do_sql($dbh,'DELETE FROM config_options WHERE id=42 or id=13');
  60. exit;