opt
/
kaspersky
/
kav4fs
/
lib
/
perl
/
KL
➕ New
📤 Upload
✎ Editing:
App.pm
← Back
package KL::App; use strict; use File::Spec; use File::Temp; use KL::AppBase; use KL::AppSamba; use KL::IniFile; use KL::Upgrade; my $APP_ID = 1046; my $TASK_ID_UPDATER = 6; my $TASK_ID_OAS = 8; use vars qw(@ISA); @ISA = qw(KL::AppBase KL::AppSamba); ### Text strings BEGIN ### my $MSG_CANT_EXECUTE = <<EOT; Couldn\'t execute the command %1 %2: %3. EOT my $MSG_COMMAND_FAILED = <<EOT; Couldn\'t execute the command %1: %2. EOT #--- my $HEADER_SETUP_OAS = <<EOT; Setting up the kernel-level real-time protection EOT my $MSG_OAS_CONFIGURE_NOT_FOUND = <<EOT; Could\'t find the initial configuration script in directory %2. EOT my $MSG_OAS_OS_NOT_SUPPORTED = <<EOT; The %1 OS is not supported. EOT my $MSG_OAS_MODULE_CONFIRM = <<EOT; Would you like to compile the kernel-level real-time protection module? EOT my $MSG_OAS_ENTER_LINUX_PATH = <<EOT; The installer found the source code for your Linux kernel. Press Enter to confirm this path, or enter another path to the source code for your Linux kernel, or enter 'cancel' to interrupt the compilation of the kernel-level real-time protection module: EOT my $MSG_OAS_ENTER_ANOTHER_LINUX_PATH = <<EOT; Enter another path to the source code for your Linux kernel, or enter 'cancel' to interrupt the compilation of the kernel-level real-time protection module: EOT my $MSG_OAS_BAD_LINUX_PATH = <<EOT; The %1 path is not a correct Linux kernel path. EOT my $MSG_OAS_GCC_NOT_FOUND = <<EOT; The installed gcc is not found; you need to install the gcc package to build the kernel-level real-time protection module. EOT my $MSG_OAS_MAKE_NOT_FOUND = <<EOT; make is not found; you need to install the make package to build the kernel-level real-time protection module. EOT my $MSG_OAS_KERNEL_SRCS_NOT_FOUND = <<EOT; Couldn\'t find the Linux kernel source code; probably, you need to install the Linux kernel source package. EOT my $MSG_OAS_KERNEL_SRCS_NOT_FOUND_AT = <<EOT; Couldn\'t find the Linux kernel source code in %1. EOT my $MSG_OAS_KERNEL_SRCS_DEF_LOCATIONS = 'default locations'; my $MSG_OAS_KERNEL_SRCS_NOT_CONFIGURED = <<EOT; The Linux kernel source code found in %1 is not configured correctly. You need to configure it to build the kernel-level real-time protection module. EOT my $MSG_OAS_LINUX_STEP_CONFIGURING = <<EOT; >>> Configuring the kernel-level real-time protection module using the Linux kernel source code from %1 EOT my $MSG_OAS_LINUX_STEP_COMPILING = <<EOT; >>> Compiling the kernel-level real-time protection module EOT my $MSG_OAS_LINUX_COMPILE_ERROR = <<EOT; Couldn\'t compile the module. EOT my $MSG_OAS_LINUX_MKDIR_ERROR = <<EOT; Couldn\'t create the %1 directory. EOT my $MSG_OAS_LINUX_CANT_FIND_MODULE = <<EOT; Couldn\'t find a compiled kernel-level real-time protection module. EOT my $MSG_OAS_LINUX_CANT_FIND_REDIR_MODULE = <<EOT; Couldn\'t find a compiled kernel-level redirfs framework module. EOT my $MSG_OAS_LINUX_STEP_INSTALL = <<EOT; >>> Installing the module as %1 EOT my $MSG_OAS_LINUX_STEP_REBUILD_DEPS = <<EOT; >>> Rebuilding modules.dep EOT my $MSG_OAS_LINUX_STEP_PROBE = <<EOT; >>> Probing a new module EOT my $MSG_OAS_LINUX_STEP_DELETE = <<EOT; >>> Deleting %1 EOT my $MSG_OAS_LINUX_BUILD_FAILED = <<EOT; Couldn\'t install the %1 module. Probably, the specified Linux kernel source code is not for the Linux kernel that you are currently using. You can run the initial configuration script again by executing <B>%2 --build[=PATH]</B>. EOT my $MSG_OAS_LINUX_STEP_UNLOAD = <<EOT; >>> Unloading the module %1 EOT my $MSG_OAS_FREEBSD_STEP_CONFIGURE = <<EOT; >>> Configuring the FreeBSD kernel module... EOT my $MSG_OAS_FREEBSD_STEP_COMPILE = <<EOT; >>> Compiling the FreeBSD kernel module EOT my $MSG_OAS_FREEBSD_COMPILE_ERROR = <<EOT; Couldn\'t compile the %1 module. EOT my $MSG_OAS_FREEBSD_STEP_PROBE = <<EOT; >>> Probing the new module EOT my $MSG_OAS_FREEBSD_STEP_DELETE = <<EOT; >>> Deleting %1... EOT my $MSG_OAS_FREEBSD_BUILD_FAILED = <<EOT; Couldn\'t install the %1 module. EOT my $MSG_OAS_FREEBSD_STEP_UNLOAD = <<EOT; >>> Unloading the module EOT my $MSG_OAS_MODULE_WARN = <<EOT; The kernel-level real-time protection module is not compiled. To manually recompile the kernel-level real-time protection module, start <B>%1 --build[=PATH]</B>. EOT my $MSG_OAS_DISABLE_CONFIRM = <<EOT; Would you like to disable the real-time protection? EOT my $MSG_OAS_DISABLED_WARN = <<EOT; The real-time protection is DISABLED. EOT #--- my $MSG_GET_PROXY_FAILED = <<EOT; Couldn\'t get proxy settings. EOT my $MSG_CHANGE_PROXY_FAILED = <<EOT; Couldn\'t change proxy settings. EOT my $MSG_INCORRECT_PROXY_VALUE = <<EOT; The %1 value is not correct value for proxy settings. EOT my $MSG_AUTOUPDATE = <<EOT; The application databases are scheduled to be updated every 30 minutes. EOT my $MSG_UPGRADE_MODULE_WARN = <<EOT; An error occurred while converting the settings. For more information, see %1. EOT #--- my $HEADER_START_OAS = <<EOT; Starting the real-time protection task EOT #--- my $HEADER_SERVICE_LOCALE = <<EOT; Setting up the Anti-Virus Service default locale EOT my $MSG_SERVICE_LOCALE_CHANGED = <<EOT; Anti-Virus Service default locale is changed to '%1'. Service will be restarted if already running. EOT my $MSG_SERVICE_ASK_LOCALE = <<EOT; You need to specify a locale the Anti-Virus Service will use when applying the protection settings. It is very important to specify the locale you are using when working with the file system names (in most cases this should be the system default locale). EOT my $MSG_SERVICE_BAD_LOCALE = <<EOT; '%1' is not a valid locale. %2 EOT my $MSG_SERVICE_LOCALE_HINT_LIST = <<EOT; You can execute 'locale -a' command line to see the list of all available locales. EOT my $MSG_SERVICE_LOCALE_HINT_ETC = <<EOT; Please select one of locales from /etc/locale (please note that on some systems not all of the locales shown by 'locale -a' command are actually available). EOT my $MSG_WAIT_AFTER_RESTART = <<EOT; Waiting for %1 to make ready after restart... EOT my $MSG_ERROR_NOTREADY_AFTER_RESTART = <<EOT; %1 is not ready yet! EOT #--- my $HEADER_WMCONSOLE = <<EOT; Setting up the Web Management Console EOT my $MSG_WMCONSOLE_PASS_CONFIRM = <<EOT; Would you like to set password for Kaspersky Web Management Console? EOT my $MSG_WMCONSOLE_WARN_PASSWORD_NOT_SET = <<EOT; Password file not found, Kaspersky Web Management Console will not be started until correct password is set! EOT my $MSG_WMCONSOLE_PASS_HINT = <<EOT; You can change password for Kaspersky Web Management Console by executing <B>%1</B> EOT my $MSG_WMCONSOLE_BROWSE_HINT = <<EOT; To open the Kaspersky Anti-Virus web console enter the following address in the address line of the web browser: http://<ip-address-or-domain-name-of-the-protected-server>:9080 EOT #--- my $HEADER_SETUP_UPDATER_SOURCE = <<EOT; Configuring the Anti-Virus Database update source EOT my $MSG_UPDATER_SOURCE_CHANGED = <<EOT; The Anti-Virus Database update source is changed to '%1' EOT my $MSG_UPDATER_SOURCE_CHANGE_FAILED = <<EOT; Cannot set the Anti-Virus Databse update source to '%1' EOT my $MSG_MKDIR_SYSTEMD_FAILED = <<EOT; Cannot create %1 folder for systemd EOT my $MSG_RELOAD_SYSTEMD_FAILED = <<EOT; Failed to reload systemd daemon. For details please run journalctl -xn EOT my $MSG_COPY_SYSTEMD_FAILED = <<EOT; Failed to install %1 into %2 EOT my $MSG_RM_FAILED = <<EOT; Failed to remove '%1': %2 EOT ### my $MSG_CMD_HELP_LOCALE = "-L, --locale\tset up service default locale"; my $MSG_CMD_HELP_WMCONSOLE = "-W, --wmconsole\tchange Web Management Console password"; my $MSG_CMD_HELP_SAMBA = "-S, --samba\tset up the Samba Server real-time protection"; my $MSG_CMD_HELP_BUILD = "-B, --build[=path]\tcompile and install the OAS kernel module, argument is ignored on non-Linux platforms"; my $MSG_AI_HELP_EULA_AGREED = "=yes\tLicense agreement flag, must be 'yes'"; my $MSG_AI_HELP_SERVICE_LOCALE = "=<locale>\tSet up the service default locale"; my $MSG_AI_HELP_INSTALL_KEY_FILE = "=<path>\tPath to key file"; my $MSG_AI_HELP_UPDATER_SOURCE = "=AKServer|KLServers|<url>\tSet up Updater source"; my $MSG_AI_HELP_UPDATER_PROXY = "=no|<url>\tSet up Updater Proxy Server"; my $MSG_AI_HELP_UPDATER_EXECUTE = "=<yes|no>\tRun the Anti-Virus Databases update procedure"; my $MSG_AI_HELP_UPDATER_ENABLE_AUTO = "=<yes|no>\tEnable auto-updates"; my $MSG_AI_HELP_RTP_BUILD_KERNEL_MODULE = "=yes|no\tBuild On-Access kernel module"; my $MSG_AI_HELP_RTP_BUILD_KERNEL_SRCS = "=<path|auto>\tPath to kernel source tree directory or 'auto', ignored on non-Linux platforms"; my $MSG_AI_HELP_RTP_SAMBA_ENABLE = "=yes|no|auto\tEnable integration with Samba server"; my $MSG_AI_HELP_RTP_SAMBA_CONF = "=<path>\tPath to Samba server configuration file"; my $MSG_AI_HELP_RTP_SAMBA_VFS = "=<path>\tPath to Samba server VFS library directory"; my $MSG_AI_HELP_RTP_SAMBA_VFS_MODULE = "=<path>\tPath to VFS module to be installed"; my $MSG_AI_HELP_RTP_START = "=<yes|no>\tStart the Real-Time Protection task"; ### Text strings END ### sub new { my $class = shift; my $self = $class->SUPER::new($APP_ID); unshift @{$self->{'COMMANDS'}}, { 'id' => 'locale', 'spec' => 'L|locale', 'sub' => 'do_setup_service_locale', 'default' => undef, 'descr' => $MSG_CMD_HELP_LOCALE, }; unshift @{$self->{'COMMANDS'}}, { 'id' => 'wmconsole', 'spec' => 'W|wmconsole', 'sub' => 'do_wmconsole_password', 'default' => undef, 'descr' => $MSG_CMD_HELP_WMCONSOLE, }; unshift @{$self->{'COMMANDS'}}, { 'id' => 'samba', 'spec' => 'S|samba', 'sub' => 'do_setup_samba_module', 'default' => undef, 'descr' => $MSG_CMD_HELP_SAMBA, }; unshift @{$self->{'COMMANDS'}}, { 'id' => 'build_oas', 'spec' => 'B|build:s', 'sub' => 'do_build_oas_module', 'default' => undef, 'descr' => $MSG_CMD_HELP_BUILD, }; $self->{'AUTOINSTALL'} = [ { 'id' => 'EULA_AGREED', 'list' => [ 'yes' ], 'required' => 1, 'descr' => $MSG_AI_HELP_EULA_AGREED, }, { 'id' => 'SERVICE_LOCALE', 'type' => 'locale', 'required' => 0, 'descr' => $MSG_AI_HELP_SERVICE_LOCALE, }, { 'id' => 'INSTALL_KEY_FILE', 'type' => 'file', 'required' => 0, 'descr' => $MSG_AI_HELP_INSTALL_KEY_FILE, }, # Updater { 'id' => 'UPDATER_SOURCE', 'type' => 'url', 'list' => [ 'AKServer', 'KLServers' ], 'protocols' => [ 'http', 'ftp' ], 'protocol_requred' => 1, 'required' => 0, 'descr' => $MSG_AI_HELP_UPDATER_SOURCE, }, { 'id' => 'UPDATER_PROXY', 'type' => 'url', 'protocols' => [ 'http' ], 'protocol_requred' => 1, 'list' => [ 'no' ], 'required' => 0, 'descr' => $MSG_AI_HELP_UPDATER_PROXY, }, { 'id' => 'UPDATER_EXECUTE', 'list' => [ 'yes', 'no' ], 'required' => 0, 'default' => 'no', 'descr' => $MSG_AI_HELP_UPDATER_EXECUTE, }, { 'id' => 'UPDATER_ENABLE_AUTO', 'list' => [ 'yes', 'no' ], 'required' => 0, 'default' => 'no', 'descr' => $MSG_AI_HELP_UPDATER_ENABLE_AUTO, }, # Kernel module { 'id' => 'RTP_BUILD_KERNEL_MODULE', 'list' => [ 'yes', 'no' ], 'required' => 1, 'descr' => $MSG_AI_HELP_RTP_BUILD_KERNEL_MODULE, }, { 'id' => 'RTP_BUILD_KERNEL_SRCS', 'type' => 'kernel_srcs', 'list' => [ 'auto' ], 'required' => 0, 'descr' => $MSG_AI_HELP_RTP_BUILD_KERNEL_SRCS, }, # Samba { 'id' => 'RTP_SAMBA_ENABLE', 'list' => [ 'yes', 'no', 'auto' ], 'required' => 1, 'descr' => $MSG_AI_HELP_RTP_SAMBA_ENABLE, }, { 'id' => 'RTP_SAMBA_CONF', 'type' => 'file', 'required' => 0, 'descr' => $MSG_AI_HELP_RTP_SAMBA_CONF, }, { 'id' => 'RTP_SAMBA_VFS', 'type' => 'dir', 'required' => 0, 'descr' => $MSG_AI_HELP_RTP_SAMBA_VFS, }, { 'id' => 'RTP_SAMBA_VFS_MODULE', 'type' => 'file', 'required' => 0, 'descr' => $MSG_AI_HELP_RTP_SAMBA_VFS_MODULE, }, { 'id' => 'RTP_START', 'list' => [ 'yes', 'no' ], 'required' => 0, 'descr' => $MSG_AI_HELP_RTP_START, }, ]; $self->load_settings(); my $bin = sprintf('%s/%s', $self->get_path('bins'), $self->appinfo('product', 'name')); $self->{'SETUP'} = "${bin}-setup.pl"; $self->{'control'} = "${bin}-control"; $self->{'wmcpasswd'} = "${bin}-wmconsole-passwd"; my $sbin = sprintf('%s/%s', $self->get_path('sbins'), $self->appinfo('product', 'name')); $self->{'fwcontrol'} = "${sbin}-supervisor-control"; return $self; } sub _control { my $self = shift; my $control = $self->{'control'}; my @args = @_; foreach (@args) { $_ = KL::Utils::shell_escape($_); } KL::Utils::debug("_control: $control " . join(' ', @args)); system($control, @args); my $ret = $?; if ($ret == -1) { KL::Utils::warning($MSG_CANT_EXECUTE, $control, join(' ', @args), $!); return -128; } elsif ($ret & 127) { $ret &= 127; } else { $ret >>= 8; } return $ret; } sub _control_nout { my $self = shift; my $control = $self->{'control'}; my ($ret, $out) = KL::Utils::execute($control, @_); KL::Utils::warning($MSG_CANT_EXECUTE, $control, join(' ', @_), $!) if $ret == -128; KL::Utils::debug("_control_nout( $control " . join(' ', @_) . " ) = $ret '$out'"); return ($ret, $out); } sub get_task_settings { my $self = shift; my $taskid = shift; my ($ret, $str) = $self->_control_nout('--get-settings', $taskid, @_); if ($ret != 0) { KL::Utils::debug("get_task_settings($taskid) = $ret: $str"); return undef; } my $values = {}; my @lines = split(/\n/, $str); foreach my $line (@lines) { if ($line =~ /^(.*?)=(.*)$/) { my $name = $1; my $value = $2; if ($value =~ /^"(.*)"$/) { $value = $1; } $values->{$name} = $value; } } return $values; } sub set_task_settings { my $self = shift; my $taskid = shift; my @options; while ( @_ ) { my $name = shift; my $value = shift; push @options, "$name=$value"; } my ($ret, $str) = $self->_control_nout('--set-settings', $taskid, @options); KL::Utils::debug("set_task_settings() = $ret: $str"); return $ret == 0; } sub update_task_settings { my $self = shift; my $taskid = shift; my $template = sprintf('%s_%d_XXXXX', $self->appinfo('product', 'name'), $taskid); my (undef, $filename) = File::Temp::tempfile($template, OPEN => 0, SUFFIX => '.ini', DIR => File::Spec->tmpdir()); my ($ret, $str) = $self->_control_nout('--get-settings', $taskid, '--file', $filename, '--file-format', 'INI'); KL::Utils::debug("update_task_settings() get-settings $taskid = $ret: $str"); if ($ret != 0) { unlink($filename) if -f $filename; return 0; } my $opts = KL::Utils::load_ini_file($filename); if (not defined $opts) { KL::Utils::debug("update_task_settings() cant load $filename"); unlink($filename) if -f $filename and not KL::Utils::debug_mode(); return 0; } while ( @_ ) { my $section = ''; my $name = shift; my $value = shift; if ($name =~ /^(.*)\.(.*?)$/) { $section = $1; $name = $2; } $opts->{$section}->{$name} = $value; } if (!KL::Utils::save_ini_file($filename, $opts)) { KL::Utils::debug("update_task_settings() cant update $filename"); unlink($filename) if -f $filename; return 0; } my ($ret, $str) = $self->_control_nout('--set-settings', $taskid, '--file', $filename, '--file-format', 'INI'); KL::Utils::debug("update_task_settings() set-settings $taskid = $ret: $str"); if ($ret != 0) { unlink($filename) if -f $filename and not KL::Utils::debug_mode(); return 0; } unlink($filename) if -f $filename; return 1; } ### override AppBase functions sub check_key_installed { my $self = shift; my ($ret, $message) = $self->_control_nout('--licenser', '--get-installed-keys'); KL::Utils::debug("check_key_installed() = $ret: $message"); return ($ret == 0, $message); } sub check_key_file { my $self = shift; my $file = shift; my ($ret, $message) = $self->_control_nout('--licenser', '--validate-on-install', $file); KL::Utils::debug("check_key_file($file) = $ret: $message"); return ($ret == 0, $message); } sub install_key_file { my $self = shift; my $file = shift; my ($ret, $output) = $self->_control_nout('--licenser', '--install-on-install', $file); KL::Utils::debug("install_key_file($file) = $ret: $output"); return ($ret == 0, $output); } sub get_http_proxy { my $self = shift; my $settings = $self->get_task_settings($TASK_ID_UPDATER, 'CommonSettings.UseProxyForKLServers', 'CommonSettings.ProxyServer', 'CommonSettings.ProxyPort', 'CommonSettings.ProxyAuthType', 'CommonSettings.ProxyAuthUser', 'CommonSettings.ProxyAuthPassword', ); if (defined $settings) { my $use_proxy = $settings->{'CommonSettings.UseProxyForKLServers'}; if ($use_proxy eq 'no') { return (1, 'no'); } my $proxy_server = $settings->{'CommonSettings.ProxyServer'}; my $proxy_port = $settings->{'CommonSettings.ProxyPort'}; my $proxy_server = "$proxy_server:$proxy_port"; my $proxy_auth = $settings->{'CommonSettings.ProxyAuthType'}; if ($proxy_auth ne 'NotRequired') { my $auth = $settings->{'CommonSettings.ProxyAuthUser'}; my $pass = $settings->{'CommonSettings.ProxyAuthPassword'}; $auth = "$auth:$pass" if $pass ne ''; $proxy_server = "$auth\@$proxy_server"; } return (1, $proxy_server); } return (0, $MSG_GET_PROXY_FAILED); } sub set_http_proxy { my $self = shift; my $value = shift; my @options; if (lc($value) eq 'no') { push @options, 'CommonSettings.UseProxyForKLServers', 'no'; } elsif ($value =~ /^(http:\/\/)?((.*?)(:(.*?))?@)?(.*):(\d+)/ ) { my ($user, $pass, $host, $port) = ($3, $5, $6, $7); push @options, 'CommonSettings.UseProxyForKLServers', 'yes'; push @options, 'CommonSettings.ProxyServer', $host; push @options, 'CommonSettings.ProxyPort', $port; if (defined $user) { push @options, 'CommonSettings.ProxyAuthType', 'Plain'; push @options, 'CommonSettings.ProxyAuthUser', $user; push @options, 'CommonSettings.ProxyAuthPassword', $pass; } } else { return (0, KL::Utils::translate_string($MSG_INCORRECT_PROXY_VALUE, $value) ); } return 1 if $self->set_task_settings($TASK_ID_UPDATER, @options); return (0, $MSG_CHANGE_PROXY_FAILED); } sub run_updater { my $self = shift; my $ret; if ( not defined $self->{IS_AUTOINSTALL} ) { $ret = $self->_control_nout('--start-task', $TASK_ID_UPDATER); KL::Utils::debug("run_updater() = $ret"); $ret = $self->_control('--progress', $TASK_ID_UPDATER); } else { $ret = $self->_control('-W', '--start-task', $TASK_ID_UPDATER); KL::Utils::debug("run_updater() = $ret"); } return $ret == 0; } sub set_updater_source { my $self = shift; my $source = shift; my @options; if ($source =~ /KLServers/i) { push @options, 'CommonSettings.SourceType', '"KLServers"'; } elsif ($source =~ /AKServer/i) { push @options, 'CommonSettings.SourceType', '"AKServer"'; } else { push @options, 'CommonSettings:CustomSources.Url', '"' . $source . '"'; push @options, 'CommonSettings:CustomSources.Enabled', 'yes'; push @options, 'CommonSettings.SourceType', '"Custom"'; } $self->ai_save('UPDATER_SOURCE', $source); if ($self->update_task_settings($TASK_ID_UPDATER, @options)) { KL::Utils::output($MSG_UPDATER_SOURCE_CHANGED, $source); return 1; } KL::Utils::error($MSG_UPDATER_SOURCE_CHANGE_FAILED, $source); return 0; } sub enable_autoupdates { my $self = shift; my ($ret, $message) = $self->_control_nout( '--set-schedule', $TASK_ID_UPDATER, 'RuleType=Minutely', 'StartTime=";;30"', ); KL::Utils::debug("enable_autoupdates() = $ret: $message"); if ($ret == 0) { return (1, $MSG_AUTOUPDATE); } else { return (0, $message); }; } sub make_linux_module { my $self = shift; my $kernel_sources = shift; my $module = "kav4fs_oas"; my $module_redir = "redirfs"; my $srcs_dir = $self->get_path('srcs') . '/kernel'; my $os_rev = `uname -r`; $os_rev =~ s/\n//; if (!-d $kernel_sources || !-f $kernel_sources . "/Makefile") { KL::Utils::warning($MSG_OAS_KERNEL_SRCS_NOT_FOUND_AT, $kernel_sources); return; } print KL::Utils::translate_string($MSG_OAS_LINUX_STEP_CONFIGURING, $kernel_sources); my $ret; chdir $srcs_dir; my $cmd = "$srcs_dir/configure"; $cmd .= ' --enable-debug' if KL::Utils::debug(); $cmd .= " --with-kernelsrc=${kernel_sources}"; $ret = system($cmd); return if ($ret); print "\n" . $MSG_OAS_LINUX_STEP_COMPILING; system('make clean'); $ret = system('make all'); if ($ret) { KL::Utils::warning($MSG_OAS_LINUX_COMPILE_ERROR); return; } my $modules_path = "/lib/modules/${os_rev}/misc"; if (!-d $modules_path) { $ret = mkdir($modules_path, 0755); if (!$ret) { KL::Utils::warning($MSG_OAS_LINUX_MKDIR_ERROR, $modules_path); return; } } my $module_name; if (-f "bin/$module.o") { $module_name = "$module.o"; } elsif (-f "bin/$module.ko") { $module_name = "$module.ko"; } if (not defined $module_name) { KL::Utils::warning($MSG_OAS_LINUX_CANT_FIND_MODULE); return; } my $module_redir_name; if (-f "bin/$module_redir.o") { $module_redir_name = "$module_redir.o"; } elsif (-f "bin/$module_redir.ko") { $module_redir_name = "$module_redir.ko"; } if (not defined $module_redir_name) { KL::Utils::debug($MSG_OAS_LINUX_CANT_FIND_REDIR_MODULE); #return; } my $dstpath = "$modules_path/$module_name"; my $dst_redir_path = ""; if (defined $module_redir_name) { $dst_redir_path = "$modules_path/$module_redir_name"; } { print "\n" . KL::Utils::translate_string($MSG_OAS_LINUX_STEP_INSTALL, $dstpath); chown("root", "bin/$module_name"); KL::Utils::copy_file("bin/$module_name", $dstpath); } if (defined $module_redir_name) { print "\n" . KL::Utils::translate_string($MSG_OAS_LINUX_STEP_INSTALL, $dst_redir_path); chown("root", "bin/$module_redir_name"); KL::Utils::copy_file("bin/$module_redir_name", $dst_redir_path); } print $MSG_OAS_LINUX_STEP_REBUILD_DEPS; system("/sbin/depmod -a"); system("/sbin/rmmod $module > /dev/null 2>&1"); system("/sbin/rmmod $module_redir > /dev/null 2>&1"); print $MSG_OAS_LINUX_STEP_PROBE; $ret = system("/sbin/modprobe $module"); if ($ret != 0) { print KL::Utils::translate_string($MSG_OAS_LINUX_STEP_DELETE, $dstpath); unlink($dstpath); KL::Utils::warning($MSG_OAS_LINUX_BUILD_FAILED, $module, $self->{'SETUP'}); return; } print KL::Utils::translate_string($MSG_OAS_LINUX_STEP_UNLOAD, $module); system("/sbin/rmmod $module"); #TODO: when these modules will be unloadable, uncomment lines below #print KL::Utils::translate_string($MSG_OAS_LINUX_STEP_UNLOAD, $module_redir); #system("/sbin/rmmod $module_redir"); $self->settings('OAS_KERNELMODULE', $dstpath); $self->settings('OAS_KERNELMODULE_REDIR', $dst_redir_path) if (defined $module_redir_name); return 1; } sub make_freebsd_module { my $self = shift; my $ret; my $os=`uname -r`; my $srcs_dir = $self->get_path('srcs') . '/kernel'; my $module = "kav4fs_oas"; if (! chdir $srcs_dir) { KL::Utils::error("Can't change dir to %1", $srcs_dir); return; } if ( (! -d "${srcs_dir}/bin") && (! mkdir("${srcs_dir}/bin")) ) { KL::Utils::error("Can't create dir %1", "$srcs_dir/bin"); return; } print $MSG_OAS_FREEBSD_STEP_CONFIGURE; my $cmd = "$srcs_dir/configure"; $cmd .= ' --enable-debug' if KL::Utils::debug(); $ret = system($cmd); return if ($ret); print $MSG_OAS_FREEBSD_STEP_COMPILE; system("make clean"); $ret = system("make"); if ($ret) { KL::Utils::warning($MSG_OAS_FREEBSD_COMPILE_ERROR, $module); return; } my $dstpath; if ($os =~ /^4\.*/) { $dstpath = "/modules/$module.ko"; } else { $dstpath = "/boot/kernel/$module.ko"; } KL::Utils::copy_file("bin/$module.ko", $dstpath); print $MSG_OAS_FREEBSD_STEP_PROBE; $ret = system("kldload $module"); if ($ret != 0) { print KL::Utils::translate_string($MSG_OAS_FREEBSD_STEP_DELETE, $dstpath); unlink($dstpath); KL::Utils::warning($MSG_OAS_FREEBSD_BUILD_FAILED, $module); return; } $self->settings('OAS_KERNELMODULE', $dstpath); print $MSG_OAS_FREEBSD_STEP_UNLOAD; system("kldunload $module"); return 1; } sub _set_oas_protection { my $self = shift; my $enable = shift; my $settings = $self->get_task_settings($TASK_ID_OAS, 'ProtectionType'); my $current = $settings->{'ProtectionType'}; my $type = 'Full'; if ($enable) { $type = ($current eq 'SambaOnly') ? 'Full' : 'KernelOnly'; } else { $type = 'SambaOnly'; KL::Utils::warning ($MSG_OAS_DISABLED_WARN); } $self->set_task_settings($TASK_ID_OAS, 'ProtectionType', $type) if $current ne $type; } sub _set_samba_protection { my $self = shift; my $enable = shift; # Setting up protection type in OAS task my $settings = $self->get_task_settings($TASK_ID_OAS, 'ProtectionType'); my $current = $settings->{'ProtectionType'}; my $type = 'SambaOnly'; if ($enable) { $type = 'Full' if $current eq 'KernelOnly'; } else { $type = 'KernelOnly' if $current eq 'Full'; } $self->set_task_settings($TASK_ID_OAS, 'ProtectionType', $type) if $current ne $type; } sub ai_validate_kernel_srcs { my $self = shift; my $rule = shift; my $value = shift; if ($^O !~ /linux/i) { return 1; } if (-d $value && -f "$value/Makefile") { return 1; } return (0, "is not a path to Linux kernel sources"); } sub find_kernel_sources { my $self = shift; # try to find kernel sources my $os_name = KL::Utils::get_os_name(); my $os_rev = `uname -r`; $os_rev =~ s/\n//; my $kernel_srcs = "/lib/modules/$os_rev/build"; if (!-d "$kernel_srcs") { if (-d "/usr/src/kernel-headers-$os_rev") { $kernel_srcs = "/usr/src/kernel-headers-$os_rev"; } elsif (-d "/usr/src/linux" && ($os_name =~ /ALT/ || $os_name =~ /Debian/)) { $kernel_srcs = "/usr/src/linux"; } } if ($self->ai_validate_kernel_srcs($kernel_srcs)) { return $kernel_srcs; } return undef; } sub build_kernel_module { my $self = shift; my $kernel_srcs = shift; my $setup_cmd = $self->{'SETUP'}; my $ok = 0; if ($^O =~ /linux/i) { $ok = $self->make_linux_module($kernel_srcs); } elsif ($^O =~ /freebsd/i) { $ok = $self->make_freebsd_module(); } else { KL::Utils::error(1, $MSG_OAS_OS_NOT_SUPPORTED, $^O); } if ($ok) { $self->_set_oas_protection(1); } return $ok; } sub do_build_oas_module { my $self = shift; my $args = shift; KL::Utils::header($HEADER_SETUP_OAS); my $setup_cmd = $self->{'SETUP'}; my $srcs_dir = $self->get_path('srcs') . '/kernel'; if ( ! -x "$srcs_dir/configure" ) { KL::Utils::warning ($MSG_OAS_CONFIGURE_NOT_FOUND . $MSG_OAS_MODULE_WARN, $setup_cmd, $srcs_dir); return 0; } my $kernel_srcs = $args->{'build_oas'}; if ( not defined $kernel_srcs ) { if (KL::Utils::ask_boolean('yes', $MSG_OAS_MODULE_CONFIRM) == 0) { if (KL::Utils::ask_boolean('no', $MSG_OAS_DISABLE_CONFIRM) != 0) { $self->_set_oas_protection(0); } KL::Utils::error($MSG_OAS_MODULE_WARN, $setup_cmd); return 0; } } my $ok = 1; my $gcc = KL::Utils::which('gcc'); if ( length($gcc)<1 ) { KL::Utils::warning($MSG_OAS_GCC_NOT_FOUND); $ok = 0; }; my $make = KL::Utils::which('make'); if ( length($make)<1 ) { KL::Utils::warning($MSG_OAS_MAKE_NOT_FOUND); $ok = 0; } if ($ok) { if ($^O =~ /linux/i) { if ($kernel_srcs eq '') { $kernel_srcs = $self->find_kernel_sources(); if (defined $kernel_srcs) { # found, ask for confirm or new path $kernel_srcs = KL::Utils::ask_question ($kernel_srcs, $MSG_OAS_ENTER_LINUX_PATH); return if $kernel_srcs =~ /^s*cancel\s*$/i; } else { $kernel_srcs = 'cancel'; } while (1) { my $location = $MSG_OAS_KERNEL_SRCS_DEF_LOCATIONS; if ($kernel_srcs ne 'cancel') { if ($self->ai_validate_kernel_srcs($kernel_srcs)) { last; } $location = $kernel_srcs; } KL::Utils::warning($MSG_OAS_KERNEL_SRCS_NOT_FOUND_AT, $location); $kernel_srcs = KL::Utils::ask_question ($kernel_srcs, $MSG_OAS_ENTER_ANOTHER_LINUX_PATH); return if $kernel_srcs =~ /^s*cancel\s*$/i; } } } $self->ai_save('RTP_BUILD_KERNEL_MODULE', 'yes'); $self->ai_save('RTP_BUILD_KERNEL_SRCS', $kernel_srcs); $ok = $self->build_kernel_module($kernel_srcs); } if ($ok) { $self->_set_oas_protection(1); } else { KL::Utils::warning ($MSG_OAS_MODULE_WARN, $setup_cmd); } return $ok; } sub is_module_loaded { my $self = shift; my $module = shift; if ($^O =~ /linux/i) { my $modules = KL::Utils::read_file('/proc/modules'); return 1 if $modules =~ /^$module\s/m; } return 0; } sub do_remove_oas_module { my $self = shift; my $os_rev = `uname -r`; $os_rev =~ s/\n//; my $module = "kav4fs_oas"; my $module_redir = "redirfs"; if ($^O =~ /linux/i) { system("/sbin/rmmod $module") if $self->is_module_loaded($module); #TODO: Uncomment next line when unloading module will be fixed #system("/sbin/rmmod $module_redir") if $self->is_module_loaded($module_redir); } else { system("kldunload $module"); } my $oasmodule = $self->settings('OAS_KERNELMODULE'); if (defined $oasmodule) { unlink($oasmodule) if -f $oasmodule; $self->remove_settings('OAS_KERNELMODULE'); } $oasmodule = $self->settings('OAS_KERNELMODULE_REDIR'); if (defined $oasmodule) { unlink($oasmodule) if -f $oasmodule; $self->remove_settings('OAS_KERNELMODULE_REDIR'); } } sub start_oas { my $self = shift; KL::Utils::header($HEADER_START_OAS); $self->ai_save('RTP_START', 'yes'); my $ret = $self->_control('--start-task', $TASK_ID_OAS); return $ret == 0; } ### Service locale setup ### sub _find_default_locale { my ($ret, $all_locales) = KL::Utils::execute('locale', '-a'); my @locales = split("\n", $all_locales); for my $lang (qw(en_US en_GB de_DE fr_FR it_IT ru_RU ja_JP)) { my @found = grep {/^$lang\.((?i)UTF-?8)$/} @locales; for my $locale (@found) { if ( ! -d '/etc/locale' || -d "/etc/locale/${locale}" ) { return $locale; } } } return ""; } sub _is_valid_locale { my $locale = shift; if ( -d '/etc/locale' ) { return ( -d "/etc/locale/${locale}" ) ? 1 : 0; } my ($ret, $all_locales) = KL::Utils::execute('locale', '-a'); return ( grep {/^\Q$locale\E$/} split("\n", $all_locales) ) ? 1 : 0; } sub ai_validate_locale { my $self = shift; my $rule = shift; my $value = shift; if ( _is_valid_locale($value) ) { return 1; } return (0, undef); } sub set_service_locale { my $self = shift; my $locale = shift; $self->settings('SERVICE_LOCALE', $locale); KL::Utils::output($MSG_SERVICE_LOCALE_CHANGED, $locale); my $restarted = 0; my $rcd = $self->appinfo('supervisor', 'rcd'); if (KL::Utils::is_linux()) { my ($ret, $out) = KL::Utils::execute($rcd, 'status'); if ($ret == 0) { system("$rcd restart"); $restarted = 1; } } elsif (KL::Utils::is_freebsd()) { my ($ret, $out) = KL::Utils::execute($rcd, 'onestatus'); if ($ret == 0) { system("$rcd onerestart"); $restarted = 1; } } if ($restarted) { my $fwcontrol = $self->{'fwcontrol'}; my $appname = $self->appinfo('product', 'title'); KL::Utils::output($MSG_WAIT_AFTER_RESTART, $appname); my $ready = 0; for (my $timeout = 0; $timeout < 60; $timeout++) { my ($ret, $out) = KL::Utils::execute($fwcontrol, '--get-app-list'); KL::Utils::debug("$fwcontrol --get-app-list = $ret '$out'"); if ($ret == 0) { if ($out =~ /^product_id:$APP_ID\s.*\sstate:Started$/) { $ready = 1; last; } } sleep(1); } if (!$ready) { KL::Utils::error($MSG_ERROR_NOTREADY_AFTER_RESTART, $appname); } } $self->ai_save('SERVICE_LOCALE', $locale); } sub do_setup_service_locale { my $self = shift; KL::Utils::header($HEADER_SERVICE_LOCALE); my $deflocale = $self->settings('SERVICE_LOCALE'); $deflocale = _find_default_locale() if not defined $deflocale; my $hint = (-d '/etc/locale') ? $MSG_SERVICE_LOCALE_HINT_ETC : $MSG_SERVICE_LOCALE_HINT_LIST; my $locale; while (1) { $locale = KL::Utils::ask_question ($deflocale, $MSG_SERVICE_ASK_LOCALE); last if _is_valid_locale($locale); KL::Utils::error($MSG_SERVICE_BAD_LOCALE, $locale, $hint); print "\n"; } $self->set_service_locale($locale); } sub setup_service_locale { my $self = shift; my $locale = $self->settings('SERVICE_LOCALE'); return if defined $locale; $self->do_setup_service_locale(); } ### Upgrade config files ### sub upgrade_config_files { my $self = shift; my $upgrd_ctl = new KL::Upgrade( 'converter_bin' => $self->get_path('libexec') . "/converter", 'logger' => $self ); if (!$upgrd_ctl->do_upgrade()) { KL::Utils::warning($MSG_UPGRADE_MODULE_WARN, $self->get_applog_path()); return 0; } return 1; } sub do_wmconsole_password { my $self = shift; KL::Utils::header($HEADER_WMCONSOLE); my $passwd = $self->get_path('var') . '/wmconsole/admin.passwd'; if (not -f $passwd) { KL::Utils::warning($MSG_WMCONSOLE_WARN_PASSWORD_NOT_SET); print "\n"; } my $result = 0; while (1) { my $answer = KL::Utils::ask_boolean ('no', $MSG_WMCONSOLE_PASS_CONFIRM); if ($answer == 0) { last; } $result = system($self->{'wmcpasswd'}) == 0; print "\n"; last if $result; } my $started = $self->start_wmconsole_service(); if ($started) { KL::Utils::output ($MSG_WMCONSOLE_BROWSE_HINT); print "\n"; } KL::Utils::output ($MSG_WMCONSOLE_PASS_HINT, $self->{'wmcpasswd'}); print "\n"; return $result; } sub start_wmconsole_service { my $self = shift; my $rcd = sprintf('%s/%s-wmconsole', $self->get_path('rcd'), $self->appinfo('product', 'name')); my ($action, $ret, $out); if (KL::Utils::is_freebsd()) { $rcd .= '.sh'; $action = 'onestatus'; ($ret, $out) = KL::Utils::execute($rcd, $action); if ($ret == 0) { # started already print "$out\n"; return 1; } elsif ($ret == 1) { # not started $action = 'onestart'; system($rcd, $action); ($ret, $out) = ($?, $!); } } else { $action = 'start'; system($rcd, $action); ($ret, $out) = ($?, $!); } print "\n"; if ($ret == 0) { return 1; } if ($ret == -1 or $ret == 127) { KL::Utils::warning($MSG_CANT_EXECUTE, $rcd, $action, $out); } return 0; } sub set_wmconsole_password { my $self = shift; my $passwd = $self->get_path('var') . '/wmconsole/admin.passwd'; return if -f $passwd; return $self->do_wmconsole_password(); } ### # Auto-installation error codes: # # Fatal errors: # 61: Cannot find Linux kernel sources # 62: Build of Linux kernel modules is failed # 63: Samba server configuring failed # # Non-fatal errors: # 71: License key file is not installed # 72: Error occured on changing updater source # 73: Error occured on changing proxy server # 74: Error occured on downloading bases # 75: Error occured on enable auto-updates # 76: Real-time protection task start failed ### sub do_auto_install { my $self = shift; my ($opt, $res, $message); $self->do_systemd_register('supervisor'); $self->do_systemd_register('wmconsole'); # check EULA agreement $opt = $self->ai_value('EULA_AGREED'); if ($opt ne 'yes') { KL::Utils::error('EULA is not agreed'); return 0; } $self->settings('EULA_AGREED', 'yes'); $self->save_settings(); # change service locale (if is assigned) $opt = $self->ai_value('SERVICE_LOCALE'); if (defined $opt) { $self->set_service_locale($opt); } # install key file (if is assigned) $opt = $self->ai_value('INSTALL_KEY_FILE'); if (defined $opt) { if (!$self->install_key( $opt )) { $self->_ai_error(71); } } # setting up and start updater task $opt = $self->ai_value('UPDATER_SOURCE'); if (defined $opt) { KL::Utils::header($HEADER_SETUP_UPDATER_SOURCE); ($res, $message) = $self->set_updater_source($opt); if (!$res) { $self->_ai_error(72); } } $opt = $self->ai_value('UPDATER_PROXY'); if (defined $opt) { if (! $self->setup_proxy($opt)) { $self->_ai_error(73); } } $opt = $self->ai_value('UPDATER_EXECUTE'); if ($opt eq 'yes') { if (! $self->download_bases(1)) { $self->_ai_error(74); } } $opt = $self->ai_value('UPDATER_ENABLE_AUTO'); if ($opt eq 'yes') { if (!$self->setup_autoupdates(1)) { $self->_ai_error(75); } } # build kernel module $opt = $self->ai_value('RTP_BUILD_KERNEL_MODULE'); if (defined $opt and $opt eq 'yes') { KL::Utils::header($HEADER_SETUP_OAS); my $kernel_srcs = $self->ai_value('RTP_BUILD_KERNEL_SRCS'); if ($kernel_srcs eq 'auto') { $kernel_srcs = $self->find_kernel_sources(); if (not defined $kernel_srcs) { KL::Utils::error($MSG_OAS_KERNEL_SRCS_NOT_FOUND); $self->_ai_error(61); } } if (not $self->build_kernel_module($kernel_srcs)) { $self->_ai_error(62); } } # build Samba module $opt = $self->ai_value('RTP_SAMBA_ENABLE'); if (defined $opt and $opt ne 'no') { $res = $self->do_autoinstall_samba_module(); if (!$res) { $self->_ai_error(63); } } $opt = $self->ai_value('RTP_START'); if ($opt eq 'yes') { my $res = $self->start_oas(); if (!$res) { $self->_ai_error(76); } } return 1; } sub do_systemd_register { my $self = shift; my $name = shift; my $ret = 0; my $sysdpath = '/etc/systemd/system'; $ret = system('ps -p 1 -o comm= | grep systemd 2>/dev/null 1>/dev/null'); if ($ret == 0 and -d $sysdpath) { # systemd is implemented on this host, copying configuration file my $srcpath = $self->get_path('systemd') . '/' . $self->appinfo('product','name') . '-' . $name . '.conf'; my $dstpath = $sysdpath . '/' . $self->appinfo('product','name') . '-' . $name . '.service.d'; if (!-d $dstpath) { $ret = mkdir($dstpath, 0755); if (!$ret) { KL::Utils::warning($MSG_MKDIR_SYSTEMD_FAILED, $dstpath); return; } } $ret = KL::Utils::copy_file( $srcpath, $dstpath ); if ($ret) { KL::Utils::warning($MSG_COPY_SYSTEMD_FAILED, $srcpath, $dstpath); return; } $ret = system('systemctl daemon-reload'); KL::Utils::warning($MSG_RELOAD_SYSTEMD_FAILED) if $ret; } } sub do_systemd_unregister { my $self = shift; my $name = shift; my $systemd_folder = '/etc/systemd/system/' . $self->appinfo('product','name') . '-' . $name . '.service.d'; my $systemd_conf = $systemd_folder . '/' . $self->appinfo('product','name') . '-' . $name . '.conf'; my $ret = system('ps -p 1 -o comm= | grep systemd 2>/dev/null 1>/dev/null'); if ($ret == 0 and -d $systemd_folder) { unlink($systemd_conf) or KL::Utils::warning($MSG_RM_FAILED, $systemd_conf, $!); my $ret = system('systemctl daemon-reload'); KL::Utils::warning($MSG_RELOAD_SYSTEMD_FAILED) if $ret; rmdir($systemd_folder) or KL::Utils::warning($MSG_RM_FAILED, $systemd_folder, $!); } } sub do_postinstall { my $self = shift; # make sure configuration file is updated for systemd $self->do_systemd_register('supervisor'); # show application license $self->show_EULA( $self->get_path('docs') . '/LICENSE' ); # setting up service locale $self->setup_service_locale(); # install key file (if requred) $self->install_key(); # start updater task $self->setup_proxy(); $self->download_bases(); $self->setup_autoupdates(); # build kernel module $self->do_build_oas_module(); # setting up Samba module $self->do_setup_samba_module(); # setting up WM Console password $self->set_wmconsole_password(); # upgrade config files from old versions of application # $self->upgrade_config_files(); # start oas task my $res = $self->start_oas(); return $res; } sub do_uninstall { my $self = shift; $self->do_remove_oas_module(); $self->do_remove_samba_module(); $self->do_systemd_unregister('supervisor'); $self->do_systemd_unregister('wmconsole'); return 1; } 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