options.php 22 KB

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