From 1ca823723668e01b1b998faec5f8d8153545cfa8 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Mon, 04 Apr 2011 08:22:29 -0400
Subject: [PATCH] Merged revisions 2181-2262 from stable branch.
---
interface/web/sites/web_domain_edit.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 96 insertions(+), 11 deletions(-)
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 83ba83f..8322f3f 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -50,6 +50,19 @@
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;
@@ -183,7 +196,8 @@
}
$ssl_domain_select = '';
- $ssl_domains = array($this->dataRecord["domain"],'www.'.$this->dataRecord["domain"]);
+ $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':'';
@@ -264,12 +278,12 @@
$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 FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
- //* Check the website quota
+ //* 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 == -1 && $client["limit_web_quota"] != -1)) {
+ 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<br>";
@@ -280,12 +294,12 @@
unset($tmp_quota);
}
- //* Check the traffic 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 == -1 && $client["limit_traffic_quota"] != -1)) {
+ 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<br>";
@@ -294,6 +308,43 @@
}
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<br>";
+ // 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<br>";
+ // 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
@@ -317,10 +368,14 @@
}
}
+
// Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
}
+
+ //* make sure that the email domain is lowercase
+ if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
parent::onSubmit();
@@ -329,7 +384,7 @@
function onAfterInsert() {
global $app, $conf;
- // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
+ // make sure that the record belongs to the clinet group and not the admin group when admin inserts it
// also make sure that the user can not delete domain created by a admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = intval($this->dataRecord["client_group_id"]);
@@ -345,6 +400,10 @@
$web_rec = $app->tform->getDataRecord($this->id);
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
+ $document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
// get the ID of the client
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
@@ -360,7 +419,12 @@
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote('web'.$this->id);
$system_group = $app->db->quote('client'.$client_id);
- $document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
+ $document_root = str_replace("[client_id]",$client_id,$document_root);
+ $document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
+ $document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
+ $document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
+ $document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
+ $document_root = $app->db->quote($document_root);
$php_open_basedir = str_replace("[website_path]",$document_root,$web_config["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($web_config["htaccess_allow_override"]);
@@ -404,6 +468,10 @@
if($this->dataRecord['ssl_organisation_unit'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_unit_empty').'<br />';
if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'<br />';
}
+
+ 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').'<br />';
+ }
}
@@ -426,6 +494,10 @@
$web_rec = $app->tform->getDataRecord($this->id);
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
+ $document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
+ $document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
// get the ID of the client
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
@@ -442,7 +514,12 @@
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote('web'.$this->id);
$system_group = $app->db->quote('client'.$client_id);
- $document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
+ $document_root = str_replace("[client_id]",$client_id,$document_root);
+ $document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
+ $document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
+ $document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
+ $document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
+ $document_root = $app->db->quote($document_root);
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
//$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group' WHERE domain_id = ".$this->id;
@@ -451,7 +528,7 @@
// Update the FTP user(s) too
$records = $app->db->queryAllRecords("SELECT ftp_user_id FROM ftp_user WHERE parent_domain_id = ".$this->id);
foreach($records as $rec) {
- $app->db->datalogUpdate('ftp_user', "uid = '$system_user', gid = '$system_group', dir = '$document_root'", 'ftp_user_id', $rec['ftp_user_id']);
+ $app->db->datalogUpdate('ftp_user', "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."', uid = '$system_user', gid = '$system_group', dir = '$document_root'", 'ftp_user_id', $rec['ftp_user_id']);
}
unset($records);
unset($rec);
@@ -459,7 +536,15 @@
// Update the Shell user(s) too
$records = $app->db->queryAllRecords("SELECT shell_user_id FROM shell_user WHERE parent_domain_id = ".$this->id);
foreach($records as $rec) {
- $app->db->datalogUpdate('shell_user', "puser = '$system_user', pgroup = '$system_group', dir = '$document_root'", 'shell_user_id', $rec['shell_user_id']);
+ $app->db->datalogUpdate('shell_user', "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."', puser = '$system_user', pgroup = '$system_group', dir = '$document_root'", 'shell_user_id', $rec['shell_user_id']);
+ }
+ unset($records);
+ unset($rec);
+
+ //* Update all subdomains and alias domains
+ $records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE parent_domain_id = ".$this->id);
+ foreach($records as $rec) {
+ $app->db->datalogUpdate('web_domain', "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."'", 'domain_id', $rec['domain_id']);
}
unset($records);
unset($rec);
@@ -483,7 +568,7 @@
$sql = "UPDATE web_domain SET allow_override = '".$app->db->quote($web_config["htaccess_allow_override"])."' WHERE domain_id = ".$this->id;
$app->db->query($sql);
}
- if($web_rec['php_open_basedir'] == '') {
+ if($web_rec['php_open_basedir'] == '' || (isset($this->dataRecord["client_group_id"]) && $this->dataRecord["client_group_id"] != $this->oldDataRecord["sys_groupid"])) {
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
$php_open_basedir = str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
--
Gitblit v1.9.1