+
\ No newline at end of file
diff --git a/interface/web/sites/templates/web_vhost_subdomain_list.htm b/interface/web/sites/templates/web_vhost_subdomain_list.htm
new file mode 100644
index 0000000000000000000000000000000000000000..f21698899839af4acb93ec0c2c71a36ac879223f
--- /dev/null
+++ b/interface/web/sites/templates/web_vhost_subdomain_list.htm
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 99e6670fe84e42bee34ea21e572277ab76f238a2..f972b0db1956a545f427f24e14656b839947e591 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -768,7 +768,7 @@ class page_action extends tform_actions {
//* If the domain name has been changed, we will have to change all subdomains
if(!empty($this->dataRecord["domain"]) && !empty($this->oldDataRecord["domain"]) && $this->dataRecord["domain"] != $this->oldDataRecord["domain"]) {
- $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE type = 'subdomain' AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'");
+ $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain') AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'");
foreach($records as $rec) {
$subdomain = $app->db->quote(str_replace($this->oldDataRecord["domain"],$this->dataRecord["domain"],$rec['domain']));
$app->db->datalogUpdate('web_domain', "domain = '".$subdomain."'", 'domain_id', $rec['domain_id']);
diff --git a/interface/web/sites/web_domain_list.php b/interface/web/sites/web_domain_list.php
index 16cac5a46b434af51c775c4a54f9dd7b4529f491..feae9c88966212593bfe027a3ded097416eba30e 100644
--- a/interface/web/sites/web_domain_list.php
+++ b/interface/web/sites/web_domain_list.php
@@ -52,7 +52,7 @@ class list_action extends listform_actions {
}
$list = new list_action;
-$list->SQLExtWhere = "type = 'vhost'";
+$list->SQLExtWhere = "type = 'vhost' AND parent_domain_id = '0'";
$list->SQLOrderBy = 'ORDER BY domain';
$list->onLoad();
diff --git a/interface/web/sites/web_subdomain_edit.php b/interface/web/sites/web_subdomain_edit.php
index e2902816bfaeb0e49145a992de0efacc0ec0eda3..0f2e6f14dcd9373fb1abe844a27bc8eccb2e51e8 100644
--- a/interface/web/sites/web_subdomain_edit.php
+++ b/interface/web/sites/web_subdomain_edit.php
@@ -57,10 +57,10 @@ class page_action extends tform_actions {
// we will check only users, not admins
if($_SESSION["s"]["user"]["typ"] == 'user') {
- if(!$app->tform->checkClientLimit('limit_web_subdomain',"type = 'subdomain'")) {
+ if(!$app->tform->checkClientLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) {
$app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
}
- if(!$app->tform->checkResellerLimit('limit_web_subdomain',"type = 'subdomain'")) {
+ if(!$app->tform->checkResellerLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) {
$app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]);
}
}
diff --git a/interface/web/sites/web_vhost_subdomain_del.php b/interface/web/sites/web_vhost_subdomain_del.php
new file mode 100644
index 0000000000000000000000000000000000000000..4f6948a701335ffb6b1c835b6af6109e0bda527a
--- /dev/null
+++ b/interface/web/sites/web_vhost_subdomain_del.php
@@ -0,0 +1,72 @@
+auth->check_module_permissions('sites');
+
+$app->uses('tpl,tform,tform_actions');
+$app->load("tform_actions");
+class page_action extends tform_actions {
+
+ function onBeforeDelete() {
+ global $app; $conf;
+
+ //* Delete all web folders
+ $records = $app->db->queryAllRecords("SELECT web_folder_id FROM web_folder WHERE parent_domain_id = '".intval($this->id)."'");
+ foreach($records as $rec) {
+ //* Delete all web folder users
+ $records2 = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = '".$rec['web_folder_id']."'");
+ foreach($records2 as $rec2) {
+ $app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec2['web_folder_user_id']);
+ }
+ $app->db->datalogDelete('web_folder','web_folder_id',$rec['web_folder_id']);
+ }
+
+ }
+}
+
+$page = new page_action;
+$page->onDelete();
+
+?>
\ No newline at end of file
diff --git a/interface/web/sites/web_vhost_subdomain_edit.php b/interface/web/sites/web_vhost_subdomain_edit.php
new file mode 100644
index 0000000000000000000000000000000000000000..afe8c38cb772cc3d931c8ee420937b0458f98ffc
--- /dev/null
+++ b/interface/web/sites/web_vhost_subdomain_edit.php
@@ -0,0 +1,456 @@
+auth->check_module_permissions('sites');
+
+// Loading classes
+$app->uses('tpl,tform,tform_actions');
+$app->load('tform_actions');
+
+class page_action extends tform_actions {
+
+ //* Returna a "3/2/1" path hash from a numeric id '123'
+ function id_hash($id,$levels) {
+ $hash = "" . $id % 10 ;
+ $id /= 10 ;
+ $levels -- ;
+ while ( $levels > 0 ) {
+ $hash .= "/" . $id % 10 ;
+ $id /= 10 ;
+ $levels-- ;
+ }
+ return $hash;
+ }
+
+ function onShowNew() {
+ global $app, $conf;
+
+ // we will check only users, not admins
+ if($_SESSION["s"]["user"]["typ"] == 'user') {
+ if(!$app->tform->checkClientLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) {
+ $app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
+ }
+ if(!$app->tform->checkResellerLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) {
+ $app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]);
+ }
+ }
+ parent::onShowNew();
+ }
+
+ function onShowEnd() {
+ global $app, $conf;
+
+ $app->uses('ini_parser,getconf');
+
+ $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl');
+
+ $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
+
+ //* Client: If the logged in user is not admin and has no sub clients (no reseller)
+ if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
+
+ // Get the limits of the client
+ $client_group_id = $_SESSION["s"]["user"]["default_group"];
+ $client = $app->db->queryOneRecord("SELECT client.limit_web_domain, client.default_webserver, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+
+ //* Get global web config
+ $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web');
+
+ //PHP Version Selection (FastCGI)
+ $server_type = 'apache';
+ if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
+ if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_records = $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 = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")");
+ }
+ if($this->dataRecord['php'] == 'fast-cgi'){
+ $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")");
+ }
+ $php_select = "";
+ if(is_array($php_records) && !empty($php_records)) {
+ foreach( $php_records as $php_record) {
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
+ } else {
+ $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
+ }
+ $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
+ $php_select .= "\r\n";
+ }
+ }
+ $app->tpl->setVar("fastcgi_php_version",$php_select);
+ unset($php_records);
+
+ // add limits to template to be able to hide settings
+ foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
+
+
+ //* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
+ } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
+
+ // Get the limits of the client
+ $client_group_id = $_SESSION["s"]["user"]["default_group"];
+ $client = $app->db->queryOneRecord("SELECT client.client_id, client.limit_web_domain, client.default_webserver, client.contact_name, CONCAT(client.company_name,' :: ',client.contact_name) as contactname, sys_group.name, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+
+ //* Get global web config
+ $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web');
+
+ //PHP Version Selection (FastCGI)
+ $server_type = 'apache';
+ if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
+ if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_records = $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 = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")");
+ }
+ if($this->dataRecord['php'] == 'fast-cgi') {
+ $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")");
+ }
+ $php_select = "";
+ if(is_array($php_records) && !empty($php_records)) {
+ foreach( $php_records as $php_record) {
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
+ } else {
+ $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
+ }
+ $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
+ $php_select .= "\r\n";
+ }
+ }
+ $app->tpl->setVar("fastcgi_php_version",$php_select);
+ unset($php_records);
+
+ // add limits to template to be able to hide settings
+ foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
+
+
+ //* Admin: If the logged in user is admin
+ } else {
+
+ //* get global web config
+ $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web');
+
+ //PHP Version Selection (FastCGI)
+ $server_type = 'apache';
+ if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
+ if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_records = $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 = " . $parent_domain['server_id']);
+ }
+ if($this->dataRecord['php'] == 'fast-cgi') {
+ $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = " . $parent_domain['server_id']);
+ }
+ $php_select = "";
+ if(is_array($php_records) && !empty($php_records)) {
+ foreach( $php_records as $php_record) {
+ if($this->dataRecord['php'] == 'php-fpm'){
+ $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
+ } else {
+ $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
+ }
+ $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
+ $php_select .= "\r\n";
+ }
+ }
+ $app->tpl->setVar("fastcgi_php_version",$php_select);
+ unset($php_records);
+
+ foreach($read_limits as $limit) $app->tpl->setVar($limit, 'y');
+ }
+
+ $ssl_domain_select = '';
+ $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = ".$this->id);
+ $ssl_domains = array($tmp["domain"],'www.'.$tmp["domain"]);
+ if(is_array($ssl_domains)) {
+ foreach( $ssl_domains as $ssl_domain) {
+ $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':'';
+ $ssl_domain_select .= "\r\n";
+ }
+ }
+
+ if($this->id > 0) $app->tpl->setVar('fixed_folder', 'y');
+ else $app->tpl->setVar('fixed_folder', 'n');
+
+ $app->tpl->setVar("ssl_domain",$ssl_domain_select);
+ unset($ssl_domain_select);
+ unset($ssl_domains);
+ unset($ssl_domain);
+
+ $tmp_txt = ($this->dataRecord['traffic_quota_lock'] == 'y')?'('.$app->tform->lng('traffic_quota_exceeded_txt').')':'';
+ $app->tpl->setVar("traffic_quota_exceeded_txt", $tmp_txt);
+
+ // remove the parent domain part of the domain name before we show it in the text field.
+ $this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"],'',$this->dataRecord["domain"]);
+ $app->tpl->setVar("domain",$this->dataRecord["domain"]);
+
+ parent::onShowEnd();
+ }
+
+ function onSubmit() {
+ global $app, $conf;
+
+ // Get the record of the parent domain
+ $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
+
+ // Set a few fixed values
+ $this->dataRecord["type"] = 'vhostsubdomain';
+ $this->dataRecord["server_id"] = $parent_domain["server_id"];
+ $this->dataRecord["ip_address"] = $parent_domain["ip_address"];
+ $this->dataRecord["ipv6_address"] = $parent_domain["ipv6_address"];
+ $this->dataRecord["client_group_id"] = $parent_domain["client_group_id"];
+ $this->dataRecord["vhost_type"] = 'name';
+ $this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
+
+ $this->parent_domain_record = $parent_domain;
+
+ $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl');
+
+
+ if($_SESSION["s"]["user"]["typ"] != 'admin') {
+ // Get the limits of the client
+ $client_group_id = $_SESSION["s"]["user"]["default_group"];
+ $client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, parent_client_id, limit_web_quota, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+
+ if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = '-';
+ if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = '-';
+ if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = '-';
+ if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = '-';
+ if($client['limit_python'] != 'y') $this->dataRecord['python'] = '-';
+ if($client['force_suexec'] != 'n') $this->dataRecord['suexec'] = '-';
+ if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = '-';
+ if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = '-';
+ if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = '-';
+
+ //* Check the website quota of the client
+ if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0) {
+ $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+ $webquota = $tmp["webquota"];
+ $new_web_quota = intval($this->dataRecord["hd_quota"]);
+ if(($webquota + $new_web_quota > $client["limit_web_quota"]) || ($new_web_quota < 0 && $client["limit_web_quota"] >= 0)) {
+ $max_free_quota = floor($client["limit_web_quota"] - $webquota);
+ if($max_free_quota < 0) $max_free_quota = 0;
+ $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB ";
+ // Set the quota field to the max free space
+ $this->dataRecord["hd_quota"] = $max_free_quota;
+ }
+ unset($tmp);
+ unset($tmp_quota);
+ }
+
+ //* Check the traffic quota of the client
+ if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0) {
+ $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+ $trafficquota = $tmp["trafficquota"];
+ $new_traffic_quota = intval($this->dataRecord["traffic_quota"]);
+ if(($trafficquota + $new_traffic_quota > $client["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $client["limit_traffic_quota"] >= 0)) {
+ $max_free_quota = floor($client["limit_traffic_quota"] - $trafficquota);
+ if($max_free_quota < 0) $max_free_quota = 0;
+ $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB ";
+ // Set the quota field to the max free space
+ $this->dataRecord["traffic_quota"] = $max_free_quota;
+ }
+ unset($tmp);
+ unset($tmp_quota);
+ }
+
+ if($client['parent_client_id'] > 0) {
+ // Get the limits of the reseller
+ $reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, limit_web_quota FROM client WHERE client_id = ".$client['parent_client_id']);
+
+ //* Check the website quota of the client
+ if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0) {
+ $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+ $webquota = $tmp["webquota"];
+ $new_web_quota = intval($this->dataRecord["hd_quota"]);
+ if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
+ $max_free_quota = floor($reseller["limit_web_quota"] - $webquota);
+ if($max_free_quota < 0) $max_free_quota = 0;
+ $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB ";
+ // Set the quota field to the max free space
+ $this->dataRecord["hd_quota"] = $max_free_quota;
+ }
+ unset($tmp);
+ unset($tmp_quota);
+ }
+
+ //* Check the traffic quota of the client
+ if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0) {
+ $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+ $trafficquota = $tmp["trafficquota"];
+ $new_traffic_quota = intval($this->dataRecord["traffic_quota"]);
+ if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {
+ $max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota);
+ if($max_free_quota < 0) $max_free_quota = 0;
+ $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB ";
+ // Set the quota field to the max free space
+ $this->dataRecord["traffic_quota"] = $max_free_quota;
+ }
+ unset($tmp);
+ unset($tmp_quota);
+ }
+ }
+
+ // When the record is updated
+ if($this->id > 0) {
+ // restore the server ID if the user is not admin and record is edited
+ $tmp = $app->db->queryOneRecord("SELECT server_id, `web_folder`, `cgi`, `ssi`, `perl`, `ruby`, `python`, `suexec`, `errordocs`, `subdomain`, `ssl` FROM web_domain WHERE domain_id = ".intval($this->id));
+ $this->dataRecord['web_folder'] = $tmp['web_folder']; // cannot be changed!
+
+ // set the settings to current if not provided (or cleared due to limits)
+ if($this->dataRecord['cgi'] == '-') $this->dataRecord['cgi'] = $tmp['cgi'];
+ if($this->dataRecord['ssi'] == '-') $this->dataRecord['ssi'] = $tmp['ssi'];
+ if($this->dataRecord['perl'] == '-') $this->dataRecord['perl'] = $tmp['perl'];
+ if($this->dataRecord['ruby'] == '-') $this->dataRecord['ruby'] = $tmp['ruby'];
+ if($this->dataRecord['python'] == '-') $this->dataRecord['python'] = $tmp['python'];
+ if($this->dataRecord['suexec'] == '-') $this->dataRecord['suexec'] = $tmp['suexec'];
+ if($this->dataRecord['errordocs'] == '-') $this->dataRecord['errordocs'] = $tmp['errordocs'];
+ if($this->dataRecord['subdomain'] == '-') $this->dataRecord['subdomain'] = $tmp['subdomain'];
+ if($this->dataRecord['ssl'] == '-') $this->dataRecord['ssl'] = $tmp['ssl'];
+
+ unset($tmp);
+ // When the record is inserted
+ } else {
+ // Check if the user may add another web_domain
+ if($client["limit_web_subdomain"] >= 0) {
+ $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and (type = 'subdomain' OR type = 'vhostsubdomain')");
+ if($tmp["number"] >= $client["limit_web_subdomain"]) {
+ $app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
+ }
+ }
+ }
+ }
+
+ //* make sure that the domain is lowercase
+ if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
+
+ //* get the server config for this server
+ $app->uses("getconf");
+ $web_config = $app->getconf->get_server_config(intval(isset($this->dataRecord["server_id"]) ? $this->dataRecord["server_id"] : 0),'web');
+ //* Check for duplicate ssl certs per IP if SNI is disabled
+ if(isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y' && $web_config['enable_sni'] != 'y') {
+ $sql = "SELECT count(domain_id) as number FROM web_domain WHERE `ssl` = 'y' AND ip_address = '".$app->db->quote($this->dataRecord['ip_address'])."' and domain_id != ".$this->id;
+ $tmp = $app->db->queryOneRecord($sql);
+ if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("error_no_sni_txt");
+ }
+
+ // Check if pm.max_children >= pm.max_spare_servers >= pm.start_servers >= pm.min_spare_servers > 0
+ if(isset($this->dataRecord['pm_max_children']) && $this->dataRecord['pm'] == 'dynamic') {
+ if(intval($this->dataRecord['pm_max_children']) >= intval($this->dataRecord['pm_max_spare_servers']) && intval($this->dataRecord['pm_max_spare_servers']) >= intval($this->dataRecord['pm_start_servers']) && intval($this->dataRecord['pm_start_servers']) >= intval($this->dataRecord['pm_min_spare_servers']) && intval($this->dataRecord['pm_min_spare_servers']) > 0){
+
+ } else {
+ $app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").' ';
+ }
+ }
+
+ parent::onSubmit();
+ }
+
+ function onAfterInsert() {
+ global $app, $conf;
+
+ // Get configuration for the web system
+ $app->uses("getconf");
+ $web_rec = $app->tform->getDataRecord($this->id);
+ $web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
+ var_dump($this->parent_domain_record, $web_rec);
+ // Set the values for document_root, system_user and system_group
+ $system_user = $app->db->quote($this->parent_domain_record['system_user']);
+ $system_group = $app->db->quote($this->parent_domain_record['system_group']);
+ $document_root = $app->db->quote($this->parent_domain_record['document_root']);
+ $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]);
+ $php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir);
+ $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir);
+ $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
+ $htaccess_allow_override = $app->db->quote($this->parent_domain_record['allow_override']);
+
+ $sql = "UPDATE web_domain SET sys_groupid = ".intval($this->parent_domain_record['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
+ $app->db->query($sql);
+ }
+
+ function onBeforeUpdate () {
+ global $app, $conf;
+
+ //* Check that all fields for the SSL cert creation are filled
+ if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') {
+ if($this->dataRecord['ssl_state'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_state_empty').' ';
+ if($this->dataRecord['ssl_locality'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_locality_empty').' ';
+ if($this->dataRecord['ssl_organisation'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_empty').' ';
+ if($this->dataRecord['ssl_organisation_unit'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_unit_empty').' ';
+ if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').' ';
+ }
+
+ if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') {
+ if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').' ';
+ }
+
+ }
+
+ function onAfterUpdate() {
+ global $app, $conf;
+
+ // Get configuration for the web system
+ $app->uses("getconf");
+ $web_rec = $app->tform->getDataRecord($this->id);
+ $web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
+
+ // Set the values for document_root, system_user and system_group
+ $system_user = $app->db->quote($this->parent_domain_record['system_user']);
+ $system_group = $app->db->quote($this->parent_domain_record['system_group']);
+ $document_root = $app->db->quote($this->parent_domain_record['document_root']);
+ $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]);
+ $php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir);
+ $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir);
+ $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
+ $htaccess_allow_override = $app->db->quote($this->parent_domain_record['allow_override']);
+
+ $sql = "UPDATE web_domain SET sys_groupid = ".intval($this->parent_domain_record['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
+ $app->db->query($sql);
+ }
+
+}
+
+$page = new page_action;
+$page->onLoad();
+
+?>
\ No newline at end of file
diff --git a/interface/web/sites/web_vhost_subdomain_list.php b/interface/web/sites/web_vhost_subdomain_list.php
new file mode 100644
index 0000000000000000000000000000000000000000..8c483399f9ae2abebe2baceb30052c812a056fff
--- /dev/null
+++ b/interface/web/sites/web_vhost_subdomain_list.php
@@ -0,0 +1,55 @@
+auth->check_module_permissions('sites');
+
+$app->uses('listform_actions');
+
+// Limit the results to alias domains
+$app->listform_actions->SQLExtWhere = "type = 'vhostsubdomain'";
+$app->listform_actions->SQLOrderBy = 'ORDER BY domain';
+$app->listform_actions->onLoad();
+
+
+?>
\ No newline at end of file
diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master
index 6c9513a567e4efbbe16fd44d1e84f87c67af3ebf..7e9df0ec974bd87e2d19d8d27c4e757d8165822d 100644
--- a/server/conf/vhost.conf.master
+++ b/server/conf/vhost.conf.master
@@ -114,11 +114,13 @@
PerlModule ModPerl::Registry
PerlModule Apache2::Reload
- SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
+
+ SetHandler perl-script
+
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index ad2abcc3108701f4f839a6e9106597216bd23344..a861265a922488d8e101e80deff51fc6964c5890 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -103,7 +103,7 @@ class apache2_plugin {
$app->log("CA path error, file does not exist:".$web_config['CA_path'].'/openssl.conf',LOGLEVEL_ERROR);
//* Only vhosts can have a ssl cert
- if($data["new"]["type"] != "vhost") return;
+ if($data["new"]["type"] != "vhost" && $data["new"]["type"] != "vhostsubdomain") return;
// if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl');
if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
@@ -279,7 +279,7 @@ class apache2_plugin {
if($this->action != 'insert') $this->action = 'update';
- if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) {
+ if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) {
$old_parent_domain_id = intval($data['old']['parent_domain_id']);
$new_parent_domain_id = intval($data['new']['parent_domain_id']);
@@ -325,6 +325,13 @@ class apache2_plugin {
return 0;
}
+ $web_folder = 'web';
+ $log_folder = 'log';
+ if($data['new']['type'] == 'vhostsubdomain') {
+ $web_folder = $data['new']['web_folder'];
+ $log_folder .= '_web' . $data['new']['domain_id'];
+ }
+
// Create group and user, if not exist
$app->uses('system');
@@ -437,9 +444,9 @@ class apache2_plugin {
// Check if the directories are there and create them if necessary.
$app->system->web_folder_protection($data['new']['document_root'],false);
- if(!is_dir($data['new']['document_root'].'/web')) $app->system->mkdirpath($data['new']['document_root'].'/web');
- if(!is_dir($data['new']['document_root'].'/web/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/web/error');
- //if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log');
+ if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
+ if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error');
+ //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder);
if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
if(!is_dir($data['new']['document_root'].'/tmp')) $app->system->mkdirpath($data['new']['document_root'].'/tmp');
@@ -457,19 +464,20 @@ class apache2_plugin {
// Remove the symlink for the site, if site is renamed
if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) {
if(is_dir('/var/log/ispconfig/httpd/'.$data['old']['domain'])) exec('rm -rf /var/log/ispconfig/httpd/'.$data['old']['domain']);
- if(is_link($data['old']['document_root'].'/log')) $app->system->unlink($data['old']['document_root'].'/log');
+ if(is_link($data['old']['document_root'].'/'.$log_folder)) $app->system->unlink($data['old']['document_root'].'/'.$log_folder);
}
//* Create the log dir if nescessary and mount it
- if(!is_dir($data['new']['document_root'].'/log') || is_link($data['new']['document_root'].'/log')) {
- if(is_link($data['new']['document_root'].'/log')) unlink($data['new']['document_root'].'/log');
- $app->system->mkdir($data['new']['document_root'].'/log');
- $app->system->chown($data['new']['document_root'].'/log','root');
- $app->system->chgrp($data['new']['document_root'].'/log','root');
- $app->system->chmod($data['new']['document_root'].'/log',0755);
- exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/log'));
+ if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']);
+ if(!is_dir($data['new']['document_root'].'/'.$log_folder) || is_link($data['new']['document_root'].'/'.$log_folder)) {
+ if(is_link($data['new']['document_root'].'/'.$log_folder)) unlink($data['new']['document_root'].'/'.$log_folder);
+ $app->system->mkdir($data['new']['document_root'].'/'.$log_folder);
+ $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root');
+ $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,'root');
+ $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755);
+ exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/'.$log_folder));
//* add mountpoint to fstab
- $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/log none bind 0 0';
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind 0 0';
$app->system->replaceLine('/etc/fstab',$fstab_line,$fstab_line,1,1);
}
@@ -532,11 +540,11 @@ class apache2_plugin {
// setting a local var here
// normally $conf['templates'] = "/usr/local/ispconfig/server/conf";
-
- if($this->action == 'insert' && $data['new']['type'] == 'vhost') {
- // Copy the error pages
+ if($this->action == 'insert' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) {
+
+ // Copy the error pages
if($data['new']['errordocs']) {
- $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/';
+ $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/';
if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) {
exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
}
@@ -552,35 +560,35 @@ class apache2_plugin {
}
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2))) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
}
else {
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
}
else {
- exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
- if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/');
- if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/');
- if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
+ if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
+ if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
+ if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
}
- exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
//** Copy the error documents on update when the error document checkbox has been activated and was deactivated before
- } elseif ($this->action == 'update' && $data['new']['type'] == 'vhost' && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) {
-
- $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/';
+ } elseif ($this->action == 'update' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain') && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) {
+
+ $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/';
if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) {
exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
}
@@ -610,12 +618,12 @@ class apache2_plugin {
if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) {
// Chown and chmod the directories below the document root
- $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
// The document root itself has to be owned by root in normal level and by the web owner in security level 20
if($web_config['security_level'] == 20) {
- $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
} else {
- $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
}
}
@@ -639,8 +647,8 @@ class apache2_plugin {
$app->system->chmod($data['new']['document_root'].'/tmp',0777);
// Set Log directory to 755 to make the logs accessible by the FTP user
- if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
- $app->system->chmod($data['new']['document_root'].'/log',0755);
+ if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
+ $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755);
}
if($web_config['add_web_users_to_sshusers_group'] == 'y') {
@@ -670,9 +678,9 @@ class apache2_plugin {
$app->system->chgrp($data['new']['document_root'],'root');
$app->system->chown($data['new']['document_root'].'/cgi-bin',$username);
$app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname);
- if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
- $app->system->chown($data['new']['document_root'].'/log','root',false);
- $app->system->chgrp($data['new']['document_root'].'/log',$groupname,false);
+ if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
+ $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root',false);
+ $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,$groupname,false);
}
$app->system->chown($data['new']['document_root'].'/ssl','root');
$app->system->chgrp($data['new']['document_root'].'/ssl','root');
@@ -697,22 +705,25 @@ class apache2_plugin {
$app->system->chmod($data['new']['document_root'].'/webdav',0755);
$app->system->chmod($data['new']['document_root'].'/ssl',0755);
$app->system->chmod($data['new']['document_root'].'/cgi-bin',0755);
- if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
- $app->system->chmod($data['new']['document_root'].'/log',0755);
- }
// make temp directory writable for Apache and the website users
$app->system->chmod($data['new']['document_root'].'/tmp',0777);
+ // Set Log directory to 755 to make the logs accessible by the FTP user
+ if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
+ $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755);
+ }
+
$app->system->chown($data['new']['document_root'],'root');
$app->system->chgrp($data['new']['document_root'],'root');
$app->system->chown($data['new']['document_root'].'/cgi-bin',$username);
$app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname);
- if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
- $app->system->chown($data['new']['document_root'].'/log','root',false);
- $app->system->chgrp($data['new']['document_root'].'/log','root',false);
+ if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
+ $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root',false);
+ $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,$groupname,false);
}
- $app->system->chown($data['new']['document_root'].'/ssl','root');
+
+ $app->system->chown($data['new']['document_root'].'/ssl','root');
$app->system->chgrp($data['new']['document_root'].'/ssl','root');
$app->system->chown($data['new']['document_root'].'/tmp',$username);
$app->system->chgrp($data['new']['document_root'].'/tmp',$groupname);
@@ -725,19 +736,39 @@ class apache2_plugin {
$app->system->chown($data['new']['document_root'].'/webdav',$username);
$app->system->chgrp($data['new']['document_root'].'/webdav',$groupname);
}
- }
+ } elseif(($this->action == 'insert' && $data['new']['type'] == 'vhostsubdomain') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhostsubdomain')) {
+ if($web_config['security_level'] == 20) {
+ $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0710);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname);
+ } else {
+ $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0755);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname);
+ }
+ }
//* Protect web folders
$app->system->web_folder_protection($data['new']['document_root'],true);
- // Change the ownership of the error log to the root user
- if(!@is_file('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')) exec('touch '.escapeshellcmd('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log'));
- $app->system->chown('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root');
- $app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root');
-
+ if($data['new']['type'] == 'vhost') {
+ // Change the ownership of the error log to the root user
+ if(!@is_file('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')) exec('touch '.escapeshellcmd('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log'));
+ $app->system->chown('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root');
+ $app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root');
+ }
//* Write the custom php.ini file, if custom_php_ini fieled is not empty
$custom_php_ini_dir = $web_config['website_basedir'].'/conf/'.$data['new']['system_user'];
+ if($data['new']['type'] == 'vhostsubdomain') $custom_php_ini_dir .= '_' . $web_folder;
if(!is_dir($web_config['website_basedir'].'/conf')) $app->system->mkdir($web_config['website_basedir'].'/conf');
//* add open_basedir restriction to custom php.ini content, required for suphp only
@@ -777,8 +808,8 @@ class apache2_plugin {
$vhost_data = $data['new'];
//unset($vhost_data['ip_address']);
- $vhost_data['web_document_root'] = $data['new']['document_root'].'/web';
- $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/web';
+ $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['security_level'] = $web_config['security_level'];
$vhost_data['allow_override'] = ($data['new']['allow_override'] == '')?'All':$data['new']['allow_override'];
@@ -811,7 +842,7 @@ class apache2_plugin {
if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
- //$vhost_data['document_root'] = $data['new']['document_root'].'/web';
+ //$vhost_data['document_root'] = $data['new']['document_root'].'/' . $web_folder;
// Set SEO Redirect
if($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')){
@@ -889,7 +920,7 @@ class apache2_plugin {
}
// get alias domains (co-domains and subdomains)
- $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y'");
+ $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND type != 'vhostsubdomain'");
switch($data['new']['subdomain']) {
case 'www':
$server_alias[] .= 'www.'.$data['new']['domain'].' ';
@@ -1039,7 +1070,7 @@ class apache2_plugin {
$php_open_basedir = ($data['new']['php_open_basedir'] == '')?$data['new']['document_root']:$data['new']['php_open_basedir'];
$fcgi_tpl->setVar('open_basedir', escapeshellcmd($php_open_basedir));
- $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script']);
+ $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : ''));
$app->system->file_put_contents($fcgi_starter_script,$fcgi_tpl->grab());
unset($fcgi_tpl);
@@ -1051,18 +1082,25 @@ class apache2_plugin {
$tpl->setVar('fastcgi_alias',$fastcgi_config['fastcgi_alias']);
$tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path);
- $tpl->setVar('fastcgi_starter_script',$fastcgi_config['fastcgi_starter_script']);
+ $tpl->setVar('fastcgi_starter_script',$fastcgi_config['fastcgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : ''));
$tpl->setVar('fastcgi_config_syntax',$fastcgi_config['fastcgi_config_syntax']);
} else {
//remove the php fastgi starter script if available
if ($data['old']['php'] == 'fast-cgi') {
- $fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi');
- $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$fastcgi_config['fastcgi_starter_path']);
- $fastcgi_starter_path = str_replace('[client_id]',$client_id,$fastcgi_starter_path);
- if (is_dir($fastcgi_starter_path)) {
- exec('rm -rf '.$fastcgi_starter_path);
- }
+ $fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi');
+ $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$fastcgi_config['fastcgi_starter_path']);
+ $fastcgi_starter_path = str_replace('[client_id]',$client_id,$fastcgi_starter_path);
+ if($data['old']['type'] == 'vhost') {
+ if (is_dir($fastcgi_starter_path)) {
+ exec('rm -rf '.$fastcgi_starter_path);
+ }
+ } else {
+ $fcgi_starter_script = $fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script'].'_web' . $data['old']['domain_id'];
+ if (file_exists($fcgi_starter_script)) {
+ exec('rm -f '.$fcgi_starter_script);
+ }
+ }
}
}
@@ -1122,7 +1160,7 @@ class apache2_plugin {
//$cgi_config = $app->getconf->get_server_config($conf['server_id'], 'cgi');
$cgi_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/';
- $cgi_config['cgi_starter_script'] = 'php-cgi-starter';
+ $cgi_config['cgi_starter_script'] = 'php-cgi-starter'.($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : '');
$cgi_config['cgi_bin'] = '/usr/bin/php-cgi';
$cgi_starter_path = str_replace('[system_user]',$data['new']['system_user'],$cgi_config['cgi_starter_path']);
@@ -1157,7 +1195,7 @@ class apache2_plugin {
$cgi_tpl->setVar('php_ini_path',escapeshellcmd($fastcgi_config['fastcgi_phpini_path']));
}
- $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config['cgi_starter_script']);
+ $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config['cgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : ''));
$app->system->file_put_contents($cgi_starter_script,$cgi_tpl->grab());
unset($cgi_tpl);
@@ -1169,7 +1207,7 @@ class apache2_plugin {
$app->system->chgrp($cgi_starter_script,$data['new']['system_group']);
$tpl->setVar('cgi_starter_path',$cgi_starter_path);
- $tpl->setVar('cgi_starter_script',$cgi_config['cgi_starter_script']);
+ $tpl->setVar('cgi_starter_script',$cgi_config['cgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : ''));
}
@@ -1288,11 +1326,11 @@ class apache2_plugin {
}
//* Create .htaccess and .htpasswd file for website statistics
- if(!is_file($data['new']['document_root'].'/web/stats/.htaccess') or $data['old']['document_root'] != $data['new']['document_root']) {
- if(!is_dir($data['new']['document_root'].'/web/stats')) $app->system->mkdir($data['new']['document_root'].'/web/stats');
+ if(!is_file($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess') or $data['old']['document_root'] != $data['new']['document_root']) {
+ if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdir($data['new']['document_root'].'/' . $web_folder . '/stats');
$ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data['new']['document_root']."/.htpasswd_stats\nrequire valid-user";
- $app->system->file_put_contents($data['new']['document_root'].'/web/stats/.htaccess',$ht_file);
- $app->system->chmod($data['new']['document_root'].'/web/stats/.htaccess',0755);
+ $app->system->file_put_contents($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess',$ht_file);
+ $app->system->chmod($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess',0755);
unset($ht_file);
}
@@ -1308,7 +1346,7 @@ class apache2_plugin {
}
//* Create awstats configuration
- if($data['new']['stats_type'] == 'awstats' && $data['new']['type'] == 'vhost') {
+ if($data['new']['stats_type'] == 'awstats' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) {
$this->awstats_update($data,$web_config);
}
@@ -1419,7 +1457,7 @@ class apache2_plugin {
$apache_chrooted = false;
}
- if($data['old']['type'] != 'vhost' && $data['old']['parent_domain_id'] > 0) {
+ if($data['old']['type'] != 'vhost' && $data['old']['type'] != 'vhostsubdomain' && $data['old']['parent_domain_id'] > 0) {
//* This is a alias domain or subdomain, so we have to update the website instead
$parent_domain_id = intval($data['old']['parent_domain_id']);
$tmp = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$parent_domain_id." AND active = 'y'");
@@ -1452,72 +1490,92 @@ class apache2_plugin {
$app->system->unlink($vhost_file);
$app->log('Removing vhost file: '.$vhost_file,LOGLEVEL_DEBUG);
-
- $docroot = escapeshellcmd($data['old']['document_root']);
- if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot);
-
-
- //remove the php fastgi starter script if available
- if ($data['old']['php'] == 'fast-cgi') {
- $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']);
- if (is_dir($fastcgi_starter_path)) {
- exec('rm -rf '.$fastcgi_starter_path);
- }
- }
+
+ if($data['old']['type'] == 'vhost') {
+ $docroot = escapeshellcmd($data['old']['document_root']);
+ if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot);
- // remove PHP-FPM pool
- if ($data['old']['php'] == 'php-fpm') {
- $this->php_fpm_pool_delete($data,$web_config);
- }
-
- //remove the php cgi starter script if available
- if ($data['old']['php'] == 'cgi') {
- // TODO: fetch the date from the server-settings
- $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/';
-
- $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']);
- if (is_dir($cgi_starter_path)) {
- exec('rm -rf '.$cgi_starter_path);
- }
- }
-
- $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG);
-
- // Delete the symlinks for the sites
- $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid']));
- $client_id = intval($client['client_id']);
- unset($client);
- $tmp_symlinks_array = explode(':',$web_config['website_symlinks']);
- if(is_array($tmp_symlinks_array)) {
- foreach($tmp_symlinks_array as $tmp_symlink) {
- $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink);
- $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink);
- // Remove trailing slash
- if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
- // create the symlinks, if not exist
- if(is_link($tmp_symlink)) {
- $app->system->unlink($tmp_symlink);
- $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG);
- }
- }
- }
- // end removing symlinks
+ //remove the php fastgi starter script if available
+ if ($data['old']['php'] == 'fast-cgi') {
+ $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']);
+ if($data['old']['type'] == 'vhost') {
+ if (is_dir($fastcgi_starter_path)) {
+ exec('rm -rf '.$fastcgi_starter_path);
+ }
+ } else {
+ $fcgi_starter_script = $fastcgi_starter_path.$web_config['fastcgi_starter_script'].'_web'.$data['old']['domain_id'];
+ if (file_exists($fcgi_starter_script)) {
+ exec('rm -f '.$fcgi_starter_script);
+ }
+ }
+ }
+
+ // remove PHP-FPM pool
+ if ($data['old']['php'] == 'php-fpm') {
+ $this->php_fpm_pool_delete($data,$web_config);
+ }
- // Delete the log file directory
- $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']);
- if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir);
- $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG);
+ //remove the php cgi starter script if available
+ if ($data['old']['php'] == 'cgi') {
+ // TODO: fetch the date from the server-settings
+ $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/';
+
+ $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']);
+ if($data['old']['type'] == 'vhost') {
+ if (is_dir($cgi_starter_path)) {
+ exec('rm -rf '.$cgi_starter_path);
+ }
+ } else {
+ $cgi_starter_script = $cgi_starter_path.'php-cgi-starter_web'.$data['old']['domain_id'];
+ if (file_exists($cgi_starter_script)) {
+ exec('rm -f '.$cgi_starter_script);
+ }
+ }
+ }
+
+ $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG);
+
+ // Delete the symlinks for the sites
+ $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid']));
+ $client_id = intval($client['client_id']);
+ unset($client);
+ $tmp_symlinks_array = explode(':',$web_config['website_symlinks']);
+ if(is_array($tmp_symlinks_array)) {
+ foreach($tmp_symlinks_array as $tmp_symlink) {
+ $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink);
+ $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink);
+ // Remove trailing slash
+ if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
+ // create the symlinks, if not exist
+ if(is_link($tmp_symlink)) {
+ $app->system->unlink($tmp_symlink);
+ $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG);
+ }
+ }
+ }
+ // end removing symlinks
+ } else {
+ // vhost subdomain
+ }
- //delete the web user
- $command = 'userdel';
- $command .= ' '.$data['old']['system_user'];
- exec($command);
- if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command);
-
- //* Remove the awstats configuration file
- if($data['old']['stats_type'] == 'awstats') {
- $this->awstats_delete($data,$web_config);
- }
+ // Delete the log file directory
+ $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']);
+ if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir);
+ $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG);
+
+ if($data['old']['type'] == 'vhost') {
+ //delete the web user
+ $command = 'userdel';
+ $command .= ' '.$data['old']['system_user'];
+ exec($command);
+ if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command);
+
+ }
+
+ //* Remove the awstats configuration file
+ if($data['old']['stats_type'] == 'awstats') {
+ $this->awstats_delete($data,$web_config);
+ }
if($apache_chrooted) {
$app->services->restartServiceDelayed('httpd','restart');
@@ -1595,10 +1653,13 @@ class apache2_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1);
if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1);
- $folder_path = escapeshellcmd($website['document_root'].'/web/'.$folder['path']);
+ $folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$folder['path']);
if(substr($folder_path,-1) != '/') $folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -1679,10 +1740,13 @@ class apache2_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1);
if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1);
- $folder_path = realpath($website['document_root'].'/web/'.$folder['path']);
+ $folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$folder['path']);
if(substr($folder_path,-1) != '/') $folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -1715,15 +1779,18 @@ class apache2_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($data['old']['path'],0,1) == '/') $data['old']['path'] = substr($data['old']['path'],1);
if(substr($data['old']['path'],-1) == '/') $data['old']['path'] = substr($data['old']['path'],0,-1);
- $old_folder_path = realpath($website['document_root'].'/web/'.$data['old']['path']);
+ $old_folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$data['old']['path']);
if(substr($old_folder_path,-1) != '/') $old_folder_path .= '/';
if(substr($data['new']['path'],0,1) == '/') $data['new']['path'] = substr($data['new']['path'],1);
if(substr($data['new']['path'],-1) == '/') $data['new']['path'] = substr($data['new']['path'],0,-1);
- $new_folder_path = escapeshellcmd($website['document_root'].'/web/'.$data['new']['path']);
+ $new_folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$data['new']['path']);
if(substr($new_folder_path,-1) != '/') $new_folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -2075,9 +2142,11 @@ class apache2_plugin {
private function awstats_update ($data,$web_config) {
global $app;
+ $web_folder = $data['new']['web_folder'];
+ if($data['new']['type'] == 'vhost') $web_folder = 'web';
$awstats_conf_dir = $web_config['awstats_conf_dir'];
- if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats");
+ if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats");
if(!@is_file($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) {
if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
$app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
@@ -2093,8 +2162,8 @@ class apache2_plugin {
$app->log('Created AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',LOGLEVEL_DEBUG);
}
- if(is_file($data['new']['document_root']."/web/stats/index.html")) $app->system->unlink($data['new']['document_root']."/web/stats/index.html");
- $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/web/stats/index.php");
+ if(is_file($data['new']['document_root']."/" . $web_folder . "/stats/index.html")) $app->system->unlink($data['new']['document_root']."/" . $web_folder . "/stats/index.html");
+ $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/" . $web_folder . "/stats/index.php");
}
//* Delete the awstats configuration file
diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php
index 5050e01ec069dbe53b324a53205c50ac1ab096e4..424d96fa8e9427d46c3f7c60dc871f14927055f2 100644
--- a/server/plugins-available/nginx_plugin.inc.php
+++ b/server/plugins-available/nginx_plugin.inc.php
@@ -91,6 +91,8 @@ class nginx_plugin {
// Handle the creation of SSL certificates
function ssl($event_name,$data) {
global $app, $conf;
+
+ $app->uses('system');
// load the server configuration options
$app->uses('getconf');
@@ -99,9 +101,11 @@ class nginx_plugin {
$app->log("CA path error, file does not exist:".$web_config['CA_path'].'/openssl.conf',LOGLEVEL_ERROR);
//* Only vhosts can have a ssl cert
- if($data["new"]["type"] != "vhost") return;
+ if($data["new"]["type"] != "vhost" && $data["new"]["type"] != "vhostsubdomain") return;
- if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl');
+ // if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl');
+ if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
+
$ssl_dir = $data['new']['document_root'].'/ssl';
$domain = $data['new']['ssl_domain'];
$key_file = $ssl_dir.'/'.$domain.'.key.org';
@@ -119,7 +123,7 @@ class nginx_plugin {
$rand_data .= md5(uniqid(microtime(),1));
$rand_data .= md5(uniqid(microtime(),1));
}
- file_put_contents($rand_file, $rand_data);
+ $app->system->file_put_contents($rand_file, $rand_data);
$ssl_password = substr(md5(uniqid(microtime(),1)), 0, 15);
@@ -134,11 +138,11 @@ class nginx_plugin {
output_password = $ssl_password
[ req_distinguished_name ]
- C = ".$data['new']['ssl_country']."
- ST = ".$data['new']['ssl_state']."
- L = ".$data['new']['ssl_locality']."
- O = ".$data['new']['ssl_organisation']."
- OU = ".$data['new']['ssl_organisation_unit']."
+ C = ".trim($data['new']['ssl_country'])."
+ ST = ".trim($data['new']['ssl_state'])."
+ L = ".trim($data['new']['ssl_locality'])."
+ O = ".trim($data['new']['ssl_organisation'])."
+ OU = ".trim($data['new']['ssl_organisation_unit'])."
CN = $domain
emailAddress = webmaster@".$data['new']['domain']."
@@ -146,7 +150,7 @@ class nginx_plugin {
challengePassword = A challenge password";
$ssl_cnf_file = $ssl_dir.'/openssl.conf';
- file_put_contents($ssl_cnf_file,$ssl_cnf);
+ $app->system->file_put_contents($ssl_cnf_file,$ssl_cnf);
$rand_file = escapeshellcmd($rand_file);
$key_file = escapeshellcmd($key_file);
@@ -156,7 +160,7 @@ class nginx_plugin {
$config_file = escapeshellcmd($ssl_cnf_file);
$crt_file = escapeshellcmd($crt_file);
- if(is_file($ssl_cnf_file)) {
+ if(is_file($ssl_cnf_file) && !is_link($ssl_cnf_file)) {
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 2048");
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file");
@@ -175,16 +179,17 @@ class nginx_plugin {
}
- exec('chmod 400 '.$key_file2);
- @unlink($config_file);
- @unlink($rand_file);
- $ssl_request = $app->db->quote(file_get_contents($csr_file));
- $ssl_cert = $app->db->quote(file_get_contents($crt_file));
+ $app->system->chmod($key_file2,0400);
+ @$app->system->unlink($config_file);
+ @$app->system->unlink($rand_file);
+ $ssl_request = $app->db->quote($app->system->file_get_contents($csr_file));
+ $ssl_cert = $app->db->quote($app->system->file_get_contents($crt_file));
+ $ssl_key2 = $app->db->quote($app->system->file_get_contents($key_file2));
/* Update the DB of the (local) Server */
- $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data['new']['domain']."'");
+ $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert', ssl_key = '$ssl_key2' WHERE domain = '".$data['new']['domain']."'");
$app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'");
/* Update also the master-DB of the Server-Farm */
- $app->dbmaster->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data['new']['domain']."'");
+ $app->dbmaster->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert', ssl_key = '$ssl_key2' WHERE domain = '".$data['new']['domain']."'");
$app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'");
}
@@ -192,6 +197,8 @@ class nginx_plugin {
if($data["new"]["ssl_action"] == 'save') {
$ssl_dir = $data["new"]["document_root"]."/ssl";
$domain = ($data["new"]["ssl_domain"] != '')?$data["new"]["ssl_domain"]:$data["new"]["domain"];
+ $key_file = $ssl_dir.'/'.$domain.'.key.org';
+ $key_file2 = $ssl_dir.'/'.$domain.'.key';
$csr_file = $ssl_dir.'/'.$domain.".csr";
$crt_file = $ssl_dir.'/'.$domain.".crt";
//$bundle_file = $ssl_dir.'/'.$domain.".bundle";
@@ -211,6 +218,7 @@ class nginx_plugin {
}
/* Update the DB of the (local) Server */
$app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'");
+
/* Update also the master-DB of the Server-Farm */
$app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'");
$app->log('Saving SSL Cert for: '.$domain,LOGLEVEL_DEBUG);
@@ -228,9 +236,9 @@ class nginx_plugin {
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke $crt_file");
$app->log("Revoking CA-signed SSL Cert for: $domain",LOGLEVEL_DEBUG);
};
- unlink($csr_file);
- unlink($crt_file);
- //unlink($bundle_file);
+ $app->system->unlink($csr_file);
+ $app->system->unlink($crt_file);
+ //$app->system->unlink($bundle_file);
/* Update the DB of the (local) Server */
$app->db->query("UPDATE web_domain SET ssl_request = '', ssl_cert = '' WHERE domain = '".$data['new']['domain']."'");
$app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'");
@@ -265,7 +273,7 @@ class nginx_plugin {
if($this->action != 'insert') $this->action = 'update';
- if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) {
+ if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) {
$old_parent_domain_id = intval($data['old']['parent_domain_id']);
$new_parent_domain_id = intval($data['new']['parent_domain_id']);
@@ -306,6 +314,58 @@ class nginx_plugin {
$app->log('Websites cannot be owned by the root user or group.',LOGLEVEL_WARN);
return 0;
}
+ if(trim($data['new']['domain']) == '') {
+ $app->log('domain is empty',LOGLEVEL_WARN);
+ return 0;
+ }
+
+ $web_folder = 'web';
+ $log_folder = 'log';
+ if($data['new']['type'] == 'vhostsubdomain') {
+ $web_folder = $data['new']['web_folder'];
+ $log_folder .= '_web' . $data['new']['domain_id'];
+ }
+
+ // Create group and user, if not exist
+ $app->uses('system');
+
+ if($web_config['connect_userid_to_webid'] == 'y') {
+ //* Calculate the uid and gid
+ $connect_userid_to_webid_start = ($web_config['connect_userid_to_webid_start'] < 1000)?1000:intval($web_config['connect_userid_to_webid_start']);
+ $fixed_uid_gid = intval($connect_userid_to_webid_start + $data['new']['domain_id']);
+ $fixed_uid_param = '--uid '.$fixed_uid_gid;
+ $fixed_gid_param = '--gid '.$fixed_uid_gid;
+
+ //* Check if a ispconfigend user and group exists and create them
+ if(!$app->system->is_group('ispconfigend')) {
+ exec('groupadd --gid '.($connect_userid_to_webid_start + 10000).' ispconfigend');
+ }
+ if(!$app->system->is_user('ispconfigend')) {
+ exec('useradd -g ispconfigend -d /usr/local/ispconfig --uid '.($connect_userid_to_webid_start + 10000).' ispconfigend');
+ }
+ } else {
+ $fixed_uid_param = '';
+ $fixed_gid_param = '';
+ }
+
+ $groupname = escapeshellcmd($data['new']['system_group']);
+ if($data['new']['system_group'] != '' && !$app->system->is_group($data['new']['system_group'])) {
+ exec('groupadd '.$fixed_gid_param.' '.$groupname);
+ if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' groupadd '.$groupname);
+ $app->log('Adding the group: '.$groupname,LOGLEVEL_DEBUG);
+ }
+
+ $username = escapeshellcmd($data['new']['system_user']);
+ if($data['new']['system_user'] != '' && !$app->system->is_user($data['new']['system_user'])) {
+ if($web_config['add_web_users_to_sshusers_group'] == 'y') {
+ exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false");
+ if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false");
+ } else {
+ exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false");
+ if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false");
+ }
+ $app->log('Adding the user: '.$username,LOGLEVEL_DEBUG);
+ }
//* If the client of the site has been changed, we have a change of the document root
if($this->action == 'update' && $data['new']['document_root'] != $data['old']['document_root']) {
@@ -339,16 +399,17 @@ class nginx_plugin {
$tmp_docroot = explode('/',$data['old']['document_root']);
unset($tmp_docroot[count($tmp_docroot)-1]);
$old_dir = implode('/',$tmp_docroot);
-
+
//* Check if there is already some data in the new docroot and rename it as we need a clean path to move the existing site to the new path
if(@is_dir($data['new']['document_root'])) {
- rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d'));
+ $app->system->rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d'));
$app->log('Renaming existing directory in new docroot location. mv '.$data['new']['document_root'].' '.$data['new']['document_root'].'_bak_'.date('Y_m_d'),LOGLEVEL_DEBUG);
}
//* Create new base directory, if it does not exist yet
- if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir);
- exec('mv '.$data['old']['document_root'].' '.$new_dir);
+ if(!is_dir($new_dir)) $app->system->mkdirpath($new_dir);
+ //exec('mv '.$data['old']['document_root'].' '.$new_dir);
+ $app->system->rename($data['old']['document_root'],$new_dir);
$app->log('Moving site to new document root: mv '.$data['old']['document_root'].' '.$new_dir,LOGLEVEL_DEBUG);
// Handle the change in php_open_basedir
@@ -372,40 +433,41 @@ class nginx_plugin {
//print_r($data);
// Check if the directories are there and create them if necessary.
- if(!is_dir($data['new']['document_root'].'/web')) exec('mkdir -p '.$data['new']['document_root'].'/web');
- if(!is_dir($data['new']['document_root'].'/web/error') and $data['new']['errordocs']) exec('mkdir -p '.$data['new']['document_root'].'/web/error');
- //if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log');
- if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl');
- if(!is_dir($data['new']['document_root'].'/cgi-bin')) exec('mkdir -p '.$data['new']['document_root'].'/cgi-bin');
- if(!is_dir($data['new']['document_root'].'/tmp')) exec('mkdir -p '.$data['new']['document_root'].'/tmp');
-
+ if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
+ if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error');
+ //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder);
+ if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
+ if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
+ if(!is_dir($data['new']['document_root'].'/tmp')) $app->system->mkdirpath($data['new']['document_root'].'/tmp');
+
+ //* Create the new private directory
+ if(!is_dir($data['new']['document_root'].'/private')) {
+ $app->system->mkdirpath($data['new']['document_root'].'/private');
+ $app->system->chmod($data['new']['document_root'].'/private',0710);
+ $app->system->chown($data['new']['document_root'].'/private',$username);
+ $app->system->chgrp($data['new']['document_root'].'/private',$groupname);
+ }
+
+
// Remove the symlink for the site, if site is renamed
if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) {
if(is_dir('/var/log/ispconfig/httpd/'.$data['old']['domain'])) exec('rm -rf /var/log/ispconfig/httpd/'.$data['old']['domain']);
- if(is_link($data['old']['document_root'].'/log')) unlink($data['old']['document_root'].'/log');
- }
-
- // Create the symlink for the logfiles
- if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']);
- if(!is_link($data['new']['document_root'].'/log')) {
- exec('ln -s /var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/log');
- $app->log('Creating symlink: ln -s /var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/log',LOGLEVEL_DEBUG);
- }
- /*
- // Create the symlink for the logfiles
- // This does not work as vlogger cannot log trough symlinks.
- if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) {
- if(is_dir($data['old']['document_root'].'/log')) exec('rm -rf '.$data['old']['document_root'].'/log');
- if(is_link('/var/log/ispconfig/httpd/'.$data['old']['domain'])) unlink('/var/log/ispconfig/httpd/'.$data['old']['domain']);
+ if(is_link($data['old']['document_root'].'/'.$log_folder)) $app->system->unlink($data['old']['document_root'].'/'.$log_folder);
}
- // Create the symlink for the logfiles
- if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log');
- if(!is_link('/var/log/ispconfig/httpd/'.$data['new']['domain'])) {
- exec('ln -s '.$data['new']['document_root'].'/log /var/log/ispconfig/httpd/'.$data['new']['domain']);
- $app->log('Creating symlink: ln -s '.$data['new']['document_root'].'/log /var/log/ispconfig/httpd/'.$data['new']['domain'],LOGLEVEL_DEBUG);
+ //* Create the log dir if nescessary and mount it
+ if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']);
+ if(!is_dir($data['new']['document_root'].'/'.$log_folder) || is_link($data['new']['document_root'].'/'.$log_folder)) {
+ if(is_link($data['new']['document_root'].'/'.$log_folder)) unlink($data['new']['document_root'].'/'.$log_folder);
+ $app->system->mkdir($data['new']['document_root'].'/'.$log_folder);
+ $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root');
+ $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,'root');
+ $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755);
+ exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/'.$log_folder));
+ //* add mountpoint to fstab
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind 0 0';
+ $app->system->replaceLine('/etc/fstab',$fstab_line,$fstab_line,1,1);
}
- */
// Get the client ID
$client = $app->dbmaster->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['new']['sys_groupid']));
@@ -440,11 +502,17 @@ class nginx_plugin {
if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
//* Remove symlink if target folder has been changed.
if($data['old']['document_root'] != '' && $data['old']['document_root'] != $data['new']['document_root'] && is_link($tmp_symlink)) {
- unlink($tmp_symlink);
+ $app->system->unlink($tmp_symlink);
}
// create the symlinks, if not exist
if(!is_link($tmp_symlink)) {
- exec('ln -s '.escapeshellcmd($data['new']['document_root']).'/ '.escapeshellcmd($tmp_symlink));
+// exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
+ if ($web_config["website_symlinks_rel"] == 'y') {
+ $this->create_relative_link(escapeshellcmd($data["new"]["document_root"]), escapeshellcmd($tmp_symlink));
+ } else {
+ exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
+ }
+
$app->log('Creating symlink: ln -s '.$data['new']['document_root'].'/ '.$tmp_symlink,LOGLEVEL_DEBUG);
}
}
@@ -458,17 +526,17 @@ class nginx_plugin {
// setting a local var here
// normally $conf['templates'] = "/usr/local/ispconfig/server/conf";
-
- if($this->action == 'insert' && $data['new']['type'] == 'vhost') {
- // Copy the error pages
+ if($this->action == 'insert' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) {
+
+ // Copy the error pages
if($data['new']['errordocs']) {
- $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/';
- if (file_exists($conf['rootpath'].'/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) {
- exec('cp ' . $conf['rootpath'].'/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
+ $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/';
+ if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) {
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
}
else {
- if (file_exists($conf['rootpath'].'/conf-custom/error/400.html')) {
- exec('cp '. $conf['rootpath'].'/conf-custom/error/*.html '.$error_page_path);
+ if (file_exists($conf['rootpath'] . '/conf-custom/error/400.html')) {
+ exec('cp '. $conf['rootpath'] . '/conf-custom/error/*.html '.$error_page_path);
}
else {
exec('cp ' . $conf['rootpath'] . '/conf/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
@@ -478,35 +546,35 @@ class nginx_plugin {
}
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2))) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
}
else {
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) {
- exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
+ exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
}
else {
- exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html');
- if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/');
- if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/');
- if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
+ if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
+ if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
+ if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
}
}
- exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/web/');
+ exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
//** Copy the error documents on update when the error document checkbox has been activated and was deactivated before
- } elseif ($this->action == 'update' && $data['new']['type'] == 'vhost' && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) {
-
- $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/';
+ } elseif ($this->action == 'update' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain') && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) {
+
+ $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/';
if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) {
exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path);
}
@@ -522,47 +590,6 @@ class nginx_plugin {
exec('chown -R '.$data['new']['system_user'].':'.$data['new']['system_group'].' '.$error_page_path);
} // end copy error docs
- // Create group and user, if not exist
- $app->uses('system');
-
- if($web_config['connect_userid_to_webid'] == 'y') {
- //* Calculate the uid and gid
- $connect_userid_to_webid_start = ($web_config['connect_userid_to_webid_start'] < 1000)?1000:intval($web_config['connect_userid_to_webid_start']);
- $fixed_uid_gid = intval($connect_userid_to_webid_start + $data['new']['domain_id']);
- $fixed_uid_param = '--uid '.$fixed_uid_gid;
- $fixed_gid_param = '--gid '.$fixed_uid_gid;
-
- //* Check if a ispconfigend user and group exists and create them
- if(!$app->system->is_group('ispconfigend')) {
- exec('groupadd --gid '.($connect_userid_to_webid_start + 10000).' ispconfigend');
- }
- if(!$app->system->is_user('ispconfigend')) {
- exec('useradd -g ispconfigend -d /usr/local/ispconfig --uid '.($connect_userid_to_webid_start + 10000).' ispconfigend');
- }
- } else {
- $fixed_uid_param = '';
- $fixed_gid_param = '';
- }
-
- $groupname = escapeshellcmd($data['new']['system_group']);
- if($data['new']['system_group'] != '' && !$app->system->is_group($data['new']['system_group'])) {
- exec('groupadd '.$fixed_gid_param.' '.$groupname);
- if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' groupadd '.$groupname);
- $app->log('Adding the group: '.$groupname,LOGLEVEL_DEBUG);
- }
-
- $username = escapeshellcmd($data['new']['system_user']);
- if($data['new']['system_user'] != '' && !$app->system->is_user($data['new']['system_user'])) {
- if($web_config['add_web_users_to_sshusers_group'] == 'y') {
- exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false");
- if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false");
- } else {
- exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false");
- if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false");
- }
- $app->log('Adding the user: '.$username,LOGLEVEL_DEBUG);
- }
-
// Set the quota for the user
if($username != '' && $app->system->is_user($username)) {
if($data['new']['hd_quota'] > 0) {
@@ -577,29 +604,36 @@ class nginx_plugin {
if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) {
// Chown and chmod the directories below the document root
- $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
// The document root itself has to be owned by root in normal level and by the web owner in security level 20
if($web_config['security_level'] == 20) {
- $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
} else {
- $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/web');
+ $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder);
}
}
-
+
//* If the security level is set to high
if(($this->action == 'insert' && $data['new']['type'] == 'vhost') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhost')) {
+ //* Check if we have the new private folder and create it if nescessary
+ if(!is_dir($data['new']['document_root'].'/private')) $app->system->mkdir($data['new']['document_root'].'/private');
+
if($web_config['security_level'] == 20) {
-
- $this->_exec('chmod 751 '.escapeshellcmd($data['new']['document_root']));
- $this->_exec('chmod 751 '.escapeshellcmd($data['new']['document_root']).'/*');
- $this->_exec('chmod 710 '.escapeshellcmd($data['new']['document_root'].'/web'));
+
+ $app->system->chmod($data['new']['document_root'],0755);
+ $app->system->chmod($data['new']['document_root'].'/web',0710);
+ $app->system->chmod($data['new']['document_root'].'/webdav',0710);
+ $app->system->chmod($data['new']['document_root'].'/private',0710);
+ $app->system->chmod($data['new']['document_root'].'/ssl',0755);
// make tmp directory writable for nginx and the website users
- $this->_exec('chmod 777 '.escapeshellcmd($data['new']['document_root'].'/tmp'));
+ $app->system->chmod($data['new']['document_root'].'/tmp',0777);
- // Set Log symlink to 755 to make the logs accessible by the FTP user
- $this->_exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"])."/log");
-
+ // Set Log directory to 755 to make the logs accessible by the FTP user
+ if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') {
+ $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755);
+ }
+
if($web_config['add_web_users_to_sshusers_group'] == 'y') {
$command = 'usermod';
$command .= ' --groups sshusers';
@@ -624,7 +658,8 @@ class nginx_plugin {
//* Chown all default directories
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']));
- $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/cgi-bin'));
+ $app->system->chown($data['new']['document_root'].'/cgi-bin',$username);
+ $app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname);
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/log'));
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/ssl'));
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/tmp'));
@@ -662,7 +697,25 @@ class nginx_plugin {
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/ssl'));
$this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/web'));
}
- }
+ } elseif(($this->action == 'insert' && $data['new']['type'] == 'vhostsubdomain') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhostsubdomain')) {
+ if($web_config['security_level'] == 20) {
+ $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0710);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname);
+ } else {
+ $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0755);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname);
+ $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username);
+ $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname);
+ }
+ }
// Change the ownership of the error log to the owner of the website
if(!@is_file($data['new']['document_root'].'/log/error.log')) exec('touch '.escapeshellcmd($data['new']['document_root']).'/log/error.log');
@@ -675,7 +728,7 @@ class nginx_plugin {
if(!is_dir($web_config['website_basedir'].'/conf')) mkdir($web_config['website_basedir'].'/conf');
if(trim($data['new']['custom_php_ini']) != '') {
$has_custom_php_ini = true;
- if(!is_dir($custom_php_ini_dir)) mkdir($custom_php_ini_dir);
+ if(!is_dir($custom_php_ini_dir)) $app->system->mkdir($custom_php_ini_dir);
$php_ini_content = '';
if($data['new']['php'] == 'mod') {
$master_php_ini_path = $web_config['php_ini_path_apache'];
@@ -687,13 +740,13 @@ class nginx_plugin {
}
}
if($master_php_ini_path != '' && substr($master_php_ini_path,-7) == 'php.ini' && is_file($master_php_ini_path)) {
- $php_ini_content .= file_get_contents($master_php_ini_path)."\n";
+ $php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
}
- $php_ini_content .= trim($data['new']['custom_php_ini']);
- file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content);
+ $php_ini_content .= str_replace("\r",'',trim($data['new']['custom_php_ini']));
+ $app->system->file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content);
} else {
$has_custom_php_ini = false;
- if(is_file($custom_php_ini_dir.'/php.ini')) unlink($custom_php_ini_dir.'/php.ini');
+ if(is_file($custom_php_ini_dir.'/php.ini')) $app->system->unlink($custom_php_ini_dir.'/php.ini');
}
*/
@@ -704,8 +757,9 @@ class nginx_plugin {
$tpl->newTemplate('nginx_vhost.conf.master');
$vhost_data = $data['new'];
- $vhost_data['web_document_root'] = $data['new']['document_root'].'/web';
- $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/web';
+ //unset($vhost_data['ip_address']);
+ $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'];
// IPv6
@@ -930,7 +984,7 @@ class nginx_plugin {
}
// get alias domains (co-domains and subdomains)
- $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y'");
+ $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND type != 'vhostsubdomain'");
switch($data['new']['subdomain']) {
case 'www':
$server_alias[] = 'www.'.$data['new']['domain'].' ';
@@ -1100,12 +1154,12 @@ class nginx_plugin {
if($data['new']['subdomain'] != $data['old']['subdomain'] or $data['new']['active'] == 'n') {
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['new']['domain'].'.vhost');
if(is_link($vhost_symlink)) {
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['new']['domain'].'.vhost');
if(is_link($vhost_symlink)) {
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
}
@@ -1125,21 +1179,21 @@ class nginx_plugin {
if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) {
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)) {
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)) {
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)) {
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_file = escapeshellcmd($web_config['nginx_vhost_conf_dir'].'/'.$data['old']['domain'].'.vhost');
- unlink($vhost_file);
+ $app->system->unlink($vhost_file);
$app->log('Removing file: '.$vhost_file,LOGLEVEL_DEBUG);
}
@@ -1154,7 +1208,7 @@ class nginx_plugin {
}
//* Create awstats configuration
- if($data['new']['stats_type'] == 'awstats' && $data['new']['type'] == 'vhost') {
+ if($data['new']['stats_type'] == 'awstats' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) {
$this->awstats_update($data,$web_config);
}
@@ -1178,7 +1232,7 @@ class nginx_plugin {
copy($vhost_file,$vhost_file.'.err');
if(is_file($vhost_file.'~')) {
//* Copy back the last backup file
- copy($vhost_file.'~',$vhost_file);
+ $app->system->copy($vhost_file.'~',$vhost_file);
} else {
//* There is no backup file, so we create a empty vhost file with a warning message inside
file_put_contents($vhost_file,"# nginx did not start after modifying this vhost file.\n# Please check file $vhost_file.err for syntax errors.");
@@ -1196,8 +1250,7 @@ class nginx_plugin {
}
// Remove the backup copy of the config file.
- if(@is_file($vhost_file.'~')) unlink($vhost_file.'~');
-
+ if(@is_file($vhost_file.'~')) $app->system->unlink($vhost_file.'~');
//* Unset action to clean it for next processed vhost.
$this->action = '';
@@ -1209,6 +1262,7 @@ class nginx_plugin {
// load the server configuration options
$app->uses('getconf');
+ $app->uses('system');
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
//* Check if this is a chrooted setup
@@ -1218,7 +1272,7 @@ class nginx_plugin {
$nginx_chrooted = false;
}
- if($data['old']['type'] != 'vhost' && $data['old']['parent_domain_id'] > 0) {
+ if($data['old']['type'] != 'vhost' && $data['old']['type'] != 'vhostsubdomain' && $data['old']['parent_domain_id'] > 0) {
//* This is a alias domain or subdomain, so we have to update the website instead
$parent_domain_id = intval($data['old']['parent_domain_id']);
$tmp = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$parent_domain_id." AND active = 'y'");
@@ -1235,87 +1289,108 @@ class nginx_plugin {
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)){
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)){
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
$vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['old']['domain'].'.vhost');
if(is_link($vhost_symlink)){
- unlink($vhost_symlink);
+ $app->system->unlink($vhost_symlink);
$app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG);
}
- unlink($vhost_file);
+ $app->system->unlink($vhost_file);
$app->log('Removing vhost file: '.$vhost_file,LOGLEVEL_DEBUG);
-
- $docroot = escapeshellcmd($data['old']['document_root']);
- if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot);
-
- //remove the php fastgi starter script and PHP-FPM pool definition if available
- if ($data['old']['php'] == 'fast-cgi') {
- $this->php_fpm_pool_delete($data,$web_config);
- $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']);
- if (is_dir($fastcgi_starter_path)) {
- exec('rm -rf '.$fastcgi_starter_path);
- }
- }
+
+ if($data['old']['type'] == 'vhost') {
+ $docroot = escapeshellcmd($data['old']['document_root']);
+ if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot);
- // remove PHP-FPM pool
- if ($data['old']['php'] == 'php-fpm') {
- $this->php_fpm_pool_delete($data,$web_config);
- }
-
- //remove the php cgi starter script if available
- if ($data['old']['php'] == 'cgi') {
- // TODO: fetch the date from the server-settings
- $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/';
-
- $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']);
- if (is_dir($cgi_starter_path)) {
- exec('rm -rf '.$cgi_starter_path);
- }
- }
-
- $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG);
-
- // Delete the symlinks for the sites
- $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid']));
- $client_id = intval($client['client_id']);
- unset($client);
- $tmp_symlinks_array = explode(':',$web_config['website_symlinks']);
- if(is_array($tmp_symlinks_array)) {
- foreach($tmp_symlinks_array as $tmp_symlink) {
- $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink);
- $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink);
- // Remove trailing slash
- if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
- // create the symlinks, if not exist
- if(is_link($tmp_symlink)) {
- unlink($tmp_symlink);
- $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG);
- }
- }
- }
- // end removing symlinks
+ //remove the php fastgi starter script if available
+ if ($data['old']['php'] == 'fast-cgi') {
+ $this->php_fpm_pool_delete($data,$web_config);
+ $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']);
+ if($data['old']['type'] == 'vhost') {
+ if (is_dir($fastcgi_starter_path)) {
+ exec('rm -rf '.$fastcgi_starter_path);
+ }
+ } else {
+ $fcgi_starter_script = $fastcgi_starter_path.$web_config['fastcgi_starter_script'].'_web'.$data['old']['domain_id'];
+ if (file_exists($fcgi_starter_script)) {
+ exec('rm -f '.$fcgi_starter_script);
+ }
+ }
+ }
+
+ // remove PHP-FPM pool
+ if ($data['old']['php'] == 'php-fpm') {
+ $this->php_fpm_pool_delete($data,$web_config);
+ }
- // Delete the log file directory
- $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']);
- if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir);
- $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG);
+ //remove the php cgi starter script if available
+ if ($data['old']['php'] == 'cgi') {
+ // TODO: fetch the date from the server-settings
+ $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/';
+
+ $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']);
+ if($data['old']['type'] == 'vhost') {
+ if (is_dir($cgi_starter_path)) {
+ exec('rm -rf '.$cgi_starter_path);
+ }
+ } else {
+ $cgi_starter_script = $cgi_starter_path.'php-cgi-starter_web'.$data['old']['domain_id'];
+ if (file_exists($cgi_starter_script)) {
+ exec('rm -f '.$cgi_starter_script);
+ }
+ }
+ }
+
+ $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG);
+
+ // Delete the symlinks for the sites
+ $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid']));
+ $client_id = intval($client['client_id']);
+ unset($client);
+ $tmp_symlinks_array = explode(':',$web_config['website_symlinks']);
+ if(is_array($tmp_symlinks_array)) {
+ foreach($tmp_symlinks_array as $tmp_symlink) {
+ $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink);
+ $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink);
+ // Remove trailing slash
+ if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
+ // create the symlinks, if not exist
+ if(is_link($tmp_symlink)) {
+ $app->system->unlink($tmp_symlink);
+ $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG);
+ }
+ }
+ }
+ // end removing symlinks
+ } else {
+ // vhost subdomain
+ }
- //delete the web user
- $command = 'userdel';
- $command .= ' '.$data['old']['system_user'];
- exec($command);
- if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command);
-
- //* Remove the awstats configuration file
- if($data['old']['stats_type'] == 'awstats') {
- $this->awstats_delete($data,$web_config);
+ // Delete the log file directory
+ $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']);
+ if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir);
+ $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG);
+
+ if($data['old']['type'] == 'vhost') {
+ //delete the web user
+ $command = 'userdel';
+ $command .= ' '.$data['old']['system_user'];
+ exec($command);
+ if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command);
+
+ }
+
+ //* Remove the awstats configuration file
+ if($data['old']['stats_type'] == 'awstats') {
+ $this->awstats_delete($data,$web_config);
}
$app->services->restartServiceDelayed('httpd','reload');
@@ -1348,10 +1423,13 @@ class nginx_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1);
if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1);
- $folder_path = escapeshellcmd($website['document_root'].'/web/'.$folder['path']);
+ $folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$folder['path']);
if(substr($folder_path,-1) != '/') $folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -1362,18 +1440,18 @@ class nginx_plugin {
//* Create the folder path, if it does not exist
if(!is_dir($folder_path)) {
- exec('mkdir -p '.$folder_path);
- chown($folder_path,$website['system_user']);
- chgrp($folder_path,$website['system_group']);
+ $app->system->mkdirpath($folder_path);
+ $app->system->chown($folder_path,$website['system_user']);
+ $app->system->chgrp($folder_path,$website['system_group']);
}
//* Create empty .htpasswd file, if it does not exist
if(!is_file($folder_path.'.htpasswd')) {
touch($folder_path.'.htpasswd');
- chmod($folder_path.'.htpasswd',0755);
- chown($folder_path.'.htpasswd',$website['system_user']);
- chgrp($folder_path.'.htpasswd',$website['system_group']);
- $app->log('Created file'.$folder_path.'.htpasswd',LOGLEVEL_DEBUG);
+ $app->system->chmod($folder_path.'.htpasswd',0755);
+ $app->system->chown($folder_path.'.htpasswd',$website['system_user']);
+ $app->system->chgrp($folder_path.'.htpasswd',$website['system_group']);
+ $app->log('Created file '.$folder_path.'.htpasswd',LOGLEVEL_DEBUG);
}
/*
@@ -1424,10 +1502,13 @@ class nginx_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1);
if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1);
- $folder_path = realpath($website['document_root'].'/web/'.$folder['path']);
+ $folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$folder['path']);
if(substr($folder_path,-1) != '/') $folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -1438,7 +1519,7 @@ class nginx_plugin {
//* Remove .htpasswd file
if(is_file($folder_path.'.htpasswd')) {
- unlink($folder_path.'.htpasswd');
+ $app->system->unlink($folder_path.'.htpasswd');
$app->log('Removed file '.$folder_path.'.htpasswd',LOGLEVEL_DEBUG);
}
@@ -1458,15 +1539,18 @@ class nginx_plugin {
return false;
}
+ $web_folder = 'web';
+ if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder'];
+
//* Get the folder path.
if(substr($data['old']['path'],0,1) == '/') $data['old']['path'] = substr($data['old']['path'],1);
if(substr($data['old']['path'],-1) == '/') $data['old']['path'] = substr($data['old']['path'],0,-1);
- $old_folder_path = realpath($website['document_root'].'/web/'.$data['old']['path']);
+ $old_folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$data['old']['path']);
if(substr($old_folder_path,-1) != '/') $old_folder_path .= '/';
if(substr($data['new']['path'],0,1) == '/') $data['new']['path'] = substr($data['new']['path'],1);
if(substr($data['new']['path'],-1) == '/') $data['new']['path'] = substr($data['new']['path'],0,-1);
- $new_folder_path = escapeshellcmd($website['document_root'].'/web/'.$data['new']['path']);
+ $new_folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$data['new']['path']);
if(substr($new_folder_path,-1) != '/') $new_folder_path .= '/';
//* Check if the resulting path is inside the docroot
@@ -1490,14 +1574,14 @@ class nginx_plugin {
}
//* Create the folder path, if it does not exist
- if(!is_dir($new_folder_path)) exec('mkdir -p '.$new_folder_path);
+ if(!is_dir($new_folder_path)) $app->system->mkdirpath($new_folder_path);
if($data['old']['path'] != $data['new']['path']) {
//* move .htpasswd file
if(is_file($old_folder_path.'.htpasswd')) {
- rename($old_folder_path.'.htpasswd',$new_folder_path.'.htpasswd');
+ $app->system->rename($old_folder_path.'.htpasswd',$new_folder_path.'.htpasswd');
$app->log('Moved file '.$old_folder_path.'.htpasswd to '.$new_folder_path.'.htpasswd',LOGLEVEL_DEBUG);
}
@@ -1527,7 +1611,7 @@ class nginx_plugin {
$website_auth_location['path'] .= '/';
}
$basic_auth_locations[] = array('htpasswd_location' => '/'.$website_auth_location['path'],
- 'htpasswd_path' => $website['document_root'].'/web/'.$website_auth_location['path']);
+ 'htpasswd_path' => $website['document_root'].'/' . ($website['type'] == 'vhostsubdomain' ? $website['web_folder'] : 'web') . '/'.$website_auth_location['path']);
}
}
return $basic_auth_locations;
@@ -1542,12 +1626,14 @@ class nginx_plugin {
private function awstats_update ($data,$web_config) {
global $app;
+ $web_folder = $data['new']['web_folder'];
+ if($data['new']['type'] == 'vhost') $web_folder = 'web';
$awstats_conf_dir = $web_config['awstats_conf_dir'];
- if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats");
+ if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats");
if(!@is_file($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) {
if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
- unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
+ $app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
}
$content = '';
@@ -1556,12 +1642,12 @@ class nginx_plugin {
$content .= "SiteDomain=\"".$data['new']['domain']."\"\n";
$content .= "HostAliases=\"www.".$data['new']['domain']." localhost 127.0.0.1\"\n";
- file_put_contents($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',$content);
+ $app->system->file_put_contents($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',$content);
$app->log('Created AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',LOGLEVEL_DEBUG);
}
- if(is_file($data['new']['document_root']."/web/stats/index.html")) unlink($data['new']['document_root']."/web/stats/index.html");
- copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/web/stats/index.php");
+ if(is_file($data['new']['document_root']."/" . $web_folder . "/stats/index.html")) $app->system->unlink($data['new']['document_root']."/" . $web_folder . "/stats/index.html");
+ $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/" . $web_folder . "/stats/index.php");
}
//* Delete the awstats configuration file
@@ -1571,7 +1657,7 @@ class nginx_plugin {
$awstats_conf_dir = $web_config['awstats_conf_dir'];
if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
- unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
+ $app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
$app->log('Removed AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf',LOGLEVEL_DEBUG);
}
}
@@ -1611,7 +1697,8 @@ class nginx_plugin {
if($data['new']['php'] == 'no'){
if(@is_file($pool_dir.$pool_name.'.conf')){
- unlink($pool_dir.$pool_name.'.conf');
+ $app->system->unlink($pool_dir.$pool_name.'.conf');
+ //$reload = true;
}
if($data['old']['php'] != 'no'){
if(!$default_php_fpm){
@@ -1630,7 +1717,7 @@ class nginx_plugin {
if($data['new']['php_fpm_use_socket'] == 'y'){
$use_tcp = 0;
$use_socket = 1;
- if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
+ if(!is_dir($socket_dir)) $app->system->mkdirpath($socket_dir);
} else {
$use_tcp = 1;
$use_socket = 0;
@@ -1699,7 +1786,7 @@ class nginx_plugin {
$tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
- file_put_contents($pool_dir.$pool_name.'.conf',$tpl->grab());
+ $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);
@@ -1708,7 +1795,7 @@ class nginx_plugin {
if(substr($default_pool_dir,-1) != '/') $default_pool_dir .= '/';
if($default_pool_dir != $pool_dir){
if ( @is_file($default_pool_dir.$pool_name.'.conf') ) {
- unlink($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']);
}
@@ -1719,7 +1806,7 @@ class nginx_plugin {
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') ) {
- unlink($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']);
}
@@ -1757,7 +1844,7 @@ class nginx_plugin {
$pool_name = 'web'.$data['old']['domain_id'];
if ( @is_file($pool_dir.$pool_name.'.conf') ) {
- unlink($pool_dir.$pool_name.'.conf');
+ $app->system->unlink($pool_dir.$pool_name.'.conf');
$app->log('Removed PHP-FPM config file: '.$pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG);
}
@@ -1766,7 +1853,7 @@ class nginx_plugin {
if(substr($default_pool_dir,-1) != '/') $default_pool_dir .= '/';
if($default_pool_dir != $pool_dir){
if ( @is_file($default_pool_dir.$pool_name.'.conf') ) {
- unlink($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']);
}
@@ -1777,7 +1864,7 @@ class nginx_plugin {
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') ) {
- unlink($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']);
}
@@ -1911,4 +1998,4 @@ class nginx_plugin {
} // end class
-?>
\ No newline at end of file
+?>
diff --git a/server/plugins-available/nginx_reverseproxy_plugin.inc.php b/server/plugins-available/nginx_reverseproxy_plugin.inc.php
index ec0e225d70bf27e81e70b6818627de6218aa074b..ae4ffe9b954b92a72ae8ee65127b346cbd79c6e6 100644
--- a/server/plugins-available/nginx_reverseproxy_plugin.inc.php
+++ b/server/plugins-available/nginx_reverseproxy_plugin.inc.php
@@ -63,7 +63,7 @@ class nginx_reverseproxy_plugin {
if($this->action != 'insert') $this->action = 'update';
- if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) {
+ if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) {
$old_parent_domain_id = intval($data['old']['parent_domain_id']);
$new_parent_domain_id = intval($data['new']['parent_domain_id']);
@@ -130,7 +130,7 @@ class nginx_reverseproxy_plugin {
// get alias domains (co-domains and subdomains)
- $aliases = $app->dbmaster->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y'");
+ $aliases = $app->dbmaster->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND type != 'vhostsubdomain' AND active = 'y'");
$server_alias = array();
switch($data['new']['subdomain']) {
case 'www':
@@ -280,7 +280,7 @@ class nginx_reverseproxy_plugin {
$nginx_config = $app->getconf->get_server_config($conf['server_id'], 'web');
- if($data['old']['type'] == 'vhost') {
+ if($data['old']['type'] == 'vhost' || $data['old']['type'] == 'vhostsubdomain') {
//* This is a website
// Deleting the vhost file, symlink and the data directory