X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_servDNS.inc;h=f12ad0f8bcc77f0de704d79532a6409e11fbbd93;hb=868f556da0e7c0003fb3ae735559e6500e5bc3ed;hp=6f39d7b221c5dcd30449d8da81eca43e52393e80;hpb=d7fd69b22dc6a6614c574f953e22fff953205209;p=gosa.git
diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc
index 6f39d7b22..f12ad0f8b 100644
--- a/plugins/admin/systems/class_servDNS.inc
+++ b/plugins/admin/systems/class_servDNS.inc
@@ -2,33 +2,70 @@
class servdns 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();
- var $objectclasses= array("whatever");
+ var $ignore_account = FALSE;
+ var $attributes = array();
+ var $objectclasses = array("whatever");
+
+ var $RecordTypes = array();
+ var $Zones = array();
+ var $dialog = NULL;
+
+ var $orig_dn = "";
+
+ var $DNSinitially_was_account;
- function servdns ($config, $dn= NULL)
+
+ function servdns ($config, $dn= NULL, $parent= NULL)
{
- plugin::plugin ($config, $dn);
+ plugin::plugin ($config, $dn, $parent);
+
+ $this->orig_dn = $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
+ */
+ if(count($this->Zones) == 0){
+ $this->is_account = false;
+ }else{
+ $this->is_account = true;
+ }
+ $this->DNSinitially_was_account = $this->is_account;
}
+
function execute()
{
- /* Fill templating stuff */
+ /* Call parent execute
+ */
+ plugin::execute();
+
+ /* 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;
+
+ /* Only change account state if allowed */
+ if($this->is_account && $this->acl == "#all#"){
+ $this->is_account= !$this->is_account;
+ $this->is_modified = true;
+ }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
+ $this->is_account= !$this->is_account;
+ $this->is_modified = true;
+ }
}
- /* Show tab dialog headers */
if ($this->is_account){
$display= $this->show_header(_("Remove DNS service"),
_("This server has DNS features enabled. You can disable them by clicking below."));
@@ -38,42 +75,258 @@ class servdns extends plugin
return ($display);
}
+
+ /* Edited or Added zone
+ */
+ if((isset($_POST['SaveZoneChanges'])) && is_object($this->dialog)){
+ $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']) && chkacl($this->acl,"servdns") == ""){
+ $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 && chkacl($this->acl,"servdns") == ""){
+ $once =true;
+ $tmp = preg_replace("/^editZone_/","",$name);
+ $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 && chkacl($this->acl,"servdns") == ""){
+
+ $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());
+ }
+
+ /* Create Listbox with existing Zones
+ */
+ $ZoneList = new divSelectBox("dNSZones");
+ $ZoneList -> SetHeight(300);
+
+ /* Add entries to divlist
+ */
+ $editImg = "
+ ";
+ foreach($this->Zones as $zone => $values ){
+ $ZoneList->AddEntry(array(
+ array("string" => getNameFromMix($zone)),
+ array("string" => _("Reverse zone")." : ".getNameFromMix($values['ReverseZone'])),
+ array("string" => _("TTL")." : ".$values['sOAttl']),
+ array("string" => _("Class")." : ".$values['dNSClass']),
+ array("string" => str_replace("%s",base64_encode($zone),$editImg))
+ ));
+ }
+
+ $smarty->assign("servdnsACL",chkacl($this->acl,"servdns"));
+
+ /* Display tempalte
+ */
+ $smarty->assign("ZoneList",$ZoneList->DrawList());
$display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE));
return($display);
}
- function remove_from_parent()
+
+ /* Delete specified zone
+ */
+ function RemoveZone($id)
{
- /* This cannot be removed... */
- }
+ $zones = $this->getUsedZoneNames();
+ $rev ="";
+
+ if(isset($this->Zones[$id]['InitialReverseZone'])){
+ $rev = FlipIp(getNameFromMix($this->Zones[$id]['InitialReverseZone']));
+ }elseif(isset($this->Zones[$id]['ReverseZone'])){
+ $rev = FlipIp(getNameFromMix($this->Zones[$id]['ReverseZone']));
+ }
+
+ $zonename = "";
+ if(isset($this->Zones[$id]['InitialzoneName'])){
+ $zonename= getNameFromMix($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"]);
+ }
- /* Save data to object */
- function save_object()
+ /* 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)));
+
+ }else{
+ unset($this->Zones[$id]);
+ return(true);
+ }
+ return(false);
+ }
+
+
+ /* This funtion returns all used Zonenames
+ */
+ function getUsedZoneNames()
{
- plugin::save_object();
+ $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);
}
- /* Check supplied data */
- function check()
+
+ /* Remove dns service
+ */
+ function remove_from_parent()
{
- $message= array();
+ if($this->DNSinitially_was_account){
+ $bool = true;
+ foreach($this->Zones as $key => $zone){
+ $bool= $bool & $this->RemoveZone($key);
+ }
- return ($message);
+ if($bool){
+ $this->save();
+ }
+ return($bool);
+ }
}
+
/* Save to LDAP */
function save()
{
- plugin::save();
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+
+ /* Get differences
+ */
- /* Optionally execute a command after we're done */
- #$this->handle_post_events($mode);
- }
+ $old_dn = $this->orig_dn;
+ if($old_dn == "new"){
+ $old_dn = $this->dn;
+ }
+
+ $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_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("Zone:".$ldap->get_error(), _("Updating DNS service failed"));
+ }
+ }
+ /* Delete dns
+ */
+ foreach($tmp['del'] as $dn => $del){
+ $ldap->cd($dn);
+ $ldap->rmdir_recursive($dn);
+ show_ldap_error($ldap->get_error(), _("Removing DNS entries failed"));
+ }
+
+ /* move follwoing entries
+ */
+ foreach($tmp['move'] as $src => $dst){
+ $this->recursive_move($src,$dst);
+ }
+
+ /* 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(), _("Saving DNS entries failed"));
+ }
+ }
+}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>