Code

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