Code

Fixed kolabAccount (Connectivity)
[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   /* constructor, if 'dn' is set, the node loads the given
63      'dn' from LDAP */
64   function nagiosAccount ($config, $dn= NULL)
65   {
66     /* Configuration is fine, allways */
67     $this->config= $config;
69     plugin::plugin ($config, $dn);
71     /* Save initial account state */  
72     $this->initially_was_account= $this->is_account;
73   }
75   function execute()
76   {
77     /* Call parent execute */
78     plugin::execute();
80     /* Load templating engine */
81     $smarty= get_smarty();
82     $display= "";
84     /* Do we need to flip is_account state? */
85     if(isset($_POST['modify_state'])){
86       if($this->is_account && $this->acl_is_removeable()){
87         $this->is_account= FALSE;
88       }elseif(!$this->is_account && $this->acl_is_createable()){
89         $this->is_account= TRUE;
90       }
91     }    
93     /* Do we represent a valid account? */
94     if (!$this->is_account && $this->parent == NULL){
95       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
96         _("This account has no nagios extensions.")."</b>";
98       $display.= back_to_main();
99       return ($display);
100     }
102     /* Show tab dialog headers */
103     if ($this->parent != NULL){
104       if ($this->is_account){
105         $display= $this->show_disable_header(_("Remove nagios account"),
106             _("This account has nagios features enabled. You can disable them by clicking below."));
107       } else {
108         $display= $this->show_enable_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
109         return($display);
110       }
111     }
113     /* Assign acls */
114     $tmp = $this->plInfo();
115     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
116     foreach($tmp['plProvidedAcls'] as $acl => $desc){
117       $smarty->assign($acl."ACL",$this->getacl($acl,$SkipWrite));
118     }
120     /* Assign attributes an ACL to smarty */
121     foreach($this->attributes as $val) { 
122       $smarty->assign("$val", $this->$val);
123       if(in_array($val,$this->is_chk_box)){
124         if($this->$val == "checked"){
125           $smarty->assign($val."CHK", " checked ");
126         }else{
127           $smarty->assign($val."CHK", "");
128         }
129       }
130     }
131     $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
132     $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
133     $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
134     $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
135     $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
136     return ($display);
137   }
139   /* Save to LDAP */
140   function save()
141   {
142     $ldap= $this->config->get_ldap_link();
144     /* Call parents save to prepare $this->attrs */
145     plugin::save();
147     /* Adapt attributes if needed */
148     //$method= new $this->method($this->config);
149     //$id= $method->uattrib;
150     //$method->fixAttributesOnStore($this);
152     /* Write back to ldap */
153     $ldap->cd($this->dn);
154     $this->cleanup();
155     $ldap->modify ($this->attrs); 
157     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/nagios account with dn '%s' failed."),$this->dn));
159     /* Optionally execute a command after we're done */
160     if ($this->initially_was_account == $this->is_account){
161       if ($this->is_modified){
162         $this->handle_post_events("modify");
163       }
164     } else {
165       $this->handle_post_events("add");
166     }
167   }
169   function check()
170   {
171     /* Call common method to give check the hook */
172     $message= plugin::check();
174     $ldap= $this->config->get_ldap_link();
175     /* must: mail */
176     if ($this->NagiosAlias == ""){
177       $message[]= _("The required field 'NagiosAlias' is not set.");
178     }
179     if ($this->NagiosMail == ""){
180       $message[]= _("The required field 'NagiosMail' is not set.");
181     }
182     if ($this->is_template){
183       if (!is_email($this->NagiosMail, TRUE)){
184         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
185       }
186     } else {
187       if (!is_email($this->NagiosMail)){
188         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
189       }
190     }
191     return($message);
192   }
195   /* Use Save_object for every Post handling */
196   function save_object()
197   {
198     if (isset($_POST['nagiosTab'])){
199       /* Save ldap attributes */
200       plugin::save_object();
202       /* Specialhandling for checkboxes */
203       foreach($this->is_chk_box as $val){
204         if($this->acl_is_writeable($val)){
205           if(isset($_POST[$val])){
206             $this->$val = "checked";
207           }else{
208             $this->$val = "unchecked";
209           }
210         }
211       }
212     }
213   }
215   function remove_from_parent()
216   {
217     /* Cancel if there's nothing to do here */
218     if (!$this->initially_was_account){
219       return;
220     }
222     /* include global link_info */
223     $ldap= $this->config->get_ldap_link();
225     /* Remove and write to LDAP */
226     plugin::remove_from_parent();
228     /* Adapt attributes if needed */
229     //     $method= new $this->method($this->config);
230     //     $method->fixAttributesOnRemove($this);
232     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
233         $this->attributes, "Save");
234     $ldap->cd($this->dn);
235     $this->cleanup();
236     $ldap->modify ($this->attrs); 
238     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/nagios account with dn '%s' failed."),$this->dn));
240     /* remove the entry from LDAP */
241     unset ($this->attrs['uid']);
243     /* Optionally execute a command after we're done */
244     $this->handle_post_events('remove');
245   }
249   function plInfo()
250   {
251     return (array(
252           "plShortName"     => _("Nagios"),
253           "plDescription"   => _("Nagios account settings"),
254           "plSelfModify"    => TRUE,
255           "plDepends"       => array("user"),
256           "plPriority"      => 8,                                 // Position in tabs
257           "plSection"       => "personal",                        // This belongs to personal
258           "plCategory"      => array("users"),                   
259           "plOptions"       => array(),
261           "plProvidedAcls"  => array(
263             "NagiosAlias"                       =>  _("Alias"),
264             "NagiosPager"                       =>  _("Pager number"),
265             "NagiosMail"                        =>  _("Mail address"),
267             "HostNotificationCommands"          =>  _("Host notification commands"),
268             "HostNotificationOptions"           =>  _("Host notification options"),
269             "HostNotificationPeriod"            =>  _("Host notification period"),
271             "ServiceNotificationCommands"       =>  _("Service notification commands"),
272             "ServiceNotificationOptions"        =>  _("Service notification options"),
273             "ServiceNotificationPeriod"         =>  _("Service notification period"),
275             "AuthorizedAllHosts"                =>  _("View all hosts"),
276             "AuthorizedAllServices"             =>  _("View all services"),
278             "AuthorizedSystemCommands"          =>  _("Trigger system commands"),
279             "AuthorizedAllHostCommands"         =>  _("Trigger all host commands"),
280             "AuthorizedAllServiceCommands"      =>  _("Trigger all service commands"),
282             "AuthorizedConfigurationInformation"=>  _("View configuration information"),
283             "AuthorizedSystemInformation"       =>  _("View system informations"))
284       ));
285   }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>