Exemplo n.º 1
0
def configure_clamav_conf(service):
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        log_root, err = common.get_clamav_log_folder_path()
        if err:
            raise Exception(err)
        with open('%s/config/%s.conf.default' % (root, service), 'r') as f:
            conf = f.read()
        with open('%s/config/%s.conf' % (root, service), 'w') as f:
            f.write(conf)
        conf_dict, err = get_clamav_conf(service)
        if err:
            raise Exception(err)
        for key, value in conf_dict.items():
            if key == 'LogFile':
                conf_dict[key] = '%s/clamd.log' % log_root
        status, err = update_clamav_conf(conf_dict, service)
        if err:
            raise Exception(err)
        ret_val = status
    except Exception, e:
        return None, 'Error making clamav conf file: %s' % str(e)
Exemplo n.º 2
0
def update_scan_list(name, activity):
    if activity not in ['add', 'remove']:
        raise Exception('Invalid activity')
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        if not os.path.isfile('%s/scan_list.txt' % root):
            cmd = 'touch %s/scan_list.txt' % root
            status, err = command.get_command_output(cmd)
            if err:
                raise Exception(err)
        old_status, err = in_scan_list(name)
        if err:
            raise Exception(err)
        path_name, err = file_processing.normalise_path(name)
        if err:
            raise Exception(err)
        if activity == 'add' and not old_status:
            with open('%s/scan_list.txt' % root, 'a') as f:
                f.write('%s\n' % path_name)
            ret_val = True
        elif activity == 'remove' and old_status:
            with open('%s/scan_list.txt' % root, 'r') as f:
                lines = f.readlines()
            with open('%s/scan_list.txt' % root, 'w') as f:
                for line in lines:
                    if line.strip('\n') != '%s' % path_name:
                        f.write(line)
            ret_val = False
    except Exception, e:
        return ret_val, 'Error updating virus scan list: %s' % str(e)
Exemplo n.º 3
0
def get_clamav_conf(service):
    ret_val = None
    try:
        if service not in ['clamd', 'freshclam']:
            raise Exception('Invalid clamav service')
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        if not os.path.isfile('%s/config/%s.conf' % (root, service)):
            status, err = configure_clamav_conf(service)
            if err:
                raise Exception(err)
        with open('%s/config/%s.conf' % (root, service), 'r') as f:
            conf = f.read()
        conf_list = conf.split('\n')
        conf_dict = dict()
        for i in conf_list:
            if i == '':
                pass
            elif i[0] == '#':
                pass
            else:
                entry = i.split(' ')
                if entry[0] not in ['VirusEvent', 'OnOutdatedExecute']:
                    conf_dict.update({entry[0]: entry[1]})
        ret_val = conf_dict
    except Exception, e:
        return None, 'Error retriving %s conf: %s' % (service, str(e))
Exemplo n.º 4
0
def restore_default_clamav_conf():
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        with open('%s/config/clamd.conf.default' % root, 'r') as f:
            lines = f.read()
        with open('%s/config/clamd.conf' % root, 'w') as f:
            f.write(lines)
        with open('%s/config/freshclam.conf.default' % root, 'r') as f:
            lines = f.read()
        with open('%s/config/freshclam.conf' % root, 'w') as f:
            f.write(lines)
        ret_val = True
    except Exception, e:
        return None, 'Error restoring default configuration: %s' % str(e)
Exemplo n.º 5
0
def get_clamav_cron_id():
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        if not os.path.isfile('%s/cron_id' % root):
            cmd = 'touch %s/cron_id' % root
            status, err = command.get_command_output(cmd)
        with open('%s/cron_id' % root, 'r') as f:
            cron_task_id = f.read()

        if cron_task_id == '':
            ret_val = None
        else:
            ret_val = int(cron_task_id)
    except Exception, e:
        return None, 'Error retriving cron id: %s' % str(e)
Exemplo n.º 6
0
def update_clamav_conf(conf_dict, service):
    ret_val = None
    try:
        if service not in ['clamd', 'freshclam']:
            raise Exception('Invalid clamav service')
        script_root, err = common.get_python_scripts_path()
        if err:
            raise Exception(err)
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        st = None
        with open('%s/config/%s.conf' % (root, service), 'w') as f:
            for key, value in conf_dict.items():
                f.write('%s %s\n' % (key, value))
            if service == 'clamd':
                f.write('VirusEvent %s/av_event_virus_found.py "%%v"\n' %
                        script_root)
                if os.path.isfile('/etc/clamd.d/scan.conf'):
                    os.unlink('/etc/clamd.d/scan.conf')
                os.symlink('%s/config/%s.conf' % (root, service),
                           '/etc/clamd.d/scan.conf')
                service = 'clamd@scan'
                action = 'restart'
                status, err = services_management.change_service_status(
                    service, action)
                if err:
                    raise Exception(err)
            elif service == 'freshclam':
                f.write(
                    'OnOutdatedExecute %s/av_event_update_available.py "%%v"\n'
                    % script_root)
                if os.path.isfile('/etc/freshclam.conf'):
                    os.unlink('/etc/freshclam.conf')
                os.symlink('%s/config/%s.conf' % (root, service),
                           '/etc/freshclam.conf')
                command.get_command_output('killall freshclam')
                cmd = 'freshclam -d'
                status, err = command.get_command_output(cmd)
                if err:
                    raise Exception(err)
    except Exception, e:
        return None, 'Error writing %s conf file: %s' % (service, str(e))
Exemplo n.º 7
0
def update_clamav_cron(schedule, old_cron_id):
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        if old_cron_id:
            cron_remove, err = scheduler_utils.remove_cron(old_cron_id)
            if err:
                raise Exception(err)
        cmd = 'clamdscan --no-summary --quiet -m -c /etc/clamd.d/scan.conf --move /opt/integralstor/integralstor_unicell/config/clamav/quarantine/  -f  /opt/integralstor/integralstor_unicell/config/clamav/scan_list.txt '
        description = 'ClamAV Scan'
        cron_task_id, err = scheduler_utils.add_cron_task(
            cmd, description, schedule[0], schedule[1], schedule[2],
            schedule[3], schedule[4])
        if err:
            raise Exception(err)
        with open('%s/cron_id' % root, 'w') as f:
            f.write(str(cron_task_id))
        ret_val = cron_task_id
    except Exception, e:
        return None, 'Error adding cron task for clamav: %s' % str(e)
Exemplo n.º 8
0
def in_scan_list(dataset_name):
    ret_val = None
    try:
        root, err = common.get_clamav_config_path()
        if err:
            raise Exception(err)
        if not os.path.isfile('%s/scan_list.txt' % root):
            cmd = 'touch %s/scan_list.txt' % root
            status, err = command.get_command_output(cmd)
            if err:
                raise Exception(err)
        with open('%s/scan_list.txt' % root, 'r') as f:
            complete_file = f.read()
        list_of_datasets = complete_file.split('\n')
        path_name, err = file_processing.normalise_path(dataset_name)
        if err:
            raise Exception(err)
        if path_name in list_of_datasets:
            ret_val = True
        else:
            ret_val = False
    except Exception, e:
        return ret_val, 'Error checking dataset scan list: %s' % str(e)