Code

Reverted to original _select. Seems to be a bug in the goto setup scripts...
[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= "locked";
12   var $gotoSyslogServer= "";
13   var $gotoNtpServer= "";
14   var $gotoSndModule= "";
15   var $gotoFloppyEnable= "";
16   var $gotoCdromEnable= "";
17   var $ghCpuType= "-";
18   var $ghMemSize= "-";
19   var $macAddress= "";
20   var $ipHostNumber= "";
21   var $ghUsbSupport= "-";
22   var $ghNetNic= array();
23   var $ghIdeDev= array();
24   var $ghScsiDev= array();
25   var $ghGfxAdapter= "-";
26   var $ghSoundAdapter= "-";
27   var $gotoLastUser= "-";
29   /* Needed values and lists */
30   var $base= "";
31   var $cn= "";
32   var $l= "";
33   var $orig_dn= "";
35   /* Plugin side filled */
36   var $modes= array();
38   /* attribute list for save action */
39   var $ignore_account= TRUE;
40   var $attributes= array("gotoMode", "macAddress", "gotoSyslogServer", "gotoNtpServer",
41       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
42       "ghCpuType", "ghMemSize", "ghUsbSupport", "ipHostNumber",
43       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l");
44   var $objectclasses= array("top", "gotoWorkstation", "GOhard");
46   function workgeneric ($config, $dn= NULL)
47   {
48     plugin::plugin ($config, $dn);
50     /* Load available modes */
51     $ldap= $this->config->get_ldap_link();
52     $ldap->cd ($this->config->current['BASE']);
53     $ldap->search ("(objectClass=gotoInstallProfile)");
54     while ($attrs= $ldap->fetch()){
55       $this->modes[]= $attrs["cn"][0];
56     }
58     /* Read arrays */
59     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
60       if (!isset($this->attrs[$val])){
61         continue;
62       }
63       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
64         array_push($this->$val, $this->attrs[$val][$i]);
65       }
66     }
68     $this->modes["active"]= _("Activated");
69     $this->modes["locked"]= _("Locked");
70     $this->modes["memcheck"]= _("Memory test");
72     /* Set base */
73     if ($this->dn == "new"){
74       $ui= get_userinfo();
75       $this->base= dn2base($ui->dn);
76     } else {
77       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
78     }
80     /* Save 'dn' for later referal */
81     $this->orig_dn= $this->dn;
82   }
84   function execute()
85   {
86     /* Do we need to flip is_account state? */
87     if (isset($_POST['modify_state'])){
88       $this->is_account= !$this->is_account;
89     }
91     if (isset($_POST['action'])){
92       $cmd= search_config($this->config->data['TABS'], "terminfo", "ACTIONCMD");
93       if ($cmd == ""){
94         print_red(_("No ACTIONCMD definition found in your gosa.conf"));
95       } else {
96         exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['action']), $dummy, $retval);
97         if ($retval != 0){
98           print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
99         }
100       }
101     }
103     /* Do we represent a valid terminal? */
104     if (!$this->is_account && $this->parent == NULL){
105       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
106         _("This 'dn' has no workstation features.")."</b>";
107       return($display);
108     }
110     /* Fill templating stuff */
111     $smarty= get_smarty();
112     $smarty->assign("cn", $this->cn);
113     $smarty->assign("l", $this->l);
114     $smarty->assign("bases", $this->config->idepartments);
115     $smarty->assign("staticAddress", "");
116         
117     /* Check if workstation is online */
118     $query= "fping -q -r 1 -t 500 ".$this->cn;
119     exec ($query, $dummy, $retval);
121     /* Offline */
122     if ($retval == 0){
123       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
124                                        "instant_update" => _("Instant update"),
125                                        "update" => _("Scheduled update"),
126                                        "rescan" => _("Rescan hardware")));
127     } else {
128       $smarty->assign("actions", array("wake" => _("Wake up"),
129                                        "update" => _("Scheduled update")));
130     }
131     /* Arrays */
132     $smarty->assign("modes", $this->modes);
133     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
134     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
135     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
137     /* Variables */
138     foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
139       $smarty->assign($val."_select", $this->$val);
140       $smarty->assign($val."ACL", chkacl($this->acl, $val));
141     }
142     $smarty->assign("ipHostNumber", $this->ipHostNumber);
143     $smarty->assign("macAddress", $this->macAddress);
144     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
146     /* Show main page */
147     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
148     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
149   }
151   function remove_from_parent()
152   {
153     $ldap= $this->config->get_ldap_link();
154     $ldap->rmdir($this->dn);
155     show_ldap_error($ldap->get_error());
157     /* Optionally execute a command after we're done */
158     $this->handle_post_events("remove");
160     /* Delete references to object groups */
161     $ldap->cd ($this->config->current['BASE']);
162     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
163     while ($ldap->fetch()){
164       $og= new ogroup($this->config, $ldap->getDN());
165       unset($og->member[$this->dn]);
166       $og->save ();
167     }
169   }
172   /* Save data to object */
173   function save_object()
174   {
175     plugin::save_object();
177     /* Save base, since this is no LDAP attribute */
178     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
179       $this->base= $_POST['base'];
180     }
181   }
184   /* Check supplied data */
185   function check()
186   {
187     $message= array();
189     $ui= get_userinfo();
190     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
191     $acl= get_permissions ($this->dn, $ui->subtreeACL);
192     $acl= get_module_permission($acl, "group", $this->dn);
193     if (chkacl($acl, "create") != ""){
194       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
195     }
197     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
198       $message[]= _("The required field 'Workstation name' is not set.");
199     }
201     if ($this->orig_dn != $this->dn){
202       $ldap= $this->config->get_ldap_link();
203       $ldap->cd ($this->base);
204       $ldap->search ("(cn=".$this->cn.")", array("cn"));
205       if ($ldap->count() != 0){
206         while ($attrs= $ldap->fetch()){
207           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
208             continue;
209           } else {
210             if ($attrs['dn'] != $this->orig_dn){
211               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
212               break;
213             }
214           }
215         }
216       }
217     }
219     return ($message);
220   }
223   /* Save to LDAP */
224   function save()
225   {
226     plugin::save();
228     /* Strip out 'default' values */
229     foreach (array("gotoSyslogServer") as $val){
231       if ($this->attrs[$val] == "default"){
232         $this->attrs[$val]= array();
233       }
234     }
236     /* Add missing arrays */
237     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
238       if (isset ($this->$val) && count ($this->$val) != 0){
239         $this->attrs["$val"]= $this->$val;
240       }
241     }
243     /* Remove all empty values */
244     if ($this->orig_dn == 'new'){
245       $attrs= array();
246       foreach ($this->attrs as $key => $val){
247         if (is_array($val) && count($val) == 0){
248           continue;
249         }
250         $attrs[$key]= $val;
251       }
252       $this->attrs= $attrs;
253     }
255     /* Write back to ldap */
256     $ldap= $this->config->get_ldap_link();
257     if ($this->orig_dn == 'new'){
258       $ldap->cd($this->config->current['BASE']);
259       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
260       $ldap->cd($this->dn);
261       $ldap->add($this->attrs);
262       $this->handle_post_events("add");
263     } else {
264       if ($this->orig_dn != $this->dn){
265         $this->move($this->orig_dn, $this->dn);
266       }
267       $ldap->cd($this->dn);
268       $ldap->modify($this->attrs);
269       $this->handle_post_events("modify");
270     }
271     show_ldap_error($ldap->get_error());
273     /* Optionally execute a command after we're done */
274     $this->postcreate();
275   }
279 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
280 ?>