eGroupWare PHP Cross Reference Groupware Applications

Source: /setup/manageheader.php - 389 lines - 16174 bytes - Summary - Text - Print

Description: Setup - Manage the eGW config file header.inc.php

   1  <?php
   2  /**
   3   * Setup - Manage the eGW config file header.inc.php
   4   *
   5   * @link http://www.egroupware.org
   6   * @package setup
   7   * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
   8   * @author Miles Lott <milos@groupwhere.org>
   9   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
  10   * @version $Id$
  11   */
  12  
  13  include ('./inc/functions.inc.php');
  14  
  15  require_once ('./inc/class.setup_header.inc.php');
  16  $GLOBALS['egw_setup']->header = new setup_header();
  17  
  18  $setup_tpl = new Template('./templates/default', 'keep');    // 'keep' to keep our {hash} prefix of passwords
  19  $setup_tpl->set_file(array(
  20      'T_head' => 'head.tpl',
  21      'T_footer' => 'footer.tpl',
  22      'T_alert_msg' => 'msg_alert_msg.tpl',
  23      'T_login_main' => 'login_main.tpl',
  24      'T_login_stage_header' => 'login_stage_header.tpl',
  25      'T_setup_manage' => 'manageheader.tpl'
  26  ));
  27  $setup_tpl->set_block('T_login_stage_header','B_multi_domain','V_multi_domain');
  28  $setup_tpl->set_block('T_login_stage_header','B_single_domain','V_single_domain');
  29  $setup_tpl->set_block('T_setup_manage','manageheader','manageheader');
  30  $setup_tpl->set_block('T_setup_manage','domain','domain');
  31  
  32  $setup_tpl->set_var(array(
  33      'lang_select' => '',
  34      'comment_l' => '',
  35      'comment_r' => '',
  36      'detected' => '',
  37  ));
  38  
  39  // authentication phase
  40  $GLOBALS['egw_info']['setup']['stage']['header'] = $GLOBALS['egw_setup']->detection->check_header();
  41  
  42  if ($GLOBALS['egw_info']['setup']['stage']['header'] > 2 && !$GLOBALS['egw_setup']->auth('Header'))
  43  {
  44      $GLOBALS['egw_setup']->html->show_header('Please login',True);
  45      $GLOBALS['egw_setup']->html->login_form();
  46      $GLOBALS['egw_setup']->html->show_footer();
  47      exit;
  48  }
  49  // Detect current mode
  50  switch($GLOBALS['egw_info']['setup']['stage']['header'])
  51  {
  52      case '1':
  53          $GLOBALS['egw_info']['setup']['HeaderFormMSG'] = lang('Create your header.inc.php');
  54          $GLOBALS['egw_info']['setup']['PageMSG'] = lang('You have not created your header.inc.php yet!<br /> You can create it now.');
  55          break;
  56      case '2':
  57          $GLOBALS['egw_info']['setup']['HeaderFormMSG'] = $GLOBALS['egw_info']['setup']['PageMSG'] =
  58              lang('Your header admin password is NOT set. Please set it now!');
  59          break;
  60      case '3':
  61          $GLOBALS['egw_info']['setup']['HeaderFormMSG'] = $GLOBALS['egw_info']['setup']['PageMSG'] =
  62              $GLOBALS['egw_info']['setup']['HeaderLoginMSG'] =
  63              lang('You need to add at least one eGroupWare domain / database instance.');
  64          break;
  65      case '4':
  66          $GLOBALS['egw_info']['setup']['HeaderFormMSG'] = $GLOBALS['egw_info']['setup']['HeaderLoginMSG'] =
  67              lang('Your header.inc.php needs upgrading.');
  68          $GLOBALS['egw_info']['setup']['PageMSG'] = lang('Your header.inc.php needs upgrading.<br /><blink><b class="msg">WARNING!</b></blink><br /><b>MAKE BACKUPS!</b>');
  69          break;
  70      case '10':
  71          $GLOBALS['egw_info']['setup']['HeaderFormMSG'] = lang('Edit your header.inc.php');
  72          $GLOBALS['egw_info']['setup']['PageMSG'] = lang('Edit your existing header.inc.php');
  73          break;
  74  }
  75  
  76  if (!file_exists('../header.inc.php') || filesize('../header.inc.php') < 200 || !is_readable('../header.inc.php') || !defined('EGW_SERVER_ROOT') || EGW_SERVER_ROOT == '..')
  77  {
  78      $GLOBALS['egw_setup']->header->defaults();
  79  }
  80  else
  81  {
  82      $GLOBALS['egw_info']['server']['server_root'] = EGW_SERVER_ROOT;
  83  }
  84  if (isset($_POST['setting']))    // Post of the header-form
  85  {
  86      $validation_errors = check_header_form();    // validate the submitted form
  87  }
  88  if (!isset($_POST['action']) || $validation_errors)    // generate form to edit the header
  89  {
  90      show_header_form($validation_errors);
  91  }
  92  else
  93  {
  94      $newheader = $GLOBALS['egw_setup']->header->generate($GLOBALS['egw_info'],$GLOBALS['egw_domain']);
  95  
  96      list($action) = @each($_POST['action']);
  97      switch($action)
  98      {
  99          case 'download':
 100              html::content_header('header.inc.php','application/octet-stream');
 101              echo $newheader;
 102              break;
 103  
 104          case 'view':
 105              $GLOBALS['egw_setup']->html->show_header('Generated header.inc.php', False, 'header');
 106              echo '<table width="90%"><tr><td>';
 107              echo '<br />' . lang('Save this text as contents of your header.inc.php') . '<br /><hr />';
 108              echo "<pre>\n";
 109              echo htmlentities($newheader);
 110              echo "\n</pre><hr />\n";
 111              echo '<form action="index.php" method="post">';
 112              echo '<br />' . lang('After retrieving the file, put it into place as the header.inc.php.  Then, click "continue".') . '<br />';
 113              echo '<input type="hidden" name="FormLogout" value="header" />';
 114              echo '<input type="submit" name="junk" value="'.lang('Continue').'" />';
 115              echo '</form>';
 116              echo '</td></tr></table>';
 117              $GLOBALS['egw_setup']->html->show_footer();
 118              break;
 119  
 120          case 'write':
 121              if ((is_writeable('../header.inc.php') || !file_exists('../header.inc.php') && is_writeable('../')) &&
 122                  ($f = fopen('../header.inc.php','wb')))
 123              {
 124                  fwrite($f,$newheader);
 125                  fclose($f);
 126                  $GLOBALS['egw_setup']->html->show_header('Saved header.inc.php', False, 'header');
 127                  echo '<form action="index.php" method="post">';
 128                      echo '<br />' . lang('Created header.inc.php!');
 129                  echo '<input type="hidden" name="FormLogout" value="header" />';
 130                  echo '<input type="submit" name="junk" value="'.lang('Continue').'" />';
 131                  echo '</form>';
 132                  $GLOBALS['egw_setup']->html->show_footer();
 133                  break;
 134              }
 135              else
 136              {
 137                  $GLOBALS['egw_setup']->html->show_header('Error generating header.inc.php', False, 'header');
 138                  echo lang('Could not open header.inc.php for writing!') . '<br />' . "\n";
 139                  echo lang('Please check read/write permissions on directories, or back up and use another option.') . '<br />';
 140                  $GLOBALS['egw_setup']->html->show_footer();
 141              }
 142              break;
 143      }
 144  }
 145  
 146  /**
 147   * Validate the posted form and place the content again in $GLOBALS['egw_info'] and $GLOBALS['egw_domain']
 148   *
 149   * @return array with validation errors, see setup_header::validation_errors
 150   */
 151  function check_header_form()
 152  {
 153      // setting the non-domain settings from the posted content
 154      foreach($_POST['setting'] as $name => $value)
 155      {
 156          if (get_magic_quotes_gpc()) $value = stripslashes($value);
 157  
 158          switch($name)
 159          {
 160              case 'show_domain_selectbox':
 161              case 'mcrypt_enabled':
 162              case 'db_persistent':
 163                  $GLOBALS['egw_info']['server'][$name] = $value == 'True';
 164                  break;
 165              case 'new_admin_password':
 166                  if ($value) $GLOBALS['egw_info']['server']['header_admin_password'] = $value;
 167                  break;
 168              default:
 169                  $GLOBALS['egw_info']['server'][$name] = $value;
 170                  break;
 171          }
 172      }
 173  
 174      // setting the domain settings from the posted content
 175      foreach($_POST['domains'] as $key => $domain)
 176      {
 177          if ($_POST['deletedomain'][$key])
 178          {
 179              // Need to actually remove the domain.  Drop the DB manually.
 180              unset($GLOBALS['egw_domain'][$domain]);
 181              continue;
 182          }
 183  
 184          foreach($_POST['setting_'.$key] as $name => $value)
 185          {
 186              if (get_magic_quotes_gpc()) $value = stripslashes($value);
 187  
 188              if ($name == 'new_config_passwd')
 189              {
 190                  if ($value) $GLOBALS['egw_domain'][$domain]['config_passwd'] = $value;
 191                  continue;
 192              }
 193              $GLOBALS['egw_domain'][$domain][$name] = $value;
 194          }
 195      }
 196  
 197      // validate the input and return errors
 198      $validation_errors = $GLOBALS['egw_setup']->header->validation_errors($GLOBALS['egw_info']['server']['server_root']);
 199  
 200      //echo "egw_info[server]=<pre>".print_r($GLOBALS['egw_info']['server'],true)."</pre>\n";
 201      //echo "egw_domain=<pre>".print_r($GLOBALS['egw_domain'],true)."</pre>\n";
 202      //if ($validation_errors) echo "validation_errors=<pre>".print_r($validation_errors,true)."</pre>\n";
 203  
 204      return $validation_errors;
 205  }
 206  
 207  /**
 208   * Display the form to edit the configuration
 209   *
 210   * @param array $validation_errors to display
 211   */
 212  function show_header_form($validation_errors)
 213  {
 214      global $setup_tpl;
 215  
 216      $GLOBALS['egw_setup']->html->show_header($GLOBALS['egw_info']['setup']['HeaderFormMSG'], False, 'header');
 217  
 218      if(!get_var('ConfigLang',array('POST','COOKIE')))
 219      {
 220          $setup_tpl->set_var('lang_select','<tr><td colspan="2"><form action="manageheader.php" method="post">Please Select your language '.setup_html::lang_select(True,'en')."</form></td></tr>");
 221      }
 222  
 223      $setup_tpl->set_var('pagemsg',$GLOBALS['egw_info']['setup']['PageMSG']);
 224  
 225      // checking required PHP version
 226      if ((float) PHP_VERSION < $GLOBALS['egw_setup']->required_php_version)
 227      {
 228          $GLOBALS['egw_setup']->html->show_header($GLOBALS['egw_info']['setup']['header_msg'],True);
 229          $GLOBALS['egw_setup']->html->show_alert_msg('Error',
 230              lang('You are using PHP version %1. eGroupWare now requires %2 or later, recommended is PHP %3.',
 231              PHP_VERSION,$GLOBALS['egw_setup']->required_php_version,$GLOBALS['egw_setup']->recommended_php_version));
 232          $GLOBALS['egw_setup']->html->show_footer();
 233          exit;
 234      }
 235      $supported_db = $GLOBALS['egw_setup']->header->check_db_support($detected);
 236  
 237      if (!count($supported_db))
 238      {
 239          echo '<p align="center" class="msg"><b>'
 240              . lang('Did not find any valid DB support!')
 241              . "<br />\n"
 242              . lang('Try to configure your php to support one of the above mentioned DBMS, or install eGroupWare by hand.')
 243              . '</b></p>';
 244          $GLOBALS['egw_setup']->html->show_footer();
 245          exit;
 246      }
 247      $js_default_db_ports = 'var default_db_ports = new Array();'."\n";
 248      foreach($GLOBALS['egw_setup']->header->default_db_ports as $db => $port)
 249      {
 250          $js_default_db_ports .= '  default_db_ports["'.$db.'"]="'.$port.'";'."\n";
 251      }
 252      $setup_tpl->set_var('js_default_db_ports',$js_default_db_ports);
 253  
 254      if ($validation_errors) $setup_tpl->set_var('detected','<ul><li>'.implode("</li>\n<li>",$validation_errors)."</li>\n</ul>\n");
 255  
 256      if ($_POST['adddomain'])
 257      {
 258          $GLOBALS['egw_domain'][lang('new')] = $GLOBALS['egw_setup']->header->domain_defaults(
 259              $GLOBALS['egw_info']['server']['header_admin_user'],
 260              $GLOBALS['egw_info']['server']['header_admin_password'],$supported_db);
 261      }
 262      // show the non-domain settings
 263      //echo "<pre>".print_r($GLOBALS['egw_info']['server'],true)."</pre>\n";
 264      foreach($GLOBALS['egw_info']['server'] as $name => $value)
 265      {
 266          switch($name)
 267          {
 268              case 'db_persistent':
 269              case 'show_domain_selectbox':
 270              case 'mcrypt_enabled':
 271                  $setup_tpl->set_var($name.($GLOBALS['egw_info']['server'][$name] ? '_yes' : '_no'),' selected="selected"');
 272                  break;
 273              default:
 274                  if (!is_array($value)) $setup_tpl->set_var($name,htmlspecialchars($value));
 275                  break;
 276          }
 277      }
 278      $supported_session_handler = array(
 279          'egw_session_files' => lang('PHP session handler enabled in php.ini'),
 280      );
 281      if ($GLOBALS['egw_info']['server']['session_handler'] && !isset($supported_session_handler[$GLOBALS['egw_info']['server']['session_handler']]))
 282      {
 283          $supported_session_handler[$GLOBALS['egw_info']['server']['session_handler']] = lang("Custom handler: %1",$GLOBALS['egw_info']['server']['session_handler']);
 284      }
 285      $options = array();
 286      foreach($supported_session_handler as $type => $label)
 287      {
 288          $options[] = '<option ' . ($type == $GLOBALS['egw_info']['server']['session_handler'] ?
 289              'selected="selected" ' : '') . 'value="' . $type . '">' . $label . '</option>';
 290      }
 291      $setup_tpl->set_var('session_options',implode("\n",$options));
 292  
 293      // showing the settings of all domains
 294      foreach($GLOBALS['egw_domain'] as $domain => $data)
 295      {
 296          $setup_tpl->set_var('db_domain',htmlspecialchars($domain));
 297          foreach($data as $name => $value)
 298          {
 299              if ($name == 'db_port' && !$value)    // Set default here if the admin didn't set a port yet
 300              {
 301                  $value = $GLOBALS['egw_setup']->header->default_db_ports[$data['db_type']];
 302              }
 303              $setup_tpl->set_var($name,htmlspecialchars($value));
 304          }
 305          $dbtype_options = '';
 306          foreach($supported_db as $db)
 307          {
 308              $dbtype_options .= '<option ' . ($db == $data['db_type'] ? 'selected="selected" ' : '').
 309                  'value="' . $db . '">' . $GLOBALS['egw_setup']->header->db_fullnames[$db] . "</option>\n";
 310          }
 311          $setup_tpl->set_var('dbtype_options',$dbtype_options);
 312  
 313          $setup_tpl->parse('domains','domain',True);
 314      }
 315      if(is_writeable('../header.inc.php') || !file_exists('../header.inc.php') && is_writeable('../'))
 316      {
 317          $setup_tpl->set_var('actions',lang('%1, %2 or %3 the configuration file.',
 318              '<input type="submit" name="action[write]" value="'.htmlspecialchars(lang('Write')).'" />',
 319              '<input type="submit" name="action[download]" value="'.htmlspecialchars(lang('Download')).'" />',
 320              '<input type="submit" name="action[view]" value="'.htmlspecialchars(lang('View')).'" />'));
 321      }
 322      else
 323      {
 324          $setup_tpl->set_var('actions',lang('Cannot create the header.inc.php due to file permission restrictions.<br /> Instead you can %1 or %2 the file.',
 325              '<input type="submit" name="action[download]" value="'.htmlspecialchars(lang('Download')).'" />',
 326              '<input type="submit" name="action[view]" value="'.htmlspecialchars(lang('View')).'" />'));
 327      }
 328      // set domain and password for the continue button
 329      @reset($GLOBALS['egw_domain']);
 330      list($firstDomain) = @each($GLOBALS['egw_domain']);
 331  
 332      $setup_tpl->set_var(array(
 333          'FormDomain' => $firstDomain,
 334          'FormUser'   => $GLOBALS['egw_domain'][$firstDomain]['config_user'],
 335          'FormPW'     => $GLOBALS['egw_domain'][$firstDomain]['config_passwd']
 336      ));
 337  
 338      $setup_tpl->set_var(array(
 339          'lang_analysis'        => $validation_errors ? lang('Validation errors') : '',
 340          'lang_settings'        => lang('Settings'),
 341          'lang_domain'          => lang('Database instance (eGW domain)'),
 342          'lang_delete'          => lang('Delete'),
 343          'lang_adddomain'       => lang('Add new database instance (eGW domain)'),
 344          'lang_serverroot'      => lang('Server Root'),
 345          'lang_serverroot_descr'=> lang('Path (not URL!) to your eGroupWare installation.'),
 346          'lang_adminuser'       => lang('Header username'),
 347          'lang_adminuser_descr' => lang('Admin user for header manager'),
 348          'lang_adminpass'       => lang('Header password'),
 349          'lang_adminpass_descr' => lang('Admin password to header manager').'.',
 350          'lang_leave_empty'     => lang('Leave empty to keep current.'),
 351          'lang_setup_acl'       => lang('Limit access'),
 352          'lang_setup_acl_descr' => lang('Limit access to setup to the following addresses, networks or hostnames (e.g. 127.0.0.1,10.1.1,myhost.dnydns.org)'),
 353          'lang_dbhost'          => lang('DB Host'),
 354          'lang_dbhostdescr'     => lang('Hostname/IP of database server').'<br />'.
 355              lang('Postgres: Leave it empty to use the prefered unix domain sockets instead of a tcp/ip connection').'<br />'.
 356              lang('ODBC / MaxDB: DSN (data source name) to use'),
 357          'lang_dbport'          => lang('DB Port'),
 358          'lang_dbportdescr'     => lang('TCP port number of database server'),
 359          'lang_dbname'          => lang('DB Name'),
 360          'lang_dbnamedescr'     => lang('Name of database'),
 361          'lang_dbuser'          => lang('DB User'),
 362          'lang_dbuserdescr'     => lang('Name of db user eGroupWare uses to connect'),
 363          'lang_dbpass'          => lang('DB Password'),
 364          'lang_dbpassdescr'     => lang('Password of db user'),
 365          'lang_dbtype'          => lang('DB Type'),
 366          'lang_whichdb'         => lang('Which database type do you want to use with eGroupWare?'),
 367          'lang_configuser'      => lang('Configuration User'),
 368          'lang_configuser_descr'=> lang('Loginname needed for domain configuration'),
 369          'lang_configpass'      => lang('Configuration Password'),
 370          'lang_passforconfig'   => lang('Password needed for domain configuration.'),
 371          'lang_persist'         => lang('Persistent connections'),
 372          'lang_persistdescr'    => lang('Do you want persistent connections (higher performance, but consumes more resources)'),
 373          'lang_session'         => lang('Sessions Handler'),
 374          'lang_session_descr'   => lang('Session handler class used.'),
 375          'lang_enablemcrypt'    => lang('Enable MCrypt'),
 376          'lang_mcrypt_warning'  => lang('Not all mcrypt algorithms and modes work with eGroupWare. If you experience problems try switching it off.'),
 377          'lang_mcryptiv'        => lang('MCrypt initialization vector'),
 378          'lang_mcryptivdescr'   => lang('This should be around 30 bytes in length.<br />Note: The default has been randomly generated.'),
 379          'lang_domselect'       => lang('Domain select box on login'),
 380          'lang_domselect_descr' => lang('Alternatively domains can be accessed by logging in with <i>username@domain</i>.'),
 381          'lang_finaldescr'      => lang('After retrieving the file, put it into place as the header.inc.php.  Then, click "continue".'),
 382          'lang_continue'        => lang('Continue'),
 383          'lang_Yes'             => lang('Yes'),
 384          'lang_No'              => lang('No')
 385      ));
 386      $setup_tpl->pfp('out','manageheader');
 387  
 388      $GLOBALS['egw_setup']->html->show_footer();
 389  }

title

Description

title

Description

title

Description

title

title

Body