- Fix compatibility with Windows path in administrator plugin (#1740469).
[squirrelmail.git] / plugins / administrator / options.php
CommitLineData
abd7a3f8 1<?php
2
3/**
fd521778 4 * Administrator Plugin - Options Page
abd7a3f8 5 *
fd521778 6 * This script creates separate page, that allows to review and modify
7 * SquirrelMail configuration file.
abd7a3f8 8 *
fd521778 9 * @author Philippe Mingo
4b5049de 10 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
fd521778 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4b4abf93 12 * @version $Id$
ea5f4b8e 13 * @package plugins
14 * @subpackage administrator
abd7a3f8 15 */
16
ea5f4b8e 17/**
18 * parse the config file
0df03ce7 19 *
20 * @param string $cfg_file
21 * @access private
ea5f4b8e 22 */
37d90494 23function parseConfig( $cfg_file ) {
24
25 global $newcfg;
26
27 $cfg = file( $cfg_file );
71e5c245 28 $mode = '';
29 $l = count( $cfg );
30 $modifier = FALSE;
0b5eb034 31 $arraykey = 0;
37d90494 32
71e5c245 33 for ($i=0;$i<$l;$i++) {
34 $line = trim( $cfg[$i] );
35 $s = strlen( $line );
36 for ($j=0;$j<$s;$j++) {
37 switch ( $mode ) {
38 case '=':
39 if ( $line{$j} == '=' ) {
40 // Ok, we've got a right value, lets detect what type
41 $mode = 'D';
42 } else if ( $line{$j} == ';' ) {
43 // hu! end of command
44 $key = $mode = '';
45 }
46 break;
47 case 'K':
48 // Key detect
ab3fe577 49 if ( $line{$j} == ' ' ) {
71e5c245 50 $mode = '=';
37d90494 51 } else {
71e5c245 52 $key .= $line{$j};
0b5eb034 53 // FIXME: this is only pour workaround for plugins[] array.
54 if ($line{$j}=='[' && $line{($j+1)}==']') {
55 $key .= $arraykey;
56 $arraykey++;
57 }
37d90494 58 }
71e5c245 59 break;
60 case ';':
61 // Skip until next ;
62 if ( $line{$j} == ';' ) {
63 $mode = '';
64 }
65 break;
66 case 'S':
67 if ( $line{$j} == '\\' ) {
68 $value .= $line{$j};
69 $modifier = TRUE;
70 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
71 // End of string;
72 $newcfg[$key] = $value . $delimiter;
73 $key = $value = '';
74 $mode = ';';
75 } else {
76 $value .= $line{$j};
77 $modifier = FALSE;
78 }
79 break;
80 case 'N':
81 if ( $line{$j} == ';' ) {
82 $newcfg{$key} = $value;
83 $key = $mode = '';
84 } else {
85 $value .= $line{$j};
86 }
87 break;
88 case 'C':
89 // Comments
88cb1b4d 90 if ( $s > $j + 1 &&
91 $line{$j}.$line{$j+1} == '*/' ) {
71e5c245 92 $mode = '';
93 $j++;
94 }
95 break;
96 case 'D':
97 // Delimiter detect
98 switch ( $line{$j} ) {
99 case '"':
100 case "'":
101 // Double quote string
102 $delimiter = $value = $line{$j};
103 $mode = 'S';
104 break;
105 case ' ':
106 // Nothing yet
107 break;
108 default:
109 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
110 // Boolean TRUE
111 $newcfg{$key} = 'TRUE';
112 $key = '';
113 $mode = ';';
114 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
115 $newcfg{$key} = 'FALSE';
116 $key = '';
117 $mode = ';';
118 } else {
119 // Number or function call
120 $mode = 'N';
121 $value = $line{$j};
122 }
123 }
124 break;
125 default:
88cb1b4d 126 if ( $line{$j} == '$' ) {
127 // We must detect $key name
128 $mode = 'K';
129 $key = '$';
130 } else if ( $s < $j + 2 ) {
131 } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
71e5c245 132 // Skip untill next ;
133 $mode = ';';
134 $j += 6;
135 } else if ( $line{$j}.$line{$j+1} == '/*' ) {
136 $mode = 'C';
137 $j++;
138 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
139 // Delete till the end of the line
140 $j = $s;
37d90494 141 }
37d90494 142 }
143 }
37d90494 144 }
a28a56da 145}
146
0df03ce7 147/**
148 * Change paths containing SM_PATH to admin-friendly paths
149 * relative to the config dir, i.e.:
150 * '' --> <empty string>
151 * SM_PATH . 'images/logo.gif' --> ../images/logo.gif
152 * '/absolute/path/logo.gif' --> /absolute/path/logo.gif
153 * 'http://whatever/' --> http://whatever
154 * Note removal of quotes in returned value
91e0dccc 155 *
0df03ce7 156 * @param string $old_path path that has to be converted
157 * @return string new path
158 * @access private
159 */
a28a56da 160function change_to_rel_path($old_path) {
91e0dccc 161 $new_path = str_replace("SM_PATH . '", "../", $old_path);
a28a56da 162 $new_path = str_replace("../config/","", $new_path);
163 $new_path = str_replace("'","", $new_path);
164 return $new_path;
165}
37d90494 166
0df03ce7 167/**
91e0dccc 168 * Change relative path (relative to config dir) to
0df03ce7 169 * internal SM_PATH, i.e.:
170 * empty_string --> ''
171 * ../images/logo.gif --> SM_PATH . 'images/logo.gif'
172 * images/logo.gif --> SM_PATH . 'config/images/logo.gif'
8e6799a3 173 * C:/absolute/win/path --> 'C:/absolute/win/path'
0df03ce7 174 * /absolute/path/logo.gif --> '/absolute/path/logo.gif'
175 * http://whatever/ --> 'http://whatever'
91e0dccc 176 *
0df03ce7 177 * @param string $old_path path that has to be converted
178 * @return string new path
179 * @access private
91e0dccc 180*/
a28a56da 181function change_to_sm_path($old_path) {
ab3fe577 182 if ( $old_path === '' || $old_path == "''" ) {
183 return "''";
8e6799a3 184 } elseif ( preg_match("/^(\/|http)/", $old_path) ||
185 substr($old_path,1,2) == ':/' ) {
ab3fe577 186 return "'" . $old_path . "'";
187 } elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
188 return $old_path;
189 }
91e0dccc 190
ab3fe577 191 $new_path = '';
192 $rel_path = explode("../", $old_path);
193 if ( count($rel_path) > 2 ) {
91e0dccc 194 // Since we're relative to the config dir,
ab3fe577 195 // more than 1 ../ puts us OUTSIDE the SM tree.
196 // get full path to config.php, then pop the filename
197 $abs_path = explode('/', realpath (SM_PATH . 'config/config.php'));
91e0dccc 198 array_pop ($abs_path);
ab3fe577 199 foreach ( $rel_path as $subdir ) {
200 if ( $subdir === '' ) {
201 array_pop ($abs_path);
202 } else {
203 array_push($abs_path, $subdir);
204 }
205 }
206 foreach ($abs_path as $subdir) {
207 $new_path .= $subdir . '/';
208 }
209 $new_path = "'$new_path'";
210 } elseif ( count($rel_path) > 1 ) {
211 // we're within the SM tree, prepend SM_PATH
212 $new_path = str_replace('../',"SM_PATH . '", $old_path . "'");
213 } else {
91e0dccc 214 // Last, if it's a relative path without a .. prefix,
ab3fe577 215 // we're somewhere within the config dir, so prepend
91e0dccc 216 // SM_PATH . 'config/
ab3fe577 217 $new_path = "SM_PATH . 'config/" . $old_path . "'";
218 }
219 return $new_path;
37d90494 220}
71e5c245 221
a28a56da 222
37d90494 223/* ---------------------- main -------------------------- */
f5da0b1e 224/** main SquirrelMail include */
225require('../../include/init.php');
226/* configuration definitions */
227include_once(SM_PATH . 'plugins/administrator/defines.php');
228/* additional functions */
229include_once(SM_PATH . 'plugins/administrator/auth.php');
abd7a3f8 230
fd521778 231global $data_dir, $username;
a3fab7e3 232
7004cc32 233if ( !adm_check_user() ) {
a28a56da 234 header('Location: ' . SM_PATH . 'src/options.php') ;
dcd6f144 235 exit;
236}
237
876fdb60 238displayPageHeader($color);
abd7a3f8 239
37d90494 240$newcfg = array( );
0e66bc84 241
242foreach ( $defcfg as $key => $def ) {
243 $newcfg[$key] = '';
244}
245
b59d1a7d 246$cfgfile = SM_PATH . 'config/config.php';
247parseConfig( SM_PATH . 'config/config_default.php' );
37d90494 248parseConfig( $cfgfile );
abd7a3f8 249
88cb1b4d 250$colapse = array( 'Titles' => 'off',
251 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
252 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
253 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
254 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
255 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
256 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
257 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
39d3ec89 258 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ),
259 'Group9' => getPref($data_dir, $username, 'adm_Group9', 'on' ),
0f610dca 260 'Group10' => getPref($data_dir, $username, 'adm_Group10', 'on' ),
0b5eb034 261 'Group11' => getPref($data_dir, $username, 'adm_Group11', 'on' ) );
a3fab7e3 262
4cd8ae7d 263/* look in $_GET array for 'switch' */
264if ( sqgetGlobalVar('switch', $switch, SQ_GET) ) {
88cb1b4d 265 if ( $colapse[$switch] == 'on' ) {
ab3fe577 266 $colapse[$switch] = 'off';
88cb1b4d 267 } else {
ab3fe577 268 $colapse[$switch] = 'on';
88cb1b4d 269 }
a3fab7e3 270 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
271}
272
78154473 273echo '<form action="options.php" method="post" name="options">' .
0d53a854 274 '<table width="95%" align="center" bgcolor="'.$color[5].'"><tr><td>'.
ab3fe577 275 '<table width="100%" cellspacing="0" bgcolor="'.$color[4].'">'.
276 '<tr bgcolor="'.$color[5].'"><th colspan="2">'.
277 _("Configuration Administrator").'</th></tr>'.
278 '<tr bgcolor="'.$color[5].'"><td colspan="2" align="center"><small>'.
279 _("Note: it is recommended that you configure your system using conf.pl, and not this plugin. conf.pl contains additional information regarding the purpose of variables and appropriate values, as well as additional verification steps.").
280 '<br />'.
281 _("Run or consult conf.pl should you run into difficulty with your configuration.").
282 '</small></td></tr>';
39d3ec89 283
a3fab7e3 284
285$act_grp = 'Titles'; /* Active group */
c83b38c1 286
abd7a3f8 287foreach ( $newcfg as $k => $v ) {
288 $l = strtolower( $v );
289 $type = SMOPT_TYPE_UNDEFINED;
290 $n = substr( $k, 1 );
291 $n = str_replace( '[', '_', $n );
292 $n = str_replace( ']', '_', $n );
293 $e = 'adm_' . $n;
294 $name = $k;
295 $size = 50;
0e66bc84 296 if ( isset( $defcfg[$k] ) ) {
297 $name = $defcfg[$k]['name'];
298 $type = $defcfg[$k]['type'];
88cb1b4d 299 if ( isset( $defcfg[$k]['size'] ) ) {
300 $size = $defcfg[$k]['size'];
301 } else {
302 $size = 40;
303 }
abd7a3f8 304 } else if ( $l == 'true' ) {
305 $v = 'TRUE';
306 $type = SMOPT_TYPE_BOOLEAN;
307 } else if ( $l == 'false' ) {
308 $v = 'FALSE';
309 $type = SMOPT_TYPE_BOOLEAN;
310 } else if ( $v{0} == "'" ) {
311 $type = SMOPT_TYPE_STRING;
312 } else if ( $v{0} == '"' ) {
313 $type = SMOPT_TYPE_STRING;
314 }
315
edd4a552 316 if ( substr( $k, 0, 7 ) == '$theme[' ) {
317 $type = SMOPT_TYPE_THEME;
318 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
319 $type = SMOPT_TYPE_PLUGINS;
65a5bae6 320 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
321 $type = SMOPT_TYPE_LDAP;
439538dc 322 } else if ( substr( $k, 0, 9 ) == '$fontsets' ||
c3d7aa6e 323 substr( $k, 0, 13 ) == '$aTemplateSet' ) {
439538dc 324 $type = SMOPT_TYPE_CUSTOM;
edd4a552 325 }
326
ab3fe577 327 if ( $type == SMOPT_TYPE_TITLE || $colapse[$act_grp] == 'off' ) {
a3fab7e3 328
329 switch ( $type ) {
330 case SMOPT_TYPE_LDAP:
439538dc 331 case SMOPT_TYPE_CUSTOM:
a3fab7e3 332 case SMOPT_TYPE_PLUGINS:
333 case SMOPT_TYPE_THEME:
334 case SMOPT_TYPE_HIDDEN:
335 break;
88cb1b4d 336 case SMOPT_TYPE_EXTERNAL:
337 echo "<tr><td>$name</td><td><b>" .
338 $defcfg[$k]['value'] .
ab3fe577 339 '</b></td></tr>';
88cb1b4d 340 break;
a3fab7e3 341 case SMOPT_TYPE_TITLE:
88cb1b4d 342 if ( $colapse[$k] == 'on' ) {
a3fab7e3 343 $sw = '(+)';
344 } else {
345 $sw = '(-)';
dcd6f144 346 }
ab3fe577 347 echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
348 "<a href=\"options.php?switch=$k\" style=\"text-decoration:none\">".
349 '<b>'.$sw.'</b></a> '.$name.'</th></tr>';
a3fab7e3 350 $act_grp = $k;
351 break;
352 case SMOPT_TYPE_COMMENT:
353 $v = substr( $v, 1, strlen( $v ) - 2 );
354 echo "<tr><td>$name</td><td>".
355 "<b>$v</b>";
356 $newcfg[$k] = "'$v'";
357 if ( isset( $defcfg[$k]['comment'] ) ) {
358 echo ' &nbsp; ' . $defcfg[$k]['comment'];
abd7a3f8 359 }
a3fab7e3 360 echo "</td></tr>\n";
361 break;
362 case SMOPT_TYPE_INTEGER:
ab3fe577 363 /* look for variable $e in POST, fill into $v */
0b5eb034 364 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
365 $v = intval( $new_v );
a3fab7e3 366 $newcfg[$k] = $v;
367 }
368 echo "<tr><td>$name</td><td>".
ab3fe577 369 "<input size=\"10\" name=\"adm_$n\" value=\"$v\" />";
a3fab7e3 370 if ( isset( $defcfg[$k]['comment'] ) ) {
371 echo ' &nbsp; ' . $defcfg[$k]['comment'];
372 }
373 echo "</td></tr>\n";
374 break;
375 case SMOPT_TYPE_NUMLIST:
0b5eb034 376 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
377 $v = $new_v;
a3fab7e3 378 $newcfg[$k] = $v;
379 }
380 echo "<tr><td>$name</td><td>";
381 echo "<select name=\"adm_$n\">";
382 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
383 echo "<option value=\"$kp\"";
384 if ( $kp == $v ) {
ab3fe577 385 echo ' selected="selected"';
a3fab7e3 386 }
387 echo ">$vp</option>";
388 }
389 echo '</select>';
390 if ( isset( $defcfg[$k]['comment'] ) ) {
391 echo ' &nbsp; ' . $defcfg[$k]['comment'];
392 }
393 echo "</td></tr>\n";
394 break;
395 case SMOPT_TYPE_STRLIST:
0b5eb034 396 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
397 $v = '"' . $new_v . '"';
a3fab7e3 398 $newcfg[$k] = $v;
399 }
400 echo "<tr><td>$name</td><td>".
401 "<select name=\"adm_$n\">";
402 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
403 echo "<option value=\"$kp\"";
404 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
ab3fe577 405 echo ' selected="selected"';
a3fab7e3 406 }
407 echo ">$vp</option>";
408 }
409 echo '</select>';
410 if ( isset( $defcfg[$k]['comment'] ) ) {
411 echo ' &nbsp; ' . $defcfg[$k]['comment'];
412 }
413 echo "</td></tr>\n";
414 break;
c83b38c1 415
a3fab7e3 416 case SMOPT_TYPE_TEXTAREA:
0b5eb034 417 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
c3d7aa6e 418 $v = '"' . addslashes($new_v) . '"';
a3fab7e3 419 $newcfg[$k] = str_replace( "\n", '', $v );
420 }
c3d7aa6e 421 echo "<tr><td valign=\"top\">$name</td><td>"
422 ."<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">"
423 .htmlspecialchars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
424 ."</textarea>";
a3fab7e3 425 if ( isset( $defcfg[$k]['comment'] ) ) {
426 echo ' &nbsp; ' . $defcfg[$k]['comment'];
427 }
428 echo "</td></tr>\n";
429 break;
430 case SMOPT_TYPE_STRING:
0b5eb034 431 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
c3d7aa6e 432 $v = '"' . addslashes($new_v) . '"';
a3fab7e3 433 $newcfg[$k] = $v;
434 }
feba1a41 435 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
436 $v = "'" . $defcfg[$k]['default'] . "'";
437 $newcfg[$k] = $v;
438 }
c3d7aa6e 439 echo "<tr><td>$name</td><td>"
440 ."<input size=\"$size\" name=\"adm_$n\" value=\""
441 .htmlspecialchars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
442 .'" />';
a3fab7e3 443 if ( isset( $defcfg[$k]['comment'] ) ) {
444 echo ' &nbsp; ' . $defcfg[$k]['comment'];
445 }
446 echo "</td></tr>\n";
447 break;
448 case SMOPT_TYPE_BOOLEAN:
0b5eb034 449 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
450 $v = $new_v;
a3fab7e3 451 $newcfg[$k] = $v;
452 } else {
453 $v = strtoupper( $v );
454 }
455 if ( $v == 'TRUE' ) {
ab3fe577 456 $ct = ' checked="checked"';
a3fab7e3 457 $cf = '';
458 } else {
459 $ct = '';
ab3fe577 460 $cf = ' checked="checked"';
a3fab7e3 461 }
462 echo "<tr><td>$name</td><td>" .
ab3fe577 463 "<input$ct type=\"radio\" name=\"adm_$n\" value=\"TRUE\" />" . _("Yes") .
464 "<input$cf type=\"radio\" name=\"adm_$n\" value=\"FALSE\" />" . _("No");
a3fab7e3 465 if ( isset( $defcfg[$k]['comment'] ) ) {
466 echo ' &nbsp; ' . $defcfg[$k]['comment'];
467 }
468 echo "</td></tr>\n";
469 break;
ab3fe577 470 case SMOPT_TYPE_PATH:
0b5eb034 471 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
f8a1ed5a 472 // FIXME: fix use of $data_dir in $attachment_dir
0b5eb034 473 $v = change_to_sm_path($new_v);
474 $newcfg[$k] = $v;
a28a56da 475 }
476 if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
477 $v = change_to_sm_path($defcfg[$k]['default']);
478 $newcfg[$k] = $v;
479 }
ab3fe577 480 echo "<tr><td>$name</td><td>".
481 "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . '" />';
a28a56da 482 if ( isset( $defcfg[$k]['comment'] ) ) {
483 echo ' &nbsp; ' . $defcfg[$k]['comment'];
484 }
ab3fe577 485 echo "</td></tr>\n";
486 break;
a3fab7e3 487 default:
488 echo "<tr><td>$name</td><td>" .
489 "<b><i>$v</i></b>";
490 if ( isset( $defcfg[$k]['comment'] ) ) {
491 echo ' &nbsp; ' . $defcfg[$k]['comment'];
492 }
493 echo "</td></tr>\n";
6a9acbca 494 }
a3fab7e3 495 }
a3fab7e3 496}
497
1fa5ece1 498/* Special Themes Block */
88cb1b4d 499if ( $colapse['Group7'] == 'off' ) {
a3fab7e3 500 $i = 0;
501 echo '<tr><th>' . _("Theme Name") .
502 '</th><th>' . _("Theme Path") .
503 '</th></tr>';
504 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
505 $k1 = "\$theme[$i]['NAME']";
506 $e1 = "theme_name_$i";
4cd8ae7d 507 if ( sqgetGlobalVar($e, $v1, SQ_POST) ) {
508 $v1 = '"' . str_replace( '\"', '"', $v1 ) . '"';
b5a29535 509 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
a3fab7e3 510 $newcfg[$k1] = $v1;
a55bb207 511 } else {
a3fab7e3 512 $v1 = $newcfg[$k1];
abd7a3f8 513 }
a3fab7e3 514 $k2 = "\$theme[$i]['PATH']";
515 $e2 = "theme_path_$i";
4cd8ae7d 516 if ( sqgetGlobalVar($e, $v2, SQ_POST) ) {
517 $v2 = change_to_sm_path($v2);
ab3fe577 518 $newcfg[$k2] = $v2;
abd7a3f8 519 } else {
a3fab7e3 520 $v2 = $newcfg[$k2];
abd7a3f8 521 }
a3fab7e3 522 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
a28a56da 523 $path = change_to_rel_path($v2);
a3fab7e3 524 echo '<tr>'.
ab3fe577 525 "<td align=\"right\">$i. <input name=\"$e1\" value=\"$name\" size=\"30\" /></td>".
526 "<td><input name=\"$e2\" value=\"$path\" size=\"40\" /></td>".
a3fab7e3 527 "</tr>\n";
528 $i++;
c83b38c1 529
6a9acbca 530 }
6a9acbca 531}
532
1fa5ece1 533/* Special Plugins Block */
88cb1b4d 534if ( $colapse['Group8'] == 'on' ) {
a3fab7e3 535 $sw = '(+)';
536} else {
537 $sw = '(-)';
6a9acbca 538}
ab3fe577 539echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
540 '<a href="options.php?switch=Group8" style="text-decoration:none"><b>'.
541 $sw.'</b></a> '._("Plugins").'</th></tr>';
542
543if ( $colapse['Group8'] == 'off' ) {
544
545 $plugpath = SM_PATH . 'plugins/';
546 if ( file_exists($plugpath) ) {
547 $fd = opendir( $plugpath );
548 $op_plugin = array();
549 $p_count = 0;
550 while (false !== ($file = readdir($fd))) {
551 if ($file != '.' && $file != '..' && $file != 'CVS' && is_dir($plugpath . $file) ) {
552 $op_plugin[] = $file;
553 $p_count++;
c83b38c1 554 }
555 }
ab3fe577 556 closedir($fd);
557 asort( $op_plugin );
558
559 /* Lets get the plugins that are active */
560 $plugins = array();
0b5eb034 561 if ( sqgetGlobalVar('plg', $v, SQ_POST) ) {
ab3fe577 562 foreach ( $op_plugin as $plg ) {
0b5eb034 563 if ( sqgetGlobalVar("plgs_$plg", $v2, SQ_POST) && $v2 == 'on' ) {
ab3fe577 564 $plugins[] = $plg;
565 }
566 }
567 $i = 0;
568 foreach ( $plugins as $plg ) {
569 $k = "\$plugins[$i]";
570 $newcfg[$k] = "'$plg'";
571 $i++;
572 }
573 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
574 $k = "\$plugins[$i]";
575 $newcfg[$k] = '';
576 $i++;
577 }
c83b38c1 578 } else {
ab3fe577 579 $i = 0;
580 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
581 $k = "\$plugins[$i]";
582 $v = $newcfg[$k];
583 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
584 $i++;
585 }
a3fab7e3 586 }
0d53a854 587 echo '<tr><td colspan="2"><input type="hidden" name="plg" value="on" /><table align="center">';
ab3fe577 588 foreach ( $op_plugin as $plg ) {
589 if ( in_array( $plg, $plugins ) ) {
590 $sw = ' checked="checked"';
591 } else {
592 $sw = '';
593 }
594 echo '<tr><td>';
595 if (file_exists(SM_PATH . "plugins/$plg/README")) {
596 echo "<a href=\"../$plg/README\" target=\"_blank\">$plg</a>";
597 } else {
598 echo $plg;
599 }
600 echo "</td>\n".
601 "<td><input$sw type=\"checkbox\" name=\"plgs_$plg\" /></td>".
602 "</tr>\n";
603 }
0d53a854 604 echo '</table></td></tr>';
ab3fe577 605 } else {
606 echo '<tr><td colspan="2" align="center">'.
607 sprintf(_("Plugin directory could not be found: %s"), $plugpath).
608 "</td></tr>\n";
609 }
6a9acbca 610}
ab3fe577 611echo '<tr bgcolor="'.$color[5].'"><th colspan="2"><input value="'.
612 _("Change Settings").'" type="submit" /><br />'.
613 '<a href="'.SM_PATH.'src/configtest.php" target="_blank">'.
614 _("Test Configuration")."</a></th></tr>\n".
0d53a854 615 '</table></td></tr></table></form>';
abd7a3f8 616
617/*
618 Write the options to the file.
619*/
71e5c245 620
ab3fe577 621if ( $fp = @fopen( $cfgfile, 'w' ) ) {
622 fwrite( $fp, "<?php\n".
b5a29535 623 "/**\n".
624 " * SquirrelMail Configuration File\n".
625 " * Created using the Administrator Plugin\n".
39d3ec89 626 " */\n".
b37e457f 627 "\n" );
b5a29535 628
c05c489a 629 foreach ( $newcfg as $k => $v ) {
781da5d4 630 if ( $k{0} == '$' && $v <> '' || is_int($v)) {
c05c489a 631 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
b5a29535 632 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
633 $v = str_replace( 'array(', "array(\n\t", $v );
634 $v = str_replace( "',", "',\n\t", $v );
c05c489a 635 }
0b5eb034 636 /* FIXME: add elseif that reverts plugins[#] to plugins[] */
c05c489a 637 fwrite( $fp, "$k = $v;\n" );
ab3fe577 638 }
0e66bc84 639 }
0b5eb034 640 // close php
c05c489a 641 fwrite( $fp, '?>' );
642 fclose( $fp );
643} else {
78154473 644 echo '<br /><p align="center"><big>'.
c05c489a 645 _("Config file can't be opened. Please check config.php.").
78154473 646 '</big></p>';
abd7a3f8 647}
c3d7aa6e 648
dcc1cc82 649?>
876fdb60 650</body></html>