index fa48534c49945a75f4d6f3b004538c37d51fae9c..997a8ad00fc0efbb481707c4cc0c3e86d76b1c71 100644 (file)
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","relativeDomainName","dNSTTL","dNSClass","sOARecord");
- var $objectclasses= array("whatever");
+ var $ignore_account = FALSE;
+ var $attributes = array();
+ var $objectclasses = array("whatever");
- var $RecordTypes = array();
- var $usedRecords = array();
+ var $RecordTypes = array();
+ var $Zones = array();
+ var $dialog = NULL;
- var $Zones = array();
- var $editMode = false;
+ var $orig_dn = "";
- function servdns ($config, $dn= NULL)
+ var $initially_was_account;
+
+ /* ServerService tab vars */
+ var $conflicts = array("servdns");
+ var $DisplayName = "";
+ var $StatusFlag = "";
+
+ function servdns ($config, $dn= NULL, $parent= NULL)
{
- plugin::plugin ($config, $dn);
-
- $RecordTypes['ARecord'] ['name'] ="A Record";
- $RecordTypes['ARecord'] ['type'] ="string";
- $RecordTypes['MDRecord'] ['name'] ="MD Record";
- $RecordTypes['MDRecord'] ['type'] ="string";
- $RecordTypes['MXRecord'] ['name'] ="MX Record";
- $RecordTypes['MXRecord'] ['type'] ="string";
- $RecordTypes['NSRecord'] ['name'] ="NS Record";
- $RecordTypes['NSRecord'] ['type'] ="string";
- $RecordTypes['CNAMERecord'] ['name'] ="CNAME Record";
- $RecordTypes['CNAMERecord'] ['type'] ="string";
- $RecordTypes['PTRRecord'] ['name'] ="PTR Record";
- $RecordTypes['PTRRecord'] ['type'] ="string";
- $RecordTypes['HINFORecord'] ['name'] ="HINFO Record";
- $RecordTypes['HINFORecord'] ['type'] ="string";
- $RecordTypes['MINFORecord'] ['name'] ="MINFO Record";
- $RecordTypes['MINFORecord'] ['type'] ="string";
- $RecordTypes['TXTRecord'] ['name'] ="TXT Record";
- $RecordTypes['TXTRecord'] ['type'] ="string";
- $RecordTypes['AFSDBRecord'] ['name'] ="AFSDB Record";
- $RecordTypes['AFSDBRecord'] ['type'] ="string";
- $RecordTypes['SIGRecord'] ['name'] ="SIG Record";
- $RecordTypes['SIGRecord'] ['type'] ="string";
- $RecordTypes['KEYRecord'] ['name'] ="KEY Record";
- $RecordTypes['KEYRecord'] ['type'] ="string";
- $RecordTypes['AAAARecord'] ['name'] ="AAAA Record";
- $RecordTypes['AAAARecord'] ['type'] ="string";
- $RecordTypes['LOCRecord'] ['name'] ="LOC Record";
- $RecordTypes['LOCRecord'] ['type'] ="string";
- $RecordTypes['NXTRecord'] ['name'] ="NXT Record";
- $RecordTypes['NXTRecord'] ['type'] ="string";
- $RecordTypes['SRVRecord'] ['name'] ="SRV Record";
- $RecordTypes['SRVRecord'] ['type'] ="string";
- $RecordTypes['NAPTRRecord'] ['name'] ="NAPTR Record";
- $RecordTypes['NAPTRRecord'] ['type'] ="string";
- $RecordTypes['KXRecord'] ['name'] ="KX Record";
- $RecordTypes['KXRecord'] ['type'] ="string";
- $RecordTypes['CERTRecord'] ['name'] ="CERT Record";
- $RecordTypes['CERTRecord'] ['type'] ="string";
- $RecordTypes['A6Record'] ['name'] ="A6 Record";
- $RecordTypes['A6Record'] ['type'] ="string";
- $RecordTypes['DNAMERecord'] ['name'] ="DBNAME Record";
- $RecordTypes['DNAMERecord'] ['type'] ="string";
- $RecordTypes['DSRecord'] ['name'] ="DS Record";
- $RecordTypes['DSRecord'] ['type'] ="string";
- $RecordTypes['SSHFPRecord'] ['name'] ="SSHFP Record";
- $RecordTypes['SSHFPRecord'] ['type'] ="string";
- $RecordTypes['RRSIGRecord'] ['name'] ="RRSIG Record";
- $RecordTypes['RRSIGRecord'] ['type'] ="string";
- $RecordTypes['NSECRecord'] ['name'] ="NSEC Record";
- $RecordTypes['NSECRecord'] ['type'] ="string";
- $RecordTypes['mXRecord'] ['name'] ="MX Record";
- $RecordTypes['mXRecord'] ['type'] ="string";
- $RecordTypes['nSRecord'] ['name'] ="nS Record";
- $RecordTypes['nSRecord'] ['type'] ="string";
-
- $this->RecordTypes = $RecordTypes;
-
- $attrs = $this->attributes;
- foreach($RecordTypes as $name => $att){
- $attrs2[] = $name;
- }
- $attrs3 = array_merge($attrs,$attrs2);
+ plugin::plugin ($config, $dn, $parent);
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->dn);
- $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",$attrs3);
- while($zone = $ldap->fetch()){
- $tmp = array();
- foreach($attrs as $att){
- if(isset($zone[$att]['count'])&&(is_array($zone[$att])))
- unset($zone[$att]['count']);
-
- if(isset($zone[$att])){
- $tmp[$att] = $zone[$att][0];
- }else{
- $tmp[$att] = "";
- }
- }
+ $this->DisplayName = _("Domain name system service");
- if(isset($tmp['sOARecord'])){
- $tmp2 = split("\ ",$tmp['sOARecord']);
- unset($tmp['sOARecord']);
- $tmp['sOARecord'] = array();
- $tmp['sOARecord']['sOAprimary'] = $tmp2[0];
- $tmp['sOARecord']['sOAmail'] = $tmp2[1];
- $tmp['sOARecord']['sOAserial'] = $tmp2[2];
- $tmp['sOARecord']['sOArefresh'] = $tmp2[3];
- $tmp['sOARecord']['sOAretry'] = $tmp2[4];
- $tmp['sOARecord']['sOAexpire'] = $tmp2[5];
- $tmp['sOARecord']['sOAttl'] = $tmp2[6];
- }
+ $this->orig_dn = $dn;
- $tmp['usedRecords'] = array();
- foreach($attrs2 as $name){
- if(isset($zone[$name])){
- for($i = 0 ; $i < $zone[$name]['count'] ; $i++ ){
- $tmp['usedRecords'][] = array("type"=> $name,"value"=>$zone[$name][$i]);
- }
- }
- }
- $this->Zones[$zone['zoneName'][0]] = $tmp;
- }
- if(count($this->Zones > 0)){
+ /* 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
+ */
+ if(count($this->Zones) == 0){
+ $this->is_account = false;
+ }else{
$this->is_account = true;
}
+ $this->initially_was_account = $this->is_account;
}
+
function execute()
{
- /* Call parent execute */
- plugin::execute();
+ /* Call parent execute
+ */
+ plugin::execute();
- /* Fill templating stuff */
+ /* Fill templating stuff
+ */
$smarty= get_smarty();
$display= "";
- /* Do we need to flip is_account state? */
+ /* 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
+ */
+ if(isset($_POST['SaveZoneChanges'])){
+ $this->dialog->save_object();
+
+ /* 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();
+ if(!$this->dialog->isNew){
+ unset($this->Zones[$this->dialog->OldZoneName]);
+ }
+ $this->Zones[$ret['zoneName']] = $ret;
+ $this->dialog = NULL;
+ }
+ }
+
+ /* Cancel zone edit / new
+ */
+ if(isset($_POST['CancelZoneChanges'])){
+ $this->dialog = NULL;
+ }
+
+ /* Add empty new zone
+ */
+ if(isset($_POST['AddZone'])){
+ $this->dialog = new servdnseditZone($this->config,$this->dn);
+ }
+
+ /* Check for edit zone request
+ */
$once = false;
foreach( $_POST as $name => $value){
+
+ /* check all post for edit request
+ */
if(preg_match("/^editZone_/",$name)&&!$once){
$once =true;
$tmp = preg_replace("/^editZone_/","",$name);
- $tmp = base64_decode(preg_replace("/_.*$/","...",$tmp));
- $this->editMode = $this->Zones[$tmp];
+ $tmp = base64_decode(preg_replace("/_.*$/","",$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));
+
+ /* Initiate deletion
+ */
+ $this->RemoveZone($tmp);
}
}
+ /* Show dialog
+ */
+ if($this->dialog!= NULL){
+ $this->dialog->save_object();
+ $this->dialog->parent = $this;
+ return($this->dialog->execute());
+ }
- $smarty->assign("editMode",$this->editMode);
- if($this->editMode){
+ /* Create Listbox with existing Zones
+ */
+ $ZoneList = new divSelectBox("dNSZones");
+ $ZoneList -> SetHeight(254);
+
+ /* 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'>";
+ foreach($this->Zones as $zone => $values ){
+ $ZoneList->AddEntry(array(
+ array("string" => $zone),
+ array("string" => _("Reverse zone")." : ".$values['ReverseZone']),
+ array("string" => _("TTL")." : ".$values['sOAttl']),
+ array("string" => _("Class")." : ".$values['dNSClass']),
+ array("string" =>str_replace("%s",base64_encode($zone),$editImg))
+ ));
+ }
+
+ /* Display tempalte
+ */
+ $smarty->assign("ZoneList",$ZoneList->DrawList());
+ $display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE));
+ return($display);
+ }
- foreach($this->attributes as $attrs){
- $smarty->assign($attrs,$this->editMode[$attrs]);
- }
-
- foreach($this->editMode['sOARecord'] as $name => $value){
- $smarty->assign($name,$value);
- }
- $smarty->assign("records","");
+ /* Delete specified zone
+ */
+ function RemoveZone($id)
+ {
+ $zones = $this->getUsedZoneNames();
+
+ if(isset($this->Zones[$id]['InitialReverseZone'])){
+ $rev = FlipIp($this->Zones[$id]['InitialReverseZone']);
}else{
- $ZoneList = new divSelectBox("dNSZones");
- $ZoneList -> SetHeight(254);
+ $rev = FlipIp($this->Zones[$id]['ReverseZone']);
+ }
- $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>";
+ $zonename = "";
+ if(isset($this->Zones[$id]['InitialzoneName'])){
+ $zonename= $this->Zones[$id]['InitialzoneName'];
+ }
- foreach($this->Zones as $zone => $values ){
- $ZoneList->AddEntry(array(array("string" => $zone.str_replace("%s",base64_encode($zone),$editImg))));
- }
+ $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"]);
+ }
- $smarty->assign("ZoneList",$ZoneList->DrawList());
+ /* There are still entries using this configuration
+ * Abort deletion
+ */
+ if(count($used)){
+ $i = 2;
+ $str ="";
+ foreach($used as $dn){
+ if($i > 0 ){
+ $i --;
+ $str.=$dn." ";
+ }
+ }
+
+ /* 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);
}
+ }
- $display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE));
- return($display);
+
+ /* 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"));
+ while($attr = $ldap->fetch()){
+ $ret[$attr['zoneName'][0]][] = $attr['dn'];
+ }
+ return($ret);
}
+
+ /* Remove dns service
+ */
function remove_from_parent()
{
- /* This cannot be removed... */
+ if($this->initially_was_account){
+ $bool = true;
+ foreach($this->Zones as $key => $zone){
+ $bool= $bool & $this->RemoveZone($key);
+ }
+
+ if($bool){
+ $this->save();
+ }
+ return($bool);
+ }
}
- /* Save data to object */
- function save_object()
+ /* Save to LDAP */
+ function save()
{
- //plugin::save_object();
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+
+ /* Get differences
+ */
+ $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$this->orig_dn);
+
+ /* Updated zone entries if reverser or forward name has changed
+ * Must be done before moving entries, else the given dn is invalid
+ */
+ if(isset($tmp['zoneUpdates'])){
+ foreach($tmp['zoneUpdates'] as $dn => $attrs){
+ $ldap->cd($dn);
+ $ldap->modify($attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Updating of system server/dns with dn '%s' failed."),$this->dn));
+ }
+ }
- if(!$this->editMode){return;}
+ /* Delete dns
+ */
+ foreach($tmp['del'] as $dn => $del){
+ $ldap->cd($dn);
+ $ldap->rmdir_recursive($dn);
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing of system server/dns with dn '%s' failed."),$this->dn));
+ }
+
+ /* move follwoing entries
+ */
+ foreach($tmp['move'] as $src => $dst){
+ $this->recursive_move($src,$dst);
+ }
- foreach($this->attributes as $attr){
- if(isset($_POST[$attr])){
- $this->editMode[$attr] = $_POST[$attr];
+ /* Add || Update new DNS entries
+ */
+ foreach($tmp['add'] as $dn => $attrs){
+ $ldap->cd($dn);
+ $ldap->cat($dn, array('dn'));
+ if(count($ldap->fetch())){
+ $ldap->cd($dn);
+ $ldap->modify ($attrs);
+ }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));
}
+ }
+
- foreach($this->editMode['sOARecord'] as $name => $value){
- if(isset($_POST[$name])){
- $this->editMode['sOARecord'][$name] = $_POST[$name];
+ /* Directly save new status flag */
+ function setStatus($value)
+ {
+ 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()){
+
+ $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();
}
+ }
+
+ function getListEntry()
+ {
+ $this->updateStatusState();
+ $flag = $this->StatusFlag;
+ if(empty($flag)){
+ $fields['Status'] = "";
+ }else{
+ $fields['Status'] = $this->$flag;
+ }
+ $fields['Message'] = _("DNS service");
+ $fields['AllowStart'] = true;
+ $fields['AllowStop'] = true;
+ $fields['AllowRestart'] = true;
+ $fields['AllowRemove']= true;
+ $fields['AllowEdit'] = true;
+ return($fields);
}
- /* Check supplied data */
- function check()
+ /* Get updates for status flag */
+ function updateStatusState()
{
- $message= array();
+ if(empty($this->StatusFlag)) return;
- return ($message);
+ $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();
+ }
+ if(isset($attrs[$flag][0])){
+ $this->$flag = $attrs[$flag][0];
+ }
}
- /* Save to LDAP */
- function save()
+ /* Return plugin informations for acl handling */
+ function plInfo()
{
- plugin::save();
-
- /* Optionally execute a command after we're done */
- #$this->handle_post_events($mode);
+ return (array(
+ "plShortName" => _("DNS"),
+ "plDescription" => _("DNS service"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "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:
?>