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> <b>".
114 _("This 'dn' has no workstation features.")."</b>";
115 return($display);
116 }
118 /* Base select dialog */
119 $once = true;
120 foreach($_POST as $name => $value){
121 if(preg_match("/^chooseBase/",$name) && $once){
122 $once = false;
123 $this->dialog = new baseSelectDialog($this->config);
124 $this->dialog->setCurrentBase($this->base);
125 }
126 }
128 /* Dialog handling */
129 if(is_object($this->dialog)){
130 /* Must be called before save_object */
131 $this->dialog->save_object();
133 if($this->dialog->isClosed()){
134 $this->dialog = false;
135 }elseif($this->dialog->isSelected()){
136 $this->base = $this->dialog->isSelected();
137 $this->dialog= false;
138 }else{
139 return($this->dialog->execute());
140 }
141 }
143 /* Fill templating stuff */
144 $smarty= get_smarty();
145 $smarty->assign("cn", $this->cn);
146 $smarty->assign("l", $this->l);
147 $smarty->assign("bases", $this->config->idepartments);
148 $smarty->assign("staticAddress", "");
150 /* Check if workstation is online */
151 $query= "fping -q -r 1 -t 500 ".$this->cn;
152 exec ($query, $dummy, $retval);
154 /* Offline */
155 if ($retval == 0){
156 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
157 "instant_update" => _("Instant update"),
158 "update" => _("Scheduled update"),
159 "reinstall" => _("Reinstall"),
160 "rescan" => _("Rescan hardware")));
161 } else {
162 $smarty->assign("actions", array("wake" => _("Wake up"),
163 "reinstall" => _("Reinstall"),
164 "update" => _("Scheduled update")));
165 }
166 /* Arrays */
167 $smarty->assign("modes", $this->modes);
168 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
169 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
170 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
172 /* Variables */
173 foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
174 $smarty->assign($val."_select", $this->$val);
175 $smarty->assign($val."ACL", chkacl($this->acl, $val));
176 }
177 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
179 /* Show main page */
180 $smarty->assign("netconfig", $this->netConfigDNS->execute());
181 return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
182 }
184 function remove_from_parent()
185 {
186 $this->netConfigDNS->remove_from_parent();
187 $ldap= $this->config->get_ldap_link();
188 $ldap->rmdir($this->dn);
189 show_ldap_error($ldap->get_error());
191 /* Optionally execute a command after we're done */
192 $this->handle_post_events("remove");
194 /* Delete references to object groups */
195 $ldap->cd ($this->config->current['BASE']);
196 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
197 while ($ldap->fetch()){
198 $og= new ogroup($this->config, $ldap->getDN());
199 unset($og->member[$this->dn]);
200 $og->save ();
201 }
202 }
205 /* Save data to object */
206 function save_object()
207 {
208 plugin::save_object();
210 /* Save base, since this is no LDAP attribute */
211 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
212 $this->base= $_POST['base'];
213 }
214 $this->netConfigDNS->save_object();
215 }
218 /* Check supplied data */
219 function check()
220 {
221 $message=$this->netConfigDNS->check();
223 $ui= get_userinfo();
224 $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
225 $acl= get_permissions ($this->dn, $ui->subtreeACL);
226 $acl= get_module_permission($acl, "group", $this->dn);
227 if (chkacl($acl, "create") != ""){
228 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
229 }
231 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
232 $message[]= _("The required field 'Workstation name' is not set.");
233 }
235 if ($this->orig_dn != $this->dn){
236 $ldap= $this->config->get_ldap_link();
237 $ldap->cd ($this->base);
238 $ldap->search ("(cn=".$this->cn.")", array("cn"));
239 if ($ldap->count() != 0){
240 while ($attrs= $ldap->fetch()){
241 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
242 continue;
243 } else {
244 if ($attrs['dn'] != $this->orig_dn){
245 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
246 break;
247 }
248 }
249 }
250 }
251 }
253 return ($message);
254 }
257 /* Save to LDAP */
258 function save()
259 {
260 plugin::save();
262 /* Strip out 'default' values */
263 foreach (array("gotoSyslogServer") as $val){
265 if ($this->attrs[$val] == "default"){
266 $this->attrs[$val]= array();
267 }
268 }
270 /* Add missing arrays */
271 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
272 if (isset ($this->$val) && count ($this->$val) != 0){
273 $this->attrs["$val"]= $this->$val;
274 }
275 }
277 /* Remove all empty values */
278 if ($this->orig_dn == 'new'){
279 $attrs= array();
280 foreach ($this->attrs as $key => $val){
281 if (is_array($val) && count($val) == 0){
282 continue;
283 }
284 $attrs[$key]= $val;
285 }
286 $this->attrs= $attrs;
287 }
289 /* Write back to ldap */
290 $ldap= $this->config->get_ldap_link();
291 if ($this->orig_dn == 'new'){
292 $ldap->cd($this->config->current['BASE']);
293 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
294 $ldap->cd($this->dn);
295 $ldap->add($this->attrs);
296 if(!$this->didAction){
297 $this->handle_post_events("add");
298 }
299 } else {
300 if ($this->orig_dn != $this->dn){
301 $this->move($this->orig_dn, $this->dn);
302 }
303 $ldap->cd($this->dn);
304 $this->cleanup();
305 $ldap->modify ($this->attrs);
307 if(!$this->didAction){
308 $this->handle_post_events("modify");
309 }
310 }
311 $this->netConfigDNS->cn = $this->cn;
312 $this->netConfigDNS->save($this->dn);
313 show_ldap_error($ldap->get_error());
314 }
316 }
318 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
319 ?>