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