opt
/
kaspersky
/
kav4fs
/
lib
/
perl
/
KL
➕ New
📤 Upload
✎ Editing:
Upgrade.pm
← Back
package KL::Upgrade; use strict; use Carp; use KL::Utils; ### Text strings BEGIN ### my $UPGRD_MSG_1 = "The following configuration file(s) have been found:"; my $UPGRD_MSG_1_VAR = "UPGRD_CHOOSE_CONF_FILES"; my $UPGRD_MSG_2 = <<MSG_END; It is impossible to convert two identical files. MSG_END my $UPGRD_MSG_3 = <<MSG_END; All configuration files were successfully converted and loaded. MSG_END my $UPGRD_MSG_4 = "An error occurred while converting the settings. See \%1 for more information."; my $UPGRD_MSG_5 = "Please choose file(s) to convert or enter an empty string to skip"; my $UPGRD_MSG_6 = "A configuration file for a previous version found:"; my $UPGRD_MSG_7 = "Checking for configuration files for previous versions: not found"; my $UPGRD_MSG_8 = "Conversion skipped by user"; ### Text strings END ### sub new { my $class = shift; $class = ref($class) if ref($class); bless my $self = {}, $class; $self->_init(@_); return $self; } sub _init { my $self = shift; my %opt = @_; $self->{supported_config} = { 'kav4fs5' => [ '/etc/opt/kaspersky/kav4fs.conf', '/etc/opt/kaspersky/kav4fs.conf.rpmsave', '/usr/local/etc/kaspersky/kav4fs.conf' ], 'kav4samba' => [ '/etc/opt/kaspersky/kav4samba.conf', '/etc/opt/kaspersky/kav4samba.conf.rpmsave', '/usr/local/etc/kaspersky/kav4samba.conf' ], 'kavmidware' => [ '/var/opt/kaspersky/middleware/sheduler.sav', '/var/db/kaspersky/middleware/sheduler.sav' ] }; for my $prod (keys %{$self->{supported_config}}) { for my $conf (@{$opt{$prod}}) { push @{$self->{supported_config}->{$prod}}, $conf; } } $self->{converter_bin} = $opt{converter_bin}; $self->{logger} = $opt{logger}; $self->{logger}->applog("config converter binary: $self->{converter_bin}"); } sub do_upgrade { my $self = shift; my %old_configs = $self->find_files(); if (!%old_configs) { $self->{logger}->applog($UPGRD_MSG_7); return 1; } my @conv = $self->ask_convert_config_list(sort keys %old_configs); while(dublicated(\@conv, \%old_configs)) { KL::Utils::output($UPGRD_MSG_2); @conv = $self->ask_convert_config_list(keys %old_configs); } if (!@conv) { $self->{logger}->applog($UPGRD_MSG_8); return 1; } my $exit_code = ""; for (@conv) { $ENV{"KL_CONVERTER_".uc($old_configs{$_})} = $_ } open(LOG, "($self->{converter_bin};echo \$?) 2>&1 |") || return 0; while(my $line = <LOG>) { chomp $line; $exit_code = $line; $self->{logger}->applog($line); } close LOG; return 0 if $exit_code ne "0"; KL::Utils::output($UPGRD_MSG_3); return 1; } # find existing files sub find_files { my $self = shift; my %ret = (); my %all_conf = $self->config_list(); for my $conf (keys %all_conf) { if (-f $conf) { $ret{$conf} = $all_conf{$conf}; $self->{logger}->applog("$UPGRD_MSG_6 $conf"); } } return %ret; } # invert files struct sub config_list { my $self = shift; my %ret = (); for my $prod (keys %{$self->{supported_config}}) { for my $conf (@{$self->{supported_config}->{$prod}}) { $ret{$conf} = $prod; } } return %ret; } # call external function to ask user ... or not sub ask_convert_config_list { my $self = shift; my @conf_list = @_; my $ask_text = $UPGRD_MSG_1; my $idx = 1; my @ret = (); for (@conf_list) { $ask_text .= "\n <B>[$idx]</B> $_"; ++$idx; } $ask_text .= "\n\n$UPGRD_MSG_5"; my @answ = KL::Utils::ask_list($UPGRD_MSG_1_VAR, " ", [1..(scalar(@conf_list))], $ask_text); for (@answ) { push @ret, $conf_list[$_ - 1] if $_ > 0 } return @ret; } # WARNING !!! This function not for external use sub dublicated { my ($list, $hash) = @_; my (%ident, %help); %ident = (); %help = (); for (@$list) { $help{$hash->{$_}}++ && return 1 } return 0; } 1;
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel