1 <?php
3 /* Create a class (name must be unique inside GOsa) which extends plugin. The plugin base
4 class contains all methods that are used by GOsa and it provides the mechanism to load data
5 from LDAP to local variables and prepare the save to ldap routine for you. */
6 class nagiosAccount extends plugin
7 {
8 /* Definitions */
9 var $plHeadline= "Nagios";
10 var $plDescription= "This does something";
12 /* CLI vars */
13 var $cli_summary= "Manage users nagios account";
14 var $cli_description= "Some longer text\nfor help";
15 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
17 /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't
18 care... */
19 var $attributes= array("NagiosAlias","NagiosPager","NagiosMail","HostNotificationPeriod","ServiceNotificationPeriod","HostNotificationCommands","ServiceNotificationCommands",
20 "HostNotificationOptions",
21 "ServiceNotificationOptions",
22 "HostNotificationPeriod",
23 "ServiceNotificationPeriod",
24 "AuthorizedAllHosts",
25 "AuthorizedAllServices",
26 "AuthorizedSystemCommands",
27 "AuthorizedAllHostCommands",
28 "AuthorizedAllServiceCommands",
29 "AuthorizedConfigurationInformation",
30 "AuthorizedSystemInformation");
31 var $objectclasses= array("nagiosContact");
33 /* The constructor just saves a copy of the config. You may add what ever you need. */
34 function nagiosAccount ($config, $dn= NULL)
35 {
36 /* Include config object */
37 $this->config= $config;
38 plugin::plugin ($config, $dn);
39 $this->initially_was_account= $this->is_account;
40 }
42 /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
43 function execute()
44 {
45 $display= "";
46 /* Use the smarty templating engine here... */
47 $smarty= get_smarty();
49 //echo "<pre>";print_r($_POST);echo "</pre>";
50 /* Do we need to flip is_account state? */
51 if (isset($_POST['modify_state'])){
52 $this->is_account= !$this->is_account;
53 }
54 /* Do we represent a valid account? */
55 if (!$this->is_account && $this->parent == NULL){
56 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
57 _("This account has no nagios extensions.")."</b>";
58 $display.= back_to_main();
59 return ($display);
60 }
61 /* Load attributes */
62 foreach($this->attributes as $val){
63 $smarty->assign("$val", $this->$val);
64 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
65 }
67 if ($this->is_account){
68 $smarty->assign("nagiosAuth","checked");
69 $smarty->assign("nagiosContact","checked");
70 }
72 /* Show tab dialog headers */
73 if ($this->parent != NULL){
74 if ($this->is_account){
75 $display= $this->show_header(_("Remove nagios account"),
76 _("This account has nagios features enabled. You can disable them by clicking below."));
77 } else {
78 $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
79 return($display);
80 }
81 }
82 $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
83 //echo "<pre>";print_r($_POST);echo "</pre>";
84 return ($display);
85 }
86 /* Save to LDAP */
87 function save()
88 {
89 /* Load uid and gid of this 'dn' */
90 $ldap= $this->config->get_ldap_link();
91 $ldap->cat($this->dn);
92 $tmp= $ldap->fetch();
94 plugin::save();
96 //nagiosContact
97 //ugly code but i will correct this after :)
99 if(isset($_POST['NagiosAlias']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias'];
100 if(isset($_POST['NagiosPager']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias'];
101 if(isset($_POST['NagiosMail']))$this->attrs['NagiosMail']=$_POST['NagiosMail'];
102 if(isset($_POST['ServiceNotificationPeriod']))$this->attrs['ServiceNotificationPeriod']=$_POST['ServiceNotificationPeriod'];
103 if(isset($_POST['HostNotificationPeriod']))$this->attrs['HostNotificationPeriod']=$_POST['HostNotificationPeriod'];
104 if(isset($_POST['ServiceNotificationOptions']))$this->attrs['ServiceNotificationOptions']=$_POST['ServiceNotificationOptions'];
105 if(isset($_POST['HostNotificationOptions']))$this->attrs['HostNotificationOptions']=$_POST['HostNotificationOptions'];
106 if(isset($_POST['ServiceNotificationCommands']))$this->attrs['ServiceNotificationCommands']=$_POST['ServiceNotificationCommands'];
107 if(isset($_POST['HostNotificationCommands']))$this->attrs['HostNotificationCommands']=$_POST['HostNotificationCommands'];
109 //nagiosAuth
110 if(isset($_POST['AuthorizedSystemInformation']))$this->attrs['AuthorizedSystemInformation']="checked";else $this->attrs['AuthorizedSystemInformation']="unchecked";
111 if(isset($_POST['AuthorizedConfigurationInformation']))$this->attrs['AuthorizedConfigurationInformation']="checked";else $this->attrs['AuthorizedConfigurationInformation']="unchecked";
112 if(isset($_POST['AuthorizedSystemCommands']))$this->attrs['AuthorizedSystemCommands']="checked";else $this->attrs['AuthorizedSystemCommands']="unchecked";
113 if(isset($_POST['AuthorizedAllServices']))$this->attrs['AuthorizedAllServices']="checked";else $this->attrs['AuthorizedAllServices']="unchecked";
114 if(isset($_POST['AuthorizedAllHosts']))$this->attrs['AuthorizedAllHosts']="checked";else $this->attrs['AuthorizedAllHosts']="unchecked";
115 if(isset($_POST['AuthorizedAllServiceCommands']))$this->attrs['AuthorizedAllServiceCommands']="checked";else $this->attrs['AuthorizedAllServiceCommands']="unchecked";
116 if(isset($_POST['AuthorizedAllHostCommands']))$this->attrs['AuthorizedAllHostCommands']="checked";else $this->attrs['AuthorizedAllHostCommands']="unchecked";
118 /* Write back to ldap */
119 $ldap->cd($this->dn);
120 $ldap->modify($this->attrs);
121 show_ldap_error($ldap->get_error());
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 }
132 }
134 function save_object()
135 {
137 if (!$this->is_account && ($_POST['nagiosAuth'] == "B" || $_POST['nagiosContact'] == "B")) {
138 $this->is_account= TRUE;
139 }
140 else {
141 $this->is_account= FALSE;
142 }
143 plugin::save_object();
144 }
146 function remove_from_parent()
147 {
148 /* Cancel if there's nothing to do here */
149 if (!$this->initially_was_account){
150 return;
151 }
153 plugin::remove_from_parent();
154 $ldap= $this->config->get_ldap_link();
156 $ldap->cd($this->dn);
157 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
158 $this->attributes, "Save");
159 $ldap->modify($this->attrs);
160 show_ldap_error($ldap->get_error());
162 /* Optionally execute a command after we're done */
163 $this->handle_post_events('remove');
164 }
165 }
166 ?>