Code

Backports from trunk
[gosa.git] / gosa-plugins / samba / admin / systems / samba / class_winGeneric.inc
index 63e20f21b88e08c301ac994e20d07ccb1872b170..56943662cd4b9cdf341355be1f571b2c4280b606 100644 (file)
@@ -33,6 +33,7 @@ class wingeneric extends plugin
 
   var $orig_cn;
   var $orig_base;
+  var $baseSelector;
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
@@ -41,25 +42,36 @@ class wingeneric extends plugin
                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
-  var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
+  var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","shadowAccount","sambaSamAccount","top");
 
   var $view_logged = FALSE;
 
   function wingeneric (&$config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
-    $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
-    $this->netConfigDNS->objectclasses=array("ipHost","ieee802Device");
+    $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses,FALSE,"uid");
+    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
     $this->netConfigDNS->MACisMust = FALSE;
-    $this->netConfigDNS->IPisMust = TRUE;
+    $this->netConfigDNS->IPisMust = FALSE;
+
+    // The combination of the used objectClasses may differ, remember the initial ones.
+    if(isset($this->attrs['objectClass'])){
+        $this->objectclasses = array();
+        for($i=0; $i < $this->attrs['objectClass']['count'] ;  $i++ ){
+            $this->objectclasses[] = $this->attrs['objectClass'][$i];
+        }
+    }
 
     /* Set base */
     if ($this->dn == "new"){
-      $ui= get_userinfo();
-      $this->base= dn2base($ui->dn);
+      $ui = get_userinfo();
+      $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
       $this->cn= "";
+    } elseif(class_available("ArpNewDevice") &&
+                preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){
+      $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn);
     } else {
-      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".preg_quote(get_winstations_ou(), '/')."/i", "", $this->dn);
     }
 
     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
@@ -68,6 +80,12 @@ class wingeneric extends plugin
     $this->orig_dn= $this->dn;
     $this->orig_base= $this->base;
     $this->orig_cn= $this->cn;
+
+    /* Instanciate base selector */
+    $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+    $this->baseSelector->setSubmitButton(false);
+    $this->baseSelector->setHeight(300);
+    $this->baseSelector->update(true);
   }
 
 
@@ -103,40 +121,9 @@ class wingeneric extends plugin
       return($display);
     }
 
-    /* Base select dialog */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once){
-        $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this);
-        $this->dialog->setCurrentBase($this->base);
-      }
-    }
-
-    /* Dialog handling */
-    if(is_object($this->dialog)){
-      /* Must be called before save_object */
-      $this->dialog->save_object();
-
-      if($this->dialog->isClosed()){
-        $this->dialog = false;
-      }elseif($this->dialog->isSelected()){
-
-        /* A new base was selected, check if it is a valid one */
-        $tmp = $this->get_allowed_bases();
-        if(isset($tmp[$this->dialog->isSelected()])){
-          $this->base = $this->dialog->isSelected();
-        }
-
-        $this->dialog= false;
-      }else{
-        return($this->dialog->execute());
-      }
-    }
-
     /* Fill templating stuff */
     $smarty= get_smarty();
-    $smarty->assign("bases"   , $this->get_allowed_bases());
+
     
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
@@ -145,10 +132,10 @@ class wingeneric extends plugin
 
     /* Assign attributes */
     foreach ($this->attributes as $attr){
-      $smarty->assign("$attr", $this->$attr);
+      $smarty->assign("$attr", set_post($this->$attr));
     }
     
-    $smarty->assign("base_select", $this->base);
+    $smarty->assign("base", $this->baseSelector->render());
 
     /* Show main page */
     $str = $this->netConfigDNS->execute();
@@ -193,13 +180,17 @@ class wingeneric extends plugin
 
     $this->netConfigDNS->save_object();
 
