Security scan. Scan for such as embedded php code in the uploaded file.

@return boolean Return true on safety, return false for otherwise.
13942
protected function securityScan()
    {
        if (
            is_array($this->files[$this->input_file_name]) && 
            array_key_exists('name', $this->files[$this->input_file_name]) && 
            array_key_exists('tmp_name', $this->files[$this->input_file_name]) && 
            $this->files[$this->input_file_name]['tmp_name'] != null
        ) {
            // there is an uploaded file.
            if (is_file($this->files[$this->input_file_name]['tmp_name'])) {
                $file_content = file_get_contents($this->files[$this->input_file_name]['tmp_name']);

                // scan php open tag
                if (stripos($file_content, '<?php') !== false || stripos($file_content, '<?=') !== false) {
                    // found php open tag. (<?php).
                    $this->setErrorMessage(
                        sprintf(static::__('Error! Found php embedded in the uploaded file. (%s).'), $this->files[$this->input_file_name]['name']),
                        'RDU_SEC_ERR_PHP',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }

                // scan cgi/perl
                if (stripos($file_content, '#!/') !== false && stripos($file_content, '/perl') !== false) {
                    // found cgi/perl header.
                    $this->setErrorMessage(
                        sprintf(static::__('Error! Found cgi/perl embedded in the uploaded file. (%s).'), $this->files[$this->input_file_name]['name']),
                        'RDU_SEC_ERR_CGI',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }

                // scan shell script
                // reference: https://en.wikipedia.org/wiki/Shell_script 
                // https://stackoverflow.com/questions/10591086/shell-script-headers-bin-sh-vs-bin-csh
                // https://www.shellscript.sh/
                if (
                    stripos($file_content, '#!/') !== false && 
                    (
                        stripos($file_content, '/bin/sh') !== false ||
                        stripos($file_content, '/bin/bash') !== false ||
                        stripos($file_content, '/bin/csh') !== false ||
                        stripos($file_content, '/bin/tcsh') !== false
                    )
                ) {
                    // found shell script.
                    $this->setErrorMessage(
                        sprintf(static::__('Error! Found shell script embedded in the uploaded file. (%s).'), $this->files[$this->input_file_name]['name']),
                        'RDU_SEC_ERR_CGI',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }

                unset($file_content);
            }
        }

        return true;
    }
1157534
public function isNotObfuscateFile(string $php_file) : bool
    {
        $files = array_flip($this->not_obfuscate_files);
        return (isset($files[$php_file]) == true);
    }
772648
public function readBodyFile()
    {
        if (!isset($this->attrs->server['REQUEST_BODY_FILE'])) {
            return false;
        }

        FileSystem::readfileChunked(
            $this->attrs->server['REQUEST_BODY_FILE'],
            function ($file, $success) {
                $this->attrs->inputDone = true;
                if ($this->sleepTime === 0) {
                    $this->wakeup();
                }
            },
            function ($file, $chunk) {
                // readed chunk
                $this->stdin($chunk);
            }
        );

        return true;
    }
390458
public function detect()
    {
        $result = null;
        if ($result === null && $this->request->server->has('SERVER_SOFTWARE')) {
            $result = $this->detectFromServer($this->request->server->get('SERVER_SOFTWARE'));
        }
        if ($result === null && function_exists('apache_get_version')) {
            $result = $this->detectFromSPL(@apache_get_version());
        }
        if ($result === null) {
            ob_start();
            phpinfo(INFO_MODULES);
            $info = ob_get_contents();
            ob_end_clean();
            $result = $this->detectFromPHPInfo($info);
        }

        return $result;
    }
371613
public function check()
    {
        $this->isFound = file_exists($this->filename);
        $this->isReadable = is_readable($this->filename);

        $result = $this->isFound && $this->isReadable;

        return $result;
    }
839995
public function check() {
        if (empty($this->_ips[$this->_ip])) {
            $this->_ips[$this->_ip] = [];
            $this->_ips[$this->_ip]['time'] = 0;
        }

        if ($this->_exception == false) {
            if (intval($this->_ips[$this->_ip]['time']) + intval($this->config['user']['security']['spam']['config']['query']['duration']) < time()) {
                $this->_updateIp(time(), 1);

                return true;
            }
            elseif ($this->_ips[$this->_ip]['number'] <= $this->config['user']['security']['spam']['config']['query']['number']) {
                $this->_updateIp($this->_ips[$this->_ip]['time'], intval($this->_ips[$this->_ip]['number']) + 1);

                return true;
            }
            else {
                $t = new Template($this->config['user']['security']['spam']['config']['error']['template'], 'core-security-spam', 0);

                foreach ($this->config['user']['security']['spam']['config']['error']['variable'] as $key => $value) {
                    if ($value['type'] == 'var') {
                        $t->assign([$key => $value['value']]);
                    }
                    else {
                        $t->assign([$key => $this->useLang($value['value'])]);
                    }
                }

                echo $t->show();

                $this->addError($this->_ip . ' : exceeded the number of queries allowed for the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action, __FILE__, __LINE__, ERROR_ERROR);

                return false;
            }
        }

        return true;
    }
1829
public function check()
    {
        foreach ($this->target->paths as $path) {
            if (! $this->getFilesystem()->isWritable($path)) {
                return $this->makeResult(
                    false,
                    sprintf($this->target->getErrorMessage(), $path)
                );
            }
        }

        return $this->makeHealthyResult();
    }
657532
public function checkSysfolder()
    {
        $queryBuilder = Db::getQueryBuilder('pages');
        $page = $queryBuilder
            ->select('doktype')
            ->from('pages')
            ->where(
                $queryBuilder->expr()->eq(
                    'uid',
                    $queryBuilder->quote($this->id, \PDO::PARAM_INT)
                )
            )
            ->setMaxResults(1)
            ->execute()
            ->fetch(0);

        return $page['doktype'] == 254 ? true : false;
    }
458984
public function check()
	{
		$this->checked	= TRUE;
		$this->methods	= array();
		$matches		= array();
		$content		= FS_File_Reader::load( $this->fileName );
		if( preg_match( "@class @i", $content ) )
			if( preg_match_all( "@\tfunction (& *)?([a-z][a-z0-9]+)@i", $content, $matches ) )
				foreach( $matches[2] as $match )
					$this->methods[]	= $match;
		return empty( $this->methods );
	}
717335
public static function isSecure() {
        $s = &$_SERVER;
        $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false;
        return $ssl;
    }
1193024
public static function checkOnDisk()
    {
        $args = func_get_args();
        if (count($args) == 2)
            $module = $args[0] . DIRECTORY_SEPARATOR . $args[1];
        elseif (count($args) == 1)
            $module = $args[1];
        else
            throw  new \Exception();
        $module = str_replace('\\', DIRECTORY_SEPARATOR, $module);
        return (bool)app('files')->exists(app_path('Modules') . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Module.php');
    }
670220
private boolean checkForSecureAccess() {
        Class[] classContext = getClassContext();
        for (Class clazz : classContext) {
            if (clazz.equals(SecureAccess.class) || clazz.equals(SecurityBreachHandler.class)
                    || clazz.equals(SecurityFunctions.class) || clazz.equals(SecureStorageImpl.class)) {
                return true;
            }
        }
        return false;
    }
449195
public function verifyChecksum()
    {
        if(empty($this->getPackage()->getChecksum())) {
            return true;
        }
        return $this->getPackage()->getChecksum() === md5_file($this->getDownloadFullPath());
    }
156370
public function validateRequest(): bool
    {
        if ($this->useNativeSession) {
            if (!isset($_SESSION[$this->sessionIndex])) {
                return false;
            }
            /** @var array<string, array<string, mixed>> $sess */
            $sess =& $_SESSION[$this->sessionIndex];
        } else {
            if (!isset($this->session[$this->sessionIndex])) {
                return false;
            }
            /** @var array<string, array<string, mixed>> $sess */
            $sess =& $this->session[$this->sessionIndex];
        }

        if (
            empty($this->post[$this->formIndex]) ||
            empty($this->post[$this->formToken])
        ) {
            // User must transmit a complete index/token pair
            return false;
        }

        // Let's pull the POST data
        /** @var string $index */
        $index = $this->post[$this->formIndex];
        /** @var string $token */
        $token = $this->post[$this->formToken];
        if (!\is_string($index) || !\is_string($token)) {
            return false;
        }

        if (!isset($sess[$index])) {
            // CSRF Token not found
            return false;
        }

        if (!\is_string($index) || !\is_string($token)) {
            return false;
        }

        // Grab the value stored at $index
        /** @var array<string, mixed> $stored */
        $stored = $sess[$index];

        // We don't need this anymore
        if ($this->deleteToken($sess[$index])) {
            unset($sess[$index]);
        }

        // Which form action="" is this token locked to?
        /** @var string $lockTo */
        $lockTo = $this->server[$this->lock_type];
        if (\preg_match('#/$#', $lockTo)) {
            // Trailing slashes are to be ignored
            $lockTo = Binary::safeSubstr(
                $lockTo,
                0,
                Binary::safeStrlen($lockTo) - 1
            );
        }

        if (!\hash_equals($lockTo, (string) $stored['lockTo'])) {
            // Form target did not match the request this token is locked to!
            return false;
        }

        // This is the expected token value
        if ($this->hmac_ip === false) {
            // We just stored it wholesale
            /** @var string $expected */
            $expected = $stored['token'];
        } else {
            // We mixed in the client IP address to generate the output
            /** @var string $expected */
            $expected = Base64UrlSafe::encode(
                \hash_hmac(
                    $this->hashAlgo,
                    isset($this->server['REMOTE_ADDR'])
                        ? (string) $this->server['REMOTE_ADDR']
                        : '127.0.0.1',
                    (string) Base64UrlSafe::decode((string) $stored['token']),
                    true
                )
            );
        }
        return \hash_equals($token, $expected);
    }
141544
public function check()
    {

        $config = $this->getConfig();

        if (isset($config['ext'])) {
            $this->setExt($config['ext']);
        }

        if (isset($config['folder'])) {

            $folder = $config['folder'];
            $this->setFolder($folder);


            if(!$this->getFileSystem()->exists($folder))
            {
                $this->getFileSystem()->createDir($folder);
                chmod($folder, 0777);
            }
        }else{

            return false;
        }

        // we have do something else

        if (function_exists('gzcompress') && function_exists('gzuncompress')) {
            return true;
        }
    }
1174219
private function checkMainScript()
    {
        if (null !== $this->script) {
            // Allow an application to set -- for standard input
            return file_exists($this->script) || '--' === $this->script;
        }

        if (file_exists($this->script = $_SERVER['argv'][0])) {
            return true;
        }

        // Use a backtrace to resolve Phar and chdir issues
        $options = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false;
        $trace = debug_backtrace($options);

        if (($main = end($trace)) && isset($main['file'])) {
            return file_exists($this->script = $main['file']);
        }

        return false;
    }
920775
public function accept() : bool
    {
        $current = $this->current();

        if (!$this->includeHidden && $current->getFilename(){0} == '.') {
            return false;
        }

        if ($this->fileExtensions && $current->isFile() && !in_array($current->getExtension(), $this->fileExtensions)) {
            return false;
        }
        return true;
    }