Ajout de la possibilité d'avoir des CNAME, TXT dans les DNS.

Possibilitée d'avoir plusieurs entrée sur le même sous-domaine.
ToDo : Merci aux experts Alternc de regarder si j'ai mit les modifications de base dans le bon fichier (install/upgrades/1.0.sql)
This commit is contained in:
Alan Garcia 2010-11-16 17:11:06 +00:00
parent 33cb13286b
commit 3343aa803a
11 changed files with 245 additions and 93 deletions

1
.gitattributes vendored
View File

@ -392,6 +392,7 @@ install/upgrades/0.9.5.sql -text
install/upgrades/0.9.6.sql -text install/upgrades/0.9.6.sql -text
install/upgrades/0.9.7.sql -text install/upgrades/0.9.7.sql -text
install/upgrades/0.9.9.sql -text install/upgrades/0.9.9.sql -text
install/upgrades/1.0.sql -text
install/upgrades/README -text install/upgrades/README -text
man/alternc-admintools.8 -text man/alternc-admintools.8 -text
man/alternc-admintools.fr.8 -text man/alternc-admintools.fr.8 -text

View File

@ -37,6 +37,9 @@ $fields = array (
"sub_local" => array ("request", "string", "/"), "sub_local" => array ("request", "string", "/"),
"sub_url" => array ("request", "string", "http://"), "sub_url" => array ("request", "string", "http://"),
"sub_ip" => array ("request", "string", ""), "sub_ip" => array ("request", "string", ""),
"sub_ipv6" => array ("request", "string", ""),
"sub_cname" => array ("request", "string", ""),
"sub_txt" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
@ -87,10 +90,10 @@ for($i=0;$i<$r["nsub"];$i++) {
?> ?>
<tr class="lst<?php echo $col; ?>"> <tr class="lst<?php echo $col; ?>">
<td class="center"> <td class="center">
<div class="ina"><a href="dom_subedit.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div> <div class="ina"><a href="dom_subedit.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&amp;type=<?php echo urlencode($r["sub"][$i]["type"]) ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div>
</td><td class="center"> </td><td class="center">
<div class="ina"><a href="dom_subdel.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div> <div class="ina"><a href="dom_subdel.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&amp;type=<?php echo urlencode($r["sub"][$i]["type"]) ?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div>
</td> </td>
<td><a href="http://<?php ecif($r["sub"][$i]["name"],$r["sub"][$i]["name"]."."); echo $r["name"] ?>" target="_blank"><?php ecif($r["sub"][$i]["name"],$r["sub"][$i]["name"]."."); echo $r["name"] ?></a></td> <td><a href="http://<?php ecif($r["sub"][$i]["name"],$r["sub"][$i]["name"]."."); echo $r["name"] ?>" target="_blank"><?php ecif($r["sub"][$i]["name"],$r["sub"][$i]["name"]."."); echo $r["name"] ?></a></td>
<td><?php echo $r["sub"][$i]['type'] === '0' ? '<a href="bro_main.php?R='.urlencode($r["sub"][$i]["dest"]).'">'.htmlspecialchars($r["sub"][$i]["dest"]).'</a>' : htmlspecialchars($r["sub"][$i]["dest"]); ?>&nbsp;</td> <td><?php echo $r["sub"][$i]['type'] === '0' ? '<a href="bro_main.php?R='.urlencode($r["sub"][$i]["dest"]).'">'.htmlspecialchars($r["sub"][$i]["dest"]).'</a>' : htmlspecialchars($r["sub"][$i]["dest"]); ?>&nbsp;</td>
@ -125,6 +128,11 @@ for($i=0;$i<$r["nsub"];$i++) {
<label for="url" ><?php __("URL redirection"); ?></label></td> <label for="url" ><?php __("URL redirection"); ?></label></td>
<td><input type="text" class="int" name="sub_url" id="sub_url" value="<?php ehe($sub_url); ?>" size="50" /></td> <td><input type="text" class="int" name="sub_url" id="sub_url" value="<?php ehe($sub_url); ?>" size="50" /></td>
</tr> </tr>
<tr>
<td><input type="radio" id="webmail" class="inc" name="type" value="<?php echo $dom->type_webmail; ?>" <?php cbox($type==$dom->type_webmail); ?>/>
<label for="webmail"><?php __("Webmail access"); ?></label></td>
<td>&nbsp;</td>
</tr>
<?php if ($r["dns"]) { // show only if dns is enabled ?> <?php if ($r["dns"]) { // show only if dns is enabled ?>
<tr> <tr>
<td><input type="radio" id="ip" class="inc" name="type" value="<?php echo $dom->type_ip; ?>" <?php cbox($type==$dom->type_ip); ?> onclick="document.main.sub_ip.focus();" /> <td><input type="radio" id="ip" class="inc" name="type" value="<?php echo $dom->type_ip; ?>" <?php cbox($type==$dom->type_ip); ?> onclick="document.main.sub_ip.focus();" />
@ -132,18 +140,27 @@ for($i=0;$i<$r["nsub"];$i++) {
<td><input type="text" class="int" name="sub_ip" id="sub_ip" value="<?php ehe($sub_ip); ?>" size="16" /> <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small></td> <td><input type="text" class="int" name="sub_ip" id="sub_ip" value="<?php ehe($sub_ip); ?>" size="16" /> <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small></td>
</tr> </tr>
<tr> <tr><td colspan=2 style="background-color: #CFE3F1;color: #007777;font-weight:bold;" >Advanced options</td></tr>
<td><input type="radio" id="ipv6" class="inc" name="type" value="<?php echo $dom->type_ipv6; ?>" <?php cbox($type==$dom->type_ipv6); ?> onclick="document.main.sub_ip.focus();" /> <tr id="advopt1">
<td><input type="radio" id="ipv6" class="inc" name="type" value="<?php echo $dom->type_ipv6; ?>" <?php cbox($type==$dom->type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" />
<label for="ipv6"><?php __("IPv6 redirection"); ?></label></td> <label for="ipv6"><?php __("IPv6 redirection"); ?></label></td>
<td><input type="text" class="int" name="sub_ipv6" id="sub_ipv6" value="<?php ehe($sub_ipv6); ?>" size="32" /> <small><?php __("(enter an IPv6 address, for example 2001:0910::)"); ?></small></td> <td><input type="text" class="int" name="sub_ipv6" id="sub_ipv6" value="<?php ehe($sub_ipv6); ?>" size="32" /> <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small></td>
</tr> </tr>
<? } ?> <tr id="advopt2">
<tr> <td><input type="radio" id="cname" class="inc" name="type" value="<?php echo $dom->type_cname; ?>" <?php cbox($type==$dom->type_cname); ?> onclick="document.main.sub_cname.focus();" />
<td><input type="radio" id="webmail" class="inc" name="type" value="<?php echo $dom->type_webmail; ?>" <?php cbox($type==$dom->type_webmail); ?>/> <label for="cname"><?php __("CNAME redirection"); ?></label></td>
<label for="webmail"><?php __("Webmail access"); ?></label></td> <td><input type="text" class="int" name="sub_cname" id="sub_cname" value="<?php ehe($sub_cname); ?>" size="32" /> <small><?php __("(enter a server address or a subdomain)"); ?></small></td>
<td>&nbsp;</td>
</tr> </tr>
<tr id="advopt3">
<td><input type="radio" id="txt" class="inc" name="type" value="<?php echo $dom->type_txt; ?>" <?php cbox($type==$dom->type_txt); ?> onclick="document.main.sub_txt.focus();" />
<label for="txt"><?php __("TXT information"); ?></label></td>
<td><input type="text" class="int" name="sub_txt" id="sub_txt" value="<?php ehe($sub_txt); ?>" size="32" /> <small><?php __("(enter a TXT informations for this domain)"); ?></small></td>
</tr>
<? } ?>
<tr class="trbtn"> <tr class="trbtn">
<td colspan="2"><input type="submit" class="inb" name="add" value="<?php __("Add this subdomain"); ?>" /></td> <td colspan="2"><input type="submit" class="inb" name="add" value="<?php __("Add this subdomain"); ?>" /></td>
</tr> </tr>

View File

@ -33,11 +33,12 @@ include_once("head.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "domain" => array ("request", "string", ""),
"sub" => array ("request", "string", ""), "sub" => array ("request", "string", ""),
"type" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
$dom->lock(); $dom->lock();
if (!$r=$dom->get_sub_domain_all($domain,$sub)) { if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) {
$error=$err->errstr(); $error=$err->errstr();
} }
$dom->unlock(); $dom->unlock();
@ -60,6 +61,7 @@ $dom->unlock();
<p class="error"> <p class="error">
<input type="hidden" name="domain" value="<?php echo $domain ?>" /> <input type="hidden" name="domain" value="<?php echo $domain ?>" />
<input type="hidden" name="sub" value="<?php echo $sub ?>" /> <input type="hidden" name="sub" value="<?php echo $sub ?>" />
<input type="hidden" name="type" value="<?php echo $type ?>" />
<?php __("WARNING : Confirm the deletion of the subdomain"); ?> : </p> <?php __("WARNING : Confirm the deletion of the subdomain"); ?> : </p>
<p><?php ecif($sub,$sub."."); echo $domain; ?></p> <p><?php ecif($sub,$sub."."); echo $domain; ?></p>
<blockquote> <blockquote>

View File

@ -33,12 +33,13 @@ include_once("head.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "domain" => array ("request", "string", ""),
"sub" => array ("request", "string", ""), "sub" => array ("request", "string", ""),
"type" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
$dom->lock(); $dom->lock();
if (!$dom->del_sub_domain($domain,$sub)) { if (!$dom->del_sub_domain($domain,$sub,$type)) {
$error=$err->errstr(); $error=$err->errstr();
} }

View File

@ -32,10 +32,13 @@ require_once("../class/config.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "domain" => array ("request", "string", ""),
"sub" => array ("request", "string", ""), "sub" => array ("request", "string", ""),
"type_old" => array ("request", "integer",""),
"type" => array ("request", "integer", $dom->type_local), "type" => array ("request", "integer", $dom->type_local),
"sub_local" => array ("request", "string", "/"), "sub_local" => array ("request", "string", "/"),
"sub_url" => array ("request", "string", "http://"), "sub_url" => array ("request", "string", "http://"),
"sub_ip" => array ("request", "string", ""), "sub_ip" => array ("request", "string", ""),
"sub_txt" => array ("request", "string", ""),
"sub_cname" => array ("request", "string", ""),
"sub_ipv6" => array ("request", "string", ""), "sub_ipv6" => array ("request", "string", ""),
"action" => array ("request", "string", "add"), "action" => array ("request", "string", "add"),
); );
@ -45,19 +48,25 @@ $dom->lock();
switch ($type) { switch ($type) {
case $dom->type_local: case $dom->type_local:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_local); $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_local, $type_old);
break; break;
case $dom->type_url: case $dom->type_url:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_url); $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_url, $type_old);
break;
case $dom->type_txt:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_txt, $type_old);
break;
case $dom->type_cname:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_cname, $type_old);
break; break;
case $dom->type_ip: case $dom->type_ip:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip); $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip, $type_old);
break; break;
case $dom->type_ipv6: case $dom->type_ipv6:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6); $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6, $type_old);
break; break;
case $dom->type_webmail: case $dom->type_webmail:
$r=$dom->set_sub_domain($domain,$sub,$type,$action,""); $r=$dom->set_sub_domain($domain,$sub,$type,$action,"", $type_old);
break; break;
} }
$dom->unlock(); $dom->unlock();

