Esempio n. 1
0
 function update($event_name, $data)
 {
     global $app, $conf;
     $domains = $this->_getSquidDomains($app);
     $rules = $this->_getSquidRewriteRules($app);
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate("squidRewriteRules.py.master");
     if (!empty($rules)) {
         $tpl->setLoop('squid_rewrite_rules', $rules);
     }
     file_put_contents('/etc/squid/squidRewriteRules.py', $tpl->grab());
     unset($tpl);
     $app->log('Writing squid rewrite configuration to /etc/squid/squidRewriteRules.py', LOGLEVEL_DEBUG);
     $tpl = new tpl();
     $tpl->newTemplate("domains.txt.master");
     $tpl->setLoop('squid_domains', $domains);
     file_put_contents('/etc/squid/domains.txt', $tpl->grab());
     unset($tpl);
     $app->log('Writing squid domains configuration to /etc/squid/domains.txt', LOGLEVEL_DEBUG);
     // request a httpd reload when all records have been processed
     $app->services->restartServiceDelayed('squid', 'restart');
 }
 private function php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir)
 {
     global $app, $conf;
     /*
     if(trim($data['new']['fastcgi_php_version']) != ''){
     	$default_php_fpm = false;
     	list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version']));
     	if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/';
     } else {
     	$default_php_fpm = true;
     }
     */
     if ($data['new']['php'] != 'no') {
         if (trim($data['new']['fastcgi_php_version']) != '') {
             $default_php_fpm = false;
             list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version']));
             if (substr($custom_php_fpm_ini_dir, -1) != '/') {
                 $custom_php_fpm_ini_dir .= '/';
             }
         } else {
             $default_php_fpm = true;
         }
     } else {
         if (trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] != 'no') {
             $default_php_fpm = false;
             list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version']));
             if (substr($custom_php_fpm_ini_dir, -1) != '/') {
                 $custom_php_fpm_ini_dir .= '/';
             }
         } else {
             $default_php_fpm = true;
         }
     }
     $app->uses("getconf");
     $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
     if ($data['new']['php'] == 'no') {
         if (@is_file($pool_dir . $pool_name . '.conf')) {
             $app->system->unlink($pool_dir . $pool_name . '.conf');
             //$reload = true;
         }
         if ($data['old']['php'] != 'no') {
             if (!$default_php_fpm) {
                 $app->services->restartService('php-fpm', 'reload:' . $custom_php_fpm_init_script);
             } else {
                 $app->services->restartService('php-fpm', 'reload:' . $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']);
             }
         }
         return;
     }
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate('php_fpm_pool.conf.master');
     if ($data['new']['php_fpm_use_socket'] == 'y') {
         $use_tcp = 0;
         $use_socket = 1;
         if (!is_dir($socket_dir)) {
             $app->system->mkdirpath($socket_dir);
         }
     } else {
         $use_tcp = 1;
         $use_socket = 0;
     }
     $tpl->setVar('use_tcp', $use_tcp);
     $tpl->setVar('use_socket', $use_socket);
     $fpm_socket = $socket_dir . $pool_name . '.sock';
     $tpl->setVar('fpm_socket', $fpm_socket);
     $tpl->setVar('fpm_listen_mode', '0660');
     $tpl->setVar('fpm_pool', $pool_name);
     $tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1);
     $tpl->setVar('fpm_user', $data['new']['system_user']);
     $tpl->setVar('fpm_group', $data['new']['system_group']);
     $tpl->setVar('pm', $data['new']['pm']);
     $tpl->setVar('pm_max_children', $data['new']['pm_max_children']);
     $tpl->setVar('pm_start_servers', $data['new']['pm_start_servers']);
     $tpl->setVar('pm_min_spare_servers', $data['new']['pm_min_spare_servers']);
     $tpl->setVar('pm_max_spare_servers', $data['new']['pm_max_spare_servers']);
     $tpl->setVar('pm_process_idle_timeout', $data['new']['pm_process_idle_timeout']);
     $tpl->setVar('pm_max_requests', $data['new']['pm_max_requests']);
     $tpl->setVar('document_root', $data['new']['document_root']);
     $tpl->setVar('security_level', $web_config['security_level']);
     $tpl->setVar('domain', $data['new']['domain']);
     $php_open_basedir = $data['new']['php_open_basedir'] == '' ? escapeshellcmd($data['new']['document_root']) : escapeshellcmd($data['new']['php_open_basedir']);
     $tpl->setVar('php_open_basedir', $php_open_basedir);
     if ($php_open_basedir != '') {
         $tpl->setVar('enable_php_open_basedir', '');
     } else {
         $tpl->setVar('enable_php_open_basedir', ';');
     }
     // Custom php.ini settings
     $final_php_ini_settings = array();
     $custom_php_ini_settings = trim($data['new']['custom_php_ini']);
     if ($custom_php_ini_settings != '') {
         // Make sure we only have Unix linebreaks
         $custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
         $custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
         $ini_settings = explode("\n", $custom_php_ini_settings);
         if (is_array($ini_settings) && !empty($ini_settings)) {
             foreach ($ini_settings as $ini_setting) {
                 $ini_setting = trim($ini_setting);
                 if (substr($ini_setting, 0, 1) == ';') {
                     continue;
                 }
                 if (substr($ini_setting, 0, 1) == '#') {
                     continue;
                 }
                 if (substr($ini_setting, 0, 2) == '//') {
                     continue;
                 }
                 list($key, $value) = explode('=', $ini_setting, 2);
                 $value = trim($value);
                 if ($value != '') {
                     $key = trim($key);
                     switch (strtolower($value)) {
                         case '0':
                             // PHP-FPM might complain about invalid boolean value if you use 0
                             $value = 'off';
                         case '1':
                         case 'on':
                         case 'off':
                         case 'true':
                         case 'false':
                         case 'yes':
                         case 'no':
                             $final_php_ini_settings[] = array('ini_setting' => 'php_admin_flag[' . $key . '] = ' . $value);
                             break;
                         default:
                             $final_php_ini_settings[] = array('ini_setting' => 'php_admin_value[' . $key . '] = ' . $value);
                     }
                 }
             }
         }
     }
     $tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
     $app->system->file_put_contents($pool_dir . $pool_name . '.conf', $tpl->grab());
     $app->log('Writing the PHP-FPM config file: ' . $pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
     unset($tpl);
     // delete pool in all other PHP versions
     $default_pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']);
     if (substr($default_pool_dir, -1) != '/') {
         $default_pool_dir .= '/';
     }
     if ($default_pool_dir != $pool_dir) {
         if (@is_file($default_pool_dir . $pool_name . '.conf')) {
             $app->system->unlink($default_pool_dir . $pool_name . '.conf');
             $app->log('Removed PHP-FPM config file: ' . $default_pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
             $app->services->restartService('php-fpm', 'reload:' . $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']);
         }
     }
     $php_versions = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = " . $conf["server_id"]);
     if (is_array($php_versions) && !empty($php_versions)) {
         foreach ($php_versions as $php_version) {
             if (substr($php_version['php_fpm_pool_dir'], -1) != '/') {
                 $php_version['php_fpm_pool_dir'] .= '/';
             }
             if ($php_version['php_fpm_pool_dir'] != $pool_dir) {
                 if (@is_file($php_version['php_fpm_pool_dir'] . $pool_name . '.conf')) {
                     $app->system->unlink($php_version['php_fpm_pool_dir'] . $pool_name . '.conf');
                     $app->log('Removed PHP-FPM config file: ' . $php_version['php_fpm_pool_dir'] . $pool_name . '.conf', LOGLEVEL_DEBUG);
                     $app->services->restartService('php-fpm', 'reload:' . $php_version['php_fpm_init_script']);
                 }
             }
         }
     }
     // Reload current PHP-FPM after all others
     sleep(1);
     if (!$default_php_fpm) {
         $app->services->restartService('php-fpm', 'reload:' . $custom_php_fpm_init_script);
     } else {
         $app->services->restartService('php-fpm', 'reload:' . $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']);
     }
 }
 function rewrite_update($event_name, $data)
 {
     global $app, $conf;
     $rules = $this->_getRewriteRules($app);
     $app->uses('getconf');
     $nginx_config = $app->getconf->get_server_config($conf['server_id'], 'web');
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate("nginx_reverseproxy_rewrites.conf.master");
     if (!empty($rules)) {
         $tpl->setLoop('nginx_rewrite_rules', $rules);
     }
     $rewrites_file = escapeshellcmd($nginx_config['nginx_vhost_conf_dir'] . '/default.rewrites.conf');
     //* Make a backup copy of vhost file
     copy($rewrites_file, $rewrites_file . '~');
     //* Write vhost file
     file_put_contents($rewrites_file, $tpl->grab());
     $app->log('Writing the nginx rewrites file: ' . $rewrites_file, LOGLEVEL_DEBUG);
     unset($tpl);
     // Set the symlink to enable the vhost
     $rewrite_symlink = escapeshellcmd($nginx_config['nginx_vhost_conf_enabled_dir'] . '/default.rewrites.conf');
     if (!is_link($rewrite_symlink)) {
         symlink($rewrites_file, $rewrite_symlink);
         $app->log('Creating symlink for nginx rewrites: ' . $rewrite_symlink . '->' . $rewrites_file, LOGLEVEL_DEBUG);
     }
 }
 function onShow()
 {
     global $app;
     $listTpl = new tpl();
     $listTpl->newTemplate('templates/web_backup_list.htm');
     //* Loading language file
     $lng_file = "lib/lang/" . $_SESSION["s"]["language"] . "_web_backup_list.lng";
     include $lng_file;
     $listTpl->setVar($wb);
     $message = '';
     $error = '';
     if (isset($_GET['backup_action'])) {
         $backup_id = $app->functions->intval($_GET['backup_id']);
         //* check if the user is  owner of the parent domain
         $domain_backup = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_backup WHERE backup_id = " . $backup_id);
         $check_perm = 'u';
         if ($_GET['backup_action'] == 'download') {
             $check_perm = 'r';
         }
         // only check read permissions on download, not update permissions
         $get_domain = $app->db->queryOneRecord("SELECT domain_id FROM web_domain WHERE domain_id = " . $app->functions->intval($domain_backup["parent_domain_id"]) . " AND " . $app->tform->getAuthSQL($check_perm));
         if (empty($get_domain) || !$get_domain) {
             $app->error($app->tform->lng('no_domain_perm'));
         }
         if ($_GET['backup_action'] == 'download' && $backup_id > 0) {
             $server_id = $this->form->dataRecord['server_id'];
             $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = " . $backup_id);
             if ($backup['server_id'] > 0) {
                 $server_id = $backup['server_id'];
             }
             $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '{$backup_id}'";
             $tmp = $app->db->queryOneRecord($sql);
             if ($tmp['number'] == 0) {
                 $message .= $wb['download_info_txt'];
                 $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . "VALUES (" . (int) $server_id . ", " . time() . ", " . "'backup_download', " . "'" . $backup_id . "', " . "'pending', " . "''" . ")";
                 $app->db->query($sql);
             } else {
                 $error .= $wb['download_pending_txt'];
             }
         }
         if ($_GET['backup_action'] == 'restore' && $backup_id > 0) {
             $server_id = $this->form->dataRecord['server_id'];
             $backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = " . $backup_id);
             if ($backup['server_id'] > 0) {
                 $server_id = $backup['server_id'];
             }
             $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '{$backup_id}'";
             $tmp = $app->db->queryOneRecord($sql);
             if ($tmp['number'] == 0) {
                 $message .= $wb['restore_info_txt'];
                 $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . "VALUES (" . (int) $server_id . ", " . time() . ", " . "'backup_restore', " . "'" . $backup_id . "', " . "'pending', " . "''" . ")";
                 $app->db->query($sql);
             } else {
                 $error .= $wb['restore_pending_txt'];
             }
         }
     }
     //* Get the data
     $server_ids = array();
     $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = " . $app->functions->intval($this->form->id));
     $databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = " . $app->functions->intval($this->form->id));
     if ($app->functions->intval($web['server_id']) > 0) {
         $server_ids[] = $app->functions->intval($web['server_id']);
     }
     if (is_array($databases) && !empty($databases)) {
         foreach ($databases as $database) {
             if ($app->functions->intval($database['server_id']) > 0) {
                 $server_ids[] = $app->functions->intval($database['server_id']);
             }
         }
     }
     $server_ids = array_unique($server_ids);
     $sql = "SELECT * FROM web_backup WHERE parent_domain_id = " . $app->functions->intval($this->form->id) . " AND server_id IN (" . implode(',', $server_ids) . ") ORDER BY tstamp DESC, backup_type ASC";
     $records = $app->db->queryAllRecords($sql);
     $bgcolor = "#FFFFFF";
     if (is_array($records)) {
         foreach ($records as $rec) {
             // Change of color
             $bgcolor = $bgcolor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
             $rec["bgcolor"] = $bgcolor;
             $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
             $rec['backup_type'] = $wb['backup_type_' . $rec['backup_type']];
             $rec['download_available'] = true;
             if ($rec['server_id'] != $web['server_id']) {
                 $rec['download_available'] = false;
             }
             $records_new[] = $rec;
         }
     }
     $listTpl->setLoop('records', @$records_new);
     $listTpl->setVar('parent_id', $this->form->id);
     $listTpl->setVar('msg', $message);
     $listTpl->setVar('error', $error);
     // Setting Returnto information in the session
     $list_name = 'backup_list';
     // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
     $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
     $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
     $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
     $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
     $_SESSION["s"]["form"]["return_to"] = $list_name;
     return $listTpl->grab();
 }
 function update($event_name, $data)
 {
     global $app, $conf;
     // load the server configuration options
     $app->uses("getconf");
     $mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
     if (substr($mail_config["homedir_path"], -1) == '/') {
         $mail_config["homedir_path"] = substr($mail_config["homedir_path"], 0, -1);
     }
     if (isset($data["new"]["email"])) {
         $email_parts = explode("@", $data["new"]["email"]);
     } else {
         $email_parts = explode("@", $data["old"]["email"]);
     }
     // Write the custom mailfilter script, if mailfilter recipe has changed
     if ($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"] or $data["old"]["move_junk"] != $data["new"]["move_junk"] or $data["old"]["autoresponder_subject"] != $data["new"]["autoresponder_subject"] or $data["old"]["autoresponder_text"] != $data["new"]["autoresponder_text"] or $data["old"]["autoresponder"] != $data["new"]["autoresponder"] or isset($data["new"]["email"]) and $data["old"]["email"] != $data["new"]["email"] or $data["old"]["autoresponder_start_date"] != $data["new"]["autoresponder_start_date"] or $data["old"]["autoresponder_end_date"] != $data["new"]["autoresponder_end_date"] or $data["old"]["cc"] != $data["new"]["cc"]) {
         $app->log("Mailfilter config has been changed", LOGLEVEL_DEBUG);
         $sieve_file = $data["new"]["maildir"] . '/.sieve';
         if (is_file($sieve_file)) {
             unlink($sieve_file) or $app->log("Unable to delete file: {$sieve_file}", LOGLEVEL_WARN);
         }
         $app->load('tpl');
         //* Select sieve filter file for dovecot version
         exec('dovecot --version', $tmp);
         if (substr($tmp[0], 0, 3) == '1.0') {
             $filter_file_template = "sieve_filter.master";
         } elseif (substr($tmp[0], 0, 3) == '1.2') {
             $filter_file_template = "sieve_filter_1.2.master";
         } elseif (substr($tmp[0], 0, 1) == '2') {
             $filter_file_template = "sieve_filter_1.2.master";
         } else {
             $filter_file_template = "sieve_filter.master";
         }
         unset($tmp);
         //* Create new filter file based on template
         $tpl = new tpl();
         $tpl->newTemplate($filter_file_template);
         // cc Field
         $tmp_mails_arr = explode(',', $data["new"]["cc"]);
         $tmp_addresses_arr = array();
         foreach ($tmp_mails_arr as $address) {
             if (trim($address) != '') {
                 $tmp_addresses_arr[] = array('address' => trim($address));
             }
         }
         $tpl->setVar('cc', $data["new"]["cc"]);
         $tpl->setLoop('ccloop', $tmp_addresses_arr);
         // Custom filters
         if ($data["new"]["custom_mailfilter"] == 'NULL') {
             $data["new"]["custom_mailfilter"] = '';
         }
         $tpl->setVar('custom_mailfilter', $data["new"]["custom_mailfilter"]);
         // Move junk
         $tpl->setVar('move_junk', $data["new"]["move_junk"]);
         // Check autoresponder dates
         if ($data["new"]["autoresponder_start_date"] == '0000-00-00 00:00:00' && $data["new"]["autoresponder_end_date"] == '0000-00-00 00:00:00') {
             $tpl->setVar('autoresponder_date_limit', 0);
         } else {
             $tpl->setVar('autoresponder_date_limit', 1);
         }
         // Set autoresponder start date
         $data["new"]["autoresponder_start_date"] = str_replace(" ", "T", $data["new"]["autoresponder_start_date"]);
         $tpl->setVar('start_date', $data["new"]["autoresponder_start_date"]);
         // Set autoresponder end date
         $data["new"]["autoresponder_end_date"] = str_replace(" ", "T", $data["new"]["autoresponder_end_date"]);
         $tpl->setVar('end_date', $data["new"]["autoresponder_end_date"]);
         // Autoresponder
         $tpl->setVar('autoresponder', $data["new"]["autoresponder"]);
         // Autoresponder Subject
         $data["new"]["autoresponder_subject"] = str_replace("\"", "'", $data["new"]["autoresponder_subject"]);
         $tpl->setVar('autoresponder_subject', $data["new"]["autoresponder_subject"]);
         // Autoresponder Text
         $data["new"]["autoresponder_text"] = str_replace("\"", "'", $data["new"]["autoresponder_text"]);
         $tpl->setVar('autoresponder_text', $data["new"]["autoresponder_text"]);
         //* Set alias addresses for autoresponder
         $sql = "SELECT * FROM mail_forwarding WHERE type = 'alias' AND destination = '" . $app->db->quote($data["new"]["email"]) . "'";
         $records = $app->db->queryAllRecords($sql);
         $addresses = array();
         $addresses[] = $data["new"]["email"];
         if (is_array($records) && count($records) > 0) {
             foreach ($records as $rec) {
                 $addresses[] = $rec['source'];
             }
         }
         $app->log("Found " . count($addresses) . " addresses.", LOGLEVEL_DEBUG);
         $alias_addresses = array();
         $email_parts = explode('@', $data["new"]["email"]);
         $sql = "SELECT * FROM mail_forwarding WHERE type = 'aliasdomain' AND destination = '@" . $app->db->quote($email_parts[1]) . "'";
         $records = $app->db->queryAllRecords($sql);
         if (is_array($records) && count($records) > 0) {
             $app->log("Found " . count($records) . " records (aliasdomains).", LOGLEVEL_DEBUG);
             foreach ($records as $rec) {
                 $aliasdomain = substr($rec['source'], 1);
                 foreach ($addresses as $email) {
                     $email_parts = explode('@', $email);
                     $alias_addresses[] = $email_parts[0] . '@' . $aliasdomain;
                 }
             }
         }
         $app->log("Found " . count($addresses) . " addresses at all.", LOGLEVEL_DEBUG);
         $addresses = array_unique(array_merge($addresses, $alias_addresses));
         $app->log("Found " . count($addresses) . " unique addresses at all.", LOGLEVEL_DEBUG);
         $address_str = '';
         if (is_array($addresses) && count($addresses) > 0) {
             $address_str .= ':addresses [';
             foreach ($addresses as $rec) {
                 $address_str .= '"' . $rec . '",';
             }
             $address_str = substr($address_str, 0, -1);
             $address_str .= ']';
         }
         $tpl->setVar('addresses', $address_str);
         file_put_contents($sieve_file, $tpl->grab());
         exec('chown ' . $mail_config['mailuser_name'] . ':' . $mail_config['mailuser_group'] . ' ' . escapeshellcmd($sieve_file));
         unset($tpl);
     }
 }
 public function configure_apache()
 {
     global $conf;
     if ($conf['apache']['installed'] == false) {
         return;
     }
     //* Create the logging directory for the vhost logfiles
     if (!@is_dir($conf['ispconfig_log_dir'] . '/httpd')) {
         mkdir($conf['ispconfig_log_dir'] . '/httpd', 0755, true);
     }
     if (is_file('/etc/suphp/suphp.conf')) {
         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);
         replaceLine('/etc/suphp/suphp.conf', 'umask=0077', 'umask=0022', 0);
     }
     if (is_file('/etc/apache2/sites-enabled/000-default')) {
         replaceLine('/etc/apache2/sites-available/000-default', 'NameVirtualHost *', 'NameVirtualHost *:80', 1, 0);
         replaceLine('/etc/apache2/sites-available/000-default', '<VirtualHost *>', '<VirtualHost *:80>', 1, 0);
     }
     if (is_file('/etc/apache2/ports.conf')) {
         // add a line "Listen 8443" to ports conf if line does not exist
         replaceLine('/etc/apache2/ports.conf', 'Listen 8443', 'Listen 8443', 1);
         // Comment out the namevirtualhost lines, as they were added by ispconfig in ispconfig.conf file again
         replaceLine('/etc/apache2/ports.conf', 'NameVirtualHost *:80', '# NameVirtualHost *:80', 1);
         replaceLine('/etc/apache2/ports.conf', 'NameVirtualHost *:8443', '# NameVirtualHost *:8443', 1);
     }
     if (is_file('/etc/apache2/apache.conf')) {
         if (hasLine('/etc/apache2/apache.conf', 'Include sites-enabled/', 1) == false) {
             if (hasLine('/etc/apache2/apache.conf', 'IncludeOptional sites-enabled/*.conf', 1) == false && hasLine('/etc/apache2/apache.conf', 'IncludeOptional sites-enabled/', 1) == false) {
                 replaceLine('/etc/apache2/apache.conf', 'Include sites-enabled/', 'Include sites-enabled/', 1, 1);
             } elseif (hasLine('/etc/apache2/apache.conf', 'IncludeOptional sites-enabled/*.vhost', 1) == false) {
                 replaceLine('/etc/apache2/apache.conf', 'IncludeOptional sites-enabled/*.vhost', 'IncludeOptional sites-enabled/', 1, 1);
             }
         }
     }
     if (is_file('/etc/apache2/apache2.conf')) {
         if (hasLine('/etc/apache2/apache2.conf', 'Include sites-enabled/', 1) == false && hasLine('/etc/apache2/apache2.conf', 'IncludeOptional sites-enabled/', 1) == false) {
             if (hasLine('/etc/apache2/apache2.conf', 'Include sites-enabled/*.conf', 1) == true) {
                 replaceLine('/etc/apache2/apache2.conf', 'Include sites-enabled/*.conf', 'Include sites-enabled/', 1, 1);
             } elseif (hasLine('/etc/apache2/apache2.conf', 'IncludeOptional sites-enabled/*.conf', 1) == true) {
                 replaceLine('/etc/apache2/apache2.conf', 'IncludeOptional sites-enabled/*.conf', 'IncludeOptional sites-enabled/', 1, 1);
             }
         }
     }
     //* Copy the ISPConfig configuration include
     $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
     $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
     $tpl = new tpl('apache_ispconfig.conf.master');
     $tpl->setVar('apache_version', getapacheversion());
     $records = $this->db->queryAllRecords('SELECT * FROM ' . $conf['mysql']['master_database'] . '.server_ip WHERE server_id = ' . $conf['server_id'] . " AND virtualhost = 'y'");
     $ip_addresses = array();
     if (is_array($records) && count($records) > 0) {
         foreach ($records as $rec) {
             if ($rec['ip_type'] == 'IPv6') {
                 $ip_address = '[' . $rec['ip_address'] . ']';
             } else {
                 $ip_address = $rec['ip_address'];
             }
             $ports = explode(',', $rec['virtualhost_port']);
             if (is_array($ports)) {
                 foreach ($ports as $port) {
                     $port = intval($port);
                     if ($port > 0 && $port < 65536 && $ip_address != '') {
                         $ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
                     }
                 }
             }
         }
     }
     if (count($ip_addresses) > 0) {
         $tpl->setLoop('ip_adresses', $ip_addresses);
     }
     wf($vhost_conf_dir . '/ispconfig.conf', $tpl->grab());
     unset($tpl);
     if (!@is_link($vhost_conf_enabled_dir . '/000-ispconfig.conf')) {
         symlink($vhost_conf_dir . '/ispconfig.conf', $vhost_conf_enabled_dir . '/000-ispconfig.conf');
     }
     //* make sure that webalizer finds its config file when it is directly in /etc
     if (@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
         mkdir('/etc/webalizer');
         symlink('/etc/webalizer.conf', '/etc/webalizer/webalizer.conf');
     }
     if (is_file('/etc/webalizer/webalizer.conf')) {
         // Change webalizer mode to incremental
         replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental     yes', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName     webalizer.hist', 0, 0);
     }
     // Check the awsatst script
     if (!is_dir('/usr/share/awstats/tools')) {
         exec('mkdir -p /usr/share/awstats/tools');
     }
     if (!file_exists('/usr/share/awstats/tools/awstats_buildstaticpages.pl') && file_exists('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl')) {
         symlink('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl', '/usr/share/awstats/tools/awstats_buildstaticpages.pl');
     }
     if (file_exists('/etc/awstats/awstats.conf.local')) {
         replaceLine('/etc/awstats/awstats.conf.local', 'LogFormat=4', 'LogFormat=1', 0, 1);
     }
     //* add a sshusers group
     $command = 'groupadd sshusers';
     if (!is_group('sshusers')) {
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
 }
Esempio n. 7
0
 public function configure_apache()
 {
     global $conf;
     if ($conf['apache']['installed'] == false) {
         return;
     }
     //* Create the logging directory for the vhost logfiles
     exec('mkdir -p /var/log/ispconfig/httpd');
     //* enable apache logio module
     exec('a2enmod logio');
     //if(is_file('/etc/suphp.conf')) {
     replaceLine('/etc/suphp.conf', 'php=php', 'x-httpd-suphp="php:/srv/www/cgi-bin/php5"', 0, 0);
     replaceLine('/etc/suphp.conf', 'php="php', 'x-httpd-suphp="php:/srv/www/cgi-bin/php5"', 0, 0);
     replaceLine('/etc/suphp.conf', 'docroot=', 'docroot=/srv/www', 0, 0);
     replaceLine('/etc/suphp.conf', 'umask=0077', 'umask=0022', 0);
     //}
     if (!file_exists('/srv/www/cgi-bin/php5') && file_exists('/srv/www/cgi-bin/php')) {
         symlink('/srv/www/cgi-bin/php', '/srv/www/cgi-bin/php5');
     }
     // Sites enabled and available dirs
     exec('mkdir -p ' . $conf['apache']['vhost_conf_enabled_dir']);
     exec('mkdir -p ' . $conf['apache']['vhost_conf_dir']);
     $content = rf('/etc/apache2/httpd.conf');
     if (!stristr($content, 'Include /etc/apache2/sites-enabled/')) {
         af('/etc/apache2/httpd.conf', "\n<Directory /srv/www>\n    Options +FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
     }
     unset($content);
     //* Copy the ISPConfig configuration include
     $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
     $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
     $tpl = new tpl('apache_ispconfig.conf.master');
     $tpl->setVar('apache_version', getapacheversion());
     $records = $this->db->queryAllRecords('SELECT * FROM ' . $conf['mysql']['master_database'] . '.server_ip WHERE server_id = ' . $conf['server_id'] . " AND virtualhost = 'y'");
     $ip_addresses = array();
     if (is_array($records) && count($records) > 0) {
         foreach ($records as $rec) {
             if ($rec['ip_type'] == 'IPv6') {
                 $ip_address = '[' . $rec['ip_address'] . ']';
             } else {
                 $ip_address = $rec['ip_address'];
             }
             $ports = explode(',', $rec['virtualhost_port']);
             if (is_array($ports)) {
                 foreach ($ports as $port) {
                     $port = intval($port);
                     if ($port > 0 && $port < 65536 && $ip_address != '') {
                         $ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
                     }
                 }
             }
         }
     }
     if (count($ip_addresses) > 0) {
         $tpl->setLoop('ip_adresses', $ip_addresses);
     }
     wf($vhost_conf_dir . '/ispconfig.conf', $tpl->grab());
     unset($tpl);
     if (!@is_link($vhost_conf_enabled_dir . "/000-ispconfig.conf")) {
         exec("ln -s " . $vhost_conf_dir . "/ispconfig.conf " . $vhost_conf_enabled_dir . "/000-ispconfig.conf");
     }
     //* make sure that webalizer finds its config file when it is directly in /etc
     if (@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
         exec('mkdir /etc/webalizer');
         exec('ln -s /etc/webalizer.conf /etc/webalizer/webalizer.conf');
     }
     if (is_file('/etc/webalizer/webalizer.conf')) {
         // Change webalizer mode to incremental
         replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental     yes', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName     webalizer.hist', 0, 0);
     }
     //* add a sshusers group
     $command = 'groupadd sshusers';
     if (!is_group('sshusers')) {
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     // create PHP-FPM pool dir
     exec('mkdir -p ' . $conf['nginx']['php_fpm_pool_dir']);
     $content = rf('/etc/php5/fpm/php-fpm.conf');
     if (stripos($content, 'include=/etc/php5/fpm/pool.d/*.conf') === false) {
         af('/etc/php5/fpm/php-fpm.conf', "\ninclude=/etc/php5/fpm/pool.d/*.conf");
     }
     unset($content);
     if (!@is_file($conf['nginx']['php_fpm_ini_path'])) {
         if (@is_file('/etc/php5/cli/php.ini')) {
             exec('cp -f /etc/php5/cli/php.ini ' . $conf['nginx']['php_fpm_ini_path']);
         } elseif (@is_file('/etc/php5/fastcgi/php.ini')) {
             exec('cp -f /etc/php5/fastcgi/php.ini ' . $conf['nginx']['php_fpm_ini_path']);
         } elseif (@is_file('/etc/php5/apache2/php.ini')) {
             exec('cp -f /etc/php5/apache2/php.ini ' . $conf['nginx']['php_fpm_ini_path']);
         }
     }
 }
 function onShow()
 {
     global $app;
     $listTpl = new tpl();
     $listTpl->newTemplate('templates/web_backup_list.htm');
     //* Loading language file
     $lng_file = "lib/lang/" . $_SESSION["s"]["language"] . "_web_backup_list.lng";
     include $lng_file;
     $listTpl->setVar($wb);
     $message = '';
     $error = '';
     if (isset($_GET['backup_action'])) {
         $backup_id = $app->functions->intval($_GET['backup_id']);
         if ($_GET['backup_action'] == 'download' && $backup_id > 0) {
             $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '{$backup_id}'";
             $tmp = $app->db->queryOneRecord($sql);
             if ($tmp['number'] == 0) {
                 $message .= $wb['download_info_txt'];
                 $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . "VALUES (" . (int) $this->form->dataRecord['server_id'] . ", " . time() . ", " . "'backup_download', " . "'" . $backup_id . "', " . "'pending', " . "''" . ")";
                 $app->db->query($sql);
             } else {
                 $error .= $wb['download_pending_txt'];
             }
         }
         if ($_GET['backup_action'] == 'restore' && $backup_id > 0) {
             $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '{$backup_id}'";
             $tmp = $app->db->queryOneRecord($sql);
             if ($tmp['number'] == 0) {
                 $message .= $wb['restore_info_txt'];
                 $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . "VALUES (" . (int) $this->form->dataRecord['server_id'] . ", " . time() . ", " . "'backup_restore', " . "'" . $backup_id . "', " . "'pending', " . "''" . ")";
                 $app->db->query($sql);
             } else {
                 $error .= $wb['restore_pending_txt'];
             }
         }
     }
     //* Get the data
     $sql = "SELECT * FROM web_backup WHERE parent_domain_id = " . $this->form->id . " ORDER BY tstamp DESC, backup_type ASC";
     $records = $app->db->queryAllRecords($sql);
     $bgcolor = "#FFFFFF";
     if (is_array($records)) {
         foreach ($records as $rec) {
             // Change of color
             $bgcolor = $bgcolor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
             $rec["bgcolor"] = $bgcolor;
             $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
             $rec['backup_type'] = $wb['backup_type_' . $rec['backup_type']];
             $records_new[] = $rec;
         }
     }
     $listTpl->setLoop('records', @$records_new);
     $listTpl->setVar('parent_id', $this->form->id);
     $listTpl->setVar('msg', $message);
     $listTpl->setVar('error', $error);
     // Setting Returnto information in the session
     $list_name = 'backup_list';
     // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
     $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
     $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
     $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
     $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
     $_SESSION["s"]["form"]["return_to"] = $list_name;
     return $listTpl->grab();
 }
 function onShow()
 {
     global $app;
     $app->uses('listform');
     $app->listform->loadListDef($this->options["listdef"]);
     //$app->listform->SQLExtWhere = "type = 'alias'";
     $listTpl = new tpl();
     $listTpl->newTemplate('templates/' . $app->listform->listDef["name"] . '_list.htm');
     //die(print_r($app->tform_actions));
     // Changing some of the list values to reflect that the list is called within a tform page
     $app->listform->listDef["file"] = $app->tform->formDef["action"];
     // $app->listform->listDef["page_params"] = "&id=".$app->tform_actions->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
     $app->listform->listDef["page_params"] = "&id=" . $this->form->id . "&next_tab=" . $_SESSION["s"]["form"]["tab"];
     $listTpl->setVar('parent_id', $this->form->id);
     $listTpl->setVar('theme', $_SESSION['s']['theme']);
     // Generate the SQL for searching
     if ($app->listform->listDef["auth"] != 'no') {
         if ($_SESSION["s"]["user"]["typ"] == "admin") {
             $sql_where = "";
         } else {
             $sql_where = $app->tform->getAuthSQL('r') . " and";
         }
     }
     if ($this->options["sqlextwhere"] != '') {
         $sql_where .= " " . $this->options["sqlextwhere"] . " and";
     }
     $sql_where = $app->listform->getSearchSQL($sql_where);
     $listTpl->setVar($app->listform->searchValues);
     // Generate SQL for paging
     $limit_sql = $app->listform->getPagingSQL($sql_where);
     $listTpl->setVar("paging", $app->listform->pagingHTML);
     $sql_order_by = '';
     if (isset($this->options["sql_order_by"])) {
         $sql_order_by = $this->options["sql_order_by"];
     }
     // Loading language field
     $lng_file = "lib/lang/" . $_SESSION["s"]["language"] . "_" . $app->listform->listDef['name'] . "_list.lng";
     include $lng_file;
     $listTpl->setVar($wb);
     // Get the data
     $records = $app->db->queryAllRecords("SELECT * FROM " . $app->listform->listDef["table"] . " WHERE {$sql_where} {$sql_order_by} {$limit_sql}");
     $bgcolor = "#FFFFFF";
     if (is_array($records)) {
         $idx_key = $app->listform->listDef["table_idx"];
         foreach ($records as $rec) {
             $rec = $app->listform->decode($rec);
             // Change of color
             $bgcolor = $bgcolor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
             $rec["bgcolor"] = $bgcolor;
             // substitute value for select fields
             foreach ($app->listform->listDef["item"] as $field) {
                 $key = $field["field"];
                 if ($field['formtype'] == "SELECT") {
                     if (strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') {
                         // Set a additional image variable for bolean fields
                         $rec['_' . $key . '_'] = strtolower($rec[$key]) == 'y' ? 'x16/tick_circle.png' : 'x16/cross_circle.png';
                     }
                     //* substitute value for select field
                     @($rec[$key] = $field['value'][$rec[$key]]);
                 }
                 // Create a lowercase version of every item
                 $rec[$key . '_lowercase'] = strtolower($rec[$key]);
             }
             // The variable "id" contains always the index field
             $rec["id"] = $rec[$idx_key];
             $rec["delete_confirmation"] = $wb['delete_confirmation'];
             $records_new[] = $rec;
         }
     }
     $listTpl->setLoop('records', @$records_new);
     // Setting Returnto information in the session
     $list_name = $app->listform->listDef["name"];
     // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
     $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
     $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
     $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
     $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
     $_SESSION["s"]["form"]["return_to"] = $list_name;
     //die(print_r($_SESSION["s"]["list"][$list_name]));
     return $listTpl->grab();
 }
 /**
  * ISPConfig update hook.
  *
  * Called every time a site gets updated from within ISPConfig.
  *
  * @see insert()
  * @see delete()
  *
  * @param string $event_name the event/action name
  * @param array  $data       the vhost data
  */
 function update($event_name, $data)
 {
     global $app, $conf;
     //* $VAR: command to run after vhost insert/update/delete
     $final_command = '/etc/init.d/nginx reload';
     if ($this->action != 'insert') {
         $this->action = 'update';
     }
     $app->uses('getconf');
     $app->uses('system');
     $web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate('nginx_reverse_proxy_plugin.vhost.conf.master');
     $web_folder = 'web';
     if ($data['new']['type'] == 'vhostsubdomain') {
         $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ' . intval($data['new']['parent_domain_id']));
         $subdomain_host = preg_replace('/^(.*)\\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $data['new']['domain']);
         if ($subdomain_host == '') {
             $subdomain_host = 'web' . $data['new']['domain_id'];
         }
         $web_folder = $data['new']['web_folder'];
         unset($tmp);
     }
     $vhost_data = $data['new'];
     $vhost_data['web_document_root'] = $data['new']['document_root'] . '/' . $web_folder;
     $vhost_data['web_document_root_www'] = $web_config['website_basedir'] . '/' . $data['new']['domain'] . '/' . $web_folder;
     $vhost_data['web_basedir'] = $web_config['website_basedir'];
     $vhost_data['ssl_domain'] = $data['new']['ssl_domain'];
     /* __ VHOST & VHOSTSUBDOMAIN - section for vhosts and vhostsubdomains //////////////*/
     if ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain') {
         if ($data['new']['ipv6_address'] != '') {
             $tpl->setVar('ipv6_enabled', 1);
         }
         $server_alias = array();
         switch ($data['new']['subdomain']) {
             case 'www':
                 // if seo-redirect is enabled, this should be placed in separate server block
                 // to prevent if statement in server/request!
                 $server_alias[] .= 'www.' . $data['new']['domain'] . ' ';
                 break;
             case '*':
                 $server_alias[] .= '*.' . $data['new']['domain'] . ' ';
                 break;
         }
         $alias_result = array();
         $alias_result = $app->dbmaster->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = ' . $data['new']['domain_id'] . " AND active = 'y' AND type != 'vhostsubdomain'");
         if (count($alias_result) > 0) {
             // if alias is redirect type, put in server block with seo-redirect to prevent
             // if statement in server/request!
             foreach ($alias_result as $alias) {
                 switch ($alias['subdomain']) {
                     case 'www':
                         $server_alias[] .= 'www.' . $alias['domain'] . ' ' . $alias['domain'] . ' ';
                         break;
                     case '*':
                         $server_alias[] .= '*.' . $alias['domain'] . ' ' . $alias['domain'] . ' ';
                         break;
                     default:
                         $server_alias[] .= $alias['domain'] . ' ';
                 }
                 $app->log('Add server alias: ' . $alias['domain'], LOGLEVEL_DEBUG);
             }
             unset($alias);
         }
         if (count($server_alias) > 0) {
             $server_alias_str = '';
             foreach ($server_alias as $tmp_alias) {
                 $server_alias_str .= $tmp_alias;
             }
             unset($tmp_alias);
             $tpl->setVar('alias', $server_alias_str);
         } else {
             $tpl->setVar('alias', '');
         }
         if (!isset($rewrite_rules)) {
             $rewrite_rules = array();
         }
         if ($data['new']['redirect_type'] != '' && $data['new']['redirect_path'] != '') {
             if (substr($data['new']['redirect_path'], -1) != '/') {
                 $data['new']['redirect_path'] .= '/';
             }
             if (substr($data['new']['redirect_path'], 0, 8) == '[scheme]') {
                 $rewrite_target = 'http' . substr($data['new']['redirect_path'], 8);
                 $rewrite_target_ssl = 'https' . substr($data['new']['redirect_path'], 8);
             } else {
                 $rewrite_target = $data['new']['redirect_path'];
                 $rewrite_target_ssl = $data['new']['redirect_path'];
             }
             if (substr($data['new']['redirect_path'], 0, 4) == 'http') {
                 $data['new']['redirect_type'] = 'permanent';
             } else {
                 switch ($data['new']['redirect_type']) {
                     case 'no':
                         $data['new']['redirect_type'] = 'break';
                         break;
                     case 'L':
                         $data['new']['redirect_type'] = 'break';
                         break;
                     default:
                         $data['new']['redirect_type'] = 'permanent';
                 }
             }
             switch ($data['new']['subdomain']) {
                 case 'www':
                     $rewrite_rules[] = array('rewrite_domain' => '^' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
                     $rewrite_rules[] = array('rewrite_domain' => '^www.' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
                     break;
                 case '*':
                     $rewrite_rules[] = array('rewrite_domain' => '(^|\\.)' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
                     break;
                 default:
                     $rewrite_rules[] = array('rewrite_domain' => '^' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
             }
         }
         if ($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')) {
             $vhost_data['seo_redirect_enabled'] = 1;
             if ($data['new']['seo_redirect'] == 'non_www_to_www') {
                 $vhost_data['seo_redirect_origin_domain'] = $data['new']['domain'];
                 $vhost_data['seo_redirect_target_domain'] = 'www.' . $data['new']['domain'];
             }
             if ($data['new']['seo_redirect'] == 'www_to_non_www') {
                 $vhost_data['seo_redirect_origin_domain'] = 'www.' . $data['new']['domain'];
                 $vhost_data['seo_redirect_target_domain'] = $data['new']['domain'];
             }
         } else {
             $vhost_data['seo_redirect_enabled'] = 0;
         }
         $errordocs = !$data['new']['errordocs'];
         $nginx_directives = $data['new']['nginx_directives'];
         $nginx_directives = str_replace("\r\n", "\n", $nginx_directives);
         $nginx_directives = str_replace("\r", "\n", $nginx_directives);
         $crt_file = escapeshellcmd($data['new']['document_root'] . '/ssl/' . $data['new']['ssl_domain'] . '.crt');
         $key_file = escapeshellcmd($data['new']['document_root'] . '/ssl/' . $data['new']['ssl_domain'] . '.key');
         if ($data['new']['ssl_domain'] != '' && $data['new']['ssl'] == 'y' && is_file($crt_file) && is_file($key_file) && filesize($crt_file) > 0 && filesize($key_file) > 0) {
             $http_to_https = 1;
         } else {
             $http_to_https = 0;
         }
         // non-ssl vhost loop
         if (count($rewrite_rules) > 0) {
             $vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 0, 'http_to_https' => $http_to_https, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 80, 'apache2_port' => 82);
         } else {
             $vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 0, 'http_to_https' => $http_to_https, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 80, 'apache2_port' => 82);
         }
         // ssl vhost loop
         if ($http_to_https == 1) {
             $vhost_data['web_document_root_ssl'] = $data['new']['document_root'] . '/ssl';
             if (count($rewrite_rules) > 0) {
                 $vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 1, 'http_to_https' => 0, 'rewrite_enabled' => 1, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 443, 'apache2_port' => 82);
             } else {
                 $vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 1, 'http_to_https' => 0, 'rewrite_enabled' => 0, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 443, 'apache2_port' => 82);
             }
         }
         $tpl->setLoop('vhosts', $vhosts);
         $tpl->setVar($vhost_data);
         if ($this->action == 'insert') {
             $this->vhost_helper('insert', $data, $tpl->grab());
         }
         if ($this->action == 'update') {
             $vhost_backup = $this->vhost_helper('update', $data, $tpl->grab());
         }
     }
     /**
      * Section for aliasdomains.
      *
      * This section is used for aliasdomains.
      */
     if ($data['new']['type'] == 'alias') {
         $parent_domain = $app->dbmaster->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ' . intval($data['new']['parent_domain_id']) . '');
         $parent_domain['parent_domain_id'] = $data['new']['parent_domain_id'];
         $data['old'] = $parent_domain;
         $data['new'] = $parent_domain;
         $this->update($event_name, $data);
     }
     /**
      * Section for classic subdomains.
      *
      * This section is used for classic subdomains (non vhost subdomains).
      */
     if ($data['new']['type'] == 'subdomain') {
         $parent_domain = $app->dbmaster->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ' . intval($data['new']['parent_domain_id']) . '');
         $parent_domain['parent_domain_id'] = $data['new']['parent_domain_id'];
         $data['old'] = $parent_domain;
         $data['new'] = $parent_domain;
         $this->update($event_name, $data);
     }
     exec($final_command);
     if (isset($vhost_backup)) {
         $app->system->unlink($vhost_backup['file_new'] . '~');
     }
     unset($vhost_backup);
     $this->action = '';
 }
 function update($event_name, $data)
 {
     global $app, $conf;
     // get the config
     $app->uses('getconf');
     $server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
     //* Configure the debian network card settings.
     //* Dont configure
     if ($server_config['auto_network_configuration'] == 'y' && $data['mirrored'] == false && $server_config['ip_address'] != '0.0.0.0' && $server_config['gateway'] != '0.0.0.0') {
         if (is_file('/etc/debian_version')) {
             copy('/etc/network/interfaces', '/etc/network/interfaces~');
             $app->load('tpl');
             $network_tpl = new tpl();
             $network_tpl->newTemplate('debian_network_interfaces.master');
             $network_tpl->setVar('ip_address', $server_config['ip_address']);
             $network_tpl->setVar('netmask', $server_config['netmask']);
             $network_tpl->setVar('gateway', $server_config['gateway']);
             $network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
             $network_tpl->setVar('network', $this->network($server_config['ip_address'], $server_config['netmask']));
             $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . ' ORDER BY server_ip_id ASC');
             $ip_records = array();
             $additionl_ip_records = 0;
             $n = 0;
             if (is_array($records)) {
                 foreach ($records as $rec) {
                     /*
                      * don't insert the main-ip again!
                      */
                     if ($rec['ip_address'] != $server_config['ip_address']) {
                         $ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']), 'network' => $this->network($rec['ip_address'], $server_config['netmask']));
                         $additionl_ip_records = 1;
                         $n++;
                     }
                 }
             }
             /*
              * If we have more than 1 IP we have to add the main-ip at the end
              * of the network-ip-list. If we don't do so, there may be problems
              * in multi-server-settings (with the acces from other server to the
              * main-server) because the LAST IP in the list is the IP mysql uses
              * to determine the host, the user is logging in from.
              */
             /*
             // Disabled this part as it causes problems on multiserver setups
             if ($additionl_ip_records != 0)
             {
             	$swap['ip_address'] = $ip_records[$n-1]['ip_address'];
             	$swap['netmask'] = $ip_records[$n-1]['netmask'];
             	$swap['gateway'] = $ip_records[$n-1]['gateway'];
             	
             	$ip_records[$n-1] = array(
             		'id' => $n-1,
             		'ip_address' => $server_config['ip_address'],
             		'netmask' => $server_config['netmask'],
             		'gateway' => $server_config['gateway'],
             		'broadcast' => $this->broadcast($server_config['ip_address'],$server_config['netmask']),
             		'network' => $this->network($server_config['ip_address'],$server_config['netmask'])
             	);
             	$network_tpl->setVar('ip_address',$swap['ip_address']);
             	$network_tpl->setVar('netmask',$swap['netmask']);
             	$network_tpl->setVar('gateway',$swap['gateway']);
             	$network_tpl->setVar('broadcast',$this->broadcast($swap['ip_address'],$swap['netmask']));
             	$network_tpl->setVar('network',$this->network($swap['ip_address'],$swap['netmask']));
             }
             */
             $network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
             $network_tpl->setLoop('interfaces', $ip_records);
             file_put_contents('/etc/network/interfaces', $network_tpl->grab());
             unset($network_tpl);
             $app->log('Changed Network settings', LOGLEVEL_DEBUG);
             exec($conf['init_scripts'] . '/' . 'networking force-reload');
         } elseif (is_file('/etc/gentoo-release')) {
             copy('/etc/conf.d/net', '/etc/conf.d/net~');
             $app->load('tpl');
             $network_tpl = new tpl();
             $network_tpl->newTemplate('gentoo_network_interfaces.master');
             $network_tpl->setVar('ip_address', $server_config['ip_address']);
             $network_tpl->setVar('netmask', $server_config['netmask']);
             $network_tpl->setVar('gateway', $server_config['gateway']);
             $network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
             $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . " order by ip_address");
             $ip_records = array();
             $additionl_ip_records = 0;
             $n = 0;
             if (is_array($records)) {
                 foreach ($records as $rec) {
                     /*
                      * don't insert the main-ip again!
                      */
                     if ($rec['ip_address'] != $server_config['ip_address']) {
                         $ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']));
                         $additionl_ip_records = 1;
                         $n++;
                     }
                 }
             }
             /*
              * If we have more than 1 IP we have to add the main-ip at the end
              * of the network-ip-list. If we don't do so, there may be problems
              * in multi-server-settings (with the acces from other server to the
              * main-server) because the LAST IP in the list is the IP mysql uses
              * to determine the host, the user is logging in from.
              */
             if ($additionl_ip_records != 0) {
                 $swap['ip_address'] = $ip_records[$n - 1]['ip_address'];
                 $swap['netmask'] = $ip_records[$n - 1]['netmask'];
                 $swap['gateway'] = $ip_records[$n - 1]['gateway'];
                 $ip_records[$n - 1] = array('id' => $n - 1, 'ip_address' => $server_config['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($server_config['ip_address'], $server_config['netmask']));
                 $network_tpl->setVar('ip_address', $swap['ip_address']);
                 $network_tpl->setVar('netmask', $swap['netmask']);
                 $network_tpl->setVar('gateway', $swap['gateway']);
                 $network_tpl->setVar('broadcast', $this->broadcast($swap['ip_address'], $swap['netmask']));
             }
             $network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
             $network_tpl->setLoop('interfaces', $ip_records);
             file_put_contents('/etc/conf.d/net', $network_tpl->grab());
             unset($network_tpl);
             $app->log('Changed Network settings', LOGLEVEL_DEBUG);
             exec($conf['init_scripts'] . '/' . 'net.eth0 restart');
         } else {
             $app->log('Network configuration not available for this Linux distribution.', LOGLEVEL_DEBUG);
         }
     } else {
         if ($data['mirrored'] == true) {
             $app->log('Skipping network config request. IP addresses from amster are not configured on the mirror.', LOGLEVEL_DEBUG);
         }
         if ($server_config['auto_network_configuration'] == 'n') {
             $app->log('Network configuration disabled in server settings.', LOGLEVEL_DEBUG);
         }
     }
 }
 function update($event_name, $data)
 {
     global $app, $conf;
     // get the config
     $app->uses('getconf');
     $server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
     //* Configure the debian network card settings.
     //* Dont configure
     if ($server_config['auto_network_configuration'] == 'y' && $data['mirrored'] == false && $server_config['ip_address'] != '0.0.0.0' && $server_config['gateway'] != '0.0.0.0') {
         if (is_file('/etc/debian_version')) {
             copy('/etc/network/interfaces', '/etc/network/interfaces~');
             $app->load('tpl');
             $network_tpl = new tpl();
             $network_tpl->newTemplate('debian_network_interfaces.master');
             $network_tpl->setVar('ip_address', $server_config['ip_address']);
             $network_tpl->setVar('netmask', $server_config['netmask']);
             $network_tpl->setVar('gateway', $server_config['gateway']);
             $network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
             $network_tpl->setVar('network', $this->network($server_config['ip_address'], $server_config['netmask']));
             $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . ' ORDER BY server_ip_id ASC');
             $ip_records = array();
             $additionl_ip_records = 0;
             $n = 0;
             if (is_array($records)) {
                 foreach ($records as $rec) {
                     /*
                      * don't insert the main-ip again!
                      */
                     if ($rec['ip_address'] != $server_config['ip_address']) {
                         $ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']), 'network' => $this->network($rec['ip_address'], $server_config['netmask']));
                         $additionl_ip_records = 1;
                         $n++;
                     }
                 }
             }
             /*
              * If we have more than 1 IP we have to add the main-ip at the end
              * of the network-ip-list. If we don't do so, there may be problems
              * in multi-server-settings (with the acces from other server to the
              * main-server) because the LAST IP in the list is the IP mysql uses
              * to determine the host, the user is logging in from.
              */
             /*
             // Disabled this part as it causes problems on multiserver setups
             if ($additionl_ip_records != 0)
             {
             	$swap['ip_address'] = $ip_records[$n-1]['ip_address'];
             	$swap['netmask'] = $ip_records[$n-1]['netmask'];
             	$swap['gateway'] = $ip_records[$n-1]['gateway'];
             
             	$ip_records[$n-1] = array(
             		'id' => $n-1,
             		'ip_address' => $server_config['ip_address'],
             		'netmask' => $server_config['netmask'],
             		'gateway' => $server_config['gateway'],
             		'broadcast' => $this->broadcast($server_config['ip_address'],$server_config['netmask']),
             		'network' => $this->network($server_config['ip_address'],$server_config['netmask'])
             	);
             	$network_tpl->setVar('ip_address',$swap['ip_address']);
             	$network_tpl->setVar('netmask',$swap['netmask']);
             	$network_tpl->setVar('gateway',$swap['gateway']);
             	$network_tpl->setVar('broadcast',$this->broadcast($swap['ip_address'],$swap['netmask']));
             	$network_tpl->setVar('network',$this->network($swap['ip_address'],$swap['netmask']));
             }
             */
             $network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
             $network_tpl->setLoop('interfaces', $ip_records);
             file_put_contents('/etc/network/interfaces', $network_tpl->grab());
             unset($network_tpl);
             $app->log('Changed Network settings', LOGLEVEL_DEBUG);
             exec($conf['init_scripts'] . '/' . 'networking force-reload');
         } elseif (is_file('/etc/gentoo-release')) {
             copy('/etc/conf.d/net', '/etc/conf.d/net~');
             $app->load('tpl');
             $network_tpl = new tpl();
             $network_tpl->newTemplate('gentoo_network_interfaces.master');
             $network_tpl->setVar('ip_address', $server_config['ip_address']);
             $network_tpl->setVar('netmask', $server_config['netmask']);
             $network_tpl->setVar('gateway', $server_config['gateway']);
             $network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
             $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . " order by ip_address");
             $ip_records = array();
             $additionl_ip_records = 0;
             $n = 0;
             if (is_array($records)) {
                 foreach ($records as $rec) {
                     /*
                      * don't insert the main-ip again!
                      */
                     if ($rec['ip_address'] != $server_config['ip_address']) {
                         $ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']));
                         $additionl_ip_records = 1;
                         $n++;
                     }
                 }
             }
             /*
              * If we have more than 1 IP we have to add the main-ip at the end
              * of the network-ip-list. If we don't do so, there may be problems
              * in multi-server-settings (with the acces from other server to the
              * main-server) because the LAST IP in the list is the IP mysql uses
              * to determine the host, the user is logging in from.
              */
             if ($additionl_ip_records != 0) {
                 $swap['ip_address'] = $ip_records[$n - 1]['ip_address'];
                 $swap['netmask'] = $ip_records[$n - 1]['netmask'];
                 $swap['gateway'] = $ip_records[$n - 1]['gateway'];
                 $ip_records[$n - 1] = array('id' => $n - 1, 'ip_address' => $server_config['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($server_config['ip_address'], $server_config['netmask']));
                 $network_tpl->setVar('ip_address', $swap['ip_address']);
                 $network_tpl->setVar('netmask', $swap['netmask']);
                 $network_tpl->setVar('gateway', $swap['gateway']);
                 $network_tpl->setVar('broadcast', $this->broadcast($swap['ip_address'], $swap['netmask']));
             }
             $network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
             $network_tpl->setLoop('interfaces', $ip_records);
             file_put_contents('/etc/conf.d/net', $network_tpl->grab());
             unset($network_tpl);
             $app->log('Changed Network settings', LOGLEVEL_DEBUG);
             exec($conf['init_scripts'] . '/' . 'net.eth0 restart');
         } else {
             $app->log('Network configuration not available for this Linux distribution.', LOGLEVEL_DEBUG);
         }
     } else {
         if ($data['mirrored'] == true) {
             $app->log('Skipping network config request. IP addresses from master are not configured on the mirror.', LOGLEVEL_DEBUG);
         }
         if ($server_config['auto_network_configuration'] == 'n') {
             $app->log('Network configuration disabled in server settings.', LOGLEVEL_DEBUG);
         }
     }
     //* Configure hostname
     if ($event_name == 'server_update' && $data['mirrored'] == false) {
         //* get old server config
         $tmp = $app->ini_parser->parse_ini_string(stripslashes($data['old']['config']));
         $old_server_config = $tmp['server'];
         unset($tmp);
         $new_hostname = trim($server_config['hostname']);
         $old_hostname = trim($old_server_config['hostname']);
         if ($new_hostname != '' && $old_hostname != $new_hostname) {
             if (is_file('/etc/hostname')) {
                 $app->system->file_put_contents('/etc/hostname', $new_hostname);
                 $app->log('Changed /etc/hostname to ' . $new_hostname, LOGLEVEL_DEBUG);
             }
             if (is_file('/etc/mailname')) {
                 $app->system->file_put_contents('/etc/mailname', $new_hostname);
                 $app->log('Changed /etc/mailname to ' . $new_hostname, LOGLEVEL_DEBUG);
             }
             $postconf_commands = array('myhostname = ' . $new_hostname, 'mydestination = ' . $new_hostname . ', localhost, localhost.localdomain');
             //* Executing the postconf commands
             foreach ($postconf_commands as $cmd) {
                 $command = "postconf -e '{$cmd}'";
                 exec($command);
             }
             $app->log('Changed changed myhostname and mydestination in postfix main.cf to ' . $new_hostname, LOGLEVEL_DEBUG);
             //* change /etc/hosts
             $hosts = file_get_contents('/etc/hosts');
             $hosts = str_replace($old_hostname, $new_hostname, $hosts);
             $app->system->file_put_contents('/etc/hosts', $hosts);
             exec($app->system->getinitcommand('postfix', 'restart') . ' 2>&1');
             exec($app->system->getinitcommand('networking', 'restart') . ' 2>&1');
         }
     }
 }
Esempio n. 13
0
 private function php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir)
 {
     global $app, $conf;
     //$reload = false;
     if ($data['new']['php'] == 'no') {
         if (@is_file($pool_dir . $pool_name . '.conf')) {
             unlink($pool_dir . $pool_name . '.conf');
             //$reload = true;
         }
         //if($reload == true) $app->services->restartService('php-fpm','reload');
         return;
     }
     $app->uses("getconf");
     $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate('php_fpm_pool.conf.master');
     if ($data['new']['php_fpm_use_socket'] == 'y') {
         $use_tcp = 0;
         $use_socket = 1;
         if (!is_dir($socket_dir)) {
             exec('mkdir -p ' . $socket_dir);
         }
     } else {
         $use_tcp = 1;
         $use_socket = 0;
     }
     $tpl->setVar('use_tcp', $use_tcp);
     $tpl->setVar('use_socket', $use_socket);
     $fpm_socket = $socket_dir . $pool_name . '.sock';
     $tpl->setVar('fpm_socket', $fpm_socket);
     $tpl->setVar('fpm_pool', $pool_name);
     $tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1);
     $tpl->setVar('fpm_user', $data['new']['system_user']);
     $tpl->setVar('fpm_group', $data['new']['system_group']);
     $tpl->setVar('pm_max_children', $data['new']['pm_max_children']);
     $tpl->setVar('pm_start_servers', $data['new']['pm_start_servers']);
     $tpl->setVar('pm_min_spare_servers', $data['new']['pm_min_spare_servers']);
     $tpl->setVar('pm_max_spare_servers', $data['new']['pm_max_spare_servers']);
     $tpl->setVar('document_root', $data['new']['document_root']);
     $tpl->setVar('security_level', $web_config['security_level']);
     $php_open_basedir = $data['new']['php_open_basedir'] == '' ? escapeshellcmd($data['new']['document_root']) : escapeshellcmd($data['new']['php_open_basedir']);
     $tpl->setVar('php_open_basedir', $php_open_basedir);
     if ($php_open_basedir != '') {
         $tpl->setVar('enable_php_open_basedir', '');
     } else {
         $tpl->setVar('enable_php_open_basedir', ';');
     }
     // Custom php.ini settings
     $final_php_ini_settings = array();
     $custom_php_ini_settings = trim($data['new']['custom_php_ini']);
     if ($custom_php_ini_settings != '') {
         // Make sure we only have Unix linebreaks
         $custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
         $custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
         $ini_settings = explode("\n", $custom_php_ini_settings);
         if (is_array($ini_settings) && !empty($ini_settings)) {
             foreach ($ini_settings as $ini_setting) {
                 list($key, $value) = explode('=', $ini_setting);
                 if ($value) {
                     $value = escapeshellcmd(trim($value));
                     $key = escapeshellcmd(trim($key));
                     switch (strtolower($value)) {
                         case 'on':
                         case 'off':
                         case '1':
                         case '0':
                             // PHP-FPM might complain about invalid boolean value if you use 0
                             $value = 'off';
                         case 'true':
                         case 'false':
                         case 'yes':
                         case 'no':
                             $final_php_ini_settings[] = array('ini_setting' => 'php_admin_flag[' . $key . '] = ' . $value);
                             break;
                         default:
                             $final_php_ini_settings[] = array('ini_setting' => 'php_admin_value[' . $key . '] = ' . $value);
                     }
                 }
             }
         }
     }
     $tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
     file_put_contents($pool_dir . $pool_name . '.conf', $tpl->grab());
     $app->log('Writing the PHP-FPM config file: ' . $pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
     unset($tpl);
     //$reload = true;
     //if($reload == true) $app->services->restartService('php-fpm','reload');
 }
Esempio n. 14
0
 function onShow()
 {
     global $app;
     $app->uses('listform');
     $app->listform->loadListDef($this->options["listdef"]);
     //$app->listform->SQLExtWhere = "type = 'alias'";
     $listTpl = new tpl();
     $listTpl->newTemplate('templates/' . $app->listform->listDef["name"] . '_list.htm');
     //die(print_r($app->tform_actions));
     // Changing some of the list values to reflect that the list is called within a tform page
     $app->listform->listDef["file"] = $app->tform->formDef["action"];
     // $app->listform->listDef["page_params"] = "&id=".$app->tform_actions->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
     $app->listform->listDef["page_params"] = "&id=" . $this->form->id . "&next_tab=" . $_SESSION["s"]["form"]["tab"];
     $listTpl->setVar('parent_id', $this->form->id);
     $listTpl->setVar('theme', $_SESSION['s']['theme']);
     // Generate the SQL for searching
     $sql_where = "";
     if ($app->listform->listDef["auth"] != 'no') {
         if ($_SESSION["s"]["user"]["typ"] != "admin") {
             $sql_where = $app->tform->getAuthSQL('r') . " and";
         }
     }
     if ($this->options["sqlextwhere"] != '') {
         $sql_where .= " " . $this->options["sqlextwhere"] . " and";
     }
     $sql_where = $app->listform->getSearchSQL($sql_where);
     $listTpl->setVar($app->listform->searchValues);
     // Generate SQL for paging
     $limit_sql = $app->listform->getPagingSQL($sql_where);
     $listTpl->setVar("paging", $app->listform->pagingHTML);
     $sql_order_by = '';
     if (isset($this->options["sql_order_by"])) {
         $sql_order_by = $this->options["sql_order_by"];
     }
     //* Limit each page
     $limits = array('5' => '5', '15' => '15', '25' => '25', '50' => '50', '100' => '100', '999999999' => 'all');
     //* create options and set selected, if default -> 15 is selected
     $options = '';
     foreach ($limits as $key => $val) {
         $options .= '<option value="' . $key . '" ' . (isset($_SESSION['search']['limit']) && $_SESSION['search']['limit'] == $key ? 'selected="selected"' : '') . (!isset($_SESSION['search']['limit']) && $key == '15' ? 'selected="selected"' : '') . '>' . $val . '</option>';
     }
     $listTpl->setVar('search_limit', '<select name="search_limit" style="width:50px">' . $options . '</select>');
     //Sorting
     if (!isset($_SESSION['search'][$app->listform->listDef["name"]]['order'])) {
         $_SESSION['search'][$app->listform->listDef["name"]]['order'] = '';
     }
     if (!empty($_GET['orderby'])) {
         $order = str_replace('tbl_col_', '', $_GET['orderby']);
         //* Check the css class submited value
         if (preg_match("/^[a-z\\_]{1,}\$/", $order)) {
             if ($_SESSION['search'][$app->listform->listDef["name"]]['order'] == $order) {
                 $_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order . ' DESC';
             } else {
                 $_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order;
             }
         }
     }
     // If a manuel oder by like customers isset the sorting will be infront
     if (!empty($_SESSION['search'][$app->listform->listDef["name"]]['order'])) {
         if (empty($sql_order_by)) {
             $sql_order_by = "ORDER BY " . $_SESSION['search'][$app->listform->listDef["name"]]['order'];
         } else {
             $sql_order_by = str_replace("ORDER BY ", "ORDER BY " . $_SESSION['search'][$app->listform->listDef["name"]]['order'] . ', ', $sql_order_by);
         }
     }
     // Loading language field
     $lng_file = "lib/lang/" . $_SESSION["s"]["language"] . "_" . $app->listform->listDef['name'] . "_list.lng";
     include $lng_file;
     $listTpl->setVar($wb);
     // Get the data
     $records = $app->db->queryAllRecords("SELECT * FROM " . $app->listform->listDef["table"] . " WHERE {$sql_where} {$sql_order_by} {$limit_sql}");
     $bgcolor = "#FFFFFF";
     if (is_array($records)) {
         $idx_key = $app->listform->listDef["table_idx"];
         foreach ($records as $rec) {
             $rec = $app->listform->decode($rec);
             // Change of color
             $bgcolor = $bgcolor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
             $rec["bgcolor"] = $bgcolor;
             // substitute value for select fields
             foreach ($app->listform->listDef["item"] as $field) {
                 $key = $field["field"];
                 if ($field['formtype'] == "SELECT") {
                     if (strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') {
                         // Set a additional image variable for bolean fields
                         $rec['_' . $key . '_'] = strtolower($rec[$key]) == 'y' ? 'x16/tick_circle.png' : 'x16/cross_circle.png';
                     }
                     //* substitute value for select field
                     @($rec[$key] = $field['value'][$rec[$key]]);
                 }
                 // Create a lowercase version of every item
                 $rec[$key . '_lowercase'] = strtolower($rec[$key]);
             }
             // The variable "id" contains always the index field
             $rec["id"] = $rec[$idx_key];
             $rec["delete_confirmation"] = $wb['delete_confirmation'];
             $records_new[] = $rec;
         }
     }
     $listTpl->setLoop('records', @$records_new);
     // Setting Returnto information in the session
     $list_name = $app->listform->listDef["name"];
     // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
     $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
     $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
     $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
     $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
     $_SESSION["s"]["form"]["return_to"] = $list_name;
     //die(print_r($_SESSION["s"]["list"][$list_name]));
     return $listTpl->grab();
 }
Esempio n. 15
0
 function write_named_conf($data, $dns_config)
 {
     global $app, $conf;
     //* Only write the master file for the current server
     $tmps = $app->db->queryAllRecords("SELECT origin, xfer, also_notify, update_acl FROM dns_soa WHERE active = 'Y' AND server_id=" . $conf["server_id"]);
     $zones = array();
     //* Check if the current zone that triggered this function has at least one NS record
     /* Has been replaced by a better zone check
     		$rec_num = $app->db->queryOneRecord("SELECT count(id) as ns FROM dns_rr WHERE type = 'NS' AND zone = ".intval($data['new']['id'])." AND active = 'Y'");
     		if($rec_num['ns'] == 0) {
     			$exclude_zone = $data['new']['origin'];
     		} else {
     			$exclude_zone = '';
     		}
     		*/
     //TODO : change this when distribution information has been integrated into server record
     if (file_exists('/etc/gentoo-release')) {
         $pri_zonefiles_path = $dns_config['bind_zonefiles_dir'] . '/pri/';
         $sec_zonefiles_path = $dns_config['bind_zonefiles_dir'] . '/sec/';
     } else {
         $pri_zonefiles_path = $dns_config['bind_zonefiles_dir'] . '/pri.';
         $sec_zonefiles_path = $dns_config['bind_zonefiles_dir'] . '/slave/sec.';
     }
     //* Loop trough zones
     foreach ($tmps as $tmp) {
         $zone_file = $pri_zonefiles_path . str_replace("/", "_", substr($tmp['origin'], 0, -1));
         $options = '';
         if (trim($tmp['xfer']) != '') {
             $options .= "        allow-transfer {" . str_replace(',', ';', $tmp['xfer']) . ";};\n";
         } else {
             $options .= "        allow-transfer {none;};\n";
         }
         if (trim($tmp['also_notify']) != '') {
             $options .= '        also-notify {' . str_replace(',', ';', $tmp['also_notify']) . ";};\n";
         }
         if (trim($tmp['update_acl']) != '') {
             $options .= "        allow-update {" . str_replace(',', ';', $tmp['update_acl']) . ";};\n";
         }
         if (file_exists($zone_file)) {
             $zones[] = array('zone' => substr($tmp['origin'], 0, -1), 'zonefile_path' => $zone_file, 'options' => $options);
         }
     }
     $tpl = new tpl();
     $tpl->newTemplate("bind_named.conf.local.master");
     $tpl->setLoop('zones', $zones);
     //* And loop through the secondary zones, but only for the current server
     $tmps_sec = $app->db->queryAllRecords("SELECT origin, xfer, ns FROM dns_slave WHERE active = 'Y' AND server_id=" . $conf["server_id"]);
     $zones_sec = array();
     foreach ($tmps_sec as $tmp) {
         $options = "        masters {" . $tmp['ns'] . ";};\n";
         if (trim($tmp['xfer']) != '') {
             $options .= "        allow-transfer {" . str_replace(',', ';', $tmp['xfer']) . ";};\n";
         } else {
             $options .= "        allow-transfer {none;};\n";
         }
         $zones_sec[] = array('zone' => substr($tmp['origin'], 0, -1), 'zonefile_path' => $sec_zonefiles_path . str_replace("/", "_", substr($tmp['origin'], 0, -1)), 'options' => $options);
         //			$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/slave/sec.'.substr($tmp['origin'],0,-1));
         //			$app->log("Writing BIND domain file: ".$filename,LOGLEVEL_DEBUG);
     }
     $tpl_sec = new tpl();
     $tpl_sec->newTemplate("bind_named.conf.local.slave");
     $tpl_sec->setLoop('zones', $zones_sec);
     file_put_contents($dns_config['named_conf_local_path'], $tpl->grab() . "\n" . $tpl_sec->grab());
     $app->log("Writing BIND named.conf.local file: " . $dns_config['named_conf_local_path'], LOGLEVEL_DEBUG);
     unset($tpl_sec);
     unset($zones_sec);
     unset($tmps_sec);
     unset($tpl);
     unset($zones);
     unset($tmps);
 }
Esempio n. 16
0
 public function configure_apache()
 {
     global $conf;
     if ($conf['apache']['installed'] == false) {
         return;
     }
     //* Create the logging directory for the vhost logfiles
     if (!is_dir($conf['ispconfig_log_dir'] . '/httpd')) {
         mkdir($conf['ispconfig_log_dir'] . '/httpd', 0755, true);
     }
     if (is_file($conf['suphp']['config_file'])) {
         $content = rf($conf['suphp']['config_file']);
         if (!preg_match('|^x-httpd-suphp=php:/usr/bin/php-cgi$|m', $content)) {
             $content = preg_replace('/;Handler for php-scripts/', ";Handler for php-scripts\nx-httpd-suphp=php:/usr/bin/php-cgi", $content);
             $content = preg_replace('/;?umask=\\d+/', 'umask=0022', $content);
         }
         $this->write_config_file($conf['suphp']['config_file'], $content);
     }
     //* Enable ISPConfig default vhost settings
     $default_vhost_path = $conf['apache']['vhost_conf_dir'] . '/' . $conf['apache']['vhost_default'];
     if (is_file($default_vhost_path)) {
         $content = rf($default_vhost_path);
         $content = preg_replace('/^#?\\s*NameVirtualHost.*$/m', 'NameVirtualHost *:80', $content);
         $content = preg_replace('/<VirtualHost[^>]+>/', '<VirtualHost *:80>', $content);
         $this->write_config_file($default_vhost_path, $content);
     }
     //* Generate default ssl certificates
     if (!is_dir($conf['apache']['ssl_dir'])) {
         mkdir($conf['apache']['ssl_dir']);
     }
     if ($conf['services']['mail'] == true) {
         copy($conf['postfix']['config_dir'] . "/smtpd.key", $conf['apache']['ssl_dir'] . "/server.key");
         copy($conf['postfix']['config_dir'] . "/smtpd.cert", $conf['apache']['ssl_dir'] . "/server.crt");
     } else {
         if (!is_file($conf['apache']['ssl_dir'] . '/server.crt')) {
             exec("openssl req -new -outform PEM -out {$conf['apache']['ssl_dir']}/server.crt -newkey rsa:2048 -nodes -keyout {$conf['apache']['ssl_dir']}/server.key -keyform PEM -days 365 -x509");
         }
     }
     //* Copy the ISPConfig configuration include
     /*
     $content = $this->get_template_file('apache_ispconfig.conf', true);
     
     $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
     if(is_array($records) && count($records) > 0)
     {
     	foreach($records as $rec) {
     		$content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
     		$content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
     	}
     }
     
     $this->write_config_file($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $content);
     */
     $tpl = new tpl('apache_ispconfig.conf.master');
     $tpl->setVar('apache_version', getapacheversion());
     $records = $this->db->queryAllRecords('SELECT * FROM ' . $conf['mysql']['master_database'] . '.server_ip WHERE server_id = ' . $conf['server_id'] . " AND virtualhost = 'y'");
     $ip_addresses = array();
     if (is_array($records) && count($records) > 0) {
         foreach ($records as $rec) {
             if ($rec['ip_type'] == 'IPv6') {
                 $ip_address = '[' . $rec['ip_address'] . ']';
             } else {
                 $ip_address = $rec['ip_address'];
             }
             $ports = explode(',', $rec['virtualhost_port']);
             if (is_array($ports)) {
                 foreach ($ports as $port) {
                     $port = intval($port);
                     if ($port > 0 && $port < 65536 && $ip_address != '') {
                         $ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
                     }
                 }
             }
         }
     }
     if (count($ip_addresses) > 0) {
         $tpl->setLoop('ip_adresses', $ip_addresses);
     }
     wf($conf['apache']['vhost_conf_dir'] . '/000-ispconfig.conf', $tpl->grab());
     unset($tpl);
     //* Gentoo by default does not include .vhost files. Add include line to config file.
     $content = rf($conf['apache']['config_file']);
     if (strpos($content, 'Include /etc/apache2/vhosts.d/*.vhost') === false) {
         $content = preg_replace('|(Include /etc/apache2/vhosts.d/\\*.conf)|', "\$1\nInclude /etc/apache2/vhosts.d/*.vhost", $content);
     }
     $this->write_config_file($conf['apache']['config_file'], $content);
     //* make sure that webalizer finds its config file when it is directly in /etc
     if (is_file('/etc/webalizer.conf') && !is_dir('/etc/webalizer')) {
         mkdir('/etc/webalizer', 0755);
         symlink('/etc/webalizer.conf', '/etc/webalizer/webalizer.conf');
     }
     if (is_file('/etc/webalizer/webalizer.conf')) {
         replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental     yes', 0, 0);
         replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName     webalizer.hist', 0, 0);
     }
     //* add a sshusers group
     if (!is_group('sshusers')) {
         $command = 'groupadd sshusers';
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
 }
Esempio n. 17
0
 function show()
 {
     global $app, $conf;
     $limits = array();
     /* Limits to be shown*/
     $limits[] = array('field' => 'limit_maildomain', 'db_table' => 'mail_domain', 'db_where' => '');
     $limits[] = array('field' => 'limit_mailmailinglist', 'db_table' => 'mail_mailinglist', 'db_where' => '');
     $limits[] = array('field' => 'limit_mailbox', 'db_table' => 'mail_user', 'db_where' => '');
     $limits[] = array('field' => 'limit_mailalias', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'alias'");
     $limits[] = array('field' => 'limit_mailaliasdomain', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'aliasdomain'");
     $limits[] = array('field' => 'limit_mailforward', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'forward'");
     $limits[] = array('field' => 'limit_mailcatchall', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'catchall'");
     $limits[] = array('field' => 'limit_mailrouting', 'db_table' => 'mail_transport', 'db_where' => "");
     $limits[] = array('field' => 'limit_mailfilter', 'db_table' => 'mail_user_filter', 'db_where' => "");
     $limits[] = array('field' => 'limit_fetchmail', 'db_table' => 'mail_get', 'db_where' => "");
     $limits[] = array('field' => 'limit_spamfilter_wblist', 'db_table' => 'spamfilter_wblist', 'db_where' => "");
     $limits[] = array('field' => 'limit_spamfilter_user', 'db_table' => 'spamfilter_users', 'db_where' => "");
     $limits[] = array('field' => 'limit_spamfilter_policy', 'db_table' => 'spamfilter_policy', 'db_where' => "");
     $limits[] = array('field' => 'limit_web_domain', 'db_table' => 'web_domain', 'db_where' => "type = 'vhost'");
     $limits[] = array('field' => 'limit_web_subdomain', 'db_table' => 'web_domain', 'db_where' => "(type = 'subdomain' OR type = 'vhostsubdomain')");
     $limits[] = array('field' => 'limit_web_aliasdomain', 'db_table' => 'web_domain', 'db_where' => "type = 'alias'");
     $limits[] = array('field' => 'limit_ftp_user', 'db_table' => 'ftp_user', 'db_where' => "");
     $limits[] = array('field' => 'limit_shell_user', 'db_table' => 'shell_user', 'db_where' => "");
     $limits[] = array('field' => 'limit_dns_zone', 'db_table' => 'dns_soa', 'db_where' => "");
     $limits[] = array('field' => 'limit_dns_slave_zone', 'db_table' => 'dns_slave', 'db_where' => "");
     $limits[] = array('field' => 'limit_dns_record', 'db_table' => 'dns_rr', 'db_where' => "");
     $limits[] = array('field' => 'limit_database', 'db_table' => 'web_database', 'db_where' => "");
     $limits[] = array('field' => 'limit_cron', 'db_table' => 'cron', 'db_where' => "");
     $limits[] = array('field' => 'limit_client', 'db_table' => 'client', 'db_where' => "");
     //* Loading Template
     $app->uses('tpl,tform');
     $tpl = new tpl();
     $tpl->newTemplate("dashlets/templates/limits.htm");
     $wb = array();
     $lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_limits.lng';
     if (is_file($lng_file)) {
         include $lng_file;
     }
     $tpl->setVar($wb);
     if ($app->auth->is_admin()) {
         $user_is_admin = true;
     } else {
         $user_is_admin = false;
     }
     $tpl->setVar('is_admin', $user_is_admin);
     if ($user_is_admin == false) {
         $client_group_id = $_SESSION["s"]["user"]["default_group"];
         $client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = {$client_group_id}");
     }
     $rows = array();
     foreach ($limits as $limit) {
         $field = $limit['field'];
         if ($user_is_admin) {
             $value = $wb['unlimited_txt'];
         } else {
             $value = $client[$field];
         }
         if ($value != 0 || $value == $wb['unlimited_txt']) {
             $value_formatted = $value == '-1' ? $wb['unlimited_txt'] : $value;
             $rows[] = array('field' => $field, 'field_txt' => $wb[$field . '_txt'], 'value' => $value_formatted, 'usage' => $this->_get_limit_usage($limit));
         }
     }
     $tpl->setLoop('rows', $rows);
     return $tpl->grab();
 }
Esempio n. 18
0
 function server_ip($event_name, $data)
 {
     global $app, $conf;
     // load the server configuration options
     $app->uses('getconf');
     $web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
     $app->load('tpl');
     $tpl = new tpl();
     $tpl->newTemplate('apache_ispconfig.conf.master');
     $records = $app->db->queryAllRecords('SELECT * FROM server_ip WHERE server_id = ' . $conf['server_id'] . " AND virtualhost = 'y'");
     $records_out = array();
     if (is_array($records)) {
         foreach ($records as $rec) {
             if ($rec['ip_type'] == 'IPv6') {
                 $ip_address = '[' . $rec['ip_address'] . ']';
             } else {
                 $ip_address = $rec['ip_address'];
             }
             $ports = explode(',', $rec['virtualhost_port']);
             if (is_array($ports)) {
                 foreach ($ports as $port) {
                     $port = intval($port);
                     if ($port > 0 && $port < 65536 && $ip_address != '') {
                         $records_out[] = array('ip_address' => $ip_address, 'port' => $port);
                     }
                 }
             }
         }
     }
     if (count($records_out) > 0) {
         $tpl->setLoop('ip_adresses', $records_out);
     }
     $vhost_file = escapeshellcmd($web_config['vhost_conf_dir'] . '/ispconfig.conf');
     file_put_contents($vhost_file, $tpl->grab());
     $app->log('Writing the conf file: ' . $vhost_file, LOGLEVEL_DEBUG);
     unset($tpl);
 }