Les sous domaines créé automatiquement à l'ajout d'un domaine sont maintenant dynamique.

Il manque l'interface web pour gérer ça.

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
This commit is contained in:
Alan Garcia 2012-08-27 19:23:23 +00:00
parent 14a5d9aa14
commit a3ea861b98
6 changed files with 111 additions and 31 deletions

View File

@ -52,7 +52,7 @@ $dom->unlock();
<h3><?php __("Add a domain"); ?></h3>
<p>
<?php printf(_("Your new domain %s has been successfully installed"),$newdomain); ?><br /><br />
<span class="inb"><a href="main.php" target="_top"><?php __("Click here to continue"); ?></a></span><br />
<span class="inb"><a href="dom_edit.php?domain=<?php echo urlencode($newdomain);?>" ><?php __("Click here to continue"); ?></a></span><br />
<?php $mem->show_help("add_domain"); ?>
<br />
<?php

View File

@ -187,10 +187,13 @@ function checkuserpath($path) {
global $mem;
$user=$mem->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")) {

View File

@ -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;
}

View File

@ -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';");

View File

@ -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');

View File

@ -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');