Code

Just use the -n option from dh_installinit and the world is fine again.
[gosa.git] / systems / class_servGeneric.inc
1 <?php
3 class servgeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server base objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Generic terminal attributes */
11   var $ignore_account= TRUE;
12   var $interfaces= array();
14   /* Needed values and lists */
15   var $base= "";
16   var $cn= "";
17   var $l= "";
18   var $description= "";
19   var $orig_dn= "";
21   /* attribute list for save action */
22   var $attributes= array("cn", "description");
23   var $objectclasses= array("top", "goServer");
25   var $netConfigDNS;
27   function servgeneric ($config, $dn= NULL)
28   {
29     plugin::plugin ($config, $dn);
31     /* Set base */
32     if ($this->dn == "new"){
33       $ui= get_userinfo();
34       $this->base= dn2base($ui->dn);
35       $this->cn= "";
36     } else {
37       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
38     }
39     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
40     /* Save dn for later references */
41     $this->orig_dn= $this->dn;
42   }
44   function execute()
45   {
46         /* Call parent execute */
47         plugin::execute();
49     /* Do we represent a valid server? */
50     if (!$this->is_account && $this->parent == NULL){
51       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
52         _("This 'dn' has no server features.")."</b>";
53       return($display);
54     }
56     /* Check for action */
57     if (isset($_POST['action'])){
58       switch($_POST['action']){
59         case 'wake':
60           $cmd= search_config($this->config->data['TABS'], "servgeneric", "WAKECMD");
61           if ($cmd == ""){
62             print_red(_("No WAKECMD definition found in your gosa.conf"));
63           } else {
64             exec ($cmd." ".$this->netConfigDNS->macAddress, $dummy, $retval);
65             if ($retval != 0){
66               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
67             }
68           }
69           break;
71         case 'reboot':
72           $cmd= search_config($this->config->data['TABS'], "servgeneric", "REBOOTCMD");
73           if ($cmd == ""){
74             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
75           } else {
76             exec ($cmd." ".$this->cn, $dummy, $retval);
77             if ($retval != 0){
78               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
79             }
80           }
81           break;
83         case 'halt':
84           $cmd= search_config($this->config->data['TABS'], "servgeneric", "HALTCMD");
85           if ($cmd == ""){
86             print_red(_("No HALTCMD definition found in your gosa.conf"));
87           } else {
88             exec ($cmd." ".$this->cn, $dummy, $retval);
89             if ($retval != 0){
90               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
91             }
92           }
93           break;
94       }
95     }
97     /* Fill templating stuff */
98     $smarty= get_smarty();
99     $smarty->assign("bases", $this->config->idepartments);
101     /* Assign attributes */
102     foreach ($this->attributes as $attr){
103       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
104       $smarty->assign("$attr", $this->$attr);
105     }
106     $smarty->assign("staticAddress", "");
107     $smarty->assign("base_select", $this->base);
109     /* Assign status */
110     $query= "fping -q -r 1 -t 500 ".$this->cn;
111     exec ($query, $dummy, $retval);
113     /* Offline */
114     if ($retval == 0){
115       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
116     } else {
117       $smarty->assign("actions", array("wake" => _("Wake up")));
118     }
121     /* Show main page */
122     $smarty->assign("netconfig", $this->netConfigDNS->execute());
124     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
125   }
127   function remove_from_parent()
128   {
129     $this->netConfigDNS->remove_from_parent();
130     $ldap= $this->config->get_ldap_link();
131     $ldap->rmdir($this->dn);
132     show_ldap_error($ldap->get_error());
134     /* Delete references to object groups */
135     $ldap->cd ($this->config->current['BASE']);
136     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
137     while ($ldap->fetch()){
138       $og= new ogroup($this->config, $ldap->getDN());
139       unset($og->member[$this->dn]);
140       $og->save ();
141     }
142     $this->handle_post_events("remove");
143   }
146   /* Save data to object */
147   function save_object()
148   {
149     plugin::save_object();
150     $this->netConfigDNS->save_object();
151     /* Save base, since this is no LDAP attribute */
152     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
153       $this->base= $_POST['base'];
154     }
155   }
158   /* Check supplied data */
159   function check()
160   {
161     $message= $this->netConfigDNS->check();
162     $this->dn= "cn=".$this->cn.",ou=servers,ou=systems,".$this->base;
164     /* must: cn */
165     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
166       $message[]= _("The required field 'Server name' is not set.");
167     }
169     $ui= get_userinfo();
170     $acl= get_permissions ($this->dn, $ui->subtreeACL);
171     $acl= get_module_permission($acl, "server", $this->dn);
172     if (chkacl($acl, "create") != ""){
173       $message[]= _("You have no permissions to create a server on this 'Base'.");
174     }
176     if ($this->orig_dn != $this->dn){
177       $ldap= $this->config->get_ldap_link();
178       $ldap->cd ($this->base);
179       $ldap->search ("(cn=".$this->cn.")", array("cn"));
180       if ($ldap->count() != 0){
181         while ($attrs= $ldap->fetch()){
182           if ($attrs['dn'] != $this->orig_dn){
183             if(!preg_match("/,ou=incoming,/",$attrs['dn'])){
184             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
185             break;
186             }
187           }
188         }
189       }
190     }
192     return ($message);
193   }
196   /* Save to LDAP */
197   function save()
198   {
199     plugin::save();
201     /* Remove all empty values */
202     if ($this->orig_dn == 'new'){
203       $attrs= array();
204       foreach ($this->attrs as $key => $val){
205         if (is_array($val) && count($val) == 0){
206           continue;
207         }
208         $attrs[$key]= $val;
209       }
210       $this->attrs= $attrs;
211     }
213     /* Write back to ldap */
214     $ldap= $this->config->get_ldap_link();
215     if ($this->orig_dn == 'new'){
216       $ldap->cd($this->config->current['BASE']);
217       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
218       $ldap->cd($this->dn);
219       $ldap->add($this->attrs);
220       $mode= "add";
221     } else {
222    
223       /* cn is not case sensitive for ldap, but for php it is!! */ 
224       if($this->config->current['DNMODE'] == "cn"){
225         if (strtolower($this->orig_dn) != (strtolower($this->dn))){
226           $this->move($this->orig_dn, $this->dn);
227           plugin::save();
228         }
229       }else{
230         if ($this->orig_dn != $this->dn){
231           $this->move($this->orig_dn, $this->dn);
232           plugin::save();
233         }
234       }
235   
236       $ldap->cd($this->dn);
237       $this->cleanup();
238 $ldap->modify ($this->attrs); 
240       $mode= "modify";
241     }
242     $this->netConfigDNS->cn = $this->cn;
243     $this->netConfigDNS->save($this->dn);
244     show_ldap_error($ldap->get_error());
246     /* Optionally execute a command after we're done */
247     $this->handle_post_events($mode);
248   }
252 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
253 ?>