[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch

title

Body

[close]

/phpbb/install/module/obtain_data/task/ -> obtain_server_data.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\install\module\obtain_data\task;
  15  
  16  use phpbb\install\exception\user_interaction_required_exception;
  17  
  18  /**
  19   * This class requests and saves some information about the server
  20   */
  21  class obtain_server_data extends \phpbb\install\task_base implements \phpbb\install\task_interface
  22  {
  23      /**
  24       * @var \phpbb\install\helper\config
  25       */
  26      protected $install_config;
  27  
  28      /**
  29       * @var \phpbb\install\helper\iohandler\iohandler_interface
  30       */
  31      protected $io_handler;
  32  
  33      /**
  34       * Constructor
  35       *
  36       * @param \phpbb\install\helper\config                            $config        Installer's config
  37       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler    Installer's input-output handler
  38       */
  39  	public function __construct(\phpbb\install\helper\config $config,
  40                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler)
  41      {
  42          $this->install_config    = $config;
  43          $this->io_handler        = $iohandler;
  44  
  45          parent::__construct(true);
  46      }
  47      /**
  48       * {@inheritdoc}
  49       */
  50  	public function run()
  51      {
  52          $cookie_secure = $this->io_handler->is_secure();
  53          $server_protocol = ($this->io_handler->is_secure()) ? 'https://' : 'http://';
  54          $server_port = $this->io_handler->get_server_variable('SERVER_PORT', 0);
  55  
  56          // HTTP_HOST is having the correct browser url in most cases...
  57          $server_name = strtolower(htmlspecialchars_decode($this->io_handler->get_header_variable(
  58              'Host',
  59              $this->io_handler->get_server_variable('SERVER_NAME')
  60          )));
  61  
  62          // HTTP HOST can carry a port number...
  63          if (strpos($server_name, ':') !== false)
  64          {
  65              $server_name = substr($server_name, 0, strpos($server_name, ':'));
  66          }
  67  
  68          $script_path = htmlspecialchars_decode($this->io_handler->get_server_variable('PHP_SELF'));
  69  
  70          if (!$script_path)
  71          {
  72              $script_path = htmlspecialchars_decode($this->io_handler->get_server_variable('REQUEST_URI'));
  73          }
  74  
  75          $script_path = str_replace(array('\\', '//'), '/', $script_path);
  76          $script_path = trim(dirname(dirname(dirname($script_path)))); // Because we are in install/app.php/route_name
  77  
  78          // Server data
  79          $cookie_secure        = $this->io_handler->get_input('cookie_secure', $cookie_secure);
  80          $server_protocol    = $this->io_handler->get_input('server_protocol', $server_protocol);
  81          $force_server_vars    = $this->io_handler->get_input('force_server_vars', 0);
  82          $server_name        = $this->io_handler->get_input('server_name', $server_name, true);
  83          $server_port        = $this->io_handler->get_input('server_port', $server_port);
  84          $script_path        = $this->io_handler->get_input('script_path', $script_path, true);
  85  
  86          // Clean up script path
  87          if ($script_path !== '/')
  88          {
  89              // Adjust destination path (no trailing slash)
  90              if (substr($script_path, -1) === '/')
  91              {
  92                  $script_path = substr($script_path, 0, -1);
  93              }
  94  
  95              $script_path = str_replace(array('../', './'), '', $script_path);
  96  
  97              if ($script_path[0] !== '/')
  98              {
  99                  $script_path = '/' . $script_path;
 100              }
 101          }
 102  
 103          // Check if data is sent
 104          if ($this->io_handler->get_input('submit_server', false))
 105          {
 106              $this->install_config->set('cookie_secure', $cookie_secure);
 107              $this->install_config->set('server_protocol', $server_protocol);
 108              $this->install_config->set('force_server_vars', $force_server_vars);
 109              $this->install_config->set('server_name', $server_name);
 110              $this->install_config->set('server_port', $server_port);
 111              $this->install_config->set('script_path', $script_path);
 112          }
 113          else
 114          {
 115              // Render form
 116              $server_form = array(
 117                  'cookie_secure' => array(
 118                      'label'            => 'COOKIE_SECURE',
 119                      'description'    => 'COOKIE_SECURE_EXPLAIN',
 120                      'type'            => 'radio',
 121                      'options'        => array(
 122                          array(
 123                              'value'        => 0,
 124                              'label'        => 'NO',
 125                              'selected'    => (!$cookie_secure),
 126                          ),
 127                          array(
 128                              'value'        => 1,
 129                              'label'        => 'YES',
 130                              'selected'    => ($cookie_secure),
 131                          ),
 132                      ),
 133                  ),
 134                  'force_server_vars' => array(
 135                      'label'            => 'FORCE_SERVER_VARS',
 136                      'description'    => 'FORCE_SERVER_VARS_EXPLAIN',
 137                      'type'            => 'radio',
 138                      'options'        => array(
 139                          array(
 140                              'value'        => 0,
 141                              'label'        => 'NO',
 142                              'selected'    => true,
 143                          ),
 144                          array(
 145                              'value'        => 1,
 146                              'label'        => 'YES',
 147                              'selected'    => false,
 148                          ),
 149                      ),
 150                  ),
 151                  'server_protocol' => array(
 152                      'label'            => 'SERVER_PROTOCOL',
 153                      'description'    => 'SERVER_PROTOCOL_EXPLAIN',
 154                      'type'            => 'text',
 155                      'default'        => $server_protocol,
 156                  ),
 157                  'server_name' => array(
 158                      'label'            => 'SERVER_NAME',
 159                      'description'    => 'SERVER_NAME_EXPLAIN',
 160                      'type'            => 'text',
 161                      'default'        => $server_name,
 162                  ),
 163                  'server_port' => array(
 164                      'label'            => 'SERVER_PORT',
 165                      'description'    => 'SERVER_PORT_EXPLAIN',
 166                      'type'            => 'text',
 167                      'default'        => $server_port,
 168                  ),
 169                  'script_path' => array(
 170                      'label'            => 'SCRIPT_PATH',
 171                      'description'    => 'SCRIPT_PATH_EXPLAIN',
 172                      'type'            => 'text',
 173                      'default'        => $script_path,
 174                  ),
 175                  'submit_server' => array(
 176                      'label'    => 'SUBMIT',
 177                      'type'    => 'submit',
 178                  )
 179              );
 180  
 181              $this->io_handler->add_user_form_group('SERVER_CONFIG', $server_form);
 182  
 183              throw new user_interaction_required_exception();
 184          }
 185      }
 186  
 187      /**
 188       * {@inheritdoc}
 189       */
 190  	static public function get_step_count()
 191      {
 192          return 0;
 193      }
 194  
 195      /**
 196       * {@inheritdoc}
 197       */
 198  	public function get_task_lang_name()
 199      {
 200          return '';
 201      }
 202  }


Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1