From db15d7e739fc33af70e4ed2cf16bd85ba2da4352 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 11 Jan 2010 14:14:42 +0000 Subject: [PATCH] Updated system Management -We've a working activation queue now ... git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15140 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../admin/systems/class_filterSYSTEMS.inc | 2 +- .../admin/systems/class_systemManagement.inc | 266 +++++++++++++++++- .../systems/admin/systems/system-filter.tpl | 2 +- .../systems/admin/systems/system-list.xml | 8 +- 4 files changed, 262 insertions(+), 16 deletions(-) diff --git a/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc b/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc index 9a4df16ee..07925c85a 100644 --- a/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc +++ b/gosa-plugins/systems/admin/systems/class_filterSYSTEMS.inc @@ -17,7 +17,7 @@ class filterSYSTEMS { $entries[$key]['objectClass'][] = 'FAKE_OC_NewTerminal'; $entries[$key]['cn'][0].= " ("._("New terminal").")"; }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].= " ("._("New unknown device").")"; }elseif(in_array('GOhard', $entry['objectClass'])){ $entries[$key]['objectClass'][] = 'FAKE_OC_NewDevice'; diff --git a/gosa-plugins/systems/admin/systems/class_systemManagement.inc b/gosa-plugins/systems/admin/systems/class_systemManagement.inc index 240d811d5..d4f6c2c59 100644 --- a/gosa-plugins/systems/admin/systems/class_systemManagement.inc +++ b/gosa-plugins/systems/admin/systems/class_systemManagement.inc @@ -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); } diff --git a/gosa-plugins/systems/admin/systems/system-filter.tpl b/gosa-plugins/systems/admin/systems/system-filter.tpl index d27452049..d373e1e11 100644 --- a/gosa-plugins/systems/admin/systems/system-filter.tpl +++ b/gosa-plugins/systems/admin/systems/system-filter.tpl @@ -28,7 +28,7 @@ {if $USE_ieee802Device} {$COMPONENT} {t}Show network devices{/t}
{/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} {t}Show incoming devices{/t}
{/if} {if $USE_FAKE_OC_OpsiHost} diff --git a/gosa-plugins/systems/admin/systems/system-list.xml b/gosa-plugins/systems/admin/systems/system-list.xml index 0e55276e5..bb7f8194a 100644 --- a/gosa-plugins/systems/admin/systems/system-list.xml +++ b/gosa-plugins/systems/admin/systems/system-list.xml @@ -37,7 +37,7 @@ - gotoWorkstation + gotoWorkstation__IS_LOCKED workstation workgeneric plugins/systems/images/workstation_locked.png @@ -45,7 +45,7 @@ - gotoTerminal + gotoTerminal__IS_LOCKED terminal termgeneric plugins/systems/images/terminal_locked.png @@ -62,7 +62,7 @@ - FAKE_OC_NewUnknownDevice + FAKE_OC_ArpNewDevice terminal termgeneric plugins/systems/images/select_newsystem.png @@ -391,7 +391,7 @@ - DaemonEvent_activate + activateMultiple DaemonEvent_activate entry images/lists/unlocked.png -- 2.30.2