Code

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