def wxUpdateVirDB(parent, config, autoClose=False): exit_code = -1 freshclam_conf = Utils.SaveFreshClamConf(config) if not len(freshclam_conf): MsgBox.ErrorBox( parent, 'Unable to create freshclam configutration file. Please check there is enough space on the disk' ) return updatelog = tempfile.mktemp() dbdir = config.Get('ClamAV', 'Database') # create database folder before downloading if not os.path.exists(dbdir): try: os.makedirs(dbdir) except: pass cmd = '--show-progress --stdout --datadir="' + dbdir + '"' + \ ' --config-file="%s" --log="%s"' % (freshclam_conf, updatelog) if config.Get('ClamAV', 'Debug') == '1': cmd += ' --debug' cmd = '"%s" %s' % (config.Get('ClamAV', 'FreshClam'), cmd) if sys.platform.startswith('win') and config.Get('UI', 'TrayNotify') == '1': import win32gui tray_notify_params = (( 'Virus Database has been updated.', 0, win32gui.NIIF_INFO, 10000 ), ('An error occured during Virus Database Update. Please review the update report.', 1, win32gui.NIIF_WARNING, 30000)) else: tray_notify_params = None dlg = wxDialogStatus.create(parent, cmd, None, 'n', 'update', tray_notify_params) dlg.SetTitle('ClamWin Free Antivirus: Downloading Update...') dlg.SetAutoClose(autoClose) try: dlg.ShowModal() exit_code = dlg.GetExitCode() maxsize = int(config.Get('ClamAV', 'MaxLogSize')) * 1048576 logfile = config.Get('Updates', 'DBUpdateLogFile') Utils.AppendLogFile(logfile, updatelog, maxsize) finally: try: os.remove(updatelog) print updatelog except Exception, e: print 'Unable to remove file %s. Error: %s' % (updatelog, str(e)) dlg.Destroy() try: os.remove(freshclam_conf) except Exception, e: print "couldn't remove file %s. Error: %s" % (freshclam_conf, str(e))
def wxScan(parent, config, path, autoClose=False): exit_code = -1 scanlog = tempfile.mktemp() cmd = Utils.GetScanCmd(config, path, scanlog) try: priority = config.Get('ClamAV', 'Priority')[:1].lower() except: priority = 'n' #check if we have downloaded the virus database and bail out if not hasdb = Utils.CheckDatabase(config) if not hasdb: if config.Get('UI', 'TrayNotify') == '1': import win32gui tray_notify_params = (( 'Virus Definitions Database Not Found! Please download it now.', -1, win32gui.NIIF_ERROR, 30000), None) # show balloon Utils.ShowBalloon(-1, tray_notify_params) #add to logfile logfile = config.Get('ClamAV', 'LogFile') if logfile != '': file(scanlog, 'wt').write( '\n-----------------------------\n' 'Scan Started %s\nERROR: Virus Definitions Database Not Found! Please download it now.\n' '-----------------------------' % time.asctime()) maxsize = int(config.Get('ClamAV', 'MaxLogSize')) * 1048576 Utils.AppendLogFile(logfile, scanlog, maxsize) os.remove(scanlog) return if config.Get('UI', 'TrayNotify') == '1': import win32gui tray_notify_params = (( 'Virus has been detected during scan! Please review the scan report.', 1, win32gui.NIIF_ERROR, 30000 ), ('An error occured during virus scan. Please review the scan report.', 0, win32gui.NIIF_WARNING, 30000)) else: tray_notify_params = None dlg = wxDialogStatus.create(parent, cmd, scanlog, priority, "scanprogress", tray_notify_params) dlg.SetTitle("ClamWin Free Antivirus: Scanning...") dlg.SetAutoClose(autoClose, 0) try: dlg.ShowModal() exit_code = dlg.GetExitCode() maxsize = int(config.Get('ClamAV', 'MaxLogSize')) * 1048576 logfile = config.Get('ClamAV', 'LogFile') Utils.AppendLogFile(logfile, scanlog, maxsize) # send email alert if config.Get('EmailAlerts', 'Enable') == '1': try: print 'Exit Code:', exit_code if exit_code == 1: msg = EmailAlert.ConfigVirusAlertMsg(config, (scanlog, )) msg.Send() except Exception, e: print 'Could not send email alert. Error: %s' % str(e) finally: if os.path.exists(scanlog): try: os.remove(scanlog) except IOError, e: print 'could not delete logfile : %s. Error: %s' % (scanlog, str(e)) dlg.Destroy() return exit_code