Nouvelle gestion des DNS, complétement repensée
Nouvelle génération des formulaires Nouvelle gestions des HOST disponible (dynamique) Nouveau update_domains.sh ToDo : - finir de tester/mettre au propre les DNS - intégrer la nouvelle gestion VHOST au reste On y crois, on se bat !
This commit is contained in:
parent
064aa0864c
commit
bb83fe83e4
|
@ -91,6 +91,7 @@ bureau/admin/direct.php -text
|
|||
bureau/admin/dom_add.php -text
|
||||
bureau/admin/dom_doadd.php -text
|
||||
bureau/admin/dom_dodel.php -text
|
||||
bureau/admin/dom_edit.inc.php -text
|
||||
bureau/admin/dom_edit.php -text
|
||||
bureau/admin/dom_editdns.php -text
|
||||
bureau/admin/dom_subdel.php -text
|
||||
|
|
|
@ -45,10 +45,6 @@ include_once("head.php");
|
|||
echo "<p class=\"error\">$error</p>";
|
||||
}
|
||||
|
||||
$dom = new m_dom();
|
||||
$r=$dom->domains_type_lst;
|
||||
// die(print_r($dom->domains_type_lst()));
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php __("Here is the list of the domains type."); ?>
|
||||
|
@ -56,10 +52,9 @@ $r=$dom->domains_type_lst;
|
|||
<p><span class="ina"><a href="adm_domstypeadd.php"><?php __("Add a new domains type"); ?></a></span></p>
|
||||
<table class="tlist">
|
||||
<tr>
|
||||
<th><?php __("Id");?></th>
|
||||
<th><?php __("Name");?></th>
|
||||
<th><?php __("Description");?></th>
|
||||
<th><?php __("Ask destination ?");?></th>
|
||||
<th><?php __("Target");?></th>
|
||||
<th><?php __("Entry");?></th>
|
||||
<th><?php __("Compatibility");?></th>
|
||||
<th><?php __("Edit");?></th>
|
||||
|
@ -70,13 +65,12 @@ foreach($dom->domains_type_lst() as $d) {
|
|||
++$pair;
|
||||
?>
|
||||
<tr class="lst<?php echo $pair%2+1 ?>">
|
||||
<td><?php echo $d['id'];?></td>
|
||||
<td><?php echo $d['name'];?></td>
|
||||
<td><?php echo $d['description'];?></td>
|
||||
<td><?php echo $d['ask_dest']?__("Yes"):__("No");?></td>
|
||||
<td><?php echo $d['target'];?></td>
|
||||
<td><?php echo $d['entry'];?></td>
|
||||
<td><?php echo $d['compatibility'];?></td>
|
||||
<td><div class="ina"><a href="adm_domstypeedit.php?id=<?php echo urlencode($d['id']); ?>"><img style="padding-bottom: 5px" src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
|
||||
<td><div class="ina"><a href="adm_domstypeedit.php?name=<?php echo urlencode($d['name']); ?>"><img style="padding-bottom: 5px" src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
|
||||
|
||||
|
||||
</tr>
|
||||
|
|
|
@ -6,7 +6,7 @@ if (!$admin->enabled) {
|
|||
}
|
||||
|
||||
|
||||
if ( ! $dom->domains_type_update($id, $name, $description, $ask_dest, $entry, $compatibility) ) {
|
||||
if ( ! $dom->domains_type_update($name, $description, $target, $entry, $compatibility) ) {
|
||||
die($err->errstr());
|
||||
} else {
|
||||
include("adm_domstype.php");
|
||||
|
|
|
@ -36,17 +36,16 @@ if (!$admin->enabled) {
|
|||
include_once("head.php");
|
||||
|
||||
$fields = array (
|
||||
"id" => array ("request", "integer", ""),
|
||||
"name" => array ("request", "string", ""),
|
||||
"description" => array ("request", "string", ""),
|
||||
"ask_dest" => array ("request", "boolean", ""),
|
||||
"target" => array ("request", "string", ""),
|
||||
"entry" => array ("request", "string", ""),
|
||||
"compatibility" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
|
||||
if (! $d=$dom->domains_type_get($id)) {
|
||||
if (! $d=$dom->domains_type_get($name)) {
|
||||
$error=$err->errstr();
|
||||
echo $error;
|
||||
} else {
|
||||
|
@ -63,19 +62,21 @@ if ($error_edit) {
|
|||
} ?>
|
||||
|
||||
<form action="adm_domstypedoedit.php" method="post" name="main" id="main">
|
||||
<input type="hidden" name="id" value="<?php echo $d['id']; ?>" />
|
||||
<input type="hidden" name="name" value="<?php echo $d['name']; ?>" />
|
||||
<table class="tedit">
|
||||
<tr>
|
||||
<th><?php __("Name");?></th>
|
||||
<td><input name="name" type=text size="15" value="<?php echo $d['name']; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php __("Description");?></th>
|
||||
<td><input name="description" type=text size="30" value="<?php echo $d['description']; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php __("Ask destination ?");?></th>
|
||||
<td><input name="ask_dest" type=checkbox value=1 <?php echo $d['ask_dest']?"checked":""; ?>/></td>
|
||||
<th><?php __("Target");?></th>
|
||||
<td>
|
||||
<select name="target">
|
||||
<?php foreach ($dom->domains_type_target_values() as $k) { ?>
|
||||
<option value="<?php echo $k ?>" <?php echo ($d['target']==$k)?"selected":"";?> ><?php echo $k;?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php __("Entry");?></th>
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
require_once("../class/config.php");
|
||||
include_once("head.php");
|
||||
|
||||
|
||||
# Function to create/edit subdomain
|
||||
# Take the values of the subdomain in arguments
|
||||
|
||||
function sub_domains_edit($domain, $sub=false,$type=false,$value=false) {
|
||||
|
||||
$dom=new m_dom();
|
||||
$dom->lock();
|
||||
if (!$r=$dom->get_domain_all($domain)) {
|
||||
$error=$err->errstr();
|
||||
}
|
||||
/*
|
||||
if (! empty($sub)) {
|
||||
if (!$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value)) {
|
||||
$error=$err->errstr();
|
||||
}
|
||||
}
|
||||
*/
|
||||
$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value);
|
||||
|
||||
$dom->unlock();
|
||||
?>
|
||||
|
||||
<form action="dom_subdoedit.php" method="post" name="main" id="main">
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" name="domain" value="<?php ehe($domain); ?>" />
|
||||
<input type="hidden" name="sub_old" value="<?php ehe($sub); ?>" />
|
||||
<input type="hidden" name="type_old" value="<?php ehe($type); ?>" />
|
||||
<input type="hidden" name="value_old" value="<?php ehe($value); ?>" />
|
||||
<input type="hidden" name="action" value="add" />
|
||||
<?php __("Create a subdomain:"); ?></td><td>
|
||||
<input type="text" class="int" name="sub" style="text-align:right" value="<?php ehe($sub); ?>" size="22" id="sub" /><span class="int" id="newsubname">.<?php echo $domain; ?></span></td>
|
||||
</tr>
|
||||
<?php foreach($dom->domains_type_lst() as $dt) {
|
||||
if (! $dt['enable']) continue;
|
||||
if ( (! $r['dns'] ) and ($dt['need_dns']) ) continue;
|
||||
$targval=(strtoupper($type)==strtoupper($dt['name']))?$sd['dest']:'';
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="radio" id="<?php echo $dt['name']?>" class="inc" name="type" value="<?php echo $dt['name']; ?>" <?php cbox(strtoupper($type)==strtoupper($dt['name'])); ?> />
|
||||
<label for="<?php echo $dt['name']?>"><?php __($dt['description']); ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
switch ($dt['target']) {
|
||||
case "NONE":
|
||||
default:
|
||||
break;
|
||||
case "DIRECTORY": ?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="28" />
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
document.write(" <input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.type_val_<?php echo $dt['name'];?>');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
|
||||
// -->
|
||||
</script><?php
|
||||
break;
|
||||
case "URL": ?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="50" />
|
||||
<small><?php __("(enter an URL here)"); ?></small><?php
|
||||
break;;
|
||||
case 'IP':?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="16" />
|
||||
<small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small><?php
|
||||
break;
|
||||
case 'IPV6':?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="32" />
|
||||
<small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small><?php
|
||||
break;
|
||||
case 'TXT':?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval);?>" size="32" />
|
||||
<small><?php __("(enter a TXT informations for this domain)"); ?></small></td><?php
|
||||
break;
|
||||
case 'DOMAIN':?>
|
||||
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval);?>" size="32" />
|
||||
<small><?php __("(enter a server address or a subdomain)"); ?></small><?php
|
||||
break;
|
||||
} // switch ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } // foreach ?>
|
||||
|
||||
<tr class="trbtn">
|
||||
<td colspan="2"><input type="submit" class="inb" name="add" value="<?php __("Add this subdomain"); ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
} // sub_domains_edit
|
||||
?>
|
||||
|
|
@ -33,13 +33,6 @@ include_once("head.php");
|
|||
$fields = array (
|
||||
"domain" => array ("request", "string", ""),
|
||||
"sub" => array ("request", "string", ""),
|
||||
"type" => array ("request", "integer", $dom->type_local),
|
||||
"sub_local" => array ("request", "string", "/"),
|
||||
"sub_url" => array ("request", "string", "http://"),
|
||||
"sub_ip" => array ("request", "string", ""),
|
||||
"sub_ipv6" => array ("request", "string", ""),
|
||||
"sub_cname" => array ("request", "string", ""),
|
||||
"sub_txt" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
|
@ -90,10 +83,10 @@ for($i=0;$i<$r["nsub"];$i++) {
|
|||
?>
|
||||
<tr class="lst<?php echo $col; ?>">
|
||||
<td class="center">
|
||||
<div class="ina"><a href="dom_subedit.php?domain=<?php echo urlencode($r["name"]) ?>&sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&type=<?php echo urlencode($r["sub"][$i]["type"]) ?>"><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"]) ?>&sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&type=<?php echo urlencode($r["sub"][$i]["type"]) ?>&value=<?php echo urlencode($r["sub"][$i]['dest'])?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div>
|
||||
|
||||
</td><td class="center">
|
||||
<div class="ina"><a href="dom_subdel.php?domain=<?php echo urlencode($r["name"]) ?>&sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&type=<?php echo urlencode($r["sub"][$i]["type"]) ?>"><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"]) ?>&sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&type=<?php echo urlencode($r["sub"][$i]["type"]) ?>&value=<?php echo urlencode($r["sub"][$i]['dest'])?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div>
|
||||
</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"]); ?> </td>
|
||||
|
@ -102,70 +95,11 @@ for($i=0;$i<$r["nsub"];$i++) {
|
|||
</table>
|
||||
<br />
|
||||
<hr/>
|
||||
<?php
|
||||
require_once('dom_edit.inc.php');
|
||||
sub_domains_edit($domain);
|
||||
?>
|
||||
<br />
|
||||
<form action="dom_subdoedit.php" method="post" name="main" id="main">
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" name="domain" value="<?php ehe($r["name"]); ?>" />
|
||||
<input type="hidden" name="action" value="add" />
|
||||
<?php __("Create a subdomain:"); ?></td><td>
|
||||
<input type="text" class="int" name="sub" style="text-align:right" value="<?php ehe($sub); ?>" size="22" id="sub" /><span class="int" id="newsubname">.<?php echo $domain; ?></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="radio" id="local" class="inc" name="type" value="<?php echo $dom->type_local; ?>" <?php cbox($type==$dom->type_local); ?> onclick="document.main.sub_local.focus();" />
|
||||
<label for="local"><?php __("Locally managed"); ?></label></td>
|
||||
<td><input type="text" class="int" name="sub_local" id="sub_local" value="<?php ehe($sub_local); ?>" size="28" />
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
document.write(" <input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
|
||||
// -->
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="radio" id="url" class="inc" name="type" value="<?php echo $dom->type_url; ?>" <?php cbox($type==$dom->type_url); ?> onclick="document.main.sub_url.focus();" />
|
||||
<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>
|
||||
</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> </td>
|
||||
</tr>
|
||||
<?php if ($r["dns"]) { // show only if dns is enabled ?>
|
||||
<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();" />
|
||||
<label for="ip"><?php __("IP redirection"); ?></label></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><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">
|
||||
<td colspan="2"><input type="submit" class="inb" name="add" value="<?php __("Add this subdomain"); ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php $mem->show_help("edit_domain"); ?>
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
|
|
@ -34,6 +34,7 @@ $fields = array (
|
|||
"domain" => array ("request", "string", ""),
|
||||
"sub" => array ("request", "string", ""),
|
||||
"type" => array ("request", "string", ""),
|
||||
"value" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
|
@ -62,6 +63,7 @@ $dom->unlock();
|
|||
<input type="hidden" name="domain" value="<?php echo $domain ?>" />
|
||||
<input type="hidden" name="sub" value="<?php echo $sub ?>" />
|
||||
<input type="hidden" name="type" value="<?php echo $type ?>" />
|
||||
<input type="hidden" name="value" value="<?php echo $value ?>" />
|
||||
<?php __("WARNING : Confirm the deletion of the subdomain"); ?> : </p>
|
||||
<p><?php ecif($sub,$sub."."); echo $domain; ?></p>
|
||||
<blockquote>
|
||||
|
|
|
@ -34,12 +34,13 @@ $fields = array (
|
|||
"domain" => array ("request", "string", ""),
|
||||
"sub" => array ("request", "string", ""),
|
||||
"type" => array ("request", "string", ""),
|
||||
"value" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
$dom->lock();
|
||||
|
||||
if (!$dom->del_sub_domain($domain,$sub,$type)) {
|
||||
if (!$dom->del_sub_domain($domain,$sub,$type,$value)) {
|
||||
$error=$err->errstr();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,43 +32,26 @@ require_once("../class/config.php");
|
|||
$fields = array (
|
||||
"domain" => array ("request", "string", ""),
|
||||
"sub" => array ("request", "string", ""),
|
||||
"type_old" => array ("request", "integer",""),
|
||||
"type" => array ("request", "integer", $dom->type_local),
|
||||
"sub_local" => array ("request", "string", "/"),
|
||||
"sub_url" => array ("request", "string", "http://"),
|
||||
"sub_ip" => array ("request", "string", ""),
|
||||
"sub_txt" => array ("request", "string", ""),
|
||||
"sub_cname" => array ("request", "string", ""),
|
||||
"sub_ipv6" => array ("request", "string", ""),
|
||||
"action" => array ("request", "string", "add"),
|
||||
"sub_old" => array ("request", "string", ""),
|
||||
"type" => array ("request", "string", $dom->type_local),
|
||||
"type_old" => array ("request", "string", ""),
|
||||
"value_old" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
// here we get a dynamic-named value
|
||||
$dynamicvar="t_$type";
|
||||
$fields = array (
|
||||
"$dynamicvar" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
$value=$$dynamicvar;
|
||||
// The dynamic value is now in $value
|
||||
|
||||
$dom->lock();
|
||||
|
||||
switch ($type) {
|
||||
case $dom->type_local:
|
||||
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_local, $type_old);
|
||||
break;
|
||||
case $dom->type_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;
|
||||
case $dom->type_ip:
|
||||
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip, $type_old);
|
||||
break;
|
||||
case $dom->type_ipv6:
|
||||
$r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6, $type_old);
|
||||
break;
|
||||
case $dom->type_webmail:
|
||||
$r=$dom->set_sub_domain($domain,$sub,$type,$action,"", $type_old);
|
||||
break;
|
||||
}
|
||||
$r=$dom->set_sub_domain($domain,$sub,$type,$value, $type_old, $sub_old, $value_old);
|
||||
|
||||
$dom->unlock();
|
||||
|
||||
if (!$r) {
|
||||
|
|
|
@ -30,136 +30,39 @@
|
|||
require_once("../class/config.php");
|
||||
include_once("head.php");
|
||||
|
||||
|
||||
$fields = array (
|
||||
"domain" => array ("request", "string", ""),
|
||||
"sub" => array ("request", "string", ""),
|
||||
"type" => array ("request", "integer", $dom->type_local),
|
||||
"sub_local" => array ("request", "string", "/"),
|
||||
"sub_url" => array ("request", "string", "http://"),
|
||||
"sub_ip" => array ("request", "string", ""),
|
||||
"sub_ipv6" => array ("request", "string", ""),
|
||||
"sub_cname" => array ("request", "string", ""),
|
||||
"sub_txt" => array ("request", "string", ""),
|
||||
"action" => array ("request", "string", "add"),
|
||||
"type" => array ("request", "string", $dom->type_local),
|
||||
"value" => array ("request", "string", ""),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
$dom->lock();
|
||||
$domroot=$dom->get_domain_all($domain);
|
||||
if (!$noread) {
|
||||
if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) {
|
||||
if (!$r=$dom->get_sub_domain_all($domain,$sub,$type,$value)) {
|
||||
$error=$err->errstr();
|
||||
?>
|
||||
<h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
echo "<h3>";
|
||||
__("Editing subdomain");
|
||||
echo " http://"; ecif($sub,$sub."."); echo $domain."</h3>";
|
||||
if ($error) {
|
||||
echo "<p class=\"error\">$error</p>";
|
||||
include_once("foot.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$sub=$r["name"];
|
||||
$type=$r["type"];
|
||||
switch ($type) {
|
||||
case $dom->type_local:
|
||||
$sub_local=$r["dest"];
|
||||
break;
|
||||
case $dom->type_url:
|
||||
$sub_url=$r["dest"];
|
||||
break;
|
||||
case $dom->type_cname:
|
||||
$sub_cname=$r["dest"];
|
||||
break;
|
||||
case $dom->type_txt:
|
||||
$sub_txt=$r["dest"];
|
||||
break;
|
||||
case $dom->type_ipv6:
|
||||
$sub_ipv6=$r["dest"];
|
||||
break;
|
||||
case $dom->type_ip:
|
||||
$sub_ip=$r["dest"];
|
||||
break;
|
||||
case $dom->type_webmail:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
include_once("foot.php");
|
||||
exit();
|
||||
}
|
||||
$dom->unlock();
|
||||
?>
|
||||
|
||||
?>
|
||||
<h3><?php __("Editing subdomain"); ?> http://<?php ecif($sub,$sub."."); echo $domain; ?></h3>
|
||||
<?php
|
||||
if ($error) {
|
||||
echo "<p class=\"error\">$error</p>";
|
||||
}
|
||||
?>
|
||||
<hr id="topbar"/>
|
||||
<br />
|
||||
<!-- *****************************************
|
||||
gestion du sous-domaine
|
||||
-->
|
||||
<form action="dom_subdoedit.php" method="post" id="main" name="main">
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td> <input type="hidden" name="domain" value="<?php ehe($domain); ?>" />
|
||||
<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" />
|
||||
<?php
|
||||
require_once('dom_edit.inc.php');
|
||||
sub_domains_edit($domain,$sub,$type,$value);
|
||||
|
||||
<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();" />
|
||||
<label for="local"><?php __("Locally managed"); ?></label></td>
|
||||
<td><input type="text" class="int" name="sub_local" id="sub_local" value="<?php ehe($sub_local); ?>" size="40" />
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
document.write(" <input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.sub_local');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
|
||||
// -->
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="radio" id="url" class="inc" name="type" value="<?php echo $dom->type_url; ?>" <?php cbox($type==$dom->type_url); ?> onclick="document.main.sub_url.focus();" />
|
||||
<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>
|
||||
</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();" />
|
||||
<label for="ip"><?php __("IP redirection"); ?></label></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="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>
|
||||
<td> </td>
|
||||
</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">
|
||||
<td colspan="2">
|
||||
<input type="submit" class="inb" name="submit" value="<?php __("Validate this change"); ?>" />
|
||||
<input type="button" class="inb" name="back" value="<?php __("Cancel"); ?>" onclick="document.location='dom_edit.php?domain=<?php ehe($domain); ?>'" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
</form>
|
||||
<?php include_once("foot.php"); ?>
|
||||
include_once("foot.php");
|
||||
?>
|
||||
|
|
|
@ -66,13 +66,13 @@ class m_dom {
|
|||
*/
|
||||
var $islocked=false;
|
||||
|
||||
var $type_local = "0";
|
||||
var $type_url = "1";
|
||||
var $type_ip = "2";
|
||||
var $type_webmail = "3";
|
||||
var $type_ipv6 = "4";
|
||||
var $type_cname = "5";
|
||||
var $type_txt = "6";
|
||||
var $type_local = "LOCAL";
|
||||
var $type_url = "URL";
|
||||
var $type_ip = "IP";
|
||||
var $type_webmail = "WEBMAIL";
|
||||
var $type_ipv6 = "IPV6";
|
||||
var $type_cname = "CNAME";
|
||||
var $type_txt = "TXT";
|
||||
|
||||
var $action_insert = "0";
|
||||
var $action_update= "1";
|
||||
|
@ -102,7 +102,7 @@ class m_dom {
|
|||
function domains_type_lst() {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","domains_type_lst");
|
||||
$db->query("select * from domaines_type order by id;");
|
||||
$db->query("select * from domaines_type order by name;");
|
||||
$this->domains_type_lst=false;
|
||||
while ($db->next_record()) {
|
||||
$this->domains_type_lst[] = $db->Record;
|
||||
|
@ -110,18 +110,38 @@ class m_dom {
|
|||
return $this->domains_type_lst;
|
||||
}
|
||||
|
||||
function domains_type_get($id) {
|
||||
function domains_type_target_values($type=null) {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","domains_type_target_values");
|
||||
if (is_null($type)) {
|
||||
$db->query("desc domaines_type;");
|
||||
$r = array();
|
||||
while ($db->next_record()) {
|
||||
if ($db->f('Field') == 'target') {
|
||||
$tab = explode(",", substr($db->f('Type'), 5, -1));
|
||||
foreach($tab as $t) { $r[]=substr($t,1,-1); }
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
} else {
|
||||
$db->query("select target from domaines_type where name='$type';");
|
||||
if (! $db->next_record()) return false;
|
||||
return $db->f('target');
|
||||
}
|
||||
}
|
||||
|
||||
function domains_type_get($name) {
|
||||
global $db,$err,$cuid;
|
||||
$id=intval($id);
|
||||
$db->query("select * from domaines_type where id = $id ;");
|
||||
$name=mysql_real_escape_string($name);
|
||||
$db->query("select * from domaines_type where name='$name' ;");
|
||||
$db->next_record();
|
||||
return $db->Record;
|
||||
}
|
||||
|
||||
function domains_type_del($id) {
|
||||
function domains_type_del($name) {
|
||||
global $db,$err,$cuid;
|
||||
$id=intval($id);
|
||||
$db->query("delete domaines_type where id=$id;");
|
||||
$name=mysql_real_escape_string($name);
|
||||
$db->query("delete domaines_type where name='$name';");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -139,15 +159,15 @@ class m_dom {
|
|||
return true;
|
||||
}
|
||||
|
||||
function domains_type_update($id, $name, $description, $ask_dest, $entry, $compatibility) {
|
||||
function domains_type_update($name, $description, $target, $entry, $compatibility) {
|
||||
global $err,$cuid,$db;
|
||||
$id=intval($id);
|
||||
$name=mysql_real_escape_string($name);
|
||||
$description=mysql_real_escape_string($description);
|
||||
$ask_dest=intval($ask_dest);
|
||||
$target=mysql_real_escape_string($target);
|
||||
$entry=mysql_real_escape_string($entry);
|
||||
$compatibility=mysql_real_escape_string($compatibility);
|
||||
$db->query("UPDATE domaines_type SET name='$name', description='$description', ask_dest='$ask_dest', entry='$entry', compatibility='$compatibility' where id='$id';");
|
||||
$db->query("UPDATE domaines_type SET description='$description', target='$target', entry='$entry', compatibility='$compatibility' where name='$name';");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -199,21 +219,20 @@ class m_dom {
|
|||
$err->raise("dom",2,$dom);
|
||||
return false;
|
||||
}
|
||||
$db->query("INSERT INTO domaines_standby (compte,domaine,mx,gesdns,gesmx,action) SELECT compte,domaine,mx,gesdns,gesmx,2 FROM domaines WHERE domaine='$dom'"); // DELETE
|
||||
$db->query("DELETE FROM domaines WHERE domaine='$dom';");
|
||||
$db->query("DELETE FROM sub_domaines WHERE domaine='$dom';");
|
||||
$db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE domaine='$dom';");
|
||||
$db->query("UPDATE domaines SET dns_action='DELETE' WHERE domaine='$dom';");
|
||||
|
||||
// DEPENDANCE :
|
||||
// Lancement de del_dom sur les classes domain_sensitive :
|
||||
// Declenchons les autres classes.
|
||||
foreach($classes as $c) {
|
||||
if (method_exists($GLOBALS[$c],"alternc_del_domain")) {
|
||||
$GLOBALS[$c]->alternc_del_domain($dom);
|
||||
$GLOBALS[$c]->alternc_del_domain($dom);
|
||||
}
|
||||
}
|
||||
foreach($classes as $c) {
|
||||
if (method_exists($GLOBALS[$c],"alternc_del_mx_domain")) {
|
||||
$GLOBALS[$c]->alternc_del_mx_domain($dom);
|
||||
$GLOBALS[$c]->alternc_del_mx_domain($dom);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -276,11 +295,6 @@ class m_dom {
|
|||
$err->raise("dom",8);
|
||||
return false;
|
||||
}
|
||||
$db->query("select compte from domaines_standby where domaine='$domain';");
|
||||
if ($db->num_rows()!=0) {
|
||||
$err->raise("dom",9);
|
||||
return false;
|
||||
}
|
||||
$this->dns=$this->whois($domain);
|
||||
if (!$force) {
|
||||
$v=checkhostallow($domain,$this->dns);
|
||||
|
@ -316,8 +330,7 @@ class m_dom {
|
|||
return false;
|
||||
}
|
||||
if ($noerase) $noerase="1"; else $noerase="0";
|
||||
$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 (compte,domaine,mx,gesdns,gesmx,noerase,dns_action) values ('$cuid','$domain','$L_MX','$dns','$mx','$noerase','UPDATE');");
|
||||
|
||||
if ($isslave) {
|
||||
$isslave=true;
|
||||
|
@ -328,9 +341,9 @@ class m_dom {
|
|||
$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);
|
||||
$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);
|
||||
}
|
||||
if (!$isslave) {
|
||||
// Creation du repertoire dans www
|
||||
|
@ -342,9 +355,9 @@ class m_dom {
|
|||
}
|
||||
|
||||
// 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', '');
|
||||
$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, '');
|
||||
}
|
||||
// DEPENDANCE :
|
||||
// Lancement de add_dom sur les classes domain_sensitive :
|
||||
|
@ -571,9 +584,6 @@ class m_dom {
|
|||
/**
|
||||
* retourne TOUTES les infos d'un domaine
|
||||
*
|
||||
* <b>Note</b> : si le domaine est en attente (présent dans
|
||||
* domaines_standby), une erreur est retournée
|
||||
*
|
||||
* @param string $dom Domaine dont on souhaite les informations
|
||||
* @return array Retourne toutes les infos du domaine sous la forme d'un
|
||||
* tableau associatif comme suit :<br /><pre>
|
||||
|
@ -604,11 +614,6 @@ class m_dom {
|
|||
return false;
|
||||
}
|
||||
$r["name"]=$dom;
|
||||
$db->query("select * from domaines_standby where compte='$cuid' and domaine='$dom'");
|
||||
if ($db->num_rows()>0) {
|
||||
$err->raise("dom",13);
|
||||
return false;
|
||||
}
|
||||
$db->query("select * from domaines where compte='$cuid' and domaine='$dom'");
|
||||
if ($db->num_rows()==0) {
|
||||
$err->raise("dom",1,$dom);
|
||||
|
@ -633,10 +638,12 @@ class m_dom {
|
|||
$r["sub"][$i]["name"]=$db->Record["sub"];
|
||||
$r["sub"][$i]["dest"]=$db->Record["valeur"];
|
||||
$r["sub"][$i]["type"]=$db->Record["type"];
|
||||
/*
|
||||
if ($db->Record["type"]==3) { // Webmail
|
||||
$this->webmail=1;
|
||||
$r["sub"][$i]["dest"]=_("Webmail access");
|
||||
}
|
||||
*/
|
||||
}
|
||||
$db->free();
|
||||
return $r;
|
||||
|
@ -657,7 +664,7 @@ class m_dom {
|
|||
* $r["type"]= Type (0-n) de la redirection.
|
||||
* Retourne FALSE si une erreur s'est produite.
|
||||
*/
|
||||
function get_sub_domain_all($dom,$sub, $type = "") {
|
||||
function get_sub_domain_all($dom,$sub, $type="", $value='') {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","get_sub_domain_all",$dom."/".$sub);
|
||||
// Locked ?
|
||||
|
@ -670,10 +677,15 @@ class m_dom {
|
|||
$err->raise("dom",3+$t);
|
||||
return false;
|
||||
}
|
||||
if ( ! empty($type)) {
|
||||
$type = " and type='".intval($type)."'";
|
||||
/*
|
||||
if ( ! empty($value)) {
|
||||
$type = " and valeur=\"".mysql_real_escape_string($value)."\"";
|
||||
}
|
||||
$db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' $type");
|
||||
if ( ! empty($type)) {
|
||||
$type = " and type=\"".mysql_real_escape_string($type)."\"";
|
||||
}
|
||||
*/
|
||||
$db->query("select * from sub_domaines where compte='$cuid' and domaine='$dom' and sub='$sub' and ( length('$type')=0 or type='$type') and (length('$value')=0 or '$value'=valeur);");
|
||||
if ($db->num_rows()==0) {
|
||||
$err->raise("dom",14);
|
||||
return false;
|
||||
|
@ -688,7 +700,66 @@ class m_dom {
|
|||
} // get_sub_domain_all
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
function check_type_value($type, $value) {
|
||||
// check the type we can have in domaines_type.target
|
||||
|
||||
switch ($this->domains_type_target_values($type)) {
|
||||
case 'NONE':
|
||||
if (empty($value) or is_null($value)) {return true;}
|
||||
break;
|
||||
case 'URL':
|
||||
if ( $value == strval($value)) {return true;}
|
||||
break;
|
||||
case 'DIRECTORY':
|
||||
if (substr($value,0,1)!="/") {
|
||||
$value="/".$value;
|
||||
}
|
||||
if (!checkuserpath($value)) {
|
||||
$err->raise("dom",21);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'IP':
|
||||
if (checkip($value)) {return true;}
|
||||
break;
|
||||
case 'IPV6':
|
||||
if (checkipv6($value)) {return true;}
|
||||
break;
|
||||
case 'DOMAIN':
|
||||
if (checkcname($value)) {return true;}
|
||||
break;
|
||||
case 'TXT':
|
||||
if ( $value == strval($value)) {return true;}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
} //check_type_value
|
||||
|
||||
|
||||
function can_create_subdomain($dom,$sub,$type) {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","can_create_subdomain",$dom."/".$sub);
|
||||
|
||||
# Get the compatibility list for this domain type
|
||||
$db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper('$type');");
|
||||
if (!$db->next_record()) return false;
|
||||
$compatibility_lst = explode(",",$db->f('compatibility'));
|
||||
|
||||
# Get the list of type of subdomains already here who have the same name
|
||||
$db->query("select distinct type from sub_domaines where sub='$sub' and domaine='$dom';");
|
||||
while ($db->next_record()) {
|
||||
# And if there is a domain with a incompatible type, return false
|
||||
if (! in_array(strtoupper($db->f('type')),$compatibility_lst)) return false;
|
||||
}
|
||||
|
||||
# All is right, go ! Create ur domain !
|
||||
return true;
|
||||
}
|
||||
|
||||
// /* ----------------------------------------------------------------- */
|
||||
/**
|
||||
* Modifier les information du sous-domaine demandé.
|
||||
*
|
||||
|
@ -704,8 +775,8 @@ class m_dom {
|
|||
* de $type (url, ip, dossier...)
|
||||
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
||||
*/
|
||||
function set_sub_domain($dom,$sub,$type,$action,$dest, $type_old=null) {
|
||||
if (is_null($type_old)) $type_old=$type;
|
||||
// TODO : j'ai viré le type action, valider que plus personne ne l'utilise (quatrieme argument)
|
||||
function set_sub_domain($dom,$sub,$type,$dest, $type_old=null,$sub_old=null,$value_old=null) {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","set_sub_domain",$dom."/".$sub);
|
||||
// Locked ?
|
||||
|
@ -725,108 +796,38 @@ class m_dom {
|
|||
$err->raise("dom",24);
|
||||
return false;
|
||||
}
|
||||
if ($type==2) { // IP
|
||||
if (!checkip($dest)) {
|
||||
$err->raise("dom",19);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($type==4) { // IPv6
|
||||
if (!checkipv6($dest)) {
|
||||
$err->raise("dom",19);
|
||||
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 (!checkurl($dest)) {
|
||||
$err->raise("dom",20);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($type==0) { // LOCAL
|
||||
if (substr($dest,0,1)!="/") {
|
||||
$dest="/".$dest;
|
||||
}
|
||||
if (!checkuserpath($dest)) {
|
||||
$err->raise("dom",21);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->check_type_value($type,$dest)) {
|
||||
# TODO have a real err code
|
||||
$err->raise("dom",667);
|
||||
return false;
|
||||
}
|
||||
|
||||
// On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
|
||||
$t=checkfqdn($dom);
|
||||
if ($t) {
|
||||
if ($t=checkfqdn($dom)) {
|
||||
$err->raise("dom",3+$t);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Si l'action demandé est une création
|
||||
if ($action=="add") {
|
||||
$do_create=false;
|
||||
// Tout d'abord on vérifie si il faut le créer
|
||||
$r=$this->get_sub_domain_all($dom,$sub);
|
||||
if ( !$r) { $do_create=true ;}; // If subdomains do not exist
|
||||
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 {
|
||||
$err->raise("dom",16);
|
||||
return false;
|
||||
if (! $this->can_create_subdomain($dom,$sub,$type)) {
|
||||
# TODO have a real error code
|
||||
$err->raise("dom", 654);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! is_null($type_old )) { // It's not a creation, it's an edit. Delete the old one
|
||||
$db->query("delete from sub_domaines where domaine='$dom' and sub='$sub' and upper(type)=upper('$type_old') and valeur='$value_old';");
|
||||
}
|
||||
|
||||
// Re-create the one we want
|
||||
$db->query("insert into sub_domaines (compte,domaine,sub,valeur,type,web_action) values ('$cuid','$dom','$sub','$dest','$type','UPDATE');");
|
||||
// Tell to update the DNS file
|
||||
$db->query("update domaines set dns_action='UPDATE' where domaine='$dom';");
|
||||
|
||||
return true;
|
||||
} // set_sub_domain
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
/**
|
||||
* Supprime le sous-domaine demandé
|
||||
|
@ -836,7 +837,7 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
|
|||
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
||||
*
|
||||
*/
|
||||
function del_sub_domain($dom,$sub,$type) {
|
||||
function del_sub_domain($dom,$sub,$type,$value='') {
|
||||
global $db,$err,$cuid;
|
||||
$err->log("dom","del_sub_domain",$dom."/".$sub);
|
||||
// Locked ?
|
||||
|
@ -855,9 +856,8 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
|
|||
return false;
|
||||
} else {
|
||||
// OK, on valide :
|
||||
$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' 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("delete from sub_domaines where domaine='$dom' and sub='$sub' and type='$type' and ( length('$value')=0 or valeur='$value') ");
|
||||
$db->query("update domaines set dns_action='UPDATE' where domaine='$dom';");
|
||||
}
|
||||
return true;
|
||||
} // del_sub_domain
|
||||
|
@ -959,13 +959,8 @@ die(" XXXX type = $type ---- type_old = $type_old XXXX ");
|
|||
}
|
||||
|
||||
$db->query("UPDATE domaines SET gesdns='$dns', mx='$mx', gesmx='$gesmx' WHERE domaine='$dom'");
|
||||
$db->query("INSERT INTO domaines_standby (compte,domaine,mx,gesdns,gesmx,action) VALUES ('$cuid','$dom','$mx','$dns','$gesmx',1);");
|
||||
// If we go from NODNS to YESDNS, we HAVE TO recreate all the subdomains of this domain in the bind zone file
|
||||
// This code will fix Ticket 517
|
||||
if ($dns==1 && $r["dns"]==0) {
|
||||
$db->query("INSERT INTO sub_domaines_standby SELECT compte,domaine,sub,valeur,type,1 FROM sub_domaines WHERE domaine='$dom';");
|
||||
}
|
||||
|
||||
$db->query("UPDATE domaines set dns_action='UPDATE' where domaine='$dom';");
|
||||
|
||||
return true;
|
||||
} // edit_domain
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ usr/sbin
|
|||
usr/share/alternc/install
|
||||
usr/share/locale/fr/LC_MESSAGES
|
||||
usr/share/lintian/overrides/
|
||||
var/alternc/apache-vhost
|
||||
var/alternc/apacheconf
|
||||
var/alternc/apacheconf/_
|
||||
var/alternc/apacheconf/0
|
||||
|
|
|
@ -227,6 +227,7 @@ EOF
|
|||
/usr/lib/alternc/slave_dns
|
||||
# Apache will not start without this file
|
||||
touch /var/alternc/apacheconf/override_php.conf
|
||||
touch /var/alternc/apache-vhost/vhosts_all.conf
|
||||
|
||||
# Update l18n files
|
||||
/usr/share/alternc/install/dopo.sh
|
||||
|
|
|
@ -39,3 +39,4 @@ ScriptAlias /cgi-bin/ /var/alternc/cgi-bin/
|
|||
</Directory>
|
||||
|
||||
Include /etc/alternc/bureau.conf
|
||||
Include /var/alternc/apache-vhost/vhosts_all.conf
|
||||
|
|
|
@ -46,3 +46,4 @@ ScriptAlias /cgi-bin/ /var/alternc/cgi-bin/
|
|||
</Directory>
|
||||
|
||||
Include /etc/alternc/bureau.conf
|
||||
Include /var/alternc/apache-vhost/vhosts_all.conf
|
||||
|
|
|
@ -1 +1 @@
|
|||
zone "@@DOMAINE@@" { type master; file "/var/alternc/bind/zones/@@DOMAINE@@"; allow-query { any; }; };
|
||||
zone "@@DOMAINE@@" { type master; file "@@ZONE_FILE@@"; allow-query { any; }; };
|
||||
|
|
|
@ -504,26 +504,3 @@ VALUES (
|
|||
'subadmin_restriction', '',
|
||||
'This variable set the way the account list works for accounts other than "admin" (2000). 0 (default) = admin other than admin/2000 can see their own account, but not the other one 1 = admin other than admin/2000 can see any account by clicking the ''show all accounts'' link. '
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `domaines_type` (
|
||||
`id` INTEGER NOT NULL ,
|
||||
`name` VARCHAR (255) NOT NULL,
|
||||
`description` TEXT,
|
||||
`ask_dest` BOOLEAN DEFAULT FALSE,
|
||||
`entry` VARCHAR (255) DEFAULT '',
|
||||
`compatibility` VARCHAR (255) DEFAULT '',
|
||||
`enable` BOOLEAN DEFAULT TRUE,
|
||||
PRIMARY KEY ( `id` )
|
||||
) COMMENT = 'Type of domains allowed';
|
||||
|
||||
INSERT IGNORE INTO `domaines_type` (id, name, description, ask_dest, entry, compatibility) values
|
||||
(0, 'local','local redirection', false, '%SUB% IN A @@PUBLIC_IP@@', '6'),
|
||||
(1, 'url','url redirection', false, '%SUB% IN A @@PUBLIC_IP@@','6'),
|
||||
(2, 'ip','ip address', true, '%SUB% IN A %TARGET%','2,4,6'),
|
||||
(3, 'webmail', 'webmail', false, '%SUB% IN A @@PUBLIC_IP@@', '6'),
|
||||
(4, 'ipv6','ipv6 address', true, '%SUB% IN AAAA %TARGET%','2,4,6'),
|
||||
(5, 'cname', 'cname entry', true, '%SUB% CNAME %TARGET%', '6'),
|
||||
(6, 'txt', 'txt entry', true, '%SUB% IN TXT "%TARGET%"','0,1,2,3,4,5,6'),
|
||||
(7, 'mx', 'mx entry', true, '%SUB% IN MX %TARGET%', '0,1,2,3,4,5,6')
|
||||
;
|
||||
|
||||
|
|
|
@ -1,10 +1,48 @@
|
|||
-- 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);
|
||||
ALTER TABLE sub_domaines ADD CONSTRAINT pk_SubDomaines PRIMARY KEY (compte,domaine,sub,type,valeur);
|
||||
|
||||
-- Alter table mail_domain to add support of temporary mail
|
||||
ALTER TABLE mail_domain ADD expiration_date datetime DEFAULT null;
|
||||
|
||||
-- Domains type
|
||||
CREATE TABLE IF NOT EXISTS `domaines_type` (
|
||||
`name` VARCHAR (255) NOT NULL, -- Uniq name
|
||||
`description` TEXT, -- Human description
|
||||
`target` enum ('NONE', 'URL', 'DIRECTORY', 'IP', 'IPV6', 'DOMAIN', 'TXT') NOT NULL DEFAULT 'NONE', -- Target type
|
||||
`entry` VARCHAR (255) DEFAULT '', -- BIND entry
|
||||
`compatibility` VARCHAR (255) DEFAULT '', -- Which type can be on the same subdomains
|
||||
`enable` BOOLEAN DEFAULT TRUE, -- Show this options to the users ?
|
||||
`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
|
||||
PRIMARY KEY ( `name` )
|
||||
) COMMENT = 'Type of domains allowed';
|
||||
|
||||
INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, only_dns, need_dns) values
|
||||
('local','Locally managed', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
|
||||
('url','URL redirection', 'URL', '%SUB% IN A @@PUBLIC_IP@@','txt', true, true),
|
||||
('ip','IP redirection', 'IP', '%SUB% IN A %TARGET%','url,ip,ipv6,txt', true, true),
|
||||
('webmail', 'Webmail access', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
|
||||
('ipv6','ipv6 address', 'IPV6', '%SUB% IN AAAA %TARGET%','ip,ipv6,webmail,txt',true, true),
|
||||
('cname', 'cname entry', 'DOMAIN', '%SUB% CNAME %TARGET%', 'txt',true, true),
|
||||
('txt', 'txt entry', 'TXT', '%SUB% IN TXT "%TARGET%"','local,url,ip,webmail,ipv6,cname,txt',true, true),
|
||||
('mx', 'mx entry', 'IP', '%SUB% IN MX %TARGET%', 'local,url,ip,webmail,ipv6,cname,txt',true, false)
|
||||
;
|
||||
|
||||
-- Changing stanby use
|
||||
-- TODO modify mysql.sh to add this changes
|
||||
alter table domaines add column dns_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE';
|
||||
alter table domaines add column dns_result varchar(255) not null default '';
|
||||
alter table sub_domaines add column web_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE';
|
||||
alter table sub add column dns_result varchar(255) not null default '';
|
||||
drop table sub_domaines_standby;
|
||||
drop table domaines_standby;
|
||||
|
||||
update sub_domaines set type='LOCAL' where type='0';
|
||||
update sub_domaines set type='URL' where type='1';
|
||||
update sub_domaines set type='IP' where type='2';
|
||||
update sub_domaines set type='WEBMAIL' where type='3';
|
||||
update sub_domaines set type='IPV6' where type='4';
|
||||
update sub_domaines set type='CNAME' where type='5';
|
||||
update sub_domaines set type='TXT' where type='6';
|
||||
|
||||
|
|
53
src/dns.sh
53
src/dns.sh
|
@ -1,13 +1,14 @@
|
|||
#!/bin/bash
|
||||
# dns.sh next-gen by Fufroma
|
||||
|
||||
# Init some vars
|
||||
# Init some vars
|
||||
. /etc/alternc/local.sh
|
||||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
# Init some other vars
|
||||
MYSQL_DO="mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "
|
||||
ZONE_TEMPLATE="/etc/alternc/templates/bind/templates/zone.template"
|
||||
NAMED_TEMPLATE="/etc/bind/templates/named.template"
|
||||
NAMED_TEMPLATE="/etc/alternc/templates/bind/templates/named.template"
|
||||
NAMED_CONF="/var/alternc/bind/automatic.conf"
|
||||
|
||||
dns_zone_file() {
|
||||
echo "$ALTERNC_LOC/bind/zones/$1"
|
||||
|
@ -15,7 +16,10 @@ dns_zone_file() {
|
|||
|
||||
dns_is_locked() {
|
||||
local domain=$1
|
||||
grep "LOCKED:YES" "$(dns_zone_file $domain)" &> /dev/null
|
||||
if [ ! -r "$(dns_zone_file $domain)" ] ; then
|
||||
return 1
|
||||
fi
|
||||
grep "LOCKED:YES" "$(dns_zone_file $domain)"
|
||||
return $?
|
||||
}
|
||||
|
||||
|
@ -37,13 +41,43 @@ dns_chmod() {
|
|||
return 0
|
||||
}
|
||||
|
||||
dns_named_conf() {
|
||||
local domain=$1
|
||||
|
||||
if [ ! -f "$(dns_zone_file $domain)" ] ; then
|
||||
echo Error : no file $(dns_zone_file $domain)
|
||||
return 1
|
||||
fi
|
||||
|
||||
grep -q "$domain" "$NAMED_CONF"
|
||||
if [ $? -ne 0 ] ; then
|
||||
local tempo=$(cat "$NAMED_TEMPLATE")
|
||||
tempo=${tempo/@@DOMAINE@@/$domain}
|
||||
tempo=${tempo/@@ZONE_FILE@@/$(dns_zone_file $domain)}
|
||||
echo $tempo >> "$NAMED_CONF"
|
||||
fi
|
||||
}
|
||||
|
||||
dns_delete() {
|
||||
local domain=$1
|
||||
|
||||
# Delete the zone file
|
||||
if [ -w $(dns_zone_file $domain) ] ; then
|
||||
rm -f $(dns_zone_file $domain)
|
||||
fi
|
||||
|
||||
# Remove from the named conf
|
||||
local file=$(cat "$NAMED_CONF")
|
||||
echo -e "$file" |grep -v "\"$domain\"" > "$NAMED_CONF"
|
||||
}
|
||||
|
||||
# DNS regenerate
|
||||
dns_regenerate() {
|
||||
local domain=$1
|
||||
local manual_tag=";;; END ALTERNC AUTOGENERATE CONFIGURATION"
|
||||
local zone_file=$(dns_zone_file $domain)
|
||||
|
||||
# Check if locked
|
||||
# Check if locked
|
||||
dns_is_locked "$domain"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "DNS $domain LOCKED"
|
||||
|
@ -59,11 +93,11 @@ dns_regenerate() {
|
|||
# Add the entry
|
||||
file=$(
|
||||
echo -e "$file"
|
||||
$MYSQL_DO "select replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', sd.sub) from sub_domaines sd,domaines_type dt where sd.type=dt.id and sd.domaine='$domain';"|sort
|
||||
$MYSQL_DO "select replace(replace(dt.entry,'%TARGET%',sd.valeur), '%SUB%', if(length(sd.sub)>0,sd.sub,'@')) from sub_domaines sd,domaines_type dt where sd.type=dt.name and sd.domaine='$domain';"|sort
|
||||
)
|
||||
|
||||
|
||||
# Get some usefull vars
|
||||
# Get some usefull vars
|
||||
local mx=$( $MYSQL_DO "select mx from domaines where domaine='$domain';")
|
||||
|
||||
# Replace the vars by their values
|
||||
|
@ -87,8 +121,11 @@ dns_regenerate() {
|
|||
file=$(echo -e "$file"; echo "$manual_tag")
|
||||
fi
|
||||
|
||||
# Init the file
|
||||
# Init the file
|
||||
echo -e "$file" > "$zone_file"
|
||||
|
||||
# And set his rights
|
||||
dns_chmod $domain
|
||||
# Add it to named conf
|
||||
dns_named_conf $domain
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
# some miscellaneous shell functions
|
||||
#!/bin/bash
|
||||
# functions.sh next-gen by Fufroma
|
||||
|
||||
# Init some vars
|
||||
. /etc/alternc/local.sh
|
||||
|
||||
# Init some other vars
|
||||
MYSQL_DO="mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "
|
||||
DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log"
|
||||
|
||||
# Some usefull miscellaneous shell functions
|
||||
print_domain_letter() {
|
||||
local domain="$1"
|
||||
|
||||
|
@ -12,379 +21,27 @@ print_domain_letter() {
|
|||
|
||||
print_user_letter() {
|
||||
local user="$1"
|
||||
|
||||
echo "$user" | awk '{print substr($1, 1, 1)}'
|
||||
}
|
||||
|
||||
add_to_php_override() {
|
||||
local fqdn="$1"
|
||||
|
||||
/usr/lib/alternc/basedir_prot.sh "$fqdn" >> "$DOMAIN_LOG_FILE"
|
||||
}
|
||||
|
||||
remove_php_override() {
|
||||
local fqdn="$1"
|
||||
local letter=`print_domain_letter $fqdn`
|
||||
|
||||
sed -i "/$fqdn/d" $APACHECONF_DIR/override_php.conf
|
||||
rm -f $APACHECONF_DIR/$letter/$fqdn
|
||||
}
|
||||
|
||||
add_to_named_reload() {
|
||||
local domain="$1"
|
||||
local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
|
||||
|
||||
if [ "domain" = "all" ] || grep -q "^all$" "$RELOAD_ZONES_TMP_FILE"; then
|
||||
echo "all" > "$RELOAD_ZONES_TMP_FILE"
|
||||
else
|
||||
if ! grep -q "^${escaped_domain}$" "$RELOAD_ZONES_TMP_FILE"; then
|
||||
echo "$domain" >> "$RELOAD_ZONES_TMP_FILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# we assume that the serial line contains the "serial string", eg.:
|
||||
# 2005012703 ; serial
|
||||
#
|
||||
# returns 1 if file isn't readable
|
||||
# returns 2 if we can't find the serial number
|
||||
# returns 3 if a tempfile can't be created
|
||||
increment_serial() {
|
||||
local domain="$1"
|
||||
local zone_file="$ZONES_DIR/$domain"
|
||||
local current_serial
|
||||
local new_serial
|
||||
local date
|
||||
local revision
|
||||
local today
|
||||
|
||||
if [ ! -f "$zone_file" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# the assumption is here
|
||||
current_serial=`awk '/^..*serial/ {print $1}' < "$zone_file"` || return 2
|
||||
if [ -z "$current_serial" ]; then
|
||||
return 2
|
||||
fi
|
||||
|
||||
date=`echo $current_serial | cut -c1-8`
|
||||
revision=`echo $current_serial | sed s/"${date}0\?"/""/g`
|
||||
today=`date +%Y%m%d`
|
||||
# increment the serial number only if the date hasn't changed
|
||||
if [ "$date" = "$today" ] ; then
|
||||
revision=$(($revision + 1))
|
||||
else
|
||||
revision=1
|
||||
date=$today
|
||||
fi
|
||||
new_serial="$date`printf '%.2d' $revision`"
|
||||
|
||||
# replace serial number
|
||||
cp -a -f "$zone_file" "$zone_file.$$"
|
||||
awk -v "NEW_SERIAL=$new_serial" \
|
||||
'{if ($3 == "serial")
|
||||
print " "NEW_SERIAL " ; serial"
|
||||
else
|
||||
print $0}' < "$zone_file" > "$zone_file.$$"
|
||||
mv -f "$zone_file.$$" "$zone_file"
|
||||
|
||||
add_to_named_reload "$domain"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
change_host_ip() {
|
||||
local domain="$1"
|
||||
local zone_file="$ZONES_DIR/$domain"
|
||||
local ip="$2"
|
||||
local host="$3"
|
||||
local pattern
|
||||
local a_line
|
||||
|
||||
if [ -z "$host" ]; then
|
||||
host="@"
|
||||
fi
|
||||
|
||||
case "$host_type" in
|
||||
"$TYPE_IPV6")
|
||||
a_line="$host IN AAAA $ip"
|
||||
pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]+.+\$"
|
||||
;;
|
||||
"$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
|
||||
echo "Should change $host.$domain, but can't find $zone_file."
|
||||
return 1
|
||||
fi
|
||||
if grep -q "$pattern" "$zone_file"; then
|
||||
cp -a -f "$zone_file" "$zone_file.$$"
|
||||
sed "s/$pattern/$a_line/" < "$zone_file" > "$zone_file.$$"
|
||||
mv "$zone_file.$$" "$zone_file"
|
||||
else
|
||||
echo "$a_line" >> "$zone_file"
|
||||
fi
|
||||
add_to_named_reload "$domain"
|
||||
}
|
||||
|
||||
add_host() {
|
||||
local domain="$1"
|
||||
local host_type="$2"
|
||||
local host="$3"
|
||||
local value="$4"
|
||||
local user="$5"
|
||||
local domain_letter=`print_domain_letter "$domain"`
|
||||
local user_letter=`print_user_letter "$user"`
|
||||
local ip
|
||||
local fqdn
|
||||
local vhost_directory
|
||||
|
||||
delete_host "$domain" "$host" "$host_type"
|
||||
|
||||
if [ "$host" = "@" -o -z "$host" ]; then
|
||||
FQDN="$domain"
|
||||
else
|
||||
FQDN="$host.$domain"
|
||||
fi
|
||||
|
||||
case "$host_type" in
|
||||
"$TYPE_IP")
|
||||
ip="$value"
|
||||
;;
|
||||
"$TYPE_IPV6")
|
||||
ip="$value"
|
||||
;;
|
||||
"$TYPE_CNAME")
|
||||
ip="$value"
|
||||
;;
|
||||
"$TYPE_TXT")
|
||||
ip="$value"
|
||||
;;
|
||||
"$TYPE_WEBMAIL")
|
||||
ip="$PUBLIC_IP"
|
||||
add_to_php_override "$FQDN"
|
||||
;;
|
||||
*)
|
||||
ip="$PUBLIC_IP"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$host" = "@" -o -z "$host" ]; then
|
||||
change_host_ip "$domain" "$ip" || true
|
||||
fqdn="$domain"
|
||||
else
|
||||
change_host_ip "$domain" "$ip" "$host" || true
|
||||
fqdn="${host}.${domain}"
|
||||
fi
|
||||
|
||||
vhost_directory="${HTTP_DNS}/${domain_letter}/${fqdn}"
|
||||
htaccess_directory="${HTTP_DNS}/redir/${domain_letter}/${fqdn}"
|
||||
|
||||
case "$host_type" in
|
||||
$TYPE_LOCAL)
|
||||
host_create_vhost $user $fqdn ${value}
|
||||
;;
|
||||
|
||||
$TYPE_WEBMAIL)
|
||||
host_create_webmail $user $fqdn
|
||||
;;
|
||||
|
||||
$TYPE_URL)
|
||||
mkdir -p "$htaccess_directory"
|
||||
# normalize the url provided to make sure the hostname part is
|
||||
# followed by at least /
|
||||
value=`echo $value | sed -e 's#\([^/:]*://\)\?\([^/]*\)/*\(.*\)#\1\2/\3#'`
|
||||
|
||||
host_create_redirect $user $fqdn $value
|
||||
;;
|
||||
|
||||
$TYPE_IP)
|
||||
rm -f "$vhost_directory"
|
||||
rm -rf "$htaccess_directory/.htaccess"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknow type code: $type" >> "$DOMAIN_LOG_FILE"
|
||||
;;
|
||||
esac
|
||||
host_enable_host $user $fqdn
|
||||
}
|
||||
|
||||
delete_host() {
|
||||
local domain="$1"
|
||||
local host="$2"
|
||||
local host_type="$3"
|
||||
local domain_letter=`print_domain_letter "$domain"`
|
||||
local fqdn
|
||||
local escaped_host
|
||||
local escaped_fqdn
|
||||
local pattern
|
||||
|
||||
if [ "$host" = "@" -o -z "$host" ]; then
|
||||
fqdn="$domain"
|
||||
escaped_host=""
|
||||
else
|
||||
fqdn="$host.$domain"
|
||||
escaped_host=`echo "$host" | sed 's/\([\*|\.]\)/\\\\\1/g'`
|
||||
fi
|
||||
|
||||
if [ -f "$ZONES_DIR/$domain" ] ; then
|
||||
cp -a -f "$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"
|
||||
increment_serial "$domain"
|
||||
add_to_named_reload "$domain"
|
||||
fi
|
||||
|
||||
rm -f "$APACHECONF_DIR/$domain_letter/$fqdn"
|
||||
|
||||
escaped_fqdn=`echo "$fqdn" | sed 's/\([\*|\.]\)/\\\\\1/g'`
|
||||
|
||||
cp -a -f "$OVERRIDE_PHP_FILE" "$OVERRIDE_PHP_FILE.$$"
|
||||
sed -e "/\/${escaped_fqdn}\$/d" \
|
||||
< "$OVERRIDE_PHP_FILE" > "$OVERRIDE_PHP_FILE.$$"
|
||||
mv "$OVERRIDE_PHP_FILE.$$" "$OVERRIDE_PHP_FILE"
|
||||
|
||||
rm -f "$HTTP_DNS/$domain_letter/$fqdn"
|
||||
rm -rf "$HTTP_DNS/redir/$domain_letter/$fqdn"
|
||||
host_disable_host $fqdn
|
||||
}
|
||||
|
||||
|
||||
init_zone() {
|
||||
local domain="$1"
|
||||
local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
|
||||
local zone_file="$ZONES_DIR/$domain"
|
||||
local serial
|
||||
|
||||
if [ ! -f "$zone_file" ]; then
|
||||
serial=`date +%Y%m%d`00
|
||||
sed -e "s/@@DOMAINE@@/$domain/g;s/@@SERIAL@@/$serial/g" \
|
||||
< "$ZONE_TEMPLATE" > "$zone_file"
|
||||
chgrp bind "$zone_file"
|
||||
chmod 640 "$zone_file"
|
||||
fi
|
||||
if ! grep -q "\"$escaped_domain\"" "$NAMED_CONF_FILE"; then
|
||||
cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE".prec
|
||||
sed -e "s/@@DOMAINE@@/$domain/g" \
|
||||
< "$NAMED_TEMPLATE" >> "$NAMED_CONF_FILE"
|
||||
add_to_named_reload "all"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_zone() {
|
||||
local domain="$1"
|
||||
local escaped_domain=`echo "$domain" | sed -e 's/\./\\\./g'`
|
||||
local zone_file="$ZONES_DIR/$domain"
|
||||
|
||||
if [ -f "$zone_file" ]; then
|
||||
rm -f "$zone_file"
|
||||
fi
|
||||
|
||||
if grep -q "\"$escaped_domain\"" "$NAMED_CONF_FILE"; then
|
||||
cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE.prec"
|
||||
cp -a -f "$NAMED_CONF_FILE" "$NAMED_CONF_FILE.$$"
|
||||
# That's for multi-line template
|
||||
#sed -e "/^zone \"$escaped_domain\"/,/^};/d" \
|
||||
# That's for one-line template
|
||||
grep -v "^zone \"$escaped_domain\"" \
|
||||
< "$NAMED_CONF_FILE" > "$NAMED_CONF_FILE.$$" || true
|
||||
mv -f "$NAMED_CONF_FILE.$$" "$NAMED_CONF_FILE"
|
||||
add_to_named_reload "all"
|
||||
fi
|
||||
}
|
||||
|
||||
change_mx() {
|
||||
local domain="$1"
|
||||
local mx="$2"
|
||||
local zone_file="$ZONES_DIR/$domain"
|
||||
local pattern="^@*[[:space:]]*IN[[:space:]]*MX[[:space:]]*[[:digit:]]*[[:space:]].*\$"
|
||||
local mx_line="@ IN MX 5 $mx."
|
||||
|
||||
# aller chercher le numéro de la ligne MX
|
||||
# XXX: comportement inconnu si plusieurs matchs ou MX commenté
|
||||
if grep -q "$pattern" "$zone_file"; then
|
||||
cp -a -f "$zone_file" "$zone_file.$$"
|
||||
sed -e "s/$pattern/$mx_line/" < "$zone_file" > "$zone_file.$$"
|
||||
mv "$zone_file.$$" "$zone_file"
|
||||
else
|
||||
echo "$mx_line" >> "$zone_file"
|
||||
fi
|
||||
|
||||
increment_serial "$domain"
|
||||
add_to_named_reload "$domain"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# imprime le nom d'usager associé au domaine
|
||||
get_account_by_domain() {
|
||||
# les admintools ne sont peut-être pas là
|
||||
if [ -x "/usr/bin/get_account_by_domain" ]
|
||||
then
|
||||
# only first field, only first line
|
||||
/usr/bin/get_account_by_domain "$1" | cut -d\ -f1 | cut -d'
|
||||
' -f 1
|
||||
else
|
||||
# implantons localement ce que nous avons besoin, puisque admintools
|
||||
# n'est pas là
|
||||
mysql --defaults-file=/etc/alternc/my.cnf -B -N -e \
|
||||
'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
||||
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
||||
fi
|
||||
# les admintools ne sont peut-être pas là
|
||||
if [ -x "/usr/bin/get_account_by_domain" ]
|
||||
then
|
||||
# only first field, only first line
|
||||
/usr/bin/get_account_by_domain "$1"|head -1|awk '{ print $1;}'
|
||||
else
|
||||
# implantons localement ce que nous avons besoin, puisque admintools
|
||||
# n'est pas là
|
||||
$MYSQL_DO 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
||||
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
||||
fi
|
||||
}
|
||||
|
||||
# add the standard input to a given file, only if not already present
|
||||
append_no_dupe() {
|
||||
realfile="$1"
|
||||
tmpfile=`mktemp`
|
||||
trap "rm -f $tmpfile; exit 1" 1 2 15
|
||||
cat > $tmpfile
|
||||
if [ -r "$realfile" ] &&
|
||||
(diff -q "$tmpfile" "$realfile" > /dev/null || \
|
||||
diff -u "$tmpfile" "$realfile" | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null)
|
||||
then
|
||||
ret=0
|
||||
else
|
||||
ret=1
|
||||
cat "$tmpfile" >> "$realfile"
|
||||
fi
|
||||
rm -f "$tmpfile"
|
||||
return "$ret"
|
||||
log_error() {
|
||||
local error=$1
|
||||
echo "`date` $0 : $1" | tee -a "$DOMAIN_LOG_FILE" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
add_dom_entry() {
|
||||
# protect ourselves from interrupts
|
||||
trap "rm -f ${override_f}.new; exit 1" 1 2 15
|
||||
# ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
|
||||
(echo "$1"; [ -r $override_f ] && cat $override_f) | \
|
||||
sort -u > ${override_f}.new && \
|
||||
cp ${override_f}.new ${override_f} && \
|
||||
rm ${override_f}.new
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
TEMPLATE_DIR="/etc/alternc/templates/apache2"
|
||||
HOSTING_DIR="/usr/lib/alternc/hosting_functions"
|
||||
|
||||
DATA_ROOT="/var/alternc"
|
||||
HTML_HOME="$DATA_ROOT/html"
|
||||
VHOST_DIR="$DATA_ROOT/apache-vhost"
|
||||
HTML_HOME="$ALTERNC_LOC/html"
|
||||
VHOST_DIR="$ALTERNC_LOC/apache-vhost"
|
||||
VHOST_FILE="$VHOST_DIR/vhosts_all.conf"
|
||||
|
||||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
host_create() {
|
||||
# Function to create a vhost for a website
|
||||
|
@ -79,7 +81,7 @@ host_create() {
|
|||
# Check if all is right in the conf file
|
||||
# If not, put a debug message
|
||||
local ISNOTGOOD=$(grep "%%" "$TMP_FILE")
|
||||
[ "$ISNOTGOOD" ] && (echo "# There was a probleme in the generation : $ISNOTGOOD" > "$TMP_FILE"
|
||||
[ "$ISNOTGOOD" ] && (echo "# There was a probleme in the generation : $ISNOTGOOD" > "$TMP_FILE" )
|
||||
|
||||
# Put the conf file in prod
|
||||
mkdir -p "$(dirname "$FILE_TARGET")"
|
||||
|
@ -87,7 +89,7 @@ host_create() {
|
|||
|
||||
# Execute post-install if there is some for this VTYPE
|
||||
[ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] && "$HOSTING_DIR/hosting_$VTYPE.sh" "postint" $@
|
||||
|
||||
|
||||
}
|
||||
|
||||
host_disable() {
|
||||
|
|
|
@ -1,92 +1,31 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# $Id: update_domaines.sh,v 1.31 2005/08/29 19:21:31 anarcat Exp $
|
||||
# ----------------------------------------------------------------------
|
||||
# AlternC - Web Hosting System
|
||||
# Copyright (C) 2002 by the AlternC Development Team.
|
||||
# http://alternc.org/
|
||||
# ----------------------------------------------------------------------
|
||||
# Based on:
|
||||
# Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
# ----------------------------------------------------------------------
|
||||
# LICENSE
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License (GPL)
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
# ----------------------------------------------------------------------
|
||||
# Original Author of file: Jerome Moinet for l'Autre Net - 14/12/2000
|
||||
# Purpose of file: system level domain management
|
||||
# ----------------------------------------------------------------------
|
||||
#
|
||||
#!/bin/bash
|
||||
# Update domain next-gen by fufrom
|
||||
|
||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
set -e
|
||||
for CONFIG_FILE in \
|
||||
/etc/alternc/local.sh \
|
||||
/usr/lib/alternc/functions.sh \
|
||||
/usr/lib/alternc/hosting_functions_v2.sh \
|
||||
/usr/lib/alternc/dns.sh
|
||||
do
|
||||
if [ ! -r "$CONFIG_FILE" ]; then
|
||||
echo "Can't access $CONFIG_FILE."
|
||||
exit 1
|
||||
fi
|
||||
. "$CONFIG_FILE"
|
||||
done
|
||||
|
||||
# Some vars
|
||||
umask 022
|
||||
LOCK_FILE="$ALTERNC_LOC/bureau/cron.lock"
|
||||
|
||||
########################################################################
|
||||
# Constants & Preliminary checks
|
||||
#
|
||||
|
||||
CONFIG_FILE="/etc/alternc/local.sh"
|
||||
|
||||
DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log"
|
||||
DATA_ROOT="/var/alternc"
|
||||
|
||||
NAMED_TEMPLATE="/etc/bind/templates/named.template"
|
||||
ZONE_TEMPLATE="/etc/bind/templates/zone.template"
|
||||
|
||||
ACTION_INSERT=0
|
||||
ACTION_UPDATE=1
|
||||
ACTION_DELETE=2
|
||||
TYPE_LOCAL=0
|
||||
TYPE_URL=1
|
||||
TYPE_IP=2
|
||||
TYPE_WEBMAIL=3
|
||||
TYPE_IPV6=4
|
||||
TYPE_CNAME=5
|
||||
TYPE_TXT=6
|
||||
YES=1
|
||||
|
||||
# Somes check before start operations
|
||||
if [ `id -u` -ne 0 ]; then
|
||||
echo "update_domains.sh must be launched as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -x "/usr/bin/get_account_by_domain" ]; then
|
||||
echo "Your AlternC installation is incorrect ! If you are using pre 0.9.4, "
|
||||
echo "you have to install alternc-admintools: "
|
||||
echo " apt-get update ; apt-get install alternc-admintools"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r "$CONFIG_FILE" ]; then
|
||||
echo "Can't access $CONFIG_FILE."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
. "$CONFIG_FILE"
|
||||
|
||||
if [ -z "$DEFAULT_MX" -o -z "$PUBLIC_IP" ]; then
|
||||
echo "Bad configuration. Please use:"
|
||||
echo " dpkg-reconfigure alternc"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
echo "`date` $0: last cron unfinished or stale lock file." |
|
||||
tee -a "$DOMAIN_LOG_FILE" >&2
|
||||
exit 1
|
||||
log_error "must be launched as root"
|
||||
elif [ -z "$DEFAULT_MX" -o -z "$PUBLIC_IP" ]; then
|
||||
log_error "Bad configuration. Please use: dpkg-reconfigure alternc"
|
||||
elif [ -f "$LOCK_FILE" ]; then
|
||||
log_error "last cron unfinished or stale lock file ($LOCK_FILE)."
|
||||
fi
|
||||
|
||||
# backward compatibility: single-server setup
|
||||
|
@ -94,167 +33,71 @@ if [ -z "$ALTERNC_SLAVES" ] ; then
|
|||
ALTERNC_SLAVES="localhost"
|
||||
fi
|
||||
|
||||
NAMED_CONF_FILE="$DATA_ROOT/bind/automatic.conf"
|
||||
ZONES_DIR="$DATA_ROOT/bind/zones"
|
||||
APACHECONF_DIR="$DATA_ROOT/apacheconf"
|
||||
OVERRIDE_PHP_FILE="$APACHECONF_DIR/override_php.conf"
|
||||
WEBMAIL_DIR="$DATA_ROOT/bureau/admin/webmail"
|
||||
LOCK_FILE="$DATA_ROOT/bureau/cron.lock"
|
||||
HTTP_DNS="$DATA_ROOT/dns"
|
||||
HTML_HOME="$DATA_ROOT/html"
|
||||
|
||||
MYSQL_SELECT="mysql --defaults-file=/etc/alternc/my.cnf -Bs "
|
||||
MYSQL_DELETE="mysql --defaults-file=/etc/alternc/my.cnf "
|
||||
|
||||
########################################################################
|
||||
# Functions
|
||||
#
|
||||
. /usr/lib/alternc/hosting_functions.sh
|
||||
|
||||
########################################################################
|
||||
# Main
|
||||
#
|
||||
|
||||
# Init
|
||||
|
||||
# We lock the application
|
||||
touch "$LOCK_FILE"
|
||||
DOMAINS_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
|
||||
HOSTS_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
|
||||
RELOAD_ZONES_TMP_FILE=`mktemp -t alternc.update_domains.XXXXXX`
|
||||
|
||||
cleanup() {
|
||||
rm -f "$LOCK_FILE" "$DOMAINS_TMP_FILE" "$HOSTS_TMP_FILE"
|
||||
rm -f "$RELOAD_ZONES_TMP_FILE"
|
||||
exit 0
|
||||
}
|
||||
# For domains we want to delete completely, make sure all the tags are all right
|
||||
# set sub_domaines.web_action = delete where domaines.dns_action = DELETE
|
||||
$MYSQL_DO "update sub_domaines sd, domaines d set sd.web_action = 'DELETE' where sd.domaine = d.domaine and sd.compte=d.compte and d.dns_action = 'DELETE';"
|
||||
|
||||
trap cleanup 0 1 2 15
|
||||
|
||||
# Query database
|
||||
|
||||
$MYSQL_SELECT <<EOF | tail -n '+1' > "$DOMAINS_TMP_FILE"
|
||||
SELECT membres.login,
|
||||
domaines_standby.domaine,
|
||||
if (domaines_standby.mx = '', '@', domaines_standby.mx),
|
||||
domaines_standby.gesdns,
|
||||
domaines_standby.gesmx,
|
||||
domaines_standby.action
|
||||
FROM domaines_standby
|
||||
LEFT JOIN membres membres
|
||||
ON membres.uid = domaines_standby.compte
|
||||
ORDER BY domaines_standby.action
|
||||
EOF
|
||||
|
||||
$MYSQL_SELECT <<EOF | tail -n '+1' > "$HOSTS_TMP_FILE"
|
||||
SELECT membres.login,
|
||||
sub_domaines_standby.domaine,
|
||||
if (sub_domaines_standby.sub = '', '@', sub_domaines_standby.sub),
|
||||
if (sub_domaines_standby.valeur = '', 'NULL',
|
||||
sub_domaines_standby.valeur),
|
||||
sub_domaines_standby.type,
|
||||
sub_domaines_standby.action
|
||||
FROM sub_domaines_standby
|
||||
LEFT JOIN membres membres
|
||||
ON membres.uid = sub_domaines_standby.compte
|
||||
ORDER BY sub_domaines_standby.action desc
|
||||
EOF
|
||||
|
||||
# Handle domain updates
|
||||
|
||||
if [ "`wc -l < $DOMAINS_TMP_FILE`" -gt 0 ]; then
|
||||
echo `date` >> $DOMAIN_LOG_FILE
|
||||
cat "$DOMAINS_TMP_FILE" >> $DOMAIN_LOG_FILE
|
||||
fi
|
||||
|
||||
# We need to tweak the IFS as $MYSQL_SELECT use tabs to separate fields
|
||||
OLD_IFS="$IFS"
|
||||
IFS=" "
|
||||
while read user domain mx are_we_dns are_we_mx action ; do
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
DOMAIN_LETTER=`print_domain_letter "$domain"`
|
||||
USER_LETTER=`print_user_letter "$user"`
|
||||
|
||||
case "$action" in
|
||||
$ACTION_INSERT)
|
||||
if [ "$are_we_dns" = "$YES" ] ; then
|
||||
init_zone "$domain"
|
||||
fi
|
||||
;;
|
||||
|
||||
$ACTION_UPDATE)
|
||||
if [ "$are_we_dns" = "$YES" ] ; then
|
||||
init_zone "$domain"
|
||||
change_mx "$domain" "$mx"
|
||||
else
|
||||
remove_zone "$domain"
|
||||
fi
|
||||
;;
|
||||
|
||||
$ACTION_DELETE)
|
||||
remove_zone "$domain"
|
||||
|
||||
# remove symlinks
|
||||
rm -f "${HTTP_DNS}/${DOMAIN_LETTER}/"*".$domain"
|
||||
rm -f "${HTTP_DNS}/${DOMAIN_LETTER}/$domain"
|
||||
rm -rf "${HTTP_DNS}/redir/${DOMAIN_LETTER}/"*".$domain"
|
||||
rm -rf "${HTTP_DNS}/redir/${DOMAIN_LETTER}/$domain"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown action code: $action" >> "$DOMAIN_LOG_FILE"
|
||||
;;
|
||||
esac
|
||||
|
||||
IFS=" "
|
||||
done < "$DOMAINS_TMP_FILE"
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
# Handle hosts update
|
||||
|
||||
if [ "`wc -l < $HOSTS_TMP_FILE`" -gt 0 ] ; then
|
||||
echo `date` >> $DOMAIN_LOG_FILE
|
||||
cat "$HOSTS_TMP_FILE" >> $DOMAIN_LOG_FILE
|
||||
fi
|
||||
|
||||
OLD_IFS="$IFS"
|
||||
IFS=" "
|
||||
while read user domain host value type action; do
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
case "$action" in
|
||||
$ACTION_UPDATE | $ACTION_INSERT)
|
||||
add_host "$domain" "$type" "$host" "$value" "$user"
|
||||
;;
|
||||
|
||||
$ACTION_DELETE)
|
||||
delete_host "$domain" "$host" "$type"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown action code: $action" >> "$DOMAIN_LOG_FILE"
|
||||
;;
|
||||
esac
|
||||
|
||||
IFS=" "
|
||||
done < "$HOSTS_TMP_FILE"
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
# Reload configuration for named and apache
|
||||
|
||||
RELOAD_ZONES=`cat "$RELOAD_ZONES_TMP_FILE"`
|
||||
|
||||
# we assume we run apache and bind on the master
|
||||
alternc_reload $RELOAD_ZONES || true
|
||||
for slave in $ALTERNC_SLAVES; do
|
||||
if [ "$slave" != "localhost" ]; then
|
||||
ssh alternc@$slave alternc_reload "$RELOAD_ZONES" || true
|
||||
fi
|
||||
# Sub_domaines we want to delete
|
||||
# sub_domaines.web_action = delete
|
||||
for sub in $( $MYSQL_DO "select if (length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) from sub_domaines sd where web_action ='DELETE';") ; do
|
||||
echo $sub
|
||||
# TODO Do the conf
|
||||
# TODO Update the entry in the DB with the result and the action
|
||||
done
|
||||
|
||||
# Cleanup
|
||||
# Sub domaines we want to update
|
||||
# sub_domaines.web_action = update and sub_domains.only_dns = false
|
||||
# TODO do the conf
|
||||
# TODO Update the entry in the DB with the result and the action
|
||||
|
||||
# Domains we do not want to be the DNS serveur anymore :
|
||||
# domaines.dns_action = UPDATE and domaines.gesdns = 0
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE' and gesdns = 0;") ; do
|
||||
dns_delete $dom
|
||||
$MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
done
|
||||
|
||||
# Domains we have to update the dns :
|
||||
# domaines.dns_action = UPDATE
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE';") ; do
|
||||
dns_regenerate $dom
|
||||
$MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
done
|
||||
|
||||
# Domains we want to delete completely, now we do it
|
||||
# domaines.dns_action = DELETE
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'DELETE';") ; do
|
||||
dns_delete $dom
|
||||
# Web configurations have already bean cleaned previously
|
||||
$MYSQL_DO "delete sub_domaines where domaine='$dom'; delete domaines where domaine='$dom';"
|
||||
done
|
||||
|
||||
|
||||
echo Exitbefore reload everything, we are testing, FUCK
|
||||
rm "$LOCK_FILE"
|
||||
exit 1
|
||||
# Concat the apaches files
|
||||
local tempo=$(mktemp /tmp/alternc-vhost.XXXXX)
|
||||
find "$VHOST_DIR" -type f -iname "*.conf" -exec cat '{}' >> "$tempo" \;
|
||||
if [ $? -ne 0 ] ; then
|
||||
log_error " web file concatenation failed"
|
||||
fi
|
||||
if [ ! -w "$VHOST_FILE" ] ; then
|
||||
log_error "cannot write on $VHOST_FILE"
|
||||
fi
|
||||
|
||||
mv "$tempo" "$VHOST_FILE"
|
||||
|
||||
# Reload web and dns
|
||||
alternc_reload all
|
||||
|
||||
# TODO reload slaves
|
||||
|
||||
rm "$LOCK_FILE"
|
||||
|
||||
exit 0
|
||||
|
||||
echo "DELETE FROM domaines_standby" | $MYSQL_DELETE
|
||||
echo "DELETE FROM sub_domaines_standby" | $MYSQL_DELETE
|
||||
|
||||
# vim: et sw=4
|
||||
|
|
Loading…
Reference in New Issue