From: hickert
Date: Tue, 6 Jun 2006 12:14:17 +0000 (+0000)
Subject: Added new service management
X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f271f422648038c39396af448362d66af0ff0073;p=gosa.git
Added new service management
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3659 594d385d-05f5-0310-b6e9-bd551577e9d8
---
diff --git a/html/images/status_restart.png b/html/images/status_restart.png
new file mode 100644
index 000000000..de65ee190
Binary files /dev/null and b/html/images/status_restart.png differ
diff --git a/html/images/status_restart_all.png b/html/images/status_restart_all.png
new file mode 100644
index 000000000..de65ee190
Binary files /dev/null and b/html/images/status_restart_all.png differ
diff --git a/html/images/status_restarting.png b/html/images/status_restarting.png
new file mode 100644
index 000000000..de65ee190
Binary files /dev/null and b/html/images/status_restarting.png differ
diff --git a/html/images/status_running.png b/html/images/status_running.png
new file mode 100755
index 000000000..543710fb7
Binary files /dev/null and b/html/images/status_running.png differ
diff --git a/html/images/status_start.png b/html/images/status_start.png
new file mode 100755
index 000000000..543710fb7
Binary files /dev/null and b/html/images/status_start.png differ
diff --git a/html/images/status_start_all.png b/html/images/status_start_all.png
new file mode 100755
index 000000000..543710fb7
Binary files /dev/null and b/html/images/status_start_all.png differ
diff --git a/html/images/status_stop.png b/html/images/status_stop.png
new file mode 100755
index 000000000..3240b29d5
Binary files /dev/null and b/html/images/status_stop.png differ
diff --git a/html/images/status_stop_all.png b/html/images/status_stop_all.png
new file mode 100755
index 000000000..3240b29d5
Binary files /dev/null and b/html/images/status_stop_all.png differ
diff --git a/html/images/status_stopped.png b/html/images/status_stopped.png
new file mode 100755
index 000000000..3240b29d5
Binary files /dev/null and b/html/images/status_stopped.png differ
diff --git a/plugins/admin/systems/ServerService/ServiceAddDialog.tpl b/plugins/admin/systems/ServerService/ServiceAddDialog.tpl
new file mode 100755
index 000000000..386e1ee08
--- /dev/null
+++ b/plugins/admin/systems/ServerService/ServiceAddDialog.tpl
@@ -0,0 +1,38 @@
+
+
+ {t}Add a new service to this server.{/t}.
+
+
+
+
+{t}This dialog allows you to add new services to the currenty edited server object. In the box below you can see all available services, services you have already in use are not shown.{/t}
+
+
+
+{if $Services}
+
+
+
+{t}Please choose a service listed below.{/t}
+
+
+ {t}Available services{/t}
+
+{else}
+
+ {t}There are no more services available, if you think that there is a service missing. Please check your gosa configuration file.{/t}
+
+{/if}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/admin/systems/ServerService/back b/plugins/admin/systems/ServerService/back
new file mode 100644
index 000000000..fbae155cb
--- /dev/null
+++ b/plugins/admin/systems/ServerService/back
@@ -0,0 +1,126 @@
+ "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+ /* This plugin only writes its objectClass */
+ var $objectclasses = array("goMailServer");
+
+ /* This class can't be assigned twice so it conflicts with itsself */
+ var $conflicts = array("goMailServer");
+
+ var $DisplayName = "";
+ var $dn = NULL;
+ var $StatusFlag = "goMailServerStatus";
+ var $attributes = array("goMailServerStatus","description","goMailServerStatus","postfixHeaderSizeLimit",
+ "postfixMailboxSizeLimit","postfixMessageSizeLimit",
+ "postfixMydestinations","postfixMydomain","postfixMyhostname",
+ "postfixMynetworks","postfixRelayhost","postfixTransportTable",
+ "postfixSenderRestrictions","postfixRecipientRestrictions");
+
+ var $goMailServerStatus
+ var $postfixHeaderSizeLimit
+ var $postfixMailboxSizeLimit
+ var $postfixMessageSizeLimit
+ var $postfixMydestinations
+ var $postfixMydomain
+ var $postfixMyhostname
+ var $postfixMynetworks
+ var $postfixRelayhost
+ var $postfixTransportTable
+ var $postfixSenderRestrictions
+ var $postfixRecipientRestrictions
+
+
+ function goMailServer($config,$dn)
+ {
+ plugin::plugin($config,$dn);
+ $this->DisplayName = _("Flag server as mail server.");
+ $this->is_account = true;
+ }
+
+ function execute()
+ {
+ /* this class can't be executed- It represents only a flag */
+ return;
+ }
+
+ function getListEntry()
+ {
+ $flag = $this->StatusFlag;
+ $fields['Status'] = $this->$flag;
+ $fields['Message'] = _("Flag server as mail server");
+ $fields['AllowStart'] = true;
+ $fields['AllowStop'] = true;
+ $fields['AllowReset'] = true;
+ $fields['AllowRemove']= true;
+ $fields['AllowEdit'] = true;
+ return($fields);
+ }
+
+ function remove_from_parent()
+ {
+ plugin::remove_from_parent();
+ /* Check if this is a new entry ... add/modify */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($this->dn,array("objectClass"));
+ if($ldap->count()){
+ $ldap->cd($this->dn);
+ $ldap->modify($this->attrs);
+ }else{
+ $ldap->cd($this->dn);
+ $ldap->add($this->attrs);
+ }
+ show_ldap_error($ldap->get_error());
+ }
+
+ function save()
+ {
+ plugin::save();
+ /* Check if this is a new entry ... add/modify */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($this->dn,array("objectClass"));
+ if($ldap->count()){
+ $ldap->cd($this->dn);
+ $ldap->modify($this->attrs);
+ }else{
+ $ldap->cd($this->dn);
+ $ldap->add($this->attrs);
+ }
+ show_ldap_error($ldap->get_error());
+ }
+
+
+ /* Directly save new status flag */
+ function setStatus($value)
+ {
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dn);
+ $ldap->cat($this->dn,array("objectClass"));
+
+ if($ldap->count()){
+ $attrs =array();
+ $tmp = $ldap->fetch();
+ for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
+ $attrs['objectClass'][] = $tmp['objectClass'][$i];
+ }
+ $flag = $this->StatusFlag;
+ $attrs[$flag] = $value;
+ $this->$flag = $value;
+ $ldap->modify($attrs);
+ show_ldap_error($ldap->get_error());
+ }
+ }
+
+
+ function check(){ return array();}
+ function save_object()
+ {
+ plugin::save_object();
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/ServerService/class_ServerService.inc b/plugins/admin/systems/ServerService/class_ServerService.inc
new file mode 100644
index 000000000..9f9747a6e
--- /dev/null
+++ b/plugins/admin/systems/ServerService/class_ServerService.inc
@@ -0,0 +1,305 @@
+"Config object" , "dn"=>"Object dn");
+
+ /* attribute list for save action */
+ var $ignore_account = TRUE;
+ var $attributes = array();
+ var $objectclasses = array();
+
+ var $divList = NULL;
+ var $dialog = NULL; // Contains dialog object if a dialog is opened
+
+ var $plugins = array();
+ var $pluign_names = array();
+
+ var $current = "";
+ var $backup = NULL;
+ var $acl ;
+
+ function ServerService ($config, $dn)
+ {
+ plugin::plugin($config);
+ $this->dn= $dn;
+ $ui= get_userinfo();
+ $this->acl= get_permissions ($ui->dn, $ui->subtreeACL);
+
+ foreach ($config->data['TABS']['SERVERSERVICE'] as $plug){
+ $name= $plug['CLASS'];
+ $this->plugin_names[]= $name;
+ $this->plugins[$name]= new $name($config, $dn);
+ $this->plugins[$name]->acl= get_module_permission($this->acl, "$name", $ui->dn);
+ }
+
+ $this->divList = new divListSystemService($config,$this);
+ }
+
+
+ function execute()
+ {
+ /* Variable initialisation */
+ $s_action = "";
+ $s_entry = "";
+
+
+ /* Walk through posts and check if there are some introductions for us */
+ $PossiblePosts = array("addNewService" => "",
+ "startServices" => "",
+ "stopServices" => "",
+ "resetServices" => "",
+ "removeServices" => "",
+
+ "StartSingleService" => "/^StartSingleService_(.*)_[xy]$/",
+ "StopSingleService" => "/^StopSingleService_(.*)_[xy]$/",
+ "ResetSingleService" => "/^ResetSingleService_(.*)_[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);
+ }
+ }
+ }
+ }
+
+
+ /* Handle state changes for services */
+ $map = array( " startServices" => array("type" => START_SERVICE , "service" => ALL_SERVICES),
+ "stopServices" => array("type" => STOP_SERVICE , "service" => ALL_SERVICES),
+ "resetServices" => array("type" => RESET_SERVICE , "service" => ALL_SERVICES),
+ "StartSingleService" => array("type" => START_SERVICE , "service" => $s_entry),
+ "StopSingleService" => array("type" => STOP_SERVICE , "service" => $s_entry),
+ "ResetSingleService" => array("type" => RESET_SERVICE , "service" => $s_entry));
+ if(isset($map[$s_action])){
+ $type = $map[$s_action]['type'];
+ $service = $map[$s_action]['service'];
+ $this->ServiceStatusUpdate($type,$service);
+ }
+
+
+ /* Open service add dialog */
+ if($s_action == "addNewService"){
+ $this->dialog = new ServiceAddDialog($this->config,$this->dn,$this);
+ }
+
+
+ /* Remove service */
+ if($s_action == "RemoveSingleService"){
+ $this->plugins[$s_entry]->is_account= false;
+ $this->plugins[$s_entry] = NULL;
+ $this->plugins[$s_entry] = new $s_entry($this->config,$this->dn);
+ $this->plguins[$s_entry]->acl = $this->acl;
+ $this->plugins[$s_entry]->is_account = false;
+ }
+
+
+ /* Edit a service and make a backup from all attributes,
+ to be able to restore old values after aborting dialog */
+ if($s_action == "EditSingleService"){
+ $this->backup = get_object_vars($this->plugins[$s_entry]);
+ $this->dialog = $this->plugins[$s_entry];
+ $this->current = $s_entry;
+ }
+
+
+ /* Abort service add */
+ if(isset($_POST['CancelServiceAdd'])){
+ $this->dialog = NULL;
+ $this->backup = NULL;
+ $this->current = "";
+ }
+
+
+ /* Abort dialog
+ Restore vars with values before editing */
+ if(isset($_POST['CancelService'])){
+ foreach($this->backup as $name => $value){
+ $this->plugins[$this->current]->$name = $value;
+ }
+ $this->dialog = NULL;
+ $this->backup = NULL;
+ $this->current = "";
+ }
+
+
+ /* Abort dialog */
+ if(isset($_POST['SaveService'])){
+
+ $msgs = $this->dialog->check();
+ if(count($msgs)){
+ foreach($msgs as $msg){
+ print_red($msg);
+ }
+ }else{
+ $this->plugins[$this->current] = $this->dialog;
+ $this->current = "";
+ $this->dialog = NULL;
+ $this->backup = NULL;
+ }
+ }
+
+
+ /* Abort dialog */
+ if(isset($_POST['SaveServiceAdd'])){
+ $serv = $_POST['ServiceName'];
+ $this->plugins[$serv]->is_account = true;
+ $this->dialog = $this->plugins[$serv];
+ $this->current = $serv;
+ }
+
+
+ /* There is currently a subdialog open, display this dialog */
+ if($this->dialog != NULL){
+ $this->dialog->save_object();
+ return($this->dialog->execute());
+ }
+
+
+ /* Dispaly services overview */
+ $this->divList->execute();
+ $list = array();
+ foreach($this->plugins as $name => $obj){
+ if($obj->is_account){
+ $list[$name] = $obj->getListEntry();
+ }
+ }
+ $this->divList -> setEntries($list);
+ return($this->divList->Draw());
+ }
+
+
+ /* Get all used services
+ CLASSNAME => _($this->plugins[*]->DisplayName); */
+ function getAllUsedServices()
+ {
+ $ret = array();
+ foreach($this->plugins as $name => $obj){
+ if($obj->is_account){
+ if(isset($obj->DisplayName)){
+ $ret[$name] = $obj->DisplayName;
+ }else{
+ $ret[$name] = $name;
+ }
+ }
+ }
+ return($ret);
+ }
+
+
+ /* Get all unused services
+ CLASSNAME => _($this->plugins[*]->DisplayName); */
+ function getAllUnusedServices()
+ {
+ $tmp = $this->getAllUsedServices();
+ $pool_of_ocs =array();
+ foreach($tmp as $name => $value){
+ if(isset($this->plugins[$name]->conflicts)){
+ $pool_of_ocs = array_merge($pool_of_ocs,$this->plugins[$name]->conflicts);
+ }
+ }
+
+ $this->plugins['goMailServer']->is_acount= true;
+
+ $ret = array();
+ foreach($this->plugins as $name => $obj){
+
+ /* Skip all pluigns that will lead into conflicts */
+ $skip = false;
+ if(isset($obj->conflicts)){
+ foreach($obj->conflicts as $oc){
+ if(in_array_ics($oc,$pool_of_ocs)){
+ $skip = true;
+ }
+ }
+ }
+ if(!$skip){
+ if(isset($obj->DisplayName)){
+ $ret[$name] = $obj->DisplayName;
+ }else{
+ $ret[$name] = $name;
+ }
+ }
+ }
+ 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)
+ {
+ $action = "";
+ if($method == START_SERVICE){
+ $action = SERVICE_STARTED;
+ }elseif($method== STOP_SERVICE){
+ $action = SERVICE_STOPPED;
+ }elseif($method == RESET_SERVICE){
+ $action = SERVICE_RESETTED;
+ }else{
+ print_red(sprintf(_("The specified method '%s' can't executed for services."),$action));
+ return;
+ }
+
+ if($service == ALL_SERVICES){
+ foreach($this->plugins as $name => $obj){
+ $this->plugins[$name]->setStatus($action);
+ }
+ }else{
+ $this->plugins[$service]->setStatus($action);
+ }
+ }
+
+
+ function check()
+ {
+ $message = plugin::check();
+ return $message;
+ }
+
+
+ function save_object()
+ {
+ foreach($this->plugins as $name => $obj){
+ if($obj->is_account){
+ $this->plugins[$name]->save_object();
+ }
+ }
+ }
+
+ function save()
+ {
+ foreach($this->plugins as $name => $obj){
+ if($this->plugins[$name]->is_account){
+ $this->plugins[$name]->save();
+ }else{
+ $this->plugins[$name]->remove_from_parent();
+ }
+ }
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/ServerService/class_ServiceAddDialog.inc b/plugins/admin/systems/ServerService/class_ServiceAddDialog.inc
new file mode 100644
index 000000000..a5a284e68
--- /dev/null
+++ b/plugins/admin/systems/ServerService/class_ServiceAddDialog.inc
@@ -0,0 +1,32 @@
+"Config object" , "dn"=>"Object dn");
+
+ /* This plugin does not have any ocs */
+ var $objectclasses = array();
+ var $parent = NULL;
+
+ function ServiceAddDialog($config,$dn,$parent)
+ {
+ plugin::plugin($config);
+ $this->parent = $parent;
+ }
+
+ function execute()
+ {
+ $smarty = get_smarty();
+ $smarty->assign("Services",$this->parent->getAllUnusedServices());
+ return($smarty->fetch(get_template_path("ServiceAddDialog.tpl", TRUE,dirname(__FILE__))));
+ }
+
+ function check(){ return array();}
+ function save_object(){;}
+ function save(){}
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/ServerService/class_divListSystem.inc b/plugins/admin/systems/ServerService/class_divListSystem.inc
new file mode 100644
index 000000000..8fdac79e8
--- /dev/null
+++ b/plugins/admin/systems/ServerService/class_divListSystem.inc
@@ -0,0 +1,127 @@
+AddCheckBox */
+ var $parent ;
+ var $ui ;
+
+ function divListSystemService ($config,$parent)
+ {
+ MultiSelectWindow::MultiSelectWindow($config,"SystemService");
+
+ $this->parent = $parent;
+ $this->ui = get_userinfo();
+
+ /* Set list strings */
+ $this->SetTitle(_("Installed services"));
+ $this->SetSummary(_("Installed services"));
+
+ /* Result page will look like a headpage */
+ $this->SetHeadpageMode();
+ $this->SetInformation(_("This menu allows you to add, remove and configure the properties of a specific service."));
+
+ /* Disable buttonsm */
+ $this->EnableCloseButton(false);
+ $this->EnableSaveButton (false);
+
+ /* set Page header */
+ $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
+ $this->AddHeader(array("string"=>_("Service name")));
+ $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:100px;border-right:0px;'"));
+ $this->HideFilterPart();
+ $this->SetHeight(500);
+ }
+
+ function GenHeader()
+ {
+ /* Prepare departments,
+ which are shown in the listbox on top of the listbox
+ */
+ $options= "";
+ foreach ($this->config->idepartments as $key => $value){
+ if ($this->selectedBase == $key){
+ $options.= "";
+ } else {
+ $options.= "";
+ }
+ }
+ $listhead = "