Code

Updated system Management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Jan 2010 14:14:42 +0000 (14:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Jan 2010 14:14:42 +0000 (14:14 +0000)
-We've a working activation queue now ...

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15140 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc
gosa-plugins/systems/admin/systems/class_systemManagement.inc
gosa-plugins/systems/admin/systems/system-filter.tpl
gosa-plugins/systems/admin/systems/system-list.xml

index 9a4df16eeb27569d603c3be6cd70cc0f159d48fe..07925c85a1c137539cb6ed1e742d724d52fbe0f4 100644 (file)
@@ -17,7 +17,7 @@ class filterSYSTEMS {
           $entries[$key]['objectClass'][] = 'FAKE_OC_NewTerminal';
           $entries[$key]['cn'][0].= " <i>("._("New terminal").")</i>";
         }elseif(in_array('GOhard', $entry['objectClass']) && !isset($entry['gotoMode'][0])){ 
-          $entries[$key]['objectClass'][] = 'FAKE_OC_NewUnknownDevice';
+          $entries[$key]['objectClass'][] = 'FAKE_OC_ArpNewDevice';
           $entries[$key]['cn'][0].= " <i>("._("New unknown device").")</i>";
         }elseif(in_array('GOhard', $entry['objectClass'])){
           $entries[$key]['objectClass'][] = 'FAKE_OC_NewDevice';
index 240d811d5af3d2911299a8637553970c4728164f..d4f6c2c59e8726f837d29f4ff4b6aefd7ed79995 100644 (file)
@@ -37,6 +37,9 @@ class systemManagement extends management
 
   protected $opsi = NULL;
 
+
+  protected $activationQueue  = array();
+  
   function __construct($config,$ui)
   {
     $this->config = $config;
@@ -72,12 +75,14 @@ class systemManagement extends management
         $this->registerAction("T_".$name,"handleEvent");
         $this->registerAction("S_".$name,"handleEvent");
       }
-      $this->registerAction("DaemonEvent_activate","handleEvent");
+      $this->registerAction("activateMultiple","activateMultiple");
     }
     $this->registerAction("saveEvent","saveEventDialog");
     $this->registerAction("createISO","createISO");
     $this->registerAction("initiateISOcreation","initiateISOcreation");
     $this->registerAction("performIsoCreation","performIsoCreation");
+    $this->registerAction("systemTypeChosen","systemTypeChosen");
+    $this->registerAction("handleActivationQueue","handleActivationQueue");
 
     // Add copy&paste and snapshot handler.
     if ($this->config->boolValueIsTrue("main", "copyPaste")){
@@ -277,13 +282,14 @@ class systemManagement extends management
         }
       }
     }
+  }
 
-    // Handle system activation 
-    if($action == "DaemonEvent_activate"){
-      echo "Aktivieren!";
-    }
+  function cancelEdit()
+  {
+    management::cancelEdit();
+    $this->activationQueue = array();
   }
