Code

Include personal title in cn/dn
[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";
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   = "";
31   var $HostNotificationOptions      = "";
32   var $HostNotificationPeriod       = "";
33   var $ServiceNotificationPeriod    = "";
34   var $ServiceNotitificationPeriod  = "";
35   var $HostNotificationCommands     = "";
36   var $ServiceNotificationCommands  = "";
37   var $HostNotitificationOptions    = "";
38   var $ServiceNotificationOptions   = "";
40   var $AuthorizedAllHosts                 = "unchecked";
41   var $AuthorizedAllServices              = "unchecked";
42   var $AuthorizedSystemCommands           = "unchecked";
43   var $AuthorizedAllHostCommands          = "unchecked";
44   var $AuthorizedAllServiceCommands       = "unchecked";
45   var $AuthorizedConfigurationInformation = "unchecked";
46   var $AuthorizedSystemInformation        = "unchecked";
48   /* attribute list for save action */
50   var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
51       "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
52       "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
53       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
54       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
56   var $is_chk_box = array("AuthorizedAllHosts","AuthorizedAllServices","AuthorizedSystemCommands",
57       "AuthorizedAllHostCommands","AuthorizedAllServiceCommands",
58       "AuthorizedConfigurationInformation","AuthorizedSystemInformation");
60   var $objectclasses= array("nagiosContact","nagiosAuth");
62   var $uid = "";
64   /* constructor, if 'dn' is set, the node loads the given
65      'dn' from LDAP */
66   function nagiosAccount ($config, $dn= NULL, $parent= NULL)
67   {
68     /* Configuration is fine, allways */
69     $this->config= $config;
71     plugin::plugin ($config, $dn, $parent);
73     /* Set uid */    
74     if(isset($this->attrs['uid'])){
75       $this->uid = $this->attrs['uid'][0];
76     }
78     /* Save initial account state */  
79     $this->initially_was_account= $this->is_account;
80   }
82   function execute()
83   {
84     /* Call parent execute */
85     plugin::execute();
87     /* Load templating engine */
88     $smarty= get_smarty();
89     $display= "";
91     /* Do we need to flip is_account state? */
92     if (isset($_POST['modify_state'])){
93       $this->is_account= !$this->is_account;
94     }
96     /* Do we represent a valid account? */
97     if (!$this->is_account && $this->parent == NULL){
98       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
99         _("This account has no nagios extensions.")."</b>";
101       $display.= back_to_main();
102       return ($display);
103     }
105     /* Show tab dialog headers */
106     if ($this->parent != NULL){
107       if ($this->is_account){
108         $display= $this->show_header(_("Remove nagios account"),
109             _("This account has nagios features enabled. You can disable them by clicking below."));
110       } else {
111         $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
112         return($display);
113       }
114     }
116     /* Assign attributes an ACL to smarty */
117     foreach($this->attributes as $val) { 
118       $smarty->assign("$val", $this->$val);
119       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
120       if(in_array($val,$this->is_chk_box)){
121         if($this->$val == "checked"){
122           $smarty->assign($val."CHK", " checked ");
123         }else{
124           $smarty->assign($val."CHK", "");
125         }
126       }
127     }
128     $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
129     $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
130     $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
131     $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
132     $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
133     return ($display);
134   }
136   /* Save to LDAP */
137   function save()
138   {
139     $ldap= $this->config->get_ldap_link();
141     /* Call parents save to prepare $this->attrs */
142     plugin::save();
144     /* Adapt attributes if needed */
145     //$method= new $this->method($this->config);
146     //$id= $method->uattrib;
147     //$method->fixAttributesOnStore($this);
149     /* Write back to ldap */
150     $ldap->cd($this->dn);
151     $this->cleanup();
152     $ldap->modify ($this->attrs); 
154     show_ldap_error($ldap->get_error(), _("Saving nagios account failed"));
156     /* Optionally execute a command after we're done */
157     if ($this->initially_was_account == $this->is_account){
158       if ($this->is_modified){
159         $this->handle_post_events("modify",array("uid" => $this->uid));
160       }
161     } else {
162       $this->handle_post_events("add", array("uid" => $this->uid));
163     }
164   }
166   function check()
167   {
168     /* Call common method to give check the hook */
169     $message= plugin::check();
171     $ldap= $this->config->get_ldap_link();
172     /* must: mail */
173     if ($this->NagiosAlias == ""){
174       $message[]= _("The required field 'NagiosAlias' is not set.");
175     }
176     if ($this->NagiosMail == ""){
177       $message[]= _("The required field 'NagiosMail' is not set.");
178     }
179     if ($this->is_template){
180       if (!is_email($this->NagiosMail, TRUE)){
181         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
182       }
183     } else {
184       if (!is_email($this->NagiosMail)){
185         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
186       }
187     }
188     return($message);
189   }
192   /* Use Save_object for every Post handling */
193   function save_object()
194   {
195     if (isset($_POST['nagiosTab'])){
196       /* Save ldap attributes */
197       plugin::save_object();
199       /* Specialhandling for checkboxes */
200       foreach($this->is_chk_box as $val){
201         if(isset($_POST[$val])){
202           $this->$val = "checked";
203         }else{
204           $this->$val = "unchecked";
205         }
206       }
207     }
208   }
210   function remove_from_parent()
211   {
212     /* Cancel if there's nothing to do here */
213     if (!$this->initially_was_account){
214       return;
215     }
217     /* include global link_info */
218     $ldap= $this->config->get_ldap_link();
220     /* Remove and write to LDAP */
221     plugin::remove_from_parent();
223     /* Adapt attributes if needed */
224     //     $method= new $this->method($this->config);
225     //     $method->fixAttributesOnRemove($this);
227     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
228         $this->attributes, "Save");
229     $ldap->cd($this->dn);
230     $this->cleanup();
231     $ldap->modify ($this->attrs); 
233     show_ldap_error($ldap->get_error(), _("Removing nagios account failed"));
235     /* remove the entry from LDAP */
236     unset ($this->attrs['uid']);
238     /* Optionally execute a command after we're done */
239     $this->handle_post_events('remove',array("uid"=>$this->uid));
240   }
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>