Code

added alt tag ....
[gosa.git] / plugins / admin / systems / class_workstationGeneric.inc
1 <?php
3 class workgeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage workstation 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 $gotoMode= "disabled";
12   var $gotoTerminalPath= "";
13   var $gotoSwapServer= "";
14   var $gotoSyslogServer= "";
15   var $gotoNtpServer= "";
16   var $gotoSndModule= "";
17   var $gotoFloppyEnable= "";
18   var $gotoCdromEnable= "";
19   var $ghCpuType= "-";
20   var $ghMemSize= "-";
21   var $macAddress= "";
22   var $ipHostNumber= "";
23   var $ghUsbSupport= "-";
24   var $ghNetNic= array();
25   var $ghIdeDev= array();
26   var $ghScsiDev= array();
27   var $ghGfxAdapter= "-";
28   var $ghSoundAdapter= "-";
29   var $gotoLastUser= "-";
32   /* Needed values and lists */
33   var $base= "";
34   var $cn= "";
35   var $orig_dn= "";
37   /* Plugin side filled */
38   var $modes= array();
40   /* attribute list for save action */
41   var $attributes= array("gotoMode", "gotoTerminalPath", "macAddress",
42       "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
43       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
44       "ghCpuType", "ghMemSize", "ghUsbSupport", "ipHostNumber",
45       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
46   var $objectclasses= array("top", "gotoWorkstation", "GOhard");
48   function workgeneric ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
52     /* Load available modes */
53     $ldap= $this->config->get_ldap_link();
54     $ldap->cd ($this->config->current['BASE']);
55     $ldap->search ("(objectClass=gotoInstallProfile)");
56     while ($attrs= $ldap->fetch()){
57       $this->modes[]= $attrs["cn"][0];
58     }
60     /* Read arrays */
61     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
62       if (!isset($this->attrs[$val])){
63         continue;
64       }
65       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
66         array_push($this->$val, $this->attrs[$val][$i]);
67       }
68     }
70     $this->modes["disabled"]= _("disabled");
71     $this->modes["text"]= _("text");
72     $this->modes["graphic"]= _("graphic");
74     /* Set base */
75     if ($this->dn == "new"){
76       $ui= get_userinfo();
77       $this->base= dn2base($ui->dn);
78     } else {
79       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
80     }
82     /* Save 'dn' for later referal */
83     $this->orig_dn= $this->dn;
84   }
86   function execute()
87   {
88     /* Do we need to flip is_account state? */
89     if (isset($_POST['modify_state'])){
90       $this->is_account= !$this->is_account;
91     }
93     if (isset($_POST['action'])){
94       switch($_POST['saction']){
95         case 'wake':
96           $cmd= $this->search($this->config->data['TABS'], "terminfo", "WAKECMD");
97           if ($cmd == ""){
98             print_red(_("No WAKECMD definition found in your gosa.conf"));
99           } else {
100             exec ($cmd." ".$this->macAddress, $dummy, $retval);
101             if ($retval != 0){
102               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
103             }
104           }
105           break;
107         case 'reboot':
108           $cmd= $this->search($this->config->data['TABS'], "terminfo", "REBOOTCMD");
109           if ($cmd == ""){
110             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
111           } else {
112             exec ($cmd." ".$this->cn, $dummy, $retval);
113             if ($retval != 0){
114               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
115             }
116           }
117           break;
119         case 'halt':
120           $cmd= $this->search($this->config->data['TABS'], "terminfo", "HALTCMD");
121           if ($cmd == ""){
122             print_red(_("No HALTCMD definition found in your gosa.conf"));
123           } else {
124             exec ($cmd." ".$this->cn, $dummy, $retval);
125             if ($retval != 0){
126               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
127             }
128           }
129           break;
130       }
131     }
133     /* Do we represent a valid terminal? */
134     if (!$this->is_account && $this->parent == NULL){
135       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
136         _("This 'dn' has no workstation features.")."</b>";
137       return($display);
138     }
140     /* Fill templating stuff */
141     $smarty= get_smarty();
142     $smarty->assign("cn", $this->cn);
143     $smarty->assign("bases", $this->config->idepartments);
145     /* Check if workstation is online */
146     $query= "fping -q -r 1 -t 500 ".$this->cn;
147     exec ($query, $dummy, $retval);
149     /* Offline */
150     if ($retval == 0){
151       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
152     } else {
153       $smarty->assign("actions", array("wake" => _("Wake up")));
154     }
155     /* Arrays */
156     $smarty->assign("modes", $this->modes);
157     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
158     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
159     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
161     /* Variables */
162     foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
163           "gotoSyslogServer", "gotoNtpServer") as $val){
165       $smarty->assign($val."_select", $this->$val);
166       $smarty->assign($val."ACL", chkacl($this->acl, $val));
167     }
168     $smarty->assign("ipHostNumber", $this->ipHostNumber);
169     $smarty->assign("macAddress", $this->macAddress);
170     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
172     /* Show main page */
173     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
174     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
175   }
177   function remove_from_parent()
178   {
179     $ldap= $this->config->get_ldap_link();
180     $ldap->rmdir($this->dn);
181     show_ldap_error($ldap->get_error());
183     /* Optionally execute a command after we're done */
184     $this->handle_post_events("remove");
186     /* Delete references to object groups */
187     $ldap->cd ($this->config->current['BASE']);
188     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
189     while ($ldap->fetch()){
190       $og= new ogroup($this->config, $ldap->getDN());
191       unset($og->member[$this->dn]);
192       $og->save ();
193     }
195   }
198   /* Save data to object */
199   function save_object()
200   {
201     plugin::save_object();
203     /* Save base, since this is no LDAP attribute */
204     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
205       $this->base= $_POST['base'];
206     }
208     /* Save terminal path to parent since it is used by termstartup, too */
209     $this->parent->by_object['termstartup']->gotoTerminalPath=
210       $this->gotoTerminalPath;
211   }
214   /* Check supplied data */
215   function check()
216   {
217     $message= array();
219     $ui= get_userinfo();
220     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
221     $acl= get_permissions ($this->dn, $ui->subtreeACL);
222     $acl= get_module_permission($acl, "group", $this->dn);
223     if (chkacl($acl, "create") != ""){
224       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
225     }
227     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
228       $message[]= _("The required field 'Workstation name' is not set.");
229     }
231     if ($this->orig_dn != $this->dn){
232       $ldap= $this->config->get_ldap_link();
233       $ldap->cd ($this->base);
234       $ldap->search ("(cn=".$this->cn.")", array("cn"));
235       if ($ldap->count() != 0){
236         while ($attrs= $ldap->fetch()){
237           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
238             continue;
239           } else {
240             if ($attrs['dn'] != $this->orig_dn){
241               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
242               break;
243             }
244           }
245         }
246       }
247     }
249     return ($message);
250   }
253   /* Save to LDAP */
254   function save()
255   {
256     plugin::save();
258     /* Strip out 'default' values */
259     foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){
261       if ($this->attrs[$val] == "default"){
262         $this->attrs[$val]= array();
263       }
264     }
266     /* Add missing arrays */
267     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
268       if (isset ($this->$val) && count ($this->$val) != 0){
269         $this->attrs["$val"]= $this->$val;
270       }
271     }
273     /* Remove all empty values */
274     if ($this->orig_dn == 'new'){
275       $attrs= array();
276       foreach ($this->attrs as $key => $val){
277         if (is_array($val) && count($val) == 0){
278           continue;
279         }
280         $attrs[$key]= $val;
281       }
282       $this->attrs= $attrs;
283     }
285     /* Write back to ldap */
286     $ldap= $this->config->get_ldap_link();
287     if ($this->orig_dn == 'new'){
288       $ldap->cd($this->config->current['BASE']);
289       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
290       $ldap->cd($this->dn);
291       $ldap->add($this->attrs);
292       $this->handle_post_events("add");
293     } else {
294       if ($this->orig_dn != $this->dn){
295         $this->move($this->orig_dn, $this->dn);
296       }
297       $ldap->cd($this->dn);
298       $ldap->modify($this->attrs);
299       $this->handle_post_events("modify");
300     }
301     show_ldap_error($ldap->get_error());
303     /* Optionally execute a command after we're done */
304     $this->postcreate();
305   }
309 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
310 ?>