Some Administrator plugin instalation tips.
[squirrelmail.git] / plugins / administrator / options.php
CommitLineData
abd7a3f8 1<?php
2
3/**
4 * Administrator Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Philippe Mingo
10 *
11 * $Id$
12 */
13
37d90494 14function parseConfig( $cfg_file ) {
15
16 global $newcfg;
17
18 $cfg = file( $cfg_file );
19 $cm = FALSE;
20 $j = count( $cfg );
21
22 for ( $i=0; $i < $j; $i++ ) {
23 $l = '';
24 $first_char = $cfg[$i]{0};
25 do {
26 // Remove comments
27 $c = trim( $cfg[$i] );
28 $c = preg_replace( '/\/\*.*\*\//', '', $c );
29 $c = preg_replace( '/#.*$/', '', $c );
30 $c = preg_replace( '/\/\/.*$/', '', $c );
31 $l .= $c;
32 $i++;
33 } while( $first_char == '$' && substr( $c, -1 ) <> ';' && $i < $j );
34 $i--;
35 if ( $l <> '' ) {
36 if ( $cm ) {
37 if( substr( $l, -2 ) == '*/' ) {
38 $l = '';
39 $cm = FALSE;
40 } else if( $k = strpos( $l, '*/' ) ) {
41 $l = substr( $l, $k );
42 $cm = FALSE;
43 } else {
44 $l = '';
45 }
46 } else {
47 if( $l{0}.$l{1} == '/*' ) {
48 $l = '';
49 $cm = TRUE;
50 } else if ( $k = strpos( $l, '/*' ) ) {
51 $l = substr( $l, 0, $k );
52 $cm = TRUE;
53 }
54 }
55
56 if ( $k = strpos( $l, '=' ) ) {
57 $key = trim( substr( $l, 0, $k - 1 ) );
58 $val = str_replace( ';', '', trim( substr( $l, $k + 1 ) ) );
59 $newcfg[$key] = $val;
60 }
61 }
62
63 }
64
65}
66/* ---------------------- main -------------------------- */
abd7a3f8 67chdir('..');
68require_once('../src/validate.php');
69require_once('../functions/page_header.php');
70require_once('../functions/imap.php');
71require_once('../src/load_prefs.php');
72require_once('../plugins/administrator/defines.php');
73
dcd6f144 74$auth = FALSE;
75if ( $adm_id = fileowner('../config/config.php') ) {
76 $adm = posix_getpwuid( $adm_id );
77 if ( $username == $adm['name'] ) {
78 $auth = TRUE;
79 }
80}
81
82if ( !auth ) {
83 header("Location: ../../src/options.php") ;
84 exit;
85}
86
abd7a3f8 87displayPageHeader($color, 'None');
88
37d90494 89$newcfg = array( );
0e66bc84 90
91foreach ( $defcfg as $key => $def ) {
92 $newcfg[$key] = '';
93}
94
37d90494 95$cfgfile = '../config/config.php';
96parseConfig( '../config/config_default.php' );
97parseConfig( $cfgfile );
abd7a3f8 98
99echo "<form action=$PHP_SELF method=post>" .
0e66bc84 100 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
101 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
abd7a3f8 102 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
103foreach ( $newcfg as $k => $v ) {
104 $l = strtolower( $v );
105 $type = SMOPT_TYPE_UNDEFINED;
106 $n = substr( $k, 1 );
107 $n = str_replace( '[', '_', $n );
108 $n = str_replace( ']', '_', $n );
109 $e = 'adm_' . $n;
110 $name = $k;
111 $size = 50;
0e66bc84 112 if ( isset( $defcfg[$k] ) ) {
113 $name = $defcfg[$k]['name'];
114 $type = $defcfg[$k]['type'];
115 $size = $defcfg[$k]['size'];
abd7a3f8 116 } else if ( $l == 'true' ) {
117 $v = 'TRUE';
118 $type = SMOPT_TYPE_BOOLEAN;
119 } else if ( $l == 'false' ) {
120 $v = 'FALSE';
121 $type = SMOPT_TYPE_BOOLEAN;
122 } else if ( $v{0} == "'" ) {
123 $type = SMOPT_TYPE_STRING;
124 } else if ( $v{0} == '"' ) {
125 $type = SMOPT_TYPE_STRING;
126 }
127
abd7a3f8 128 switch ( $type ) {
0e66bc84 129 case SMOPT_TYPE_TITLE:
dcd6f144 130 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
0e66bc84 131 break;
132 case SMOPT_TYPE_COMMENT:
133 $v = substr( $v, 1, strlen( $v ) - 2 );
134 echo "<tr><td>$name</td><td>";
135 echo "<b>$v</b>";
136 $newcfg[$k] = "'$v'";
137 break;
abd7a3f8 138 case SMOPT_TYPE_INTEGER:
139 if ( isset( $HTTP_POST_VARS[$e] ) ) {
140 $v = intval( $HTTP_POST_VARS[$e] );
141 $newcfg[$k] = $v;
142 }
0e66bc84 143 echo "<tr><td>$name</td><td>";
abd7a3f8 144 echo "<input size=10 name=\"adm_$n\" value=\"$v\">";
145 break;
dcd6f144 146 case SMOPT_TYPE_NUMLIST:
147 if ( isset( $HTTP_POST_VARS[$e] ) ) {
148 $v = $HTTP_POST_VARS[$e];
149 $newcfg[$k] = $v;
150 }
151 echo "<tr><td>$name</td><td>";
152 echo "<select name=\"adm_$n\">";
153 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
154 echo "<option value=\"$kp\"";
155 if ( $kp == $v ) {
156 echo ' selected';
157 }
158 echo ">$vp</option>";
159 }
160 echo '</select>';
161 break;
abd7a3f8 162 case SMOPT_TYPE_STRLIST:
163 if ( isset( $HTTP_POST_VARS[$e] ) ) {
164 $v = '"' . $HTTP_POST_VARS[$e] . '"';
165 $newcfg[$k] = $v;
166 }
0e66bc84 167 echo "<tr><td>$name</td><td>";
abd7a3f8 168 echo "<select name=\"adm_$n\">";
0e66bc84 169 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
abd7a3f8 170 echo "<option value=\"$kp\"";
171 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
172 echo ' selected';
173 }
174 echo ">$vp</option>";
175 }
176 echo '</select>';
177 break;
178
179 case SMOPT_TYPE_STRING:
180 if ( isset( $HTTP_POST_VARS[$e] ) ) {
181 $v = '"' . $HTTP_POST_VARS[$e] . '"';
182 $newcfg[$k] = $v;
183 }
0e66bc84 184 echo "<tr><td>$name</td><td>";
abd7a3f8 185 echo "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
186 break;
187 case SMOPT_TYPE_BOOLEAN:
188 if ( isset( $HTTP_POST_VARS[$e] ) ) {
189 $v = $HTTP_POST_VARS[$e];
190 $newcfg[$k] = $v;
191 }
192 if ( $v == 'TRUE' ) {
193 $ct = ' checked';
194 $cf = '';
195 } else {
196 $ct = '';
197 $cf = ' checked';
198 }
0e66bc84 199 echo "<tr><td>$name</td><td>";
abd7a3f8 200 echo "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
201 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
202 break;
203 default:
0e66bc84 204 echo "<tr><td>$name</td><td>";
abd7a3f8 205 echo "<b><i>$v</i></b>";
206 }
207 echo "</td></tr>\n";
208}
209echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
210 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 211 '</table></td></tr></table></form>';
abd7a3f8 212
213/*
214 Write the options to the file.
215*/
216$fp = fopen( $cfgfile, 'w' );
217fwrite( $fp, "<?PHP\n".
218 "/**\n".
219 " * SquirrelMail Configuration File\n".
220 " * Created using the Administrator Plugin\n".
221 " */\n\n" );
222
223fwrite( $fp, 'GLOBAL ' );
224$not_first = FALSE;
225foreach ( $newcfg as $k => $v ) {
0e66bc84 226 if ( $k{0} == '$' ) {
227 if( $i = strpos( $k, '[' ) ) {
228 if( strpos( $k, '[0]' ) ) {
229 if( $not_first ) {
230 fwrite( $fp, ', ' );
231 }
232 fwrite( $fp, substr( $k, 0, $i) );
233 $not_first = TRUE;
234 }
235 } else {
abd7a3f8 236 if( $not_first ) {
237 fwrite( $fp, ', ' );
238 }
0e66bc84 239 fwrite( $fp, $k );
abd7a3f8 240 $not_first = TRUE;
241 }
abd7a3f8 242 }
243}
244fwrite( $fp, ";\n" );
245foreach ( $newcfg as $k => $v ) {
0e66bc84 246 if ( $k{0} == '$' ) {
247 fwrite( $fp, "$k = $v;\n" );
248 }
abd7a3f8 249}
250fwrite( $fp, '?>' );
251fclose( $fp );
37d90494 252?>