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