1 <?php
3 class termgroup extends plugin
4 {
5 /* attribute list for save action */
6 var $attributes= array("gotoMode","gotoSyslogServer", "gotoNtpServer");
7 var $objectclasses= array("gotoWorkstationTemplate");
9 var $members= array();
11 var $gotoMode = "locked";
12 var $gotoSyslogServer = "";
13 var $gotoNtpServer = array();
14 var $gotoNtpServers = array();
15 var $modes = array();
16 var $inheritTimeServer = true;
17 var $is_account = true;
18 var $orig_dn = "";
19 var $didAction = FALSE;
20 var $mapActions = array("reboot" => "",
21 "instant_update" => "softupdate",
22 "update" => "sceduledupdate",
23 "reinstall" => "install",
24 "rescan" => "",
25 "memcheck" => "memcheck",
26 "sysinfo" => "sysinfo");
29 function termgroup ($config, $dn= NULL)
30 {
31 /***************
32 Some initialisations
33 ***************/
35 plugin::plugin($config, $dn);
37 $ldap= $config->get_ldap_link();
39 $this->is_account = true;
40 $this->modes["active"]= _("Activated");
41 $this->modes["locked"]= _("Locked");
42 // $this->modes["memcheck"]= _("Memory test");
43 // $this->modes["sysinfo"]= _("System analysis");
45 $this->orig_dn = $this->dn;
47 /***************
48 Get mac addresses from member objects
49 ***************/
51 /* We're only interested in the terminal members here, evaluate
52 these... */
53 if(isset($this->attrs['member'])){
54 for ($i= 0; $i<$this->attrs['member']['count']; $i++){
55 $member= $this->attrs['member'][$i];
56 $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
57 if (preg_match("/success/i", $ldap->error)){
58 $attrs = $ldap->fetch();
59 if (in_array("gotoTerminal", $attrs['objectClass']) ||
60 in_array("gotoWorkstation", $attrs['objectClass'])){
61 if (isset($attrs['macAddress'])){
62 $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
63 } else {
64 $this->members[$attrs['cn'][0]]= "";
65 }
66 }
67 }
68 }
69 }
71 /***************
72 Perpare NTP settings
73 ***************/
75 /* Create used ntp server array */
76 $this->gotoNtpServer= array();
77 if(isset($this->attrs['gotoNtpServer'])){
78 $this->inheritTimeServer = false;
79 unset($this->attrs['gotoNtpServer']['count']);
80 foreach($this->attrs['gotoNtpServer'] as $server){
81 $this->gotoNtpServer[$server] = $server;
82 }
83 }
85 /* Set inherit checkbox state */
86 if(in_array("default",$this->gotoNtpServer)){
87 $this->inheritTimeServer = true;
88 $this->gotoNtpServer=array();
89 }
91 /* Create available ntp options */
92 $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
93 foreach($this->gotoNtpServers as $key => $server){
94 if($server == "default"){
95 unset($this->gotoNtpServers[$key]);
96 }
97 }
100 }
102 function check()
103 {
104 /* Call common method to give check the hook */
105 $message= plugin::check();
107 if ($this->acl_is_createable()){
108 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
109 }
111 /* Check for valid ntpServer selection */
112 if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
113 $message[]= _("There must be at least one NTP server selected.");
114 }
115 return($message);
116 }
118 function remove_from_parent()
119 {
120 /* Workstation startup is using gotoWorkstationTemplate too,
121 if we remove this oc all other not manged attributes will cause errors */
122 if(isset($this->attrs['gotoKernelParameters'])){
123 $this->objectclasses = array();
124 }
126 /* Remove acc */
127 plugin::remove_from_parent();
128 $ldap = $this->config->get_ldap_link();
129 $ldap->cd($this->orig_dn);
130 $ldap->modify($this->attrs);
131 $this->handle_post_events("remove");
132 }
134 function execute()
135 {
136 /* Call parent execute */
137 plugin::execute();
140 /***************
141 Handle requested action
142 ***************/
144 /* Watch for events */
145 if (isset($_POST['action'])){
146 $macaddresses="";
147 $names="";
148 foreach ($this->members as $cn => $macAddress){
149 $macaddresses.= "$macAddress ";
150 $names.= "$cn ";
151 }
153 if (isset($_POST['action'])){
154 $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
156 if ($cmd == ""){
157 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
158 } else {
159 exec ($cmd." ".$macaddresses." ".escapeshellarg($_POST['saction']), $dummy, $retval);
160 if ($retval != 0){
161 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
162 } else {
163 $this->didAction= TRUE;
165 /* Get dns from member objects. Create ldap object */
166 $member = $this->parent->by_object['ogroup']->member;
167 $ldap = $this->config->get_ldap_link();
168 $ldap->cd($this->config->current['BASE']);
170 /* walk trough members and add FAIstate */
171 foreach($member as $dn => $object){
173 /* Get object */
174 $ldap->cat($dn,array("objectClass"));
175 $res = $ldap->fetch();
176 $attrs = array();
178 /* Add FAI state */
179 $attrs['FAIstate'] = "";
180 if(isset($this->mapActions[$_POST['saction']])){
181 $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
182 }
184 /* Fix objectClass index */
185 for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
186 $attrs['objectClass'][] = $res['objectClass'][$i];
187 }
189 /* Check if we must add the objectClass */
190 if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
191 $attrs['objectClass'][] = "FAIobject";
192 }
194 if($attrs['FAIstate'] == ""){
195 $attrs['FAIstate'] = array();
196 }
198 $ldap->cd($dn);
199 $ldap->modify($attrs);
200 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic (FAIstate) with dn '%s' failed."),$dn));
201 }
202 $this->didAction= TRUE;
203 }
204 }
205 }
206 }
209 /***************
210 Add remove NTP server
211 ***************/
213 /* Add new ntp Server to our list */
214 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
215 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
216 }
218 /* Delete selected NtpServer for list of used servers */
219 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
220 foreach($_POST['gotoNtpServerSelected'] as $name){
221 unset($this->gotoNtpServer[$name]);
222 }
223 }
226 /***************
227 Prepare smarty
228 ***************/
230 /* Set government mode */
231 $smarty= get_smarty();
233 $tmp = $this->plInfo();
234 foreach($tmp['plProvidedAcls'] as $name => $translated) {
235 $smarty->assign($name."ACL",$this->getacl($name));
236 }
238 foreach($this->attributes as $attr){
239 $smarty->assign($attr, $this->$attr);
240 }
242 /* Variables */
243 foreach(array("gotoMode","gotoNtpServer") as $val){
244 $smarty->assign($val."_select", $this->$val);
245 }
247 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
248 "instant_update" => _("Instant update"),
249 "update" => _("Scheduled update"),
250 "reinstall" => _("Reinstall"),
251 "rescan" => _("Rescan hardware"),
252 "memcheck" => _("Memory test"),
253 "sysinfo" => _("System analysis")));
255 $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
256 $smarty->assign("modes", $this->modes);
258 $tmp = array();
259 foreach($this->gotoNtpServers as $server){
260 if(!in_array($server,$this->gotoNtpServer)){
261 $tmp[$server] = $server;
262 }
263 }
265 $smarty->assign("gotoNtpServers",$tmp);
266 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
267 $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer);
269 /* Show main page */
270 return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
271 }
273 function save_object()
274 {
275 plugin::save_object();
276 /* Set inherit mode */
277 if(isset($_POST['workgeneric_posted'])){
278 if(isset($_POST["inheritTimeServer"])){
279 $this->inheritTimeServer = true;
280 }else{
281 $this->inheritTimeServer = false;
282 }
283 }
284 }
286 /* Save to LDAP */
287 function save()
288 {
289 plugin::save();
291 /***************
292 Prepare special vars
293 ***************/
295 /* Unset some special vars ... */
296 foreach (array("gotoSyslogServer") as $val){
297 if ($this->attrs[$val] == "default"){
298 $this->attrs[$val]= array();
299 }
300 }
302 /* Update ntp server settings */
303 if($this->inheritTimeServer){
304 $this->attrs['gotoNtpServer'] = "default";
305 }else{
306 /* Set ntpServers */
307 $this->attrs['gotoNtpServer'] = array();
308 foreach($this->gotoNtpServer as $server){
309 $this->attrs['gotoNtpServer'][] = $server;
310 }
311 }
314 /***************
315 Write to ldap
316 ***************/
318 /* Write back to ldap */
319 $ldap= $this->config->get_ldap_link();
320 $ldap->cd($this->dn);
321 $this->cleanup();
322 $ldap->modify ($this->attrs);
324 if(!$this->didAction){
325 $this->handle_post_events("modify");
326 }
327 show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
329 }
331 function plInfo()
332 {
333 return (array(
334 "plShortName" => _("System"),
335 "plDescription" => _("System group"),
336 "plSelfModify" => FALSE,
337 "plDepends" => array(),
338 "plPriority" => 0,
339 "plSection" => array("administration"),
340 "plCategory" => array("ogroups"),
341 "plProvidedAcls"=> array(
342 "gotoMode" => _("Mode"),
343 "gotoSyslogServer" => _("Syslog server"),
344 "FAIstate" => _("Action flag"),
345 "gotoNtpServer" => _("Ntp server"))
346 ));
347 }
351 }
353 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
354 ?>