+  
   
   function saveEventDialog()
   {
@@ -428,12 +434,244 @@ class systemManagement extends management
       $tInfo = $this->getObjectDefinitions();
       $headpage = $this->getHeadpage();
       $dn = $target[0];
-      $type = $tInfo[$headpage->getType($dn)];
-      return(management::editEntry($action,$target,$all,$type['tabClass'],$type['tabDesc'],$type['aclCategory']));
+      $type =$headpage->getType($dn);
+      $tData = $tInfo[$type];
+
+      if($type == "FAKE_OC_ArpNewDevice"){
+        if(!class_available("ArpNewDeviceTabs")){
+          msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
+        }else{
+          $this->system_activation_object= array($dn);
+          return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
+        }
+      }elseif($type == "FAKE_OC_NewDevice"){
+        if(!class_available("SelectDeviceType")){
+          msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
+        }else{
+          $this->system_activation_object= array($dn);
+          $this->dialogObject = new SelectDeviceType($this->config,$dn);
+          $this->skipFooter = TRUE;
+          $this->displayApplyBtn = FALSE;
+          // see condition  -$s_action == "::systemTypeChosen"-  for further handling
+        }
+      }else{
+         return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
+      }
+    }
+  }
+
+
+  function activateMultiple($action,$target)
+  {
+    $headpage = $this->getHeadpage();
+    foreach($target as $dn) {
+      if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
+        $this->activationQueue[$dn] = array();
+      }
+    }
+    if(count($this->activationQueue)){
+      $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
+      $this->skipFooter = TRUE;
+    }
+  }
+
+
+
+
+  function systemTypeChosen()
+  {
+    // Detect the systems target type 
+    $tInfo = $this->getObjectDefinitions();
+    $selected_group = "none";
+    if(isset($_POST['ObjectGroup'])){
+      $selected_group = $_POST['ObjectGroup'];
+    }
+    $selected_system = $_POST['SystemType'];
+    $tmp = array();
+    foreach($this->activationQueue as $dn => $data){
+      $tmp[$dn]['OG'] = $selected_group;
+      $tmp[$dn]['SS'] = $selected_system;
+    }
+    $this->closeDialogs();
+    $this->activationQueue = $tmp;
+    return($this->handleActivationQueue());
+  }
+
+
+  function handleActivationQueue()
+  {
+    if(!count($this->activationQueue)) return("");
+
+    $ldap     = $this->config->get_ldap_link();
+    $pInfo    = $this->getObjectDefinitions(); 
+    $ui       = get_userinfo();
+    $headpage = $this->getHeadpage();
+    $ldap->cd($this->config->current['BASE']);
+
+    // Walk through systems to activate
+    foreach($this->activationQueue as $dn => $data){
+
+      if(!isset($data['SS'])) continue;
+
+      $sysType = $data['SS'];
+      $type = $pInfo[$sysType];
+
+      // Get target type definition 
+      $plugClass    = $type["plugClass"];
+      $tabClass     = $type["tabClass"];
+      $aclCategory  = $type["aclCategory"];
+      $tabDesc      = $type["tabDesc"];
+
+      if(!class_available($tabClass)){
+        msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
+      }else{
+
+        // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' 
+        $this->dn = $dn;
+        $acls   = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
+
+        // Check permissions
+        if(!preg_match("/c/",$acls)){
+          unset($this->activationQueue[$dn]);
+          msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
+          continue;
+        }else{
+
+          // Open object an preset some values like the objects base 
+          del_lock($dn);
+          management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
+          $this->tabObject->set_acl_base($headpage->getBase());
+          if($data['OG'] != "none"){
+            $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou('ogroupRDN'), '/')."/i", "", $data['OG']);
+            $this->tabObject->by_object[$plugClass]->base = $this->tabObject->base;
+          } else {
+            $this->tabObject->by_object[$plugClass]->base = $headpage->getBase();
+            $this->tabObject->base = $headpage->getBase();
+          }
+
+          // Assign some default values for opsi hosts
+          if($this->tabObject instanceOf opsi_tabs){
+            $ldap = $this->config->get_ldap_link();
+            $ldap->cat($dn);
+            $source_attrs = $ldap->fetch();
+            foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
+              if(isset($source_attrs[$src][0])){
+                $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
+              }
+            }
+          }
+
+          // Queue entry to be activated, when it is saved.
+          if($data['OG'] != "none"){
+
+            // Set gotoMode to active if there was an ogroup selected.
+            $found = false;
+            foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
+              if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
+                $found = true;
+                $this->tabObject->by_object[$tab]->gotoMode = $value;
+              }
+            }
+            if(!$found){
+              msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
+            }
+
+            // Update object group membership
+            $og = new ogroup($this->config,$data['OG']);
+            if($og){
+              $og->AddDelMembership($this->tabObject->dn);
+              $og->save();
+            }
+
+            // Set default system specific attributes
+            foreach (array("workgeneric", "termgeneric") as $cls){
+              if (isset($this->tabObject->by_object[$cls])){
+                $this->tabObject->by_object[$cls]->set_everything_to_inherited();
+              }
+            }
+
+            // Enable activation
+            foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
+              if (isset($this->tabObject->by_object[$cls])){
+                $this->tabObject->by_object[$cls]->auto_activate= TRUE;
+              }
+            }
+
+            // Enable sending of LDAP events
+            if (isset($this->tabObject->by_object["workstartup"])){
+              $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
+            }
+          }
+
+          // Try to inherit everythin from the selected object group and then save
+          //  the entry, normally this should work without any problems. 
+          // But if there is any, then display the dialogs.
+          if($data['OG'] != "none"){
+            $str = $this->saveChanges();
+
+            // There was a problem, skip activation here and allow to fix the problems..
+            if(is_object($this->tabObject)){
+              return;
+            }
+          }else{
+            return;
+          }
+        }
+      }
+    }
+  }
+
+
+  protected function saveChanges()
+  {
+    $str = management::saveChanges();
+    if($this->tabObject) return("");
+
+    if(isset($this->activationQueue[$this->last_dn])){
+      $this->activate_new_device($this->last_dn);
+      unset($this->activationQueue[$this->last_dn]);
     }
+    $this->handleActivationQueue();
   }
 
 
