Eliminated all eveil chdir statements.
[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
88cb1b4d 75 if ( $s > $j + 1 &&
76 $line{$j}.$line{$j+1} == '*/' ) {
71e5c245 77 $mode = '';
78 $j++;
79 }
80 break;
81 case 'D':
82 // Delimiter detect
83 switch ( $line{$j} ) {
84 case '"':
85 case "'":
86 // Double quote string
87 $delimiter = $value = $line{$j};
88 $mode = 'S';
89 break;
90 case ' ':
91 // Nothing yet
92 break;
93 default:
94 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
95 // Boolean TRUE
96 $newcfg{$key} = 'TRUE';
97 $key = '';
98 $mode = ';';
99 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
100 $newcfg{$key} = 'FALSE';
101 $key = '';
102 $mode = ';';
103 } else {
104 // Number or function call
105 $mode = 'N';
106 $value = $line{$j};
107 }
108 }
109 break;
110 default:
88cb1b4d 111 if ( $line{$j} == '$' ) {
112 // We must detect $key name
113 $mode = 'K';
114 $key = '$';
115 } else if ( $s < $j + 2 ) {
116 } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
71e5c245 117 // Skip untill next ;
118 $mode = ';';
119 $j += 6;
120 } else if ( $line{$j}.$line{$j+1} == '/*' ) {
121 $mode = 'C';
122 $j++;
123 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
124 // Delete till the end of the line
125 $j = $s;
37d90494 126 }
37d90494 127 }
128 }
37d90494 129 }
130
131}
71e5c245 132
37d90494 133/* ---------------------- main -------------------------- */
71e5c245 134
8d6a115b 135define('SM_PATH','../../');
cf1efdce 136
137/* SquirrelMail required files. */
138require_once(SM_PATH . 'include/validate.php');
139require_once(SM_PATH . 'functions/page_header.php');
140require_once(SM_PATH . 'functions/imap.php');
aa7fb30c 141require_once(SM_PATH . 'include/load_prefs.php');
cf1efdce 142require_once(SM_PATH . 'plugins/administrator/defines.php');
143require_once(SM_PATH . 'plugins/administrator/auth.php');
abd7a3f8 144
a3fab7e3 145GLOBAL $data_dir, $username;
146
7004cc32 147if ( !adm_check_user() ) {
dcd6f144 148 header("Location: ../../src/options.php") ;
149 exit;
150}
151
abd7a3f8 152displayPageHeader($color, 'None');
153
37d90494 154$newcfg = array( );
0e66bc84 155
156foreach ( $defcfg as $key => $def ) {
157 $newcfg[$key] = '';
158}
159
37d90494 160$cfgfile = '../config/config.php';
161parseConfig( '../config/config_default.php' );
162parseConfig( $cfgfile );
abd7a3f8 163
88cb1b4d 164$colapse = array( 'Titles' => 'off',
165 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
166 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
167 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
168 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
169 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
170 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
171 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
172 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
a3fab7e3 173
174if ( isset( $switch ) ) {
88cb1b4d 175
176 if ( $colapse[$switch] == 'on' ) {
177 $colapse[$switch] = 'off';
178 } else {
179 $colapse[$switch] = 'on';
180 }
a3fab7e3 181 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
88cb1b4d 182
a3fab7e3 183}
184
88cb1b4d 185echo "<form action=options.php method=post name=options>" .
6206f6c4 186 "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
0e66bc84 187 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
abd7a3f8 188 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
a3fab7e3 189
190$act_grp = 'Titles'; /* Active group */
c83b38c1 191
abd7a3f8 192foreach ( $newcfg as $k => $v ) {
193 $l = strtolower( $v );
194 $type = SMOPT_TYPE_UNDEFINED;
195 $n = substr( $k, 1 );
196 $n = str_replace( '[', '_', $n );
197 $n = str_replace( ']', '_', $n );
198 $e = 'adm_' . $n;
199 $name = $k;
200 $size = 50;
0e66bc84 201 if ( isset( $defcfg[$k] ) ) {
202 $name = $defcfg[$k]['name'];
203 $type = $defcfg[$k]['type'];
88cb1b4d 204 if ( isset( $defcfg[$k]['size'] ) ) {
205 $size = $defcfg[$k]['size'];
206 } else {
207 $size = 40;
208 }
abd7a3f8 209 } else if ( $l == 'true' ) {
210 $v = 'TRUE';
211 $type = SMOPT_TYPE_BOOLEAN;
212 } else if ( $l == 'false' ) {
213 $v = 'FALSE';
214 $type = SMOPT_TYPE_BOOLEAN;
215 } else if ( $v{0} == "'" ) {
216 $type = SMOPT_TYPE_STRING;
217 } else if ( $v{0} == '"' ) {
218 $type = SMOPT_TYPE_STRING;
219 }
220
edd4a552 221 if ( substr( $k, 0, 7 ) == '$theme[' ) {
222 $type = SMOPT_TYPE_THEME;
223 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
224 $type = SMOPT_TYPE_PLUGINS;
65a5bae6 225 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
226 $type = SMOPT_TYPE_LDAP;
edd4a552 227 }
228
88cb1b4d 229 if( $type == SMOPT_TYPE_TITLE || $colapse[$act_grp] == 'off' ) {
a3fab7e3 230
231 switch ( $type ) {
232 case SMOPT_TYPE_LDAP:
233 case SMOPT_TYPE_PLUGINS:
234 case SMOPT_TYPE_THEME:
235 case SMOPT_TYPE_HIDDEN:
236 break;
88cb1b4d 237 case SMOPT_TYPE_EXTERNAL:
238 echo "<tr><td>$name</td><td><b>" .
239 $defcfg[$k]['value'] .
240 "</b></td></tr>";
241 break;
a3fab7e3 242 case SMOPT_TYPE_TITLE:
88cb1b4d 243 if ( $colapse[$k] == 'on' ) {
a3fab7e3 244 $sw = '(+)';
245 } else {
246 $sw = '(-)';
dcd6f144 247 }
a3fab7e3 248 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
249 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
250 "$name</th></tr>";
251 $act_grp = $k;
252 break;
253 case SMOPT_TYPE_COMMENT:
254 $v = substr( $v, 1, strlen( $v ) - 2 );
255 echo "<tr><td>$name</td><td>".
256 "<b>$v</b>";
257 $newcfg[$k] = "'$v'";
258 if ( isset( $defcfg[$k]['comment'] ) ) {
259 echo ' &nbsp; ' . $defcfg[$k]['comment'];
abd7a3f8 260 }
a3fab7e3 261 echo "</td></tr>\n";
262 break;
263 case SMOPT_TYPE_INTEGER:
264 if ( isset( $HTTP_POST_VARS[$e] ) ) {
265 $v = intval( $HTTP_POST_VARS[$e] );
266 $newcfg[$k] = $v;
267 }
268 echo "<tr><td>$name</td><td>".
269 "<input size=10 name=\"adm_$n\" value=\"$v\">";
270 if ( isset( $defcfg[$k]['comment'] ) ) {
271 echo ' &nbsp; ' . $defcfg[$k]['comment'];
272 }
273 echo "</td></tr>\n";
274 break;
275 case SMOPT_TYPE_NUMLIST:
276 if ( isset( $HTTP_POST_VARS[$e] ) ) {
277 $v = $HTTP_POST_VARS[$e];
278 $newcfg[$k] = $v;
279 }
280 echo "<tr><td>$name</td><td>";
281 echo "<select name=\"adm_$n\">";
282 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
283 echo "<option value=\"$kp\"";
284 if ( $kp == $v ) {
285 echo ' selected';
286 }
287 echo ">$vp</option>";
288 }
289 echo '</select>';
290 if ( isset( $defcfg[$k]['comment'] ) ) {
291 echo ' &nbsp; ' . $defcfg[$k]['comment'];
292 }
293 echo "</td></tr>\n";
294 break;
295 case SMOPT_TYPE_STRLIST:
296 if ( isset( $HTTP_POST_VARS[$e] ) ) {
297 $v = '"' . $HTTP_POST_VARS[$e] . '"';
298 $newcfg[$k] = $v;
299 }
300 echo "<tr><td>$name</td><td>".
301 "<select name=\"adm_$n\">";
302 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
303 echo "<option value=\"$kp\"";
304 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
305 echo ' selected';
306 }
307 echo ">$vp</option>";
308 }
309 echo '</select>';
310 if ( isset( $defcfg[$k]['comment'] ) ) {
311 echo ' &nbsp; ' . $defcfg[$k]['comment'];
312 }
313 echo "</td></tr>\n";
314 break;
c83b38c1 315
a3fab7e3 316 case SMOPT_TYPE_TEXTAREA:
317 if ( isset( $HTTP_POST_VARS[$e] ) ) {
318 $v = '"' . $HTTP_POST_VARS[$e] . '"';
319 $newcfg[$k] = str_replace( "\n", '', $v );
320 }
321 echo "<tr><td valign=top>$name</td><td>".
322 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
323 if ( isset( $defcfg[$k]['comment'] ) ) {
324 echo ' &nbsp; ' . $defcfg[$k]['comment'];
325 }
326 echo "</td></tr>\n";
327 break;
328 case SMOPT_TYPE_STRING:
329 if ( isset( $HTTP_POST_VARS[$e] ) ) {
330 $v = '"' . $HTTP_POST_VARS[$e] . '"';
331 $newcfg[$k] = $v;
332 }
feba1a41 333 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
334 $v = "'" . $defcfg[$k]['default'] . "'";
335 $newcfg[$k] = $v;
336 }
a3fab7e3 337 echo "<tr><td>$name</td><td>".
338 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
339 if ( isset( $defcfg[$k]['comment'] ) ) {
340 echo ' &nbsp; ' . $defcfg[$k]['comment'];
341 }
342 echo "</td></tr>\n";
343 break;
344 case SMOPT_TYPE_BOOLEAN:
345 if ( isset( $HTTP_POST_VARS[$e] ) ) {
346 $v = $HTTP_POST_VARS[$e];
347 $newcfg[$k] = $v;
348 } else {
349 $v = strtoupper( $v );
350 }
351 if ( $v == 'TRUE' ) {
352 $ct = ' checked';
353 $cf = '';
354 } else {
355 $ct = '';
356 $cf = ' checked';
357 }
358 echo "<tr><td>$name</td><td>" .
359 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
360 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
361 if ( isset( $defcfg[$k]['comment'] ) ) {
362 echo ' &nbsp; ' . $defcfg[$k]['comment'];
363 }
364 echo "</td></tr>\n";
365 break;
366 default:
367 echo "<tr><td>$name</td><td>" .
368 "<b><i>$v</i></b>";
369 if ( isset( $defcfg[$k]['comment'] ) ) {
370 echo ' &nbsp; ' . $defcfg[$k]['comment'];
371 }
372 echo "</td></tr>\n";
6a9acbca 373 }
a3fab7e3 374 }
abd7a3f8 375
a3fab7e3 376}
377
1fa5ece1 378/* Special Themes Block */
88cb1b4d 379if ( $colapse['Group7'] == 'off' ) {
a3fab7e3 380 $i = 0;
381 echo '<tr><th>' . _("Theme Name") .
382 '</th><th>' . _("Theme Path") .
383 '</th></tr>';
384 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
385 $k1 = "\$theme[$i]['NAME']";
386 $e1 = "theme_name_$i";
387 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
b5a29535 388 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
389 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
a3fab7e3 390 $newcfg[$k1] = $v1;
a55bb207 391 } else {
a3fab7e3 392 $v1 = $newcfg[$k1];
abd7a3f8 393 }
a3fab7e3 394 $k2 = "\$theme[$i]['PATH']";
395 $e2 = "theme_path_$i";
396 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
b5a29535 397 $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
398 $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
a3fab7e3 399 $newcfg[$k2] = $v2;
abd7a3f8 400 } else {
a3fab7e3 401 $v2 = $newcfg[$k2];
abd7a3f8 402 }
a3fab7e3 403 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
404 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
405 echo '<tr>'.
406 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
407 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
408 "</tr>\n";
409 $i++;
c83b38c1 410
6a9acbca 411 }
6a9acbca 412}
413
1fa5ece1 414/* Special Plugins Block */
88cb1b4d 415if ( $colapse['Group8'] == 'on' ) {
a3fab7e3 416 $sw = '(+)';
417} else {
418 $sw = '(-)';
6a9acbca 419}
a3fab7e3 420echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
c83b38c1 421 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
a3fab7e3 422 _("Plugins") . '</th></tr>';
6a9acbca 423
88cb1b4d 424if( $colapse['Group8'] == 'off' ) {
6a9acbca 425
a3fab7e3 426 $fd = opendir( '../plugins/' );
427 $op_plugin = array();
c83b38c1 428 $p_count = 0;
a3fab7e3 429 while (false!==($file = readdir($fd))) {
430 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
431 if ( filetype( $file ) == 'dir' ) {
432 $op_plugin[] = $file;
c83b38c1 433 $p_count++;
a3fab7e3 434 }
6a9acbca 435 }
edd4a552 436 }
a3fab7e3 437 closedir($fd);
438 asort( $op_plugin );
c83b38c1 439
440 /* Lets get the plugins that are active */
441 $plugins = array();
442 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
443 foreach ( $op_plugin as $plg ) {
88cb1b4d 444 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
445 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
c83b38c1 446 $plugins[] = $plg;
447 }
448 }
449 $i = 0;
450 foreach ( $plugins as $plg ) {
451 $k = "\$plugins[$i]";
452 $newcfg[$k] = "'$plg'";
453 $i++;
454 }
455 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
456 $k = "\$plugins[$i]";
457 $newcfg[$k] = '';
458 $i++;
459 }
460 } else {
461 $i = 0;
462 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
463 $k = "\$plugins[$i]";
a3fab7e3 464 $v = $newcfg[$k];
c83b38c1 465 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
466 $i++;
6a9acbca 467 }
c83b38c1 468 }
469 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
470 foreach ( $op_plugin as $plg ) {
471 if ( in_array( $plg, $plugins ) ) {
472 $sw = ' checked';
473 } else {
474 $sw = '';
a3fab7e3 475 }
c83b38c1 476 echo '<tr>' .
477 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
88cb1b4d 478 "</tr>\n";
6a9acbca 479 }
c83b38c1 480 echo '</td></tr></table>';
481
6a9acbca 482}
abd7a3f8 483echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
484 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 485 '</table></td></tr></table></form>';
abd7a3f8 486
487/*
488 Write the options to the file.
489*/
71e5c245 490
c05c489a 491if( $fp = @fopen( $cfgfile, 'w' ) ) {
492 fwrite( $fp, "<?PHP\n".
b5a29535 493 "/**\n".
494 " * SquirrelMail Configuration File\n".
495 " * Created using the Administrator Plugin\n".
496 " */\n" );
497
c05c489a 498 foreach ( $newcfg as $k => $v ) {
b5a29535 499 if ( $k{0} == '$' && $v <> '' ) {
c05c489a 500 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
b5a29535 501 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
502 $v = str_replace( 'array(', "array(\n\t", $v );
503 $v = str_replace( "',", "',\n\t", $v );
c05c489a 504 }
505 fwrite( $fp, "$k = $v;\n" );
b5a29535 506 }
0e66bc84 507 }
c05c489a 508 fwrite( $fp, '?>' );
509 fclose( $fp );
510} else {
511 echo '<font size=+1><br>'.
512 _("Config file can't be opened. Please check config.php.").
513 '</font>';
abd7a3f8 514}
c05c489a 515
6206f6c4 516?>