tbrehm
2007-08-13 313e336525fa923002095ef1858b1f29df8da7af
install/lib/installer_base.lib.php
@@ -38,13 +38,68 @@
   
   */
   
   function lng() {
   function lng($text) {
      return $text;
   }
   
   function error($msg) {
      die("ERROR: ".$msg."\n");
   }
   function simple_query($query,$answers,$default) {
      global $conf;
      $finished = false;
      do {
         $answers_str = implode(",",$answers);
         swrite($this->lng($query).' ('.$answers_str.') ['.$default.']: ');
         $input = sread();
         // Stop the installation
         if($input == 'quit') {
            swriteln($this->lng('Installation interrupted.'));
            die();
         }
         // Select the default
         if($input == '') {
            $answer = $default;
            $finished = true;
         }
         if(in_array($input,$answers)) {
            $answer = $input;
            $finished = true;
         }
      } while ($finished == false);
      swriteln();
      return $answer;
   }
   function free_query($query,$default) {
      global $conf;
      swrite($this->lng($query).' ['.$default.']: ');
      $input = sread();
      // Stop the installation
      if($input == 'quit') {
         swriteln($this->lng('Installation interrupted.'));
         die();
      }
      // Select the default
      if($input == '') {
         $answer = $default;
      } else {
         $answer = $input;
      }
      swriteln();
      return $answer;
   }
   
   function request_language() {
      
@@ -104,7 +159,7 @@
      Create postfix configuration files
   */
   
   function configure_postfix() {
   function configure_postfix($options = '') {
      global $conf;
      
      if(!is_dir($conf["dist_postfix_config_dir"])) $this->error("The postfix configuration directory ".$conf["dist_postfix_config_dir"]." does not exist.");
@@ -117,6 +172,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_forwardings.cf
@@ -127,6 +183,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_mailboxes.cf
@@ -137,6 +194,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_email2email.cf
@@ -147,6 +205,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_transports.cf
@@ -157,6 +216,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_recipient.cf
@@ -167,6 +227,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_sender.cf
@@ -177,6 +238,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // mysql-virtual_client.cf
@@ -187,6 +249,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
      
      // Changing mode and group of the new created config files.
@@ -229,8 +292,19 @@
         'smtpd_client_restrictions = check_client_access mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_client.cf',
         'maildrop_destination_concurrency_limit = 1',
         'maildrop_destination_recipient_limit   = 1',
         'virtual_transport = maildrop'
         'virtual_transport = maildrop',
         'header_checks = regexp:/etc/postfix/header_checks',
         'mime_header_checks = regexp:/etc/postfix/mime_header_checks',
         'nested_header_checks = regexp:/etc/postfix/nested_header_checks',
         'body_checks = regexp:/etc/postfix/body_checks'
      );
      // Create the header ynd body check files
      touch('/etc/postfix/header_checks');
      touch('/etc/postfix/mime_header_checks');
      touch('/etc/postfix/nested_header_checks');
      touch('/etc/postfix/body_checks');
      
      // Make a backup copy of the main.cf file
      copy($conf["dist_postfix_config_dir"].'/main.cf',$conf["dist_postfix_config_dir"].'/main.cf~');
@@ -248,13 +322,14 @@
  flags=R user=vmail argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}
      
      */
      if(!stristr($options,'dont-create-certs')) {
         // Create the SSL certificate
         $command = "cd ".$conf["dist_postfix_config_dir"]."; openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509";
         exec($command);
      
      // Create the SSL certificate
      $command = "cd ".$conf["dist_postfix_config_dir"]."; openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509";
      exec($command);
      $command = "chmod o= ".$conf["dist_postfix_config_dir"]."/smtpd.key";
      caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
         $command = "chmod o= ".$conf["dist_postfix_config_dir"]."/smtpd.key";
         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
      }
      
      /*
      We have to change the permissions of the courier authdaemon directory
@@ -263,6 +338,14 @@
      
      $command = "chmod 755  /var/run/courier/authdaemon/";
      caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
      // Changing maildrop lines in posfix master.cf
      if(is_file($conf["dist_postfix_config_dir"].'/master.cf')) copy($conf["dist_postfix_config_dir"].'/master.cf',$conf["dist_postfix_config_dir"].'/master.cf~');
      if(is_file($conf["dist_postfix_config_dir"].'/master.cf~')) exec('chmod 400 '.$conf["dist_postfix_config_dir"].'/master.cf~');
      $configfile = $conf["dist_postfix_config_dir"].'/master.cf';
      $content = rf($configfile);
      $content = str_replace('  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}','  flags=R user='.$conf["dist_postfix_vmail_username"].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',$content);
      wf($configfile,$content);
      
      // Writing the Maildrop mailfilter file
      $configfile = 'mailfilter';
@@ -289,47 +372,7 @@
   function configure_saslauthd() {
      global $conf;
      
      /*
      TODO: The example below is for Ubuntu 6.10
      mkdir -p /var/spool/postfix/var/run/saslauthd
Edit /etc/default/saslauthd. Remove the # in front of START=yes and add the line PARAMS="-m /var/spool/postfix/var/run/saslauthd -r".
vi /etc/default/saslauthd
The file should then look like this:
# This needs to be uncommented before saslauthd will be run automatically
START=yes
# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"
MECHANISMS="pam"
PARAMS="-m /var/spool/postfix/var/run/saslauthd -r"
We must also edit /etc/init.d/saslauthd and change the location of saslauthd's PID file.
vi /etc/init.d/saslauthd
Change the value of PIDFILE to /var/spool/postfix/var/run/${NAME}/saslauthd.pid:
PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"
Then restart Postfix and Saslauthd:
/etc/init.d/postfix restart
postfix check
/etc/init.d/saslauthd restart
      */
      $configfile = 'sasl_smtpd.conf';
      if(is_file($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf')) copy($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf',$conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~');
      if(is_file($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~')) exec('chmod 400 '.$conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~');
@@ -341,6 +384,26 @@
      wf($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf',$content);
      
      // TODO: Chmod and chown on the config file
      // Create the spool directory
      exec("mkdir -p /var/spool/postfix/var/run/saslauthd");
      // Edit the file /etc/default/saslauthd
      $configfile = '/etc/default/saslauthd';
      if(is_file($configfile)) copy($configfile,$configfile.'~');
      if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
      $content = rf($configfile);
      $content = str_replace('START=no','START=yes',$content);
      $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
      wf($configfile,$content);
      // Edit the file /etc/default/saslauthd
      $configfile = '/etc/init.d/saslauthd';
      $content = rf($configfile);
      $content = str_replace('PIDFILE=$RUN_DIR/saslauthd.pid','PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"',$content);
      wf($configfile,$content);
      
      
   }
@@ -379,6 +442,16 @@
      
      exec('chmod 660 '.$conf["dist_courier_config_dir"].'/'.$configfile);
      exec('chown daemon:daemon '.$conf["dist_courier_config_dir"].'/'.$configfile);
      //authdaemonrc
      $configfile = $conf["dist_courier_config_dir"].'/authdaemonrc';
      if(is_file($configfile)) copy($configfile,$configfile.'~');
      if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
      $content = rf($configfile);
      $content = str_replace('authmodulelist="authpam"','authmodulelist="authmysql"',$content);
      wf($configfile,$content);
   }
   
   function configure_amavis() {
@@ -453,6 +526,55 @@
   }
   
   
   function configure_pureftpd() {
      global $conf;
      // configure pam for SMTP authentication agains the ispconfig database
      $configfile = 'mysql.conf';
      if(is_file($conf["dist_pureftpd_config_dir"].'/'.$configfile)) copy($conf["dist_pureftpd_config_dir"].'/'.$configfile,$conf["dist_pureftpd_config_dir"].'/'.$configfile.'~');
      if(is_file($conf["dist_pureftpd_config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["dist_pureftpd_config_dir"].'/'.$configfile.'~');
      $content = rf("tpl/pureftpd_".$configfile.".master");
      $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_pureftpd_config_dir"].'/'.$configfile,$content);
      exec('chmod 600 '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
      exec('chown root:root '.$conf["dist_pureftpd_config_dir"].'/'.$configfile);
      // enable chrooting
      exec('echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone');
   }
   function configure_mydns() {
      global $conf;
      // configure pam for SMTP authentication agains the ispconfig database
      $configfile = 'mydns.conf';
      if(is_file($conf["dist_mydns_config_dir"].'/'.$configfile)) copy($conf["dist_mydns_config_dir"].'/'.$configfile,$conf["dist_mydns_config_dir"].'/'.$configfile.'~');
      if(is_file($conf["dist_mydns_config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["dist_mydns_config_dir"].'/'.$configfile.'~');
      $content = rf("tpl/".$configfile.".master");
      $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_host}',$conf["mysql_server_host"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["dist_mydns_config_dir"].'/'.$configfile,$content);
      exec('chmod 600 '.$conf["dist_mydns_config_dir"].'/'.$configfile);
      exec('chown root:root '.$conf["dist_mydns_config_dir"].'/'.$configfile);
   }
   function configure_apache() {
      global $conf;
      // Create the logging directory for the vhost logfiles
      exec("mkdir -p /var/log/ispconfig/httpd");
   }
   function install_ispconfig() {
      global $conf;
      
@@ -497,6 +619,7 @@
      $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
      $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
      $content = str_replace('{mysql_server_host}',$conf["mysql_server_host"],$content);
      $content = str_replace('{server_id}',$conf["server_id"],$content);
      wf($conf["ispconfig_install_dir"].'/server/lib/'.$configfile,$content);
      
      
@@ -508,6 +631,10 @@
      $command = "chown -R ispconfig:ispconfig ".$conf["ispconfig_install_dir"];
      caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
      
      // make sure that the server config file (not the interface one) is only readable by the root user
      exec('chmod 600 '.$conf["ispconfig_install_dir"].'/server/lib/'.$configfile);
      exec('chown root:root '.$conf["ispconfig_install_dir"].'/server/lib/'.$configfile);
      // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
      // and must be fixed as this will allow the apache user to read the ispconfig files.
      // Later this must run as own apache server or via suexec!
@@ -518,6 +645,13 @@
      // Make the shell scripts executable
      $command = "chmod +x ".$conf["ispconfig_install_dir"]."/server/scripts/*.sh";
      caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
      // Copy the ISPConfig vhost for the controlpanel
      copy('tpl/apache_ispconfig.vhost.master',$conf["dist_apache_vhost_conf_dir"].'/ispconfig.vhost');
      // and create the symlink
      if(!is_link($conf["dist_apache_vhost_conf_enabled_dir"].'/ispconfig.vhost')) {
         exec('ln -s '.$conf["dist_apache_vhost_conf_dir"].'/ispconfig.vhost '.$conf["dist_apache_vhost_conf_enabled_dir"].'/ispconfig.vhost');
      }
      
   }
   
@@ -539,7 +673,7 @@
      unlink('crontab.txt');
      
      // Getmail crontab
      exec("crontab -u root -l > crontab.txt");
      exec("crontab -u getmail -l > crontab.txt");
      $existing_cron_jobs = file('crontab.txt');
      
      $cron_jobs = array('*/5 * * * * '.$conf["dist_getmail_program"].' -g '.$conf["dist_getmail_config_dir"].' -r '.$conf["dist_getmail_config_dir"].'/*.conf &> /dev/null');
@@ -549,7 +683,7 @@
         }
      }
      file_put_contents('crontab.txt',$existing_cron_jobs);
      exec("crontab -u root crontab.txt &> /dev/null");
      exec("crontab -u getmail crontab.txt &> /dev/null");
      unlink('crontab.txt');
      
   }