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 );
22 for ( $i=0; $i < $j; $i++
) {
24 $first_char = $cfg[$i]{0};
27 $c = trim( $cfg[$i] );
28 // This is not correct. We should extract strings before removing comments.
29 $c = preg_replace( '/\/\*.*\*\//', '', $c );
30 $c = preg_replace( '/#.*$/', '', $c );
31 $c = preg_replace( '/\/\/.*$/', '', $c );
35 } while( $first_char == '$' && substr( $c, -1 ) <> ';' && $i < $j );
39 if( substr( $l, -2 ) == '*/' ) {
42 } else if( $k = strpos( $l, '*/' ) ) {
43 $l = substr( $l, $k );
49 if( $l{0}.$l{1} == '/*' ) {
52 } else if ( $k = strpos( $l, '/*' ) ) {
53 $l = substr( $l, 0, $k );
58 if ( $k = strpos( $l, '=' ) ) {
59 $key = trim( substr( $l, 0, $k - 1 ) );
60 $val = str_replace( ';', '', trim( substr( $l, $k +
1 ) ) );
68 /* ---------------------- main -------------------------- */
70 require_once('../src/validate.php');
71 require_once('../functions/page_header.php');
72 require_once('../functions/imap.php');
73 require_once('../src/load_prefs.php');
74 require_once('../plugins/administrator/defines.php');
77 if ( $adm_id = fileowner('../config/config.php') ) {
78 $adm = posix_getpwuid( $adm_id );
79 if ( $username == $adm['name'] ) {
85 header("Location: ../../src/options.php") ;
89 displayPageHeader($color, 'None');
93 foreach ( $defcfg as $key => $def ) {
97 $cfgfile = '../config/config.php';
98 parseConfig( '../config/config_default.php' );
99 parseConfig( $cfgfile );
101 echo "<form action=$PHP_SELF method=post>" .
102 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
103 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
104 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
105 foreach ( $newcfg as $k => $v ) {
106 $l = strtolower( $v );
107 $type = SMOPT_TYPE_UNDEFINED
;
108 $n = substr( $k, 1 );
109 $n = str_replace( '[', '_', $n );
110 $n = str_replace( ']', '_', $n );
114 if ( isset( $defcfg[$k] ) ) {
115 $name = $defcfg[$k]['name'];
116 $type = $defcfg[$k]['type'];
117 $size = $defcfg[$k]['size'];
118 } else if ( $l == 'true' ) {
120 $type = SMOPT_TYPE_BOOLEAN
;
121 } else if ( $l == 'false' ) {
123 $type = SMOPT_TYPE_BOOLEAN
;
124 } else if ( $v{0} == "'" ) {
125 $type = SMOPT_TYPE_STRING
;
126 } else if ( $v{0} == '"' ) {
127 $type = SMOPT_TYPE_STRING
;
131 case SMOPT_TYPE_TITLE
:
132 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
134 case SMOPT_TYPE_COMMENT
:
135 $v = substr( $v, 1, strlen( $v ) - 2 );
136 echo "<tr><td>$name</td><td>".
138 $newcfg[$k] = "'$v'";
140 case SMOPT_TYPE_INTEGER
:
141 if ( isset( $HTTP_POST_VARS[$e] ) ) {
142 $v = intval( $HTTP_POST_VARS[$e] );
145 echo "<tr><td>$name</td><td>".
146 "<input size=10 name=\"adm_$n\" value=\"$v\">";
148 case SMOPT_TYPE_NUMLIST
:
149 if ( isset( $HTTP_POST_VARS[$e] ) ) {
150 $v = $HTTP_POST_VARS[$e];
153 echo "<tr><td>$name</td><td>";
154 echo "<select name=\"adm_$n\">";
155 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
156 echo "<option value=\"$kp\"";
160 echo ">$vp</option>";
164 case SMOPT_TYPE_STRLIST
:
165 if ( isset( $HTTP_POST_VARS[$e] ) ) {
166 $v = '"' . $HTTP_POST_VARS[$e] . '"';
169 echo "<tr><td>$name</td><td>".
170 "<select name=\"adm_$n\">";
171 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
172 echo "<option value=\"$kp\"";
173 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
176 echo ">$vp</option>";
181 case SMOPT_TYPE_STRING
:
182 if ( isset( $HTTP_POST_VARS[$e] ) ) {
183 $v = '"' . $HTTP_POST_VARS[$e] . '"';
186 echo "<tr><td>$name</td><td>".
187 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
189 case SMOPT_TYPE_BOOLEAN
:
190 if ( isset( $HTTP_POST_VARS[$e] ) ) {
191 $v = $HTTP_POST_VARS[$e];
194 $v = strtoupper( $v );
196 if ( $v == 'TRUE' ) {
203 echo "<tr><td>$name</td><td>" .
204 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
205 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
208 echo "<tr><td>$name</td><td>" .
213 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
214 _("Change Settings") . "\" type=submit></th></tr>" ,
215 '</table></td></tr></table></form>';
218 Write the options to the file.
220 $fp = fopen( $cfgfile, 'w' );
221 fwrite( $fp, "<?PHP\n".
223 " * SquirrelMail Configuration File\n".
224 " * Created using the Administrator Plugin\n".
227 fwrite( $fp, 'GLOBAL ' );
229 foreach ( $newcfg as $k => $v ) {
230 if ( $k{0} == '$' ) {
231 if( $i = strpos( $k, '[' ) ) {
232 if( strpos( $k, '[0]' ) ) {
236 fwrite( $fp, substr( $k, 0, $i) );
248 fwrite( $fp, ";\n" );
249 foreach ( $newcfg as $k => $v ) {
250 if ( $k{0} == '$' ) {
251 fwrite( $fp, "$k = $v;\n" );