From 33cb13286bae04961a4a135fd0cf01c9ba0ceeba Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Sun, 14 Nov 2010 16:54:27 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20gestion=20des=20sous-domaine?= =?UTF-8?q?=20IPv6=20ToDo:=20Pouvoir=20avoir=20un=20domaine=20simultan?= =?UTF-8?q?=C3=A9ment=20IPv4=20et=20IPv6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/admin/dom_edit.php | 7 +++++++ bureau/admin/dom_subdoedit.php | 6 +++++- bureau/admin/dom_subedit.php | 12 ++++++++++++ bureau/class/functions.php | 9 +++++++++ bureau/class/m_dom.php | 7 +++++++ src/functions.sh | 13 ++++++++++--- src/update_domains.sh | 1 + 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/bureau/admin/dom_edit.php b/bureau/admin/dom_edit.php index 0647fc8a..ec1a7a73 100644 --- a/bureau/admin/dom_edit.php +++ b/bureau/admin/dom_edit.php @@ -131,6 +131,13 @@ for($i=0;$i<$r["nsub"];$i++) { + + + type_ipv6); ?> onclick="document.main.sub_ip.focus();" /> + + + + type_webmail); ?>/> diff --git a/bureau/admin/dom_subdoedit.php b/bureau/admin/dom_subdoedit.php index 810a00b5..6841fa5d 100644 --- a/bureau/admin/dom_subdoedit.php +++ b/bureau/admin/dom_subdoedit.php @@ -36,6 +36,7 @@ $fields = array ( "sub_local" => array ("request", "string", "/"), "sub_url" => array ("request", "string", "http://"), "sub_ip" => array ("request", "string", ""), + "sub_ipv6" => array ("request", "string", ""), "action" => array ("request", "string", "add"), ); getFields($fields); @@ -52,6 +53,9 @@ switch ($type) { case $dom->type_ip: $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ip); break; + case $dom->type_ipv6: + $r=$dom->set_sub_domain($domain,$sub,$type,$action,$sub_ipv6); + break; case $dom->type_webmail: $r=$dom->set_sub_domain($domain,$sub,$type,$action,""); break; @@ -72,4 +76,4 @@ if (!$r) { include("dom_edit.php"); exit; -?> \ No newline at end of file +?> diff --git a/bureau/admin/dom_subedit.php b/bureau/admin/dom_subedit.php index 46f92318..b8b2404a 100644 --- a/bureau/admin/dom_subedit.php +++ b/bureau/admin/dom_subedit.php @@ -37,6 +37,7 @@ $fields = array ( "sub_local" => array ("request", "string", "/"), "sub_url" => array ("request", "string", "http://"), "sub_ip" => array ("request", "string", ""), + "sub_ipv6" => array ("request", "string", ""), "action" => array ("request", "string", "add"), ); getFields($fields); @@ -62,6 +63,9 @@ switch ($type) { case $dom->type_url: $sub_url=$r["dest"]; break; + case $dom->type_ipv6: + $sub_ipv6=$r["dest"]; + break; case $dom->type_ip: $sub_ip=$r["dest"]; break; @@ -106,10 +110,18 @@ $dom->unlock(); + type_ip); ?> onclick="document.main.sub_ip.focus();" /> + + + + type_ipv6); ?> onclick="document.main.sub_ipv6.focus();" /> + + + type_webmail); ?> /> diff --git a/bureau/class/functions.php b/bureau/class/functions.php index 200d157b..c8e7855a 100644 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -124,6 +124,15 @@ function checkip($ip) { return true; } +/* Check that $ip is a correct ipv6 ip */ +function checkipv6($ip) { + // return true or false whether the ip is correctly formatted + $pattern = +'/^((([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 */ function checkloginmail($mail) { if (!preg_match("/^[a-zA-Z0-9_\.:\+\-]*[a-zA-Z0-9_]$/",$mail)) { diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 8393c0fa..44606a2e 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -70,6 +70,7 @@ class m_dom { var $type_url = "1"; var $type_ip = "2"; var $type_webmail = "3"; + var $type_ipv6 = "4"; var $action_insert = "0"; var $action_update= "1"; @@ -700,6 +701,12 @@ class m_dom { return false; } } + if ($type==4) { // IPv6 + if (!checkipv6($dest)) { + $err->raise("dom",19); + return false; + } + } if ($type==1) { // URL if (!checkurl($dest)) { $err->raise("dom",20); diff --git a/src/functions.sh b/src/functions.sh index f96e94d1..2bc14a14 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -105,8 +105,13 @@ change_host_ip() { if [ -z "$host" ]; then host="@" fi - a_line="$host IN A $ip" - pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]*.*\$" + if [ "$host_type" = "$TYPE_IPV6" ]; then + a_line="$host IN AAAA $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*AAAA[[:space:]]*.*\$" + else + a_line="$host IN A $ip" + pattern="^$host[[:space:]]*IN[[:space:]]*A[[:space:]]*.*\$" + fi if [ ! -f "$zone_file" ]; then echo "Should change $host.$domain, but can't find $zone_file." return 1 @@ -143,6 +148,8 @@ add_host() { if [ "$host_type" = "$TYPE_IP" ]; then ip="$value" + elif [ "$host_type" = "$TYPE_IPV6" ]; then + ip="$value" else ip="$PUBLIC_IP" if [ "$host_type" != "$TYPE_WEBMAIL" ]; then @@ -211,7 +218,7 @@ delete_host() { if [ -f "$ZONES_DIR/$domain" ] ; then cp -a -f "$ZONES_DIR/$domain" "$ZONES_DIR/$domain.$$" - sed -e "/^$escaped_host[[:space:]]*IN[[:space:]]*A[[:space:]]/d" \ + sed -e "/^$escaped_host[[:space:]]*IN[[:space:]]*\(AAAA\|A\)[[:space:]]/d" \ < "$ZONES_DIR/$domain" > "$ZONES_DIR/$domain.$$" mv "$ZONES_DIR/$domain.$$" "$ZONES_DIR/$domain" increment_serial "$domain" diff --git a/src/update_domains.sh b/src/update_domains.sh index 4006664d..c38b6423 100755 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -53,6 +53,7 @@ TYPE_LOCAL=0 TYPE_URL=1 TYPE_IP=2 TYPE_WEBMAIL=3 +TYPE_IPV6=4 YES=1 if [ `id -u` -ne 0 ]; then