e6b46ca26e9efb2d8ec0205cd0d43e8555a716ff
1 <?php
2 class workstartup extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage terminal startup options";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Generic terminal attributes */
10 var $bootmode= "G";
11 var $goLdapServerList= array("default");
12 var $gotoBootKernel= "default";
13 var $gotoKernelParameters= "";
14 var $gotoLdapServer= "";
15 var $gotoModules= array();
16 var $gotoAutoFs= array();
17 var $gotoFilesystem= array();
18 var $gotoTerminalPath= "";
19 var $FAIstatus= "";
20 var $FAIclass = array();
21 var $FAIclasses = array();
22 var $FAIclassInfo = array();
23 var $FAIdebianMirror = array();
26 /* attribute list for save action */
27 var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror");
28 var $objectclasses= array("GOhard", "FAIobject");
30 /* Share */
31 var $gotoShares = array();// Currently Share Option
32 var $gotoShare = ""; // currently selected Share Option
33 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34 var $gotoAvailableShares= array();// Available Shares for this account
36 /* Helper */
37 var $customParameters= "";
38 var $orig_dn= "";
39 var $ignore_account= TRUE;
40 var $FAIdebianMirrors = array();
42 function workstartup ($config, $dn= NULL)
43 {
44 plugin::plugin ($config, $dn);
46 // Create Mirror
47 $this->FAIdebianMirrors=array();
48 $path = "/etc/gosa/fai/";
49 $suffix = "http://";
50 if(is_readable($path)){
51 $od= opendir($path);
52 if($od){
53 while($dir = readdir($od)){
54 if((is_dir($path.$dir))&&($dir[0]!=".")){
55 $this->FAIdebianMirrors[$suffix.$dir]=$suffix.$dir;
56 }
57 }
58 }
59 }
61 /* Get arrays */
62 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
63 if (isset($this->attrs["$val"]["count"])){
64 for ($i= 0; $i<$this->attrs["count"]; $i++){
65 if (isset($this->attrs["$val"][$i])){
66 array_push($this->$val, $this->attrs["$val"][$i]);
67 }
68 }
69 }
70 sort ($this->$val);
71 $this->$val= array_unique($this->$val);
72 }
74 /* Parse Kernel Parameters to decide what boot mode is enabled */
75 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
76 $this->bootmode= "G";
77 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
78 $this->bootmode= "D";
79 } elseif ($this->gotoKernelParameters == "") {
80 $this->bootmode= "G";
81 } else {
82 $this->bootmode= "T";
83 }
84 if (preg_match("/ o /", $this->gotoKernelParameters)){
85 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
86 } else {
87 $this->customParameters= "";
88 }
90 /* Prepare Shares */
91 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
92 unset($this->attrs['gotoShare']['count']);
93 foreach($this->attrs['gotoShare'] as $share){
94 $tmp = $tmp2 = array();
95 $tmp = split("\|",$share);
96 $tmp2['server'] =$tmp[0];
97 $tmp2['name'] =$tmp[1];
98 $tmp2['mountPoint'] =$tmp[2];
99 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
100 }
101 }
103 $this->gotoShareSelections= $config->getShareList(true);
104 $this->gotoAvailableShares= $config->getShareList(false);
105 $tmp2 = array();
107 //$ldap->cd($base);
108 $ldap = $this->config->get_ldap_link();
109 $ldap->cd($this->config->current['BASE']);
110 $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)
111 (objectClass=FAIvariable)(objectClass=FAIscript')(objectClass=FAIhook)
112 (objectClass=FAIpartitionTable))",array("objectClass","cn"),true);
113 while($attr = $ldap->fetch()){
114 $cn = $attr['cn'][0];
115 if(in_array('FAIpackageList',$attr['objectClass'])){
116 $tmp2[$cn]['FAIpackageList']['obj'] = 'FAIpackageList';
117 $tmp2[$cn]['FAIpackageList']['kzl'] = 'P';
118 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
119 }
120 if(in_array('FAItemplate',$attr['objectClass'])){
121 $tmp2[$cn]['FAItemplate']['obj'] = 'FAItemplate';
122 $tmp2[$cn]['FAItemplate']['kzl'] = 'T';
123 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
124 }
125 if(in_array('FAIvariable',$attr['objectClass'])){
126 $tmp2[$cn]['FAIvariable']['obj'] = 'FAIvariable';
127 $tmp2[$cn]['FAIvariable']['kzl'] = 'V';
128 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
129 }
130 if(in_array('FAIscript',$attr['objectClass'])){
131 $tmp2[$cn]['FAIscript']['obj'] = 'FAIscript';
132 $tmp2[$cn]['FAIscript']['kzl'] = 'S';
133 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
134 }
135 if(in_array('FAIhook',$attr['objectClass'])){
136 $tmp2[$cn]['FAIhook']['obj'] = 'FAIhook';
137 $tmp2[$cn]['FAIhook']['kzl'] = 'H';
138 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
139 }
140 if(in_array('FAIpartitionTable',$attr['objectClass'])){
141 $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable';
142 $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt';
143 $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
144 }
145 }
147 $this->FAIclassInfo = $tmp2;
149 if(isset($this->attrs['FAIclass'])){
150 $tmp = array();
151 $tmp2 = $this->attrs['FAIclass'];
152 unset($tmp2['count']);
153 foreach($tmp2 as $class){
154 $tmp[$class] = $class;
155 }
156 $this->FAIclass = $tmp;
157 }
159 if(!is_array($this->FAIclass)){
160 $this->FAIclass = array();
161 }
164 $this->orig_dn= $this->dn;
165 }
167 function selectFriendlyClasses(){
168 $tmp=array();
169 foreach($this->FAIclasses as $class){
170 $str = "";
171 if(isset($this->FAIclassInfo[$class])){
172 foreach($this->FAIclassInfo[$class] as $objs){
173 $str .= $objs['kzl']." ";
174 }
175 }
176 $tmp[$class] = $class." [".$str."]";
177 }
178 return($tmp);
179 }
181 function execute()
182 {
183 /* Do we need to flip is_account state? */
184 if (isset($_POST['modify_state'])){
185 $this->is_account= !$this->is_account;
186 }
189 /* Do we represent a valid terminal? */
190 if (!$this->is_account && $this->parent == NULL){
191 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
192 _("This 'dn' has no terminal features.")."</b>";
193 return ($display);
194 }
196 /* Add module */
197 if (isset ($_POST['add_module'])){
198 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
199 $this->add_list ($this->gotoModules, $_POST['module']);
200 }
201 }
203 /* Delete module */
204 if (isset ($_POST['delete_module'])){
205 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
206 $this->del_list ($this->gotoModules, $_POST['modules_list']);
207 }
208 }
210 /* FAI class management */
211 if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
213 $found = 0 ;
215 foreach($this->FAIclass as $name){
216 if(isset($this->FAIclassInfo[$name])){
217 foreach($this->FAIclassInfo[$name] as $atr){
218 if($atr['obj'] == "FAIpartitionTable"){
219 $found ++ ;
220 }
221 }
222 }
223 }
225 if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpackageList']))&&($found>0)){
226 print_red(_("There is already a profile in your selection that contain partition table configuratons."));
227 }else{
228 $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
229 }
230 }
232 if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
233 if(isset($this->FAIclass[$_POST['FAIclassSel']])){
234 unset($this->FAIclass[$_POST['FAIclassSel']]);
235 }
236 }
238 /* Show main page */
239 $smarty= get_smarty();
241 /* In this section server shares will be defined
242 * A user can select one of the given shares and a mount point
243 * and attach this combination to his setup.
244 */
245 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
246 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
248 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
249 * This entry will be, a combination of mountPoint and sharedefinitions
250 */
251 if(isset($_POST['gotoShareAdd'])){
252 /* We assign a share to this user, if we don't know where to mount the share */
253 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
254 print_red(_("You must specify a valid mount point."));
255 }else{
256 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
257 $s_mount = $_POST['gotoShareMountPoint'];
258 /* Preparing the new assignment */
259 $this->gotoShares[$a_share['name']]=$a_share;
260 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
261 }
262 }
264 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
265 * If there is no defined share selected, we will abort the deletion without any message
266 */
267 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
268 unset($this->gotoShares[$_POST['gotoShare']]);
269 }
271 $smarty->assign("gotoShares",$this->printOutAssignedShares());
272 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
274 /* Arrays */
275 $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
276 $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
277 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
278 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
279 $smarty->assign("$val", $this->$val);
280 }
282 /* Values */
283 foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror") as $val){
284 $smarty->assign($val, $this->$val);
285 $smarty->assign($val."ACL", chkacl($this->acl, $val));
286 }
288 $smarty->assign("FAIdebianMirrors",$this->FAIdebianMirrors);
290 $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
291 $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
292 $smarty->assign("FAIclassKeys",$this->FAIclass);
294 /* Radio button group */
295 if (preg_match("/G/", $this->bootmode)) {
296 $smarty->assign("graphicalbootup", "checked");
297 } else {
298 $smarty->assign("graphicalbootup", "");
299 }
300 if (preg_match("/T/", $this->bootmode)) {
301 $smarty->assign("textbootup", "checked");
302 } else {
303 $smarty->assign("textbootup", "");
304 }
305 if (preg_match("/D/", $this->bootmode)) {
306 $smarty->assign("debugbootup", "checked");
307 } else {
308 $smarty->assign("debugbootup", "");
309 }
311 /* ACL's */
312 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
313 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
314 }
316 /* Show main page */
317 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
318 }
320 function remove_from_parent()
321 {
322 $ldap= $this->config->get_ldap_link();
323 $ldap->rmdir($this->dn);
324 show_ldap_error($ldap->get_error());
325 $this->handle_post_events("remove");
326 }
329 /* Save data to object */
330 function save_object()
331 {
332 plugin::save_object();
334 /* Save group radio buttons */
335 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
336 $this->bootmode= $_POST["bootmode"];
337 }
339 /* Save kernel parameters */
340 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
341 $this->customParameters= $_POST["customParameters"];
342 }
343 }
346 /* Save to LDAP */
347 function save()
348 {
349 /* Find proper terminal path for tftp configuration
350 FIXME: This is suboptimal when the default has changed to
351 another location! */
352 if ($this->gotoTerminalPath == "default"){
353 $ldap= $this->config->get_ldap_link();
355 /* Strip relevant part from dn, keep trailing ',' */
356 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
357 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
359 /* Walk from top to base and try to load default values for
360 'gotoTerminalPath'. Abort when an entry is found. */
361 while (TRUE){
362 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
364 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
365 $this->config->current['BASE']);
366 $attrs= $ldap->fetch();
367 if (isset($attrs['gotoTerminalPath'])){
368 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
369 break;
370 }
372 /* Nothing left? */
373 if ($tmp == ""){
374 break;
375 }
376 }
377 }
379 /* Add semi automatic values */
380 // FIXME: LDAP Server may not be set here...
381 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
382 $this->gotoTerminalPath.
383 ",ro,hard,nolock,fg,rsize=8192 ".
384 "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
386 switch ($this->bootmode){
387 case "D":
388 $this->gotoKernelParameters.= " debug";
389 break;
390 case "G":
391 $this->gotoKernelParameters.= " splash=silent";
392 break;
393 }
394 if ($this->customParameters != ""){
395 $this->gotoKernelParameters.= " o ".$this->customParameters;
396 }
398 $tmp = array();
399 foreach($this->FAIclass as $class){
400 $tmp[] = $class;
401 }
402 $this->FAIclass = $tmp;
404 plugin::save();
406 /* Add missing arrays */
407 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
408 if (isset ($this->$val) && count ($this->$val) != 0){
410 $this->attrs["$val"]= array_unique($this->$val);
411 }
412 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
413 }
414 /* Strip out 'default' values */
415 if ($this->attrs['gotoLdapServer'] == "default"){
416 unset ($this->attrs['gotoLdapServer']);
417 }
419 $tmp = array();
420 foreach($this->FAIclass as $class){
421 $tmp[] = $class;
422 }
423 $this->attrs['FAIclass'] = $tmp;
424 /* Write back to ldap */
426 if(count($this->attrs['FAIclass'])==0){
427 $tmp = array();
428 foreach($this->attrs['objectClass'] as $class){
429 if($class != "FAIobject"){
430 $tmp[] = $class;
431 }
432 }
433 $this->attrs['objectClass'] = $tmp;
434 $this->attrs['FAIclass'] = array();;
435 }
437 $ldap= $this->config->get_ldap_link();
438 $ldap->cd($this->dn);
439 $ldap->modify($this->attrs);
440 show_ldap_error($ldap->get_error());
441 $this->handle_post_events("modify");
442 }
444 /* Add value to array, check if unique */
445 function add_list (&$array, $value)
446 {
447 if ($value != ""){
448 $array[]= $value;
449 sort($array);
450 array_unique ($array);
451 }
452 }
455 /* Delete value to array, check if unique */
456 function del_list (&$array, $list)
457 {
458 $tmp= array();
459 foreach ($array as $mod){
460 if (!in_array($mod, $list)){
461 $tmp[]= $mod;
462 }
463 }
464 $array= $tmp;
465 }
467 /* Generate ListBox frindly output for the defined shares
468 * Possibly Add or remove an attribute here,
469 */
470 function printOutAssignedShares()
471 {
472 $a_return = array();
473 if(is_array($this->gotoShares)){
474 foreach($this->gotoShares as $share){
475 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
476 }
477 }
478 return($a_return);
479 }
481 }
483 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
484 ?>