diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc
index 13ed5678e06b1d4e97a59b2f514d89549f44487c..02a887407c8096cd61d60eff0d1c173277805aad 100644 (file)
class servdnseditZone extends plugin
{
- /* CLI vars */
- var $cli_summary= "Manage server basic objects";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
/* attribute list for save action */
var $ignore_account= TRUE;
- var $attributes = array("zoneName","ReverseZone","dNSClass",
+ var $attributes = array("zoneName","ReverseZone","dNSClass","cn",
"sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl");
var $objectclasses = array("whatever");
var $InitialReverseZone = "";
var $InitialzoneName = "";
+ var $NetworkClass = "A" ; // One out of A,B,C
var $dialog = false;
var $isNew = true;
-
+ var $cn;
var $ZoneObject = array();
function servdnseditZone ($config, $dn= NULL,$attrs = array())
}else{
$this->ZoneObject = $attrs;
+
$this->OldZoneName = $attrs['zoneName'];
$this->OldReverseZone = $attrs['ReverseZone'];
$this->isNew = false;
foreach($this->attributes as $value){
- $this->$value = $attrs[$value];
+ if(isset($attrs[$value])){
+ $this->$value = $attrs[$value];
+ }
}
+
+ $this->sOAmail = preg_replace("/\./","@",$this->sOAmail,1);
+ $this->sOAmail = preg_replace("/\.$/","",$this->sOAmail);
+ $this->sOAprimary = preg_replace("/\.$/","",$this->sOAprimary);
+ $this->zoneName = preg_replace("/\.$/","",$this->zoneName);
+
if(isset($attrs['RECORDS'])){
$this->Records = $attrs['RECORDS'];
$tmp2[$tmp[0]] = $rec;
unset($this->Records[$key]);
}
+ if($rec['type'] == "nSRecord"){
+ unset($this->Records[$key]);
+ }
}
if(count($tmp2) != 0){
reset($tmp2);
$this->sOAserial = date("Ymd")."01";
}
}
+
+ /* Detect Network class */
+ if(!empty($this->ReverseZone)){
+
+ $dots = count(split(".",$this->ReverseZone));
+ if($dots == 0){
+ $this->NetworkClass = "A";
+ $this->ReverseZone .= ".0.0.0";
+ }elseif($dots == 1){
+ $this->NetworkClass = "B";
+ $this->ReverseZone .= ".0.0";
+ }else{
+ $this->NetworkClass = "C";
+ $this->ReverseZone .= ".0";
+ }
+ }
}
/* TRansports the geiven Arraykey one position up*/
$smarty->assign("AllowZoneEdit" , true);
if(isset($_POST['EditZoneEntries'])){
$this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->ZoneObject);
+ $this->dialog->parent = $this;
}
}
}
}else{
$this->dialog->save();
+ $rev = FlipIp(getNameFromMix($this->InitialReverseZone)).".in-addr.arpa";
+ $for = getNameFromMix($this->InitialzoneName);
+
+ $this->parent->handle_post_events("modify",array("dn" => $this->dn,"zoneName" => $rev));
+ $this->parent->handle_post_events("modify",array("dn" => $this->dn,"zoneName" => $for));
$this->dialog = false;
}
}
$smarty->assign($name,$this->$name);
}
+ /* Set zoneNames without server suffix */
+ foreach(array("zoneName","ReverseZone") as $attr){
+ $smarty->assign($attr,getNameFromMix($this->$attr));
+ }
$div = new DivSelectBox("MxRecords");
$div->setHeight(120);
}
/* Assign records list */
-
- $smarty->assign("NotNew", false);
-
+ $smarty->assign("NotNew", false);
$smarty->assign("Mxrecords", $div->DrawList());
$smarty->assign("records" , $this->generateRecordsList());
+ $smarty->assign("NetworkClass", $this->NetworkClass);
+ $smarty->assign("NetworkClasses", array("A"=>"255.0.0.0 (Class A)","B"=>"255.255.0.0 (Class B)","C"=>"255.255.255.0 (Class C)"));
/* Display tempalte */
$display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
}
}
+ if(isset($_POST['NetworkClass'])){
+ $this->NetworkClass = $_POST['NetworkClass'];
+ }
+
+ foreach(array("zoneName","ReverseZone") as $attr){
+ if(isset($_POST[$attr])){
+ $this->$attr = strtoupper($this->cn)."/".$_POST[$attr];
+ }
+ }
+
foreach($this->Records as $id => $value){
if(isset($_POST['RecordTypeSelectedFor_'.$id])){
$this->Records[$id]['type'] = $_POST['RecordTypeSelectedFor_'.$id];
/* Check supplied data */
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
+
/* Check if zoneName is already in use */
$usedZones = $this->getUsedZoneNames();
if(($this->isNew == true)||($this->zoneName != $this->InitialzoneName)||($this->ReverseZone != $this->InitialReverseZone)){
- if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitialzoneName)){
+/* if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitialzoneName)){
$message[] =_("This zoneName is already in use");
}
if((in_array($this->ReverseZone,$usedZones))&&($this->ReverseZone != $this->InitialReverseZone)){
$message[] =_("This reverse zone is already in use");
- }
+ }*/
}
- if(!preg_match("/\.$/",$this->sOAprimary)){
- $message[] = _("Primary dns server must end with '.' to be a valid entry.");
+ if(empty($this->zoneName)){
+ $message[] =sprintf(_("Please choose a valid zone name."));
}
- if(!preg_match("/\.$/",$this->sOAmail)){
- $message[] = _("Your specified mail address must end with '.' to be a valid record.");
+ if(empty($this->ReverseZone)){
+ $message[] =sprintf(_("Please choose a valid reverse zone name."));
}
- if(preg_match("/@/",$this->sOAmail)){
- $message[] = _("Your mail address contains '@' replace this with '.' to enable GOsa to create a valid SOA record.");
- }
-
- if(preg_match("/@/",$this->sOAmail)){
- $message[] = _("Your mail address contains '@' replace this with '.' to enable GOsa to create a valid SOA record.");
- }
-
- if($this->zoneName != strtolower($this->zoneName)){
+ if(getNameFromMix($this->zoneName) != strtolower(getNameFromMix($this->zoneName))){
$message[] = _("Only lowercase strings are allowed as zone name.");
}
$message[] = sprintf(_("Only lowercase is allowed, please check your '%ss'."),$values['type']);
}
}
+
+ /* Check class for given Zone Address */
+ $addr = preg_replace("/^[^\/]*+\//","",$this->ReverseZone);
+
+ /* Check for valid&complete IP address */
+ if(!is_ip($addr)){
+ $message[] = _("The given network address is not a valid, please specify a valid IP address.");
+ }
+
+ /* Check if given address matches selected network class */
+ switch($this->NetworkClass){
+ case 'A': {
+ if(!preg_match("/^[0-9]*\.0\.0\.0$/",$addr)){
+ $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.0.0.0"));
+ }
+ }
+ break;
+ case 'B': {
+ if(!preg_match("/^[0-9]*\.[0-9]*\.0\.0$/",$addr)){
+ $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.x.0.0"));
+ }
+ }
+ break;
+ case 'C': {
+ if(!preg_match("/^[0-9]*\.[0-9]*\.[0-9]*\.0$/",$addr)){
+ $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.x.x.0"));
+ }
+ }
+ break;
+ default : $message[] =sprintf(_("The given network class '%s' is not valid."),$this->NetworkClass);
+ }
+
return ($message);
}
$this->Records [] = $rec;
}
+
$ret['RECORDS'] = $this->Records;
+
+ switch($this->NetworkClass){
+ case 'C' : $ret['ReverseZone']= preg_replace("/\.[0-9]*$/","",$this->ReverseZone);break;
+ case 'B' : $ret['ReverseZone']= preg_replace("/\.[0-9]*\.[0-9]*$/","",$this->ReverseZone);break;
+ case 'A' : $ret['ReverseZone']= preg_replace("/\.[0-9]*\.[0-9]*\.[0-9]*$/","",$this->ReverseZone);break;
+ default : trigger_error("Invalid network class given '".$this->NetworkClass."'");
+ }
$ret['InitialReverseZone']= $this->InitialReverseZone;
$ret['InitialzoneName'] = $this->InitialzoneName;
+ $ret['sOAmail'] = preg_replace("/\@/",".",$this->sOAmail);
+
+ foreach(array("sOAprimary","zoneName","sOAmail") as $attr){
+ if(!preg_match("/\.$/",$ret[$attr])){
+ if(!is_ip($ret[$attr])){
+ $ret[$attr] = $ret[$attr].".";
+ }
+ }
+ }
+
+ $ret['RECORDS'][] = array("type" => "nSRecord","value" => $ret['sOAprimary']) ;
return($ret);
}