Code

Backport from trunk
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationGeneric.inc
1 <?php
3 class workgeneric extends plugin
4 {
5     /* Generic terminal attributes */
6     var $gotoMode= "locked";
7     var $initial_gotoMode= "locked";
8     var $gotoSyslogServer= "";
9     var $gotoSyslogServers= array();
10     var $gotoNtpServer= array();
11     var $gotoNtpServers= array();
12     var $gotoSndModule= "";
13     var $gotoFloppyEnable= "";
14     var $gotoCdromEnable= "";
15     var $description= "";
16     var $ghCpuType= "-";
17     var $ghMemSize= "-";
18     var $ghUsbSupport= "-";
19     var $ghNetNic= array();
20     var $ghIdeDev= array();
21     var $ghScsiDev= array();
22     var $ghGfxAdapter= "-";
23     var $ghSoundAdapter= "-";
24     var $gotoLastUser= "-";
25     var $FAIscript= "";
26     var $view_logged = FALSE;
27     var $auto_activate= FALSE;
29     /* Needed values and lists */
30     var $base= "";
31     var $cn= "";
32     var $l= "";
33     var $orig_dn= "";
34     var $orig_cn= "";
35     var $orig_base= "";
37     /* Plugin side filled */
38     var $modes= array();
40     var $netConfigDNS;
41     var $baseSelector;
43     var $inheritTimeServer = true;
45     /* attribute list for save action */
46     var $ignore_account= TRUE;
47     var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer",
48             "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
49             "ghCpuType", "ghMemSize", "ghUsbSupport", "description",
50             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript");
51     var $objectclasses= array("top", "gotoWorkstation", "GOhard");
53     var $validActions   = array("reboot" => "", "localboot" => "", "halt" => "", "update" => "", "reinstall" => "",
54             "rescan" => "", "wakeup" => "", "memcheck" => "", "sysinfo" => "");
56     var $fai_activated = FALSE;
58     var $member_of_ogroup = FALSE;
60     var $currently_installing = FALSE;
61     var $currently_installing_warned = FALSE;
63     var $kerberos_key_service = NULL;
65     function workgeneric (&$config, $dn= NULL, $parent= NULL)
66     {
67         $this->fai_activated = $config->pluginEnabled("faiManagement");
69         plugin::plugin ($config, $dn, $parent);
71         if(class_available("krbHostKeys")){
72             $this->kerberos_key_service = new krbHostKeys($this->config,$this);
73         }
75         if(!isset($this->parent->by_object['ogroup'])){
76             $ldap = $this->config->get_ldap_link();
77             $ldap->cd ($this->config->current['BASE']);
78             $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn"));
79             $this->member_of_ogroup = $ldap->count() >= 1;
80         }
82         $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
83         $this->netConfigDNS->MACisMust =TRUE;
85         /* Check if this host is currently in installation process*/
86         if(class_available("gosaSupportDaemon") && class_available("DaemonEvent")){
87             $o = new gosaSupportDaemon();
88             $e_types = DaemonEvent::get_event_types(USER_EVENT | SYSTEM_EVENT | HIDDEN_EVENT);
89             $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress));
90             foreach($evts as $evt){
91                 if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" &&
92                         $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){
93                     $this->currently_installing =TRUE;
94                 }
95             }
96         }
98         /* Read arrays */
99         foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
100             if (!isset($this->attrs[$val])){
101                 continue;
102             }
103             for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
104                 array_push($this->$val, $this->attrs[$val][$i]);
105             }
106         }
108         /* Create used ntp server array */
109         $this->gotoNtpServer= array();
110         if(isset($this->attrs['gotoNtpServer'])){
111             $this->inheritTimeServer = false;
112             unset($this->attrs['gotoNtpServer']['count']);
113             foreach($this->attrs['gotoNtpServer'] as $server){
114                 $this->gotoNtpServer[$server] = $server;
115             }
116         }
118         /* Set inherit checkbox state */
119         if((in_array_strict("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer) == 0)){
120             $this->inheritTimeServer = true;
121             $this->gotoNtpServer=array();
122         }
124         /* You can't inherit the NTP service, if we are not member in an object group */
125         if(!$this->member_of_ogroup){
126             $this->inheritTimeServer = FALSE;
127         }
129         /* Create available ntp options */
130         $tmp = $this->config->data['SERVERS']['NTP'];
131         $this->gotoNtpServers = array();
132         foreach($tmp as $key => $server){
133             if($server == "default") continue;
134             $this->gotoNtpServers[$server] = $server;
135         }
137         $this->modes["active"]= _("Activated");
138         $this->modes["locked"]= _("Locked");
140         /* Set base */
141         if ($this->dn == "new"){
142             $ui= get_userinfo();
143             $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
144         } elseif(class_available("ArpNewDevice") &&
145                 preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){
146             $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn);
147         }else{
148             $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("workgeneric", "workstationRDN"), '/')."/i", "", $this->dn);
149         }
151         /* Create an array of all Syslog servers */
152         $tmp = $this->config->data['SERVERS']['SYSLOG'];
153         foreach($tmp as $server){
154             $visible = $server;
155             if($server == "default" && $this->member_of_ogroup) {
156                 $visible = "["._("inherited")."]";
157             }
158             $this->gotoSyslogServers[$server] = $visible;
159         }
161         $this->initial_gotoMode = $this->gotoMode;
163         /* Save 'dn' for later referal */
164         $this->orig_dn= $this->dn;
165         $this->orig_cn= $this->cn;
166         $this->orig_base= $this->base;
168         /* Instanciate base selector */
169         $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
170         $this->baseSelector->setSubmitButton(false);
171         $this->baseSelector->setHeight(300);
172         $this->baseSelector->update(true);
173     }
176     function set_acl_base($base)
177     {
178         plugin::set_acl_base($base);
179         $this->netConfigDNS->set_acl_base($base);
180     }
182     function set_acl_category($cat)
183     {
184         plugin::set_acl_category($cat);
185         $this->netConfigDNS->set_acl_category($cat);
186     }
188     function execute()
189     {
190         /* Call parent execute */
191         plugin::execute();
193         if($this->is_account && !$this->view_logged){
194             $this->view_logged = TRUE;
195             new log("view","workstation/".get_class($this),$this->dn);
196         }
198         /* Do we need to flip is_account state? */
199         if(isset($_POST['modify_state'])){
200             if($this->is_account && $this->acl_is_removeable()){
201                 $this->is_account= FALSE;
202             }elseif(!$this->is_account && $this->acl_is_createable()){
203                 $this->is_account= TRUE;
204             }
205         }
207         if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->validActions[$_POST['saction']]) ){
208             $action= get_post('saction');
210             /* Check if we have an DaemonEvent for this action */ 
211             if(class_available("DaemonEvent")){
212                 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
213                 if(isset($events['TRIGGERED']["DaemonEvent_".$action])){
214                     $evt = $events['TRIGGERED']["DaemonEvent_".$action];
215                     $tmp = new $evt['CLASS_NAME']($this->config);
216                     $tmp->add_targets(array($this->netConfigDNS->macAddress));
217                     $tmp->set_type(TRIGGERED_EVENT);
218                     $o_queue = new gosaSupportDaemon();
219                     if(!$o_queue->append($tmp)){
220                         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
221                     }
222                 }
223             } else {
224                 msg_dialog::display(_("Event error"),
225                         sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG);
226             }
229         }
231         /* Do we represent a valid terminal? */
232         if (!$this->is_account && $this->parent === NULL){
233             $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
234                 msgPool::noValidExtension(_("workstation"))."</b>";
235             return($display);
236         }
238         /* Add new ntp Server to our list */ 
239         if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){
240             $this->gotoNtpServer[$_POST['gotoNtpServers']] = get_post('gotoNtpServers');
241         }
243         /* Delete selected NtpServer for list of used servers  */
244         if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){
245             foreach($_POST['gotoNtpServerSelected'] as $name){
246                 unset($this->gotoNtpServer[$name]);
247             }
248         }
250         /* Fill templating stuff */
251         $smarty= get_smarty();
254         /* Set acls */
255         $tmp = $this->plInfo();
256         foreach($tmp['plProvidedAcls'] as $name => $translation){
257             $smarty->assign($name."ACL",$this->getacl($name));
258         }
260         $smarty->assign("cn", set_post($this->cn));
261         $smarty->assign("description", set_post($this->description));
262         $smarty->assign("l", set_post($this->l));
264         $tmp = array();
265         foreach($this->gotoNtpServers as $server){
266             if(!in_array_strict($server,$this->gotoNtpServer)){
267                 $tmp[$server] = $server;
268             }
269         }
270         $smarty->assign("gotoNtpServers", set_post($tmp));
272         /* Check if workstation is online */
273         if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){
274             $smarty->assign("actions", 
275                     set_post(
276                         array(
277                             "halt" => _("Switch off"), 
278                             "reboot" => _("Reboot"),
279                             "update" => _("Software update"),
280                             "reinstall" => _("Reinstall"),
281                             "rescan" => _("Rescan hardware"),
282                             "localboot" => _("Force local boot"),
283                             )
284                         )
285                     );
286         } else {
287             $smarty->assign("actions", 
288                     set_post(
289                         array(
290                             "wakeup" => _("Wake up"),
291                             "reinstall" => _("Reinstall"),
292                             "update" => _("Software update"),
293                             "localboot" => _("Force local boot"),
294                             )
295                         )
296                     );
297         }
298         /* Arrays */
299         $smarty->assign("modes",        set_post($this->modes));
300         $smarty->assign("nfsservers",   set_post($this->config->data['SERVERS']['NFS']));
301         $smarty->assign("syslogservers",set_post($this->gotoSyslogServers));
302         $smarty->assign("fai_activated",set_post($this->fai_activated));
304         $ntpser = array();
305         foreach($this->gotoNtpServers as $server){
306             if(!in_array_strict($server,$this->gotoNtpServer)){
307                 $ntpser[$server] = set_post($server);
308             }
309         }
310         $smarty->assign("gotoNtpServers", $ntpser);
312         /* Variables */
313         foreach(array("gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
314             $smarty->assign($val."_select", set_post($this->$val));
315         }
316         $smarty->assign("base", $this->baseSelector->render());
318         /* tell smarty the inherit checkbox state */
319         $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
320         $smarty->assign("member_of_ogroup", $this->member_of_ogroup);
322         $str = $this->netConfigDNS->execute();
323         if(is_object($this->netConfigDNS->dialog)){
324             return($str);
325         }
326         $smarty->assign("netconfig", $str);
328         /* Display kerberos host key options */
329         $smarty->assign("host_key","");
330         if(is_object($this->kerberos_key_service)){
331             $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/"));
332         }
334         /* Show main page */
335         $smarty->assign("currently_installing", $this->currently_installing);
336         return($smarty->fetch (get_template_path('workstation.tpl', TRUE, dirname(__FILE__))));
337     }
339     function remove_from_parent()
340     {
341         if($this->acl_is_removeable()){
343             $this->netConfigDNS->remove_from_parent();
344             $ldap= $this->config->get_ldap_link();
345             $ldap->rmdir($this->dn);
346             new log("remove","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
347             if (!$ldap->success()){
348                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
349             }
351             /* Remove kerberos key dependencies too */
352             if(is_object($this->kerberos_key_service)){
353                 $this->kerberos_key_service->remove_from_parent_by_prefix("host/");
354             }
356             /* Optionally execute a command after we're done */
357             $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
359             /* Delete references to object groups */
360             $ldap->cd ($this->config->current['BASE']);
361             $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
362             while ($ldap->fetch()){
363                 $og= new ogroup($this->config, $ldap->getDN());
364                 unset($og->member[$this->dn]);
365                 $og->save ();
366             }
368             /* Remove all accessTo/trust dependencies */
369             update_accessTo($this->cn,"");
370         }
372         /* Clean queue form entries with this mac 
373          */
374         if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){
375             $q = new gosaSupportDaemon();
376             $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress);
377         }
379         if(isset($_POST["inheritAll"])){
380             $this->set_everything_to_inherited();
381         }
382     }
385     /* Save data to object */
386     function save_object()
387     {
389         /* Create a base backup and reset the
390            base directly after calling plugin::save_object();
391            Base will be set seperatly a few lines below */
392         $base_tmp = $this->base;
393         plugin::save_object();
394         $this->base = $base_tmp;
396         /* Refresh base */
397         if ($this->acl_is_moveable($this->base)){
398             if (!$this->baseSelector->update()) {
399                 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
400             }
401             if ($this->base != $this->baseSelector->getBase()) {
402                 $this->base= $this->baseSelector->getBase();
403                 $this->is_modified= TRUE;
404             }
405         }
407         $this->netConfigDNS->save_object();
409         /* Set inherit mode */
410         if((isset($_POST['workgeneric_posted'])) && ($this->acl_is_writeable("gotoNtpServer"))){
411             if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){
412                 $this->inheritTimeServer = true;
413             }else{
414                 $this->inheritTimeServer = false;
415             }
416         }
418         if(isset($_POST["inheritAll"])){
419             $this->set_everything_to_inherited();
420         }
422         /* Hanle kerberos host key plugin */
423         if(is_object($this->kerberos_key_service)){
424             $this->kerberos_key_service->save_object_by_prefix("host/");
425         }
426     }
429     /* Check supplied data */
430     function check()
431     {
432         /* Call common method to give check the hook */
433         $message= plugin::check();
435         /* Skip IP & Mac checks if this is a template */
436         if($this->cn != "wdefault"){
437             $message= array_merge($message, $this->netConfigDNS->check());
438         }
440         $this->dn= "cn=".$this->cn.",".get_ou("workgeneric", "workstationRDN").$this->base;
442         if ($this->cn == ""){
443             $message[]= msgPool::required(_("Name"));
444         }
446         /* Check if given name is a valid host/dns name */
447         if(!tests::is_dns_name($this->cn)){
448             $message[] = msgPool::invalid(_("Name"));
449         }
451         // Check if a wrong base was supplied
452         if(!$this->baseSelector->checkLastBaseUpdate()){
453             $message[]= msgPool::check_base();
454         }
456         if ($this->orig_dn != $this->dn){
457             $ldap= $this->config->get_ldap_link();
458             $ldap->cd ($this->base);
460             if($this->cn == "wdefault"){
461                 $ldap->cat($this->dn);
462             }else{
463                 $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn"));
464             }
465             if ($ldap->count() != 0){
466                 while ($attrs= $ldap->fetch()){
468                     $matchArp = FALSE;
469                     if(class_available("ArpNewDevice") &&
470                             preg_match ("/,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $ldap->getDN())){
471                         $matchArp = TRUE;
472                     } 
474                     if (preg_match("/cn=dhcp,/",$attrs['dn']) || $matchArp){
475                         continue;
476                     } else {
477                         if ($attrs['dn'] != $this->orig_dn){
478                             $message[]= msgPool::duplicated(_("Name"));
479                             break;
480                         }
481                     }
482                 }
483             }
484         }
486         /* Check for valid ntpServer selection */
487         if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
488             $message[]= msgPool::required(_("NTP server"));
489         }
491         /* Only systems with a valid ldap handle can be activated 
492          */
493         if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){
495             if(isset($this->parent->by_object['workstartup']) &&
496                     !count($this->parent->by_object['workstartup']->gotoLdapServers) && 
497                     !$this->parent->by_object['workstartup']->gotoLdap_inherit){
499                 $message[] = _("A valid LDAP server assignment is missing!");
500             }
501         }else{
502             /* Warn the user, that this host is currently installing */
503             if($this->currently_installing && !$this->currently_installing_warned && 
504                     !preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i",$this->orig_dn)){
506                 /* Force aborting without message dialog */
507                 $message[] = "";
508                 $this->currently_installing_warned = TRUE;
509                 msg_dialog::display(_("Software deployment"), 
510                         _("This host is currently installing. If you want to save it, press 'OK'."),
511                         CONFIRM_DIALOG);
512             }
513         }
515         /* Check if we are allowed to create or move this object
516          */
517         if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
518             $message[] = msgPool::permCreate();
519         }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
520             $message[] = msgPool::permMove();
521         }
523         return ($message);
524     }
527     /* Save to LDAP */
528     function save()
529     {
530         /* Detect mode changes */
531         $activate= (isset($this->saved_attributes['gotoMode']) &&
532                 $this->gotoMode != $this->saved_attributes['gotoMode'] &&
533                 $this->gotoMode == "active" &&
534                 tests::is_ip($this->netConfigDNS->ipHostNumber)) || $this->auto_activate;
535         plugin::save();
537         /* Strip out 'default' values */
538         foreach (array("gotoSyslogServer") as $val){
540             if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){
541                 $this->attrs[$val]= array();
542             }
543         }
545         /* Add missing arrays */
546         foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
547             if (isset ($this->$val) && count ($this->$val) != 0){
548                 $this->attrs["$val"]= $this->$val;
549             }
550         }
552         /* Remove all empty values */
553         if ($this->orig_dn == 'new'){
554             $attrs= array();
555             foreach ($this->attrs as $key => $val){
556                 if (is_array($val) && count($val) == 0){
557                     continue;
558                 }
559                 $attrs[$key]= $val;
560             }
561             $this->attrs= $attrs;
562         }
564         /* Update ntp server settings */
565         if($this->inheritTimeServer){
566             if($this->is_new){
567                 if(isset($this->attrs['gotoNtpServer'])){
568                     unset($this->attrs['gotoNtpServer']);
569                 }
570             }else{
571                 $this->attrs['gotoNtpServer'] = array();
572             }
573         }else{
574             /* Set ntpServers */
575             $this->attrs['gotoNtpServer'] = array();
576             foreach($this->gotoNtpServer as $server){
577                 $this->attrs['gotoNtpServer'][] = $server;
578             }
579         }
581         /* cn=default and macAddress=- indicates that this is a template */
582         if($this->cn == "wdefault"){
583             $this->netConfigDNS->macAddress = "-";
584         }
586         /* Write back to ldap */
587         $ldap= $this->config->get_ldap_link();
588         if ($this->orig_dn == 'new'){
589             $ldap->cd($this->config->current['BASE']);
590             $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
591             $ldap->cd($this->dn);
592             $ldap->add($this->attrs);
593             new log("create","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
594             if (!$ldap->success()){
595                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
596             }
598             $this->netConfigDNS->cn = $this->cn;
599             $this->netConfigDNS->save();
601             $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
602         } else {
603             if ($this->orig_dn != $this->dn){
605                 /* Remove all accessTo/trust dependencies */
606                 update_accessTo($this->orig_cn,$this->cn);
607             }
608             $ldap->cd($this->dn);
609             $this->cleanup();
610             $ldap->modify ($this->attrs); 
611             if (!$ldap->success()){
612                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
613             }
614             new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
616             $this->netConfigDNS->cn = $this->cn;
617             $this->netConfigDNS->save();
619             $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
620         }
622         if ($activate && class_available("DaemonEvent")){
624             /* Send installation activation
625              */
626             $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
627             $o_queue = new gosaSupportDaemon();
628             if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){
629                 $evt = $events['TRIGGERED']['DaemonEvent_installation_activation'];
630                 $tmp = new $evt['CLASS_NAME']($this->config);
631                 $tmp->set_type(TRIGGERED_EVENT);
632                 $tmp->add_targets(array($this->netConfigDNS->macAddress));
633                 if(!$o_queue->append($tmp)){
634                     msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
635                 }
636             }
637         }
638     }
641     /* Display generic part for server copy & paste */
642     function getCopyDialog()
643     {
644         $vars = array("cn");
645         $smarty = get_smarty();
646         $smarty->assign("cn", set_post($this->cn));
647         $smarty->assign("object","workstation");
648         $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
649         $ret = array();
650         $ret['string'] = $str;
651         $ret['status'] = "";
652         return($ret);
653     }
656     function saveCopyDialog()
657     {
658         if(isset($_POST['cn'])){
659             $this->cn = get_post('cn');
660         }
661     }
664     function PrepareForCopyPaste($source)
665     {
666         plugin::PrepareForCopyPaste($source);
667         if(isset($source['macAddress'][0])){
668             $this->netConfigDNS->macAddress = $source['macAddress'][0];
669         }
670         if(isset($source['ipHostNumber'][0])){
671             $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0];
672         }
674         /* Create used ntp server array */
675         $this->gotoNtpServer= array();
676         if(isset($source['gotoNtpServer'])){
677             $this->inheritTimeServer = false;
678             unset($source['gotoNtpServer']['count']);
679             foreach($source['gotoNtpServer'] as $server){
680                 $this->gotoNtpServer[$server] = $server;
681             }
682         }
684         /* Set inherit checkbox state */
685         if((in_array_strict("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){
686             $this->inheritTimeServer = true;
687             $this->gotoNtpServer=array();
688         }
689     }
692     /* Return plugin informations for acl handling 
693 #FIXME FAIscript seams to ununsed within this class... */ 
694     static function plInfo()
695     {
696         return (array(  
697                     "plShortName"   => _("Generic"),
698                     "plDescription" => _("Workstation generic"),
699                     "plSelfModify"  => FALSE,
700                     "plDepends"     => array(),
701                     "plPriority"    => 0,
702                     "plSection"     => array("administration"),
703                     "plRequirements"=> array(
704                         'ldapSchema' => array('gotoWorkstation' => '>=2.7'),
705                         'onFailureDisablePlugin' => array(get_class())
706                         ),
707                     "plCategory"    => array("workstation" => array("description"  => _("Workstation"),
708                             "objectClass"  => "gotoWorkstation")),
709                     "plProperties" =>
710                     array(
711                         array(
712                             "name"          => "workstationRDN",
713                             "type"          => "rdn",
714                             "default"       => "ou=workstations,ou=systems,",
715                             "description"   => _("RDN for workstation storage."),
716                             "check"         => "gosaProperty::isRdn",
717                             "migrate"       => "migrate_workstationRDN",
718                             "group"         => "plugin",
719                             "mandatory"     => FALSE
720                             ),
721                         array(
722                             "name"          => "systemIsoHook",
723                             "type"          => "command",
724                             "default"       => "",
725                             "description"   => _("Script to create system ISO images."),
726                             "check"         => "gosaProperty::isCommand",
727                             "migrate"       => "",
728                             "group"         => "plugin",
729                             "mandatory"     => FALSE
730                             )
731                             ),
733                         "plProvidedAcls"=> array(
734                                 "cn"                  => _("Workstation name"),
735                                 "description"         => _("Description") ,
736                                 "l"                   => _("Location") ,
737                                 "base"                => _("Base") ,
738                                 "gotoMode"            => _("Goto mode"), 
739                                 "gotoSyslogServer"    => _("Syslog server"), 
740                                 "gotoNtpServer"       => _("NTP server"), 
741                                 "userPassword"      => _("Root password"),
742                                 "createFAICD"         => _("Create FAI CD"),
743                                 "FAIstate"            => _("Action flag"))
744                             ));
745     }
747     function set_everything_to_inherited()
748     {
749         $this->gotoSyslogServer  = "default";
750         $this->inheritTimeServer = TRUE;
752         /* Set workstation service attributes to inherited */
753         if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){
754             foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant","gotoXDriver",
755                         "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
756                 if($this->parent->by_object['workservice']->acl_is_writeable($name)){
757                     $this->parent->by_object['workservice']->$name = "default"; 
758                 }
759             }
760         }
762         /* Set workstation startup attributes to inherited */
763         if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){
764             $obj = $this->parent->by_object['workstartup'];
765             if($obj->acl_is_writeable("gotoBootKernel")){
766                 $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited";
767             }
768             if($obj->acl_is_writeable("gotoLdapServer")){
769                 $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited";
770                 $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE;
771                 $this->parent->by_object['workstartup']->gotoLdapServers = array();
772             }
773             if($obj->acl_is_writeable("FAIdebianMirror")){
774                 $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited";
775             }
776         }
777     }
780     function is_modal_dialog()
781     {
782         return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog));
783     }
787 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
788 ?>