1 <?php
2 class termstartup 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 $gotoTerminalPath= "";
18 /* Share */
19 var $gotoShares = array();// Currently Share Option
20 var $gotoShare = ""; // currently selected Share Option
21 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
22 var $gotoAvailableShares= array();// Available Shares for this account
25 /* attribute list for save action */
26 var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters");
27 var $objectclasses= array("GOhard");
29 /* Helper */
30 var $customParameters= "";
31 var $orig_dn= "";
32 var $ignore_account= TRUE;
34 function termstartup ($config, $dn= NULL)
35 {
36 plugin::plugin ($config, $dn);
38 /* Get arrays */
39 foreach (array("gotoModules") as $val){
40 if (isset($this->attrs["$val"]["count"])){
41 for ($i= 0; $i<$this->attrs["count"]; $i++){
42 if (isset($this->attrs["$val"][$i])){
43 array_push($this->$val, $this->attrs["$val"][$i]);
44 }
45 }
46 }
47 sort ($this->$val);
48 $this->$val= array_unique($this->$val);
49 }
51 /* Parse Kernel Parameters to decide what boot mode is enabled */
52 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
53 $this->bootmode= "G";
54 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
55 $this->bootmode= "D";
56 } elseif ($this->gotoKernelParameters == "") {
57 $this->bootmode= "G";
58 } else {
59 $this->bootmode= "T";
60 }
61 if (preg_match("/ o /", $this->gotoKernelParameters)){
62 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
63 } else {
64 $this->customParameters= "";
65 }
67 /* Prepare Shares */
68 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
69 unset($this->attrs['gotoShare']['count']);
70 foreach($this->attrs['gotoShare'] as $share){
71 $tmp = $tmp2 = array();
72 $tmp = split("\|",$share);
73 $tmp2['server'] =$tmp[0];
74 $tmp2['name'] =$tmp[1];
75 $tmp2['mountPoint'] =$tmp[2];
76 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
77 }
78 }
80 $this->gotoShareSelections= $config->getShareList(true);
81 $this->gotoAvailableShares= $config->getShareList(false);
83 $this->orig_dn= $this->dn;
84 }
86 function execute()
87 {
88 /* Call parent execute */
89 plugin::execute();
90 /* Do we need to flip is_account state? */
91 if (isset($_POST['modify_state'])){
92 $this->is_account= !$this->is_account;
93 }
95 /* Do we represent a valid terminal? */
96 if (!$this->is_account && $this->parent == NULL){
97 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
98 _("This 'dn' has no terminal features.")."</b>";
99 return ($display);
100 }
102 /* Add module */
103 if (isset ($_POST['add_module'])){
104 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
105 $this->add_list ($this->gotoModules, $_POST['module']);
106 }
107 }
109 /* Delete module */
110 if (isset ($_POST['delete_module'])){
111 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
112 $this->del_list ($this->gotoModules, $_POST['modules_list']);
113 }
114 }
116 /* Show main page */
117 $smarty= get_smarty();
120 /* In this section server shares will be defined
121 * A user can select one of the given shares and a mount point
122 * and attach this combination to his setup.
123 */
124 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
125 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
127 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
128 * This entry will be, a combination of mountPoint and sharedefinitions
129 */
130 if(isset($_POST['gotoShareAdd'])){
131 /* We assign a share to this user, if we don't know where to mount the share */
132 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
133 print_red(_("You must specify a valid mount point."));
134 }else{
135 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
136 $s_mount = $_POST['gotoShareMountPoint'];
137 /* Preparing the new assignment */
138 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
139 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
140 }
141 }
143 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
144 * If there is no defined share selected, we will abort the deletion without any message
145 */
146 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
147 unset($this->gotoShares[$_POST['gotoShare']]);
148 }
150 $smarty->assign("gotoShares",$this->printOutAssignedShares());
151 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
155 /* Arrays */
156 $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
157 $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
158 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
159 $smarty->assign("gotoShareACL", chkacl($this->acl, "gotoShareACL"));
160 foreach (array("gotoModules" ) as $val){
161 $smarty->assign("$val", $this->$val);
162 }
164 /* Values */
165 foreach(array("gotoBootKernel", "customParameters") as $val){
166 $smarty->assign($val, $this->$val);
167 $smarty->assign($val."ACL", chkacl($this->acl, $val));
168 }
170 /* Radio button group */
171 if (preg_match("/G/", $this->bootmode)) {
172 $smarty->assign("graphicalbootup", "checked");
173 } else {
174 $smarty->assign("graphicalbootup", "");
175 }
176 if (preg_match("/T/", $this->bootmode)) {
177 $smarty->assign("textbootup", "checked");
178 } else {
179 $smarty->assign("textbootup", "");
180 }
181 if (preg_match("/D/", $this->bootmode)) {
182 $smarty->assign("debugbootup", "checked");
183 } else {
184 $smarty->assign("debugbootup", "");
185 }
187 /* ACL's */
188 foreach (array("gotoKernelParameters", "gotoModules") as $value){
189 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
190 }
192 /* Show main page */
193 return($smarty->fetch (get_template_path('terminalStartup.tpl', TRUE)));
194 }
196 function remove_from_parent()
197 {
198 $ldap= $this->config->get_ldap_link();
199 $ldap->rmdir($this->dn);
200 show_ldap_error($ldap->get_error());
201 $this->handle_post_events("remove");
202 }
205 /* Save data to object */
206 function save_object()
207 {
208 plugin::save_object();
210 /* Save group radio buttons */
211 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
212 $this->bootmode= $_POST["bootmode"];
213 }
215 /* Save kernel parameters */
216 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
217 $this->customParameters= $_POST["customParameters"];
218 }
219 }
222 /* Save to LDAP */
223 function save()
224 {
225 /* Find proper terminal path for tftp configuration
226 FIXME: This is suboptimal when the default has changed to
227 another location! */
228 if ($this->gotoTerminalPath == "default"){
229 $ldap= $this->config->get_ldap_link();
231 /* Strip relevant part from dn, keep trailing ',' */
232 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
233 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
235 /* Walk from top to base and try to load default values for
236 'gotoTerminalPath'. Abort when an entry is found. */
237 while (TRUE){
238 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
240 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
241 $this->config->current['BASE']);
242 $attrs= $ldap->fetch();
243 if (isset($attrs['gotoTerminalPath'])){
244 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
245 break;
246 }
248 /* Nothing left? */
249 if ($tmp == ""){
250 break;
251 }
252 }
253 }
255 /* Add semi automatic values */
256 // FIXME: LDAP Server may not be set here...
257 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
258 $this->gotoTerminalPath.
259 ",ro,hard,nolock,fg,rsize=8192 ".
260 "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
262 switch ($this->bootmode){
263 case "D":
264 $this->gotoKernelParameters.= " debug";
265 break;
266 case "G":
267 $this->gotoKernelParameters.= " splash=silent";
268 break;
269 }
270 if ($this->customParameters != ""){
271 $this->gotoKernelParameters.= " o ".$this->customParameters;
272 }
274 plugin::save();
276 /* Add missing arrays */
277 foreach (array("gotoModules") as $val){
278 if (isset ($this->$val) && count ($this->$val) != 0){
280 $this->attrs["$val"]= array_unique($this->$val);
281 }
282 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
283 }
285 /* Strip out 'default' values */
286 if ($this->attrs['gotoLdapServer'] == "default"){
287 unset ($this->attrs['gotoLdapServer']);
288 }
290 /* prepare share settings */
291 $tmp = array();
292 foreach($this->gotoShares as $name => $settings){
293 $tmp2 = split("\|",$name);
294 $name = $tmp2[0];
295 $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
296 }
297 $this->attrs['gotoShare']=$tmp;
299 /* Write back to ldap */
300 $ldap= $this->config->get_ldap_link();
301 $ldap->cd($this->dn);
302 $ldap->modify($this->attrs);
303 show_ldap_error($ldap->get_error());
304 $this->handle_post_events("modify");
305 }
307 /* Add value to array, check if unique */
308 function add_list (&$array, $value)
309 {
310 if ($value != ""){
311 $array[]= $value;
312 sort($array);
313 array_unique ($array);
314 }
315 }
318 /* Delete value to array, check if unique */
319 function del_list (&$array, $list)
320 {
321 $tmp= array();
322 foreach ($array as $mod){
323 if (!in_array($mod, $list)){
324 $tmp[]= $mod;
325 }
326 }
327 $array= $tmp;
328 }
330 /* Generate ListBox frindly output for the defined shares
331 * Possibly Add or remove an attribute here,
332 */
333 function printOutAssignedShares()
334 {
335 $a_return = array();
336 if(is_array($this->gotoShares)){
337 foreach($this->gotoShares as $share){
338 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
339 }
340 }
341 return($a_return);
342 }
345 }
347 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
348 ?>