From a3ea861b986107be76630457c69fcba25b488496 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Mon, 27 Aug 2012 19:23:23 +0000 Subject: [PATCH] =?UTF-8?q?Les=20sous=20domaines=20cr=C3=A9=C3=A9=20automa?= =?UTF-8?q?tiquement=20=C3=A0=20l'ajout=20d'un=20domaine=20sont=20maintena?= =?UTF-8?q?nt=20dynamique.=20Il=20manque=20l'interface=20web=20pour=20g?= =?UTF-8?q?=C3=A9rer=20=C3=A7a.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG : la création du répertoire ne se fait pas. Message d'erreur affiché en gros. Trouvé un peut-etre bug dans le checkuserpath de function.php, ajouté un FIXME --- bureau/admin/dom_doadd.php | 2 +- bureau/class/functions.php | 5 ++- bureau/class/m_bro.php | 2 +- bureau/class/m_dom.php | 84 ++++++++++++++++++++++++++------------ install/mysql.sql | 23 ++++++++++- install/upgrades/1.1.sql | 26 ++++++++++++ 6 files changed, 111 insertions(+), 31 deletions(-) diff --git a/bureau/admin/dom_doadd.php b/bureau/admin/dom_doadd.php index abd9f73f..4abaaab2 100644 --- a/bureau/admin/dom_doadd.php +++ b/bureau/admin/dom_doadd.php @@ -52,7 +52,7 @@ $dom->unlock();



