Code

Updated locales
[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   var $didAction= FALSE;
31   /* Needed values and lists */
32   var $base= "";
33   var $cn= "";
34   var $l= "";
35   var $orig_dn= "";
37   /* Plugin side filled */
38   var $modes= array();
40   /* attribute list for save action */
41   var $ignore_account= TRUE;
42   var $attributes= array("gotoMode", "macAddress", "gotoSyslogServer", "gotoNtpServer",
43       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
44       "ghCpuType", "ghMemSize", "ghUsbSupport", "ipHostNumber",
45       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l");
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["active"]= _("Activated");
71     $this->modes["locked"]= _("Locked");
72     $this->modes["memcheck"]= _("Memory test");
73     $this->modes["sysinfo"]= _("System analysis");
75     /* Set base */
76     if ($this->dn == "new"){
77       $ui= get_userinfo();
78       $this->base= dn2base($ui->dn);
79     } else {
80       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
81     }
83     /* Save 'dn' for later referal */
84     $this->orig_dn= $this->dn;
85   }
87   function execute()
88   {
89         /* Call parent execute */
90         plugin::execute();
92     /* Do we need to flip is_account state? */
93     if (isset($_POST['modify_state'])){
94       $this->is_account= !$this->is_account;
95     }
97     if (isset($_POST['action'])){
98       $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
99       if ($cmd == ""){
100         print_red(_("No ACTIONCMD definition found in your gosa.conf"));
101       } else {
102         exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['saction']), $dummy, $retval);
103         if ($retval != 0){
104           print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
105         } else {
106           $this->didAction= TRUE;
107         }
108       }
109     }
111     /* Do we represent a valid terminal? */
112     if (!$this->is_account && $this->parent == NULL){
113       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
114         _("This 'dn' has no workstation features.")."</b>";
115       return($display);
116     }
118     /* Fill templating stuff */
119     $smarty= get_smarty();
120     $smarty->assign("cn", $this->cn);
121     $smarty->assign("l", $this->l);
122     $smarty->assign("bases", $this->config->idepartments);
123     $smarty->assign("staticAddress", "");
124         
125     /* Check if workstation is online */
126     $query= "fping -q -r 1 -t 500 ".$this->cn;
127     exec ($query, $dummy, $retval);
129     /* Offline */
130     if ($retval == 0){
131       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
132                                        "instant_update" => _("Instant update"),
133                                        "update" => _("Scheduled update"),
134                                        "reinstall" => _("Reinstall"),
135                                        "rescan" => _("Rescan hardware")));
136     } else {
137       $smarty->assign("actions", array("wake" => _("Wake up"),
138                                        "reinstall" => _("Reinstall"),
139                                        "update" => _("Scheduled update")));
140     }
141     /* Arrays */
142     $smarty->assign("modes", $this->modes);
143     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
144     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
145     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
147     /* Variables */
148     foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
149       $smarty->assign($val."_select", $this->$val);
150       $smarty->assign($val."ACL", chkacl($this->acl, $val));
151     }
152     $smarty->assign("ipHostNumber", $this->ipHostNumber);
153     $smarty->assign("macAddress", $this->macAddress);
154     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
156     /* Show main page */
157     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
158     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
159   }
161   function remove_from_parent()
162   {
163     $ldap= $this->config->get_ldap_link();
164     $ldap->rmdir($this->dn);
165     show_ldap_error($ldap->get_error());
167     /* Optionally execute a command after we're done */
168     $this->handle_post_events("remove");
170     /* Delete references to object groups */
171     $ldap->cd ($this->config->current['BASE']);
172     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
173     while ($ldap->fetch()){
174       $og= new ogroup($this->config, $ldap->getDN());
175       unset($og->member[$this->dn]);
176       $og->save ();
177     }
179   }
182   /* Save data to object */
183   function save_object()
184   {
185     plugin::save_object();
187     /* Save base, since this is no LDAP attribute */
188     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
189       $this->base= $_POST['base'];
190     }
191   }
194   /* Check supplied data */
195   function check()
196   {
197     $message= array();
199     $ui= get_userinfo();
200     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
201     $acl= get_permissions ($this->dn, $ui->subtreeACL);
202     $acl= get_module_permission($acl, "group", $this->dn);
203     if (chkacl($acl, "create") != ""){
204       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
205     }
207     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
208       $message[]= _("The required field 'Workstation name' is not set.");
209     }
211     if ($this->orig_dn != $this->dn){
212       $ldap= $this->config->get_ldap_link();
213       $ldap->cd ($this->base);
214       $ldap->search ("(cn=".$this->cn.")", array("cn"));
215       if ($ldap->count() != 0){
216         while ($attrs= $ldap->fetch()){
217           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
218             continue;
219           } else {
220             if ($attrs['dn'] != $this->orig_dn){
221               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
222               break;
223             }
224           }
225         }
226       }
227     }
229     return ($message);
230   }
233   /* Save to LDAP */
234   function save()
235   {
236     plugin::save();
238     /* Strip out 'default' values */
239     foreach (array("gotoSyslogServer") as $val){
241       if ($this->attrs[$val] == "default"){
242         $this->attrs[$val]= array();
243       }
244     }
246     /* Add missing arrays */
247     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
248       if (isset ($this->$val) && count ($this->$val) != 0){
249         $this->attrs["$val"]= $this->$val;
250       }
251     }
253     /* Remove all empty values */
254     if ($this->orig_dn == 'new'){
255       $attrs= array();
256       foreach ($this->attrs as $key => $val){
257         if (is_array($val) && count($val) == 0){
258           continue;
259         }
260         $attrs[$key]= $val;
261       }
262       $this->attrs= $attrs;
263     }
265     /* Write back to ldap */
266     $ldap= $this->config->get_ldap_link();
267     if ($this->orig_dn == 'new'){
268       $ldap->cd($this->config->current['BASE']);
269       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
270       $ldap->cd($this->dn);
271       $ldap->add($this->attrs);
272       if(!$this->didAction){
273         $this->handle_post_events("add");
274       }
275     } else {
276       if ($this->orig_dn != $this->dn){
277         $this->move($this->orig_dn, $this->dn);
278       }
279       $ldap->cd($this->dn);
280       $ldap->modify($this->attrs);
281       if(!$this->didAction){
282         $this->handle_post_events("modify");
283       }
284     }
285     show_ldap_error($ldap->get_error());
287     /* Optionally execute a command after we're done */
288     $this->postcreate();
289   }
293 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
294 ?>