fantu
2008-11-30 07cdaafc715bf55126959f93bd79b51b3cadddce
install/lib/installer_base.lib.php
@@ -35,6 +35,7 @@
   var $db;
   public $conf;
   public $install_ispconfig_interface = true;
    public function __construct()
@@ -118,7 +119,7 @@
      
      $cf = $conf['mysql']; // make $conf['mysql'] more accessible
      //** Create the database
      if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$cf['database'])) {
      if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$cf['database'].' DEFAULT CHARACTER SET '.$cf['charset'])) {
         $this->error('Unable to create MySQL database: '.$cf['database'].'.');
      }
      
@@ -131,10 +132,10 @@
         $this->error('Stopped: Database already contains some tables.');
      } else {
         if($cf['admin_password'] == '') {
            caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' '".$cf['database']."' < 'sql/ispconfig3.sql' &> /dev/null",
            caselog("mysql --default-character-set=".$cf['charset']." -h '".$cf['host']."' -u '".$cf['admin_user']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null",
                        __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql');
         } else {
            caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' -p'".$cf['admin_password']."' '".$cf['database']."' < 'sql/ispconfig3.sql' &> /dev/null",
            caselog("mysql --default-character-set=".$cf['charset']." -h '".$cf['host']."' -u '".$cf['admin_user']."' -p'".$cf['admin_password']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null",
                        __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql');
         }
         $db_tables = $this->db->getTables();
@@ -368,8 +369,10 @@
      wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
      
      //* Create the directory for the custom mailfilters
      $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
      caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
      if(!is_dir($cf['vmail_mailbox_base'].'/mailfilters')) {
         $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
      }
      
      //* Chmod and chown the .mailfilter file
      $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
@@ -407,7 +410,10 @@
      if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
      $content = rf($configfile);
      $content = str_replace('START=no','START=yes',$content);
      // Debian
      $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
      // Ubuntu
      $content = str_replace('OPTIONS="-c -m /var/run/saslauthd"','OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"',$content);
      wf($configfile,$content);
      
      // Edit the file /etc/init.d/saslauthd
@@ -415,6 +421,9 @@
      $content = rf($configfile);
      $content = str_replace('PIDFILE=$RUN_DIR/saslauthd.pid','PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"',$content);
      wf($configfile,$content);
      // add the postfix user to the sasl group (at least nescessary for ubuntu 8.04 and most likely debian lenny too.
      exec('adduser postfix sasl');
      
      
   }
@@ -611,7 +620,7 @@
      exec('mkdir -p /var/log/ispconfig/httpd');
      
      if(is_file('/etc/suphp/suphp.conf')) {
         replaceLine('/etc/suphp/suphp.conf','application/x-httpd-php=php:/usr/bin/php-cgi','x-httpd-suphp=php:/usr/bin/php-cgi',0);
         replaceLine('/etc/suphp/suphp.conf','php=php:/usr/bin','x-httpd-suphp=php:/usr/bin/php-cgi',0);
         replaceLine('/etc/suphp/suphp.conf','docroot=','docroot=/var/clients',0);
      }
      
@@ -741,6 +750,9 @@
            while (($file = readdir($dh)) !== false) {
               if($file != '.' && $file != '..') {
                  if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
                  if (strpos($file, '_core_module') !== false) {
                     if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
                  }
               }
            }
            closedir($dh);
@@ -753,6 +765,9 @@
            while (($file = readdir($dh)) !== false) {
               if($file != '.' && $file != '..') {
                  if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
                  if (strpos($file, '_core_plugin') !== false) {
                     if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
                  }
               }
            }
            closedir($dh);
@@ -817,13 +832,22 @@
         
        $content = rf("tpl/apache_ispconfig.vhost.master");
      $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
      // comment out the listen directive if port is 80 or 443
      if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
         $content = str_replace('{vhost_port_listen}', '#', $content);
      } else {
         $content = str_replace('{vhost_port_listen}', '', $content);
      }
      wf("$vhost_conf_dir/ispconfig.vhost", $content);
      
      //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
      //* and create the symlink
      if($this->install_ispconfig_interface == true) {
         if(!@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) {
            exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/ispconfig.vhost");
         if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
         if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
            exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
         }
      }
      
@@ -844,6 +868,10 @@
      if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
      if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
      if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
      //* Create the ispconfig log directory
      if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
      if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
      
      
   }
@@ -880,9 +908,14 @@
      exec('crontab -u root -l > crontab.txt');
      $existing_root_cron_jobs = file('crontab.txt');
      
      // remove existing ispconfig cronjobs, in case the syntax has changed
      foreach($existing_root_cron_jobs as $key => $val) {
         if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
      }
      $root_cron_jobs = array(
         '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
         '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
         '* * * * * /usr/local/ispconfig/server/server.sh > /dev/null',
         '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null'
      );
      foreach($root_cron_jobs as $cron_job) {
         if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
@@ -894,19 +927,27 @@
      unlink('crontab.txt');
      
      //* Getmail crontab
        $cf = $conf['getmail'];
      exec('crontab -u getmail -l > crontab.txt');
      $existing_cron_jobs = file('crontab.txt');
      if(is_user('getmail')) {
           $cf = $conf['getmail'];
         exec('crontab -u getmail -l > crontab.txt');
         $existing_cron_jobs = file('crontab.txt');
      
      $cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null');
      foreach($cron_jobs as $cron_job) {
         if(!in_array($cron_job."\n", $existing_cron_jobs)) {
            $existing_cron_jobs[] = $cron_job."\n";
         $cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null');
         // remove existing ispconfig cronjobs, in case the syntax has changed
         foreach($cron_jobs as $key => $val) {
            if(stristr($val,$cf['program'])) unset($cron_jobs[$key]);
         }
         foreach($cron_jobs as $cron_job) {
            if(!in_array($cron_job."\n", $existing_cron_jobs)) {
               $existing_cron_jobs[] = $cron_job."\n";
            }
         }
         file_put_contents('crontab.txt', $existing_cron_jobs);
         exec('crontab -u getmail crontab.txt &> /dev/null');
         unlink('crontab.txt');
      }
      file_put_contents('crontab.txt', $existing_cron_jobs);
      exec('crontab -u getmail crontab.txt &> /dev/null');
      unlink('crontab.txt');
   }
   
}