-
+
show_help("add_domain"); ?>
user["login"]; $usar=substr($user,0,1); - if (substr($path,0,1)=="/") + if (substr($path,0,1)!="/") $path="/".$path; $rpath = realpath(ALTERNC_HTML."/$usar/$user$path"); + if (!$rpath) { // if file or directory does not exist + return 1; // FIXME is it safe to say OK in this case ? + } $userpath = getuserpath(); if(strpos($rpath,$userpath) === 0){ if (is_dir(ALTERNC_HTML."/$usar/$user$path")) { diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index 548c8c25..e6f97f00 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -338,7 +338,7 @@ class m_bro { $absolute=$this->convertabsolute($dir."/".$file,0); #echo "$absolute"; if ($absolute && (!file_exists($absolute))) { - if (!mkdir($absolute,00777)) { + if (!mkdir($absolute,00777,true)) { $err->raise("bro",_("Cannot create the requested directory. Please check permissions.")); return false; } diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 87ede2c0..317c0c9d 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -257,6 +257,10 @@ class m_dom { return true; } + function domshort($dom, $sub="") { + return str_replace("-","",str_replace(".","",empty($sub)?"":"$sub.").$dom ); + } + /* ----------------------------------------------------------------- */ /** * Installe un domaine sur le compte courant. @@ -364,33 +368,10 @@ class m_dom { $isslave=false; } // Point to the master domain : - $this->set_sub_domain($domain, '', $this->type_url, 'http://www.'.$slavedom); - $this->set_sub_domain($domain, 'www', $this->type_url, 'http://www.'.$slavedom); - $this->set_sub_domain($domain, 'mail', $this->type_url, 'http://mail.'.$slavedom); + $this->create_default_subdomains($domain, $slavedom); } if (!$isslave) { - // Creation du repertoire dans www - $dest_root = $bro->get_userid_root($cuid); - $domshort=str_replace("-","",str_replace(".","",$domain)); - - if (! is_dir($dest_root . "/". $domshort)) { - if(!mkdir($dest_root . "/". $domshort)){ - $err->raise("dom",_("I can't write to the destination folder")); - return false; - } - } - - if (! is_dir($dest_root . "/tmp")) { - if(!mkdir($dest_root . "/tmp")){ - $err->raise("dom",_("I can't write to the destination folder")); - return false; - } - } - - // Creation des 3 sous-domaines par défaut : Vide, www et mail - $this->set_sub_domain($domain, '', $this->type_url, 'http://www.'.$domain); - $this->set_sub_domain($domain, 'www', $this->type_local, '/'. $domshort); - $this->set_sub_domain($domain, 'mail', $this->type_webmail, ''); + $this->create_default_subdomains($domain); } // TODO: Old hooks, FIXME: when unused remove them @@ -408,6 +389,32 @@ class m_dom { return true; } + function create_default_subdomains($domain,$target_domain=""){ + global $db; + $query="SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE concerned = 'SLAVE' or concerned = 'BOTH' and enabled=1;"; + if(empty($target_domain)) { + $query="SELECT sub, domain_type, domain_type_parameter FROM default_subdomains WHERE concerned = 'MAIN' or concerned = 'BOTH' and enabled=1;"; + } + $domaindir=$this->domdefaultdir($domain); + $db->query($query); + $jj=array(); + while ($db->next_record()) { + $jj[]=Array("domain_type_parameter"=>$db->f('domain_type_parameter'),"sub"=>$db->f('sub'), "domain_type"=>$db->f('domain_type')); + } + $src_var=array("%%SUB%%","%%DOMAIN%%","%%DOMAINDIR%%", "%%TARGETDOM%%"); + foreach($jj as $j){ + $trg_var=array($j['sub'],$domain,$domaindir,$target_domain); + $domain_type_parameter=str_ireplace($src_var,$trg_var,$j['domain_type_parameter']); + $this->set_sub_domain($domain, $j['sub'], strtolower($j['domain_type']), $domain_type_parameter); + } + } + + function domdefaultdir($domain) { + global $bro,$cuid; + $dest_root = $bro->get_userid_root($cuid); + # return $dest_root."/www/".$this->domshort($domain); + return "/www/".$this->domshort($domain); + } /* ----------------------------------------------------------------- */ /** @@ -736,7 +743,7 @@ class m_dom { } if (!checkuserpath($value)) { $err->raise("dom",_("The folder you entered is incorrect or does not exist.")); - return false; + return false; } return true; break; @@ -807,7 +814,7 @@ class m_dom { * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. */ function set_sub_domain($dom,$sub,$type,$dest, $type_old=null,$sub_old=null,$value_old=null) { - global $db,$err,$cuid; + global $db,$err,$cuid,$bro; $err->log("dom","set_sub_domain",$dom."/".$sub."/".$type."/".$dest); // Locked ? if (!$this->islocked) { @@ -853,6 +860,29 @@ class m_dom { return false; } + // Create TMP dir and TARGET dir if needed by the domains_type + $dest_root = $bro->get_userid_root($cuid); + $domshort=$this->domshort($dom,$sub); + $db->query("select create_tmpdir, create_targetdir from domaines_type where name = '$type';"); + $db->next_record(); + if ($db->f('create_tmpdir')) { + if (! is_dir($dest_root . "/tmp")) { + if(!mkdir($dest_root . "/tmp")){ +printvar("je viens de tenter de mkdir ++$dest_root/tmp++"); // FIXME Bullshit. Safemode à la con ? + $err->raise("dom",_("I can't write to the destination folder")); + } + } + } + if ($db->f('create_targetdir')) { + $dirr=$dest_root.$dest; + if (! is_dir($dirr)) { + if(!mkdir($dirr,null,1)){ +printvar("je viens de tenter de mkdir ++$dirr++"); // FIXME Bullshit. Safemode à la con ? + $err->raise("dom",_("I can't write to the destination folder")); + } + } + } + // Tell to update the DNS file $db->query("update domaines set dns_action='UPDATE' where domaine='$dom';"); diff --git a/install/mysql.sql b/install/mysql.sql index e836715c..1243016d 100644 --- a/install/mysql.sql +++ b/install/mysql.sql @@ -489,6 +489,8 @@ CREATE TABLE IF NOT EXISTS `domaines_type` ( `only_dns` BOOLEAN DEFAULT FALSE, -- Update_domains modify just the dns, no web configuration `need_dns` BOOLEAN DEFAULT TRUE, -- The server need to be the DNS to allow this service `advanced` BOOLEAN DEFAULT TRUE, -- It's an advanced option + create_tmpdir BOOLEAN NOT NULL DEFAULT FALSE, -- do we create tmp dir ? + create_targetdir BOOLEAN NOT NULL DEFAULT FALSE, -- do we create target dir ? PRIMARY KEY ( `name` ) ) COMMENT = 'Type of domains allowed'; @@ -505,7 +507,7 @@ INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibil ('defmx2', 'Default backup mail server', 'NONE', '%SUB% IN MX 10 @@DEFAULT_SECONDARY_MX@@.', 'vhost,url,ip,ipv6,cname,txt,defmx',true, false, true, 'ADMIN'), ('panel', 'AlternC panel access', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,ip,ipv6,cname,txt,mx,mx2,defmx,defmx2',true, false, true, 'ALL') ; - +UPDATE domaines_type SET create_tmpdir=true, create_targetdir=true WHERE target='DIRECTORY'; -- Add function who are not in mysql 5 to be able ton convert ipv6 to decimal (and reverse it) DELIMITER // @@ -670,4 +672,23 @@ CREATE TABLE IF NOT EXISTS `piwik_sites` ( UNIQUE KEY `unique_site_per_user` (`uid`,`piwik_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; +-- Defaults subdomains to create when a domain is added +CREATE TABLE IF NOT EXISTS `default_subdomains` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `sub` varchar(255) NOT NULL, + `domain_type` varchar(255) NOT NULL, + `domain_type_parameter` varchar(255) NOT NULL, + `concerned` enum('BOTH','MAIN','SLAVE') NOT NULL DEFAULT 'MAIN', + `enabled` boolean not null default true, + PRIMARY KEY (`id`) +) COMMENT='Contains the defaults subdomains created on domains creation'; + +INSERT INTO `default_subdomains` (`sub`, `domain_type`, `domain_type_parameter`, `concerned`) VALUES +('www', 'VHOST', '%%DOMAINDIR%%', 'MAIN'), +('mail', 'WEBMAIL', '', 'MAIN'), +('', 'URL', 'www.%%DOMAIN%%', 'MAIN'), +('www', 'URL', 'www.%%TARGETDOM%%', 'SLAVE'), +('mail', 'URL', 'mail.%%TARGETDOM%%', 'SLAVE'), +('', 'URL', '%%TARGETDOM%%', 'SLAVE'); + diff --git a/install/upgrades/1.1.sql b/install/upgrades/1.1.sql index ed57c492..7c4e7d0e 100644 --- a/install/upgrades/1.1.sql +++ b/install/upgrades/1.1.sql @@ -229,3 +229,29 @@ DROP TABLE size_mail; -- now that we have separate packages for the webmails, we can't serve webmail domainetype anymore DELETE FROM domaines_type WHERE name='webmail'; UPDATE domaines_type SET compatibility=REPLACE(compatibility,'webmail,',''); + +-- Edit domains_type +ALTER TABLE `domaines_type` ADD create_tmpdir BOOLEAN NOT NULL DEFAULT FALSE ; +ALTER TABLE `domaines_type` ADD create_targetdir BOOLEAN NOT NULL DEFAULT FALSE ; +UPDATE domaines_type SET create_tmpdir=true, create_targetdir=true WHERE target='DIRECTORY'; + +-- Defaults subdomains to create when a domain is added +CREATE TABLE IF NOT EXISTS `default_subdomains` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `sub` varchar(255) NOT NULL, + `domain_type` varchar(255) NOT NULL, + `domain_type_parameter` varchar(255) NOT NULL, + `concerned` enum('BOTH','MAIN','SLAVE') NOT NULL DEFAULT 'MAIN', + `enabled` boolean not null default true, + PRIMARY KEY (`id`) +) COMMENT='Contains the defaults subdomains created on domains creation'; + +INSERT INTO `default_subdomains` (`sub`, `domain_type`, `domain_type_parameter`, `concerned`) VALUES +('www', 'VHOST', '%%DOMAINDIR%%', 'MAIN'), +('mail', 'WEBMAIL', '', 'MAIN'), +('', 'URL', 'www.%%DOMAIN%%', 'MAIN'), +('www', 'URL', 'www.%%TARGETDOM%%', 'SLAVE'), +('mail', 'URL', 'mail.%%TARGETDOM%%', 'SLAVE'), +('', 'URL', '%%TARGETDOM%%', 'SLAVE'); + +