• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_clam_error_code函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_clam_error_code函数的典型用法代码示例。如果您正苦于以下问题:PHP get_clam_error_code函数的具体用法?PHP get_clam_error_code怎么用?PHP get_clam_error_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_clam_error_code函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: clam_scan_moodle_file

/**
 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
 *
 * This function will add on a uploadlog index in $file.
 *
 * @global object
 * @global object
 * @param mixed $file The file to scan from $files. or an absolute path to a file.
 * @param course $course {@link $COURSE}
 * @return int 1 if good, 0 if something goes wrong (opposite from actual error code from clam)
 */
function clam_scan_moodle_file(&$file, $course)
{
    global $CFG, $USER;
    if (is_array($file) && is_uploaded_file($file['tmp_name'])) {
        // it's from $_FILES
        $appendlog = true;
        $fullpath = $file['tmp_name'];
    } else {
        if (file_exists($file)) {
            // it's a path to somewhere on the filesystem!
            $fullpath = $file;
        } else {
            return false;
            // erm, what is this supposed to be then, huh?
        }
    }
    $CFG->pathtoclam = trim($CFG->pathtoclam);
    if (!$CFG->pathtoclam || !file_exists($CFG->pathtoclam) || !is_executable($CFG->pathtoclam)) {
        $newreturn = 1;
        $notice = get_string('clamlost', 'moodle', $CFG->pathtoclam);
        if ($CFG->clamfailureonupload == 'actlikevirus') {
            $notice .= "\n" . get_string('clamlostandactinglikevirus');
            $notice .= "\n" . clam_handle_infected_file($fullpath);
            $newreturn = false;
        }
        clam_message_admins($notice);
        if ($appendlog) {
            $file['uploadlog'] .= "\n" . get_string('clambroken');
            $file['clam'] = 1;
        }
        return $newreturn;
        // return 1 if we're allowing clam failures
    }
    $cmd = $CFG->pathtoclam . ' ' . $fullpath . " 2>&1";
    // before we do anything we need to change perms so that clamscan can read the file (clamdscan won't work otherwise)
    chmod($fullpath, $CFG->directorypermissions);
    exec($cmd, $output, $return);
    switch ($return) {
        case 0:
            // glee! we're ok.
            return 1;
            // translate clam return code into reasonable return code consistent with everything else.
        // translate clam return code into reasonable return code consistent with everything else.
        case 1:
            // bad wicked evil, we have a virus.
            $info = new stdClass();
            if (!empty($course)) {
                $info->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
            } else {
                $info->course = 'No course';
            }
            $info->user = fullname($USER);
            $notice = get_string('virusfound', 'moodle', $info);
            $notice .= "\n\n" . implode("\n", $output);
            $notice .= "\n\n" . clam_handle_infected_file($fullpath);
            clam_message_admins($notice);
            if ($appendlog) {
                $info->filename = $file['originalname'];
                $file['uploadlog'] .= "\n" . get_string('virusfounduser', 'moodle', $info);
                $file['virus'] = 1;
            }
            return false;
            // in this case, 0 means bad.
        // in this case, 0 means bad.
        default:
            // error - clam failed to run or something went wrong
            $notice .= get_string('clamfailed', 'moodle', get_clam_error_code($return));
            $notice .= "\n\n" . implode("\n", $output);
            $newreturn = true;
            if ($CFG->clamfailureonupload == 'actlikevirus') {
                $notice .= "\n" . clam_handle_infected_file($fullpath);
                $newreturn = false;
            }
            clam_message_admins($notice);
            if ($appendlog) {
                $file['uploadlog'] .= "\n" . get_string('clambroken');
                $file['clam'] = 1;
            }
            return $newreturn;
            // return 1 if we're allowing failures.
    }
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:93,代码来源:uploadlib.php


示例2: antivir_scan_file

 /**
  * Scan file, throws exception in case of infected file.
  *
  * Please note that the scanning engine must be able to access the file,
  * permissions of the file are not modified here!
  *
  * @static
  * @param string $thefile
  * @param string $filename name of the file
  * @param bool $deleteinfected
  */
 public static function antivir_scan_file($thefile, $filename, $deleteinfected)
 {
     global $CFG;
     if (!is_readable($thefile)) {
         // this should not happen
         return;
     }
     if (empty($CFG->runclamonupload) or empty($CFG->pathtoclam)) {
         // clam not enabled
         return;
     }
     $CFG->pathtoclam = trim($CFG->pathtoclam);
     if (!file_exists($CFG->pathtoclam) or !is_executable($CFG->pathtoclam)) {
         // misconfigured clam - use the old notification for now
         require "{$CFG->libdir}/uploadlib.php";
         $notice = get_string('clamlost', 'moodle', $CFG->pathtoclam);
         clam_message_admins($notice);
         return;
     }
     $clamparam = ' --stdout ';
     // If we are dealing with clamdscan, clamd is likely run as a different user
     // that might not have permissions to access your file.
     // To make clamdscan work, we use --fdpass parameter that passes the file
     // descriptor permissions to clamd, which allows it to scan given file
     // irrespective of directory and file permissions.
     if (basename($CFG->pathtoclam) == 'clamdscan') {
         $clamparam .= '--fdpass ';
     }
     // execute test
     $cmd = escapeshellcmd($CFG->pathtoclam) . $clamparam . escapeshellarg($thefile);
     exec($cmd, $output, $return);
     if ($return == 0) {
         // perfect, no problem found
         return;
     } else {
         if ($return == 1) {
             // infection found
             if ($deleteinfected) {
                 unlink($thefile);
             }
             throw new moodle_exception('virusfounduser', 'moodle', '', array('filename' => $filename));
         } else {
             //unknown problem
             require "{$CFG->libdir}/uploadlib.php";
             $notice = get_string('clamfailed', 'moodle', get_clam_error_code($return));
             $notice .= "\n\n" . implode("\n", $output);
             clam_message_admins($notice);
             if ($CFG->clamfailureonupload === 'actlikevirus') {
                 if ($deleteinfected) {
                     unlink($thefile);
                 }
                 throw new moodle_exception('virusfounduser', 'moodle', '', array('filename' => $filename));
             } else {
                 return;
             }
         }
     }
 }
开发者ID:isuruAb,项目名称:moodle,代码行数:69,代码来源:lib.php


示例3: antivir_scan_file

 /**
  * Scan file, throws exception in case of infected file.
  *
  * Please note that the scanning engine must be able to access the file,
  * permissions of the file are not modified here!
  *
  * @static
  * @param string $thefile
  * @param string $filename name of the file
  * @param bool $deleteinfected
  */
 public static function antivir_scan_file($thefile, $filename, $deleteinfected)
 {
     global $CFG;
     if (!is_readable($thefile)) {
         // this should not happen
         return;
     }
     if (empty($CFG->runclamonupload) or empty($CFG->pathtoclam)) {
         // clam not enabled
         return;
     }
     $CFG->pathtoclam = trim($CFG->pathtoclam);
     if (!file_exists($CFG->pathtoclam) or !is_executable($CFG->pathtoclam)) {
         // misconfigured clam - use the old notification for now
         require "{$CFG->libdir}/uploadlib.php";
         $notice = get_string('clamlost', 'moodle', $CFG->pathtoclam);
         clam_message_admins($notice);
         return;
     }
     // do NOT mess with permissions here, the calling party is responsible for making
     // sure the scanner engine can access the files!
     // execute test
     $cmd = escapeshellcmd($CFG->pathtoclam) . ' --stdout ' . escapeshellarg($thefile);
     exec($cmd, $output, $return);
     if ($return == 0) {
         // perfect, no problem found
         return;
     } else {
         if ($return == 1) {
             // infection found
             if ($deleteinfected) {
                 unlink($thefile);
             }
             throw new moodle_exception('virusfounduser', 'moodle', '', array('filename' => $filename));
         } else {
             //unknown problem
             require "{$CFG->libdir}/uploadlib.php";
             $notice = get_string('clamfailed', 'moodle', get_clam_error_code($return));
             $notice .= "\n\n" . implode("\n", $output);
             clam_message_admins($notice);
             if ($CFG->clamfailureonupload === 'actlikevirus') {
                 if ($deleteinfected) {
                     unlink($thefile);
                 }
                 throw new moodle_exception('virusfounduser', 'moodle', '', array('filename' => $filename));
             } else {
                 return;
             }
         }
     }
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:62,代码来源:lib.php


示例4: clam_scan_file

/**
 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
 *
 * This function will add on a uploadlog index in $file.
 * @param mixed $file The file to scan from $files. or an absolute path to a file.
 * @return int 1 if good, 0 if something goes wrong (opposite from actual error code from clam)
 */
function clam_scan_file(&$file)
{
    global $CFG, $USER;
    if (is_array($file) && is_uploaded_file($file['tmp_name'])) {
        // it's from $_FILES
        $appendlog = true;
        $fullpath = $file['tmp_name'];
    } else {
        if (file_exists($file)) {
            // it's a path to somewhere on the filesystem!
            $fullpath = $file;
        } else {
            return false;
            // erm, what is this supposed to be then, huh?
        }
    }
    $CFG->pathtoclam = trim($CFG->pathtoclam);
    if (!$CFG->pathtoclam || !file_exists($CFG->pathtoclam) || !is_executable($CFG->pathtoclam)) {
        $newreturn = 1;
        $notice = sprintf(__gettext('Yupana is configured to run clam on file upload, but the path supplied to Clam AV, %s,  is invalid.'), $CFG->pathtoclam);
        if ($CFG->clamfailureonupload == 'actlikevirus') {
            $notice .= "\n" . __gettext('In addition, Yupana is configured so that if clam fails to run, files are treated like viruses.  This essentially means that no student can upload a file successfully until you fix this.');
            $notice .= "\n" . clam_handle_infected_file($fullpath);
            $newreturn = false;
        }
        clam_mail_admins($notice);
        if ($appendlog) {
            $file['uploadlog'] .= "\n" . __gettext('Your administrator has enabled virus checking for file uploads but has misconfigured something.<br />Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.<br />Maybe try uploading this file later.');
            $file['clam'] = 1;
        }
        return $newreturn;
        // return 1 if we're allowing clam failures
    }
    $cmd = $CFG->pathtoclam . ' ' . $fullpath . " 2>&1";
    // before we do anything we need to change perms so that clamscan can read the file (clamdscan won't work otherwise)
    chmod($fullpath, 0644);
    exec($cmd, $output, $return);
    switch ($return) {
        case 0:
            // glee! we're ok.
            return 1;
            // translate clam return code into reasonable return code consistent with everything else.
        // translate clam return code into reasonable return code consistent with everything else.
        case 1:
            // bad wicked evil, we have a virus.
            $info->user = $USER->name;
            $notice = sprintf(__gettext('Attention administrator! Clam AV has found a virus in a file uploaded by %s. Here is the output of clamscan:'), $info->user);
            $notice .= "\n\n" . implode("\n", $output);
            $notice .= "\n\n" . clam_handle_infected_file($fullpath);
            clam_mail_admins($notice);
            if ($appendlog) {
                $info->filename = $file['originalname'];
                $file['uploadlog'] .= "\n" . sprintf(__gettext('The file you have uploaded, %s, has been scanned by a virus checker and found to be infected! Your file upload was NOT successful.'), $info->filename);
                $file['virus'] = 1;
            }
            return false;
            // in this case, 0 means bad.
        // in this case, 0 means bad.
        default:
            // error - clam failed to run or something went wrong
            $notice .= sprintf(__gettext('Clam AV has failed to run.  The return error message was %s. Here is the output from Clam:'), get_clam_error_code($return));
            $notice .= "\n\n" . implode("\n", $output);
            $newreturn = true;
            if ($CFG->clamfailureonupload == 'actlikevirus') {
                $notice .= "\n" . clam_handle_infected_file($fullpath);
                $newreturn = false;
            }
            clam_mail_admins($notice);
            if ($appendlog) {
                $file['uploadlog'] .= "\n" . __gettext('Your administrator has enabled virus checking for file uploads but has misconfigured something.<br />Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.<br />Maybe try uploading this file later.');
                $file['clam'] = 1;
            }
            return $newreturn;
            // return 1 if we're allowing failures.
    }
}
开发者ID:BackupTheBerlios,项目名称:yupana,代码行数:83,代码来源:uploadlib.php


示例5: mahara_clam_scan_file

/**
 * Scan a file for viruses using clamav.
 *
 * @param mixed $file The file to scan from $files. or an absolute path to a file.
 * @return false if no errors, or a string if there's an error.
 */
function mahara_clam_scan_file($file, $inputindex = null)
{
    if (isset($inputindex)) {
        $tmpname = $file['tmp_name'][$inputindex];
    } else {
        if (is_array($file)) {
            $tmpname = $file['tmp_name'];
        }
    }
    if (is_array($file) && is_uploaded_file($tmpname)) {
        // it's from $_FILES
        $fullpath = $tmpname;
    } else {
        if (file_exists($file)) {
            $fullpath = $file;
        } else {
            throw new SystemException('mahara_clam_scan_file: not called correctly, read phpdoc for this function');
        }
    }
    $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
    if (!$pathtoclam) {
        return false;
    }
    if (!file_exists($pathtoclam) || !is_executable($pathtoclam)) {
        clam_mail_admins(get_string('clamlost', 'mahara', $pathtoclam));
        clam_handle_infected_file($fullpath);
        return get_string('clambroken');
    }
    $clamparam = ' ';
    // If we are dealing with clamdscan, clamd is likely run as a different user
    // that might not have permissions to access your file.
    // To make clamdscan work, we use --fdpass parameter that passes the file
    // descriptor permissions to clamd, which allows it to scan given file
    // irrespective of directory and file permissions.
    if (basename($pathtoclam) == 'clamdscan') {
        $clamparam .= '--fdpass ';
    }
    $cmd = $pathtoclam . $clamparam . escapeshellarg($fullpath) . " 2>&1";
    exec($cmd, $output, $return);
    switch ($return) {
        case 0:
            // glee! we're ok.
            return false;
            // no error
        // no error
        case 1:
            // bad wicked evil, we have a virus.
            global $USER;
            $userid = $USER->get('id');
            clam_handle_infected_file($fullpath);
            // Notify admins if user has uploaded more than 3 infected
            // files in the last month
            if (count_records_sql('
            SELECT
                COUNT(*)
            FROM {usr_infectedupload}
            WHERE usr = ? AND time > ?', array($userid, db_format_timestamp(time() - 60 * 60 * 24 * 30))) >= 2) {
                log_debug('sending virusrepeat notification');
                $data = (object) array('username' => $USER->get('username'), 'userid' => $userid, 'fullname' => full_name());
                require_once 'activity.php';
                activity_occurred('virusrepeat', $data);
            }
            $data = (object) array('usr' => $userid, 'time' => db_format_timestamp(time()));
            insert_record('usr_infectedupload', $data, 'id');
            return get_string('virusfounduser', 'mahara', display_name($USER));
        default:
            // error - clam failed to run or something went wrong
            $notice = get_string('clamfailed', 'mahara', get_clam_error_code($return));
            $notice .= "\n\n" . implode("\n", $output);
            $notice .= "\n" . clam_handle_infected_file($fullpath);
            clam_mail_admins($notice);
            return get_string('clambroken');
    }
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:80,代码来源:uploadmanager.php


示例6: mahara_clam_scan_file

/**
 * Scan a file for viruses using clamav.
 *
 * @param mixed $file The file to scan from $files. or an absolute path to a file.
 * @return false if no errors, or a string if there's an error.
 */
function mahara_clam_scan_file($file)
{
    if (is_array($file) && is_uploaded_file($file['tmp_name'])) {
        // it's from $_FILES
        $fullpath = $file['tmp_name'];
    } else {
        if (file_exists($file)) {
            $fullpath = $file;
        } else {
            throw new SystemException('mahara_clam_scan_file: not called correctly, read phpdoc for this function');
        }
    }
    $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
    if (!$pathtoclam || !file_exists($pathtoclam) || !is_executable($pathtoclam)) {
        clam_mail_admins(get_string('clamlost', 'mahara', $pathtoclam));
        clam_handle_infected_file($fullpath);
        return get_string('clambroken');
    }
    $cmd = $pathtoclam . ' ' . escapeshellarg($fullpath) . " 2>&1";
    // before we do anything we need to change perms so that clamscan
    // can read the file (clamdscan won't work otherwise)
    chmod($fullpath, 0644);
    exec($cmd, $output, $return);
    switch ($return) {
        case 0:
            // glee! we're ok.
            return false;
            // no error
        // no error
        case 1:
            // bad wicked evil, we have a virus.
            global $USER;
            $userid = $USER->get('id');
            clam_handle_infected_file($fullpath);
            // Notify admins if user has uploaded more than 3 infected
            // files in the last month
            if (count_records_sql('
            SELECT
                COUNT(*)
            FROM {usr_infectedupload}
            WHERE usr = ? AND time > ?', array($userid, db_format_timestamp(time() - 60 * 60 * 24 * 30))) >= 2) {
                log_debug('sending virusrepeat notification');
                $data = (object) array('username' => $USER->get('username'), 'userid' => $userid, 'fullname' => full_name());
                require_once 'activity.php';
                activity_occurred('virusrepeat', $data);
            }
            $data = (object) array('usr' => $userid, 'time' => db_format_timestamp(time()));
            insert_record('usr_infectedupload', $data, 'id');
            return get_string('virusfounduser', 'mahara', display_name($USER));
        default:
            // error - clam failed to run or something went wrong
            $notice = get_string('clamfailed', 'mahara', get_clam_error_code($return));
            $notice .= "\n\n" . implode("\n", $output);
            $notice .= "\n" . clam_handle_infected_file($fullpath);
            clam_mail_admins($notice);
            return get_string('clambroken');
    }
}
开发者ID:Br3nda,项目名称:mahara,代码行数:64,代码来源:uploadmanager.php



注:本文中的get_clam_error_code函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_class函数代码示例发布时间:2022-05-15
下一篇:
PHP get_city函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap