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 -------------------------- */
137 define('SM_PATH','../');
139 /* SquirrelMail required files. */
140 require_once(SM_PATH
. 'include/validate.php');
141 require_once(SM_PATH
. 'functions/page_header.php');
142 require_once(SM_PATH
. 'functions/imap.php');
143 require_once(SM_PATH
. 'src/load_prefs.php');
144 require_once(SM_PATH
. 'plugins/administrator/defines.php');
145 require_once(SM_PATH
. 'plugins/administrator/auth.php');
147 GLOBAL $data_dir, $username;
149 if ( !adm_check_user() ) {
150 header("Location: ../../src/options.php") ;
154 displayPageHeader($color, 'None');
158 foreach ( $defcfg as $key => $def ) {
162 $cfgfile = '../config/config.php';
163 parseConfig( '../config/config_default.php' );
164 parseConfig( $cfgfile );
166 $colapse = array( 'Titles' => 'off',
167 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
168 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
169 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
170 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
171 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
172 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
173 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
174 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
176 if ( isset( $switch ) ) {
178 if ( $colapse[$switch] == 'on' ) {
179 $colapse[$switch] = 'off';
181 $colapse[$switch] = 'on';
183 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
187 echo "<form action=options.php method=post name=options>" .
188 "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
189 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
190 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
192 $act_grp = 'Titles'; /* Active group */
194 foreach ( $newcfg as $k => $v ) {
195 $l = strtolower( $v );
196 $type = SMOPT_TYPE_UNDEFINED
;
197 $n = substr( $k, 1 );
198 $n = str_replace( '[', '_', $n );
199 $n = str_replace( ']', '_', $n );
203 if ( isset( $defcfg[$k] ) ) {
204 $name = $defcfg[$k]['name'];
205 $type = $defcfg[$k]['type'];
206 if ( isset( $defcfg[$k]['size'] ) ) {
207 $size = $defcfg[$k]['size'];
211 } else if ( $l == 'true' ) {
213 $type = SMOPT_TYPE_BOOLEAN
;
214 } else if ( $l == 'false' ) {
216 $type = SMOPT_TYPE_BOOLEAN
;
217 } else if ( $v{0} == "'" ) {
218 $type = SMOPT_TYPE_STRING
;
219 } else if ( $v{0} == '"' ) {
220 $type = SMOPT_TYPE_STRING
;
223 if ( substr( $k, 0, 7 ) == '$theme[' ) {
224 $type = SMOPT_TYPE_THEME
;
225 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
226 $type = SMOPT_TYPE_PLUGINS
;
227 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
228 $type = SMOPT_TYPE_LDAP
;
231 if( $type == SMOPT_TYPE_TITLE ||
$colapse[$act_grp] == 'off' ) {
234 case SMOPT_TYPE_LDAP
:
235 case SMOPT_TYPE_PLUGINS
:
236 case SMOPT_TYPE_THEME
:
237 case SMOPT_TYPE_HIDDEN
:
239 case SMOPT_TYPE_EXTERNAL
:
240 echo "<tr><td>$name</td><td><b>" .
241 $defcfg[$k]['value'] .
244 case SMOPT_TYPE_TITLE
:
245 if ( $colapse[$k] == 'on' ) {
250 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
251 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
255 case SMOPT_TYPE_COMMENT
:
256 $v = substr( $v, 1, strlen( $v ) - 2 );
257 echo "<tr><td>$name</td><td>".
259 $newcfg[$k] = "'$v'";
260 if ( isset( $defcfg[$k]['comment'] ) ) {
261 echo ' ' . $defcfg[$k]['comment'];
265 case SMOPT_TYPE_INTEGER
:
266 if ( isset( $HTTP_POST_VARS[$e] ) ) {
267 $v = intval( $HTTP_POST_VARS[$e] );
270 echo "<tr><td>$name</td><td>".
271 "<input size=10 name=\"adm_$n\" value=\"$v\">";
272 if ( isset( $defcfg[$k]['comment'] ) ) {
273 echo ' ' . $defcfg[$k]['comment'];
277 case SMOPT_TYPE_NUMLIST
:
278 if ( isset( $HTTP_POST_VARS[$e] ) ) {
279 $v = $HTTP_POST_VARS[$e];
282 echo "<tr><td>$name</td><td>";
283 echo "<select name=\"adm_$n\">";
284 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
285 echo "<option value=\"$kp\"";
289 echo ">$vp</option>";
292 if ( isset( $defcfg[$k]['comment'] ) ) {
293 echo ' ' . $defcfg[$k]['comment'];
297 case SMOPT_TYPE_STRLIST
:
298 if ( isset( $HTTP_POST_VARS[$e] ) ) {
299 $v = '"' . $HTTP_POST_VARS[$e] . '"';
302 echo "<tr><td>$name</td><td>".
303 "<select name=\"adm_$n\">";
304 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
305 echo "<option value=\"$kp\"";
306 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
309 echo ">$vp</option>";
312 if ( isset( $defcfg[$k]['comment'] ) ) {
313 echo ' ' . $defcfg[$k]['comment'];
318 case SMOPT_TYPE_TEXTAREA
:
319 if ( isset( $HTTP_POST_VARS[$e] ) ) {
320 $v = '"' . $HTTP_POST_VARS[$e] . '"';
321 $newcfg[$k] = str_replace( "\n", '', $v );
323 echo "<tr><td valign=top>$name</td><td>".
324 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
325 if ( isset( $defcfg[$k]['comment'] ) ) {
326 echo ' ' . $defcfg[$k]['comment'];
330 case SMOPT_TYPE_STRING
:
331 if ( isset( $HTTP_POST_VARS[$e] ) ) {
332 $v = '"' . $HTTP_POST_VARS[$e] . '"';
335 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
336 $v = "'" . $defcfg[$k]['default'] . "'";
339 echo "<tr><td>$name</td><td>".
340 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
341 if ( isset( $defcfg[$k]['comment'] ) ) {
342 echo ' ' . $defcfg[$k]['comment'];
346 case SMOPT_TYPE_BOOLEAN
:
347 if ( isset( $HTTP_POST_VARS[$e] ) ) {
348 $v = $HTTP_POST_VARS[$e];
351 $v = strtoupper( $v );
353 if ( $v == 'TRUE' ) {
360 echo "<tr><td>$name</td><td>" .
361 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
362 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
363 if ( isset( $defcfg[$k]['comment'] ) ) {
364 echo ' ' . $defcfg[$k]['comment'];
369 echo "<tr><td>$name</td><td>" .
371 if ( isset( $defcfg[$k]['comment'] ) ) {
372 echo ' ' . $defcfg[$k]['comment'];
380 /* Special Themes Block */
381 if ( $colapse['Group7'] == 'off' ) {
383 echo '<tr><th>' . _("Theme Name") .
384 '</th><th>' . _("Theme Path") .
386 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
387 $k1 = "\$theme[$i]['NAME']";
388 $e1 = "theme_name_$i";
389 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
390 $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
391 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
396 $k2 = "\$theme[$i]['PATH']";
397 $e2 = "theme_path_$i";
398 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
399 $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
400 $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
405 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
406 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
408 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
409 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
416 /* Special Plugins Block */
417 if ( $colapse['Group8'] == 'on' ) {
422 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
423 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
424 _("Plugins") . '</th></tr>';
426 if( $colapse['Group8'] == 'off' ) {
428 $fd = opendir( '../plugins/' );
429 $op_plugin = array();
431 while (false!==($file = readdir($fd))) {
432 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
433 if ( filetype( $file ) == 'dir' ) {
434 $op_plugin[] = $file;
442 /* Lets get the plugins that are active */
444 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
445 foreach ( $op_plugin as $plg ) {
446 if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
447 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
452 foreach ( $plugins as $plg ) {
453 $k = "\$plugins[$i]";
454 $newcfg[$k] = "'$plg'";
457 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
458 $k = "\$plugins[$i]";
464 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
465 $k = "\$plugins[$i]";
467 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
471 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
472 foreach ( $op_plugin as $plg ) {
473 if ( in_array( $plg, $plugins ) ) {
479 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
482 echo '</td></tr></table>';
485 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
486 _("Change Settings") . "\" type=submit></th></tr>" ,
487 '</table></td></tr></table></form>';
490 Write the options to the file.
493 if( $fp = @fopen
( $cfgfile, 'w' ) ) {
494 fwrite( $fp, "<?PHP\n".
496 " * SquirrelMail Configuration File\n".
497 " * Created using the Administrator Plugin\n".
500 foreach ( $newcfg as $k => $v ) {
501 if ( $k{0} == '$' && $v <> '' ) {
502 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
503 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
504 $v = str_replace( 'array(', "array(\n\t", $v );
505 $v = str_replace( "',", "',\n\t", $v );
507 fwrite( $fp, "$k = $v;\n" );
513 echo '<font size=+1><br>'.
514 _("Config file can't be opened. Please check config.php.").