options.php 22 KB

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