after_sql.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use FindBin '$Bin';
  7. use lib "/opt/Eye/scripts";
  8. use eyelib::config;
  9. use eyelib::main;
  10. use eyelib::database;
  11. use strict;
  12. use warnings;
  13. my $upgrade_from = '2.7.3';
  14. my $this_release = '2.7.4';
  15. $dbh=init_db();
  16. init_option($dbh);
  17. if (!$config_ref{version}) {
  18. print "Current version unknown! Skip upgrade!\n";
  19. exit 100;
  20. }
  21. if ($this_release eq $config_ref{version}) { print "Already updated!\n"; exit; }
  22. if ($upgrade_from ne $config_ref{version}) { print "Illegal version. Needed $upgrade_from!\n"; exit; }
  23. print 'Current version: '.$config_ref{version}.' upgrade to: '.$this_release."\n";
  24. my @authlist_ref = get_records_sql($dbh,"SELECT * FROM User_auth WHERE `created_by` IS NULL" );
  25. my $total = scalar @authlist_ref;
  26. print "Fill field created_by\n";
  27. my $i = 0;
  28. foreach my $row (@authlist_ref) {
  29. my $new;
  30. $i++;
  31. if (!$row->{dhcp_action}) { $new->{created_by} = 'manual'; }
  32. if ($row->{dhcp_action}=~/^(add|old|del)$/i) {
  33. $new->{created_by}='dhcp';
  34. } else {
  35. $new->{created_by}=$row->{dhcp_action};
  36. $new->{dhcp_action}='';
  37. }
  38. my $percent = int(($i / $total) * 100);
  39. update_record($dbh,'User_auth',$new,'id='.$row->{id});
  40. print "\r::Progress: [$percent%] ";
  41. }
  42. print "Done!";
  43. exit;