Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-5369

Under Settings > System > General: Basic Setup check for open_basedir restrictions

    Details

    • Type: Task
    • Status: In Review
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.11.0
    • Fix Version/s: 5.13.0-b1
    • Component/s: Staff Interface
    • Labels:
      None

      Description

      People often have open_basedir restrictions set in PHP, and then open a ticket because Blesta shows that the uploads or logs directory is not writable under Settings > System > General: Basic Setup, but they are convinced that the directory is writable and that it's Blesta's problem.

      Let's check if open_basedir restrictions exist, if they do exist, let's list them in a red alert box above Basic Setup. The box should not appear if there are no restrictions, and if there are restrictions we should list them.

      Here's some pseudo code. Obviously this will be done differently, but it shows the basics and includes support for Windows.

      <?php
      
      function checkOpenBaseDir() {
          // Get the open_basedir setting
          $openBaseDir = ini_get('open_basedir');
      
          // Check if it's empty (no restrictions)
          if (empty($openBaseDir)) {
              // There are no restrictions, do not show alert box
              return false;
          }
      
          // Determine the separator based on the OS
          $separator = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? ';' : ':';
      
          // Split the string into an array of paths
          $restrictedPaths = explode($separator, $openBaseDir);
      
          // Output the restrictions
          $message = "An open_basedir restriction is in effect. Remove all restrictions to remove this message. If any paths below are not writable, make sureThe following paths are allowed:\n";
          foreach ($restrictedPaths as $index => $path) {
              // Clean up any empty or malformed entries
              $path = trim($path);
              if (!empty($path)) {
                  $message .= ($index + 1) . ". " . $path . "\n";
              }
          }
         return $message;
      }
      
      // Run the function and evaluate to determine if we need to display the box including allowed paths
      checkOpenBaseDir();
      
      ?>
      

        Activity

        admin Paul Phillips created issue -
        admin Paul Phillips made changes -
        Field Original Value New Value
        Description People often have open_basedir restrictions set in PHP, and then open a ticket because Blesta shows that the uploads or logs directory is not writable under Settings > System > General: Basic Setup, but they are convinced that the directory is writable and that it's Blesta's problem.

        Let's check if open_basedir restrictions exist, if they do exist, let's list them in a red alert box above Basic Setup. The box should not appear if there are no restrictions, and if there are restrictions we should list them.

        Here's some pseudo code.

        {code:java}
        <?php

        function checkOpenBaseDir() {
            // Get the open_basedir setting
            $openBaseDir = ini_get('open_basedir');

            // Check if it's empty (no restrictions)
            if (empty($openBaseDir)) {
                // There are no restrictions, do not show alert box
                return false;
            }

            // Determine the separator based on the OS
            $separator = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? ';' : ':';

            // Split the string into an array of paths
            $restrictedPaths = explode($separator, $openBaseDir);

            // Output the restrictions
            $message = "An open_basedir restriction is in effect. Remove all restrictions to remove this message. If any paths below are not writable, make sureThe following paths are allowed:\n";
            foreach ($restrictedPaths as $index => $path) {
                // Clean up any empty or malformed entries
                $path = trim($path);
                if (!empty($path)) {
                    $message .= ($index + 1) . ". " . $path . "\n";
                }
            }
           return $message;
        }

        // Run the function and evaluate to determine if we need to display the box including allowed paths
        checkOpenBaseDir();

        ?>
        {code}
        People often have open_basedir restrictions set in PHP, and then open a ticket because Blesta shows that the uploads or logs directory is not writable under Settings > System > General: Basic Setup, but they are convinced that the directory is writable and that it's Blesta's problem.

        Let's check if open_basedir restrictions exist, if they do exist, let's list them in a red alert box above Basic Setup. The box should not appear if there are no restrictions, and if there are restrictions we should list them.

        Here's some pseudo code. Obviously this will be done differently, but it shows the basics and includes support for Windows.

        {code:java}
        <?php

        function checkOpenBaseDir() {
            // Get the open_basedir setting
            $openBaseDir = ini_get('open_basedir');

            // Check if it's empty (no restrictions)
            if (empty($openBaseDir)) {
                // There are no restrictions, do not show alert box
                return false;
            }

            // Determine the separator based on the OS
            $separator = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? ';' : ':';

            // Split the string into an array of paths
            $restrictedPaths = explode($separator, $openBaseDir);

            // Output the restrictions
            $message = "An open_basedir restriction is in effect. Remove all restrictions to remove this message. If any paths below are not writable, make sureThe following paths are allowed:\n";
            foreach ($restrictedPaths as $index => $path) {
                // Clean up any empty or malformed entries
                $path = trim($path);
                if (!empty($path)) {
                    $message .= ($index + 1) . ". " . $path . "\n";
                }
            }
           return $message;
        }

        // Run the function and evaluate to determine if we need to display the box including allowed paths
        checkOpenBaseDir();

        ?>
        {code}
        admin Paul Phillips made changes -
        Rank Ranked higher
        admin Paul Phillips made changes -
        Rank Ranked lower
        jonathan Jonathan Reissmueller made changes -
        Sprint 5.13.0 Sprint 5 [ 220 ]
        abdy Abdy Franco made changes -
        Assignee Abdy Franco [ abdy ]
        abdy Abdy Franco made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        abdy Abdy Franco made changes -
        Remaining Estimate 0 minutes [ 0 ]
        Time Spent 2 hours, 9 minutes [ 7740 ]
        Worklog Id 17943 [ 17943 ]
        abdy Abdy Franco made changes -
        Status In Progress [ 3 ] In Review [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            abdy Abdy Franco
            Reporter:
            admin Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours, 9 minutes
              2h 9m

                Agile