Code

added missing main.inc
[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", "AuthorizedAllHosts", "AuthorizedAllServices",
49       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
50       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
52   var $objectclasses= array("nagiosContact");
54   /* constructor, if 'dn' is set, the node loads the given
55        'dn' from LDAP */
56   function nagiosAccount ($config, $dn= NULL)
57   {
58     /* Configuration is fine, allways */
59     $this->config= $config;
60     
61         plugin::plugin ($config, $dn);
63     /* Save initial account state */  
64           $this->initially_was_account= $this->is_account;
65   }
67   function execute()
68   {
69     /* Load templating engine */
70     $smarty= get_smarty();
71     $display= "";
72             
73           /* Do we need to flip is_account state? */
74           if (isset($_POST['modify_state'])){
75             $this->is_account= !$this->is_account;
76           }
77   
78           /* Do we represent a valid account? */
79             if (!$this->is_account && $this->parent == NULL){
80               $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
81                       _("This account has no nagios extensions.")."</b>";
82     
83         $display.= back_to_main();
84         return ($display);
85             }
86   
87           /* Show tab dialog headers */
88           if ($this->parent != NULL){
89       if ($this->is_account){
90         $display= $this->show_header(_("Remove nagios account"),
91             _("This account has nagios features enabled. You can disable them by clicking below."));
92       } else {
93         $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
94         return($display);
95             }
96           }
97         $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
98             return ($display);
99   }
101   /* Save to LDAP */
102   function save()
103   {
104     $ldap= $this->config->get_ldap_link();
106     /* Call parents save to prepare $this->attrs */
107           plugin::save();
109     /* Adapt attributes if needed */
110     $method= new $this->method($this->config);
111     $id= $method->uattrib;
112     $method->fixAttributesOnStore($this);
113                 
115           /* Write back to ldap */
116           $ldap->cd($this->dn);
117           $ldap->modify($this->attrs);
118           show_ldap_error($ldap->get_error());
119         
120           /* Optionally execute a command after we're done */
121           if ($this->initially_was_account == $this->is_account){
122             if ($this->is_modified){
123                     $this->handle_post_events("modify");
124             }
125           } else {
126             $this->handle_post_events("add");
127     }
128         
129   }
131   function check()
132   {
133   }
134   
135   function save_object()
136   {
138     if (isset($_POST['nagiosTab'])){
139       /* Save ldap attributes */
140       plugin::save_object();
141     }
142   }
144   function remove_from_parent()
145   {
146           /* Cancel if there's nothing to do here */
147           if (!$this->initially_was_account){
148             return;
149           }
151     /* include global link_info */
152     $ldap= $this->config->get_ldap_link();
154     /* Remove and write to LDAP */
155     plugin::remove_from_parent();
157     /* Adapt attributes if needed */
158     $method= new $this->method($this->config);
159     $method->fixAttributesOnRemove($this);
160     
162     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
163       $this->attributes, "Save");
164     $ldap->cd($this->dn);
165     $ldap->modify($this->attrs);
166     show_ldap_error($ldap->get_error());
167                         
168     /* remove the entry from LDAP */
169     //unset ($this->attrs['uid']);
170                 
171     /* Optionally execute a command after we're done */
172     $this->handle_post_events('remove');
173   }
177 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
179 ?>