diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc
index 766344ea88f5feebc94c7d13638d6e257c2cfe52..f8866b2defa0f5970a56d455ec87748b6178d77f 100644 (file)
/* attribute list for save action */
var $ignore_account= TRUE;
/* attribute list for save action */
var $ignore_account= TRUE;
- var $attributes = array("zoneName","ReverseZone","dNSTTL","dNSClass",
+ var $attributes = array("zoneName","ReverseZone","dNSClass",
"sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl");
var $objectclasses = array("whatever");
"sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl");
var $objectclasses = array("whatever");
- var $RecordTypes = array();
+ var $RecordTypes = array();
var $ReverseZone = "";
var $ReverseZone = "";
- var $ReverseDN = "";
var $zoneName = "";
var $zoneName = "";
- var $dNSTTL = "7200";
var $dNSClass = "IN";
var $dNSClass = "IN";
- var $status = "new";
var $sOAprimary = "";
var $sOAmail = "";
var $sOAserial = "";
var $sOArefresh = "3600";
var $sOAretry = "1800";
var $sOAprimary = "";
var $sOAmail = "";
var $sOAserial = "";
var $sOArefresh = "3600";
var $sOAretry = "1800";
- var $sOAexpire = "";
+ var $sOAexpire = "720000";
var $sOAttl = "6400";
var $Records = array();
var $sOAttl = "6400";
var $Records = array();
+ var $mXRecords = array();
+
+ var $OldZoneName = ""; // To detect changes made with this edit
+ var $OldReverseZone = "";
+
+ var $InitialReverseZone = "";
+ var $InitialzoneName = "";
+
+ var $dialog = false;
- var $InitiallyZoneName = "";
- var $InitiallyReverseZone = "";
var $isNew = true;
var $isNew = true;
- function servdnseditZone ($config, $dn= NULL,$recordtypes,$attrs = array())
+ var $ZoneObject = array();
+
+ function servdnseditZone ($config, $dn= NULL,$attrs = array())
{
plugin::plugin ($config, $dn);
/* All types with required attrs */
{
plugin::plugin ($config, $dn);
/* All types with required attrs */
- $this->RecordTypes = $recordtypes;
+ $this->RecordTypes = getDnsRecordTypes(true);
if(!count($attrs)){
if(!count($attrs)){
- $this->InitiallyZoneName = "";
- $this->InitiallyReverseZone = "";
- $this->isNew = true;
+ $this->OldZoneName = "";
+ $this->OldReverseZone = "";
+ $this->isNew = true;
+ $this->sOAserial = date("Ymd")."1";
+
+ $this->InitialzoneName = "";//$attrs['InitialzoneName'];
+ $this->InitialReverseZone = "";//$attrs['InitialReverseZone'];
}else{
}else{
- $this->InitiallyZoneName = $attrs['zoneName'];
- $this->InitiallyReverseZone = $attrs['ReverseZone'];
+ $this->ZoneObject = $attrs;
+
+ $this->OldZoneName = $attrs['zoneName'];
+ $this->OldReverseZone = $attrs['ReverseZone'];
+
+ $this->InitialzoneName = $attrs['InitialzoneName'];
+ $this->InitialReverseZone = $attrs['InitialReverseZone'];
+
$this->isNew = false;
foreach($this->attributes as $value){
$this->$value = $attrs[$value];
}
$this->isNew = false;
foreach($this->attributes as $value){
$this->$value = $attrs[$value];
}
- if(isset($attrs['Records'])){
- $this->Records = $attrs['Records'];
+ if(isset($attrs['RECORDS'])){
+ $this->Records = $attrs['RECORDS'];
+
+ $tmp2 = array();
+ $usedPrio = array();
+ foreach($this->Records as $key => $rec){
+ if($rec['type'] == "mXRecord"){
+ $tmp = split(" ",$rec['value']);
+ $rec['value'] = $tmp[1];
+ $tmp2[$tmp[0]] = $rec;
+ unset($this->Records[$key]);
+ }
+ }
+ if(count($tmp2) != 0){
+ reset($tmp2);
+ ksort($tmp2);
+ }
+ $this->mXRecords = $tmp2;
}else{
}else{
- $this->Records = array();
+ $this->mXRecords = array();
+ $this->Records = array();
}
}
+
+ $str = date("Ymd");
+ if(preg_match("/^".$str."/",$this->sOAserial)){
+ $this->sOAserial = $this->sOAserial + 1;
+ }else{
+ $this->sOAserial = date("Ymd")."01";
+ }
+ }
+ }
+
+ /* TRansports the geiven Arraykey one position up*/
+ function ArrayUp($atr,$attrs)
+ {
+ $ret = $attrs;
+ $pos = $atr ;
+ $cn = count($attrs);
+ if(!(($pos == -1)||($pos == 1)||($pos >$cn))){
+ $before = array_slice($attrs,0,($pos-2));
+ $mitte = array_reverse(array_slice($attrs,($pos-2),2));
+ $unten = array_slice($attrs,$pos);
+ $ret = array();
+ $ret = $this->combineArrays($before,$mitte,$unten);
+ }
+ return($ret);
+ }
+
+
+ /* TRansports the geiven Arraykey one position up*/
+ function ArrayDown($atr,$attrs)
+ {
+ $ret = $attrs;
+ $pos = $atr ;
+ $cn = count($attrs);
+ if(!(($pos == -1)||($pos == $cn))){
+ $before = array_slice($attrs,0,($pos-1));
+ $mitte = array_reverse(array_slice($attrs,($pos-1),2));
+ $unten = array_slice($attrs,($pos+1));
+ $ret = array();
+ $ret = $this->combineArrays($before,$mitte,$unten);
}
}
+ return($ret);
}
}
+ /* Combine new array */
+ function combineArrays($ar0,$ar1,$ar2)
+ {
+ $ret = array();
+ if(is_array($ar0))
+ foreach($ar0 as $ar => $a){
+ $ret[]=$a;
+ }
+ if(is_array($ar1))
+ foreach($ar1 as $ar => $a){
+ $ret[]=$a;
+ }
+ if(is_array($ar2))
+ foreach($ar2 as $ar => $a){
+ $ret[]=$a;
+ }
+ return($ret);
+ }
+
+ function getpos($atr,$attrs)
+ {
+ $i = 0;
+ foreach($attrs as $attr => $name) {
+ $i++;
+ if($attr == $atr){
+ return($i);
+ }
+ }
+ return(-1);
+ }
+
+
function execute()
{
/* Call parent execute */
plugin::execute();
function execute()
{
/* Call parent execute */
plugin::execute();
+
/* Fill templating stuff */
$smarty= get_smarty();
$display= "";
/* Fill templating stuff */
$smarty= get_smarty();
$display= "";
+ /* Open Zone Entry Edit Dialog
+ */
+ if(!count($this->ZoneObject)){
+ $smarty->assign("AllowZoneEdit" , false);
+ }else{
+ $smarty->assign("AllowZoneEdit" , true);
+ if(isset($_POST['EditZoneEntries'])){
+ $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->ZoneObject);
+ }
+ }
+
+ /* Save Zone Entry Edit Dialog
+ */
+ if(isset($_POST['SaveZoneEntryChanges'])){
+ $this->dialog->save_object();
+ if(count($this->dialog->check())){
+ $msgs = $this->dialog->check();
+ foreach($msgs as $msg){
+ print_red($msg);
+ }
+ }else{
+ $this->dialog->save();
+ $this->dialog = false;
+ }
+ }
+
+ /* Cancel Zone Entrie Edit Dialog
+ */
+ if(isset($_POST['CancelZoneEntryChanges'])){
+ $this->dialog = false;
+ }
+
+ /* Display any type of open dialogs
+ */
+ if($this->dialog){
+ $this->dialog->save_object();
+ return($this->dialog->execute());
+ }
+
+ $once =true;
+ foreach($_POST as $name => $value){
+ if((preg_match("/^MXup_/",$name)) && ($once)){
+ $once = false;
+
+ $id = preg_replace("/^MXup_/","",$name);
+ $id = preg_replace("/_.*$/","",$id);
+ $id = base64_decode($id);
+
+ $this->mXRecords = $this->ArrayUp(($id+1),$this->mXRecords);
+ }
+ if((preg_match("/^MXdown_/",$name)) && ($once)){
+ $once = false;
+
+ $id = preg_replace("/^MXdown_/","",$name);
+ $id = preg_replace("/_.*$/","",$id);
+ $id = base64_decode($id);
+
+ $this->mXRecords = $this->ArrayDown(($id+1),$this->mXRecords);
+ }
+ if((preg_match("/^MXdel_/",$name)) && ($once)){
+ $once = false;
+
+ $id = preg_replace("/^MXdel_/","",$name);
+ $id = preg_replace("/_.*$/","",$id);
+ $id = base64_decode($id);
+
+ unset($this->mXRecords[$id]);
+
+ $tmp =array();
+ foreach($this->mXRecords as $entry){
+ $tmp[] = $entry;
+ }
+
+ $this->mXRecords = $tmp;
+ }
+ }
+
+ if((isset($_POST['AddMXRecord'])) && (!empty($_POST['StrMXRecord']))){
+ $this->mXRecords[] = array("type"=>"mXRecord","value"=>trim($_POST['StrMXRecord']));
+ }
+
/* Handle Post events */
$once = true;
foreach($_POST as $name => $value){
/* Handle Post events */
$once = true;
foreach($_POST as $name => $value){
if((preg_match("/RemoveRecord_/",$name))&&($once)){
$once = false;
$id= preg_replace("/RemoveRecord_/","",$name);
if((preg_match("/RemoveRecord_/",$name))&&($once)){
$once = false;
$id= preg_replace("/RemoveRecord_/","",$name);
- if($this->Records[$id]['status']!= "new"){
- $this->Records[$id]['status']= "deleted";
- }else{
- unset($this->Records[$id]);
- }
+ unset($this->Records[$id]);
}
}
/* Add new Zonerecord */
if(isset($_POST['AddNewRecord'])){
}
}
/* Add new Zonerecord */
if(isset($_POST['AddNewRecord'])){
- $this->Records[] = array("type"=>"aRecord","inittype"=>"","value"=>"","status"=>"new");
+ $this->Records[] = array("type"=>"aRecord","value"=>"");
}
/* Fill in values */
}
/* Fill in values */
$smarty->assign($name,$this->$name);
}
$smarty->assign($name,$this->$name);
}
+
+ $div = new DivSelectBox("MxRecords");
+ $div->setHeight(120);
+ $recs = $this->mXRecords;
+
+ $oneup = "<input name='MXup_%s' type='image' src='images/sort_up.png' title='"._("Up")."' class='center'> ";
+ $onedown = "<input name='MXdown_%s' type='image' src='images/sort_down.png' title='"._("Down")."' class='center'> ";
+ $onedel = "<img src='images/empty.png' width='20' class='center'>
+ <input name='MXdel_%s' type='image' src='images/edittrash.png' title='"._("Delete")."' class='center'>";
+
+ foreach($recs as $key => $rec){
+ $div ->AddEntry(array(
+ array("string"=>$rec['value']),
+/* array("string"=>$key,
+ "attach"=>"style='width:20px;'"),*/
+ array("string"=>str_replace("%s",base64_encode($key),$oneup.$onedown.$onedel),
+ "attach"=>"style='width:70px;border-right:0px;'")
+ ));
+ }
+
/* Assign records list */
/* Assign records list */
- $smarty->assign("records",$this->generateRecordsList());
+
+ $smarty->assign("NotNew", false);
+
+ $smarty->assign("Mxrecords", $div->DrawList());
+ $smarty->assign("records" , $this->generateRecordsList());
/* Display tempalte */
$display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
/* Display tempalte */
$display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
/* Check supplied data */
function check()
{
/* 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();
/* Check if zoneName is already in use */
$usedZones = $this->getUsedZoneNames();
- if(($this->isNew == true)||($this->zoneName != $this->InitiallyZoneName)||($this->ReverseZone != $this->InitiallyReverseZone)){
- if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitiallyZoneName)){
+ if(($this->isNew == true)||($this->zoneName != $this->InitialzoneName)||($this->ReverseZone != $this->InitialReverseZone)){
+/* if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitialzoneName)){
$message[] =_("This zoneName is already in use");
}
$message[] =_("This zoneName is already in use");
}
- if((in_array($this->ReverseZone,$usedZones))&&($this->ReverseZone != $this->InitiallyReverseZone)){
+ if((in_array($this->ReverseZone,$usedZones))&&($this->ReverseZone != $this->InitialReverseZone)){
$message[] =_("This reverse zone is already in use");
$message[] =_("This reverse zone is already in use");
+ }*/
+ }
+
+ if(empty($this->zoneName)){
+ $message[] =sprintf(_("Please choose a valid zone name."));
+ }
+
+ if(empty($this->ReverseZone)){
+ $message[] =sprintf(_("Please choose a valid reverse zone name."));
+ }
+
+ if(!preg_match("/\.$/",$this->sOAprimary)){
+ $message[] = _("Primary dns server must end with '.' to be a valid entry.");
+ }
+
+ if(!preg_match("/\.$/",$this->sOAmail)){
+ $message[] = _("Your specified mail address must end with '.' to be a valid record.");
+ }
+
+ 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)){
+ $message[] = _("Only lowercase strings are allowed as zone name.");
+ }
+
+ if(!is_numeric($this->sOAserial)){
+ $message[] = _("Please specify a numeric value for serial number.");
+ }
+
+ if(!is_numeric($this->sOArefresh)){
+ $message[] = _("Please specify a numeric value for refresh.");
+ }
+
+ if(!is_numeric($this->sOAttl)){
+ $message[] = _("Please specify a numeric value for ttl.");
+ }
+
+ if(!is_numeric($this->sOAexpire)){
+ $message[] = _("Please specify a numeric value for expire.");
+ }
+
+ if(!is_numeric($this->sOAretry)){
+ $message[] = _("Please specify a numeric value for retry.");
+ }
+
+ foreach($this->Records as $name => $values){
+ /* only lower-case is allowed in record entries ... */
+ if($values['value'] != strtolower($values['value'])){
+ $message[] = sprintf(_("Only lowercase is allowed, please check your '%ss'."),$values['type']);
}
}
return ($message);
}
}
}
return ($message);
}
+ /* This funtion returns all used Zonenames */
function getUsedZoneNames()
{
$ret = array();
function getUsedZoneNames()
{
$ret = array();
$ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",array("zoneName","tXTRecord"));
while($attr = $ldap->fetch()){
if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
$ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",array("zoneName","tXTRecord"));
while($attr = $ldap->fetch()){
if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
- $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
- $ret[$zn] = preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]);
+ if(isset($attr['tXTRecord'][0])){
+ $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
+ $ret[$zn] =FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
+ }
}else{
$ret[$attr['zoneName'][0]]="";
}
}
return($ret);
}
}else{
$ret[$attr['zoneName'][0]]="";
}
}
return($ret);
}
-
/* Save to LDAP */
function save()
/* Save to LDAP */
function save()
foreach($this->attributes as $name){
$ret[$name] = $this->$name;
}
foreach($this->attributes as $name){
$ret[$name] = $this->$name;
}
- $ret['Records'] = $this->Records;
+
+ /* Create mx records
+ */
+ foreach($this->mXRecords as $key => $rec){
+ $rec['value']= $key." ".$rec['value'];
+ $this->Records [] = $rec;
+ }
+
+ $ret['RECORDS'] = $this->Records;
+
+ $ret['InitialReverseZone']= $this->InitialReverseZone;
+ $ret['InitialzoneName'] = $this->InitialzoneName;
+
return($ret);
}
return($ret);
}
+
+ /* This function generate a table row for each used record.
+ This table row displays the recordtype in a select box
+ and the specified value for the record, and a remove button.
+ The last element of the table also got an 'add' button.
+ */
function generateRecordsList($changeStateForRecords="")
{
$changeStateForRecords = "";
$str = "<table summary=''>";
foreach($this->Records as $key => $entry){
function generateRecordsList($changeStateForRecords="")
{
$changeStateForRecords = "";
$str = "<table summary=''>";
foreach($this->Records as $key => $entry){
- if($entry['status'] == "deleted") continue;
+ if($entry['type'] == "mXRecord") continue;
+
$changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
$changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
$changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
$changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
$changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
$changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
return($str);
}
return($str);
}
+ /* This function generates a select box out of $this->RecordTypes options.
+ The Parameter $selected is used to predefine an attribute.
+ $name is used to specify a post name
+ */
function generateRecordListBox($selected,$name)
{
$str = "<select name='".$name."' id='".$name."'>";
foreach($this->RecordTypes as $type => $value){
function generateRecordListBox($selected,$name)
{
$str = "<select name='".$name."' id='".$name."'>";
foreach($this->RecordTypes as $type => $value){
+
+ if(preg_match("/^mXRecord$/i",$value)) continue;
+
$use = "";
if($type == $selected){
$use = " selected ";
}
$use = "";
if($type == $selected){
$use = " selected ";
}
- $str.="\n <option value='".$type."' ".$use.">".$type."</option>";
+ $str.="\n <option value='".$type."' ".$use.">".strtoupper(preg_replace("/record/i","",$type))."</option>";
}
$str.="</select>";
return($str);
}
$str.="</select>";
return($str);