index a876012c44dc99e782d5cc963aa125498dc8c839..fed9c92f71120d54fd01530aac9e7d3fe50f5c8c 100644 (file)
<?php
-class servdns extends plugin
+class servdns extends goService
{
/* CLI vars */
var $cli_summary= "Manage server basic objects";
var $objectclasses = array("whatever");
var $RecordTypes = array();
+ var $Zones = array();
- var $Zones = array();
- var $dialog = NULL;
+ var $orig_dn = "";
- var $usedDNS = array();
-
- var $orig_dn = "";
+ var $initially_was_account;
+
+ /* ServerService tab vars */
+ var $conflicts = array("servdns");
+ var $DisplayName = "";
+ var $StatusFlag = "";
+ var $view_logged = FALSE;
- var $DNSinitially_was_account;
+ var $dns_server_list = array("ENTRIES"=> array(),"FOR_LIST"=> array());
+ var $take_over_id = -1;
- function servdns ($config, $dn= NULL)
+ function servdns (&$config, $dn= NULL, $parent= NULL)
{
- plugin::plugin ($config, $dn);
-
- $this->orig_dn = $dn;
-
- /* All types with required attrs */
- $this->RecordTypes['aRecord'] = "aRecord"; // ok
- $this->RecordTypes['mDRecord'] = "mDRecord"; // ok
- $this->RecordTypes['mXRecord'] = "mXRecord"; // ok
- $this->RecordTypes['nSRecord'] = "nSRecord"; // ok
- $this->RecordTypes['hInfoRecord'] = "hInfoRecord"; // ok
- $this->RecordTypes['mInfoRecord'] = "mInfoRecord"; // ok
-// $this->RecordTypes['tXTRecord'] = "tXTRecord"; // ok
- $this->RecordTypes['aFSDBRecord'] = "aFSDBRecord"; // ok
- $this->RecordTypes['SigRecord'] = "SigRecord"; // ok
- $this->RecordTypes['KeyRecord'] = "KeyRecord"; // ok
- $this->RecordTypes['aAAARecord'] = "aAAARecord"; // ok
- $this->RecordTypes['LocRecord'] = "LocRecord"; // ok
- $this->RecordTypes['nXTRecord'] = "nXTRecord"; // ok
- $this->RecordTypes['sRVRecord'] = "sRVRecord"; // ok
- $this->RecordTypes['nAPTRRecord'] = "nAPTRRecord"; // ok
- $this->RecordTypes['kXRecord'] = "kXRecord"; // ok
- $this->RecordTypes['certRecord'] = "certRecord"; // ok
- $this->RecordTypes['a6Record'] = "a6Record"; // ok
- $this->RecordTypes['dSRecord'] = "dSRecord"; // ok
- $this->RecordTypes['sSHFPRecord'] = "sSHFPRecord"; // ok
- $this->RecordTypes['rRSIGRecord'] = "rRSIGRecord"; // ok
- $this->RecordTypes['nSECRecord'] = "nSECRecord"; // ok
-
- $types = array();
-
- /* Get all records */
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->dn);
- $ldap->ls("(&(objectClass=dNSZone)(relativeDomainName=@))",$dn,array("*"));
-
- while($attrs = $ldap->fetch()){
-
- /* If relative domainname
- * Try to read dnsclass / TTl / zone
- */
- $this->usedDNS[$attrs['dn']] = $attrs['dn'];
- if((isset($attrs['tXTRecord'][0]))&&(preg_match("/zoneName\=/",$attrs['tXTRecord'][0]))){
- $zoneName= preg_replace("/zoneName\=/","",$attrs['tXTRecord'][0]);
- $z = preg_replace("/\.in\-addr\.arpa/","",$attrs['zoneName'][0]);
-
- $z = $this->FlipIp($z);
-
- $types[$zoneName]['ReverseZone'] = $z;
- $types[$zoneName]['ReverseDN'] = $attrs['dn'];
- }else{
-
- /* Generate SOA entry
- */
- if(isset($attrs['sOARecord'][0])){
- $tmp = split("\ ",$attrs['sOARecord'][0]) ;
- $tmp2 = array();
- $ar = array("0"=>"sOAprimary","1"=>"sOAmail","2"=>"sOAserial","3"=>"sOArefresh","4"=>"sOAretry","5"=>"sOAexpire","6"=>"sOAttl");
-
- /* Assign soa vars */
- foreach($ar as $key => $name){
- if(isset($tmp[$key])){
- $types[$attrs['zoneName'][0]][$name] = $tmp[$key];
- }else{
- $types[$attrs['zoneName'][0]][$name] = "";
- }
- }
- }
+ plugin::plugin ($config, $dn, $parent);
- /* Set dns Class
- */
- if(isset($attrs['dNSClass'][0])){
- $types[$attrs['zoneName'][0]]['dNSClass'] = $attrs['dNSClass'][0];
- }
+ $this->DisplayName = _("DNS service");
- /* Set zone Name
- */
- if(isset($attrs['zoneName'][0])){
- $types[$attrs['zoneName'][0]]['zoneName'] = $attrs['zoneName'][0];
- }
+ $this->orig_dn = $dn;
- /* Create list with all used records
- */
- foreach($this->RecordTypes as $name => $value){
-
- /* If there is a record attribute
- */
- if(isset($attrs[$name])){
-
- /* get all entries
- */
- for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
- $types[$attrs['zoneName'][0]]['Records'][] =array("type" =>$name,
- "inittype" =>$name,
- "value" =>$attrs[$value][$i],
- "status" =>"edited",
- "dn" =>$attrs['dn']);
- }
- }
- }
- }
- }
+ /* Get record types for zones
+ */
+ $this->RecordTypes = getDnsRecordTypes(true);
+ /* Get all zone Informations
+ */
+ $this->Zones = getDNSZoneEntries($config,$dn);
+
/* If there is at least one entry in this -> types, we have DNS enabled
*/
- $this->Zones = $types;
if(count($this->Zones) == 0){
$this->is_account = false;
+ $this->dns_server_list = $this->get_list_of_dns_servers();
}else{
$this->is_account = true;
}
-
- /* Store initally account settings
- */
- $this->DNSinitially_was_account = $this->is_account;
+ $this->initially_was_account = $this->is_account;
}
- /* this is used to flip the ip address for example
- 12.3.45 -> 54.3.12
- Because some entries (like zones) are store like that 54.3.12.in-addr.arpa
- but we want to display 12.3.45.
- */
- function FlipIp($ip)
+ function get_list_of_dns_servers()
+ {
+ $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array());
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=dNSZone)(zoneName=*))",array("dn","zoneName"));
+ $dns = array();
+ while($attrs = $ldap->fetch()){
+ /* Skip own config */
+ if($this->dn != "new" && preg_match("/".normalizePreg($this->dn)."$/",$attrs['dn'])){
+ continue;
+ }
+ $dn = preg_replace("/^zoneName=[^,]+,/","",$attrs['dn']);
+ if(preg_match("/^cn=/",$dn) && !in_array($dn,$dns)){
+ $dns[] = $dn;
+ }
+ }
+ $i = 0;
+ foreach($dns as $dn){
+ $ldap->cat($dn,array('*'));
+ if($ldap->count()){
+ $i ++;
+ $attrs = $ldap->fetch();
+ $ret['ENTRIES'][$i] = $attrs;
+ $ret['FOR_LIST'][$i] = $attrs['cn'][0];
+ }
+ }
+ return($ret);
+ }
+
+
+ function get_dns_info_string($id)
{
- $tmp = array_reverse(split("\.",$ip));
- $new = "";
- foreach($tmp as $section){
- $new .= $section.".";
+ $ret="";
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dns_server_list['ENTRIES'][$id]['dn']);
+ $ldap->search("(|(zoneName=*)(relativeDomainName=*))",array("dn"));
+ while($attrs = $ldap->fetch()){
+ $ret .= $attrs['dn']."\n";
}
- return(preg_replace("/.$/","",$new));
+ return($ret);
}
+
function execute()
{
/* Call parent execute
*/
plugin::execute();
+ if($this->is_account && !$this->view_logged){
+ $this->view_logged = TRUE;
+ new log("view","server/".get_class($this),$this->dn);
+ }
+
/* Fill templating stuff
*/
$smarty= get_smarty();
+ $smarty->assign("dns_take_over",FALSE);
+ $smarty->assign("is_createable",$this->acl_is_createable());
$display= "";
+
+ $this->initially_was_account= $this->is_account;
+ /*****************/
+ /* Handle Take Over Actions
+ /*****************/
+
+ /* Give smarty the required informations */
+ $smarty->assign("dns_server_list", $this->dns_server_list['FOR_LIST']);
+ $smarty->assign("dns_server_list_cnt", count($this->dns_server_list['FOR_LIST']));
+
+ /* Take over requested, save id */
+ if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){
+ $id = $_POST['take_over_src'];
+ if(isset($this->dns_server_list['ENTRIES'][$id])){
+ $this->take_over_id = $id;
+ }
+ }
+
+ /* Abort take over action */
+ if(isset($_POST['cancel_take_over'])){
+ $this->dialog =false;
+ $this->take_over_id = -1;
+ $this->dns_server_list = $this->get_list_of_dns_servers();
+ }
+
+ /* Display informartion about take over that will be started when saving this server
+ * and hide default dns output
+ */
+ if($this->take_over_id != -1){
+ $this->dialog = FALSE;
+ $id = $this->take_over_id;
+ $info = $this->get_dns_info_string($id);
+ $smarty->assign("dns_take_over",TRUE);
+ $smarty->assign("info",$info);
+ $warning = sprintf(_("You are going to migrate the DNS setup from server '%s'."),$this->dns_server_list['ENTRIES'][$id]['cn'][0]);
+ $warning2 = _("The migration will be startet when you save this system. To cancel this action, use the cancel button below.");
+ $smarty->assign("warning",$warning);
+ $smarty->assign("warning2",$warning2);
+ return($smarty->fetch(get_template_path('servdns.tpl', TRUE)));
+ }
+
+
/* Do we need to flip is_account state?
*/
if (isset($_POST['modify_state'])){
$this->is_account= !$this->is_account;
}
- /* Show tab dialog headers
- */
if ($this->is_account){
- $display= $this->show_header(_("Remove DNS service"),
+ $display= $this->show_disable_header(_("Remove DNS service"),
_("This server has DNS features enabled. You can disable them by clicking below."));
} else {
- $display= $this->show_header(_("Add DNS service"),
+ $display= $this->show_enable_header(_("Add DNS service"),
_("This server has DNS features disabled. You can enable them by clicking below."));
return ($display);
}
- /* Edited or Added zone hould be saved saved
+
+ /* Edited or Added zone
*/
if(isset($_POST['SaveZoneChanges'])){
$this->dialog->save_object();
- /* Check if noting went wrong
+ /* Check for errors
*/
if(count($this->dialog->check())){
foreach($this->dialog->check() as $msgs){
print_red($msgs);
}
}else{
-
/* add new/edited zone
*/
$ret = $this->dialog->save();
- $ret['InitialzoneName']= $this->dialog->InitiallyZoneName;
- $ret['InitialreverseZone']= $this->dialog->InitiallyReverseZone;
- unset($this->Zones[$this->dialog->InitiallyZoneName]);
- $this->Zones[$ret['zoneName']] = $ret;
- $this->dialog = NULL;
+ if(!$this->dialog->isNew){
+ unset($this->Zones[$this->dialog->OldZoneName]);
+ }
+ $this->Zones[$ret['zoneName']] = $ret;
+ $this->dialog = FALSE;
}
}
/* Cancel zone edit / new
*/
if(isset($_POST['CancelZoneChanges'])){
- $this->dialog = NULL;
+ $this->dialog = FALSE;
}
/* Add empty new zone
*/
if(isset($_POST['AddZone'])){
- $this->dialog = new servdnseditZone($this->config,$this->dn,$this->RecordTypes);
+ $this->dialog = new servdnseditZone($this->config,$this->dn);
}
/* Check for edit zone request
$once =true;
$tmp = preg_replace("/^editZone_/","",$name);
$tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
- $this->dialog= new servdnseditZone($this->config,$this->dn,$this->RecordTypes,$this->Zones[$tmp]);
+ $this->dialog= new servdnseditZone($this->config,$this->dn,$this->Zones[$tmp]);
}
/* check posts for delete zone
*/
if(preg_match("/^delZone_/",$name)&&!$once){
+
$once =true;
$tmp = preg_replace("/^delZone_/","",$name);
$tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
-
- $zones = $this->getUsedZoneNames();
- $rev = $this->Zones[$tmp]['ReverseZone'];
- $res = array_merge(($zones[$tmp]),($zones[$rev.".in-addr.arpa"]));
-
- if(count($res)){
- $i = 2;
- $str ="";
- foreach($res as $dn){
- if($i > 0 ){
- $i --;
- $str.=$dn." ";
- }
- }
- if(count($res)> 2) $str .=" ... ";
- print_red(sprintf(_("Can't delete the selected zone, because it is still in use by these entry/entries '%s'"),trim($str)));
- }else{
- unset($this->Zones[$tmp]);
- }
+
+ /* Initiate deletion
+ */
+ $this->RemoveZone($tmp);
+ }
+ }
+
+ if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
+ $id = base64_decode($_GET['id']);
+ if(isset($this->Zones[$id])){
+ $this->dialog= new servdnseditZone($this->config,$this->dn,$this->Zones[$id]);
+ }
+ }
+
+ if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
+ $id = base64_decode($_GET['id']);
+ if(isset($this->Zones[$id])){
+ $this->dialog= new servdnseditZone($this->config,$this->dn,$this->Zones[$id]);
}
}
/* Show dialog
*/
- if($this->dialog!= NULL){
+ if(is_object($this->dialog)){
$this->dialog->save_object();
$this->dialog->parent = $this;
return($this->dialog->execute());
/* Add entries to divlist
*/
- $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>
- <input type='image' src='images/edittrash.png' name='delZone_%s'>";
+ $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>";
+ if($this->acl_is_removeable()){
+ $editImg.= "<input type='image' src='images/edittrash.png' name='delZone_%s'>";
+ }
+
+ $link = "<a href='?plug=".$_GET['plug']."&act=edit&id=%s'>%s</a>";
foreach($this->Zones as $zone => $values ){
$ZoneList->AddEntry(array(
- array("string" => $zone),
- array("string" => _("Reverse zone")." : ".$values['ReverseZone']),
+ array("string" => sprintf($link,base64_encode($zone),($zone))),
+ array("string" => sprintf($link,base64_encode($zone),_("Reverse zone")." : ".($values['ReverseZone']))),
array("string" => _("TTL")." : ".$values['sOAttl']),
array("string" => _("Class")." : ".$values['dNSClass']),
array("string" =>str_replace("%s",base64_encode($zone),$editImg))
}
+ /* Delete specified zone
+ */
+ function RemoveZone($id)
+ {
+ $zones = $this->getUsedZoneNames();
+
+ if(isset($this->Zones[$id]['InitialReverseZone'])){
+ $rev = FlipIp($this->Zones[$id]['InitialReverseZone']);
+ }else{
+ $rev = FlipIp($this->Zones[$id]['ReverseZone']);
+ }
+
+ $zonename = "";
+ if(isset($this->Zones[$id]['InitialzoneName'])){
+ $zonename= $this->Zones[$id]['InitialzoneName'];
+ }
+
+ $used = array();
+
+ /* Add Records which use this zoneName
+ */
+ if(isset($zones[$zonename])){
+ $used = array_merge($used,$zones[$zonename]);
+ }
+
+ /* Add Records which uses this reverse zone
+ */
+ if(isset($zones[$rev.".in-addr.arpa"])){
+ $used = array_merge($used,$zones[$rev.".in-addr.arpa"]);
+ }
+
+ /* There are still entries using this configuration
+ * Abort deletion
+ */
+ if(count($used)){
+ $i = 2;
+ $str ="";
+ foreach($used as $dn){
+ if($i > 0 && !preg_match("/,relativeDomainName=/",$dn)){
+ $i --;
+ $name = preg_replace("/^[^=]+=([^,]*),.*$/","\\1",$dn);
+ $zone = preg_replace("/^.*zoneName=([^,]*),.*$/","\\1",$dn);
+ $str.= $name.".".$zone." ";
+ }
+ }
+
+ /* Only show 2 dns in the error message
+ */
+ if(count($used)> 2) {
+ $str .=" ... ";
+ }
+ print_red(sprintf(_("Can't delete the selected zone, because it is still in use by these entry/entries '%s'"),trim($str)));
+ return(false);
+ }else{
+ unset($this->Zones[$id]);
+ return(true);
+ }
+ }
+
+
/* This funtion returns all used Zonenames
*/
function getUsedZoneNames()
$ret = array();
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=dNSZone)(!(relativeDomainName=@))(zoneName=*))",array("zoneName","relativeDomainName","tXTRecord"));
+ $ldap->search("(&(objectClass=dNSZone)(!(relativeDomainName=@))(zoneName=*))",array("zoneName","relativeDomainName"));
while($attr = $ldap->fetch()){
- if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
- $ret[$attr['zoneName'][0]][] = $attr['dn'];
- }else{
- $ret[$attr['zoneName'][0]][] = $attr['dn'];
- }
+ $ret[$attr['zoneName'][0]][] = $attr['dn'];
}
return($ret);
}
*/
function remove_from_parent()
{
- if(!$this->DNSinitially_was_account){
- return;
- }
-
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- foreach($this->usedDNS as $dn){
- $ldap->cd($dn);
- $ldap->rmdir_recursive($dn);
- }
+ if($this->initially_was_account){
+ $bool = true;
+ $this->is_account = FALSE;
+ foreach($this->Zones as $key => $zone){
+ $bool= $bool & $this->RemoveZone($key);
+ }
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->orig_dn);
- $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=@))",array("relativeDomainName","zoneName"));
- while($attr = $ldap->fetch()){
- $ldap->cd($attr['dn']);
- $ldap->rmDir($attr['dn']);
+ if($bool){
+ $this->save();
+ }
+ return($bool);
}
-
-
- show_ldap_error($ldap->get_error());
- }
-
-
- /* Save data to object */
- function save_object()
- {
- }
-
-
- /* Check supplied data */
- function check()
- {
- $message= array();
- return ($message);
}
/* Save to LDAP */
function save()
{
- /* Ldap conenction / var initialization
- */
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- $actions =array("update"=>array(),"add"=>array(),"delete"=>array());
- /* Generate entries for all zones, and check if they must be updated deleted added
+ /* Take over handling
+ * - Create list of zones managed by source server
+ * - Copy ldap entries to destination server
+ * - Remove old zone entries from source
*/
- foreach($this->Zones as $key => $zone){
- if(isset($zone['InitialzoneName']) && ($zone['zoneName'] != $zone['InitialzoneName'])){
- $dst = "zoneName=".$zone['zoneName'].",".$this->dn;
- $src = "zoneName=".$zone['InitialzoneName'].",".$this->dn;
- $this->recursive_move($src,$dst);
-
- $tmp['zoneName'] = $zone['zoneName'];
- $ldap->search ("(&(objectClass=dNSZone)(zoneName=".$zone['InitialzoneName']."))",array("relativeDomainName"));
- while($attrs = $ldap->fetch()){
- $ldap->cd($attrs['dn']);
- $ldap->modify($tmp);
- show_ldap_error($ldap->get_error());
+ if($this->take_over_id != -1){
+ $del = array();
+ $id = $this->take_over_id;
+ $src = $this->dns_server_list['ENTRIES'][$id]['dn'];
+ $ldap = $this->config->get_ldap_link();
+ $ldap->ls("(objectClass=dnsZone)",$src,array('cn'));
+ while($attrs = $ldap->fetch()){
+ $src_zone = $attrs['dn'];
+ $dst_zone = preg_replace("/".normalizePreg($src)."$/",$this->dn,$src_zone);
+ $res = plugin::recursive_move($src_zone, $dst_zone);
+
+ if($res){
+ $del [] = $src_zone;
}
}
- if(isset($zone['InitialreverseZone']) &&($zone['InitialreverseZone'] != $zone['ReverseZone'])){
- $dst = "zoneName=".$zone['ReverseZone'].",".$this->dn;
- $src = "zoneName=".$zone['InitialreverseZone'].",".$this->dn;
- $this->recursive_move($src,$dst);
-
- $tmp['zoneName'] = $zone['zoneName'];
- $ldap->search ("(&(objectClass=dNSZone)(zoneName=".$zone['InitialzoneName']."))",array("relativeDomainName"));
- while($attrs = $ldap->fetch()){
- $ldap->cd($attrs['dn']);
- $ldap->modify($tmp);
- show_ldap_error($ldap->get_error());
- }
- }
-
-
- /* Get ldap syntax
- */
- $tmp = $this->generate_LDAP_entries($zone);
+ foreach($del as $src_zone){
+ $ldap->rmdir_recursive($src_zone);
+ }
+ return;
+ }
- /* Check if dn is new, or if entry was edited
- */
- foreach($tmp as $key => $values){
- if(isset($this->usedDNS[$key])){
- $actions['update'][$key]=$values;
- unset($this->usedDNS[$key]);
- }else{
- $actions['add'][$key] = $values;
- }
+ /* Save zone editor changes now */
+ foreach($this->Zones as $name => $zone){
+ if(isset($zone['zoneEditor'] ) && $zone['zoneEditor'] != NULL && is_object($zone['zoneEditor'])){
+ $zone['zoneEditor']->save();
+ unset($this->Zones[$name]['zoneEditor']);;
}
}
- /* Check which dns are not used anymore ...
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+
+ /* Get differences
*/
- foreach($this->usedDNS as $key => $values){
- $actions['delete'][$key] = $values;
+ $old_dn = $this->orig_dn;
+ if($old_dn == "new"){
+ $old_dn = $this->dn;
+ }
+
+ $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
+
+ /* Update dns to current object dn */
+ $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
+ $tmp2 = array();
+ foreach($tmp as $key1 => $data1){
+ $tmp2[$key1] = array();
+ foreach($data1 as $key2 => $data2){
+ $tmp2[$key1][preg_replace("/".normalizePreg($old_dn)."$/",$this->dn,$key2)] = $data2;
+ }
}
+ $tmp = $tmp2;
- /* Remove deleted zones
+ /* Updated zone entries if reverser or forward name has changed
+ * Must be done before moving entries, else the given dn is invalid
*/
- foreach($actions['delete'] as $dn => $attrs){
+ if(isset($tmp['zoneUpdates'])){
+ foreach($tmp['zoneUpdates'] as $dn => $attrs){
+ $ldap->cd($dn);
+ $ldap->modify($attrs);
+ new log("modfiy","unknown/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+ show_ldap_error($ldap->get_error(), sprintf(_("Updating of system server/dns with dn '%s' failed."),$this->dn));
+ }
+ }
+
+ /* Delete dns
+ */
+ foreach($tmp['del'] as $dn => $del){
+
+ $for = $del['InitialzoneName'];
+ $rev = FlipIp($del['InitialReverseZone']).".in-addr.arpa";
+
$ldap->cd($dn);
$ldap->rmdir_recursive($dn);
+ new log("remove","unknown/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing of system server/dns with dn '%s' failed."),$this->dn));
+
+ /* Handle Post events */
+ if(preg_match("/^zoneName=/",$dn)){
+# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $for));
+# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $rev));
+ }
}
- /* Add new zones
+ /* move follwoing entries
*/
- foreach($actions['add'] as $dn => $attrs){
- $ldap->cd($this->config->current['BASE']);
- $ldap->cd($dn);
- $ldap->add($attrs);
+ foreach($tmp['move'] as $src => $dst){
+ $this->recursive_move($src,$dst);
}
- /* Update existing entries
+ /* Add || Update new DNS entries
*/
- foreach($actions['update'] as $dn => $attrs){
+ foreach($tmp['add'] as $dn => $attrs){
$ldap->cd($dn);
- $ldap->modify ($attrs);
+ $ldap->cat($dn, array('dn'));
+ if($ldap->fetch()){
+ $ldap->cd($dn);
+ $ldap->modify ($attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/dns with dn '%s' failed."),$this->dn));
+
+ /* Handle Post events */
+ if(preg_match("/^zoneName=/",$dn)){
+# $this->handle_post_events("modify",array("dn" => $dn,"zoneName" => $attrs['zoneName']));
+ }
+ }else{
+ $ldap->cd($dn);
+ $ldap->add($attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/dns with dn '%s' failed."),$this->dn));
+ /* Handle Post events */
+ if(preg_match("/^zoneName=/",$dn)){
+# $this->handle_post_events("add",array("dn" => $dn,"zoneName" => $attrs['zoneName']));
+ }
+ }
}
-
- show_ldap_error($ldap->get_error());
+ $this->handle_post_events("modify");
}
- /* This function generates ldap friendly output
- of all changes for a single zone (reverse and forward)
- */
- function generate_LDAP_entries($zone)
+ /* Directly save new status flag */
+ function setStatus($value)
{
- $tmp = array();
- $tmp['objectClass'] = array("top","dNSZone");
- $tmp['dNSClass'] = "IN";//$zone['dNSClass'];
- $tmp['relativeDomainName'] = "@";//$zone['relativeDomainName'];
+ if($value == "none") return;
+ if(!$this->initially_was_account) return;
+ if(empty($this->StatusFlag)) return;
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dn);
+ $ldap->cat($this->dn,array("objectClass"));
+ if($ldap->count()){
- $str = "";
- foreach(array("sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl") as $name){
- $str .= $zone[$name]." ";
+ $tmp = $ldap->fetch();
+ for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
+ $attrs['objectClass'][] = $tmp['objectClass'][$i];
+ }
+ $flag = $this->StatusFlag;
+ $attrs[$flag] = $value;
+ $this->$flag = $value;
+ $ldap->modify($attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for system server/dns with dn '%s' failed."),$this->dn));
+ $this->action_hook();
}
- $tmp['sOARecord'] = $str;
+ }
- /* Generate Record entries
- */
- $arr = array("aRecord","SigRecord","KeyRecord","aAAARecord","nSRecord","iaFSDBRecord","mInfoRecord","hInfoRecord","mXRecord","mDRecord","tXTRecord",
- "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord");
- $aRecords = array();
- foreach($arr as $ar){
- if((isset($zone['Records']))&&(is_array($zone['Records']))){
- foreach($zone['Records'] as $type){
- if(($type['type'] == $ar)&&($type['status']!="deleted")){
- $tmp[$ar][] = $type['value'];
- }
- }
- }
+ function getListEntry()
+ {
+ $fields = goService::getListEntry();
+ $fields['Message'] = _("DNS service");
+ $fields['AllowEdit'] = true;
+ return($fields);
+ }
+
+
+ /* Get updates for status flag */
+ function updateStatusState()
+ {
+ if(empty($this->StatusFlag)) return;
+
+ $attrs = array();
+ $flag = $this->StatusFlag;
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->cn);
+ $ldap->cat($this->dn,array($flag));
+ if($ldap->count()){
+ $attrs = $ldap->fetch();
}
- /* Check if there are records removed,
- if there are some removed records, then append an array
- to ensure that these record types are deleted
- */
- if((isset($zone['Records']))&&(is_array($zone['Records']))){
- foreach($zone['Records'] as $type){
- if((isset($type['inittype']))&&($type['inittype']!="")){
- if($type['type'] != $type['inittype']){
- $tmp[$type['inittype']] = array();
- }
- }
- }
+ if(isset($attrs[$flag][0])){
+ $this->$flag = $attrs[$flag][0];
}
-
- /* generate forward entry
- */
- $dn = "zoneName=".$zone['zoneName'].",".$this->dn;
- $tmp2[$dn] = $tmp;
- $tmp2[$dn]['zoneName'] = $zone['zoneName'];
+ }
- /* generate reverse entry
- */
- $dn = "zoneName=".$this->FlipIp($zone['ReverseZone']).".in-addr.arpa,".$this->dn;
- $tmp2[$dn] = $tmp;
- $tmp2[$dn]['tXTRecord'] ="zoneName=".$zone['zoneName'];
- $tmp2[$dn]['zoneName'] = $this->FlipIp($zone['ReverseZone']).".in-addr.arpa";
- return($tmp2);
+ /* Return plugin informations for acl handling */
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("DNS service"),
+ "plDescription" => _("DNS service")." ("._("Services").")",
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 83,
+ "plSection" => array("administration"),
+ "plCategory" => array("server"),
+
+ "plProvidedAcls"=> array(
+ "zoneName" =>_("Zone name"),
+ "ReverseZone" =>_("Reverse zone"),
+ "sOAprimary" =>_("Primary dns server"),
+ "sOAmail" =>_("Mail address"),
+ "sOAserial" =>_("Serial"),
+ "sOArefresh" =>_("Refresh"),
+ "sOAretry" =>_("Retry"),
+ "sOAexpire" =>_("Expire"),
+ "sOAttl" =>_("TTL"),
+ "zoneRecords" =>_("Zone records"))
+ ));
}
+
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>