View File

@ -38,13 +38,15 @@ $fields = array (
"sub_url" => array ("request", "string", "http://"), "sub_url" => array ("request", "string", "http://"),
"sub_ip" => array ("request", "string", ""), "sub_ip" => array ("request", "string", ""),
"sub_ipv6" => array ("request", "string", ""), "sub_ipv6" => array ("request", "string", ""),
"sub_cname" => array ("request", "string", ""),
"sub_txt" => array ("request", "string", ""),
"action" => array ("request", "string", "add"), "action" => array ("request", "string", "add"),
); );
getFields($fields); getFields($fields);
$dom->lock(); $dom->lock();
if (!$noread) { if (!$noread) {
if (!$r=$dom->get_sub_domain_all($domain,$sub)) { if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) {
$error=$err->errstr(); $error=$err->errstr();
?> ?>
<h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3> <h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3>
@ -63,6 +65,12 @@ switch ($type) {
case $dom->type_url: case $dom->type_url:
$sub_url=$r["dest"]; $sub_url=$r["dest"];
break; break;
case $dom->type_cname:
$sub_cname=$r["dest"];
break;
case $dom->type_txt:
$sub_txt=$r["dest"];
break;
case $dom->type_ipv6: case $dom->type_ipv6:
$sub_ipv6=$r["dest"]; $sub_ipv6=$r["dest"];
break; break;
@ -93,6 +101,7 @@ $dom->unlock();
<tr> <tr>
<td> <input type="hidden" name="domain" value="<?php ehe($domain); ?>" /> <td> <input type="hidden" name="domain" value="<?php ehe($domain); ?>" />
<input type="hidden" name="sub" value="<?php echo ehe($sub); ?>" /> <input type="hidden" name="sub" value="<?php echo ehe($sub); ?>" />
<input type="hidden" name="type_old" value="<?php echo ehe($type); ?>" />
<input type="hidden" name="action" value="edit" /> <input type="hidden" name="action" value="edit" />
<input type="radio" id="local" class="inc" name="type" value="<?php echo $dom->type_local; ?>" <?php cbox($r["type"]==$dom->type_local); ?> onclick="document.main.sub_local.focus();" /> <input type="radio" id="local" class="inc" name="type" value="<?php echo $dom->type_local; ?>" <?php cbox($r["type"]==$dom->type_local); ?> onclick="document.main.sub_local.focus();" />
@ -117,17 +126,32 @@ $dom->unlock();
<td><input type="text" class="int" name="sub_ip" id="sub_ip" value="<?php ehe($sub_ip); ?>" size="16" /> <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small></td> <td><input type="text" class="int" name="sub_ip" id="sub_ip" value="<?php ehe($sub_ip); ?>" size="16" /> <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small></td>
<tr>
<td><input type="radio" id="ipv6" class="inc" name="type" value="<?php echo $dom->type_ipv6; ?>" <?php cbox($type==$dom->type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" />
<label for="ipv6"><?php __("IPv6 redirection"); ?></label></td>
<td><input type="text" class="int" name="sub_ipv6" id="sub_ipv6" value="<?php ehe($sub_ipv6); ?>" size="16" /> <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small></td>
</tr>
<tr> <tr>
<td><input type="radio" id="webmail" class="inc" name="type" value="<?php echo $dom->type_webmail; ?>" <?php cbox($r["type"]==$dom->type_webmail); ?> /> <td><input type="radio" id="webmail" class="inc" name="type" value="<?php echo $dom->type_webmail; ?>" <?php cbox($r["type"]==$dom->type_webmail); ?> />
<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 colspan=2 style="background-color: #CFE3F1;color: #007777;font-weight:bold;" >Advanced options</td></tr>
<tr id="advopt1">
<td><input type="radio" id="ipv6" class="inc" name="type" value="<?php echo $dom->type_ipv6; ?>" <?php cbox($type==$dom->type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" />
<label for="ipv6"><?php __("IPv6 redirection"); ?></label></td>
<td><input type="text" class="int" name="sub_ipv6" id="sub_ipv6" value="<?php ehe($sub_ipv6); ?>" size="32" /> <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small></td>
</tr>
<tr id="advopt2">
<td><input type="radio" id="cname" class="inc" name="type" value="<?php echo $dom->type_cname; ?>" <?php cbox($type==$dom->type_cname); ?> onclick="document.main.sub_cname.focus();" />
<label for="cname"><?php __("CNAME redirection"); ?></label></td>
<td><input type="text" class="int" name="sub_cname" id="sub_cname" value="<?php ehe($sub_cname); ?>" size="32" /> <small><?php __("(enter a server address or a subdomain)"); ?></small></td>
</tr>
<tr id="advopt3">
<td><input type="radio" id="txt" class="inc" name="type" value="<?php echo $dom->type_txt; ?>" <?php cbox($type==$dom->type_txt); ?> onclick="document.main.sub_txt.focus();" />
<label for="txt"><?php __("TXT information"); ?></label></td>
<td><input type="text" class="int" name="sub_txt" id="sub_txt" value="<?php ehe($sub_txt); ?>" size="32" /> <small><?php __("(enter a TXT informations for this domain)"); ?></small></td>
</tr>
<tr class="trbtn"> <tr class="trbtn">
<td colspan="2"> <td colspan="2">
<input type="submit" class="inb" name="submit" value="<?php __("Validate this change"); ?>" /> <input type="submit" class="inb" name="submit" value="<?php __("Validate this change"); ?>" />

View File

@ -115,22 +115,25 @@ function checkurl($url) {
return true; return true;
} }
/* Check that TXT domain is correct */
function checksubtxt($txt) {
return true;
}
/* Check that CNAME domain is correct */
function checkcname($cname) {
return true;
}
/* Check that $ip is a correct 4 Dotted ip */ /* Check that $ip is a correct 4 Dotted ip */
function checkip($ip) { function checkip($ip) {
// return true or false whether the ip is correctly formatted // return true or false whether the ip is correctly formatted
if (!ereg("[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*",$ip)) return false; return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
$l=explode(".",$ip);
if ($l[0]>255 || $l[1]>255 || $l[2]>255 || $l[3]>255) return false;
return true;
} }
/* Check that $ip is a correct ipv6 ip */ /* Check that $ip is a correct ipv6 ip */
function checkipv6($ip) { function checkipv6($ip) {
// return true or false whether the ip is correctly formatted // return true or false whether the ip is correctly formatted
$pattern = return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
'/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/';
return preg_match( $pattern, $ip ) ? TRUE : FALSE;
} }
/* Check a login mail */ /* Check a login mail */

View File

@ -71,6 +71,8 @@ class m_dom {
var $type_ip = "2"; var $type_ip = "2";
var $type_webmail = "3"; var $type_webmail = "3";
var $type_ipv6 = "4"; var $type_ipv6 = "4";
var $type_cname = "5";
var $type_txt = "6";
var $action_insert = "0"; var $action_insert = "0";
var $action_update= "1"; var $action_update= "1";
@ -631,7 +633,7 @@ class m_dom {
* $r["type"]= Type (0-n) de la redirection. * $r["type"]= Type (0-n) de la redirection.
* Retourne FALSE si une erreur s'est produite. * Retourne FALSE si une erreur s'est produite.
*/ */
function get_sub_domain_all($dom,$sub) { function get_sub_domain_all($dom,$sub, $type = "") {
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","get_sub_domain_all",$dom."/".$sub); $err->log("dom","get_sub_domain_all",$dom."/".$sub);
// Locked ? // Locked ?
@ -644,7 +646,10 @@ class m_dom {
$err->raise("dom",3+$t); $err->raise("dom",3+$t);
return false; return false;
} }
$db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub'"); if ( ! empty($type)) {
$type = " and type='".intval($type)."'";
}
$db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' $type");
if ($db->num_rows()==0) { if ($db->num_rows()==0) {
$err->raise("dom",14); $err->raise("dom",14);
return false; return false;
@ -675,7 +680,8 @@ class m_dom {
* de $type (url, ip, dossier...) * de $type (url, ip, dossier...)
* @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 set_sub_domain($dom,$sub,$type,$action,$dest) { function set_sub_domain($dom,$sub,$type,$action,$dest, $type_old=null) {
if (is_null($type_old)) $type_old=$type;
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","set_sub_domain",$dom."/".$sub); $err->log("dom","set_sub_domain",$dom."/".$sub);
// Locked ? // Locked ?
@ -697,29 +703,41 @@ class m_dom {
} }
if ($type==2) { // IP if ($type==2) { // IP
if (!checkip($dest)) { if (!checkip($dest)) {
$err->raise("dom",19); $err->raise("dom",19);
return false; return false;
} }
} }
if ($type==4) { // IPv6 if ($type==4) { // IPv6
if (!checkipv6($dest)) { if (!checkipv6($dest)) {
$err->raise("dom",19); $err->raise("dom",19);
return false; return false;
}
}
if ($type==5) { // Cname
if (!checkcname($dest)) {
$err->raise("dom",19);
return false;
}
}
if ($type==6) { // TXT
if (!checksubtxt($dest)) {
$err->raise("dom",19);
return false;
} }
} }
if ($type==1) { // URL if ($type==1) { // URL
if (!checkurl($dest)) { if (!checkurl($dest)) {
$err->raise("dom",20); $err->raise("dom",20);
return false; return false;
} }
} }
if ($type==0) { // LOCAL if ($type==0) { // LOCAL
if (substr($dest,0,1)!="/") { if (substr($dest,0,1)!="/") {
$dest="/".$dest; $dest="/".$dest;
} }
if (!checkuserpath($dest)) { if (!checkuserpath($dest)) {
$err->raise("dom",21); $err->raise("dom",21);
return false; return false;
} }
} }
// On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur. // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
@ -728,31 +746,59 @@ class m_dom {
$err->raise("dom",3+$t); $err->raise("dom",3+$t);
return false; return false;
} }
if (!$r=$this->get_sub_domain_all($dom,$sub)) {
// Le sous-domaine n'existe pas, on le crée seulement si $action vaut add
if ($action=="add") { // Si l'action demandé est une création
$db->query("insert into sub_domaines (compte,domaine,sub,valeur,type) values ('$cuid','$dom','$sub','$dest',$type);"); if ($action=="add") {
$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub';"); $do_create=false;
$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',0);"); // INSERT // Tout d'abord on vérifie si il faut le créer
} else { $r=$this->get_sub_domain_all($dom,$sub);
$err->raise("dom",14); if ( !$r) { $do_create=true ;}; // If subdomains do not exist
return false; if ($r and (!in_array($type, Array(0,1,3))) ) { // Les types URL, LOCAL et WEBMAIL ne peuvent pas être en doublon
} foreach($r as $rr) { $rtype[] = $rr['type'];} // Tableau pour vérifier les compatibilitées de type
if (
( $type==$this->type_ipv6 and (in_array($this->type_cname, $rtype)) ) or
( $type==$this->type_ipv4 and (in_array($this->type_cname, $rtype)) ) or
( $type==$this->type_cname and (in_array($this->type_ipv4, $rtype)) ) or
( $type==$this->type_cname and (in_array($this->type_ipv6, $rtype)) )
) { $do_create=false; } else {$do_create=true ;}
}
if ($do_create) {
// Tout est, je peux créer le sous-domaine
$db->query("insert into sub_domaines (compte,domaine,sub,valeur,type) values ('$cuid','$dom','$sub','$dest',$type);");
$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type=$type;");
$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',0);"); // INSERT
} else {
$err->raise("dom",14);
return false;
}
}elseif ($action=="edit") {
// On vérifie que des modifications ont bien eu lieu :)
if ($r["type"]==$type && $r["dest"]==$dest) {
$err->raise("dom",15);
return false;
}
// OK, des modifs ont été faites, on valide :
//$db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub' and type='".$r["type"]."'");
//$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type='".$r["type"]."'");
//$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE
/*
$type contient la valeur QUE LON VEUT DONNER au sous domaine
$type_old contient la valeur du subdomain QUE LON VEUX EDITER
die(" XXXX type = $type ---- type_old = $type_old XXXX ");
*/
if ($type != $type_old) {
$this->del_sub_domain($dom,$sub,$type_old);
$this->set_sub_domain($dom,$sub,$type,"add",$dest);
} else {
$db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub' and type='$type_old';");
$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' and type='$type_old';");
$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE
}
} else { } else {
if ($action=="edit") { $err->raise("dom",16);
// On vérifie que des modifications ont bien eu lieu :) return false;
if ($r["type"]==$type && $r["dest"]==$dest) {
$err->raise("dom",15);
return false;
}
// OK, des modifs ont été faites, on valide :
$db->query("update sub_domaines set type='$type', valeur='$dest' where domaine='$dom' and sub='$sub'");
$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'");
$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','$dest','$type',1);"); // UPDATE
} else {
$err->raise("dom",16);
return false;
}
} }
return true; return true;
} // set_sub_domain } // set_sub_domain
@ -766,7 +812,7 @@ class m_dom {
* @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 del_sub_domain($dom,$sub) { function del_sub_domain($dom,$sub,$type) {
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","del_sub_domain",$dom."/".$sub); $err->log("dom","del_sub_domain",$dom."/".$sub);
// Locked ? // Locked ?
@ -779,14 +825,14 @@ class m_dom {
$err->raise("dom",3+$t); $err->raise("dom",3+$t);
return false; return false;
} }
if (!$r=$this->get_sub_domain_all($dom,$sub)) { if (!$r=$this->get_sub_domain_all($dom,$sub,$type)) {
// Le sous-domaine n'existe pas, erreur // Le sous-domaine n'existe pas, erreur
$err->raise("dom",14); $err->raise("dom",14);
return false; return false;
} else { } else {
// OK, on valide : // OK, on valide :
$db->query("delete from sub_domaines where domaine='$dom' and sub='$sub'"); $db->query("delete from sub_domaines where domaine='$dom' and sub='$sub' and type='$type'");
$db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub'"); $db->query("delete from sub_domaines_standby where domaine='$dom' and sub='$sub' type='$type");
$db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','".$r["dest"]."','".$r["type"]."',2);"); // DELETE $db->query("insert into sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$dom','$sub','".$r["dest"]."','".$r["type"]."',2);"); // DELETE
} }
return true; return true;

7
install/upgrades/1.0.sql Normal file
View File

@ -0,0 +1,7 @@
-- Alter table to allow use of ipv6, cname and txt in dns record
ALTER TABLE sub_domaines_standby DROP PRIMARY KEY;
ALTER TABLE sub_domaines_standby ADD CONSTRAINT pk_SubDomainesStandby PRIMARY KEY (compte,domaine,sub,action,type);
-- Alter table to allow use of ipv6, cname and txt in dns record
ALTER TABLE sub_domaines DROP PRIMARY KEY;
ALTER TABLE sub_domaines ADD CONSTRAINT pk_SubDomaines PRIMARY KEY (compte,domaine,sub,type);

View File

@ -105,13 +105,25 @@ change_host_ip() {
if [ -z "$host" ]; then if [ -z "$host" ]; then
host="@" host="@"
fi fi
if [ "$host_type" = "$TYPE_IPV6" ]; then
a_line="$host IN AAAA $ip" case "$host_type" in
pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]*.*\$" "$TYPE_IPV6")
else a_line="$host IN AAAA $ip"
a_line="$host IN A $ip" pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]+.+\$"
pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]*.*\$" ;;
fi "$TYPE_CNAME")
a_line="$host IN CNAME $ip"
pattern="^$host[[:space:]]*IN[[:space:]]*CNAME[[:space:]]+.+\$"
;;
"$TYPE_TXT")
a_line="$host IN TXT $ip"
pattern="^$host[[:space:]]*IN[[:space:]]*TXT[[:space:]]+.+\$"
;;
*)
a_line="$host IN A $ip"
pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]+.+\$"
esac
if [ ! -f "$zone_file" ]; then if [ ! -f "$zone_file" ]; then
echo "Should change $host.$domain, but can't find $zone_file." echo "Should change $host.$domain, but can't find $zone_file."
return 1 return 1
@ -138,7 +150,7 @@ add_host() {
local fqdn local fqdn
local vhost_directory local vhost_directory
delete_host "$domain" "$host" delete_host "$domain" "$host" "$host_type"
if [ "$host" = "@" -o -z "$host" ]; then if [ "$host" = "@" -o -z "$host" ]; then
FQDN="$domain" FQDN="$domain"
@ -146,16 +158,28 @@ add_host() {
FQDN="$host.$domain" FQDN="$host.$domain"
fi fi
if [ "$host_type" = "$TYPE_IP" ]; then case "$host_type" in
ip="$value" "$TYPE_IP")
elif [ "$host_type" = "$TYPE_IPV6" ]; then ip="$value"
ip="$value" ;;
else "$TYPE_IPV6")
ip="$PUBLIC_IP" ip="$value"
if [ "$host_type" != "$TYPE_WEBMAIL" ]; then ;;
add_to_php_override "$FQDN" "$TYPE_CNAME")
fi ip="$value"
fi ;;
"$TYPE_TXT")
ip="$value"
;;
"$TYPE_WEBMAIL")
ip="$PUBLIC_IP"
add_to_php_override "$FQDN"
;;
*)
ip="$PUBLIC_IP"
;;
esac
if [ "$host" = "@" -o -z "$host" ]; then if [ "$host" = "@" -o -z "$host" ]; then
change_host_ip "$domain" "$ip" || true change_host_ip "$domain" "$ip" || true
fqdn="$domain" fqdn="$domain"
@ -203,10 +227,12 @@ add_host() {
delete_host() { delete_host() {
local domain="$1" local domain="$1"
local host="$2" local host="$2"
local host_type="$3"
local domain_letter=`print_domain_letter "$domain"` local domain_letter=`print_domain_letter "$domain"`
local fqdn local fqdn
local escaped_host local escaped_host
local escaped_fqdn local escaped_fqdn
local pattern
if [ "$host" = "@" -o -z "$host" ]; then if [ "$host" = "@" -o -z "$host" ]; then
fqdn="$domain" fqdn="$domain"
@ -218,8 +244,22 @@ delete_host() {
if [ -f "$ZONES_DIR/$domain" ] ; then if [ -f "$ZONES_DIR/$domain" ] ; then
cp -a -f "$ZONES_DIR/$domain" "$ZONES_DIR/$domain.$$" cp -a -f "$ZONES_DIR/$domain" "$ZONES_DIR/$domain.$$"
sed -e "/^$escaped_host[[:space:]]*IN[[:space:]]*\(AAAA\|A\)[[:space:]]/d" \
< "$ZONES_DIR/$domain" > "$ZONES_DIR/$domain.$$" case "$host_type" in
"$TYPE_IPV6")
pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]/d"
;;
"$TYPE_CNAME")
pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*CNAME[[:space:]]/d"
;;
"$TYPE_TXT")
pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*TXT[[:space:]]/d"
;;
*)
pattern="/^$escaped_host[[:space:]]*IN[[:space:]]*A[[:space:]]/d"
esac
sed -e "$pattern" < "$ZONES_DIR/$domain" > "$ZONES_DIR/$domain.$$"
mv "$ZONES_DIR/$domain.$$" "$ZONES_DIR/$domain" mv "$ZONES_DIR/$domain.$$" "$ZONES_DIR/$domain"
increment_serial "$domain" increment_serial "$domain"
add_to_named_reload "$domain" add_to_named_reload "$domain"

View File

@ -54,6 +54,8 @@ TYPE_URL=1
TYPE_IP=2 TYPE_IP=2
TYPE_WEBMAIL=3 TYPE_WEBMAIL=3
TYPE_IPV6=4 TYPE_IPV6=4
TYPE_CNAME=5
TYPE_TXT=6
YES=1 YES=1
if [ `id -u` -ne 0 ]; then if [ `id -u` -ne 0 ]; then
@ -226,7 +228,7 @@ while read user domain host value type action; do
;; ;;
$ACTION_DELETE) $ACTION_DELETE)
delete_host "$domain" "$host" delete_host "$domain" "$host" "$type"
;; ;;
*) *)