We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21606
    • 46 Posts
    Hey folks!
    In the process of installing Modx on a server for a client, I received errors indicating that function fopen failed to open stream. Tech Support for this hosting service reported to me that they have disabled that php functionality due to "several hundred sites" recently being hacked and defaced due to the vulnerability of this fopen. Apparently it’s an old problem, but nevertheless I could use some assistance figuring out how to get files such as accesscontrol.inc.php which uses this command to work.
    I’m somewhat php conversant but not enough to extend this companies’ help notes to address this particular problem. Anyone available to assist?
    Thanks!
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: nitrojane at Mar 02, 2010, 08:33 AM

      Hey folks!
      In the process of installing Modx on a server for a client, I received errors indicating that function fopen failed to open stream. Tech Support for this hosting service reported to me that they have disabled that php functionality due to "several hundred sites" recently being hacked and defaced due to the vulnerability of this fopen. Apparently it’s an old problem, but nevertheless I could use some assistance figuring out how to get files such as accesscontrol.inc.php which uses this command to work.
      I’m somewhat php conversant but not enough to extend this companies’ help notes to address this particular problem. Anyone available to assist?
      Thanks!
      This company has disabled a critical function for the operation of MODx. Not being able to open a file on the local filesystem which you have access to is crippling, and there is no vulnerability inherent in the fopen function. They have disabled the use of this function so PHP software that is vulnerable cannot compromise the system, but at the same time, they have made their environment akin to an invalid.
        • 21606
        • 46 Posts
        i’ve done some more research and this vulnerability has a history going back to 2002 (http://www.securiteam.com/unixfocus/5OP0C0A8AC.html ). supposedly other open source projects such as drupal and joomla (those were the two mentioned in documentation i received from this hosting company) have been fixed although there are plugins that are still vulnerable.

        this is the error i received going into the manager:

        Warning: fopen(/data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/assets/templates/manager/login.html) [function.fopen]: failed to open stream: No such file or directory in /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/manager/includes/accesscontrol.inc.php on line 130

        Warning: filesize() [function.filesize]: stat failed for /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/assets/templates/manager/login.html in /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/manager/includes/accesscontrol.inc.php on line 131

        Warning: fread(): supplied argument is not a valid stream resource in /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/manager/includes/accesscontrol.inc.php on line 131

        Warning: fclose(): supplied argument is not a valid stream resource in /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/manager/includes/accesscontrol.inc.php on line 132

        this was the error on the site:

        « MODx Parse Error »MODx encountered the following error while attempting to parse the requested resource:
        « PHP Parse Error »

        PHP error debug
        Error: file_get_contents(/data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/assets/snippets/ajaxSearch/templates/results.tpl.html) [function.file-get-contents]: failed to open stream: No such file or directory
        Error type/ Nr.: Warning - 2
        File: /data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/assets/snippets/ajaxSearch/classes/chunkie.class.inc.php
        Line: 73
        Line 73 source: $fcontents = file_get_contents($filename);

        Parser timing
        MySQL: 0.0184 s (0 Requests)
        PHP: 0.2119 s
        Total: 0.2303 s

        this is the explanation from the company to fix the problem:

        For security reasons (to prevent “PHP include” hacker attacks), [company removed] sets the allow_url_fopen and allow_url_include PHP directives to off. If you see errors similar to the following on your website, then your website (or software you have installed on your website) uses insecure PHP calls.

        Common Errors

        Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /……../ on line (..)
        Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in in /……../ on line (..)
        Warning: include() [function.include]: URL file-access is disabled in the server configuration in /……../ on line (..)
        Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in in /……../ on line (..)
        Warning: readfile() [function.readfile]: URL file-access is disabled in the server configuration in in /……../ on line (..)

        Solution

        WordPress / Joomla / Drupal Software: These applications do not use functions that require allow_url_fopen or allow_url_include to be turned on. However, certain third party plugins may require changes. If you see any of the errors above, try to isolate which plugin is causing the issue and replace it with an alternative plugin. You should also consider reporting the issue to the plugin developer so that they may fix it in an upcoming release. Alternatively, you can check out some of the examples below and attempt to fix the errors yourself.

        Note: Do not attempt to fix issues yourself if you do not have prior software development experience. If the below does not make sense, you should consult with your web professional.

        The errors above manifest themselves when your website is attempting to retrieve outside web URLs. The solution is to use the PHP Curl library to do so instead, which is more secure. How you use PHP ‘s Curl library to circumvent this issue depends on which warning you’ve received.

        Example 1: Warning: fopen() [function.fopen]:

        $file = “http://news.google.com/news?ned=us&topic=h&output=rss”;
        $xml_parser = xml_parser_create();
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");
        if (!($fp = fopen($file, "r"))) {
        die("could not open XML input");
        }

        while ($data = fread($fp, 4096)) {
        if (!xml_parse($xml_parser, $data, feof($fp))) {
        die(sprintf("XML error: %s at line %d",
        xml_error_string(xml_get_error_code($xml_parser)),
        xml_get_current_line_number($xml_parser)));
        }
        }
        In the above example, an attempt to open a Google RSS feed is being made. The fopen() call will fail because $file is an outside web site, and the rest of the code will not be executed. To properly load the RSS feed and parse, this snipit of code would need to be rewritten as follows:

        $xml_parser = xml_parser_create();
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");
        $file = “http://news.google.com/news?ned=us&topic=h&output=rss”;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $file);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $xmldata = curl_exec($ch);
        curl_close($ch);

        $xmldata = split("\n",$xmldata);

        foreach ($xmldata as $data) {
        if (!xml_parse($xml_parser, $data)) {
        die(sprintf("XML error: %s at line %d",
        xml_error_string(xml_get_error_code($xml_parser)),
        xml_get_current_line_number($xml_parser)));
        }
        }

        Example 2: Warning: file_get_contents() [function.file-get-contents]:

        <?php

        $contents = file_get_contents(’http://www.cnn.com/’);
        echo $contents;
        ?>

        In the above example, the file_get_contents function is used to retrieve the content of the CNN website. You can accomplish the same thing safely using CURL as follows:

        <?php

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, ’http://www.cnn.com’);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $contents = curl_exec($ch);
        curl_close($ch);

        // display file
        echo $contents;
        ?>

        Example 3: Warning: include() [function.include]:

        Including files from web hosts is not allowed.

        <? php include(“http://www.example.com/new.php”); ?>

        If the file that you are trying to include is local, use relative paths instead , not the web URL. Otherwise, use the following:

        <?php

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, ’http://www.example.com/mew.php’);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $contents = curl_exec($ch);
        curl_close($ch);

        // display file
        echo $file_contents;
        ?>

        Example 4: Warning: getimagesize() [function.getimagesize]:

        getimagesize() allows you to get the height, width and size of an image file. To use getimagesize() safely, CURL can be used to get the remote file, the data can be saved to a local temporary image file and getimagesize() can be used on the local version.

        <php

        $filename = “http://www.example.com/example.jpg”;

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $filename);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $contents = curl_exec($ch);
        curl_close($ch);

        $new_image = ImageCreateFromString($contents);
        imagejpeg($new_image, "temp.jpg",100);
        $size = getimagesize("temp.jpg");
        // width and height
        $width = $size[0];
        $height = $size[1];

        Example 5: Warning: readfile() [function.readfile]:

        <?php

        $contents = readfile(’http://www.example.com/some.txt’);
        echo $contents;
        ?>

        In the above example, the readfile function is used to retrieve the content of a remote text file. You can accomplish the same thing safely using CURL as follows:

        <?php

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, ’http://www.example.com/some.txt’);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $contents = curl_exec($ch);
        curl_close($ch);

        // display file
        echo $contents;
        ?>

        The above examples are not guaranteed to run without changes, they are strictly guidance to illustrate how to safely retrieve off-site content.

        Do i need to re-post this to get more attention?
          • 22303 MODX Staff
          • 10,725 Posts
          What you have posted has no relevance to this discussion what-so-ever. Your errors are not related to the allow_url_fopen/allow_url_include features the hosting company has disabled. Those fopen calls do not attempt to open URLs, just local files on the file system. Those errors are saying it cannot find the files it’s looking for, so something is wrong with your paths. Look at the paths indicated in those error messages and verify those are the correct paths for your server environment.
            • 21606
            • 46 Posts
            agreed, my first reaction to the company’s action regarding this php function was one of pure frustration and irritation - ! So these lines aren’t the same as they’re squawking about (posted below from accesscontrol.inc.php apparently (although the paths are ’local’, i can see that, their solutions weren’t helpful i was hoping for an exploratory discussion)

            <snipped from file>
            // load template file
            $tplFile = $base_path.’assets/templates/manager/login.html’;
            $handle = fopen($tplFile, "r");
            $tpl = fread($handle, filesize($tplFile));
            fclose($handle);
            <end of snip>
            i am still working the issue and sorry to bother. perhaps another attempt at installing the software will fix the problem... glad i don’t have to worry about having my websites hacked...i love modx! if a moderator wants to close this feel free...

              • 3749
              • 24,544 Posts
              It appears that $base_path is set to ’/data/16/1/32/5/1521494/user/1637500/htdocs/missioninsight/’

              Is that really the physical path to your site on the server?

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting