Code

Removed unused attribute
[gosa.git] / plugins / admin / 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 $macAddress= "";
19   var $ipHostNumber= "";
20   var $description= "";
21   var $orig_dn= "";
23   /* attribute list for save action */
24   var $attributes= array("cn", "description", "macAddress", "ipHostNumber");
25   var $objectclasses= array("top", "goServer");
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     }
40     /* Save dn for later references */
41     $this->orig_dn= $this->dn;
42   }
44   function execute()
45   {
46     /* Do we represent a valid server? */
47     if (!$this->is_account && $this->parent == NULL){
48       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
49         _("This 'dn' has no server features.")."</b>";
50       return($display);
51     }
53     /* Check for action */
54     if (isset($_POST['action'])){
55       switch($_POST['action']){
56         case 'wake':
57           $cmd= $this->search($this->config->data['TABS'], "servgeneric", "WAKECMD");
58           if ($cmd == ""){
59             print_red(_("No WAKECMD definition found in your gosa.conf"));
60           } else {
61             exec ($cmd." ".$this->macAddress, $dummy, $retval);
62             if ($retval != 0){
63               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
64             }
65           }
66           break;
68         case 'reboot':
69           $cmd= $this->search($this->config->data['TABS'], "servgeneric", "REBOOTCMD");
70           if ($cmd == ""){
71             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
72           } else {
73             exec ($cmd." ".$this->cn, $dummy, $retval);
74             if ($retval != 0){
75               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
76             }
77           }
78           break;
80         case 'halt':
81           $cmd= $this->search($this->config->data['TABS'], "servgeneric", "HALTCMD");
82           if ($cmd == ""){
83             print_red(_("No HALTCMD definition found in your gosa.conf"));
84           } else {
85             exec ($cmd." ".$this->cn, $dummy, $retval);
86             if ($retval != 0){
87               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
88             }
89           }
90           break;
91       }
92     }
94     /* Fill templating stuff */
95     $smarty= get_smarty();
96     $smarty->assign("bases", $this->config->idepartments);
98     /* Assign attributes */
99     foreach ($this->attributes as $attr){
100       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
101       $smarty->assign("$attr", $this->$attr);
102     }
103     $smarty->assign("staticAddress", "");
104     $smarty->assign("base_select", $this->base);
106     /* Assign status */
107     $query= "fping -q -r 1 -t 500 ".$this->cn;
108     exec ($query, $dummy, $retval);
110     /* Offline */
111     if ($retval == 0){
112       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
113     } else {
114       $smarty->assign("actions", array("wake" => _("Wake up")));
115     }
118     /* Show main page */
119     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
121     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
122   }
124   function remove_from_parent()
125   {
126     $ldap= $this->config->get_ldap_link();
127     $ldap->rmdir($this->dn);
128     show_ldap_error($ldap->get_error());
130     /* Delete references to object groups */
131     $ldap->cd ($this->config->current['BASE']);
132     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
133     while ($ldap->fetch()){
134       $og= new ogroup($this->config, $ldap->getDN());
135       unset($og->member[$this->dn]);
136       $og->save ();
137     }
139     $this->handle_post_events("remove");
140   }
143   /* Save data to object */
144   function save_object()
145   {
146     plugin::save_object();
148     /* Save base, since this is no LDAP attribute */
149     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
150       $this->base= $_POST['base'];
151     }
152   }
155   /* Check supplied data */
156   function check()
157   {
158     $message= array();
159     $this->dn= "cn=".$this->cn.",ou=servers,ou=systems,".$this->base;
161     /* must: cn */
162     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
163       $message[]= _("The required field 'Server name' is not set.");
164     }
166     $ui= get_userinfo();
167     $acl= get_permissions ($this->dn, $ui->subtreeACL);
168     $acl= get_module_permission($acl, "server", $this->dn);
169     if (chkacl($acl, "create") != ""){
170       $message[]= _("You have no permissions to create a server on this 'Base'.");
171     }
173     if ($this->orig_dn != $this->dn){
174       $ldap= $this->config->get_ldap_link();
175       $ldap->cd ($this->base);
176       $ldap->search ("(cn=".$this->cn.")", array("cn"));
177       if ($ldap->count() != 0){
178         while ($attrs= $ldap->fetch()){
179           if ($attrs['dn'] != $this->orig_dn){
180             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
181             break;
182           }
183         }
184       }
185     }
187     return ($message);
188   }
191   /* Save to LDAP */
192   function save()
193   {
194     plugin::save();
196     /* Remove all empty values */
197     if ($this->orig_dn == 'new'){
198       $attrs= array();
199       foreach ($this->attrs as $key => $val){
200         if (is_array($val) && count($val) == 0){
201           continue;
202         }
203         $attrs[$key]= $val;
204       }
205       $this->attrs= $attrs;
206     }
208     /* Write back to ldap */
209     $ldap= $this->config->get_ldap_link();
210     if ($this->orig_dn == 'new'){
211       $ldap->cd($this->config->current['BASE']);
212       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
213       $ldap->cd($this->dn);
214       $ldap->add($this->attrs);
215       $mode= "add";
216     } else {
217       if ($this->orig_dn != $this->dn){
218         $this->move($this->orig_dn, $this->dn);
219       }
221       $ldap->cd($this->dn);
222       $ldap->modify($this->attrs);
223       $mode= "modify";
224     }
225     show_ldap_error($ldap->get_error());
227     /* Optionally execute a command after we're done */
228     $this->handle_post_events($mode);
229   }
233 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
234 ?>