Code

51dbac1e3e55a26b05d5b12d3dea169ffeda8738
[gosa.git] / plugins / personal / nagios / class_nagiosAccount.inc
1 <?php
3 /*! \brief   mail plugin
4   \author  Guillame Delecourt <guillaume@opensides.be>
5   \author  Benoit Mortier <benoit.mortier@opensides.be>
6   \version 1.00
7   \date    25.09.2005
9   This class provides the functionality to read and write all attributes
10   relevant for nagiosAccount from/to the LDAP. It does syntax checking
11   and displays the formulars required.
12  */
14 class nagiosAccount extends plugin
15 {
16         /* Definitions */
17         var $plHeadline= "Nagios";
18         var $plDescription= "This does something";
19         
20         /* CLI vars */
21         var $cli_summary= "Manage users nagios account";
22         var $cli_description= "Manage Account and autorization\nfor Nagios";
23         var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
25   /* plugin specific values */
26   var $NagiosAlias= "";
27   var $NagiosPager= "";
28   var $NagiosMail= "";
29   var $HostNotificationPeriod= "";
30   var $ServiceNotitificationPeriod= "";
31   var $HostNotificationCommands= "";
32   var $ServiceNotificationCommands= "";
33   var $HostNotitificationOptions= "";
34   var $ServiceNotificationOptions= "";
36   var $AuthorizedAllHosts= "";
37   var $AuthorizedAllServices= "";
38   var $AuthorizedSystemCommands= "";
39   var $AuthorizedAllHostCommands= "";
40   var $AuthorizedAllServiceCommands= "";
41   var $AuthorizedConfigurationInformation= "";
42   var $AuthorizedSystemInformation= "";
44   /* attribute list for save action */
45   
46         var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
47       "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
48       "HostNotificationOptions", "ServiceNotificationOptions", "HostNotificationPeriod",
49       "ServiceNotificationPeriod", "AuthorizedAllHosts", "AuthorizedAllServices",
50       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
51       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
53   var $objectclasses= array("nagiosContact");
55   /* constructor, if 'dn' is set, the node loads the given
56        'dn' from LDAP */
57   function nagiosAccount ($config, $dn= NULL)
58   {
59     /* Configuration is fine, allways */
60     $this->config= $config;
61     
62         plugin::plugin ($config, $dn);
64     /* Save initial account state */  
65           $this->initially_was_account= $this->is_account;
66   }
68   function execute()
69   {
70     /* Load templating engine */
71     $smarty= get_smarty();
72     $display= "";
73             
74           /* Do we need to flip is_account state? */
75           if (isset($_POST['modify_state'])){
76             $this->is_account= !$this->is_account;
77           }
78   
79           /* Do we represent a valid account? */
80             if (!$this->is_account && $this->parent == NULL){
81               $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
82                       _("This account has no nagios extensions.")."</b>";
83     
84         $display.= back_to_main();
85         return ($display);
86             }
87   
88           /* Show tab dialog headers */
89           if ($this->parent != NULL){
90       if ($this->is_account){
91         $display= $this->show_header(_("Remove nagios account"),
92             _("This account has nagios features enabled. You can disable them by clicking below."));
93       } else {
94         $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
95         return($display);
96             }
97           }
98         $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
99             return ($display);
100   }
102   /* Save to LDAP */
103   function save()
104   {
105     $ldap= $this->config->get_ldap_link();
107     /* Call parents save to prepare $this->attrs */
108           plugin::save();
110     /* Adapt attributes if needed */
111     $method= new $this->method($this->config);
112     $id= $method->uattrib;
113     $method->fixAttributesOnStore($this);
114                 
116           /* Write back to ldap */
117           $ldap->cd($this->dn);
118           $ldap->modify($this->attrs);
119           show_ldap_error($ldap->get_error());
120         
121           /* Optionally execute a command after we're done */
122           if ($this->initially_was_account == $this->is_account){
123             if ($this->is_modified){
124                     $this->handle_post_events("modify");
125             }
126           } else {
127             $this->handle_post_events("add");
128     }
129         
130   }
132   function check()
133   {
134   }
135   
136   function save_object()
137   {
139     if (isset($_POST['mailTab'])){
140       /* Save ldap attributes */
141       plugin::save_object();
142     }
143   }
145   function remove_from_parent()
146   {
147           /* Cancel if there's nothing to do here */
148           if (!$this->initially_was_account){
149             return;
150           }
152     /* include global link_info */
153     $ldap= $this->config->get_ldap_link();
155     /* Remove and write to LDAP */
156     plugin::remove_from_parent();
158     /* Adapt attributes if needed */
159     $method= new $this->method($this->config);
160     $method->fixAttributesOnRemove($this);
161     
163     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
164       $this->attributes, "Save");
165     $ldap->cd($this->dn);
166     $ldap->modify($this->attrs);
167     show_ldap_error($ldap->get_error());
168                         
169     /* remove the entry from LDAP */
170     //unset ($this->attrs['uid']);
171                 
172     /* Optionally execute a command after we're done */
173     $this->handle_post_events('remove');
174   }
178 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
180 ?>