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');
141 if ( $adm_id = fileowner('../config/config.php') ) {
142 $adm = posix_getpwuid( $adm_id );
143 if ( $username == $adm['name'] ) {
149 header("Location: ../../src/options.php") ;
153 displayPageHeader($color, 'None');
157 foreach ( $defcfg as $key => $def ) {
161 $cfgfile = '../config/config.php';
162 parseConfig( '../config/config_default.php' );
163 parseConfig( $cfgfile );
165 echo "<form action=$PHP_SELF method=post>" .
166 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
167 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
168 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
169 foreach ( $newcfg as $k => $v ) {
170 $l = strtolower( $v );
171 $type = SMOPT_TYPE_UNDEFINED
;
172 $n = substr( $k, 1 );
173 $n = str_replace( '[', '_', $n );
174 $n = str_replace( ']', '_', $n );
178 if ( isset( $defcfg[$k] ) ) {
179 $name = $defcfg[$k]['name'];
180 $type = $defcfg[$k]['type'];
181 $size = $defcfg[$k]['size'];
182 } else if ( $l == 'true' ) {
184 $type = SMOPT_TYPE_BOOLEAN
;
185 } else if ( $l == 'false' ) {
187 $type = SMOPT_TYPE_BOOLEAN
;
188 } else if ( $v{0} == "'" ) {
189 $type = SMOPT_TYPE_STRING
;
190 } else if ( $v{0} == '"' ) {
191 $type = SMOPT_TYPE_STRING
;
195 case SMOPT_TYPE_TITLE
:
196 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
198 case SMOPT_TYPE_COMMENT
:
199 $v = substr( $v, 1, strlen( $v ) - 2 );
200 echo "<tr><td>$name</td><td>".
202 $newcfg[$k] = "'$v'";
204 case SMOPT_TYPE_INTEGER
:
205 if ( isset( $HTTP_POST_VARS[$e] ) ) {
206 $v = intval( $HTTP_POST_VARS[$e] );
209 echo "<tr><td>$name</td><td>".
210 "<input size=10 name=\"adm_$n\" value=\"$v\">";
212 case SMOPT_TYPE_NUMLIST
:
213 if ( isset( $HTTP_POST_VARS[$e] ) ) {
214 $v = $HTTP_POST_VARS[$e];
217 echo "<tr><td>$name</td><td>";
218 echo "<select name=\"adm_$n\">";
219 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
220 echo "<option value=\"$kp\"";
224 echo ">$vp</option>";
228 case SMOPT_TYPE_STRLIST
:
229 if ( isset( $HTTP_POST_VARS[$e] ) ) {
230 $v = '"' . $HTTP_POST_VARS[$e] . '"';
233 echo "<tr><td>$name</td><td>".
234 "<select name=\"adm_$n\">";
235 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
236 echo "<option value=\"$kp\"";
237 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
240 echo ">$vp</option>";
245 case SMOPT_TYPE_STRING
:
246 if ( isset( $HTTP_POST_VARS[$e] ) ) {
247 $v = '"' . $HTTP_POST_VARS[$e] . '"';
250 echo "<tr><td>$name</td><td>".
251 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
253 case SMOPT_TYPE_BOOLEAN
:
254 if ( isset( $HTTP_POST_VARS[$e] ) ) {
255 $v = $HTTP_POST_VARS[$e];
258 $v = strtoupper( $v );
260 if ( $v == 'TRUE' ) {
267 echo "<tr><td>$name</td><td>" .
268 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
269 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
272 echo "<tr><td>$name</td><td>" .
277 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
278 _("Change Settings") . "\" type=submit></th></tr>" ,
279 '</table></td></tr></table></form>';
282 Write the options to the file.
285 $fp = fopen( $cfgfile, 'w' );
286 fwrite( $fp, "<?PHP\n".
288 " * SquirrelMail Configuration File\n".
289 " * Created using the Administrator Plugin\n".
292 fwrite( $fp, 'GLOBAL ' );
294 foreach ( $newcfg as $k => $v ) {
295 if ( $k{0} == '$' ) {
296 if( $i = strpos( $k, '[' ) ) {
297 if( strpos( $k, '[0]' ) ) {
301 fwrite( $fp, substr( $k, 0, $i) );
313 fwrite( $fp, ";\n" );
314 foreach ( $newcfg as $k => $v ) {
315 if ( $k{0} == '$' ) {
316 fwrite( $fp, "$k = $v;\n" );