adding slave domain management

This commit is contained in:
Benjamin Sonntag 2010-03-04 16:16:13 +00:00
parent 929f1808ba
commit 18022b34fb
8 changed files with 148 additions and 35 deletions

View File

@ -35,6 +35,7 @@ if (!isset($dns)) $dns="1";
?> ?>
<h3><?php __("Domain hosting"); ?></h3> <h3><?php __("Domain hosting"); ?></h3>
<hr />
<?php <?php
if (!$quota->cancreate("dom")) { ?> if (!$quota->cancreate("dom")) { ?>
<p class="error"><?php echo _("You cannot add any new domain, your quota is over.")." "._("Contact your administrator for more information."); ?></p> <p class="error"><?php echo _("You cannot add any new domain, your quota is over.")." "._("Contact your administrator for more information."); ?></p>
@ -44,14 +45,39 @@ exit();
if ($error) echo "<p class=\"error\">$error</p>"; if ($error) echo "<p class=\"error\">$error</p>";
?> ?>
<form method="post" action="dom_doadd.php" id="main"> <form method="post" action="dom_doadd.php" id="main">
<table><tr><td>
<b><label for="newdomain"><?php __("Domain name"); ?> : www.</label></b></td><td><input type="text" class="int" id="newdomain" name="newdomain" value="<?php echo $newdomain ?>" size="32" maxlength="255" />
</td></tr><tr><td></td><td><input type="submit" class="inb" name="submit" value="<?php __("Add this domain"); ?>" /></td></tr>
</table>
<p> <p>
<input type="checkbox" name="dns" class="inc" value="1" id="yndns" <?php if ($dns=="1") echo "checked=\"checked\""; ?> /><br /> <label for="newdomain"><b><?php __("Domain name"); ?> :</b></label> <span class="int" id="newdomwww">www.</span><input type="text" class="int" id="newdomain" name="newdomain" value="<?php echo $newdomain ?>" size="32" maxlength="255" />
<label for="yndns"><?php __("host my dns here"); ?></label>
</p> </p>
<p>
<input type="checkbox" name="dns" class="inc" value="1" id="yndns" <?php if ($dns=="1") echo "checked=\"checked\""; ?> />&nbsp;<label for="yndns"><?php __("host my dns here"); ?></label>
</p>
<?php
$q = $quota->getquota("dom");
if ($q["u"]>0) {
?>
<p>
<?php __("Do you want to point this domain to another domain already installed in your account?"); ?>
<br />
<input type="radio" id="newisslave0" name="newisslave" value="0" checked="checked" /><label for="newisslave0"><?php __("No: This domain will have its own folder."); ?></label>
<br />
<input type="radio" id="newisslave1" name="newisslave" value="1" /><label for="newisslave1"><?php __("Yes, redirect this new domain to this one: "); ?></label> <select name="slavedom" id="slavedom" class="inl">
<option value=""><?php __("-- Choose a domain --"); ?></option>
<?php
$dl=$dom->get_domain_list();
$ddl=array();
foreach($dl as $d) {
$ddl[$d]=$d;
}
eoption($ddl,"slavedom");
?></select>
<br />
</p>
<?php } ?>
<p>
<input type="submit" class="inb" name="submit" value="<?php __("Add this domain"); ?>" />
</p>
<p class="error"> <p class="error">
<small> <small>
<?php __("If you don't want to host in our server the DNS of your domain, don't check the box 'host my dns here'. If you don't know what it mean, leave it checked."); ?></small></p> <?php __("If you don't want to host in our server the DNS of your domain, don't check the box 'host my dns here'. If you don't know what it mean, leave it checked."); ?></small></p>

View File

@ -33,12 +33,14 @@ include_once("head.php");
$fields = array ( $fields = array (
"newdomain" => array ("post", "string", ""), "newdomain" => array ("post", "string", ""),
"dns" => array ("post", "string", ""), "dns" => array ("post", "string", ""),
"newisslave" => array ("post", "integer" ,0),
"slavedom" => array ("post", "string" ,0),
); );
getFields($fields); getFields($fields);
$dom->lock(); $dom->lock();
if (!$dom->add_domain($newdomain,$dns)) { if (!$dom->add_domain($newdomain,$dns,0,0,$newisslave,$slavedom)) {
$error=$err->errstr(); $error=$err->errstr();
include("dom_add.php"); include("dom_add.php");
exit(); exit();

View File

@ -97,7 +97,7 @@ for($i=0;$i<$r["nsub"];$i++) {
<input type="hidden" name="domain" value="<?php echo $r["name"]; ?>" /> <input type="hidden" name="domain" value="<?php echo $r["name"]; ?>" />
<input type="hidden" name="action" value="add" /> <input type="hidden" name="action" value="add" />
<?php __("Create a subdomain:"); ?> <?php __("Create a subdomain:"); ?>
<input type="text" class="int" name="sub" style="text-align:right" value="" size="22" id="sub" /><code>.<?php echo $domain; ?></code></td> <input type="text" class="int" name="sub" style="text-align:right" value="" size="22" id="sub" /><span class="int" id="newsubname">.<?php echo $domain; ?></span></td>
</tr> </tr>
<tr> <tr>
<td><input type="radio" id="local" class="inc" name="type" value="<?php echo $dom->type_local; ?>" checked="checked" onclick="document.main.sub_local.focus();" /> <td><input type="radio" id="local" class="inc" name="type" value="<?php echo $dom->type_local; ?>" checked="checked" onclick="document.main.sub_local.focus();" />
@ -105,7 +105,7 @@ for($i=0;$i<$r["nsub"];$i++) {
<td><input type="text" class="int" name="sub_local" id="sub_local" value="/" size="28" /> <td><input type="text" class="int" name="sub_local" id="sub_local" value="/" size="28" />
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" Choisir un r&eacute;pertoire... \" class=\"bff\">"); document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
// --> // -->
</script> </script>
</td> </td>

View File

@ -43,7 +43,7 @@ if (!$r=$dom->get_sub_domain_all($domain,$sub)) {
$dom->unlock(); $dom->unlock();
?> ?>
<h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?> : </h3> <h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3>
<?php <?php
if ($error) { if ($error) {
echo "<p class=\"erroe\">$error</p>"; echo "<p class=\"erroe\">$error</p>";
@ -52,10 +52,10 @@ $dom->unlock();
} }
?> ?>
<hr /> <hr />
<br />
<!-- ***************************************** <!-- *****************************************
gestion du sous-domaine gestion du sous-domaine
--> -->
<h3><?php __("Sub-domain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3>
<form action="dom_subdoedit.php" method="post" id="main" name="main"> <form action="dom_subdoedit.php" method="post" id="main" name="main">
<table border="0"> <table border="0">
<tr> <tr>
@ -68,7 +68,7 @@ $dom->unlock();
<td><input type="text" class="int" name="sub_local" id="sub_local" value="<?php ecif($r["type"]==0,$r["dest"],"/"); ?>" size="40" /> <td><input type="text" class="int" name="sub_local" id="sub_local" value="<?php ecif($r["type"]==0,$r["dest"],"/"); ?>" size="40" />
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" ... \" class=\"inb\">"); document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
// --> // -->
</script> </script>
</td> </td>
@ -88,10 +88,9 @@ $dom->unlock();
<label for="webmail"><?php __("Webmail access"); ?></label></td> <label for="webmail"><?php __("Webmail access"); ?></label></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<tr>
<td><input type="submit" class="inb" name="submit" value="<?php __("Validate this change"); ?>" /></td>
<td><input type="button" class="inb" name="back" value="<?php __("Cancel"); ?>" onclick="history.back();" /></td>
</tr>
</table> </table>
<br />
<input type="submit" class="inb" name="submit" value="<?php __("Validate this change"); ?>" />
<input type="button" class="inb" name="back" value="<?php __("Cancel"); ?>" onclick="history.back();" />
</form> </form>
<?php include_once("foot.php"); ?> <?php include_once("foot.php"); ?>

View File

@ -95,6 +95,7 @@ hr {
color: black; color: black;
background-color: #CFE3F1; background-color: #CFE3F1;
cursor: pointer; cursor: pointer;
margin-right: 4px;
} }
.inb:hover { .inb:hover {
background-color: #BFD3E1; background-color: #BFD3E1;
@ -144,9 +145,8 @@ hr {
border: 1px dotted black; border: 1px dotted black;
background-color: white; background-color: white;
font-family: Verdana, Arial, Helvetica, sans-serif; font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px; font-size: 11px;
padding-left: 2px; padding: 2px;
padding-right: 2px;
color: black; color: black;
} }
@ -213,8 +213,9 @@ img {
#content { #content {
display: block; display: block;
width: 740px; width: 730px;
padding-left: 10px; padding-left: 10px;
padding-right: 10px;
vertical-align: top; vertical-align: top;
} }
@ -349,4 +350,21 @@ a:hover {
.breadcrumb { .breadcrumb {
font-size: 12px; font-size: 12px;
} }
#newdomwww {
border-right: 0;
padding-right: 0;
}
#newdomain {
border-left: 0;
padding-left: 0;
}
#sub {
border-right: 0;
padding-right: 0;
}
#newsubname {
border-left: 0;
padding-left: 0;
}

View File

@ -398,5 +398,19 @@ function duration_list($name, $selected=0) {
return $res; return $res;
} }
/* select_values($arr,$cur) echo des <option> du tableau $values ou de la table sql $values
selectionne $current par defaut. Par defaut prends les champs 0 comme id et 1 comme
donnees pour la table. sinon utilise $info[0] et $info[1].
*/
function eoption($values,$cur,$info="") {
if (is_array($values)) {
foreach ($values as $k=>$v) {
echo "<option value=\"$k\"";
if ($k==$cur) echo " selected=\"selected\"";
echo ">".$v."</option>";
}
}
}
?> ?>

View File

@ -178,7 +178,7 @@ class m_dom {
* force ne devrait être utilisé que par le super-admin. * force ne devrait être utilisé que par le super-admin.
$ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. $ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
*/ */
function add_domain($domain,$dns,$noerase=0,$force=0) { function add_domain($domain,$dns,$noerase=0,$force=0,$isslave,$slavedom) {
global $db,$err,$quota,$classes,$L_MX,$L_FQDN,$tld,$cuid,$bro; global $db,$err,$quota,$classes,$L_MX,$L_FQDN,$tld,$cuid,$bro;
$err->log("dom","add_domain",$domain); $err->log("dom","add_domain",$domain);
$mx="1"; $mx="1";
@ -257,21 +257,36 @@ class m_dom {
$db->query("insert into domaines (compte,domaine,mx,gesdns,gesmx,noerase) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase');"); $db->query("insert into domaines (compte,domaine,mx,gesdns,gesmx,noerase) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase');");
$db->query("insert into domaines_standby (compte,domaine,mx,gesdns,gesmx,action) values ('$cuid','$domain','$L_MX','$dns','$mx',0);"); // INSERT $db->query("insert into domaines_standby (compte,domaine,mx,gesdns,gesmx,action) values ('$cuid','$domain','$L_MX','$dns','$mx',0);"); // INSERT
// Creation du repertoire dans www if ($isslave) {
$dest_root = $bro->get_userid_root($cuid); $isslave=true;
$domshort=str_replace("-","",str_replace(".","",$domain)); $db->query("SELECT domaine FROM domaines WHERE compte='$cuid' AND domaine='$slavedom';");
$db->next_record();
if (! is_dir($dest_root . "/". $domshort)) { if (!$db->Record["domaine"]) {
mkdir($dest_root . "/". $domshort); $err->raise("dom",1,$slavedom);
$isslave=false;
}
// Point to the master domain :
$this->set_sub_domain($domain, '', $this->type_url,'add', 'http://www.'.$slavedom);
$this->set_sub_domain($domain, 'www', $this->type_url,'add', 'http://www.'.$slavedom);
$this->set_sub_domain($domain, 'mail', $this->type_url,'add', 'http://mail.'.$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)) {
mkdir($dest_root . "/". $domshort);
}
// Creation des 3 sous-domaines par défaut : Vide, www et mail
$this->set_sub_domain($domain, '', $this->type_url, 'add', 'http://www.'.$domain);
$this->set_sub_domain($domain, 'www', $this->type_local, 'add', '/'. $domshort);
$this->set_sub_domain($domain, 'mail', $this->type_webmail, 'add', '');
} }
// Creation des 3 sous-domaines par défaut : Vide, www et mail
$this->set_sub_domain($domain, '', $this->type_url, 'add', 'http://www.'.$domain);
$this->set_sub_domain($domain, 'www', $this->type_local, 'add', '/'. $domshort);
$this->set_sub_domain($domain, 'mail', $this->type_webmail, 'add', '');
// DEPENDANCE : // DEPENDANCE :
// Lancement de add_dom sur les classes domain_sensitive : // Lancement de add_dom sur les classes domain_sensitive :
// Declenchons les autres classes. // Declenchons les autres classes.
foreach($classes as $c) { foreach($classes as $c) {
if (method_exists($GLOBALS[$c],"alternc_add_domain")) { if (method_exists($GLOBALS[$c],"alternc_add_domain")) {
$GLOBALS[$c]->alternc_add_domain($domain); $GLOBALS[$c]->alternc_add_domain($domain);
@ -282,7 +297,14 @@ class m_dom {
$GLOBALS[$c]->alternc_add_mx_domain($domain); $GLOBALS[$c]->alternc_add_mx_domain($domain);
} }
} }
return true; if ($isslave) {
foreach($classes as $c) {
if (method_exists($GLOBALS[$c],"alternc_add_slave_domain")) {
$GLOBALS[$c]->alternc_add_slave_domain($domain,$slavedom);
}
}
}
return true;
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
@ -948,6 +970,22 @@ class m_dom {
return true; return true;
} }
/* ----------------------------------------------------------------- */
/**
* Returns the complete hosted domain list :
*/
function get_domain_list() {
global $db,$err;
$res=array();
$db->query("SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine");
while ($db->next_record()) {
$res[]=$db->f("domaine");
}
return $res;
}
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** /**
* Return the list of allowed slave accounts * Return the list of allowed slave accounts

View File

@ -695,6 +695,22 @@ class m_mail {
} }
/* ----------------------------------------------------------------- */
/** hook function called by AlternC when a domain is created for
* the current user account using the SLAVE DOMAIN feature
* This function create a CATCHALL to the master domain
* @param string $dom Domain that has just been created
* @param string $master Master domain
* @access private
*/
function alternc_add_slave_domain($dom,$slave) {
global $err;
$err->log("mail","alternc_add_slave_domain",$dom);
$this->add_mail($dom,"",0,"","@".$slave);
return true;
}
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** /**
* Returns the used quota for the $name service for the current user. * Returns the used quota for the $name service for the current user.