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');
140 GLOBAL $data_dir, $username;
143 if ( $adm_id = fileowner('../config/config.php') ) {
144 $adm = posix_getpwuid( $adm_id );
145 if ( $username == $adm['name'] ) {
151 header("Location: ../../src/options.php") ;
155 displayPageHeader($color, 'None');
159 foreach ( $defcfg as $key => $def ) {
163 $cfgfile = '../config/config.php';
164 parseConfig( '../config/config_default.php' );
165 parseConfig( $cfgfile );
167 $colapse = array( 'Titles' => FALSE,
168 'Group1' => getPref($data_dir, $username, 'adm_Group1', FALSE ),
169 'Group2' => getPref($data_dir, $username, 'adm_Group2', TRUE ),
170 'Group3' => getPref($data_dir, $username, 'adm_Group3', TRUE ),
171 'Group4' => getPref($data_dir, $username, 'adm_Group4', TRUE ),
172 'Group5' => getPref($data_dir, $username, 'adm_Group5', TRUE ),
173 'Group6' => getPref($data_dir, $username, 'adm_Group6', TRUE ),
174 'Group7' => getPref($data_dir, $username, 'adm_Group7', TRUE ),
175 'Group8' => getPref($data_dir, $username, 'adm_Group8', TRUE ) );
177 if ( isset( $switch ) ) {
178 $colapse[$switch] = !$colapse[$switch];
179 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
182 echo "<form action=options.php method=post>" .
183 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
184 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
185 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
187 $act_grp = 'Titles'; /* Active group */
189 foreach ( $newcfg as $k => $v ) {
190 $l = strtolower( $v );
191 $type = SMOPT_TYPE_UNDEFINED
;
192 $n = substr( $k, 1 );
193 $n = str_replace( '[', '_', $n );
194 $n = str_replace( ']', '_', $n );
198 if ( isset( $defcfg[$k] ) ) {
199 $name = $defcfg[$k]['name'];
200 $type = $defcfg[$k]['type'];
201 $size = $defcfg[$k]['size'];
202 } else if ( $l == 'true' ) {
204 $type = SMOPT_TYPE_BOOLEAN
;
205 } else if ( $l == 'false' ) {
207 $type = SMOPT_TYPE_BOOLEAN
;
208 } else if ( $v{0} == "'" ) {
209 $type = SMOPT_TYPE_STRING
;
210 } else if ( $v{0} == '"' ) {
211 $type = SMOPT_TYPE_STRING
;
214 if ( substr( $k, 0, 7 ) == '$theme[' ) {
215 $type = SMOPT_TYPE_THEME
;
216 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
217 $type = SMOPT_TYPE_PLUGINS
;
218 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
219 $type = SMOPT_TYPE_LDAP
;
222 if( $type == SMOPT_TYPE_TITLE ||
!$colapse[$act_grp] ) {
225 case SMOPT_TYPE_LDAP
:
226 case SMOPT_TYPE_PLUGINS
:
227 case SMOPT_TYPE_THEME
:
228 case SMOPT_TYPE_HIDDEN
:
230 case SMOPT_TYPE_TITLE
:
231 if ( $colapse[$k] ) {
236 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
237 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
241 case SMOPT_TYPE_COMMENT
:
242 $v = substr( $v, 1, strlen( $v ) - 2 );
243 echo "<tr><td>$name</td><td>".
245 $newcfg[$k] = "'$v'";
246 if ( isset( $defcfg[$k]['comment'] ) ) {
247 echo ' ' . $defcfg[$k]['comment'];
251 case SMOPT_TYPE_INTEGER
:
252 if ( isset( $HTTP_POST_VARS[$e] ) ) {
253 $v = intval( $HTTP_POST_VARS[$e] );
256 echo "<tr><td>$name</td><td>".
257 "<input size=10 name=\"adm_$n\" value=\"$v\">";
258 if ( isset( $defcfg[$k]['comment'] ) ) {
259 echo ' ' . $defcfg[$k]['comment'];
263 case SMOPT_TYPE_NUMLIST
:
264 if ( isset( $HTTP_POST_VARS[$e] ) ) {
265 $v = $HTTP_POST_VARS[$e];
268 echo "<tr><td>$name</td><td>";
269 echo "<select name=\"adm_$n\">";
270 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
271 echo "<option value=\"$kp\"";
275 echo ">$vp</option>";
278 if ( isset( $defcfg[$k]['comment'] ) ) {
279 echo ' ' . $defcfg[$k]['comment'];
283 case SMOPT_TYPE_STRLIST
:
284 if ( isset( $HTTP_POST_VARS[$e] ) ) {
285 $v = '"' . $HTTP_POST_VARS[$e] . '"';
288 echo "<tr><td>$name</td><td>".
289 "<select name=\"adm_$n\">";
290 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
291 echo "<option value=\"$kp\"";
292 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
295 echo ">$vp</option>";
298 if ( isset( $defcfg[$k]['comment'] ) ) {
299 echo ' ' . $defcfg[$k]['comment'];
304 case SMOPT_TYPE_TEXTAREA
:
305 if ( isset( $HTTP_POST_VARS[$e] ) ) {
306 $v = '"' . $HTTP_POST_VARS[$e] . '"';
307 $newcfg[$k] = str_replace( "\n", '', $v );
309 echo "<tr><td valign=top>$name</td><td>".
310 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
311 if ( isset( $defcfg[$k]['comment'] ) ) {
312 echo ' ' . $defcfg[$k]['comment'];
316 case SMOPT_TYPE_STRING
:
317 if ( isset( $HTTP_POST_VARS[$e] ) ) {
318 $v = '"' . $HTTP_POST_VARS[$e] . '"';
321 echo "<tr><td>$name</td><td>".
322 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
323 if ( isset( $defcfg[$k]['comment'] ) ) {
324 echo ' ' . $defcfg[$k]['comment'];
328 case SMOPT_TYPE_BOOLEAN
:
329 if ( isset( $HTTP_POST_VARS[$e] ) ) {
330 $v = $HTTP_POST_VARS[$e];
333 $v = strtoupper( $v );
335 if ( $v == 'TRUE' ) {
342 echo "<tr><td>$name</td><td>" .
343 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
344 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
345 if ( isset( $defcfg[$k]['comment'] ) ) {
346 echo ' ' . $defcfg[$k]['comment'];
351 echo "<tr><td>$name</td><td>" .
353 if ( isset( $defcfg[$k]['comment'] ) ) {
354 echo ' ' . $defcfg[$k]['comment'];
362 /* Special Themes Block */
363 if ( !($colapse['Group7']) ) {
365 echo '<tr><th>' . _("Theme Name") .
366 '</th><th>' . _("Theme Path") .
368 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
369 $k1 = "\$theme[$i]['NAME']";
370 $e1 = "theme_name_$i";
371 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
372 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
377 $k2 = "\$theme[$i]['PATH']";
378 $e2 = "theme_path_$i";
379 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
380 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
385 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
386 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
388 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
389 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
396 /* Special Plugins Block */
397 if ( $colapse['Group8'] ) {
402 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
403 "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
404 _("Plugins") . '</th></tr>';
406 if( !$colapse['Group8'] ) {
408 $fd = opendir( '../plugins/' );
409 $op_plugin = array();
411 while (false!==($file = readdir($fd))) {
412 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
413 if ( filetype( $file ) == 'dir' ) {
414 $op_plugin[] = $file;
422 /* Lets get the plugins that are active */
424 if ( isset( $HTTP_POST_VARS['plg'] ) ) {
425 foreach ( $op_plugin as $plg ) {
426 if ( $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
431 foreach ( $plugins as $plg ) {
432 $k = "\$plugins[$i]";
433 $newcfg[$k] = "'$plg'";
436 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
437 $k = "\$plugins[$i]";
443 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
444 $k = "\$plugins[$i]";
446 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
450 echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
451 foreach ( $op_plugin as $plg ) {
452 if ( in_array( $plg, $plugins ) ) {
458 "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
461 echo '</td></tr></table>';
464 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
465 _("Change Settings") . "\" type=submit></th></tr>" ,
466 '</table></td></tr></table></form>';
469 Write the options to the file.
472 $fp = fopen( $cfgfile, 'w' );
473 fwrite( $fp, "<?PHP\n".
475 " * SquirrelMail Configuration File\n".
476 " * Created using the Administrator Plugin\n".
480 fwrite( $fp, 'GLOBAL ' );
482 foreach ( $newcfg as $k => $v ) {
483 if ( $k{0} == '$' ) {
484 if( $i = strpos( $k, '[' ) ) {
485 if( strpos( $k, '[0]' ) ) {
489 fwrite( $fp, substr( $k, 0, $i) );
500 fwrite( $fp, ";\n" );
502 foreach ( $newcfg as $k => $v ) {
503 if ( $k{0} == '$' && $v <> '' ) {
504 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
505 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
506 $v = str_replace( 'array(', "array(\n\t", $v );
507 $v = str_replace( "',", "',\n\t", $v );
509 fwrite( $fp, "$k = $v;\n" );