Beispiel #1
0
/**
 * Deals with an infected file - either moves it to a quarantinedir 
 * (specified in CFG->quarantinedir) or deletes it.
 *
 * If moving it fails, it deletes it.
 *
 *@uses $CFG
 * @uses $USER
 * @param string $file Full path to the file
 * @param int $userid If not used, defaults to $USER->id (there in case called from cron)
 * @param boolean $basiconly Admin level reporting or user level reporting.
 * @return string Details of what the function did.
 */
function clam_handle_infected_file($file, $userid = 0, $basiconly = false)
{
    global $CFG, $USER;
    if ($USER && !$userid) {
        $userid = $USER->ident;
    }
    $delete = true;
    if (file_exists($CFG->quarantinedir) && is_dir($CFG->quarantinedir) && is_writable($CFG->quarantinedir)) {
        $now = date('YmdHis');
        if (rename($file, $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected')) {
            $delete = false;
            clam_log_infected($file, $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected', $userid);
            if ($basiconly) {
                $notice .= "\n" . __gettext('The file has been moved to a quarantine directory.');
            } else {
                $notice .= "\n" . sprintf(__gettext('The file has been moved to your specified quarantine directory, the new location is %s'), $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected');
            }
        } else {
            if ($basiconly) {
                $notice .= "\n" . __gettext('The file has been deleted');
            } else {
                $notice .= "\n" . sprintf(__gettext('Could not move the file into your specified quarantine directory, %s. You need to fix this as files are being deleted if they\'re found to be infected.'), $CFG->quarantinedir);
            }
        }
    } else {
        if ($basiconly) {
            $notice .= "\n" . __gettext('The file has been deleted');
        } else {
            $notice .= "\n" . sprintf(__gettext('Could not move the file into your specified quarantine directory, %s. You need to fix this as files are being deleted if they\'re found to be infected.'), $CFG->quarantinedir);
        }
    }
    if ($delete) {
        if (unlink($file)) {
            clam_log_infected($file, '', $userid);
            $notice .= "\n" . __gettext('The file has been deleted');
        } else {
            if ($basiconly) {
                // still tell the user the file has been deleted. this is only for admins.
                $notice .= "\n" . __gettext('The file has been deleted');
            } else {
                $notice .= "\n" . __gettext('The file could not be deleted');
            }
        }
    }
    return $notice;
}
/**
 * Deals with an infected file - either moves it to a quarantinedir
 * (specified in CFG->quarantinedir) or deletes it.
 *
 * If moving it fails, it deletes it.
 *
 * @global object
 * @global object
 * @param string $file Full path to the file
 * @param int $userid If not used, defaults to $USER->id (there in case called from cron)
 * @param boolean $basiconly Admin level reporting or user level reporting.
 * @return string Details of what the function did.
 */
function clam_handle_infected_file($file, $userid = 0, $basiconly = false)
{
    global $CFG, $USER;
    if ($USER && !$userid) {
        $userid = $USER->id;
    }
    $delete = true;
    if (file_exists($CFG->quarantinedir) && is_dir($CFG->quarantinedir) && is_writable($CFG->quarantinedir)) {
        $now = date('YmdHis');
        if (rename($file, $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected')) {
            $delete = false;
            clam_log_infected($file, $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected', $userid);
            if ($basiconly) {
                $notice .= "\n" . get_string('clammovedfilebasic');
            } else {
                $notice .= "\n" . get_string('clammovedfile', 'moodle', $CFG->quarantinedir . '/' . $now . '-user-' . $userid . '-infected');
            }
        } else {
            if ($basiconly) {
                $notice .= "\n" . get_string('clamdeletedfile');
            } else {
                $notice .= "\n" . get_string('clamquarantinedirfailed', 'moodle', $CFG->quarantinedir);
            }
        }
    } else {
        if ($basiconly) {
            $notice .= "\n" . get_string('clamdeletedfile');
        } else {
            $notice .= "\n" . get_string('clamquarantinedirfailed', 'moodle', $CFG->quarantinedir);
        }
    }
    if ($delete) {
        if (unlink($file)) {
            clam_log_infected($file, '', $userid);
            $notice .= "\n" . get_string('clamdeletedfile');
        } else {
            if ($basiconly) {
                // still tell the user the file has been deleted. this is only for admins.
                $notice .= "\n" . get_string('clamdeletedfile');
            } else {
                $notice .= "\n" . get_string('clamdeletedfilefailed');
            }
        }
    }
    return $notice;
}
/**
 * Deals with an infected file - either moves it to a quarantinedir
 * (specified in CFG->quarantinedir) or deletes it.
 *
 * If moving it fails, it deletes it.
 *
 *@uses $CFG
 * @uses $USER
 * @param string $file Full path to the file
 * @param int $userid If not used, defaults to $USER->id (there in case called from cron)
 * @param boolean $basiconly Admin level reporting or user level reporting.
 * @return string Details of what the function did.
 */
function clam_handle_infected_file($file)
{
    global $USER;
    $userid = $USER->get('id');
    $quarantinedir = get_config('dataroot') . get_string('quarantinedirname');
    check_dir_exists($quarantinedir);
    if (is_dir($quarantinedir) && is_writable($quarantinedir)) {
        $now = date('YmdHis');
        $newname = $quarantinedir . '/' . $now . '-user-' . $userid . '-infected';
        if (rename($file, $newname)) {
            clam_log_infected($file, $newname);
            return get_string('clammovedfile');
        }
    }
    if (unlink($file)) {
        clam_log_infected($file, '', $userid);
        return get_string('clamdeletedfile');
    }
    return get_string('clamdeletefilefailed');
}