opt
/
kaspersky
/
kav4fs
/
libexec
➕ New
📤 Upload
✎ Editing:
kav4fs-uninstall.pl
← Back
#!/usr/bin/env perl # # Configration script for a Kaspersky application # Copyright (C) Kaspersky Lab 2003-2009 # use strict; $| = 1; BEGIN { my $appname; $appname = $1 if $0 =~ /.*[\/](\w+)-(\w+)(\.pl)?$/; my $lib = ($^O !~ /^freebsd$/i) ? "/opt/kaspersky/$appname/lib/perl" : "/usr/local/lib/kaspersky/$appname/perl"; unshift @INC, $lib; } use locale; use KL::IniFile; use KL::Utils; sub hex2ascii { my $hexString = shift; $hexString =~ s/\$HEX_//; my @codes = unpack "a2" x (length($hexString)/2), $hexString; my $result = pack("C*", map hex, @codes ); $result; } use constant { SUCCESS => 0, NEEDREBOOT => 1, NOBINARIES => 2, PKGMGRERROR => 3, WALLFAILED => 4, }; my $LOGFILE="/var/log/kaspersky/klnagent/uninstall.log"; my %kpd = KL::IniFile::load("setup.kpd"); my %ini = KL::IniFile::load("klrbtagt.ini"); my $RebootMsg = hex2ascii(KL::IniFile::get_value(\%ini,"Action","AskRebootMsg")); my $PkgMan = KL::IniFile::get_value(\%kpd, "Uninstall", "PkgMan"); my $reboot_msg = KL::IniFile::get_value(\%kpd, "Uninstall", "RebootMsg") or die("No reboot message"); my $RebootImmediately = KL::IniFile::get_value(\%ini, "Action", "RebootImmediately"); my $AskReboot = KL::IniFile::get_value(\%ini, "Action", "AskReboot"); my $AskRebootPeriod = KL::IniFile::get_value(\%ini, "Action", "AskRebootPeriod"); my $ForceReboot = KL::IniFile::get_value(\%ini, "Action", "ForceReboot"); my $ForceRebootTime = KL::IniFile::get_value(\%ini, "Action", "ForceRebootTime"); my $Product = KL::IniFile::get_value(\%kpd, "Product", "Name"); sub exit_on_print { my $err = shift; my $msg = KL::IniFile::get_value(\%kpd, "UninstallResults","$err"); report($msg); print $msg; exit($err); } sub which { my $binary = shift; my @folders = ('/bin/','/sbin/','/usr/bin/','/usr/sbin/','/usr/local/bin/','/usr/local/sbin/'); foreach my $folder (@folders) { my $test_file = "${folder}${binary}"; if ( -x $test_file ) { return $test_file; } } report("Could not find binary $binary"); exit_on_print(NOBINARIES); } sub get_remove_command { my $pkgmgr = shift; return ($pkgmgr =~ /RPM/) ? which("rpm") . " -e " : which("dpkg") . " -r"; } sub get_query_command { my $pkgmgr = shift; return ($pkgmgr =~ /RPM/) ? which("rpm") . " -q " : which("dpkg") . " -s"; } sub report { my $date = localtime(); my $msg = shift; open(LOG, ">>$LOGFILE") or return; print LOG "[${date}] $msg\n"; close(LOG); } exit_on_print(2, "Script started without root privileges") if ($< != 0); my $invoker = $ARGV[0] || "-sh"; my $WALL_CMD = which("wall"); my $REBOOT_CMD = which("shutdown"); my $PKG_CMD = ""; my $PKG_QUERY= get_query_command($PkgMan); if (system("$PKG_QUERY $Product 2>&1 > /dev/null") == 0) { $PKG_CMD = get_remove_command($PkgMan) . " ${Product}"; } elsif (system("$PKG_QUERY ${Product}:i386 2>&1 > /dev/null") == 0) { $PKG_CMD = get_remove_command($PkgMan) . " ${Product}:i386"; } else { exit_on_print(PKGMGRERROR); } my $rc = 0; report("Running $PKG_CMD..."); if (system($PKG_CMD) != 0) { exit_on_print(PKGMGRERROR); } report("$PKG_CMD has completed,"); if ($invoker =~ /^-ak$/) { if ($RebootImmediately =~ /1/){ system("$REBOOT_CMD -r 1&"); } if ($ForceReboot =~ /1/ && $AskReboot =~ /1/) { report("System will reboot in $ForceRebootTime minutes."); system("$REBOOT_CMD -r $ForceRebootTime \"$reboot_msg\"&"); exit_on_print(SUCCESS); } my $pid = fork(); if ($pid == 0) { while ($AskReboot =~ /1/) { print "Sending: $reboot_msg\n"; open my $WALL => "| $WALL_CMD"; print $WALL "$reboot_msg\n"; close $WALL; if ($AskRebootPeriod =~ /^0/) { exit(0); } select(undef, undef, undef, $AskRebootPeriod * 60); } exit(0); } elsif ($pid == undef) { report("Failed to inform users"); exit_on_print(4); } exit_on_print(SUCCESS); } exit_on_print(SUCCESS);
💾 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