Some small bugfixes. Still testing.
[squirrelmail.git] / plugins / administrator / options.php
CommitLineData
abd7a3f8 1<?php
2
3/**
4 * Administrator Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Philippe Mingo
10 *
11 * $Id$
12 */
13
37d90494 14function parseConfig( $cfg_file ) {
15
16 global $newcfg;
17
18 $cfg = file( $cfg_file );
71e5c245 19 $mode = '';
20 $l = count( $cfg );
21 $modifier = FALSE;
37d90494 22
71e5c245 23 for ($i=0;$i<$l;$i++) {
24 $line = trim( $cfg[$i] );
25 $s = strlen( $line );
26 for ($j=0;$j<$s;$j++) {
27 switch ( $mode ) {
28 case '=':
29 if ( $line{$j} == '=' ) {
30 // Ok, we've got a right value, lets detect what type
31 $mode = 'D';
32 } else if ( $line{$j} == ';' ) {
33 // hu! end of command
34 $key = $mode = '';
35 }
36 break;
37 case 'K':
38 // Key detect
39 if( $line{$j} == ' ' ) {
40 $mode = '=';
37d90494 41 } else {
71e5c245 42 $key .= $line{$j};
37d90494 43 }
71e5c245 44 break;
45 case ';':
46 // Skip until next ;
47 if ( $line{$j} == ';' ) {
48 $mode = '';
49 }
50 break;
51 case 'S':
52 if ( $line{$j} == '\\' ) {
53 $value .= $line{$j};
54 $modifier = TRUE;
55 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
56 // End of string;
57 $newcfg[$key] = $value . $delimiter;
58 $key = $value = '';
59 $mode = ';';
60 } else {
61 $value .= $line{$j};
62 $modifier = FALSE;
63 }
64 break;
65 case 'N':
66 if ( $line{$j} == ';' ) {
67 $newcfg{$key} = $value;
68 $key = $mode = '';
69 } else {
70 $value .= $line{$j};
71 }
72 break;
73 case 'C':
74 // Comments
75 if ( $line{$j}.$line{$j+1} == '*/' ) {
76 $mode = '';
77 $j++;
78 }
79 break;
80 case 'D':
81 // Delimiter detect
82 switch ( $line{$j} ) {
83 case '"':
84 case "'":
85 // Double quote string
86 $delimiter = $value = $line{$j};
87 $mode = 'S';
88 break;
89 case ' ':
90 // Nothing yet
91 break;
92 default:
93 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
94 // Boolean TRUE
95 $newcfg{$key} = 'TRUE';
96 $key = '';
97 $mode = ';';
98 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
99 $newcfg{$key} = 'FALSE';
100 $key = '';
101 $mode = ';';
102 } else {
103 // Number or function call
104 $mode = 'N';
105 $value = $line{$j};
106 }
107 }
108 break;
109 default:
110 if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
111 // Skip untill next ;
112 $mode = ';';
113 $j += 6;
114 } else if ( $line{$j}.$line{$j+1} == '/*' ) {
115 $mode = 'C';
116 $j++;
117 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
118 // Delete till the end of the line
119 $j = $s;
120 } else if ( $line{$j} == '$' ) {
121 // We must detect $key name
122 $mode = 'K';
123 $key = '$';
37d90494 124 }
37d90494 125 }
126 }
37d90494 127 }
128
129}
71e5c245 130
37d90494 131/* ---------------------- main -------------------------- */
71e5c245 132
abd7a3f8 133chdir('..');
134require_once('../src/validate.php');
135require_once('../functions/page_header.php');
136require_once('../functions/imap.php');
137require_once('../src/load_prefs.php');
138require_once('../plugins/administrator/defines.php');
139
a3fab7e3 140GLOBAL $data_dir, $username;
141
dcd6f144 142$auth = FALSE;
143if ( $adm_id = fileowner('../config/config.php') ) {
144 $adm = posix_getpwuid( $adm_id );
145 if ( $username == $adm['name'] ) {
146 $auth = TRUE;
147 }
148}
149
150if ( !auth ) {
151 header("Location: ../../src/options.php") ;
152 exit;
153}
154
abd7a3f8 155displayPageHeader($color, 'None');
156
37d90494 157$newcfg = array( );
0e66bc84 158
159foreach ( $defcfg as $key => $def ) {
160 $newcfg[$key] = '';
161}
162
37d90494 163$cfgfile = '../config/config.php';
164parseConfig( '../config/config_default.php' );
165parseConfig( $cfgfile );
abd7a3f8 166
a3fab7e3 167$colapse = array( 'Titles' => FALSE,
168 'Group1' => getPref($data_dir, $username, 'adm_Group1', FALSE ),
169 'Group2' => getPref($data_dir, $username, 'adm_Group2', TRUE ),
170 'Group3' => getPref($data_dir, $username, 'adm_Group3', TRUE ),
171 'Group4' => getPref($data_dir, $username, 'adm_Group4', TRUE ),
172 'Group5' => getPref($data_dir, $username, 'adm_Group5', TRUE ),
173 'Group6' => getPref($data_dir, $username, 'adm_Group6', TRUE ),
174 'Group7' => getPref($data_dir, $username, 'adm_Group7', TRUE ) );
175
176if ( isset( $switch ) ) {
177 $colapse[$switch] = !$colapse[$switch];
178 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
179}
180
abd7a3f8 181echo "<form action=$PHP_SELF method=post>" .
0e66bc84 182 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
183 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
abd7a3f8 184 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
a3fab7e3 185
186$act_grp = 'Titles'; /* Active group */
187
abd7a3f8 188foreach ( $newcfg as $k => $v ) {
189 $l = strtolower( $v );
190 $type = SMOPT_TYPE_UNDEFINED;
191 $n = substr( $k, 1 );
192 $n = str_replace( '[', '_', $n );
193 $n = str_replace( ']', '_', $n );
194 $e = 'adm_' . $n;
195 $name = $k;
196 $size = 50;
0e66bc84 197 if ( isset( $defcfg[$k] ) ) {
198 $name = $defcfg[$k]['name'];
199 $type = $defcfg[$k]['type'];
200 $size = $defcfg[$k]['size'];
abd7a3f8 201 } else if ( $l == 'true' ) {
202 $v = 'TRUE';
203 $type = SMOPT_TYPE_BOOLEAN;
204 } else if ( $l == 'false' ) {
205 $v = 'FALSE';
206 $type = SMOPT_TYPE_BOOLEAN;
207 } else if ( $v{0} == "'" ) {
208 $type = SMOPT_TYPE_STRING;
209 } else if ( $v{0} == '"' ) {
210 $type = SMOPT_TYPE_STRING;
211 }
212
edd4a552 213 if ( substr( $k, 0, 7 ) == '$theme[' ) {
214 $type = SMOPT_TYPE_THEME;
215 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
216 $type = SMOPT_TYPE_PLUGINS;
65a5bae6 217 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
218 $type = SMOPT_TYPE_LDAP;
edd4a552 219 }
220
a3fab7e3 221 if( $type == SMOPT_TYPE_TITLE || !$colapse[$act_grp] ) {
222
223 switch ( $type ) {
224 case SMOPT_TYPE_LDAP:
225 case SMOPT_TYPE_PLUGINS:
226 case SMOPT_TYPE_THEME:
227 case SMOPT_TYPE_HIDDEN:
228 break;
229 case SMOPT_TYPE_TITLE:
230 if ( $colapse[$k] ) {
231 $sw = '(+)';
232 } else {
233 $sw = '(-)';
dcd6f144 234 }
a3fab7e3 235 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
236 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
237 "$name</th></tr>";
238 $act_grp = $k;
239 break;
240 case SMOPT_TYPE_COMMENT:
241 $v = substr( $v, 1, strlen( $v ) - 2 );
242 echo "<tr><td>$name</td><td>".
243 "<b>$v</b>";
244 $newcfg[$k] = "'$v'";
245 if ( isset( $defcfg[$k]['comment'] ) ) {
246 echo ' &nbsp; ' . $defcfg[$k]['comment'];
abd7a3f8 247 }
a3fab7e3 248 echo "</td></tr>\n";
249 break;
250 case SMOPT_TYPE_INTEGER:
251 if ( isset( $HTTP_POST_VARS[$e] ) ) {
252 $v = intval( $HTTP_POST_VARS[$e] );
253 $newcfg[$k] = $v;
254 }
255 echo "<tr><td>$name</td><td>".
256 "<input size=10 name=\"adm_$n\" value=\"$v\">";
257 if ( isset( $defcfg[$k]['comment'] ) ) {
258 echo ' &nbsp; ' . $defcfg[$k]['comment'];
259 }
260 echo "</td></tr>\n";
261 break;
262 case SMOPT_TYPE_NUMLIST:
263 if ( isset( $HTTP_POST_VARS[$e] ) ) {
264 $v = $HTTP_POST_VARS[$e];
265 $newcfg[$k] = $v;
266 }
267 echo "<tr><td>$name</td><td>";
268 echo "<select name=\"adm_$n\">";
269 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
270 echo "<option value=\"$kp\"";
271 if ( $kp == $v ) {
272 echo ' selected';
273 }
274 echo ">$vp</option>";
275 }
276 echo '</select>';
277 if ( isset( $defcfg[$k]['comment'] ) ) {
278 echo ' &nbsp; ' . $defcfg[$k]['comment'];
279 }
280 echo "</td></tr>\n";
281 break;
282 case SMOPT_TYPE_STRLIST:
283 if ( isset( $HTTP_POST_VARS[$e] ) ) {
284 $v = '"' . $HTTP_POST_VARS[$e] . '"';
285 $newcfg[$k] = $v;
286 }
287 echo "<tr><td>$name</td><td>".
288 "<select name=\"adm_$n\">";
289 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
290 echo "<option value=\"$kp\"";
291 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
292 echo ' selected';
293 }
294 echo ">$vp</option>";
295 }
296 echo '</select>';
297 if ( isset( $defcfg[$k]['comment'] ) ) {
298 echo ' &nbsp; ' . $defcfg[$k]['comment'];
299 }
300 echo "</td></tr>\n";
301 break;
302
303 case SMOPT_TYPE_TEXTAREA:
304 if ( isset( $HTTP_POST_VARS[$e] ) ) {
305 $v = '"' . $HTTP_POST_VARS[$e] . '"';
306 $newcfg[$k] = str_replace( "\n", '', $v );
307 }
308 echo "<tr><td valign=top>$name</td><td>".
309 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
310 if ( isset( $defcfg[$k]['comment'] ) ) {
311 echo ' &nbsp; ' . $defcfg[$k]['comment'];
312 }
313 echo "</td></tr>\n";
314 break;
315 case SMOPT_TYPE_STRING:
316 if ( isset( $HTTP_POST_VARS[$e] ) ) {
317 $v = '"' . $HTTP_POST_VARS[$e] . '"';
318 $newcfg[$k] = $v;
319 }
320 echo "<tr><td>$name</td><td>".
321 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
322 if ( isset( $defcfg[$k]['comment'] ) ) {
323 echo ' &nbsp; ' . $defcfg[$k]['comment'];
324 }
325 echo "</td></tr>\n";
326 break;
327 case SMOPT_TYPE_BOOLEAN:
328 if ( isset( $HTTP_POST_VARS[$e] ) ) {
329 $v = $HTTP_POST_VARS[$e];
330 $newcfg[$k] = $v;
331 } else {
332 $v = strtoupper( $v );
333 }
334 if ( $v == 'TRUE' ) {
335 $ct = ' checked';
336 $cf = '';
337 } else {
338 $ct = '';
339 $cf = ' checked';
340 }
341 echo "<tr><td>$name</td><td>" .
342 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
343 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
344 if ( isset( $defcfg[$k]['comment'] ) ) {
345 echo ' &nbsp; ' . $defcfg[$k]['comment'];
346 }
347 echo "</td></tr>\n";
348 break;
349 default:
350 echo "<tr><td>$name</td><td>" .
351 "<b><i>$v</i></b>";
352 if ( isset( $defcfg[$k]['comment'] ) ) {
353 echo ' &nbsp; ' . $defcfg[$k]['comment'];
354 }
355 echo "</td></tr>\n";
6a9acbca 356 }
a3fab7e3 357 }
abd7a3f8 358
a3fab7e3 359}
360
361if ( !($colapse['Group6']) ) {
362 $i = 0;
363 echo '<tr><th>' . _("Theme Name") .
364 '</th><th>' . _("Theme Path") .
365 '</th></tr>';
366 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
367 $k1 = "\$theme[$i]['NAME']";
368 $e1 = "theme_name_$i";
369 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
370 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
371 $newcfg[$k1] = $v1;
a55bb207 372 } else {
a3fab7e3 373 $v1 = $newcfg[$k1];
abd7a3f8 374 }
a3fab7e3 375 $k2 = "\$theme[$i]['PATH']";
376 $e2 = "theme_path_$i";
377 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
378 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
379 $newcfg[$k2] = $v2;
abd7a3f8 380 } else {
a3fab7e3 381 $v2 = $newcfg[$k2];
abd7a3f8 382 }
a3fab7e3 383 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
384 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
385 echo '<tr>'.
386 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
387 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
388 "</tr>\n";
389 $i++;
390
6a9acbca 391 }
6a9acbca 392}
393
a3fab7e3 394if ( $colapse['Group7'] ) {
395 $sw = '(+)';
396} else {
397 $sw = '(-)';
6a9acbca 398}
a3fab7e3 399echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
400 "<a href=options.php?switch=Group7 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
401 _("Plugins") . '</th></tr>';
6a9acbca 402
a3fab7e3 403if( !$colapse['Group7'] ) {
6a9acbca 404
a3fab7e3 405 $fd = opendir( '../plugins/' );
406 $op_plugin = array();
407 while (false!==($file = readdir($fd))) {
408 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
409 if ( filetype( $file ) == 'dir' ) {
410 $op_plugin[] = $file;
411 }
6a9acbca 412 }
edd4a552 413 }
a3fab7e3 414 closedir($fd);
415 asort( $op_plugin );
416
417 $i = 0;
418 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
419 $k = "\$plugins[$i]";
420 $e = "plugin_$i";
421 if ( isset( $HTTP_POST_VARS[$e] ) ) {
422 $v = '"' . $HTTP_POST_VARS[$e] . '"';
423 $newcfg[$k] = $v;
6a9acbca 424 } else {
a3fab7e3 425 $v = $newcfg[$k];
6a9acbca 426 }
a3fab7e3 427 $name = substr( $v, 1, strlen( $v ) - 2 );
428 echo '<tr>'.
429 "<td align=right>$i.</td>".
430 "<td><select name=\"$e\">";
431 foreach ( $op_plugin as $op ) {
432 if ( $op == $name ) {
433 $cs = ' selected';
434 } else {
435 $cs = '';
436 }
437 echo "<option$cs>$op</option>";
438 }
439 echo "</select></td>".
440 '</tr>';
441 $i++;
442
6a9acbca 443 }
6a9acbca 444}
abd7a3f8 445echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
446 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 447 '</table></td></tr></table></form>';
abd7a3f8 448
449/*
450 Write the options to the file.
451*/
71e5c245 452
abd7a3f8 453$fp = fopen( $cfgfile, 'w' );
454fwrite( $fp, "<?PHP\n".
455 "/**\n".
456 " * SquirrelMail Configuration File\n".
457 " * Created using the Administrator Plugin\n".
a3fab7e3 458 " */\n" );
abd7a3f8 459
edd4a552 460/*
abd7a3f8 461fwrite( $fp, 'GLOBAL ' );
462$not_first = FALSE;
463foreach ( $newcfg as $k => $v ) {
0e66bc84 464 if ( $k{0} == '$' ) {
465 if( $i = strpos( $k, '[' ) ) {
466 if( strpos( $k, '[0]' ) ) {
467 if( $not_first ) {
468 fwrite( $fp, ', ' );
469 }
470 fwrite( $fp, substr( $k, 0, $i) );
0e66bc84 471 }
472 } else {
abd7a3f8 473 if( $not_first ) {
474 fwrite( $fp, ', ' );
edd4a552 475 }
0e66bc84 476 fwrite( $fp, $k );
abd7a3f8 477 }
7c8d1194 478 $not_first = TRUE;
abd7a3f8 479 }
480}
481fwrite( $fp, ";\n" );
edd4a552 482*/
abd7a3f8 483foreach ( $newcfg as $k => $v ) {
0e66bc84 484 if ( $k{0} == '$' ) {
7c8d1194 485 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
486 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
487 $v = str_replace( 'array(', "array(\n\t", $v );
488 $v = str_replace( "',", "',\n\t", $v );
489 }
0e66bc84 490 fwrite( $fp, "$k = $v;\n" );
491 }
abd7a3f8 492}
493fwrite( $fp, '?>' );
494fclose( $fp );
37d90494 495?>