Scan file using Unix domain sockets.

@param string $file Full path to the file.
@return int Scanning result constant.
966985
public function scan_file_execute_unixsocket($file) {
        $socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'),
                $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
        if (!$socket) {
            // Can't open socket for some reason, notify admins.
            $notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
            $this->set_scanning_notice($notice);
            return self::SCAN_RESULT_ERROR;
        } else {
            // Execute scanning. We are running SCAN command and passing file as an argument,
            // it is the fastest option, but clamav user need to be able to access it, so
            // we give group read permissions first and assume 'clamav' user is in web server
            // group (in Debian the default webserver group is 'www-data').
            // Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
            // this is to avoid unexpected newline characters on different systems.
            $perms = fileperms($file);
            chmod($file, 0640);
            fwrite($socket, "nSCAN ".$file."\n");
            $output = stream_get_line($socket, 4096);
            fclose($socket);
            // After scanning we revert permissions to initial ones.
            chmod($file, $perms);
            // Parse the output.
            return $this->parse_unixsocket_response($output);
        }
    }
378687
protected function findMiddlewareFromFile($file)
    {
        $filename = pathinfo($file, PATHINFO_FILENAME);

        foreach ($this->middleware as $alias => $class) {
            if (strpos($class, $filename) !== false) {
                return $alias;
            }
        }
    }
1017980
private function readFileContent(string $file): void
    {
        $autodetect = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', '1');
        $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        ini_set('auto_detect_line_endings', $autodetect);

        $this->lines = array_merge($this->lines, $lines);
    }
368707
protected function Read($file)
    {
        # Open File
        $fh = fopen($file, 'r');
        $fileSize = filesize($file);
        
        if(!empty($fileSize)) {
            # Read Data
            $data = fread($fh, $fileSize);
            
            # Fix Data Stream to be the exact same format as PHP's strings
            $data = str_replace(array("\r\n", "\r", "\n"), "\n", $data);
        } else {
            $data = '';
        }
        
        # Close File
        fclose($fh);
        
        # Return Data
        return $data;
    }
776877
public function file($file)
    {
        $filePaths = loader()->getPublicDirs(true);

        foreach ($filePaths as $filePath) {
            if (is_file($filePath . $file)) {
                return path_to_url($filePath . $file);
                break;
            }
        }
    }
240848
public static function scanFile($file, DOMDocument $dom = null)
    {
        if (!file_exists($file)) {
            throw new Exception(
                "The file $file specified doesn't exist"
            );
        }
        return self::scan(file_get_contents($file), $dom);
    }
800296
public static function get($file = false) {

        if ($file && self::isFile($file)) {

            return file_get_contents($file);
        }

        return false;
    }
616419
public static function get(
        $file
    ) {
        if (is_string($file)) {
            $file = new \SplFileInfo($file);
        }

        $extension = mb_strtolower($file->getExtension());
        if ('' === $extension) {
            return static::MIME_TYPE_IF_UNKNOWN;
        }

        if (array_key_exists($extension, static::$mimeTypes)) {
            return static::$mimeTypes[$extension];
        }

        if (function_exists('finfo_open') && $file->isFile()) {
            $path = $file->getPath();

            $fileInfo = finfo_open(FILEINFO_MIME);
            $mimeType = finfo_file($fileInfo, $path);
            finfo_close($fileInfo);

            return $mimeType;
        }

        return static::MIME_TYPE_IF_UNKNOWN;
    }
534018
public static function read($file)
    {
        $cwd = getcwd();
        $log = $cwd.'/producer.log';

        if (file_exists($file)) {
            file_put_contents($log, file_get_contents($file), FILE_APPEND);
        }
    }
1133284
protected function getFileRecord($file)
    {
        $result = null;
        $segment = implode('/', [DIRNAME_GEOLOCATION, $this->geolocator->getGeolocatorHandle(), $file]);
        $fileLocator = $this->app->make(FileLocator::class);
        /* @var FileLocator $fileLocator */
        $package = $this->geolocator->getGeolocatorPackage();
        if ($package !== null) {
            $fileLocator->addPackageLocation($package->getPackageHandle());
        }

        return $fileLocator->getRecord($segment);
    }
1175681
public static function read($file)
    {
        if (!is_readable($file)) {
            return;
        }
        $data = @file_get_contents($file);
        if ($data === false) {
            return;
        }
        $value = @unserialize($data);
        if ($value === false) {
            return;
        }

        return $value;
    }
734158
protected function getFile($file)
    {
        $mapping = [
            '%environment%' => $this->runtime->getEnvironment(),
        ];

        if ($this->runtime->getHostName() !== null) {
            $mapping['%host%'] = $this->runtime->getHostName();
        }

        if ($this->runtime->getReleaseId() !== null) {
            $mapping['%release%'] = $this->runtime->getReleaseId();
        }

        $options = $this->getOptions();
        return str_replace(
            array_keys($mapping),
            array_values($mapping),
            $options[$file]
        );
    }
610163
private function read_file($file)
  {
    $handler = fopen($file, "r");
    $file_content = fread($handler, filesize($file));
    fclose($handler);

    return $file_content;
  }
519935
public function fileIsIgnored($file)
    {
        $line = $this->ignoreFile[0];
        $mode = 'regexp';
        $ignored = false;
        if (preg_match('#^syntax\s*:\s*(glob|regexp)$#', $line, $matches)
            || $matches[1] === 'glob'
        ) {
            $mode = 'glob';
        }
        if ($mode === 'glob') {
            $ignored = $this->ignoredByGlob($file);
        } elseif ($mode === 'regexp') {
            $ignored = $this->ignoredByRegex($file);
        }
        return $ignored;
    }
921886
public static function getPidByFile(string $file, bool $checkLive = false): int
    {
        if ($file && \file_exists($file)) {
            $pid = (int)\file_get_contents($file);

            // check live
            if ($checkLive && self::isRunning($pid)) {
                return $pid;
            }

            \unlink($file);
        }

        return 0;
    }
726893
public function scan_file_execute_commandline($file) {
        $pathtoclam = trim($this->get_config('pathtoclam'));

        if (!file_exists($pathtoclam) or !is_executable($pathtoclam)) {
            // Misconfigured clam, notify admins.
            $notice = get_string('invalidpathtoclam', 'antivirus_clamav', $pathtoclam);
            $this->set_scanning_notice($notice);
            return self::SCAN_RESULT_ERROR;
        }

        $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($pathtoclam) == 'clamdscan') {
            $clamparam .= '--fdpass ';
        }
        // Execute scan.
        $cmd = escapeshellcmd($pathtoclam).$clamparam.escapeshellarg($file);
        exec($cmd, $output, $return);
        // Return variable will contain execution return code. It will be 0 if no virus is found,
        // 1 if virus is found, and 2 or above for the error. Return codes 0 and 1 correspond to
        // SCAN_RESULT_OK and SCAN_RESULT_FOUND constants, so we return them as it is.
        // If there is an error, it gets stored as scanning notice and function
        // returns SCAN_RESULT_ERROR.
        if ($return > self::SCAN_RESULT_FOUND) {
            $notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code($return));
            $notice .= "\n\n". implode("\n", $output);
            $this->set_scanning_notice($notice);
            return self::SCAN_RESULT_ERROR;
        }

        return (int)$return;
    }
181766
public static function rmfile($file)
    {
        if (is_file($file)) {
            return chmod($file, 0777) && unlink($file);
        } else {
            throw new RuntimeException(sprintf(
                'Invalid file path supplied "%s"', $file
            ));
        }
    }