Code

Added execute methods
[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   \author  Vincent Seynhaeve <vincent@opensides.be>  
7   \version 1.00
8   \date    25.09.2005
10   This class provides the functionality to read and write all attributes
11   relevant for nagiosAccount from/to the LDAP. It does syntax checking
12   and displays the formulars required.
13  */
15 class nagiosAccount extends plugin
16 {
17         /* Definitions */
18         var $plHeadline= "Nagios";
19         var $plDescription= "This does something";
20         
21         /* CLI vars */
22         var $cli_summary= "Manage users nagios account";
23         var $cli_description= "Manage Account and autorization\nfor Nagios";
24         var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
26   /* plugin specific values */
27   var $NagiosAlias= "";
28   var $NagiosPager= "";
29   var $NagiosMail= "";
30   var $HostNotificationPeriod= "";
31   var $ServiceNotitificationPeriod= "";
32   var $HostNotificationCommands= "";
33   var $ServiceNotificationCommands= "";
34   var $HostNotitificationOptions= "";
35   var $ServiceNotificationOptions= "";
37   var $AuthorizedAllHosts= "";
38   var $AuthorizedAllServices= "";
39   var $AuthorizedSystemCommands= "";
40   var $AuthorizedAllHostCommands= "";
41   var $AuthorizedAllServiceCommands= "";
42   var $AuthorizedConfigurationInformation= "";
43   var $AuthorizedSystemInformation= "";
45   /* attribute list for save action */
46   
47         var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
48       "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
49       "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
50       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
51       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
53   var $objectclasses= array("nagiosContact","nagiosAuth");
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         /* Call parent execute */
71         plugin::execute();
72     /* Load templating engine */
73     $smarty= get_smarty();
74     $display= "";
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           
101     foreach(array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
102                   "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
103                   "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
104                   "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
105                   "AuthorizedConfigurationInformation", "AuthorizedSystemInformation") as $val) {
107     $smarty->assign("$val", $this->$val);
108     $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
109     }
110     $smarty->assign('ServiceNotificationOptionsValues',array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
111     $smarty->assign('HostNotificationOptionsValues',array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
114     $smarty->assign('ServiceNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
115     $smarty->assign('HostNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
117         $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
118             return ($display);
120   }
122   /* Save to LDAP */
123   function save()
124   {
125     $ldap= $this->config->get_ldap_link();
127     /* Call parents save to prepare $this->attrs */
128           plugin::save();
130     /* Adapt attributes if needed */
131     //$method= new $this->method($this->config);
132     //$id= $method->uattrib;
133     //$method->fixAttributesOnStore($this);
135         $check="unchecked";
136         if(isset($_POST['AuthorizedSystemInformation'])){$check="checked";}$this->attrs['AuthorizedSystemInformation']=$check;
137         $check="unchecked";
138         if(isset($_POST['AuthorizedConfigurationInformation'])){$check="checked";}$this->attrs['AuthorizedConfigurationInformation']=$check;
139         $check="unchecked";
140         if(isset($_POST['AuthorizedSystemCommands'])){$check="checked";}$this->attrs['AuthorizedSystemCommands']=$check;
141         $check="unchecked";
142         if(isset($_POST['AuthorizedAllServices'])){$check="checked";}$this->attrs['AuthorizedAllServices']=$check;
143         $check="unchecked";
144         if(isset($_POST['AuthorizedAllHosts'])){$check="checked";}$this->attrs['AuthorizedAllHosts']=$check;
145         $check="unchecked";
146         if(isset($_POST['AuthorizedAllServiceCommands'])){$check="checked";}$this->attrs['AuthorizedAllServiceCommands']=$check;
147         $check="unchecked";
148         if(isset($_POST['AuthorizedAllHostCommands'])){$check="checked";}$this->attrs['AuthorizedAllHostCommands']=$check;
149           /* Write back to ldap */
150           $ldap->cd($this->dn);
151           $ldap->modify($this->attrs);
152           show_ldap_error($ldap->get_error());
153         
154           /* Optionally execute a command after we're done */
155           if ($this->initially_was_account == $this->is_account){
156             if ($this->is_modified){
157                     $this->handle_post_events("modify");
158             }
159           } else {
160             $this->handle_post_events("add");
161     }
162         
163   }
165   function check()
166   {
167     $message= array();
168     $ldap= $this->config->get_ldap_link();
169     /* must: mail */
170     if ($this->NagiosAlias == ""){
171       $message[]= _("The required field 'NagiosAlias' is not set.");
172     }
173     if ($this->NagiosMail == ""){
174       $message[]= _("The required field 'NagiosMail' is not set.");
175     }
176     if ($this->is_template){
177       if (!is_email($this->NagiosMail, TRUE)){
178         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
179       }
180     } else {
181       if (!is_email($this->NagiosMail)){
182         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
183       }
184     }
185         return($message);
186   }
187   
188   function save_object()
189   {
191     if (isset($_POST['nagiosTab'])){
192       /* Save ldap attributes */
193       plugin::save_object();
194     }
195   }
197   function remove_from_parent()
198   {
199           /* Cancel if there's nothing to do here */
200           if (!$this->initially_was_account){
201             return;
202           }
204     /* include global link_info */
205     $ldap= $this->config->get_ldap_link();
207     /* Remove and write to LDAP */
208     plugin::remove_from_parent();
210     /* Adapt attributes if needed */
211 //     $method= new $this->method($this->config);
212 //     $method->fixAttributesOnRemove($this);
213     
215     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
216       $this->attributes, "Save");
217     $ldap->cd($this->dn);
218     $ldap->modify($this->attrs);
219     show_ldap_error($ldap->get_error());
220                         
221     /* remove the entry from LDAP */
222     unset ($this->attrs['uid']);
223                 
224     /* Optionally execute a command after we're done */
225     $this->handle_post_events('remove');
226   }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
232 ?>