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