upgrade-to-2-4-12.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use FindBin '$Bin';
  7. use lib "$Bin/";
  8. use Data::Dumper;
  9. use eyelib::config;
  10. use eyelib::main;
  11. use eyelib::mysql;
  12. use eyelib::net_utils;
  13. use strict;
  14. use warnings;
  15. if ($config_ref{encryption_key}=~/change_me/i) { print "Set encryption key please!\n"; exit 100; }
  16. print "Stage 1: Migrate default password\n";
  17. my $current_password = get_option($dbh,29);
  18. my $crypted_password = crypt_string($current_password);
  19. do_sql($dbh,"UPDATE config set value='".$crypted_password."' WHERE option_id=29");
  20. print "Stage 2: Add default access settings for all netdevices\n";
  21. my $default_login = get_option($dbh,28);
  22. my $default_port = get_option($dbh,30);
  23. my @dev_list = get_records_sql($dbh,"SELECT * FROM devices WHERE device_type <= 2");
  24. foreach my $row (@dev_list) {
  25. #0 - 'Router'
  26. #1 - 'Switch'
  27. #2 - 'Gateway'
  28. my $device;
  29. $device->{login} = $default_login;
  30. $device->{password} = $crypted_password;
  31. #control
  32. #0 - ssh
  33. #1 - telnet
  34. #2 - api
  35. $device->{protocol} = 1;
  36. $device->{control_port} = 23;
  37. if ($row->{device_type} eq '2') {
  38. $device->{control_port} = $default_port;
  39. $device->{protocol} = 0;
  40. }
  41. update_record($dbh,'devices',$device,"id=".$row->{id});
  42. }
  43. print "Done!\n";
  44. exit;