protected function composePhpOptions($domain, $ssl_vhost = false)
 {
     $php_options_text = '';
     if ($domain['phpenabled'] == '1') {
         $php = new phpinterface($domain);
         $phpconfig = $php->getPhpConfig((int) $domain['phpsettingid']);
         if ((int) Settings::Get('phpfpm.enabled') == 1) {
             $srvName = 'fpm.external';
             if ($domain['ssl'] == 1 && $ssl_vhost) {
                 $srvName = 'ssl-fpm.external';
             }
             // #1317 - perl is executed via apache and therefore, when using fpm, does not know the user
             // which perl is supposed to run as, hence the need for Suexec need
             if (customerHasPerlEnabled($domain['customerid'])) {
                 $php_options_text .= '  SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";
             }
             // mod_proxy stuff for apache-2.4
             if (Settings::Get('system.apache24') == '1' && Settings::Get('phpfpm.use_mod_proxy') == '1') {
                 $php_options_text .= '  <FilesMatch \\.php$>' . "\n";
                 $php_options_text .= '  SetHandler proxy:unix:' . $php->getInterface()->getSocketFile() . '|fcgi://localhost' . "\n";
                 $php_options_text .= '  </FilesMatch>' . "\n";
                 $mypath_dir = new frxDirectory($domain['documentroot']);
                 // only create the require all granted if there is not active directory-protection
                 // for this path, as this would be the first require and therefore grant all access
                 if ($mypath_dir->isUserProtected() == false) {
                     $php_options_text .= '  <Directory "' . makeCorrectDir($domain['documentroot']) . '">' . "\n";
                     $php_options_text .= '    Require all granted' . "\n";
                     $php_options_text .= '  </Directory>' . "\n";
                 }
             } else {
                 $php_options_text .= '  FastCgiExternalServer ' . $php->getInterface()->getAliasConfigDir() . $srvName . ' -socket ' . $php->getInterface()->getSocketFile() . ' -idle-timeout ' . Settings::Get('phpfpm.idle_timeout') . "\n";
                 $php_options_text .= '  <Directory "' . makeCorrectDir($domain['documentroot']) . '">' . "\n";
                 $php_options_text .= '    <FilesMatch "\\.php$">' . "\n";
                 $php_options_text .= '      SetHandler php5-fastcgi' . "\n";
                 $php_options_text .= '      Action php5-fastcgi /fastcgiphp' . "\n";
                 $php_options_text .= '      Options +ExecCGI' . "\n";
                 $php_options_text .= '    </FilesMatch>' . "\n";
                 // >=apache-2.4 enabled?
                 if (Settings::Get('system.apache24') == '1') {
                     $mypath_dir = new frxDirectory($domain['documentroot']);
                     // only create the require all granted if there is not active directory-protection
                     // for this path, as this would be the first require and therefore grant all access
                     if ($mypath_dir->isUserProtected() == false) {
                         $php_options_text .= '    Require all granted' . "\n";
                     }
                 } else {
                     $php_options_text .= '    Order allow,deny' . "\n";
                     $php_options_text .= '    allow from all' . "\n";
                 }
                 $php_options_text .= '  </Directory>' . "\n";
                 $php_options_text .= '  Alias /fastcgiphp ' . $php->getInterface()->getAliasConfigDir() . $srvName . "\n";
             }
         } else {
             $php_options_text .= '  FcgidIdleTimeout ' . Settings::Get('system.mod_fcgid_idle_timeout') . "\n";
             if ((int) Settings::Get('system.mod_fcgid_wrapper') == 0) {
                 $php_options_text .= '  SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";
                 $php_options_text .= '  ScriptAlias /php/ ' . $php->getInterface()->getConfigDir() . "\n";
             } else {
                 $php_options_text .= '  SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";
                 $php_options_text .= '  <Directory "' . makeCorrectDir($domain['documentroot']) . '">' . "\n";
                 $file_extensions = explode(' ', $phpconfig['file_extensions']);
                 $php_options_text .= '    <FilesMatch "\\.(' . implode('|', $file_extensions) . ')$">' . "\n";
                 $php_options_text .= '      SetHandler fcgid-script' . "\n";
                 foreach ($file_extensions as $file_extension) {
                     $php_options_text .= '      FcgidWrapper ' . $php->getInterface()->getStarterFile() . ' .' . $file_extension . "\n";
                 }
                 $php_options_text .= '      Options +ExecCGI' . "\n";
                 $php_options_text .= '    </FilesMatch>' . "\n";
                 // >=apache-2.4 enabled?
                 if (Settings::Get('system.apache24') == '1') {
                     $mypath_dir = new frxDirectory($domain['documentroot']);
                     // only create the require all granted if there is not active directory-protection
                     // for this path, as this would be the first require and therefore grant all access
                     if ($mypath_dir->isUserProtected() == false) {
                         $php_options_text .= '    Require all granted' . "\n";
                     }
                 } else {
                     $php_options_text .= '    Order allow,deny' . "\n";
                     $php_options_text .= '    allow from all' . "\n";
                 }
                 $php_options_text .= '  </Directory>' . "\n";
             }
         }
         // create starter-file | config-file
         $php->getInterface()->createConfig($phpconfig);
         // create php.ini (fpm does nothing here, as it
         // defines ini-settings in its pool config)
         $php->getInterface()->createIniFile($phpconfig);
     } else {
         $php_options_text .= '  # PHP is disabled for this vHost' . "\n";
     }
     return $php_options_text;
 }
 /**
  * We write the configs
  */
 public function writeConfigs()
 {
     // Write diroptions
     fwrite($this->debugHandler, '  apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_diroptions') . "\n");
     $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_diroptions'));
     if (count($this->diroptions_data) > 0) {
         $optsDir = new frxDirectory(Settings::Get('system.apacheconf_diroptions'));
         if (!$optsDir->isConfigDir()) {
             // Save one big file
             $diroptions_file = '';
             foreach ($this->diroptions_data as $diroptions_filename => $diroptions_content) {
                 $diroptions_file .= $diroptions_content . "\n\n";
             }
             $diroptions_filename = Settings::Get('system.apacheconf_diroptions');
             // Apply header
             $diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file;
             $diroptions_file_handler = fopen($diroptions_filename, 'w');
             fwrite($diroptions_file_handler, $diroptions_file);
             fclose($diroptions_file_handler);
         } else {
             if (!file_exists(Settings::Get('system.apacheconf_diroptions'))) {
                 fwrite($this->debugHandler, '  apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions'))) . "\n");
                 $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions'))));
                 safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions'))));
             }
             // Write a single file for every diroption
             foreach ($this->diroptions_data as $diroptions_filename => $diroptions_file) {
                 $this->known_diroptionsfilenames[] = basename($diroptions_filename);
                 // Apply header
                 $diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file;
                 $diroptions_file_handler = fopen($diroptions_filename, 'w');
                 fwrite($diroptions_file_handler, $diroptions_file);
                 fclose($diroptions_file_handler);
             }
         }
     }
     // Write htpasswds
     fwrite($this->debugHandler, '  apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_htpasswddir') . "\n");
     $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_htpasswddir'));
     if (count($this->htpasswds_data) > 0) {
         if (!file_exists(Settings::Get('system.apacheconf_htpasswddir'))) {
             $umask = umask();
             umask(00);
             mkdir(Settings::Get('system.apacheconf_htpasswddir'), 0751);
             umask($umask);
         }
         $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir'));
         if ($htpasswdDir->isConfigDir(true)) {
             foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) {
                 $this->known_htpasswdsfilenames[] = basename($htpasswd_filename);
                 $htpasswd_file_handler = fopen($htpasswd_filename, 'w');
                 fwrite($htpasswd_file_handler, $htpasswd_file);
                 fclose($htpasswd_file_handler);
             }
         } else {
             fwrite($this->debugHandler, '  cron_tasks: WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n");
             echo 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!';
             $this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!');
         }
     }
     // Write virtualhosts
     fwrite($this->debugHandler, '  apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n");
     $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost'));
     if (count($this->virtualhosts_data) > 0) {
         $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost'));
         if (!$vhostDir->isConfigDir()) {
             // Save one big file
             $vhosts_file = '';
             // sort by filename so the order is:
             // 1. subdomains                  x-29
             // 2. subdomains as main-domains  30
             // 3. main-domains                35
             // #437
             ksort($this->virtualhosts_data);
             foreach ($this->virtualhosts_data as $vhosts_filename => $vhost_content) {
                 $vhosts_file .= $vhost_content . "\n\n";
             }
             // Include diroptions file in case it exists
             if (file_exists(Settings::Get('system.apacheconf_diroptions'))) {
                 $vhosts_file .= "\n" . 'Include ' . Settings::Get('system.apacheconf_diroptions') . "\n\n";
             }
             $vhosts_filename = Settings::Get('system.apacheconf_vhost');
             // Apply header
             $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
             $vhosts_file_handler = fopen($vhosts_filename, 'w');
             fwrite($vhosts_file_handler, $vhosts_file);
             fclose($vhosts_file_handler);
         } else {
             if (!file_exists(Settings::Get('system.apacheconf_vhost'))) {
                 fwrite($this->debugHandler, '  apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))) . "\n");
                 $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
                 safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
             }
             // Write a single file for every vhost
             foreach ($this->virtualhosts_data as $vhosts_filename => $vhosts_file) {
                 $this->known_vhostfilenames[] = basename($vhosts_filename);
                 // Apply header
                 $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
                 $vhosts_file_handler = fopen($vhosts_filename, 'w');
                 fwrite($vhosts_file_handler, $vhosts_file);
                 fclose($vhosts_file_handler);
             }
         }
     }
 }
 public function writeConfigs()
 {
     fwrite($this->debugHandler, '  nginx::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n");
     $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost'));
     $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost'));
     if (!$vhostDir->isConfigDir()) {
         // Save one big file
         $vhosts_file = '';
         // sort by filename so the order is:
         // 1. subdomains
         // 2. subdomains as main-domains
         // 3. main-domains
         ksort($this->nginx_data);
         foreach ($this->nginx_data as $vhosts_filename => $vhost_content) {
             $vhosts_file .= $vhost_content . "\n\n";
         }
         $vhosts_filename = Settings::Get('system.apacheconf_vhost');
         // Apply header
         $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
         $vhosts_file_handler = fopen($vhosts_filename, 'w');
         fwrite($vhosts_file_handler, $vhosts_file);
         fclose($vhosts_file_handler);
     } else {
         if (!file_exists(Settings::Get('system.apacheconf_vhost'))) {
             fwrite($this->debugHandler, '  nginx::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))) . "\n");
             $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
             safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
         }
         // Write a single file for every vhost
         foreach ($this->nginx_data as $vhosts_filename => $vhosts_file) {
             $this->known_filenames[] = basename($vhosts_filename);
             // Apply header
             $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
             if (!empty($vhosts_filename)) {
                 $vhosts_file_handler = fopen($vhosts_filename, 'w');
                 fwrite($vhosts_file_handler, $vhosts_file);
                 fclose($vhosts_file_handler);
             }
         }
     }
     // htaccess stuff
     if (count($this->htpasswds_data) > 0) {
         if (!file_exists(Settings::Get('system.apacheconf_htpasswddir'))) {
             $umask = umask();
             umask(00);
             mkdir(Settings::Get('system.apacheconf_htpasswddir'), 0751);
             umask($umask);
         } elseif (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) {
             fwrite($this->debugHandler, '  cron_tasks: WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n");
             echo 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!';
             $this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!');
         }
         if (is_dir(Settings::Get('system.apacheconf_htpasswddir'))) {
             foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) {
                 $this->known_htpasswdsfilenames[] = basename($htpasswd_filename);
                 $htpasswd_file_handler = fopen($htpasswd_filename, 'w');
                 // Filter duplicate pairs of username and password
                 $htpasswd_file = implode("\n", array_unique(explode("\n", $htpasswd_file)));
                 fwrite($htpasswd_file_handler, $htpasswd_file);
                 fclose($htpasswd_file_handler);
             }
         }
     }
 }
 public function writeConfigs()
 {
     $this->logger->logAction(CRON_ACTION, LOG_INFO, "lighttpd::writeConfigs: rebuilding " . Settings::Get('system.apacheconf_vhost'));
     $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost'));
     if (!$vhostDir->isConfigDir()) {
         // Save one big file
         $vhosts_file = '';
         // sort by filename so the order is:
         // 1. main-domains
         // 2. subdomains as main-domains
         // 3. subdomains
         // (former #437) - #833 (the numbering is done in createLighttpdHosts())
         ksort($this->lighttpd_data);
         foreach ($this->lighttpd_data as $vhosts_filename => $vhost_content) {
             $vhosts_file .= $vhost_content . "\n\n";
         }
         $vhosts_filename = Settings::Get('system.apacheconf_vhost');
         // Apply header
         $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
         $vhosts_file_handler = fopen($vhosts_filename, 'w');
         fwrite($vhosts_file_handler, $vhosts_file);
         fclose($vhosts_file_handler);
     } else {
         if (!file_exists(Settings::Get('system.apacheconf_vhost'))) {
             $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'lighttpd::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
             safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
         }
         // Write a single file for every vhost
         foreach ($this->lighttpd_data as $vhosts_filename => $vhosts_file) {
             $this->known_filenames[] = basename($vhosts_filename);
             // Apply header
             $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
             if (!empty($vhosts_filename)) {
                 $vhosts_file_handler = fopen($vhosts_filename, 'w');
                 fwrite($vhosts_file_handler, $vhosts_file);
                 fclose($vhosts_file_handler);
             }
         }
     }
     // Write the diroptions
     $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir'));
     if ($htpasswdDir->isConfigDir()) {
         foreach ($this->needed_htpasswds as $key => $data) {
             if (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) {
                 mkdir(makeCorrectDir(Settings::Get('system.apacheconf_htpasswddir')));
             }
             $filename = makeCorrectFile(Settings::Get('system.apacheconf_htpasswddir') . '/' . $key);
             $htpasswd_handler = fopen($filename, 'w');
             fwrite($htpasswd_handler, $data);
             fclose($htpasswd_handler);
         }
     }
 }
 * Copyright (c) 2010 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Lib
 *
 */
$configcommand = array();
$vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost'));
$optsDir = new frxDirectory(Settings::Get('system.apacheconf_diroptions'));
if ($vhostDir->isConfigDir()) {
    $configcommand['vhost'] = 'mkdir -p ' . Settings::Get('system.apacheconf_vhost');
    $configcommand['include'] = 'echo -e "\\nInclude ' . makeCorrectDir(Settings::Get('system.apacheconf_vhost')) . '*.conf" >> ' . makeCorrectFile(makeCorrectDir('/etc/apache2/httpd.conf'));
    $configcommand['v_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir(Settings::Get('system.apacheconf_vhost')) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf';
} else {
    $configcommand['vhost'] = 'touch ' . Settings::Get('system.apacheconf_vhost');
    $configcommand['include'] = 'echo -e "\\nInclude ' . Settings::Get('system.apacheconf_vhost') . '" >> ' . makeCorrectFile('/etc/apache2/httpd.conf');
    $configcommand['v_inclighty'] = 'echo -e \'\\ninclude "' . Settings::Get('system.apacheconf_vhost') . '"\' >> /etc/lighttpd/lighttpd.conf';
}
if ($optsDir->isConfigDir()) {
    $configcommand['diroptions'] = 'mkdir -p ' . Settings::Get('system.apacheconf_diroptions');
    $configcommand['d_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir(Settings::Get('system.apacheconf_diroptions')) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf';
} else {
    $configcommand['diroptions'] = 'touch ' . Settings::Get('system.apacheconf_diroptions');
    $configcommand['d_inclighty'] = 'echo -e \'\\ninclude "' . Settings::Get('system.apacheconf_diroptions') . '"\' >> /etc/lighttpd/lighttpd.conf';