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);
53 /* Read arrays */
54 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
55 if (!isset($this->attrs[$val])){
56 continue;
57 }
58 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
59 array_push($this->$val, $this->attrs[$val][$i]);
60 }
61 }
63 $this->modes["active"]= _("Activated");
64 $this->modes["locked"]= _("Locked");
65 $this->modes["memcheck"]= _("Memory test");
66 $this->modes["sysinfo"]= _("System analysis");
68 /* Set base */
69 if ($this->dn == "new"){
70 $ui= get_userinfo();
71 $this->base= dn2base($ui->dn);
72 } else {
73 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
74 }
76 /* Save 'dn' for later referal */
77 $this->orig_dn= $this->dn;
78 }
80 function execute()
81 {
82 /* Call parent execute */
83 plugin::execute();
85 /* Do we need to flip is_account state? */
86 if (isset($_POST['modify_state'])){
87 $this->is_account= !$this->is_account;
88 }
90 if (isset($_POST['action'])){
91 $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
92 if ($cmd == ""){
93 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
94 } else {
95 exec ($cmd." ".$this->netConfigDNS->macAddress." ".escapeshellarg($_POST['saction']), $dummy, $retval);
96 if ($retval != 0){
97 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
98 } else {
99 $this->didAction= TRUE;
100 }
101 }
102 }
104 /* Do we represent a valid terminal? */
105 if (!$this->is_account && $this->parent == NULL){
106 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
107 _("This 'dn' has no workstation features.")."</b>";
108 return($display);
109 }
111 /* Base select dialog */
112 $once = true;
113 foreach($_POST as $name => $value){
114 if(preg_match("/^chooseBase/",$name) && $once){
115 $once = false;
116 $this->dialog = new baseSelectDialog($this->config);
117 $this->dialog->setCurrentBase($this->base);
118 }
119 }
121 /* Dialog handling */
122 if(is_object($this->dialog)){
123 /* Must be called before save_object */
124 $this->dialog->save_object();
126 if($this->dialog->isClosed()){
127 $this->dialog = false;
128 }elseif($this->dialog->isSelected()){
129 $this->base = $this->dialog->isSelected();
130 $this->dialog= false;
131 }else{
132 return($this->dialog->execute());
133 }
134 }
136 /* Fill templating stuff */
137 $smarty= get_smarty();
138 $smarty->assign("cn", $this->cn);
139 $smarty->assign("l", $this->l);
140 $smarty->assign("bases", $this->config->idepartments);
141 $smarty->assign("staticAddress", "");
143 /* Check if workstation is online */
144 $query= "fping -q -r 1 -t 500 ".$this->cn;
145 exec ($query, $dummy, $retval);
147 /* Offline */
148 if ($retval == 0){
149 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
150 "instant_update" => _("Instant update"),
151 "update" => _("Scheduled update"),
152 "reinstall" => _("Reinstall"),
153 "rescan" => _("Rescan hardware")));
154 } else {
155 $smarty->assign("actions", array("wake" => _("Wake up"),
156 "reinstall" => _("Reinstall"),
157 "update" => _("Scheduled update")));
158 }
159 /* Arrays */
160 $smarty->assign("modes", $this->modes);
161 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
162 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
163 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
165 /* Variables */
166 foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
167 $smarty->assign($val."_select", $this->$val);
168 $smarty->assign($val."ACL", chkacl($this->acl, $val));
169 }
170 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
172 /* Show main page */
173 $smarty->assign("netconfig", $this->netConfigDNS->execute());
174 return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
175 }
177 function remove_from_parent()
178 {
179 $this->netConfigDNS->remove_from_parent();
180 $ldap= $this->config->get_ldap_link();
181 $ldap->rmdir($this->dn);
182 show_ldap_error($ldap->get_error());
184 /* Optionally execute a command after we're done */
185 $this->handle_post_events("remove");
187 /* Delete references to object groups */
188 $ldap->cd ($this->config->current['BASE']);
189 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
190 while ($ldap->fetch()){
191 $og= new ogroup($this->config, $ldap->getDN());
192 unset($og->member[$this->dn]);
193 $og->save ();
194 }
195 }
198 /* Save data to object */
199 function save_object()
200 {
201 plugin::save_object();
203 /* Save base, since this is no LDAP attribute */
204 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
205 $this->base= $_POST['base'];
206 }
207 $this->netConfigDNS->save_object();
208 }
211 /* Check supplied data */
212 function check()
213 {
214 /* Call common method to give check the hook */
215 $message= plugin::check();
216 $message= array_merge($message, $this->netConfigDNS->check());
218 $ui= get_userinfo();
219 $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
220 $acl= get_permissions ($this->dn, $ui->subtreeACL);
221 $acl= get_module_permission($acl, "group", $this->dn);
222 if (chkacl($acl, "create") != ""){
223 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
224 }
226 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
227 $message[]= _("The required field 'Workstation name' is not set.");
228 }
230 if ($this->orig_dn != $this->dn){
231 $ldap= $this->config->get_ldap_link();
232 $ldap->cd ($this->base);
233 $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn"));
234 if ($ldap->count() != 0){
235 while ($attrs= $ldap->fetch()){
236 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
237 continue;
238 } else {
239 if ($attrs['dn'] != $this->orig_dn){
240 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
241 break;
242 }
243 }
244 }
245 }
246 }
248 return ($message);
249 }
252 /* Save to LDAP */
253 function save()
254 {
255 plugin::save();
257 /* Strip out 'default' values */
258 foreach (array("gotoSyslogServer") as $val){
260 if ($this->attrs[$val] == "default"){
261 $this->attrs[$val]= array();
262 }
263 }
265 /* Add missing arrays */
266 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
267 if (isset ($this->$val) && count ($this->$val) != 0){
268 $this->attrs["$val"]= $this->$val;
269 }
270 }
272 /* Remove all empty values */
273 if ($this->orig_dn == 'new'){
274 $attrs= array();
275 foreach ($this->attrs as $key => $val){
276 if (is_array($val) && count($val) == 0){
277 continue;
278 }
279 $attrs[$key]= $val;
280 }
281 $this->attrs= $attrs;
282 }
284 /* Write back to ldap */
285 $ldap= $this->config->get_ldap_link();
286 if ($this->orig_dn == 'new'){
287 $ldap->cd($this->config->current['BASE']);
288 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
289 $ldap->cd($this->dn);
290 $ldap->add($this->attrs);
291 if(!$this->didAction){
292 $this->handle_post_events("add");
293 }
294 } else {
295 if ($this->orig_dn != $this->dn){
296 $this->move($this->orig_dn, $this->dn);
297 }
298 $ldap->cd($this->dn);
299 $this->cleanup();
300 $ldap->modify ($this->attrs);
302 if(!$this->didAction){
303 $this->handle_post_events("modify");
304 }
305 }
306 $this->netConfigDNS->cn = $this->cn;
307 $this->netConfigDNS->save($this->dn);
308 show_ldap_error($ldap->get_error());
309 }
311 }
313 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
314 ?>