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;
23 function termgroup ($config, $dn= NULL)
24 {
25 /***************
26 Some initialisations
27 ***************/
29 plugin::plugin($config, $dn);
31 $ldap= $config->get_ldap_link();
33 $this->is_account = true;
34 $ui = get_userinfo();
35 $acl = get_permissions ($this->dn, $ui->subtreeACL);
36 $this->acl = get_module_permission($acl, "group", $this->dn);
38 $this->modes["active"]= _("Activated");
39 $this->modes["locked"]= _("Locked");
40 $this->modes["memcheck"]= _("Memory test");
41 $this->modes["sysinfo"]= _("System analysis");
43 $this->orig_dn = $this->dn;
45 /***************
46 Get mac addresses from member objects
47 ***************/
49 /* We're only interested in the terminal members here, evaluate
50 these... */
51 if(isset($this->attrs['member'])){
52 for ($i= 0; $i<$this->attrs['member']['count']; $i++){
53 $member= $this->attrs['member'][$i];
54 $ldap->cat($member, array('objectClass', 'macAddress', 'cn'));
55 if (preg_match("/success/i", $ldap->error)){
56 $attrs = $ldap->fetch();
57 if (in_array("gotoTerminal", $attrs['objectClass']) ||
58 in_array("gotoWorkstation", $attrs['objectClass'])){
59 if (isset($attrs['macAddress'])){
60 $this->members[$attrs['cn'][0]]= $attrs['macAddress'][0];
61 } else {
62 $this->members[$attrs['cn'][0]]= "";
63 }
64 }
65 }
66 }
67 }
69 /***************
70 Perpare NTP settings
71 ***************/
73 /* Create used ntp server array */
74 $this->gotoNtpServer= array();
75 if(isset($this->attrs['gotoNtpServer'])){
76 $this->inheritTimeServer = false;
77 unset($this->attrs['gotoNtpServer']['count']);
78 foreach($this->attrs['gotoNtpServer'] as $server){
79 $this->gotoNtpServer[$server] = $server;
80 }
81 }
83 /* Set inherit checkbox state */
84 if(in_array("default",$this->gotoNtpServer)){
85 $this->inheritTimeServer = true;
86 $this->gotoNtpServer=array();
87 }
89 /* Create available ntp options */
90 $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
91 foreach($this->gotoNtpServers as $key => $server){
92 if($server == "default"){
93 unset($this->gotoNtpServers[$key]);
94 }
95 }
98 }
100 function check()
101 {
102 /* Call common method to give check the hook */
103 $message= plugin::check();
105 if (chkacl($this->acl, "create") != ""){
106 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
107 }
109 /* Check for valid ntpServer selection */
110 if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
111 $message[]= _("There must be at least one NTP server selected.");
112 }
113 return($message);
114 }
116 function remove_from_parent()
117 {
118 /* Workstation startup is using gotoWorkstationTemplate too,
119 if we remove this oc all other not manged attributes will cause errors */
120 if(isset($this->attrs['gotoKernelParameters'])){
121 $this->objectclasses = array();
122 }
124 /* Remove acc */
125 plugin::remove_from_parent();
126 $ldap = $this->config->get_ldap_link();
127 $ldap->cd($this->orig_dn);
128 $ldap->modify($this->attrs);
129 $this->handle_post_events("remove");
130 }
132 function execute()
133 {
134 /* Call parent execute */
135 plugin::execute();
138 /***************
139 Handle requested action
140 ***************/
142 /* Watch for events */
143 if (isset($_POST['action'])){
144 $macaddresses="";
145 $names="";
146 foreach ($this->members as $cn => $macAddress){
147 $macaddresses.= "$macAddress ";
148 $names.= "$cn ";
149 }
151 if (isset($_POST['action'])){
152 $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
153 if ($cmd == ""){
154 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
155 } else {
156 exec ($cmd." ".$macaddresses." ".escapeshellarg($_POST['saction']), $dummy, $retval);
157 if ($retval != 0){
158 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
159 } else {
160 $this->didAction= TRUE;
161 }
162 }
163 }
164 }
167 /***************
168 Add remove NTP server
169 ***************/
171 /* Add new ntp Server to our list */
172 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
173 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
174 }
176 /* Delete selected NtpServer for list of used servers */
177 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
178 foreach($_POST['gotoNtpServerSelected'] as $name){
179 unset($this->gotoNtpServer[$name]);
180 }
181 }
184 /***************
185 Prepare smarty
186 ***************/
188 /* Set government mode */
189 $smarty= get_smarty();
191 foreach($this->attributes as $attr){
192 $smarty->assign($attr, $this->$attr);
193 $smarty->assign($attr."ACL",chkacl($this->acl,$this->$attr));
194 }
196 /* Variables */
197 foreach(array("gotoMode","gotoNtpServer") as $val){
198 $smarty->assign($val."_select", $this->$val);
199 $smarty->assign($val."ACL", chkacl($this->acl, $val));
200 }
202 /* Check if workstation is online */
203 $smarty->assign("actions", array(
204 "halt" => _("Switch off"),
205 "reboot" => _("Reboot"),
206 "instant_update" => _("Instant update"),
207 "update" => _("Scheduled update"),
208 "reinstall" => _("Reinstall"),
209 "rescan" => _("Rescan hardware")));
211 $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
212 $smarty->assign("modes", $this->modes);
213 $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
214 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
216 $tmp = array();
217 foreach($this->gotoNtpServers as $server){
218 if(!in_array($server,$this->gotoNtpServer)){
219 $tmp[$server] = $server;
220 }
221 }
223 $smarty->assign("gotoNtpServers",$tmp);
224 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
225 $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer);
227 /* Show main page */
228 return ($smarty->fetch (get_template_path('termgroup.tpl', TRUE)));
229 }
231 function save_object()
232 {
233 plugin::save_object();
234 /* Set inherit mode */
235 if(isset($_POST['workgeneric_posted'])){
236 if(isset($_POST["inheritTimeServer"])){
237 $this->inheritTimeServer = true;
238 }else{
239 $this->inheritTimeServer = false;
240 }
241 }
242 }
244 /* Save to LDAP */
245 function save()
246 {
247 plugin::save();
249 /***************
250 Prepare special vars
251 ***************/
253 /* Unset some special vars ... */
254 foreach (array("gotoSyslogServer") as $val){
255 if ($this->attrs[$val] == "default"){
256 $this->attrs[$val]= array();
257 }
258 }
260 /* Update ntp server settings */
261 if($this->inheritTimeServer){
262 $this->attrs['gotoNtpServer'] = "default";
263 }else{
264 /* Set ntpServers */
265 $this->attrs['gotoNtpServer'] = array();
266 foreach($this->gotoNtpServer as $server){
267 $this->attrs['gotoNtpServer'][] = $server;
268 }
269 }
272 /***************
273 Write to ldap
274 ***************/
276 /* Write back to ldap */
277 $ldap= $this->config->get_ldap_link();
278 if ($this->orig_dn == 'new'){
279 $ldap->cd($this->config->current['BASE']);
280 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
281 $ldap->cd($this->dn);
282 $ldap->add($this->attrs);
283 if(!$this->didAction){
284 $this->handle_post_events("add");
285 }
286 } else {
287 if ($this->orig_dn != $this->dn){
288 $this->move($this->orig_dn, $this->dn);
289 }
290 $ldap->cd($this->dn);
291 $this->cleanup();
292 $ldap->modify ($this->attrs);
294 if(!$this->didAction){
295 $this->handle_post_events("modify");
296 }
297 }
298 show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
299 }
300 }
302 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
303 ?>