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= "";
22 /* attribute list for save action */
23 var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare");
24 var $objectclasses= array("GOhard", "FAIobject");
26 /* Share */
27 var $gotoShares = array();// Currently Share Option
28 var $gotoShare = ""; // currently selected Share Option
29 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30 var $gotoAvailableShares= array();// Available Shares for this account
32 /* Helper */
33 var $customParameters= "";
34 var $orig_dn= "";
35 var $ignore_account= TRUE;
37 function workstartup ($config, $dn= NULL)
38 {
39 plugin::plugin ($config, $dn);
41 /* Get arrays */
42 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
43 if (isset($this->attrs["$val"]["count"])){
44 for ($i= 0; $i<$this->attrs["count"]; $i++){
45 if (isset($this->attrs["$val"][$i])){
46 array_push($this->$val, $this->attrs["$val"][$i]);
47 }
48 }
49 }
50 sort ($this->$val);
51 $this->$val= array_unique($this->$val);
52 }
54 /* Parse Kernel Parameters to decide what boot mode is enabled */
55 if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
56 $this->bootmode= "G";
57 } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
58 $this->bootmode= "D";
59 } elseif ($this->gotoKernelParameters == "") {
60 $this->bootmode= "G";
61 } else {
62 $this->bootmode= "T";
63 }
64 if (preg_match("/ o /", $this->gotoKernelParameters)){
65 $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
66 } else {
67 $this->customParameters= "";
68 }
70 /* Prepare Shares */
71 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
72 unset($this->attrs['gotoShare']['count']);
73 foreach($this->attrs['gotoShare'] as $share){
74 $tmp = $tmp2 = array();
75 $tmp = split("\|",$share);
76 $tmp2['server'] =$tmp[0];
77 $tmp2['name'] =$tmp[1];
78 $tmp2['mountPoint'] =$tmp[2];
79 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
80 }
81 }
83 $this->gotoShareSelections= $config->getShareList(true);
84 $this->gotoAvailableShares= $config->getShareList(false);
86 $this->orig_dn= $this->dn;
87 }
89 function execute()
90 {
91 /* Do we need to flip is_account state? */
92 if (isset($_POST['modify_state'])){
93 $this->is_account= !$this->is_account;
94 }
96 /* Do we represent a valid terminal? */
97 if (!$this->is_account && $this->parent == NULL){
98 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
99 _("This 'dn' has no terminal features.")."</b>";
100 return ($display);
101 }
103 /* Add module */
104 if (isset ($_POST['add_module'])){
105 if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
106 $this->add_list ($this->gotoModules, $_POST['module']);
107 }
108 }
110 /* Delete module */
111 if (isset ($_POST['delete_module'])){
112 if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
113 $this->del_list ($this->gotoModules, $_POST['modules_list']);
114 }
115 }
117 /* Show main page */
118 $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;
139 $this->gotoShares[$a_share['name']]['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()));
153 /* Arrays */
154 $smarty->assign("ldapservers", $this->config->data['SERVERS']['LDAP']);
155 $smarty->assign("gotoLdapServer_select", $this->gotoLdapServer);
156 $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
157 foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
158 $smarty->assign("$val", $this->$val);
159 }
161 /* Values */
162 foreach(array("gotoBootKernel", "customParameters", "gotoShare") as $val){
163 $smarty->assign($val, $this->$val);
164 $smarty->assign($val."ACL", chkacl($this->acl, $val));
165 }
167 /* Radio button group */
168 if (preg_match("/G/", $this->bootmode)) {
169 $smarty->assign("graphicalbootup", "checked");
170 } else {
171 $smarty->assign("graphicalbootup", "");
172 }
173 if (preg_match("/T/", $this->bootmode)) {
174 $smarty->assign("textbootup", "checked");
175 } else {
176 $smarty->assign("textbootup", "");
177 }
178 if (preg_match("/D/", $this->bootmode)) {
179 $smarty->assign("debugbootup", "checked");
180 } else {
181 $smarty->assign("debugbootup", "");
182 }
184 /* ACL's */
185 foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem") as $value){
186 $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
187 }
189 /* Show main page */
190 return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE)));
191 }
193 function remove_from_parent()
194 {
195 $ldap= $this->config->get_ldap_link();
196 $ldap->rmdir($this->dn);
197 show_ldap_error($ldap->get_error());
198 $this->handle_post_events("remove");
199 }
202 /* Save data to object */
203 function save_object()
204 {
205 plugin::save_object();
207 /* Save group radio buttons */
208 if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
209 $this->bootmode= $_POST["bootmode"];
210 }
212 /* Save kernel parameters */
213 if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
214 $this->customParameters= $_POST["customParameters"];
215 }
216 }
219 /* Save to LDAP */
220 function save()
221 {
222 /* Find proper terminal path for tftp configuration
223 FIXME: This is suboptimal when the default has changed to
224 another location! */
225 if ($this->gotoTerminalPath == "default"){
226 $ldap= $this->config->get_ldap_link();
228 /* Strip relevant part from dn, keep trailing ',' */
229 $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
230 $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
232 /* Walk from top to base and try to load default values for
233 'gotoTerminalPath'. Abort when an entry is found. */
234 while (TRUE){
235 $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
237 $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
238 $this->config->current['BASE']);
239 $attrs= $ldap->fetch();
240 if (isset($attrs['gotoTerminalPath'])){
241 $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
242 break;
243 }
245 /* Nothing left? */
246 if ($tmp == ""){
247 break;
248 }
249 }
250 }
252 /* Add semi automatic values */
253 // FIXME: LDAP Server may not be set here...
254 $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
255 $this->gotoTerminalPath.
256 ",ro,hard,nolock,fg,rsize=8192 ".
257 "ip=::::::dhcp LDAP=".$this->gotoLdapServer;
259 switch ($this->bootmode){
260 case "D":
261 $this->gotoKernelParameters.= " debug";
262 break;
263 case "G":
264 $this->gotoKernelParameters.= " splash=silent";
265 break;
266 }
267 if ($this->customParameters != ""){
268 $this->gotoKernelParameters.= " o ".$this->customParameters;
269 }
271 plugin::save();
273 /* Add missing arrays */
274 foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
275 if (isset ($this->$val) && count ($this->$val) != 0){
277 $this->attrs["$val"]= array_unique($this->$val);
278 }
279 if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
280 }
282 /* Strip out 'default' values */
283 if ($this->attrs['gotoLdapServer'] == "default"){
284 unset ($this->attrs['gotoLdapServer']);
285 }
287 /* Write back to ldap */
288 $ldap= $this->config->get_ldap_link();
289 $ldap->cd($this->dn);
290 $ldap->modify($this->attrs);
291 show_ldap_error($ldap->get_error());
292 $this->handle_post_events("modify");
293 }
295 /* Add value to array, check if unique */
296 function add_list (&$array, $value)
297 {
298 if ($value != ""){
299 $array[]= $value;
300 sort($array);
301 array_unique ($array);
302 }
303 }
306 /* Delete value to array, check if unique */
307 function del_list (&$array, $list)
308 {
309 $tmp= array();
310 foreach ($array as $mod){
311 if (!in_array($mod, $list)){
312 $tmp[]= $mod;
313 }
314 }
315 $array= $tmp;
316 }
318 /* Generate ListBox frindly output for the defined shares
319 * Possibly Add or remove an attribute here,
320 */
321 function printOutAssignedShares()
322 {
323 $a_return = array();
324 if(is_array($this->gotoShares)){
325 foreach($this->gotoShares as $share){
326 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
327 }
328 }
329 return($a_return);
330 }
332 }
334 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
335 ?>