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 $c = preg_replace( '/\/\*.*\*\//', '', $c );
29 $c = preg_replace( '/#.*$/', '', $c );
30 $c = preg_replace( '/\/\/.*$/', '', $c );
34 } while( $first_char == '$' && substr( $c, -1 ) <> ';' && $i < $j );
38 if( substr( $l, -2 ) == '*/' ) {
41 } else if( $k = strpos( $l, '*/' ) ) {
42 $l = substr( $l, $k );
48 if( $l{0}.$l{1} == '/*' ) {
51 } else if ( $k = strpos( $l, '/*' ) ) {
52 $l = substr( $l, 0, $k );
57 if ( $k = strpos( $l, '=' ) ) {
58 $key = trim( substr( $l, 0, $k - 1 ) );
59 $val = str_replace( ';', '', trim( substr( $l, $k +
1 ) ) );
67 /* ---------------------- main -------------------------- */
69 require_once('../src/validate.php');
70 require_once('../functions/page_header.php');
71 require_once('../functions/imap.php');
72 require_once('../src/load_prefs.php');
73 require_once('../plugins/administrator/defines.php');
76 if ( $adm_id = fileowner('../config/config.php') ) {
77 $adm = posix_getpwuid( $adm_id );
78 if ( $username == $adm['name'] ) {
84 header("Location: ../../src/options.php") ;
88 displayPageHeader($color, 'None');
92 foreach ( $defcfg as $key => $def ) {
96 $cfgfile = '../config/config.php';
97 parseConfig( '../config/config_default.php' );
98 parseConfig( $cfgfile );
100 echo "<form action=$PHP_SELF method=post>" .
101 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
102 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
103 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
104 foreach ( $newcfg as $k => $v ) {
105 $l = strtolower( $v );
106 $type = SMOPT_TYPE_UNDEFINED
;
107 $n = substr( $k, 1 );
108 $n = str_replace( '[', '_', $n );
109 $n = str_replace( ']', '_', $n );
113 if ( isset( $defcfg[$k] ) ) {
114 $name = $defcfg[$k]['name'];
115 $type = $defcfg[$k]['type'];
116 $size = $defcfg[$k]['size'];
117 } else if ( $l == 'true' ) {
119 $type = SMOPT_TYPE_BOOLEAN
;
120 } else if ( $l == 'false' ) {
122 $type = SMOPT_TYPE_BOOLEAN
;
123 } else if ( $v{0} == "'" ) {
124 $type = SMOPT_TYPE_STRING
;
125 } else if ( $v{0} == '"' ) {
126 $type = SMOPT_TYPE_STRING
;
130 case SMOPT_TYPE_TITLE
:
131 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
133 case SMOPT_TYPE_COMMENT
:
134 $v = substr( $v, 1, strlen( $v ) - 2 );
135 echo "<tr><td>$name</td><td>".
137 $newcfg[$k] = "'$v'";
139 case SMOPT_TYPE_INTEGER
:
140 if ( isset( $HTTP_POST_VARS[$e] ) ) {
141 $v = intval( $HTTP_POST_VARS[$e] );
144 echo "<tr><td>$name</td><td>".
145 "<input size=10 name=\"adm_$n\" value=\"$v\">";
147 case SMOPT_TYPE_NUMLIST
:
148 if ( isset( $HTTP_POST_VARS[$e] ) ) {
149 $v = $HTTP_POST_VARS[$e];
152 echo "<tr><td>$name</td><td>";
153 echo "<select name=\"adm_$n\">";
154 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
155 echo "<option value=\"$kp\"";
159 echo ">$vp</option>";
163 case SMOPT_TYPE_STRLIST
:
164 if ( isset( $HTTP_POST_VARS[$e] ) ) {
165 $v = '"' . $HTTP_POST_VARS[$e] . '"';
168 echo "<tr><td>$name</td><td>".
169 "<select name=\"adm_$n\">";
170 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
171 echo "<option value=\"$kp\"";
172 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
175 echo ">$vp</option>";
180 case SMOPT_TYPE_STRING
:
181 if ( isset( $HTTP_POST_VARS[$e] ) ) {
182 $v = '"' . $HTTP_POST_VARS[$e] . '"';
185 echo "<tr><td>$name</td><td>".
186 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
188 case SMOPT_TYPE_BOOLEAN
:
189 if ( isset( $HTTP_POST_VARS[$e] ) ) {
190 $v = $HTTP_POST_VARS[$e];
193 $v = strtoupper( $v );
195 if ( $v == 'TRUE' ) {
202 echo "<tr><td>$name</td><td>" .
203 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
204 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
207 echo "<tr><td>$name</td><td>" .
212 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
213 _("Change Settings") . "\" type=submit></th></tr>" ,
214 '</table></td></tr></table></form>';
217 Write the options to the file.
219 $fp = fopen( $cfgfile, 'w' );
220 fwrite( $fp, "<?PHP\n".
222 " * SquirrelMail Configuration File\n".
223 " * Created using the Administrator Plugin\n".
226 fwrite( $fp, 'GLOBAL ' );
228 foreach ( $newcfg as $k => $v ) {
229 if ( $k{0} == '$' ) {
230 if( $i = strpos( $k, '[' ) ) {
231 if( strpos( $k, '[0]' ) ) {
235 fwrite( $fp, substr( $k, 0, $i) );
247 fwrite( $fp, ";\n" );
248 foreach ( $newcfg as $k => $v ) {
249 if ( $k{0} == '$' ) {
250 fwrite( $fp, "$k = $v;\n" );