-    /* Set new base if allowed */
-    $tmp = $this->get_allowed_bases();
-    if(isset($_POST['base'])){
-      if(isset($tmp[$_POST['base']])){
-        $this->base= $_POST['base'];
+    /* Refresh base */
+    if ($this->acl_is_moveable($this->base)){
+      if (!$this->baseSelector->update()) {
+        msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+      }
+      if ($this->base != $this->baseSelector->getBase()) {
+        $this->base= $this->baseSelector->getBase();
+        $this->is_modified= TRUE;
       }
     }
+
   }
 
 
@@ -209,7 +200,7 @@ class wingeneric extends plugin
     /* Call common method to give check the hook */
     $message= plugin::check();
     $message= array_merge($message, $this->netConfigDNS->check());
-    $this->dn= "cn=".$this->uid.",".get_ou('sambaMachineAccountRDN').$this->base;
+    $this->dn= "cn=".$this->uid.",".get_ou("wingeneric", "sambaMachineAccountRDN").$this->base;
 
     if(!$this->acl_is_createable()){
       $message[]= msgPool::permCreate();
@@ -232,6 +223,11 @@ class wingeneric extends plugin
       }
     }
 
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();;
+    }
+
     /* Check if we are allowed to create or move this object
      */
     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
@@ -265,6 +261,26 @@ class wingeneric extends plugin
       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
     }
 
+    $curOcs = $this->attrs['objectClass'];
+    $this->cleanup();
+
+    // Prepare list of object classes
+    $ocs = array();
+    if(!empty($this->netConfigDNS->macAddress)){
+        $ocs [] = 'ieee802Device';
+    }else{
+        $curOcs = array_remove_entries(array('ieee802Device'), $curOcs);
+        $this->attrs['macAddress'] = array();
+    } 
+    if(!empty($this->netConfigDNS->ipHostNumber)){
+        $ocs [] = 'ipHost';
+    }else{
+        $curOcs = array_remove_entries(array('ipHost'), $curOcs);
+        $this->attrs['ipHostNumber'] = array();
+    } 
+
+    $this->attrs['objectClass']=$curOcs;
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     if ($this->orig_dn == 'new'){
@@ -280,35 +296,71 @@ class wingeneric extends plugin
       }
 
       $ldap->cd($this->dn);
-      $this->cleanup();
       $ldap->modify ($this->attrs); 
       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $this->handle_post_events("modify");
     }
 
-    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
-    $this->netConfigDNS->save();
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
     }
 
-    /* Optionally execute a command after we're done */
-    $this->postcreate();
+    // Prepare list of object classes
+    $ocs = array();
+    if(!empty($this->netConfigDNS->macAddress)){
+        $ocs [] = 'ieee802Device';
+    } 
+    if(!empty($this->netConfigDNS->ipHostNumber)){
+        $ocs [] = 'ipHost';
+    } 
+
+    $this->netConfigDNS->objectclasses=$ocs;
+    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
+    $this->netConfigDNS->save();
   }
 
   /* Return plugin informations for acl handling
   #FIXME FAIscript seams to ununsed within this class... */
   static function plInfo()
   {
-    return (array(
-          "plShortName"   => _("Win generic"),
-          "plDescription" => _("Windows workstation generic"),
-          "plSelfModify"  => FALSE,
-          "plDepends"     => array(),
-          "plPriority"    => 0,
-          "plSection"     => array("administration"),
-          "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
-                                                          "objectClass"  => "gotoWorkstation")),
+      return (array(
+                  "plShortName"   => _("Win generic"),
+                  "plDescription" => _("Windows workstation generic"),
+                  "plSelfModify"  => FALSE,
+                  "plDepends"     => array(),
+                  "plPriority"    => 0,
+                  "plSection"     => array("administration"),
+                  "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
+                          "objectClass"  => "gotoWorkstation")),
+
+                  "plRequirements"=> array(
+                      'ldapSchema' => array(
+                          'posixAccount' => '',
+                          'organizationalPerson' => '',
+                          'person' => '',
+                          'inetOrgPerson' => '',
+                          'gosaAccount' => '>=2.7',
+                          'shadowAccount' => '',
+                          'sambaSamAccount' => ''
+                          ),
+                      'onFailureDisablePlugin' => array(get_class())
+                      ),
+
+
+                  "plProperties" =>
+                  array(
+                      array(
+                          "name"          => "sambaMachineAccountRDN",
+                          "type"          => "rdn",
+                          "default"       => "ou=winstations,ou=systems,",
+                          "description"   => _("RDN for samba machine account storage."),
+                          "check"         => "gosaProperty::isRdn",
+                          "migrate"       => "migrate_sambaMachineAccountRDN",
+                          "group"         => "plugin",
+                          "mandatory"     => FALSE
+                          )
+                      ),
+
           "plProvidedAcls"=> array(
             "cn"                  => _("Name"),
             "base"                => _("Base"),