967ebc6f836f65699aff134e0394f1c74ecb3bd9
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 $acl ;
18 var $is_account = true;
19 var $orig_dn = "";
20 var $didAction = FALSE;
22 var $mapActions = array("reboot" => "localboot",
23 "instant_update" => "softupdate",
24 "update" => "sceduledupdate",
25 "reinstall" => "install",
26 "rescan" => "",
27 "memcheck" => "memcheck",
28 "sysinfo" => "sysinfo");
31 function termgroup ($config, $dn= NULL)
32 {
33 /***************
34 Some initialisations
35 ***************/
37 plugin::plugin($config, $dn);
39 $ldap= $config->get_ldap_link();
41 $this->is_account = true;
42 $ui = get_userinfo();
43 $acl = get_permissions ($this->dn, $ui->subtreeACL);
44 $this->acl = get_module_permission($acl, "group", $this->dn);
46 $this->modes["active"]= _("Activated");
47 $this->modes["locked"]= _("Locked");
48 $this->modes["memcheck"]= _("Memory test");
49 $this->modes["sysinfo"]= _("System analysis");
51 $this->orig_dn = $this->dn;
53 /***************
54 Get mac addresses from member objects
55 ***************/
57 /* We're only interested in the terminal members here, evaluate
58 these... */
59 if(isset($this->attrs['member'])){
60 for ($i= 0; $i<$this->attrs['member']['count']; $i++){
61 $member= $this->attrs['member'][$i];
62 $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
63 if (preg_match("/success/i", $ldap->error)){
64 $attrs = $ldap->fetch();
65 if (in_array("gotoTerminal", $attrs['objectClass']) ||
66 in_array("gotoWorkstation", $attrs['objectClass'])){
67 if (isset($attrs['macAddress'])){
68 $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
69 } else {
70 $this->members[$attrs['cn'][0]]= "";
71 }
72 }
73 }
74 }
75 }
77 /***************
78 Perpare NTP settings
79 ***************/
81 /* Create used ntp server array */
82 $this->gotoNtpServer= array();
83 if(isset($this->attrs['gotoNtpServer'])){
84 $this->inheritTimeServer = false;
85 unset($this->attrs['gotoNtpServer']['count']);
86 foreach($this->attrs['gotoNtpServer'] as $server){
87 $this->gotoNtpServer[$server] = $server;
88 }
89 }
91 /* Set inherit checkbox state */
92 if(in_array("default",$this->gotoNtpServer)){
93 $this->inheritTimeServer = true;
94 $this->gotoNtpServer=array();
95 }
97 /* Create available ntp options */
98 $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
99 foreach($this->gotoNtpServers as $key => $server){
100 if($server == "default"){
101 unset($this->gotoNtpServers[$key]);
102 }
103 }
106 }
108 function check()
109 {
110 /* Call common method to give check the hook */
111 $message= plugin::check();
113 if (chkacl($this->acl, "create") != ""){
114 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
115 }
117 /* Check for valid ntpServer selection */
118 if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
119 $message[]= _("There must be at least one NTP server selected.");
120 }
121 return($message);
122 }
124 function remove_from_parent()
125 {
126 /* Workstation startup is using gotoWorkstationTemplate too,
127 if we remove this oc all other not manged attributes will cause errors */
128 if(isset($this->attrs['gotoKernelParameters'])){
129 $this->objectclasses = array();
130 }
132 /* Remove acc */
133 plugin::remove_from_parent();
134 $ldap = $this->config->get_ldap_link();
135 $ldap->cd($this->orig_dn);
136 $ldap->modify($this->attrs);
137 $this->handle_post_events("remove");
138 }
141 function update_term_member_FAIstate($act)
142 {
143 /* Get required informations */
144 $og = $this->parent->by_object['ogroup'];
145 $allobs = $og->allobjects;
146 $mem = $og->member;
148 /* Get correct value for FAIstate */
149 $action = $this->mapActions[$act];
151 /* Get ldap connection */
152 $ldap = $this->config->get_ldap_link();
153 $ldap->cd ($this->config->current['BASE']);
155 /* Foreach member of mthis ogroup ... */
156 foreach($mem as $key ){
158 /* check objectClasses and create attributes array */
159 $attrs = array("FAIstate"=>$action);
160 for($i = 0; $i < $allobs[$key]['objectClass']['count'] ; $i ++){
161 $attrs['objectClass'][] = $allobs[$key]['objectClass'][$i];
162 }
163 if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
164 $attrs['objectClass'][] = "FAIobject";
165 }
166 if($attrs['FAIstate'] == ""){
167 $attrs['FAIstate'] = array();
168 }
170 /* If this objects is workstation,terminal or server upodate FAIstate */
171 if(preg_match("/(w|t|s)/i",$allobs[$key]['type'])){
172 $ldap->cd ($key);
173 $ldap->modify($attrs);
174 show_ldap_error($ldap->get_error(),sprintf(_("Setting action state (FAIstate) failed for object '%s', value was '%s'."),$key,$action));
176 if(!preg_match("/success/i",$ldap->get_error())) {
177 gosa_log("FAILED !! Updating FAIstate to '".$action."' : ".$key);
178 }else{
179 gosa_log("OK. Updating FAIstate to '".$action."' : ".$key);
180 }
181 }
182 }
183 }
186 function execute()
187 {
188 /* Call parent execute */
189 plugin::execute();
192 /***************
193 Handle requested action
194 ***************/
196 /* Watch for events */
197 if (isset($_POST['action'])){
198 $macaddresses="";
199 $names="";
200 foreach ($this->members as $cn => $macAddress){
201 $macaddresses.= "$macAddress ";
202 $names.= "$cn ";
203 }
205 if (isset($_POST['action'])){
207 /* Update members fai state */
208 $this->update_term_member_FAIstate(trim($_POST['saction']));
210 $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
211 if ($cmd == ""){
212 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
213 } else {
214 exec ($cmd." ".$macaddresses." ".escapeshellarg($_POST['saction']), $dummy, $retval);
215 if ($retval != 0){
216 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
217 } else {
218 $this->didAction= TRUE;
219 }
220 }
221 }
222 }
225 /***************
226 Add remove NTP server
227 ***************/
229 /* Add new ntp Server to our list */
230 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
231 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
232 }
234 /* Delete selected NtpServer for list of used servers */
235 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
236 foreach($_POST['gotoNtpServerSelected'] as $name){
237 unset($this->gotoNtpServer[$name]);
238 }
239 }
242 /***************
243 Prepare smarty
244 ***************/
246 /* Set government mode */
247 $smarty= get_smarty();
249 foreach($this->attributes as $attr){
250 $smarty->assign($attr, $this->$attr);
251 $smarty->assign($attr."ACL",chkacl($this->acl,$this->$attr));
252 }
254 /* Variables */
255 foreach(array("gotoMode","gotoNtpServer") as $val){
256 $smarty->assign($val."_select", $this->$val);
257 $smarty->assign($val."ACL", chkacl($this->acl, $val));
258 }
260 /* Check if workstation is online */
261 $smarty->assign("actions", array(
262 "halt" => _("Switch off"),
263 "reboot" => _("Reboot"),
264 "instant_update" => _("Instant update"),
265 "update" => _("Scheduled update"),
266 "reinstall" => _("Reinstall"),
267 "rescan" => _("Rescan hardware")));
269 $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
270 $smarty->assign("modes", $this->modes);
271 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
272 $smarty->assign("gotoNtpServers",$this->gotoNtpServers);
273 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
274 $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer);
276 /* Show main page */
277 return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
278 }
280 function save_object()
281 {
282 plugin::save_object();
283 /* Set inherit mode */
284 if(isset($_POST['workgeneric_posted'])){
285 if(isset($_POST["inheritTimeServer"])){
286 $this->inheritTimeServer = true;
287 }else{
288 $this->inheritTimeServer = false;
289 }
290 }
291 }
293 /* Save to LDAP */
294 function save()
295 {
296 plugin::save();
298 /***************
299 Prepare special vars
300 ***************/
302 /* Unset some special vars ... */
303 foreach (array("gotoSyslogServer") as $val){
304 if ($this->attrs[$val] == "default"){
305 $this->attrs[$val]= array();
306 }
307 }
309 /* Update ntp server settings */
310 if($this->inheritTimeServer){
311 $this->attrs['gotoNtpServer'] = "default";
312 }else{
313 /* Set ntpServers */
314 $this->attrs['gotoNtpServer'] = array();
315 foreach($this->gotoNtpServer as $server){
316 $this->attrs['gotoNtpServer'][] = $server;
317 }
318 }
321 /***************
322 Write to ldap
323 ***************/
325 /* Write back to ldap */
326 $ldap= $this->config->get_ldap_link();
327 $ldap->cd($this->dn);
328 $this->cleanup();
329 $ldap->modify ($this->attrs);
331 if(!$this->didAction){
332 $this->handle_post_events("modify");
333 }
334 show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
335 }
336 }
338 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
339 ?>