| | |
| | | die('ERROR: '.$msg."\n"); |
| | | } |
| | | |
| | | public function warning($msg) { |
| | | echo('WARNING: '.$msg."\n"); |
| | | } |
| | | |
| | | public function simple_query($query, $answers, $default) { |
| | | $finished = false; |
| | | do { |
| | |
| | | |
| | | if(is_installed('mysql') || is_installed('mysqld')) $conf['mysql']['installed'] = true; |
| | | if(is_installed('postfix')) $conf['postfix']['installed'] = true; |
| | | if(is_installed('mailman')) $conf['mailman']['installed'] = true; |
| | | if(is_installed('apache') || is_installed('apache2') || is_installed('httpd')) $conf['apache']['installed'] = true; |
| | | if(is_installed('getmail')) $conf['getmail']['installed'] = true; |
| | | if(is_installed('couriertcpd')) $conf['courier']['installed'] = true; |
| | | if(is_installed('courierlogger')) $conf['courier']['installed'] = true; |
| | | if(is_installed('dovecot')) $conf['dovecot']['installed'] = true; |
| | | if(is_installed('saslsauthd')) $conf['saslauthd']['installed'] = true; |
| | | if(is_installed('saslauthd')) $conf['saslauthd']['installed'] = true; |
| | | if(is_installed('amavisd-new')) $conf['amavis']['installed'] = true; |
| | | if(is_installed('clamdscan')) $conf['clamav']['installed'] = true; |
| | | if(is_installed('pure-ftpd') || is_installed('pure-ftpd-wrapper')) $conf['pureftpd']['installed'] = true; |
| | |
| | | if(is_installed('jk_chrootsh')) $conf['jailkit']['installed'] = true; |
| | | if(is_installed('pdns_server') || is_installed('pdns_control')) $conf['powerdns']['installed'] = true; |
| | | if(is_installed('named') || is_installed('bind') || is_installed('bind9')) $conf['bind']['installed'] = true; |
| | | |
| | | if(is_installed('squid')) $conf['squid']['installed'] = true; |
| | | if(is_installed('nginx')) $conf['nginx']['installed'] = true; |
| | | if(is_installed('iptables') && is_installed('ufw')) $conf['ufw']['installed'] = true; |
| | | if(is_installed('fail2ban-server')) $conf['fail2ban']['installed'] = true; |
| | | if(is_dir("/etc/Bastille")) $conf['bastille']['installed'] = true; |
| | | |
| | | if ($conf['services']['web'] && $conf['apache']['installed'] && is_file($conf['apache']["vhost_conf_enabled_dir"]."/000-ispconfig.vhost")) $this->ispconfig_interface_installed = true; |
| | | } |
| | | |
| | | /** Create the database for ISPConfig */ |
| | |
| | | $tpl_ini_array['dns']['bind_zonefiles_dir'] = $conf['bind']['bind_zonefiles_dir']; |
| | | $tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path']; |
| | | $tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path']; |
| | | |
| | | if ($conf['nginx']['installed'] == true) { |
| | | $tpl_ini_array['nginx']['vhost_conf_dir'] = $conf['nginx']['vhost_conf_dir']; |
| | | $tpl_ini_array['nginx']['vhost_conf_enabled_dir'] = $conf['nginx']['vhost_conf_enabled_dir']; |
| | | } |
| | | |
| | | if (array_key_exists('awstats', $conf)) { |
| | | foreach ($conf['awstats'] as $aw_sett => $aw_value) { |
| | | $tpl_ini_array['web']['awstats_'.$aw_sett] = $aw_value; |
| | | } |
| | | } |
| | | |
| | | $server_ini_content = array_to_ini($tpl_ini_array); |
| | | $server_ini_content = mysql_real_escape_string($server_ini_content); |
| | |
| | | $file_server_enabled = ($conf['services']['file'])?1:0; |
| | | $db_server_enabled = ($conf['services']['db'])?1:0; |
| | | $vserver_server_enabled = ($conf['services']['vserver'])?1:0; |
| | | |
| | | $proxy_server_enabled = ($conf['services']['proxy'])?1:0; |
| | | $firewall_server_enabled = ($conf['services']['firewall'])?1:0; |
| | | |
| | | //** Get the database version number based on the patchfiles |
| | | $found = true; |
| | | $current_db_version = 1; |
| | | while($found == true) { |
| | | $next_db_version = intval($current_db_version + 1); |
| | | $patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql'; |
| | | if(is_file($patch_filename)) { |
| | | $current_db_version = $next_db_version; |
| | | } else { |
| | | $found = false; |
| | | } |
| | | } |
| | | $current_db_version = intval($current_db_version); |
| | | |
| | | |
| | | if($conf['mysql']['master_slave_setup'] == 'y') { |
| | | |
| | | //* Insert the server record in master DB |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);"; |
| | | $this->dbmaster->query($sql); |
| | | $conf['server_id'] = $this->dbmaster->insertID(); |
| | | $conf['server_id'] = $conf['server_id']; |
| | | |
| | | //* Insert the same record in the local DB |
| | | $sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
| | | $sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);"; |
| | | $this->db->query($sql); |
| | | |
| | | //* username for the ispconfig user |
| | |
| | | |
| | | } else { |
| | | //* Insert the server, if its not a mster / slave setup |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);"; |
| | | $this->db->query($sql); |
| | | $conf['server_id'] = $this->db->insertID(); |
| | | $conf['server_id'] = $conf['server_id']; |
| | |
| | | |
| | | } |
| | | |
| | | public function grant_master_database_rights() { |
| | | public function grant_master_database_rights($verbose = false) { |
| | | global $conf; |
| | | |
| | | /* |
| | |
| | | * 1) it is a single server |
| | | * 2) it is the MASTER of n clients |
| | | */ |
| | | $hosts = array(); |
| | | |
| | | if($conf['mysql']['master_slave_setup'] == 'y') { |
| | | /* |
| | | * it is a master-slave - Setup so the slave has to grant its rights in the master |
| | |
| | | } |
| | | } |
| | | |
| | | if(is_array($hosts)) { |
| | | if(count($hosts) > 0) { |
| | | foreach($hosts as $host => $value) { |
| | | /* |
| | | * If a pwd exists, this means, we have to add the new user (and his pwd). |
| | |
| | | */ |
| | | if ($value['pwd'] != ''){ |
| | | $query = "CREATE USER '".$value['user']."'@'".$host."' IDENTIFIED BY '" . $value['pwd'] . "'"; |
| | | if ($verbose){ |
| | | echo "\n\n" . $query ."\n"; |
| | | } |
| | | $this->dbmaster->query($query); // ignore the error |
| | | } |
| | | |
| | |
| | | * In Case that it will not exist, do nothing (ignore the error!) |
| | | */ |
| | | $query = "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo "\n\n" . $query ."\n"; |
| | | } |
| | | $this->dbmaster->query($query); // ignore the error |
| | | |
| | | //* Create the ISPConfig database user in the remote database |
| | | $query = "GRANT SELECT ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, INSERT ON ".$value['db'].".`sys_log` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`sys_datalog` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`software_update_inst` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, UPDATE(`updated`) ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, UPDATE (`ssl_request`, `ssl_cert`, `ssl_action`) ON ".$value['db'].".`web_domain` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT ON ".$value['db'].".`sys_group` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, UPDATE (`action_state`, `response`) ON ".$value['db'].".`sys_remoteaction` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, INSERT , DELETE ON ".$value['db'].".`monitor_data` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`mail_traffic` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | $query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`web_traffic` TO '".$value['user']."'@'".$host."' "; |
| | | if ($verbose){ |
| | | echo $query ."\n"; |
| | | } |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
| | | $this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage); |
| | | } |
| | | } |
| | | |
| | |
| | | copy('tpl/'.$jk_chrootsh.'.master', $config_dir.'/'.$jk_chrootsh); |
| | | } |
| | | |
| | | } |
| | | |
| | | public function configure_mailman($status = 'insert') { |
| | | global $conf; |
| | | |
| | | $config_dir = $conf['mailman']['config_dir'].'/'; |
| | | $full_file_name = $config_dir.'mm_cfg.py'; |
| | | //* Backup exiting file |
| | | if(is_file($full_file_name)) { |
| | | copy($full_file_name, $config_dir.'mm_cfg.py~'); |
| | | } |
| | | |
| | | // load files |
| | | $content = rf('tpl/mm_cfg.py.master'); |
| | | $old_file = rf($full_file_name); |
| | | |
| | | $old_options = array(); |
| | | $lines = explode("\n", $old_file); |
| | | foreach ($lines as $line) |
| | | { |
| | | if (trim($line) != '' && substr($line, 0, 1) != '#') |
| | | { |
| | | @list($key, $value) = @explode("=", $line); |
| | | if (!empty($value)) |
| | | { |
| | | $key = rtrim($key); |
| | | $old_options[$key] = trim($value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | $virtual_domains = ''; |
| | | if($status == 'update') |
| | | { |
| | | // create virtual_domains list |
| | | $domainAll = $this->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain"); |
| | | |
| | | if(is_array($domainAll)) { |
| | | foreach($domainAll as $domain) |
| | | { |
| | | if ($domainAll[0]['domain'] == $domain['domain']) |
| | | $virtual_domains .= "'".$domain['domain']."'"; |
| | | else |
| | | $virtual_domains .= ", '".$domain['domain']."'"; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | $virtual_domains = "' '"; |
| | | |
| | | $content = str_replace('{hostname}', $conf['hostname'], $content); |
| | | if(!isset($old_options['DEFAULT_SERVER_LANGUAGE'])) $old_options['DEFAULT_SERVER_LANGUAGE'] = ''; |
| | | $content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content); |
| | | $content = str_replace('{virtual_domains}', $virtual_domains, $content); |
| | | |
| | | wf($full_file_name, $content); |
| | | } |
| | | |
| | | public function configure_postfix($options = '') { |
| | |
| | | 'myhostname = '.$conf['hostname'], |
| | | 'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain', |
| | | 'mynetworks = 127.0.0.0/8 [::1]/128', |
| | | 'alias_maps = hash:/etc/aliases, hash:/var/lib/mailman/data/aliases', |
| | | 'alias_database = hash:/etc/aliases, hash:/var/lib/mailman/data/aliases', |
| | | 'virtual_alias_domains =', |
| | | 'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf', |
| | | 'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, proxy:mysql:'.$config_dir.'/mysql-virtual_email2email.cf, hash:/var/lib/mailman/data/virtual-mailman', |
| | | 'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf', |
| | | 'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf', |
| | | 'virtual_mailbox_base = '.$cf['vmail_mailbox_base'], |
| | |
| | | 'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf', |
| | | 'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf', |
| | | 'relay_recipient_maps = mysql:'.$config_dir.'/mysql-virtual_relayrecipientmaps.cf', |
| | | 'virtual_create_maildirsize = yes', |
| | | 'virtual_maildir_extended = yes', |
| | | 'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf', |
| | | 'virtual_mailbox_limit_override = yes', |
| | | 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."', |
| | | 'virtual_overquota_bounce = yes', |
| | | 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps', |
| | | 'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf', |
| | | 'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf', |
| | | 'smtpd_client_message_rate_limit = 100', |
| | | 'maildrop_destination_concurrency_limit = 1', |
| | | 'maildrop_destination_recipient_limit = 1', |
| | | 'virtual_transport = maildrop', |
| | | 'header_checks = regexp:'.$config_dir.'/header_checks', |
| | | 'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks', |
| | | 'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks', |
| | | 'body_checks = regexp:'.$config_dir.'/body_checks' |
| | | 'body_checks = regexp:'.$config_dir.'/body_checks', |
| | | 'owner_request_special = no' |
| | | ); |
| | | |
| | | //* Create the header and body check files |
| | |
| | | touch($config_dir.'/mime_header_checks'); |
| | | touch($config_dir.'/nested_header_checks'); |
| | | touch($config_dir.'/body_checks'); |
| | | |
| | | |
| | | //* Create the mailman files |
| | | exec('mkdir -p /var/lib/mailman/data'); |
| | | touch('/var/lib/mailman/data/aliases'); |
| | | exec('postmap /var/lib/mailman/data/aliases'); |
| | | touch('/var/lib/mailman/data/virtual-mailman'); |
| | | exec('postmap /var/lib/mailman/data/virtual-mailman'); |
| | | |
| | | //* Make a backup copy of the main.cf file |
| | | copy($config_dir.'/main.cf', $config_dir.'/main.cf~'); |
| | |
| | | if(!stristr($options,'dont-create-certs')) { |
| | | //* Create the SSL certificate |
| | | $command = 'cd '.$config_dir.'; ' |
| | | .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509'; |
| | | .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509'; |
| | | exec($command); |
| | | |
| | | $command = 'chmod o= '.$config_dir.'/smtpd.key'; |
| | |
| | | |
| | | |
| | | // Recursively create the spool directory |
| | | mkdir('/var/spool/postfix/var/run/saslauthd', 0755, true); |
| | | if(!@is_dir('/var/spool/postfix/var/run/saslauthd')) mkdir('/var/spool/postfix/var/run/saslauthd', 0755, true); |
| | | |
| | | // Edit the file /etc/default/saslauthd |
| | | $configfile = $conf['saslauthd']['config']; |
| | |
| | | $config_dir = $conf['dovecot']['config_dir']; |
| | | |
| | | //* Configure master.cf and add a line for deliver |
| | | if(is_file($config_dir.'/master.cf')) { |
| | | copy($config_dir.'/master.cf', $config_dir.'/master.cf~2'); |
| | | if(is_file($conf['postfix']['config_dir'].'/master.cf')) { |
| | | copy($conf['postfix']['config_dir'].'/master.cf', $conf['postfix']['config_dir'].'/master.cf~2'); |
| | | } |
| | | if(is_file($config_dir.'/master.cf~')) { |
| | | chmod($config_dir.'/master.cf~2', 0400); |
| | | if(is_file($conf['postfix']['config_dir'].'/master.cf~')) { |
| | | chmod($conf['postfix']['config_dir'].'/master.cf~2', 0400); |
| | | } |
| | | $content = rf($conf['postfix']['config_dir'].'/master.cf'); |
| | | // Only add the content if we had not addded it before |
| | |
| | | |
| | | $config_dir = $conf['getmail']['config_dir']; |
| | | |
| | | if(!is_dir($config_dir)) mkdir(escapeshellcmd($config_dir), 0700, true); |
| | | if(!@is_dir($config_dir)) mkdir(escapeshellcmd($config_dir), 0700, true); |
| | | |
| | | $command = 'useradd -d '.$config_dir.' getmail'; |
| | | if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
| | |
| | | |
| | | //* Create the slave subdirectory |
| | | $content .= 'slave'; |
| | | mkdir($content, 0770, true); |
| | | if(!@is_dir($content)) mkdir($content, 0770, true); |
| | | |
| | | //* Chown the slave subdirectory to $conf['bind']['bind_user'] |
| | | chown($content, $conf['bind']['bind_user']); |
| | |
| | | global $conf; |
| | | |
| | | //* Create the logging directory for the vhost logfiles |
| | | mkdir($conf['ispconfig_log_dir'].'/httpd', 0755, true); |
| | | 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); |
| | |
| | | // copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf'); |
| | | |
| | | $content = rf('tpl/apache_ispconfig.conf.master'); |
| | | $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'"); |
| | | $records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.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"; |
| | |
| | | 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"); |
| | | |
| | | } |
| | | |
| | | public function configure_nginx() |
| | | { |
| | | global $conf; |
| | | $row = $this->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$conf["server_id"].""); |
| | | $ip_address = gethostbyname($row["server_name"]); |
| | | $server_name = $row["server_name"]; |
| | | |
| | | //setup proxy.conf |
| | | $configfile = 'proxy.conf'; |
| | | if(is_file($conf["nginx"]["config_dir"].'/'.$configfile)) copy($conf["nginx"]["config_dir"].'/'.$configfile,$conf["nginx"]["config_dir"].'/'.$configfile.'~'); |
| | | if(is_file($conf["nginx"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["nginx"]["config_dir"].'/'.$configfile.'~'); |
| | | $content = rf("tpl/nginx_".$configfile.".master"); |
| | | wf($conf["nginx"]["config_dir"].'/'.$configfile,$content); |
| | | exec('chmod 600 '.$conf["nginx"]["config_dir"].'/'.$configfile); |
| | | exec('chown root:root '.$conf["nginx"]["config_dir"].'/'.$configfile); |
| | | |
| | | //setup conf.d/cache.conf |
| | | $configfile = 'cache.conf'; |
| | | if(is_file($conf["nginx"]["config_dir"].'/conf.d/'.$configfile)) copy($conf["nginx"]["config_dir"].'/conf.d/'.$configfile,$conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~'); |
| | | if(is_file($conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~')) exec('chmod 400 '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~'); |
| | | $content = rf("tpl/nginx_".$configfile.".master"); |
| | | wf($conf["nginx"]["config_dir"].'/conf.d/'.$configfile,$content); |
| | | exec('chmod 600 '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile); |
| | | exec('chown root:root '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile); |
| | | |
| | | //setup cache directories |
| | | mkdir('/var/cache/nginx/cache'); |
| | | exec('chown www-data:www-data /var/cache/nginx/cache'); |
| | | mkdir('/var/cache/nginx/temp'); |
| | | exec('chown www-data:www-data /var/cache/nginx/temp'); |
| | | } |
| | | |
| | | public function configure_squid() |
| | | { |
| | | global $conf; |
| | | $row = $this->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$conf["server_id"].""); |
| | | $ip_address = gethostbyname($row["server_name"]); |
| | | $server_name = $row["server_name"]; |
| | | |
| | | $configfile = 'squid.conf'; |
| | | if(is_file($conf["squid"]["config_dir"].'/'.$configfile)) copy($conf["squid"]["config_dir"].'/'.$configfile,$conf["squid"]["config_dir"].'/'.$configfile.'~'); |
| | | if(is_file($conf["squid"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["squid"]["config_dir"].'/'.$configfile.'~'); |
| | | $content = rf("tpl/".$configfile.".master"); |
| | | $content = str_replace('{server_name}',$server_name,$content); |
| | | $content = str_replace('{ip_address}',$ip_address, $content); |
| | | $content = str_replace('{config_dir}',$conf['squid']['config_dir'], $content); |
| | | wf($conf["squid"]["config_dir"].'/'.$configfile,$content); |
| | | exec('chmod 600 '.$conf["squid"]["config_dir"].'/'.$configfile); |
| | | exec('chown root:root '.$conf["squid"]["config_dir"].'/'.$configfile); |
| | | } |
| | | |
| | | public function configure_ufw_firewall() |
| | | { |
| | | $configfile = 'ufw.conf'; |
| | | if(is_file('/etc/ufw/ufw.conf')) copy('/etc/ufw/ufw.conf','/etc/ufw/ufw.conf~'); |
| | | $content = rf("tpl/".$configfile.".master"); |
| | | wf('/etc/ufw/ufw.conf',$content); |
| | | exec('chmod 600 /etc/ufw/ufw.conf'); |
| | | exec('chown root:root /etc/ufw/ufw.conf'); |
| | | } |
| | | |
| | | public function configure_firewall() { |
| | |
| | | $tcp_public_services = ''; |
| | | $udp_public_services = ''; |
| | | |
| | | $row = $this->db->queryOneRecord('SELECT * FROM firewall WHERE server_id = '.intval($conf['server_id'])); |
| | | $row = $this->db->queryOneRecord('SELECT * FROM '.$conf["mysql"]["database"].'.firewall WHERE server_id = '.intval($conf['server_id'])); |
| | | |
| | | if(trim($row['tcp_port']) != '' || trim($row['udp_port']) != '') { |
| | | $tcp_public_services = trim(str_replace(',',' ',$row['tcp_port'])); |
| | |
| | | $command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group; |
| | | caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
| | | |
| | | mkdir($install_dir, 0755, true); |
| | | if(!@is_dir($install_dir)) mkdir($install_dir, 0755, true); |
| | | chown($install_dir, $apps_vhost_user); |
| | | chgrp($install_dir, $apps_vhost_group); |
| | | |
| | |
| | | $ssl_csr_file = $install_dir.'/interface/ssl/ispserver.csr'; |
| | | $ssl_key_file = $install_dir.'/interface/ssl/ispserver.key'; |
| | | |
| | | if(!is_dir($install_dir.'/interface/ssl')) mkdir($install_dir.'/interface/ssl', 0755, true); |
| | | if(!@is_dir($install_dir.'/interface/ssl')) mkdir($install_dir.'/interface/ssl', 0755, true); |
| | | |
| | | $ssl_pw = substr(md5(mt_rand()),0,6); |
| | | exec("openssl genrsa -des3 -passout pass:$ssl_pw -out $ssl_key_file 4096"); |
| | |
| | | $file_server_enabled = ($conf['services']['file'])?1:0; |
| | | $db_server_enabled = ($conf['services']['db'])?1:0; |
| | | $vserver_server_enabled = ($conf['services']['vserver'])?1:0; |
| | | $proxy_server_enabled = ($conf['services']['proxy'])?1:0; |
| | | $firewall_server_enabled = ($conf['services']['firewall'])?1:0; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | $sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']); |
| | | $sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled', proxy_server = '$proxy_server_enabled', firewall_server = '$firewall_server_enabled' WHERE server_id = ".intval($conf['server_id']); |
| | | |
| | | if($conf['mysql']['master_slave_setup'] == 'y') { |
| | | $this->dbmaster->query($sql); |
| | |
| | | } |
| | | |
| | | $root_cron_jobs = array( |
| | | "* * * * * $install_dir/server/server.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log", |
| | | "30 00 * * * $install_dir/server/cron_daily.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log" |
| | | "* * * * * ".$install_dir."/server/server.sh > /dev/null 2>> ".$conf['ispconfig_log_dir']."/cron.log", |
| | | "30 00 * * * ".$install_dir."/server/cron_daily.sh > /dev/null 2>> ".$conf['ispconfig_log_dir']."/cron.log" |
| | | ); |
| | | foreach($root_cron_jobs as $cron_job) { |
| | | if(!in_array($cron_job."\n", $existing_root_cron_jobs)) { |
| | |
| | | $existing_cron_jobs = file('crontab.txt'); |
| | | |
| | | $cron_jobs = array( |
| | | '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log' |
| | | '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> '.$conf['ispconfig_log_dir'].'/cron.log' |
| | | ); |
| | | |
| | | // remove existing ispconfig cronjobs, in case the syntax has changed |
| | |
| | | } |
| | | } |
| | | |
| | | ?> |
| | | ?> |