3963b972136cc82c63f97811b12deb2fa06cc833
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
14 function parseConfig( $cfg_file ) {
18 $cfg = file( $cfg_file );
23 for ($i=0;$i<$l;$i++
) {
24 $line = trim( $cfg[$i] );
26 for ($j=0;$j<$s;$j++
) {
29 if ( $line{$j} == '=' ) {
30 // Ok, we've got a right value, lets detect what type
32 } else if ( $line{$j} == ';' ) {
39 if( $line{$j} == ' ' ) {
47 if ( $line{$j} == ';' ) {
52 if ( $line{$j} == '\\' ) {
55 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
57 $newcfg[$key] = $value . $delimiter;
66 if ( $line{$j} == ';' ) {
67 $newcfg{$key} = $value;
76 $line{$j}.$line{$j+
1} == '*/' ) {
83 switch ( $line{$j} ) {
86 // Double quote string
87 $delimiter = $value = $line{$j};
94 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
96 $newcfg{$key} = 'TRUE';
99 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
100 $newcfg{$key} = 'FALSE';
104 // Number or function call
111 if ( $line{$j} == '$' ) {
112 // We must detect $key name
115 } else if ( $s < $j +
2 ) {
116 } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
117 // Skip untill next ;
120 } else if ( $line{$j}.$line{$j+
1} == '/*' ) {
123 } else if ( $line{$j} == '#' ||
$line{$j}.$line{$j+
1} == '//' ) {
124 // Delete till the end of the line
133 /* ---------------------- main -------------------------- */
136 require_once('../src/validate.php');
137 require_once('../functions/page_header.php');
138 require_once('../functions/imap.php');
139 require_once('../src/load_prefs.php');
140 require_once('../plugins/administrator/defines.php');
141 require_once('../plugins/administrator/auth.php');
143 GLOBAL $data_dir, $username;
145 if ( !adm_check_user() ) {
146 header("Location: ../../src/options.php") ;
150 displayPageHeader($color, 'None');
154 foreach ( $defcfg as $key => $def ) {
158 $cfgfile = '../config/config.php';
159 parseConfig( '../config/config_default.php' );
160 parseConfig( $cfgfile );
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' ) );
172 if ( isset( $switch ) ) {
174 if ( $colapse[$switch] == 'on' ) {
175 $colapse[$switch] = 'off';
177 $colapse[$switch] = 'on';
179 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
183 echo "<form action=options.php method=post name=options>" .
184 "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
185 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
186 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
188 $act_grp = 'Titles'; /* Active group */
190 foreach ( $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 );
199 if ( isset( $defcfg[$k] ) ) {
200 $name = $defcfg[$k]['name'];
201 $type = $defcfg[$k]['type'];
202 if ( isset( $defcfg[$k]['size'] ) ) {
203 $size = $defcfg[$k]['size'];
207 } else if ( $l == 'true' ) {
209 $type = SMOPT_TYPE_BOOLEAN
;
210 } else if ( $l == '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
;
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
;
223 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
224 $type = SMOPT_TYPE_LDAP
;
227 if( $type == SMOPT_TYPE_TITLE ||
$colapse[$act_grp] == 'off' ) {
230 case SMOPT_TYPE_LDAP
:
231 case SMOPT_TYPE_PLUGINS
:
232 case SMOPT_TYPE_THEME
:
233 case SMOPT_TYPE_HIDDEN
:
235 case SMOPT_TYPE_EXTERNAL
:
236 echo "<tr><td>$name</td><td><b>" .
237 $defcfg[$k]['value'] .
240 case SMOPT_TYPE_TITLE
:
241 if ( $colapse[$k] == 'on' ) {
246 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
247 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
251 case SMOPT_TYPE_COMMENT
:
252 $v = substr( $v, 1, strlen( $v ) - 2 );
253 echo "<tr><td>$name</td><td>".
255 $newcfg[$k] = "'$v'";
256 if ( isset( $defcfg[$k]['comment'] ) ) {
257 echo ' ' . $defcfg[$k]['comment'];
261 case SMOPT_TYPE_INTEGER
:
262 if ( isset( $HTTP_POST_VARS[$e] ) ) {
263 $v = intval( $HTTP_POST_VARS[$e] );
266 echo "<tr><td>$name</td><td>".
267 "<input size=10 name=\"adm_$n\" value=\"$v\">";
268 if ( isset( $defcfg[$k]['comment'] ) ) {
269 echo ' ' . $defcfg[$k]['comment'];
273 case SMOPT_TYPE_NUMLIST
:
274 if ( isset( $HTTP_POST_VARS[$e] ) ) {
275 $v = $HTTP_POST_VARS[$e];
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\"";
285 echo ">$vp</option>";
288 if ( isset( $defcfg[$k]['comment'] ) ) {
289 echo ' ' . $defcfg[$k]['comment'];
293 case SMOPT_TYPE_STRLIST
:
294 if ( isset( $HTTP_POST_VARS[$e] ) ) {
295 $v = '"' . $HTTP_POST_VARS[$e] . '"';
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 ) ) {
305 echo ">$vp</option>";
308 if ( isset( $defcfg[$k]['comment'] ) ) {
309 echo ' ' . $defcfg[$k]['comment'];
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 );
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 ' ' . $defcfg[$k]['comment'];
326 case SMOPT_TYPE_STRING
:
327 if ( isset( $HTTP_POST_VARS[$e] ) ) {
328 $v = '"' . $HTTP_POST_VARS[$e] . '"';
331 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
332 $v = "'" . $defcfg[$k]['default'] . "'";
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 ' ' . $defcfg[$k]['comment'];
342 case SMOPT_TYPE_BOOLEAN
:
343 if ( isset( $HTTP_POST_VARS[$e] ) ) {
344 $v = $HTTP_POST_VARS[$e];
347 $v = strtoupper( $v );
349 if ( $v == 'TRUE' ) {
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 ' ' . $defcfg[$k]['comment'];
365 echo "<tr><td>$name</td><td>" .
367 if ( isset( $defcfg[$k]['comment'] ) ) {
368 echo ' ' . $defcfg[$k]['comment'];
376 /* Special Themes Block */
377 if ( $colapse['Group7'] == 'off' ) {
379 echo '<tr><th>' . _("Theme Name") .
380 '</th><th>' . _("Theme Path") .
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 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
387 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
392 $k2 = "\$theme[$i]['PATH']";
393 $e2 = "theme_path_$i";
394 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
395 $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
396 $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
401 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
402 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
404 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
405 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
412 /* Special Plugins Block */
413 if ( $colapse['Group8'] == 'on' ) {
418 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
419 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
420 _("Plugins") . '</th></tr>';
422 if( $colapse['Group8'] == 'off' ) {
424 $fd = opendir( '../plugins/' );
425 $op_plugin = array();
427 while (false!==($file = readdir($fd))) {
428 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
429 if ( filetype( $file ) == 'dir' ) {
430 $op_plugin[] = $file;
438 /* Lets get the plugins that are active */
440 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
441 foreach ( $op_plugin as $plg ) {
442 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
443 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
448 foreach ( $plugins as $plg ) {
449 $k = "\$plugins[$i]";
450 $newcfg[$k] = "'$plg'";
453 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
454 $k = "\$plugins[$i]";
460 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
461 $k = "\$plugins[$i]";
463 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
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 ) ) {
475 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
478 echo '</td></tr></table>';
481 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
482 _("Change Settings") . "\" type=submit></th></tr>" ,
483 '</table></td></tr></table></form>';
486 Write the options to the file.
489 if( $fp = @fopen
( $cfgfile, 'w' ) ) {
490 fwrite( $fp, "<?PHP\n".
492 " * SquirrelMail Configuration File\n".
493 " * Created using the Administrator Plugin\n".
496 foreach ( $newcfg as $k => $v ) {
497 if ( $k{0} == '$' && $v <> '' ) {
498 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
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 );
503 fwrite( $fp, "$k = $v;\n" );
509 echo '<font size=+1><br>'.
510 _("Config file can't be opened. Please check config.php.").