From: hickert Date: Mon, 25 Jan 2010 08:17:01 +0000 (+0000) Subject: Updated server service dialogs. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3a435dd022ce0cf31ede7bff9bd33a5e92b4c8cd;p=gosa.git Updated server service dialogs. -Not yet finished. Some cleanup is still required. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15274 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/systems/admin/systems/class_filterServerService.inc b/gosa-plugins/systems/admin/systems/class_filterServerService.inc index b388570d6..84ac8e7e9 100644 --- a/gosa-plugins/systems/admin/systems/class_filterServerService.inc +++ b/gosa-plugins/systems/admin/systems/class_filterServerService.inc @@ -22,11 +22,11 @@ class filterServerService { $list[$name][$key] = $data[$key]; $list[$name][$key]['count'] = count($data[$key]); $list[$name]['count'] = count($data); - $list[$name]['dn'] = $key; + $list[$name]['dn'] = $name; } } } - return($list); + return(array_values($list)); } } diff --git a/gosa-plugins/systems/admin/systems/class_serverService.inc b/gosa-plugins/systems/admin/systems/class_serverService.inc index 455a6702a..44682aa97 100644 --- a/gosa-plugins/systems/admin/systems/class_serverService.inc +++ b/gosa-plugins/systems/admin/systems/class_serverService.inc @@ -34,23 +34,22 @@ class ServerService extends management { /* attribute list for save action */ var $ignore_account = TRUE; - var $attributes = array(); - var $objectclasses = array(); var $skipFooter = TRUE; var $skipHeader = TRUE; - var $divList = NULL; - var $plugins = array(); var $pluign_names = array(); - var $current = ""; var $dialog = FALSE; + var $read_only = FALSE; var $backup = NULL; var $acl ; var $cn; var $parent ; - var $pl_notify = FALSE; + var $acl_category = ""; + var $acl_base = ""; + + var $is_account; function __construct (&$config, $dn,$parent) { @@ -67,148 +66,152 @@ class ServerService extends management $this->storagePoints = array(); # // Build filter - # if (session::global_is_set(get_class($this)."_filter")){ - # $filter= session::global_get(get_class($this)."_filter"); - # } else { - $filter = new filter(get_template_path("serverService-filter.xml", true)); - $filter->setObjectStorage($this->storagePoints); - #} - $this->setFilter($filter); - - // Build headpage - $headpage = new listing(get_template_path("serverService-list.xml", true)); - $headpage->registerElementFilter("filterServiceStatus", "ServerService::filterServiceStatus"); - $headpage->setFilter($filter); - - - // Initialize list of used and useable services. - foreach ($config->data['TABS']['SERVERSERVICE'] as $plug){ - if(class_available($plug['CLASS'])){ - - $name= $plug['CLASS']; - $this->plugin_names[]= $name; - $this->plugins[$name]= new $name($config, $dn, $this); - - /* Initialize kerberos key support */ - if(isset($this->plugins[$name]->krb_service_prefix) && !empty($this->plugins[$name]->krb_service_prefix)){ - $this->plugins[$name]->krb_host_key = &$this->parent->kerberos_key_service; - } +# if (session::global_is_set(get_class($this)."_filter")){ +# $filter= session::global_get(get_class($this)."_filter"); +# } else { + $filter = new filter(get_template_path("serverService-filter.xml", true)); + $filter->setObjectStorage($this->storagePoints); +#} + $this->setFilter($filter); + + // Build headpage + $headpage = new listing(get_template_path("serverService-list.xml", true)); + $headpage->registerElementFilter("filterServiceStatus", "ServerService::filterServiceStatus"); + $headpage->setFilter($filter); + + + // Initialize list of used and useable services. + foreach ($config->data['TABS']['SERVERSERVICE'] as $plug){ + if(class_available($plug['CLASS'])){ + + $name= $plug['CLASS']; + $this->plugin_names[]= $name; + $this->plugins[$name]= new $name($config, $dn, $this); + + /* Initialize kerberos key support */ + if(isset($this->plugins[$name]->krb_service_prefix) && !empty($this->plugins[$name]->krb_service_prefix)){ + $this->plugins[$name]->krb_host_key = &$this->parent->kerberos_key_service; + } - /* Capture all service objectClases, necessary for acl handling */ - if(isset($this->plugins[$name]->objectclasses)){ - foreach($this->plugins[$name]->objectclasses as $oc){ - $this->objectclasses[] = $oc; - } + /* Capture all service objectClases, necessary for acl handling */ + if(isset($this->plugins[$name]->objectclasses)){ + foreach($this->plugins[$name]->objectclasses as $oc){ + $this->objectclasses[] = $oc; } - }else{ - #trigger_error("Service class missing: ".$plug['CLASS']); } + }else{ +#trigger_error("Service class missing: ".$plug['CLASS']); } + } - parent::__construct($config, $ui, "systems", $headpage); - } - + parent::__construct($config, $this->ui, "services", $headpage); + $this->registerAction("new", "newService"); + $this->registerAction("remove", "removeService"); + $this->registerAction("newServiceSelected", "newServiceSelected"); + $this->registerAction("saveService", "saveService"); + $this->registerAction("cancelService", "cancelEdit"); + $this->registerAction("restart", "updateServiceStatus"); + $this->registerAction("stop", "updateServiceStatus"); + $this->registerAction("start", "updateServiceStatus"); + } - static function getServiceList() - { - return(session::get('ServerService')); + function detectPostActions() + { + $action = management::detectPostActions(); + if(isset($_POST['SaveServiceAdd'])) $action['action'] = "newServiceSelected"; + if(isset($_POST['CancelServiceAdd'])) $action['action'] = "cancel"; + if(isset($_POST['SaveService'])) $action['action'] = "save"; + if(isset($_POST['CancelService'])) $action['action'] = "cancelService"; + return($action); } - static function filterServiceStatus($a,$b,$c,$d) + function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="") { - $img =""; - if(isset($d['0'])){ - switch($d[0]){ - case 'Restart' : $img = ('images/status_restarting.png'); break; - case 'Stop' : $img = ('images/lists/off.png'); break; - case 'Start' : $img = ('images/lists/on.png'); break; - } - } - if(!empty($img)){ - return(''); + $this->dialog = TRUE; + $s_entry = array_pop($target); + if($this->plugins[$s_entry]->acl_is_readable("")){ + $this->backup = get_object_vars($this->plugins[$s_entry]); + $this->dialogObject = $this->plugins[$s_entry]; + $this->current = $s_entry; } - return(""); } - - function execute() + /*! \brief Editing an object was caneled. + * Close dialogs/tabs and remove locks. + */ + protected function cancelEdit() { - /* Variable initialisation */ - $s_action = ""; - $s_entry = ""; - - /* Walk through posts and check if there are some introductions for us */ - $PossiblePosts = array("addNewService" => "", - "startServices" => "", - "stopServices" => "", - "restartServices" => "", - "removeServices" => "", - - "StartSingleService" => "/^StartSingleService_(.*)_[xy]$/", - "StopSingleService" => "/^StopSingleService_(.*)_[xy]$/", - "RestartSingleService" => "/^RestartSingleService_(.*)_[xy]$/", - "RemoveSingleService" => "/^RemoveSingleService_(.*)_[xy]$/", - "EditSingleService" => "/^EditSingleService_(.*)_[xy]$/"); - - - $once = true; - foreach($_POST as $name => $value){ - foreach($PossiblePosts as $pregCheck => $idPreg) { - if(preg_match("/^".$pregCheck."/",$name) && $once){ - $once = false; - $s_action = $pregCheck; - - if(!empty($idPreg)){ - $s_entry = preg_replace($idPreg,"\\1",$name); - } - } + if($this->backup == NULL){ + $this->plugins[$this->current] = new $this->current($this->config,$this->dn,$this); + $this->plugins[$this->current]-> set_acl_base($this->acl_base); + $this->plugins[$this->current]-> set_acl_category(preg_replace("/\/$/","",$this->acl_category)); + + }else{ + foreach($this->backup as $name => $value){ + $this->plugins[$this->current]->$name = $value; } } + $this->backup = NULL; + $this->current = ""; + $this->closeDialogs(); + } - /* Handle state changes for services */ - $map = array( "startServices" => array("type" => START_SERVICE , "service" => ALL_SERVICES), - "stopServices" => array("type" => STOP_SERVICE , "service" => ALL_SERVICES), - "restartServices" => array("type" => RESTART_SERVICE , "service" => ALL_SERVICES), - "StartSingleService" => array("type" => START_SERVICE , "service" => $s_entry), - "StopSingleService" => array("type" => STOP_SERVICE , "service" => $s_entry), - "RestartSingleService" => array("type" => RESTART_SERVICE , "service" => $s_entry)); - if(isset($map[$s_action])){ - $type = $map[$s_action]['type']; - $service = $map[$s_action]['service']; - $this->ServiceStatusUpdate($type,$service); - } + function newService() + { + $this->dialog = TRUE; + $this->dialogObject = new ServiceAddDialog($this->config,$this->dn,$this); + } - /* Handle actions linked via href */ - if(isset($_GET['act']) && $_GET['act'] == "open" && isset($_GET['id'])){ - $id = $_GET['id']; - if(isset($this->plugins[$id])){ - $s_entry = $id; - $s_action = "EditSingleService"; - } + function saveService() + { + $this->dialogObject->save_object(); + $msgs = $this->dialogObject->check(); + if(count($msgs)){ + foreach($msgs as $msg){ + msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); + } + }else{ + $this->plugins[$this->current] = $this->dialog; + $tmp = get_object_vars($this->dialog); + foreach($tmp as $name => $value){ + $this->plugins[$this->current]->$name = $value; + } + $this->current = ""; + $this->dialog = FALSE; + $this->backup = NULL; } + } - /* Open service add dialog */ - if($s_action == "addNewService"){ - $this->dialog = new ServiceAddDialog($this->config,$this->dn,$this); - } + function newServiceSelected() + { + $this->closeDialogs(); + $serv = $_POST['ServiceName']; + $this->plugins[$serv]->is_account = true; + $this->dialogObject = $this->plugins[$serv]; + $this->current = $serv; + $this->dialog = TRUE; + } - /* Remove service */ - if($s_action == "RemoveSingleService"){ + function closeDialogs() + { + management::closeDialogs(); + $this->dialog = FALSE; + } - /* Create resetted obj */ + protected function removeService($action="",$target=array(),$all=array()) + { + foreach($target as $s_entry){ $new_obj = new $s_entry($this->config,$this->dn, $this); - $new_obj -> set_acl_base($this->acl_base); - $new_obj -> set_acl_category(preg_replace("/\/$/","",$this->acl_category)); + $new_obj->set_acl_base($this->acl_base); + $new_obj->set_acl_category(preg_replace("/\/$/","",$this->acl_category)); $tmp = $new_obj->getListEntry(); + /* Check if we are allowed to remove this service + */ if($tmp['AllowRemove']){ - - /* Check if we are allowed to remove this service - */ $str = $this->plugins[$s_entry]->allow_remove(); - if(empty($str)){ $this->plugins[$s_entry] = $new_obj; $this->plugins[$s_entry]->is_account = false; @@ -217,75 +220,115 @@ class ServerService extends management } } } + } + static function getServiceList() + { + return(session::get('ServerService')); + } - /* Edit a service and make a backup from all attributes, - to be able to restore old values after aborting dialog */ - if($s_action == "EditSingleService"){ - if($this->plugins[$s_entry]->acl_is_readable("")){ - $this->backup = get_object_vars($this->plugins[$s_entry]); - $this->dialog = $this->plugins[$s_entry]; - $this->current = $s_entry; + static function filterServiceStatus($a,$b,$c,$d) + { + $img =""; + if(isset($d['0'])){ + switch($d[0]){ + case 'Restart' : $img = ('images/status_restarting.png'); break; + case 'Stop' : $img = ('images/lists/off.png'); break; + case 'Start' : $img = ('images/lists/on.png'); break; } } + if(!empty($img)){ + return(''); + } + return(""); + } - - /* Abort service add */ - if(isset($_POST['CancelServiceAdd'])){ - $this->dialog = FALSE; - $this->backup = NULL; - $this->current = ""; + + /*! \brief Execute this plugin + * Handle actions/events, locking, snapshots, dialogs, tabs,... + */ + function execute() + { + // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog. + $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/'); + session::set('LOCK_VARS_TO_USE',$vars); + + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandler("",array()); + if($ret){ + return($this->getHeader().$ret); } - - /* Abort dialog - Restore vars with values before editing */ - if(isset($_POST['CancelService']) && !empty($this->current)){ - if($this->backup == NULL){ - $this->plugins[$this->current] = new $this->current($this->config,$this->dn,$this); - $this->plugins[$this->current]-> set_acl_base($this->acl_base); - $this->plugins[$this->current]-> set_acl_category(preg_replace("/\/$/","",$this->acl_category)); + // Update filter + $filter = $this->getFilter(); + if ($filter) { + $filter->update(); + session::global_set(get_class($this)."_filter", $filter); + session::set('autocomplete', $filter); + if (!$filter->isValid()){ + msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG); + } + } - }else{ - foreach($this->backup as $name => $value){ - $this->plugins[$this->current]->$name = $value; - } + + // Handle actions (POSTs and GETs) + $str = $this->handleActions($this->detectPostActions()); + if($str) return($this->getHeader().$str); + + // Open single dialog objects + if(is_object($this->dialogObject)){ + if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); + if(method_exists($this->dialogObject,'execute')){ + $display = $this->dialogObject->execute(); + $display.= $this->_getTabFooter(); + return($this->getHeader().$display); } - $this->dialog = FALSE; - $this->backup = NULL; - $this->current = ""; } - - - /* Abort dialog */ - if(isset($_POST['SaveService']) && is_object($this->dialog)){ -# $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)){ - foreach($msgs as $msg){ - msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); - } - }else{ - $this->plugins[$this->current] = $this->dialog; - $tmp = get_object_vars($this->dialog); - foreach($tmp as $name => $value){ - $this->plugins[$this->current]->$name = $value; - } - $this->current = ""; - $this->dialog = FALSE; - $this->backup = NULL; + + // Display tab object. + if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){ +# $this->tabObject->save_object(); + $display = $this->tabObject->execute(); + $display.= $this->_getTabFooter(); + return($this->getHeader().$display); + } + + // Set current restore base for snapshot handling. + if(is_object($this->snapHandler)){ + $bases = array(); + foreach($this->storagePoints as $sp){ + $bases[] = $sp.$this->headpage->getBase(); } + + // No bases specified? Try base + if(!count($bases)) $bases[] = $this->headpage->getBase(); + + $this->snapHandler->setSnapshotBases($bases); } + // Display list + session::set('ServerService', $this->plugins); + return($this->renderList()); + } - /* Abort dialog */ - if((isset($_POST['SaveServiceAdd'])) && (!empty($_POST['ServiceName']))){ - $serv = $_POST['ServiceName']; - $this->plugins[$serv]->is_account = true; - $this->dialog = $this->plugins[$serv]; - $this->current = $serv; + function updateServiceStatus($action, $target,$all) + { + /* Handle state changes for services */ + $map = array( + "start" => START_SERVICE , + "stop" => STOP_SERVICE , + "restart" => RESTART_SERVICE ); + foreach($target as $s_entry){ + if(isset($map[$action])){ + $type = $map[$action]; + $service = $s_entry; + $this->ServiceStatusUpdate($type,$service); + } } + } + function _execute() + { /* There is currently a subdialog open, display this dialog */ if(is_object($this->dialog)){ @@ -305,7 +348,7 @@ class ServerService extends management /* Get all used services - CLASSNAME => _($this->plugins[*]->DisplayName); */ + CLASSNAME => _($this->plugins[*]->DisplayName); */ function getAllUsedServices() { $ret = array(); @@ -323,7 +366,7 @@ class ServerService extends management /* Get all unused services - CLASSNAME => _($this->plugins[*]->DisplayName); */ + CLASSNAME => _($this->plugins[*]->DisplayName); */ function getAllUnusedServices() { $tmp = $this->getAllUsedServices(); @@ -333,7 +376,7 @@ class ServerService extends management $pool_of_ocs[]= get_class($this->plugins[$name]); } } - + $ret = array(); foreach($this->plugins as $name => $obj){ @@ -362,8 +405,8 @@ class ServerService extends management } return($ret); } - - + + /* This function sets the status var for each used service && calls an external hook if specified in gosa.conf*/ function ServiceStatusUpdate($method , $service) @@ -385,7 +428,7 @@ class ServerService extends management msg_dialog::display(_("Error"), _("Cannot update service status!"), ERROR_DIALOG); return; } - + $caseVars = array("cn","dn"); if($service == ALL_SERVICES){ foreach($this->plugins as $name => $obj){ @@ -397,8 +440,8 @@ class ServerService extends management /* check if services can be restarted */ $map =array(SERVICE_STARTED=> "AllowStart" , - SERVICE_STOPPED => "AllowStop", - SERVICE_RESTARTED => "AllowRestart"); + SERVICE_STOPPED => "AllowStop", + SERVICE_RESTARTED => "AllowRestart"); /* get plugins informations, restart/start/stop actions allowed ?*/ $tmp = $this->plugins[$name]->getListEntry(); @@ -424,9 +467,8 @@ class ServerService extends management function check() - { - $message = plugin::check(); - return $message; + { + return(array()); } @@ -480,7 +522,7 @@ class ServerService extends management } } - + function PrepareForCopyPaste($source) { plugin::PrepareForCopyPaste($source); @@ -501,11 +543,12 @@ class ServerService extends management } } } - + // Forward plugin ACLs function set_acl_base($base) { + $this->acl_base = $base; foreach($this->plugins as $name => $obj){ $this->plugins[$name]->set_acl_base($base); } @@ -514,6 +557,7 @@ class ServerService extends management // Forward plugin ACLs function set_acl_category($category) { + $this->acl_category = $category; foreach($this->plugins as $name => $obj){ $this->plugins[$name]->set_acl_category($category); } diff --git a/gosa-plugins/systems/admin/systems/serverService-list.xml b/gosa-plugins/systems/admin/systems/serverService-list.xml index e92f659e5..0ea40c00d 100644 --- a/gosa-plugins/systems/admin/systems/serverService-list.xml +++ b/gosa-plugins/systems/admin/systems/serverService-list.xml @@ -72,6 +72,35 @@ + + separator + + + + start + entry + images/status_start.png + + + + + stop + entry + images/status_stop.png + + + + + restart + entry + images/lists/reload.png + + + + + separator + + exporter @@ -109,7 +138,7 @@ entry images/lists/edit.png AllowEdit - + @@ -117,7 +146,7 @@ entry images/lists/trash.png AllowRemove - +