3d045bec5d76969e2e19742d0c459cc1346ee68a
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;
75 if ( $line{$j}.$line{$j+
1} == '*/' ) {
82 switch ( $line{$j} ) {
85 // Double quote string
86 $delimiter = $value = $line{$j};
93 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
95 $newcfg{$key} = 'TRUE';
98 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
99 $newcfg{$key} = 'FALSE';
103 // Number or function call
110 if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
111 // Skip untill next ;
114 } else if ( $line{$j}.$line{$j+
1} == '/*' ) {
117 } else if ( $line{$j} == '#' ||
$line{$j}.$line{$j+
1} == '//' ) {
118 // Delete till the end of the line
120 } else if ( $line{$j} == '$' ) {
121 // We must detect $key name
131 /* ---------------------- main -------------------------- */
134 require_once('../src/validate.php');
135 require_once('../functions/page_header.php');
136 require_once('../functions/imap.php');
137 require_once('../src/load_prefs.php');
138 require_once('../plugins/administrator/defines.php');
139 require_once('../plugins/administrator/auth.php');
141 GLOBAL $data_dir, $username;
143 if ( !adm_check_user() ) {
144 header("Location: ../../src/options.php") ;
148 displayPageHeader($color, 'None');
152 foreach ( $defcfg as $key => $def ) {
156 $cfgfile = '../config/config.php';
157 parseConfig( '../config/config_default.php' );
158 parseConfig( $cfgfile );
160 $colapse = array( 'Titles' => FALSE,
161 'Group1' => getPref($data_dir, $username, 'adm_Group1', FALSE ),
162 'Group2' => getPref($data_dir, $username, 'adm_Group2', TRUE ),
163 'Group3' => getPref($data_dir, $username, 'adm_Group3', TRUE ),
164 'Group4' => getPref($data_dir, $username, 'adm_Group4', TRUE ),
165 'Group5' => getPref($data_dir, $username, 'adm_Group5', TRUE ),
166 'Group6' => getPref($data_dir, $username, 'adm_Group6', TRUE ),
167 'Group7' => getPref($data_dir, $username, 'adm_Group7', TRUE ),
168 'Group8' => getPref($data_dir, $username, 'adm_Group8', TRUE ) );
170 if ( isset( $switch ) ) {
171 $colapse[$switch] = !$colapse[$switch];
172 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
175 echo "<form action=options.php method=post>" .
176 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
177 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
178 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
180 $act_grp = 'Titles'; /* Active group */
182 foreach ( $newcfg as $k => $v ) {
183 $l = strtolower( $v );
184 $type = SMOPT_TYPE_UNDEFINED
;
185 $n = substr( $k, 1 );
186 $n = str_replace( '[', '_', $n );
187 $n = str_replace( ']', '_', $n );
191 if ( isset( $defcfg[$k] ) ) {
192 $name = $defcfg[$k]['name'];
193 $type = $defcfg[$k]['type'];
194 $size = $defcfg[$k]['size'];
195 } else if ( $l == 'true' ) {
197 $type = SMOPT_TYPE_BOOLEAN
;
198 } else if ( $l == 'false' ) {
200 $type = SMOPT_TYPE_BOOLEAN
;
201 } else if ( $v{0} == "'" ) {
202 $type = SMOPT_TYPE_STRING
;
203 } else if ( $v{0} == '"' ) {
204 $type = SMOPT_TYPE_STRING
;
207 if ( substr( $k, 0, 7 ) == '$theme[' ) {
208 $type = SMOPT_TYPE_THEME
;
209 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
210 $type = SMOPT_TYPE_PLUGINS
;
211 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
212 $type = SMOPT_TYPE_LDAP
;
215 if( $type == SMOPT_TYPE_TITLE ||
!$colapse[$act_grp] ) {
218 case SMOPT_TYPE_LDAP
:
219 case SMOPT_TYPE_PLUGINS
:
220 case SMOPT_TYPE_THEME
:
221 case SMOPT_TYPE_HIDDEN
:
223 case SMOPT_TYPE_TITLE
:
224 if ( $colapse[$k] ) {
229 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
230 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
234 case SMOPT_TYPE_COMMENT
:
235 $v = substr( $v, 1, strlen( $v ) - 2 );
236 echo "<tr><td>$name</td><td>".
238 $newcfg[$k] = "'$v'";
239 if ( isset( $defcfg[$k]['comment'] ) ) {
240 echo ' ' . $defcfg[$k]['comment'];
244 case SMOPT_TYPE_INTEGER
:
245 if ( isset( $HTTP_POST_VARS[$e] ) ) {
246 $v = intval( $HTTP_POST_VARS[$e] );
249 echo "<tr><td>$name</td><td>".
250 "<input size=10 name=\"adm_$n\" value=\"$v\">";
251 if ( isset( $defcfg[$k]['comment'] ) ) {
252 echo ' ' . $defcfg[$k]['comment'];
256 case SMOPT_TYPE_NUMLIST
:
257 if ( isset( $HTTP_POST_VARS[$e] ) ) {
258 $v = $HTTP_POST_VARS[$e];
261 echo "<tr><td>$name</td><td>";
262 echo "<select name=\"adm_$n\">";
263 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
264 echo "<option value=\"$kp\"";
268 echo ">$vp</option>";
271 if ( isset( $defcfg[$k]['comment'] ) ) {
272 echo ' ' . $defcfg[$k]['comment'];
276 case SMOPT_TYPE_STRLIST
:
277 if ( isset( $HTTP_POST_VARS[$e] ) ) {
278 $v = '"' . $HTTP_POST_VARS[$e] . '"';
281 echo "<tr><td>$name</td><td>".
282 "<select name=\"adm_$n\">";
283 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
284 echo "<option value=\"$kp\"";
285 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
288 echo ">$vp</option>";
291 if ( isset( $defcfg[$k]['comment'] ) ) {
292 echo ' ' . $defcfg[$k]['comment'];
297 case SMOPT_TYPE_TEXTAREA
:
298 if ( isset( $HTTP_POST_VARS[$e] ) ) {
299 $v = '"' . $HTTP_POST_VARS[$e] . '"';
300 $newcfg[$k] = str_replace( "\n", '', $v );
302 echo "<tr><td valign=top>$name</td><td>".
303 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
304 if ( isset( $defcfg[$k]['comment'] ) ) {
305 echo ' ' . $defcfg[$k]['comment'];
309 case SMOPT_TYPE_STRING
:
310 if ( isset( $HTTP_POST_VARS[$e] ) ) {
311 $v = '"' . $HTTP_POST_VARS[$e] . '"';
314 echo "<tr><td>$name</td><td>".
315 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
316 if ( isset( $defcfg[$k]['comment'] ) ) {
317 echo ' ' . $defcfg[$k]['comment'];
321 case SMOPT_TYPE_BOOLEAN
:
322 if ( isset( $HTTP_POST_VARS[$e] ) ) {
323 $v = $HTTP_POST_VARS[$e];
326 $v = strtoupper( $v );
328 if ( $v == 'TRUE' ) {
335 echo "<tr><td>$name</td><td>" .
336 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
337 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
338 if ( isset( $defcfg[$k]['comment'] ) ) {
339 echo ' ' . $defcfg[$k]['comment'];
344 echo "<tr><td>$name</td><td>" .
346 if ( isset( $defcfg[$k]['comment'] ) ) {
347 echo ' ' . $defcfg[$k]['comment'];
355 /* Special Themes Block */
356 if ( !($colapse['Group7']) ) {
358 echo '<tr><th>' . _("Theme Name") .
359 '</th><th>' . _("Theme Path") .
361 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
362 $k1 = "\$theme[$i]['NAME']";
363 $e1 = "theme_name_$i";
364 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
365 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
370 $k2 = "\$theme[$i]['PATH']";
371 $e2 = "theme_path_$i";
372 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
373 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
378 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
379 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
381 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
382 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
389 /* Special Plugins Block */
390 if ( $colapse['Group8'] ) {
395 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
396 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
397 _("Plugins") . '</th></tr>';
399 if( !$colapse['Group8'] ) {
401 $fd = opendir( '../plugins/' );
402 $op_plugin = array();
404 while (false!==($file = readdir($fd))) {
405 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
406 if ( filetype( $file ) == 'dir' ) {
407 $op_plugin[] = $file;
415 /* Lets get the plugins that are active */
417 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
418 foreach ( $op_plugin as $plg ) {
419 if ( $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
424 foreach ( $plugins as $plg ) {
425 $k = "\$plugins[$i]";
426 $newcfg[$k] = "'$plg'";
429 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
430 $k = "\$plugins[$i]";
436 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
437 $k = "\$plugins[$i]";
439 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
443 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
444 foreach ( $op_plugin as $plg ) {
445 if ( in_array( $plg, $plugins ) ) {
451 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
454 echo '</td></tr></table>';
457 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
458 _("Change Settings") . "\" type=submit></th></tr>" ,
459 '</table></td></tr></table></form>';
462 Write the options to the file.
465 $fp = fopen( $cfgfile, 'w' );
466 fwrite( $fp, "<?PHP\n".
468 " * SquirrelMail Configuration File\n".
469 " * Created using the Administrator Plugin\n".
473 fwrite( $fp, 'GLOBAL ' );
475 foreach ( $newcfg as $k => $v ) {
476 if ( $k{0} == '$' ) {
477 if( $i = strpos( $k, '[' ) ) {
478 if( strpos( $k, '[0]' ) ) {
482 fwrite( $fp, substr( $k, 0, $i) );
493 fwrite( $fp, ";\n" );
495 foreach ( $newcfg as $k => $v ) {
496 if ( $k{0} == '$' && $v <> '' ) {
497 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
498 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
499 $v = str_replace( 'array(', "array(\n\t", $v );
500 $v = str_replace( "',", "',\n\t", $v );
502 fwrite( $fp, "$k = $v;\n" );