fix for getting the filenames
[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] ) ) {
b5a29535 386 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
387 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
a3fab7e3 388 $newcfg[$k1] = $v1;
a55bb207 389 } else {
a3fab7e3 390 $v1 = $newcfg[$k1];
abd7a3f8 391 }
a3fab7e3 392 $k2 = "\$theme[$i]['PATH']";
393 $e2 = "theme_path_$i";
394 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
b5a29535 395 $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
396 $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
a3fab7e3 397 $newcfg[$k2] = $v2;
abd7a3f8 398 } else {
a3fab7e3 399 $v2 = $newcfg[$k2];
abd7a3f8 400 }
a3fab7e3 401 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
402 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
403 echo '<tr>'.
404 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
405 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
406 "</tr>\n";
407 $i++;
c83b38c1 408
6a9acbca 409 }
6a9acbca 410}
411
1fa5ece1 412/* Special Plugins Block */
88cb1b4d 413if ( $colapse['Group8'] == 'on' ) {
a3fab7e3 414 $sw = '(+)';
415} else {
416 $sw = '(-)';
6a9acbca 417}
a3fab7e3 418echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
c83b38c1 419 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
a3fab7e3 420 _("Plugins") . '</th></tr>';
6a9acbca 421
88cb1b4d 422if( $colapse['Group8'] == 'off' ) {
6a9acbca 423
a3fab7e3 424 $fd = opendir( '../plugins/' );
425 $op_plugin = array();
c83b38c1 426 $p_count = 0;
a3fab7e3 427 while (false!==($file = readdir($fd))) {
428 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
429 if ( filetype( $file ) == 'dir' ) {
430 $op_plugin[] = $file;
c83b38c1 431 $p_count++;
a3fab7e3 432 }
6a9acbca 433 }
edd4a552 434 }
a3fab7e3 435 closedir($fd);
436 asort( $op_plugin );
c83b38c1 437
438 /* Lets get the plugins that are active */
439 $plugins = array();
440 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
441 foreach ( $op_plugin as $plg ) {
88cb1b4d 442 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
443 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
c83b38c1 444 $plugins[] = $plg;
445 }
446 }
447 $i = 0;
448 foreach ( $plugins as $plg ) {
449 $k = "\$plugins[$i]";
450 $newcfg[$k] = "'$plg'";
451 $i++;
452 }
453 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
454 $k = "\$plugins[$i]";
455 $newcfg[$k] = '';
456 $i++;
457 }
458 } else {
459 $i = 0;
460 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
461 $k = "\$plugins[$i]";
a3fab7e3 462 $v = $newcfg[$k];
c83b38c1 463 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
464 $i++;
6a9acbca 465 }
c83b38c1 466 }
467 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
468 foreach ( $op_plugin as $plg ) {
469 if ( in_array( $plg, $plugins ) ) {
470 $sw = ' checked';
471 } else {
472 $sw = '';
a3fab7e3 473 }
c83b38c1 474 echo '<tr>' .
475 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
88cb1b4d 476 "</tr>\n";
6a9acbca 477 }
c83b38c1 478 echo '</td></tr></table>';
479
6a9acbca 480}
abd7a3f8 481echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
482 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 483 '</table></td></tr></table></form>';
abd7a3f8 484
485/*
486 Write the options to the file.
487*/
71e5c245 488
c05c489a 489if( $fp = @fopen( $cfgfile, 'w' ) ) {
490 fwrite( $fp, "<?PHP\n".
b5a29535 491 "/**\n".
492 " * SquirrelMail Configuration File\n".
493 " * Created using the Administrator Plugin\n".
494 " */\n" );
495
c05c489a 496 foreach ( $newcfg as $k => $v ) {
b5a29535 497 if ( $k{0} == '$' && $v <> '' ) {
c05c489a 498 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
b5a29535 499 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
500 $v = str_replace( 'array(', "array(\n\t", $v );
501 $v = str_replace( "',", "',\n\t", $v );
c05c489a 502 }
503 fwrite( $fp, "$k = $v;\n" );
b5a29535 504 }
0e66bc84 505 }
c05c489a 506 fwrite( $fp, '?>' );
507 fclose( $fp );
508} else {
509 echo '<font size=+1><br>'.
510 _("Config file can't be opened. Please check config.php.").
511 '</font>';
abd7a3f8 512}
c05c489a 513
37d90494 514?>