options.php 22 KB

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