Code

added seperated dns class for network devices
[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 $ghUsbSupport= "-";
20   var $ghNetNic= array();
21   var $ghIdeDev= array();
22   var $ghScsiDev= array();
23   var $ghGfxAdapter= "-";
24   var $ghSoundAdapter= "-";
25   var $gotoLastUser= "-";
26   var $FAIscript="";
27   var $didAction= FALSE;
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   var $netConfigDNS;
40   /* attribute list for save action */
41   var $ignore_account= TRUE;
42   var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer",
43       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
44       "ghCpuType", "ghMemSize", "ghUsbSupport",
45       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript");
46   var $objectclasses= array("top", "gotoWorkstation", "GOhard","FAIobject");
48   function workgeneric ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
51     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
52     /* Load available modes */
53     $ldap= $this->config->get_ldap_link();
54     $ldap->cd ($this->config->current['BASE']);
55     $ldap->search ("(objectClass=gotoInstallProfile)",array("cn"));
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->netConfigDNS->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("actionACL", chkacl($this->acl, 'action'));
154     /* Show main page */
155     $smarty->assign("netconfig", $this->netConfigDNS->execute());
156     return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
157   }
159   function remove_from_parent()
160   {
161     $ldap= $this->config->get_ldap_link();
162     $ldap->rmdir($this->dn);
163     show_ldap_error($ldap->get_error());
165     /* Optionally execute a command after we're done */
166     $this->handle_post_events("remove");
168     /* Delete references to object groups */
169     $ldap->cd ($this->config->current['BASE']);
170     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
171     while ($ldap->fetch()){
172       $og= new ogroup($this->config, $ldap->getDN());
173       unset($og->member[$this->dn]);
174       $og->save ();
175     }
176     $this->netConfigDNS->remove_from_parent();
177   }
180   /* Save data to object */
181   function save_object()
182   {
183     plugin::save_object();
185     /* Save base, since this is no LDAP attribute */
186     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
187       $this->base= $_POST['base'];
188     }
189     $this->netConfigDNS->save_object();
190   }
193   /* Check supplied data */
194   function check()
195   {
196     $message=$this->netConfigDNS->check();
198     $ui= get_userinfo();
199     $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
200     $acl= get_permissions ($this->dn, $ui->subtreeACL);
201     $acl= get_module_permission($acl, "group", $this->dn);
202     if (chkacl($acl, "create") != ""){
203       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
204     }
206     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
207       $message[]= _("The required field 'Workstation name' is not set.");
208     }
210     if ($this->orig_dn != $this->dn){
211       $ldap= $this->config->get_ldap_link();
212       $ldap->cd ($this->base);
213       $ldap->search ("(cn=".$this->cn.")", array("cn"));
214       if ($ldap->count() != 0){
215         while ($attrs= $ldap->fetch()){
216           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
217             continue;
218           } else {
219             if ($attrs['dn'] != $this->orig_dn){
220               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
221               break;
222             }
223           }
224         }
225       }
226     }
228     return ($message);
229   }
232   /* Save to LDAP */
233   function save()
234   {
235     plugin::save();
237     /* Strip out 'default' values */
238     foreach (array("gotoSyslogServer") as $val){
240       if ($this->attrs[$val] == "default"){
241         $this->attrs[$val]= array();
242       }
243     }
245     /* Add missing arrays */
246     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
247       if (isset ($this->$val) && count ($this->$val) != 0){
248         $this->attrs["$val"]= $this->$val;
249       }
250     }
252     /* Remove all empty values */
253     if ($this->orig_dn == 'new'){
254       $attrs= array();
255       foreach ($this->attrs as $key => $val){
256         if (is_array($val) && count($val) == 0){
257           continue;
258         }
259         $attrs[$key]= $val;
260       }
261       $this->attrs= $attrs;
262     }
264     /* Write back to ldap */
265     $ldap= $this->config->get_ldap_link();
266     if ($this->orig_dn == 'new'){
267       $ldap->cd($this->config->current['BASE']);
268       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
269       $ldap->cd($this->dn);
270       $ldap->add($this->attrs);
271       if(!$this->didAction){
272         $this->handle_post_events("add");
273       }
274     } else {
275       if ($this->orig_dn != $this->dn){
276         $this->move($this->orig_dn, $this->dn);
277       }
278       $ldap->cd($this->dn);
279       $ldap->modify($this->attrs);
280       if(!$this->didAction){
281         $this->handle_post_events("modify");
282       }
283     }
284     $this->netConfigDNS->save($this->dn);
285     show_ldap_error($ldap->get_error());
286   }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>