+  /*! \brief  Sets FAIstate to "install" for "New Devices".
+    This function is some kind of "Post handler" for activated systems,
+    it is called directly after the object (workstabs,servtabs) gets saved.
+    @param  String  $dn   The dn of the newly activated object.
+    @return Boolean TRUE if activated else FALSE
+   */
+  function activate_new_device($dn)
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->cat($dn);
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+      if(count(array_intersect(array('goServer','gotoTerminal'), $attrs['objectClass']))){
+        $ocs = $attrs['objectClass'];
+        unset($ocs['count']);
+        $new_attrs = array();
+        if(!in_array("FAIobject",$ocs)){
+          $ocs[] = "FAIobject";
+          $new_attrs['objectClass'] = $ocs;
+        }
+        $new_attrs['FAIstate'] = "install";
+        $ldap->cd($dn);
+        $ldap->modify($new_attrs);
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
+                LDAP_MOD, "activate_new_device($dn)"));
+        }else{
+          return(TRUE);
+        }
+      }
+    }
+    return(FALSE);
+  }
+
+
+
  /*! \brief  Detects actions/events send by the ui
    *           and the corresponding targets.
    */
@@ -444,11 +682,19 @@ class systemManagement extends management
     if(isset($_POST['save_event_dialog']))  $action['action'] = "saveEvent";
     if(isset($_POST['cd_create']))  $action['action'] = "initiateISOcreation";
     if(isset($_GET['PerformIsoCreation']))  $action['action'] = "performIsoCreation";
+    if(isset($_POST['SystemTypeAborted']))  $action['action'] = "cancel";
+
+    if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
+      if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
+    }
+
+    if(isset($_POST['systemTypeChosen']))  $action['action'] = "systemTypeChosen";
+
     return($action);
   }
 
 
-  /*! \brief   Overridden render method of class mangement.
+  /*! \brief   Overridden render method of class management.
    *            this allows us to add a release selection box.
    */
   function renderList()
@@ -566,7 +812,7 @@ class systemManagement extends management
     $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
     $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
 
-    $tabs['FAKE_OC_NewUnknownDevice'] = &$tabs['FAKE_OC_NewDevice'];
+    $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
 
     return($tabs);
   }
index d274520493c8ed4edb2a99d32dc7d755d01eac6d..d373e1e11c818fa049ca99845ec1c2c3717e6bca 100644 (file)
@@ -28,7 +28,7 @@
   {if $USE_ieee802Device}
   {$COMPONENT}&nbsp;{t}Show network devices{/t}<br>
   {/if}
-  {if $USE_FAKE_OC_NewWorkstation || $USE_FAKE_OC_NewTerminal || $USE_FAKE_OC_NewServer || $USE_FAKE_OC_NewDevice || $USE_FAKE_OC_NewUnknownDevice}
+  {if $USE_FAKE_OC_NewWorkstation || $USE_FAKE_OC_NewTerminal || $USE_FAKE_OC_NewServer || $USE_FAKE_OC_NewDevice || $USE_FAKE_OC_ArpNewDevice}
   {$INCOMING}&nbsp;{t}Show incoming devices{/t}<br>
   {/if}
   {if $USE_FAKE_OC_OpsiHost}
index 0e55276e5c3dd5ca4da48327c2ff39d3f921bbde..bb7f8194a197832001760c0382c94c6ec80ca52b 100644 (file)
@@ -37,7 +37,7 @@
 
     <objectType>
       <label>Locked workstation</label>
-      <objectClass>gotoWorkstation</objectClass>
+      <objectClass>gotoWorkstation__IS_LOCKED</objectClass>
       <category>workstation</category>
       <class>workgeneric</class>
       <image>plugins/systems/images/workstation_locked.png</image>
@@ -45,7 +45,7 @@
 
     <objectType>
       <label>Locked terminal</label>
-      <objectClass>gotoTerminal</objectClass>
+      <objectClass>gotoTerminal__IS_LOCKED</objectClass>
       <category>terminal</category>
       <class>termgeneric</class>
       <image>plugins/systems/images/terminal_locked.png</image>
@@ -62,7 +62,7 @@
 
     <objectType>
       <label>New unknown device</label>
-      <objectClass>FAKE_OC_NewUnknownDevice</objectClass>
+      <objectClass>FAKE_OC_ArpNewDevice</objectClass>
       <category>terminal</category>
       <class>termgeneric</class>
       <image>plugins/systems/images/select_newsystem.png</image>
     </action>
 
     <action>
-      <name>DaemonEvent_activate</name>
+      <name>activateMultiple</name>
       <depends>DaemonEvent_activate</depends>
       <type>entry</type>
       <image>images/lists/unlocked.png</image>