5bf886ddbced63152818a527e9f47edfe095d6a5
1 <?php
3 class termgroup extends plugin
4 {
5 /* attribute list for save action */
6 var $members= array();
8 /* Stores a list of the member dn's */
9 var $member_dn = array();
11 var $gotoMode = "locked";
12 var $gotoSyslogServer = "";
13 var $gotoNtpServer = array();
14 var $gotoTerminalPath = array();
15 var $gotoSwapServer = array();
16 var $modes = array();
17 var $inheritTimeServer = true;
18 var $is_account = true;
19 var $orig_dn = "";
20 var $didAction = FALSE;
21 var $mapActions = array("halt" => "halt",
22 "reboot" => "reboot",
23 "update" => "update",
24 "reinstall" => "reinstall",
25 "rescan" => "rescan",
26 "wake" => "wakeup",
27 # These are currently not supported by the tftp daemon
28 # "memcheck" => "memcheck",
29 # "sysinfo" => "sysinfo"
30 );
32 var $attributes = array("gotoMode","gotoSyslogServer", "gotoNtpServer", "gotoTerminalPath", "gotoSwapServer");
33 var $objectclasses = array("gotoWorkstationTemplate");
34 var $CopyPasteVars = array("gotoNtpServers","modes","inheritTimeServer","members");
35 var $view_logged = FALSE;
36 var $nfsservers = array();
37 var $swapservers = array();
38 var $member_of_ogroup= false;
39 var $members_inherit_from_group = true;
41 function termgroup (&$config, $dn= NULL, $parent= NULL)
42 {
43 /***************
44 Some initialisations
45 ***************/
47 plugin::plugin($config, $dn, $parent);
48 $ldap= $config->get_ldap_link();
50 $this->is_account = true;
51 $this->modes["active"]= _("Activated");
52 $this->modes["locked"]= _("Locked");
53 // $this->modes["memcheck"]= _("Memory test");
54 // $this->modes["sysinfo"]= _("System analysis");
56 $this->orig_dn = $this->dn;
58 /***************
59 Get mac addresses from member objects
60 ***************/
62 /* We're only interested in the terminal members here, evaluate
63 these... */
64 if(isset($this->attrs['member'])){
65 for ($i= 0; $i<$this->attrs['member']['count']; $i++){
66 $member= $this->attrs['member'][$i];
67 array_push($this->member_dn, $member);
68 $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
69 if ($ldap->success()){
70 $attrs = $ldap->fetch();
71 if (in_array("gotoTerminal", $attrs['objectClass']) ||
72 in_array("gotoWorkstation", $attrs['objectClass'])){
73 if (isset($attrs['macAddress'])){
74 $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
75 } else {
76 $this->members[$attrs['cn'][0]]= "";
77 }
78 }
79 }
80 }
81 }
83 /***************
84 Perpare NTP settings
85 ***************/
87 /* Create used ntp server array */
88 $this->gotoNtpServer= array();
89 if(isset($this->attrs['gotoNtpServer'])){
90 $this->inheritTimeServer = false;
91 unset($this->attrs['gotoNtpServer']['count']);
92 foreach($this->attrs['gotoNtpServer'] as $server){
93 $this->gotoNtpServer[$server] = $server;
94 }
95 }
97 /* Get Share servers */
98 $tmp2 = array();
99 $tmp2['!']= _("Local swap");
100 foreach($this->config->data['SERVERS']['NBD'] as $server){
101 if($server != "default"){
102 $tmp2[$server]= $server;
103 }else{
104 if($this->member_of_ogroup){
105 $tmp2[$server]="["._("inherited")."]";
106 }
107 }
108 }
109 $this->swapservers= $tmp2;
111 $tmp2 = array();
112 foreach($this->config->data['SERVERS']['NFS'] as $server){
113 if($server != "default"){
114 $tmp2[$server]= $server;
115 }else{
116 if($this->member_of_ogroup){
117 $tmp2[$server]="["._("inherited")."]";
118 }
119 }
120 }
121 $this->nfsservers= $tmp2;
123 /* Set inherit checkbox state */
124 if(in_array("default",$this->gotoNtpServer)){
125 $this->inheritTimeServer = true;
126 $this->gotoNtpServer=array();
127 }
129 /* Create available ntp options */
130 $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
131 foreach($this->gotoNtpServers as $key => $server){
132 if($server == "default"){
133 unset($this->gotoNtpServers[$key]);
134 }
135 }
136 }
138 function check()
139 {
140 /* Call common method to give check the hook */
141 $message= plugin::check();
143 if (!$this->acl_is_createable() && $this->dn == "new"){
144 $message[]= msgPool::permCreate();
145 }
147 /* Check for valid ntpServer selection */
148 if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
149 $message[]= msgPool::required(_("NTP server"));
150 }
151 return($message);
152 }
154 function remove_from_parent()
155 {
156 /* Workstation startup is using gotoWorkstationTemplate too,
157 if we remove this oc all other not manged attributes will cause errors */
158 if(isset($this->attrs['gotoKernelParameters'])){
159 $this->objectclasses = array();
160 }
162 /* Remove acc */
163 plugin::remove_from_parent();
164 $ldap = $this->config->get_ldap_link();
165 $ldap->cd($this->orig_dn);
166 $ldap->modify($this->attrs);
167 $this->handle_post_events("remove");
168 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
169 }
173 function execute()
174 {
175 /* Call parent execute */
176 plugin::execute();
178 if(!$this->view_logged){
179 $this->view_logged = TRUE;
180 new log("view","ogroups/".get_class($this),$this->dn);
181 }
184 /***************
185 Handle requested action
186 ***************/
188 /* Handle the inherit to members button */
189 if (isset($_POST['inheritToMembers'])) {
190 $this->members_inherit_from_group = true;
191 }
193 /* Watch for events */
194 if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->mapActions[$_POST['saction']]) ){
196 /* Check if we have an DaemonEvent for this action */
197 $action = $this->mapActions[$_POST['saction']];
198 if(class_available("DaemonEvent")){
199 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
200 $macaddresses= array();
201 foreach ($this->members as $cn => $macAddress){
202 $macaddresses[]= $macAddress;
203 }
205 if(isset($events['TRIGGERED']["DaemonEvent_".$action])){
206 $evt = $events['TRIGGERED']["DaemonEvent_".$action];
207 $tmp = new $evt['CLASS_NAME']($this->config);
208 $tmp->add_targets($macaddresses);
209 $tmp->set_type(TRIGGERED_EVENT);
210 $o_queue = new gosaSupportDaemon();
211 if(!$o_queue->append($tmp)){
212 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
213 }
214 }
215 } else {
216 msg_dialog::display(_("Event error"),
217 sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG);
218 }
219 }
222 /***************
223 Add remove NTP server
224 ***************/
226 /* Add new ntp Server to our list */
227 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
228 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
229 }
231 /* Delete selected NtpServer for list of used servers */
232 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
233 foreach($_POST['gotoNtpServerSelected'] as $name){
234 unset($this->gotoNtpServer[$name]);
235 }
236 }
239 /***************
240 Prepare smarty
241 ***************/
243 /* Set government mode */
244 $smarty= get_smarty();
246 if (isset($this->parent->by_name['termstartup'])){
247 $smarty->assign("is_termgroup", "1");
248 } else {
249 $smarty->assign("is_termgroup", "0");
250 }
252 $tmp = $this->plInfo();
253 foreach($tmp['plProvidedAcls'] as $name => $translated) {
254 $smarty->assign($name."ACL",$this->getacl($name));
255 }
257 foreach($this->attributes as $attr){
258 $smarty->assign($attr, $this->$attr);
259 }
261 /* Variables */
262 foreach(array("gotoMode","gotoNtpServer") as $val){
263 $smarty->assign($val."_select", $this->$val);
264 }
266 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
267 "update" => _("Software update"),
268 "wake" => _("Wake"),
269 "reinstall" => _("Reinstall"),
270 "rescan" => _("Rescan hardware")
271 # "memcheck" => _("Memory test"),
272 # "sysinfo" => _("System analysis")
273 ));
275 $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
276 $smarty->assign("modes", $this->modes);
278 $tmp = array();
279 foreach($this->gotoNtpServers as $server){
280 if(!in_array($server,$this->gotoNtpServer)){
281 $tmp[$server] = $server;
282 }
283 }
285 $smarty->assign("gotoNtpServers",$tmp);
287 $smarty->assign("nfsservers", $this->nfsservers);
288 $smarty->assign("swapservers", $this->swapservers);
290 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
291 $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer);
293 /* Variables */
294 foreach(array("gotoTerminalPath", "gotoSwapServer") as $val){
295 $smarty->assign($val."_select", $this->$val);
296 }
299 /* Show main page */
300 return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE, dirname(__FILE__))));
301 }
304 function save_object()
305 {
306 plugin::save_object();
307 /* Set inherit mode */
308 if(isset($_POST['workgeneric_posted'])){
309 if(isset($_POST["inheritTimeServer"])){
310 $this->inheritTimeServer = true;
311 }else{
312 $this->inheritTimeServer = false;
313 }
314 }
315 }
317 /* Save to LDAP */
318 function save()
319 {
320 if (isset($this->parent->by_name['termstartup'])){
321 $this->objectclasses= array("gotoTerminalTemplate");
322 } else {
323 $this->objectclasses= array("gotoWorkstationTemplate");
324 }
326 plugin::save();
328 /* Tell members to inherit all attributes if the flag is set */
329 $this->inherit_attributes_to_members();
331 /***************
332 Prepare special vars
333 ***************/
335 /* Unset some special vars ... */
336 foreach (array("gotoSyslogServer") as $val){
337 if ($this->attrs[$val] == "default"){
338 $this->attrs[$val]= array();
339 }
340 }
342 /* Update ntp server settings */
343 if($this->inheritTimeServer){
344 $this->attrs['gotoNtpServer'] = "default";
345 }else{
346 /* Set ntpServers */
347 $this->attrs['gotoNtpServer'] = array();
348 foreach($this->gotoNtpServer as $server){
349 $this->attrs['gotoNtpServer'][] = $server;
350 }
351 }
354 /***************
355 Write to ldap
356 ***************/
358 /* Write back to ldap */
359 $ldap= $this->config->get_ldap_link();
360 $ldap->cd($this->dn);
361 $this->cleanup();
362 $ldap->modify ($this->attrs);
364 if($this->initially_was_account){
365 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
366 }else{
367 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
368 }
370 if(!$this->didAction){
371 $this->handle_post_events("modify");
372 }
373 if (!$ldap->success()){
374 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
375 }
376 }
379 static function plInfo()
380 {
381 return (array(
382 "plShortName" => _("System"),
383 "plDescription" => _("System group"),
384 "plSelfModify" => FALSE,
385 "plDepends" => array(),
386 "plPriority" => 5,
387 "plSection" => array("administration"),
388 "plCategory" => array("ogroups"),
389 "plProvidedAcls"=> array(
390 "gotoMode" => _("Mode"),
391 "gotoSyslogServer" => _("Syslog server"),
392 "FAIstate" => _("Action flag"),
393 "gotoNtpServer" => _("Ntp server"),
394 "gotoTerminalPath" => _("Root server"),
395 "gotoSwapServer" => _("Swap server"))
396 ));
397 }
399 function inherit_attributes_to_members()
400 {
401 if ($this->members_inherit_from_group) {
402 foreach ($this->member_dn as $dn) {
403 $member_obj = new worktabs($this->config, $this->config->data['TABS']['WORKTABS'], $dn);
404 $member_obj->by_object['workgeneric']->set_everything_to_inherited();
405 $member_obj->save();
406 }
407 }
408 }
410 function PrepareForCopyPaste($source)
411 {
412 /* Create used ntp server array */
413 $this->gotoNtpServer= array();
415 if(isset($source['gotoNtpServer'])){
416 $this->inheritTimeServer = false;
417 unset($source['gotoNtpServer']['count']);
418 foreach($source['gotoNtpServer'] as $server){
419 $this->gotoNtpServer[$server] = $server;
420 }
421 }
423 /* Set inherit checkbox state */
424 if(in_array("default",$this->gotoNtpServer)){
425 $this->inheritTimeServer = true;
426 $this->gotoNtpServer=array();
427 }
429 /* Create available ntp options */
430 $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
431 foreach($this->gotoNtpServers as $key => $server){
432 if($server == "default"){
433 unset($this->gotoNtpServers[$key]);
434 }
435 }
436 }
437 }
439 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
440 ?>