Code

Added recovery
[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");
71     $this->modes["recovery"]= _("Recovery");
73     /* Set base */
74     if ($this->dn == "new"){
75       $ui= get_userinfo();
76       $this->base= dn2base($ui->dn);
77     } else {
78       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
79     }
81     /* Save 'dn' for later referal */
82     $this->orig_dn= $this->dn;
83   }
85   function execute()
86   {
87         /* Call parent execute */
88         plugin::execute();
90     /* Do we need to flip is_account state? */
91     if (isset($_POST['modify_state'])){
92       $this->is_account= !$this->is_account;
93     }
95     if (isset($_POST['action'])){
96       $cmd= search_config($this->config->data['TABS'], "terminfo", "ACTIONCMD");
97       if ($cmd == ""){
98         print_red(_("No ACTIONCMD definition found in your gosa.conf"));
99       } else {
100         exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['action']), $dummy, $retval);
101         if ($retval != 0){
102           print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
103         }
104       }
105     }
107     /* Do we represent a valid terminal? */
108     if (!$this->is_account && $this->parent == NULL){
109       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
110         _("This 'dn' has no workstation features.")."</b>";
111       return($display);
112     }
114     /* Fill templating stuff */
115     $smarty= get_smarty();
116     $smarty->assign("cn", $this->cn);
117     $smarty->assign("l", $this->l);
118     $smarty->assign("bases", $this->config->idepartments);
119     $smarty->assign("staticAddress", "");
120         
121     /* Check if workstation is online */
122     $query= "fping -q -r 1 -t 500 ".$this->cn;
123     exec ($query, $dummy, $retval);
125     /* Offline */
126     if ($retval == 0){
127       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
128                                        "instant_update" => _("Instant update"),
129                                        "update" => _("Scheduled update"),
130                                        "update" => _("Reinstall"),
131                                        "rescan" => _("Rescan hardware")));
132     } else {
133       $smarty->assign("actions", array("wake" => _("Wake up"),
134                                        "update" => _("Scheduled update")));
135     }
136     /* Arrays */
137     $smarty->assign("modes", $this->modes);
138     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
139     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
140     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
142     /* Variables */
143     foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
144       $smarty->assign($val."_select", $this->$val);
145       $smarty->assign($val."ACL", chkacl($this->acl, $val));
146     }
147     $smarty->assign("ipHostNumber", $this->ipHostNumber);
148     $smarty->assign("macAddress", $this->macAddress);
149     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
151     /* Show main page */
152     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
153     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
154   }
156   function remove_from_parent()
157   {
158     $ldap= $this->config->get_ldap_link();
159     $ldap->rmdir($this->dn);
160     show_ldap_error($ldap->get_error());
162     /* Optionally execute a command after we're done */
163     $this->handle_post_events("remove");
165     /* Delete references to object groups */
166     $ldap->cd ($this->config->current['BASE']);
167     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
168     while ($ldap->fetch()){
169       $og= new ogroup($this->config, $ldap->getDN());
170       unset($og->member[$this->dn]);
171       $og->save ();
172     }
174   }
177   /* Save data to object */
178   function save_object()
179   {
180     plugin::save_object();
182     /* Save base, since this is no LDAP attribute */
183     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
184       $this->base= $_POST['base'];
185     }
186   }
189   /* Check supplied data */
190   function check()
191   {
192     $message= array();
194     $ui= get_userinfo();
195     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
196     $acl= get_permissions ($this->dn, $ui->subtreeACL);
197     $acl= get_module_permission($acl, "group", $this->dn);
198     if (chkacl($acl, "create") != ""){
199       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
200     }
202     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
203       $message[]= _("The required field 'Workstation name' is not set.");
204     }
206     if ($this->orig_dn != $this->dn){
207       $ldap= $this->config->get_ldap_link();
208       $ldap->cd ($this->base);
209       $ldap->search ("(cn=".$this->cn.")", array("cn"));
210       if ($ldap->count() != 0){
211         while ($attrs= $ldap->fetch()){
212           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
213             continue;
214           } else {
215             if ($attrs['dn'] != $this->orig_dn){
216               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
217               break;
218             }
219           }
220         }
221       }
222     }
224     return ($message);
225   }
228   /* Save to LDAP */
229   function save()
230   {
231     plugin::save();
233     /* Strip out 'default' values */
234     foreach (array("gotoSyslogServer") as $val){
236       if ($this->attrs[$val] == "default"){
237         $this->attrs[$val]= array();
238       }
239     }
241     /* Add missing arrays */
242     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
243       if (isset ($this->$val) && count ($this->$val) != 0){
244         $this->attrs["$val"]= $this->$val;
245       }
246     }
248     /* Remove all empty values */
249     if ($this->orig_dn == 'new'){
250       $attrs= array();
251       foreach ($this->attrs as $key => $val){
252         if (is_array($val) && count($val) == 0){
253           continue;
254         }
255         $attrs[$key]= $val;
256       }
257       $this->attrs= $attrs;
258     }
260     /* Write back to ldap */
261     $ldap= $this->config->get_ldap_link();
262     if ($this->orig_dn == 'new'){
263       $ldap->cd($this->config->current['BASE']);
264       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
265       $ldap->cd($this->dn);
266       $ldap->add($this->attrs);
267       $this->handle_post_events("add");
268     } else {
269       if ($this->orig_dn != $this->dn){
270         $this->move($this->orig_dn, $this->dn);
271       }
272       $ldap->cd($this->dn);
273       $ldap->modify($this->attrs);
274       $this->handle_post_events("modify");
275     }
276     show_ldap_error($ldap->get_error());
278     /* Optionally execute a command after we're done */
279     $this->postcreate();
280   }
284 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
285 ?>