YACS PHP Cross Reference Content Management Systems

Source: /setup.php - 356 lines - 14223 bytes - Summary - Text - Print

Description: the main setup script

   1  <?php
   2  /**
   3   * the main setup script
   4   *
   5   * This page is used for the very first installation of the server
   6   *
   7   * This script looks for following items:
   8   * - [code]parameters/control.include.php[/code]
   9   * - [code]parameters/hooks.include.php[/code]
  10   * - [code]parameters/skins.include.php[/code]
  11   *
  12   * If all of these items are absent, the script assumes this is a first installation,
  13   * welcomes the surfer, and offers to jump to [script]control/configure.php[/script].
  14   *
  15   * Also, the script performs several test to ensure:
  16   * - that the version of PHP is greater or equal than 4.3
  17   * - that the MySQL PHP extension is available
  18   * - that the XML parser of PHP is available
  19   * - that it can write to local files (configuration and log files)
  20   *
  21   * If one of these tests fails, the script advises the user on the right thing to do.
  22   * For example, it will offer to chmod the YACS installation directory is necessary.
  23   *
  24   * On first installation this script will behave like a setup assistant,
  25   * and the user will have to pass through successive screens:
  26   * - the configuration panel ([script]control/configure.php[/script]), to record database and other essential parameters
  27   * - the extension scanner ([script]control/scan.php[/script]), to load all hooks
  28   * - the database setup ([script]control/setup.php[/script]), to create tables in the database
  29   * - the populate screen ([script]control/populate.php[/script]), to create a basic set of records in the database
  30   * - the configuration panel for skins ([script]scripts/configure.php[/script]), to set rendering parameters
  31   *
  32   * @see control/configure.php
  33   * @see control/scan.php
  34   * @see control/setup.php
  35   * @see control/populate.php
  36   * @see scripts/configure.php
  37   *
  38   * If at least one file is missing, the script assumes there is an on-going installation,
  39   * and proposes to jump to the control panel at [script]control/index.php[/script].
  40   * In this case the control panel will redirect to the adequate script depending of the missing element.
  41   *
  42   * If all files are present, but there is no [code]parameters/switch.on[/code] nor [code]parameters/switch.off[/code] file, the script
  43   * assumes the installation ends correctly, creates [code]parameters/switch.on[/code], and offers to jump to the
  44   * control panel at [script]control/index.php[/script].
  45   * Also, if there is no index page at the upper directory level, the script will silently attempt
  46   * to duplicate index.php there.
  47   *
  48   * Else the script assumes there is no need for an installation,
  49   * and offers to jump to the control panel at [script]control/index.php[/script].
  50   *
  51   * @see control/index.php
  52   *
  53   * @author Bernard Paques
  54   * @reference
  55   * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  56   */
  57  
  58  // include explicitly some libraries
  59  if(!is_readable('shared/global.php'))
  60      exit('No shared library. Please copy the entire set of files in the provided archive.');
  61  include_once  'shared/global.php';
  62  
  63  // load localized strings
  64  i18n::bind('root');
  65  
  66  // load the skin
  67  load_skin('setup');
  68  
  69  // check key files
  70  $missing = 0;
  71  if(!file_exists('parameters/control.include.php'))
  72      $missing++;
  73  if(!file_exists('parameters/hooks.include.php'))
  74      $missing++;
  75  if(!file_exists('parameters/skins.include.php'))
  76      $missing++;
  77  
  78  // title
  79  $context['page_title'] = i18n::s('Setup assistant');
  80  
  81  // stop crawlers
  82  if(Surfer::is_crawler()) {
  83      Safe::header('Status: 401 Unauthorized', TRUE, 401);
  84      Logger::error(i18n::s('You are not allowed to perform this operation.'));
  85  
  86  // first installation
  87  } elseif($missing == 3) {
  88  
  89      // to report on checks
  90      $checks = array();
  91  
  92      // ensure we have a minimum version of PHP
  93      if(version_compare(phpversion(),'5.1','<')) {
  94  
  95          // provide instructions
  96          Logger::error(sprintf(i18n::s('ERROR: YACS requires at least PHP version 5.1. The server runs version %s.'), phpversion()));
  97  
  98          $context['text'] .= '<p class="details"><a href="setup.php">'.i18n::s('Check PHP version again')."</a></p>\n";
  99  
 100          // check
 101          $check = i18n::s('ERROR');
 102  
 103      } else
 104          $check = i18n::s('OK');
 105  
 106      // check
 107      $checks[] = array(i18n::s('PHP'), phpversion(), $check);
 108  
 109      // ensure we have MySQL
 110      if(!SQL::check()) {
 111  
 112          // provide instructions
 113          Logger::error(i18n::s('ERROR: YACS requires the MySQL PHP extension.'));
 114  
 115          $context['text'] .= '<p class="details"><a href="setup.php">'.i18n::s('Check the MySQL PHP extension again')."</a></p>\n";
 116  
 117          // check
 118          $value = i18n::s('Absent');
 119          $check = i18n::s('ERROR');
 120  
 121      } else {
 122          $value = i18n::s('Present');
 123          $check = i18n::s('OK');
 124      }
 125  
 126      // check
 127      $checks[] = array(i18n::s('MySQL'), $value, $check);
 128  
 129      // ensure we can handle XML
 130      if(!is_callable('xml_parser_create')) {
 131  
 132          // provide instructions
 133          Logger::error(i18n::s('ERROR: YACS requires the XML PHP extension.'));
 134  
 135          $context['text'] .= '<p class="details"><a href="setup.php">'.i18n::s('Check the XML PHP extension again')."</a></p>\n";
 136  
 137          // check
 138          $value = i18n::s('Absent');
 139          $check = i18n::s('ERROR');
 140  
 141      } else {
 142          $value = i18n::s('Present');
 143          $check = i18n::s('OK');
 144      }
 145  
 146      // check
 147      $checks[] = array(i18n::s('XML'), $value, $check);
 148  
 149      // ensure we can handle ZIP files
 150      if(!is_callable('zip_open')) {
 151          $context['text'] .= '<p>'.i18n::s('WARNING: You will not be able to upload zip files.')."</p>\n";
 152          $context['text'] .= '<p class="details"><a href="setup.php">'.i18n::s('Check the ZIP PHP extension again')."</a></p>\n";
 153  
 154          // check
 155          $value = i18n::s('Absent');
 156          $check = i18n::s('WARNING');
 157  
 158      } else {
 159          $value = i18n::s('Present');
 160          $check = i18n::s('OK');
 161      }
 162  
 163      // check
 164      $checks[] = array(i18n::s('zip'), $value, $check);
 165  
 166      // show evidence of safe mode
 167      if(Safe::ini_get('safe_mode')) {
 168          $context['text'] .= '<p>'.i18n::s('WARNING: This server runs in safe mode, and YACS may be prevented to perform a number of key operations.')."</p>\n";
 169  
 170          // check
 171          $value = i18n::s('Yes');
 172          $check = i18n::s('WARNING');
 173  
 174      } else {
 175          $value = i18n::s('No');
 176          $check = i18n::s('OK');
 177      }
 178  
 179      // check
 180      $checks[] = array(i18n::s('Safe mode'), $value, $check);
 181  
 182      // test our ability to write to files
 183      $can_write = TRUE;
 184  
 185      // actual attempt to write to representative files
 186      $files = array();
 187      $files[] = './parameters/agents.include.php';
 188      $files[] = './parameters/collections.include.php';
 189      $files[] = './parameters/control.include.php';
 190      $files[] = './parameters/feeds.include.php';
 191      $files[] = './parameters/files.include.php';
 192      $files[] = './parameters/hooks.include.php';
 193      $files[] = './parameters/hooks.xml';
 194      $files[] = './parameters/letters.include.php';
 195      $files[] = './parameters/scripts.include.php';
 196      $files[] = './parameters/servers.include.php';
 197      $files[] = './parameters/services.include.php';
 198      $files[] = './parameters/skins.include.php';
 199      $files[] = './parameters/switch.on';
 200      $files[] = './parameters/users.include.php';
 201      $files[] = './temporary/debug.txt';
 202      $files[] = './temporary/ie_bookmarklet.html';
 203      $files[] = './temporary/ie_bookmarklet.reg';
 204      $files[] = './temporary/log.txt';
 205      foreach($files as $file) {
 206  
 207          // test one file at a time
 208          if(!Safe::is_writable($file)) {
 209              $context['text'] .= sprintf(i18n::s('Impossible to write to %s.'), $file).BR;
 210              $can_write = FALSE;
 211          }
 212      }
 213  
 214      // please chmod or chown files
 215      if(!$can_write) {
 216  
 217          // provide instructions
 218          $context['text'] .= '<p>'.i18n::s('WARNING: YACS cannot write to files. If you are running some Unix, please ensure that permissions have been properly set. This issue can also be due to server running in safe mode.')."</p>\n";
 219  
 220          $context['text'] .= '<p>'.sprintf(i18n::s('Check the provided %s file to find more help on file permissions.'), '<a href="'.i18n::s('readme.txt').'">'.i18n::s('readme.txt').'</a>')."</p>\n";
 221  
 222          $context['text'] .= '<p class="details"><a href="setup.php">'.i18n::s('Check again our ability to write to files')."</a></p>\n";
 223  
 224  
 225          // check
 226          $value = i18n::s('Configuration files cannot be changed');
 227          $check = i18n::s('WARNING');
 228  
 229      } else {
 230          $value = i18n::s('May change configuration files');
 231          $check = i18n::s('OK');
 232      }
 233  
 234      // check
 235      $checks[] = array(i18n::s('Permissions'), $value, $check);
 236  
 237      // report on prerequisite checks
 238      $context['text'] .= '<h2>'.i18n::s('Pre-installation checks').'</h2>';
 239  
 240      // check results
 241      $context['text'] .= '<table border="1">';
 242      $row_count = 1;
 243      foreach($checks as $cells)
 244          $context['text'] .= Skin::table_row($cells, $row_count++);
 245      $context['text'] .= '</table>';
 246  
 247      // link to the readme file
 248      $context['text'] .= '<p>'.sprintf(i18n::s('Check the provided %s file to ensure prerequisites are fulfilled.'), '<a href="'.i18n::s('readme.txt').'">'.i18n::s('readme.txt').'</a>')."</p>\n";
 249  
 250      // link to the configuration page
 251      if(!count($context['error'])) {
 252  
 253          // report on checks
 254          $context['text'] .= '<h2>'.i18n::s('Ready to start the installation').'</h2>';
 255  
 256          // splash screen
 257          $context['text'] .= i18n::s("<p>At the moment no configuration file has been found. You will now have to pass through several steps in order to achieve the setup of your server:</p>\n<ul>\n<li>Configure parameters related to the database.</li>\n<li>Load extension hooks.</li>\n<li>Create tables in the database.</li>\n<li>Add one user profile and populate the database.</li>\n<li>Configure the theme of your server.</li>\n</ul>\nIn normal conditions this will take only some minutes. If you have any problems, please consult <a href=\"http://www.yacs.fr/\">www.yacs.fr</a> for additional support.<p>Thank you for having selected the YACS solution.</p>")."\n";
 258  
 259          // add a button to start the installation process
 260          $context['text'] .= '<form method="get" action="control/configure.php" id="main_form">'."\n"
 261              .'<p class="assistant_bar">'.Skin::build_submit_button(i18n::s('Start the installation process'), NULL, NULL, 'confirmed').'</p>'."\n"
 262              .'</form>'."\n";
 263  
 264          // a place holder for cookies activation
 265          $context['text'] .= '<p id="ask_for_cookies" style="display: none; color: red; text-decoration: blink;"></p>';
 266  
 267          // the script used to check that cookies are activated
 268          $context['text'] .= JS_PREFIX
 269              .'document.cookie = \'CookiesEnabled=1\';'."\n"
 270              .'if((document.cookie == "") && document.getElementById) {'."\n"
 271              .'    $("ask_for_cookies").update("'.i18n::s('You must enable cookies to manage this server. Change settings of your browser accordingly, then revisit this page afterwards.').'");'."\n"
 272              .'    $("ask_for_cookies").style.display = "block";'."\n"
 273              .'    $("confirmed").disabled = true;'."\n"
 274              .'}'."\n"
 275              .JS_SUFFIX."\n";
 276  
 277          // purge the scripts/run_once directory on first installation
 278          include_once $context['path_to_root'].'scripts/scripts.php';
 279          Scripts::purge_run_once();
 280  
 281      }
 282  
 283  // on-going installation
 284  } elseif($missing) {
 285  
 286      // splash screen
 287      $context['text'] .= '<p>'.i18n::s('Some configuration files are missing. Please follow the link to complete the installation process.')."</p>\n";
 288  
 289      // to the control panel
 290      $context['text'] .= '<p><a href="control/">'.i18n::s('Control Panel')."</a></p>\n";
 291  
 292  // end of the installation
 293  } elseif(!file_exists('parameters/switch.on') && !file_exists('parameters/switch.off')) {
 294  
 295      // create the switch
 296      $content = '---------------------------------------------'."\n"
 297          .'YACS will process requests if this file is named switch.on,'."\n"
 298          .'and will redirect everything to control/closed.php if its name is changed to switch.off.'."\n"
 299          ."\n"
 300          .'Associates can use the script control/switch.php to stop and restart remotely.'."\n"
 301          .'---------------------------------------------'."\n";
 302      if(!Safe::file_put_contents('parameters/switch.on', $content)) {
 303  
 304          // not enough rights to write the file
 305          Logger::error(i18n::s('ERROR: YACS cannot create the file parameters/switch.on to activate the server.'));
 306  
 307          // allow for a manual update
 308          $context['text'] .= '<p style="text-decoration: blink;">'.sprintf(i18n::s('To actually switch on the server, please copy and paste following lines by yourself in file %s.'), 'parameters/switch.on')."</p>\n";
 309  
 310          // content of the switch file
 311          $context['text'] .= '<pre>'.$content."</pre>\n";
 312  
 313      }
 314  
 315      // if there is no index at the upper level
 316      if(!file_exists($context['path_to_root'].'../index.php') && ($content = Safe::file_get_contents($context['path_to_root'].'index.php'))) {
 317  
 318          // silently attempt to duplicate our index
 319          Safe::file_put_contents('../index.php', $content);
 320  
 321          // remember this for the next incremental update
 322          $content = '<?php'."\n"
 323              .'// This file has been created by the setup script setup.php'."\n"
 324              .'// on '.gmdate("F j, Y, g:i a").' GMT, for '.Surfer::get_name().'. Please do not modify it manually.'."\n"
 325              .'$context[\'home_at_root\']=\'Y\';'."\n"
 326              .'$context[\'reference_server\']=\''.addcslashes(i18n::s('www.yacs.fr'), "\\'")."';\n"
 327              .'?>'."\n";
 328          Safe::file_put_contents('parameters/scripts.include.php', $content);
 329  
 330      }
 331  
 332      // the splash message
 333      $context['text'] .= sprintf(i18n::s("<p>You have passed through the several installation steps.</p>\nWhat do you want to do now?<ul>\n<li>Select %s for your site.</li>\n<li>Populate your site with the %s.</li>\n<li>Manage everything from the %s.</li>\n<li>Check the %s of this site.</li>\n<li>Review %s.</li>\n<li>%s.</li>\n<li>Look at the %s.</li>\n<li>Visit %s to learn more.</li>\n</ul>\n<p>Thank you for having selected to use YACS for your web site.</p>\n"),
 334          Skin::build_link('skins/', i18n::s('another skin')),
 335          Skin::build_link('help/populate.php', i18n::s('Content Assistant')),
 336          Skin::build_link('control/', i18n::s('Control Panel')),
 337          Skin::build_link($context['url_to_root'], i18n::s('front page')),
 338          Skin::build_link('users/view.php', i18n::s('your profile')),
 339          Skin::build_link('articles/edit.php', i18n::s('Add a page')),
 340          Skin::build_link('help/', i18n::s('Help index')),
 341          Skin::build_link(i18n::s('http://www.yacs.fr/'), i18n::s('www.yacs.fr'), 'external'))."\n";
 342  
 343  // no need for installation
 344  } else {
 345  
 346      // the splash message
 347      $context['text'] .= i18n::s('<p>Since basic configuration files exist on your server, it is likely that the installation has been achieved successfully. Click on the link below to modify the running parameters of your server.</p>')."\n";
 348  
 349      // to the control panel
 350      $context['text'] .= '<p><a href="control/">'.i18n::s('Control Panel')."</a></p>\n";
 351  
 352  }
 353  
 354  // render the skin
 355  render_skin();
 356  ?>

title

Description

title

Description

title

Description

title

title

Body