Code

b9354649232ac667cb3511668fe58cd6ac8b8557
[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["sysinfo"]= _("System analysis");
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'], "workgeneric", "ACTIONCMD");
97       if ($cmd == ""){
98         print_red(_("No ACTIONCMD definition found in your gosa.conf"));
99       } else {
100         exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['saction']), $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                                        "reinstall" => _("Reinstall"),
131                                        "rescan" => _("Rescan hardware")));
132     } else {
133       $smarty->assign("actions", array("wake" => _("Wake up"),
134                                        "reinstall" => _("Reinstall"),
135                                        "update" => _("Scheduled update")));
136     }
137     /* Arrays */
138     $smarty->assign("modes", $this->modes);
139     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
140     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
141     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
143     /* Variables */
144     foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
145       $smarty->assign($val."_select", $this->$val);
146       $smarty->assign($val."ACL", chkacl($this->acl, $val));
147     }
148     $smarty->assign("ipHostNumber", $this->ipHostNumber);
149     $smarty->assign("macAddress", $this->macAddress);
150     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
152     /* Show main page */
153     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
154     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
155   }
157   function remove_from_parent()
158   {
159     $ldap= $this->config->get_ldap_link();
160     $ldap->rmdir($this->dn);
161     show_ldap_error($ldap->get_error());
163     /* Optionally execute a command after we're done */
164     $this->handle_post_events("remove");
166     /* Delete references to object groups */
167     $ldap->cd ($this->config->current['BASE']);
168     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
169     while ($ldap->fetch()){
170       $og= new ogroup($this->config, $ldap->getDN());
171       unset($og->member[$this->dn]);
172       $og->save ();
173     }
175   }
178   /* Save data to object */
179   function save_object()
180   {
181     plugin::save_object();
183     /* Save base, since this is no LDAP attribute */
184     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
185       $this->base= $_POST['base'];
186     }
187   }
190   /* Check supplied data */
191   function check()
192   {
193     $message= array();
195     $ui= get_userinfo();
196     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
197     $acl= get_permissions ($this->dn, $ui->subtreeACL);
198     $acl= get_module_permission($acl, "group", $this->dn);
199     if (chkacl($acl, "create") != ""){
200       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
201     }
203     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
204       $message[]= _("The required field 'Workstation name' is not set.");
205     }
207     if ($this->orig_dn != $this->dn){
208       $ldap= $this->config->get_ldap_link();
209       $ldap->cd ($this->base);
210       $ldap->search ("(cn=".$this->cn.")", array("cn"));
211       if ($ldap->count() != 0){
212         while ($attrs= $ldap->fetch()){
213           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
214             continue;
215           } else {
216             if ($attrs['dn'] != $this->orig_dn){
217               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
218               break;
219             }
220           }
221         }
222       }
223     }
225     return ($message);
226   }
229   /* Save to LDAP */
230   function save()
231   {
232     plugin::save();
234     /* Strip out 'default' values */
235     foreach (array("gotoSyslogServer") as $val){
237       if ($this->attrs[$val] == "default"){
238         $this->attrs[$val]= array();
239       }
240     }
242     /* Add missing arrays */
243     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
244       if (isset ($this->$val) && count ($this->$val) != 0){
245         $this->attrs["$val"]= $this->$val;
246       }
247     }
249     /* Remove all empty values */
250     if ($this->orig_dn == 'new'){
251       $attrs= array();
252       foreach ($this->attrs as $key => $val){
253         if (is_array($val) && count($val) == 0){
254           continue;
255         }
256         $attrs[$key]= $val;
257       }
258       $this->attrs= $attrs;
259     }
261     /* Write back to ldap */
262     $ldap= $this->config->get_ldap_link();
263     if ($this->orig_dn == 'new'){
264       $ldap->cd($this->config->current['BASE']);
265       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
266       $ldap->cd($this->dn);
267       $ldap->add($this->attrs);
268       $this->handle_post_events("add");
269     } else {
270       if ($this->orig_dn != $this->dn){
271         $this->move($this->orig_dn, $this->dn);
272       }
273       $ldap->cd($this->dn);
274       $ldap->modify($this->attrs);
275       $this->handle_post_events("modify");
276     }
277     show_ldap_error($ldap->get_error());
279     /* Optionally execute a command after we're done */
280     $this->postcreate();
281   }
285 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
286 ?>