migrate-devices.pl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 NetAddr::IP;
  12. use Data::Dumper;
  13. use Rstat::config;
  14. use Rstat::main;
  15. use Rstat::mysql;
  16. use Rstat::net_utils;
  17. use File::Basename;
  18. use File::Path;
  19. print "Start migration: ";
  20. #1 - switch
  21. #2 - router
  22. #3 - server
  23. #get userid list
  24. my $sSQL="SELECT * FROM devices";
  25. my @devices = get_custom_records($dbh,$sSQL);
  26. foreach my $row (@devices) {
  27. next if (!$row);
  28. if (exists($row->{'is_router'})) {
  29. if ($row->{'is_router'}) { $row->{device_type}=2; }
  30. update_record($dbh,'devices',$row,"id=$row->{id}");
  31. print ".";
  32. }
  33. if (exists($row->{wan_int})) {
  34. my @wan_int=split(/;/,$row->{'wan_int'});
  35. foreach my $dev (@wan_int) {
  36. next if (!$dev);
  37. my $new_l3;
  38. $new_l3->{'name'}=trim($dev);
  39. $new_l3->{'interface_type'}=1;
  40. $new_l3->{'device_id'}=$row->{'id'};
  41. insert_record($dbh,'device_l3_interfaces',$new_l3);
  42. }
  43. }
  44. if (exists($row->{lan_int})) {
  45. my @lan_int=split(/;/,$row->{'lan_int'});
  46. foreach my $dev (@lan_int) {
  47. next if (!$dev);
  48. my $new_l3;
  49. $new_l3->{'name'}=trim($dev);
  50. $new_l3->{'interface_type'}=0;
  51. $new_l3->{'device_id'}=$row->{'id'};
  52. insert_record($dbh,'device_l3_interfaces',$new_l3);
  53. }
  54. }
  55. }
  56. do_sql($dbh,"ALTER TABLE `devices` DROP `lan_int`;");
  57. do_sql($dbh,"ALTER TABLE `devices` DROP `wan_int`;");
  58. do_sql($dbh,"ALTER TABLE `devices` DROP `is_router`;");
  59. do_sql($dbh,"ALTER TABLE `devices` CHANGE `internet_gateway` `user_acl` TINYINT(1) NOT NULL DEFAULT '0';");
  60. exit 0;