|
@@ -15,6 +15,7 @@ use eyelib::main;
|
|
|
use eyelib::database;
|
|
use eyelib::database;
|
|
|
use strict;
|
|
use strict;
|
|
|
use warnings;
|
|
use warnings;
|
|
|
|
|
+use Data::Dumper;
|
|
|
|
|
|
|
|
STDOUT->autoflush(1);
|
|
STDOUT->autoflush(1);
|
|
|
|
|
|
|
@@ -24,14 +25,17 @@ my $this_release = '2.8.0';
|
|
|
$dbh=init_db();
|
|
$dbh=init_db();
|
|
|
init_option($dbh);
|
|
init_option($dbh);
|
|
|
|
|
|
|
|
|
|
+my $force = 0;
|
|
|
|
|
+if ($ARGV[0] and $ARGV[0] eq 'force') { $force = 1; }
|
|
|
|
|
+
|
|
|
if (!$config_ref{version}) {
|
|
if (!$config_ref{version}) {
|
|
|
print "Current version unknown! Skip upgrade!\n";
|
|
print "Current version unknown! Skip upgrade!\n";
|
|
|
exit 100;
|
|
exit 100;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-if ($this_release eq $config_ref{version}) { print "Already updated!\n"; exit; }
|
|
|
|
|
|
|
+if (!$force and $this_release eq $config_ref{version}) { print "Already updated!\n"; exit; }
|
|
|
|
|
|
|
|
-if ($upgrade_from ne $config_ref{version}) { print "Illegal version. Needed $upgrade_from!\n"; exit; }
|
|
|
|
|
|
|
+if (!$force and $upgrade_from ne $config_ref{version}) { print "Illegal version. Needed $upgrade_from!\n"; exit; }
|
|
|
|
|
|
|
|
print 'Apply patch for version: '.$config_ref{version}.' upgrade to: '.$this_release."\n";
|
|
print 'Apply patch for version: '.$config_ref{version}.' upgrade to: '.$this_release."\n";
|
|
|
|
|
|
|
@@ -43,35 +47,45 @@ print "Stage 1: Fix dns name fields\n";
|
|
|
|
|
|
|
|
my $i = 0;
|
|
my $i = 0;
|
|
|
foreach my $row (@authlist_ref) {
|
|
foreach my $row (@authlist_ref) {
|
|
|
-my $new;
|
|
|
|
|
-$i++;
|
|
|
|
|
-my $dns_name = trim($row->{dns_name});
|
|
|
|
|
-if ($dns_name and $dns_name =~ /\.\Q$domain_name\E$/i) {
|
|
|
|
|
- $dns_name =~ s/\.\Q$domain_name\E$//i;
|
|
|
|
|
- $dns_name =~s/\.$//g;
|
|
|
|
|
- $dns_name =~s/_/-/g;
|
|
|
|
|
- $dns_name =~s/ /-/g;
|
|
|
|
|
- $dns_name =~s/-$//g;
|
|
|
|
|
- $dns_name = trim($dns_name);
|
|
|
|
|
- if ($dns_name) { $new->{dns_name}=$dns_name; }
|
|
|
|
|
- } else {
|
|
|
|
|
- $dns_name =~s/_/-/g;
|
|
|
|
|
- $dns_name =~s/ /-/g;
|
|
|
|
|
- $dns_name =~s/-$//g;
|
|
|
|
|
|
|
+ $i++;
|
|
|
|
|
+ my $percent = int(($i / $total) * 100);
|
|
|
|
|
+ print "\r::Progress: [$percent%] ";
|
|
|
|
|
+
|
|
|
|
|
+ my $dns_name = trim($row->{dns_name});
|
|
|
|
|
+ next unless $dns_name;
|
|
|
|
|
+ my $original_name = $dns_name;
|
|
|
|
|
+
|
|
|
|
|
+ $dns_name =~ s/\.$//g;
|
|
|
|
|
+ $dns_name =~ s/_/-/g;
|
|
|
|
|
+ $dns_name =~ s/ /-/g;
|
|
|
|
|
+ $dns_name =~ s/-$//g;
|
|
|
$dns_name = trim($dns_name);
|
|
$dns_name = trim($dns_name);
|
|
|
- if ($dns_name and $dns_name=~/\./) {
|
|
|
|
|
- $dns_name = $dns_name.".";
|
|
|
|
|
- $new->{dns_name}=$dns_name;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
-my $percent = int(($i / $total) * 100);
|
|
|
|
|
|
|
+ my $new;
|
|
|
|
|
|
|
|
-if (exists $new->{dns_name} and $new->{dns_name}) {
|
|
|
|
|
- update_record($dbh,'User_auth',$new,'id='.$row->{id});
|
|
|
|
|
|
|
+ # --- Если имя заканчивается на домен, убираем его
|
|
|
|
|
+ if ($dns_name =~ /\.\Q$domain_name\E$/i) {
|
|
|
|
|
+ $dns_name =~ s/\.\Q$domain_name\E$//i;
|
|
|
|
|
+ $dns_name = trim($dns_name);
|
|
|
|
|
+ $new->{dns_name} = $dns_name if $dns_name;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-print "\r::Progress: [$percent%] ";
|
|
|
|
|
|
|
+ # --- Если домен не указан в конце (возможно, уже очищен), обрабатываем точки
|
|
|
|
|
+ if ($dns_name !~ /\.\Q$domain_name\E$/i) {
|
|
|
|
|
+ $dns_name =~ s/\.\.$//g;
|
|
|
|
|
+ my $dot_count = ($dns_name =~ tr/.//);
|
|
|
|
|
+ if ($dot_count > 1) {
|
|
|
|
|
+ $dns_name .= "." unless $dns_name =~ /\.$/;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $dns_name =~ s/\.$//g;
|
|
|
|
|
+ }
|
|
|
|
|
+ $new->{dns_name} = $dns_name if $dns_name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # --- Обновляем, только если имя изменилось
|
|
|
|
|
+ if (exists $new->{dns_name} && $new->{dns_name} ne $original_name) {
|
|
|
|
|
+ do_sql($dbh, 'UPDATE User_auth SET dns_name = ? WHERE id = ?', $new->{dns_name}, $row->{id});
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
print "Done!\n";
|
|
print "Done!\n";
|