3 # Written March 26, 2000
4 # Luke Ehresman (lehresma@css.tayloru.edu)
6 # A simple configure script to configure squirrelmail
7 ############################################################
11 print "\n\n--------------------------------------------------------\n";
12 print "SquirrelMail version 0.4 -- Configure script\n";
13 print "by SquirrelMail Development Team\n";
14 print "http://squirrelmail.sourceforge.net\n";
15 print "--------------------------------------------------------\n";
18 ############################################################
19 # First, lets read in the data already in there...
20 ############################################################
21 if ( -e
"config.php") {
22 print "The file \"config.php\" exists. Using it for defaults.\n\n";
23 open (FILE
, "config.php");
25 print "No config file found. Reading from config_defaults.php.\n\n";
26 open (FILE
, "config_default.php");
29 # Reads and parses the current configuration file (either
30 # config.php or config_default.php).
32 while ($line = <FILE
>) {
33 if ($line =~ /^\s+\$/) {
37 if ($var =~ /^([a-z]|[A-Z])/) {
38 @options = split(/\s=\s/, $var);
39 $options[1] =~ s/[\n|\r]//g;
40 $options[1] =~ s/^"//g;
41 $options[1] =~ s/;.*$//g;
42 $options[1] =~ s/"$//g;
44 if ($options[0] =~ /^special_folders/) {
45 if ($options[0] =~ /\[.*\]$/) {
48 $sub = substr ($sub, @sub-1, 1);
50 $special_folders[$sub] = $options[1];
52 } elsif ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) {
54 $sub =~ s/\]\["PATH"\]//;
55 $sub = substr ($sub, @sub-1, 1);
56 $theme_path[$sub] = $options[1];
57 } elsif ($options[0] =~ /^theme\[[0-9]+\]\["NAME"\]/) {
59 $sub =~ s/\]\["NAME"\]//;
60 $sub = substr ($sub, @sub-1, 1);
61 $theme_name[$sub] = $options[1];
63 ${$options[0]} = $options[1];
69 open (FILE
, ">cf.php");
70 print FILE
"<?\n\t/** SquirrelMail configure script\n";
71 print FILE
" ** Created using the configure script, config.pl.\n\t **/\n\n";
73 print "\n-------------------------------------------------.\n";
74 print " General Information )\n";
75 print "-------------------------------------------------'\n";
76 ############################################################
78 ############################################################
79 print $WHT."What is the name of your organization [$org_name]: $NRM";
80 $new_org_name = <STDIN
>;
81 if ($new_org_name eq "\n") {
82 $new_org_name = $org_name;
84 $new_org_name =~ s/[\r|\n]//g;
86 print FILE
" ".'$org_name = "' . $new_org_name . "\";\n";
90 ############################################################
92 ############################################################
93 print $WHT."Where is the logo for your organization [$org_logo]: $NRM";
94 $new_org_logo = <STDIN
>;
95 if ($new_org_logo eq "\n") {
96 $new_org_logo = $org_logo;
98 $new_org_logo =~ s/[\r|\n]//g;
100 print FILE
" ".'$org_logo = "' . $new_org_logo . "\";\n";
105 ############################################################
107 ############################################################
108 print "The title of the web page [$org_title]: ";
109 $new_org_title = <STDIN
>;
110 if ($new_org_title eq "\n") {
111 $new_org_title = $org_title;
113 $new_org_title =~ s/[\r|\n]//g;
115 print FILE
" ".'$org_title = "' . $new_org_title . "\";\n";
119 print "\n-------------------------------------------------.\n";
120 print " Server Information )\n";
121 print "-------------------------------------------------'\n";
122 ############################################################
124 ############################################################
125 print "Where is the IMAP server [$imapServerAddress]: ";
126 $new_imapServerAddress = <STDIN
>;
127 if ($new_imapServerAddress eq "\n") {
128 $new_imapServerAddress = $imapServerAddress;
130 $new_imapServerAddress =~ s/[\r|\n]//g;
132 print FILE
" ".'$imapServerAddress = "' . $new_imapServerAddress . "\";\n";
136 ############################################################
138 ############################################################
139 print "The port for your IMAP server [$imapPort]: ";
140 $new_imapPort = <STDIN
>;
141 if ($new_imapPort eq "\n") {
142 $new_imapPort = $imapPort;
144 $new_imapPort =~ s/[\r|\n]//g;
146 print FILE
" ".'$imapPort = ' . $new_imapPort . ";\n";
150 ############################################################
152 ############################################################
153 print "What is your domain name (ex: usa.om.org) [$domain]: ";
154 $new_domain = <STDIN
>;
155 if ($new_domain eq "\n") {
156 $new_domain = $domain;
158 $new_domain =~ s/[\r|\n]//g;
160 print FILE
" ".'$domain = "' . $new_domain . "\";\n";
163 ############################################################
164 # USE SMTP OR SENDMAIL?
165 ############################################################
166 print "\nYou now need to choose the method that you will use for sending\n";
167 print "messages in SquirrelMail. You can either connect to an SMTP server\n";
168 print "or use sendmail directly.\n";
169 if ($useSendmail eq "true") {
170 $default_value = "n";
172 $default_value = "y";
174 print "Use SMTP (y/n) [$default_value]: ";
176 if (($use_smtp =~ /^y\n/i) || (($use_smtp =~ /^\n/) && ($default_value eq "y"))) {
177 ############################################################
179 ############################################################
180 print " What is the SMTP server [$smtpServerAddress]: ";
181 $new_smtpServerAddress = <STDIN
>;
182 if ($new_smtpServerAddress eq "\n") {
183 $new_smtpServerAddress = $smtpServerAddress;
185 $new_smtpServerAddress =~ s/[\r|\n]//g;
187 print FILE
" ".'$smtpServerAddress = "' . $new_smtpServerAddress . "\";\n";
191 ############################################################
193 ############################################################
194 print " The port for your SMTP server [$smtpPort]: ";
195 $new_smtpPort = <STDIN
>;
196 if ($new_smtpPort eq "\n") {
197 $new_smtpPort = $smtpPort;
199 $new_smtpPort =~ s/[\r|\n]//g;
201 print FILE
" ".'$smtpPort = ' . $new_smtpPort . ";\n";
203 ############################################################
205 ############################################################
206 if ($sendmail_path[0] !~ /./) {
207 $sendmail_path = "/usr/sbin/sendmail";
209 print " Where is sendmail located [$sendmail_path]: ";
210 $new_sendmail_path = <STDIN
>;
211 if ($new_sendmail_path eq "\n") {
212 $new_sendmail_path = $sendmail_path;
214 $new_sendmail_path =~ s/[\r|\n]//g;
216 print FILE
" ".'$useSendmail'." = true;\n";
217 print FILE
" ".'$sendmail_path = "' . $new_sendmail_path . "\";\n";
222 print "\n-------------------------------------------------.\n";
223 print " General Options )\n";
224 print "-------------------------------------------------'\n";
225 ###############################################################
227 ###############################################################
228 print "\nYou can now create the welcome message that is displayed\n";
229 print "every time a user logs on. You can use HTML or just plain\n";
230 print "text.\n\n(Type @ on a blank line to exit)\n";
234 $line =~ s/[\r|\n]//g;
235 $line =~ s/ /\ \ /g;
237 $new_motd = $new_motd . $line;
239 } while ($line ne "@");
240 print FILE
" ".'$motd = "'.$new_motd."\";\n";
243 ############################################################
245 ############################################################
246 if ($auto_expunge eq "false") {
247 $default_value = "n";
249 $default_value = "y";
251 print "Should we automatically expunge deleted messages (y/n) [$default_value]: ";
253 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
254 print FILE
" \$auto_expunge = true;\n";
256 print FILE
" \$auto_expunge = false;\n";
260 ############################################################
261 # default_sub_of_inbox
262 ############################################################
263 if ($default_sub_of_inbox eq "false") {
264 $default_value = "n";
266 $default_value = "y";
268 print "By default, are new folders subfolders of INBOX (y/n) [$default_value]: ";
270 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
271 print FILE
" \$default_sub_of_inbox = true;\n";
273 print FILE
" \$default_sub_of_inbox = false;\n";
279 ############################################################
280 # show_contain_subfolders_option
281 ############################################################
282 print "\nSome IMAP daemons (UW) handle folders weird. They only allow a\n";
283 print "folder to contain either messages or subfolders. Not both at the\n";
284 print "same time. This option controls whether or not to display an \n";
285 print "option during folder creation letting them choose if this folder\n";
286 print "contains messages or folders.\n";
287 if ($show_contain_subfolders_option eq "false") {
288 $default_value = "n";
290 $default_value = "y";
292 print "Show the option to contain subfolders (y/n) [$default_value]: ";
294 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
295 print FILE
" \$show_contain_subfolders_option = true;\n";
297 print FILE
" \$show_contain_subfolders_option = false;\n";
304 ############################################################
306 ############################################################
307 print "\nThis option decides whether or not to use META tags to forward\n";
308 print "users past some of the notification screens\n";
309 if ($auto_forward eq "false") {
310 $default_value = "n";
312 $default_value = "y";
314 print "Automatically forward where possible (y/n) [$default_value]: ";
316 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
317 print FILE
" \$auto_forward = true;\n";
319 print FILE
" \$auto_forward = false;\n";
325 ############################################################
327 ############################################################
328 print "\nThis option controls what character set is used when sending mail\n";
329 print "and when sending HTMl to the browser. Do not set this to US-ASCII,\n";
330 print "use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R,\n";
331 print "since this implementation is faster than the alternatives.\n";
332 print "Default charset [$default_charset]: ";
333 $new_default_charset = <STDIN
>;
334 if ($new_default_charset eq "\n") {
335 $new_default_charset = $default_charset;
337 $new_default_charset =~ s/[\r|\n]//g;
339 print FILE
" ".'$default_charset = "' . $new_default_charset . "\";\n";
344 ############################################################
346 ############################################################
347 print "\nIt is a possible security hole to have a writable directory\n";
348 print "under the web server's root directory (ex: /home/httpd/html).\n";
349 print "For this reason, it is possible to put the data directory\n";
350 print "anywhere you would like. The path name can be absolute or\n";
351 print "relative (to the config directory). It doesn't matter. Here are\n";
352 print "two examples:\n";
353 print " Absolute:\n";
354 print " /usr/local/squirrelmail/data/;\n";
355 print " Relative (to the config directory):\n";
356 print " ../data/;\n";
357 print "Where is the data directory [$data_dir]: ";
358 $new_data_dir = <STDIN
>;
359 if ($new_data_dir eq "\n") {
360 $new_data_dir = $data_dir;
362 $new_data_dir =~ s/[\r|\n]//g;
364 print FILE
" ".'$data_dir = "' . $new_data_dir . "\";\n";
369 ############################################################
370 # ATTACHMENT DIRECTORY
371 ############################################################
372 print "\nPath to directory used for storing attachments while a mail is\n";
373 print "being sent. There are a few security considerations regarding this\n";
374 print "directory:\n";
375 print " - It should have the permission 733 (rwx-wx-wx) to make it\n";
376 print " impossible for a random person with access to the webserver to\n";
377 print " list files in this directory. Confidential data might be laying\n";
378 print " around there\n";
379 print " - Since the webserver is not able to list the files in the content\n";
380 print " is also impossible for the webserver to delete files lying around\n";
381 print " there for too long.\n";
382 print " - It should probably be another directory than data_dir.\n";
383 print "Where is the attachment directory [$attachment_dir]: ";
384 $new_attachment_dir = <STDIN
>;
385 if ($new_attachment_dir eq "\n") {
386 $new_attachment_dir = $attachment_dir;
388 $new_attachment_dir =~ s/[\r|\n]//g;
390 print FILE
" ".'$attachment_dir = "' . $new_attachment_dir . "\";\n";
395 ############################################################
397 ############################################################
398 print "What is the default left folder list size (pixels) [$default_left_size]: ";
399 $new_default_left_size = <STDIN
>;
400 if ($new_default_left_size eq "\n") {
401 $new_default_left_size = $default_left_size;
403 $new_default_left_size =~ s/[\r|\n]//g;
405 print FILE
" ".'$default_left_size = "' . $new_default_left_size . "\";\n";
413 print "\n-------------------------------------------------.\n";
414 print " Special Folders )\n";
415 print "-------------------------------------------------'\n";
417 ############################################################
419 ############################################################
420 print "What is the default trash folder [$trash_folder]: ";
421 $new_trash_folder = <STDIN
>;
422 if ($new_trash_folder eq "\n") {
423 $new_trash_folder = $trash_folder;
425 $new_trash_folder =~ s/[\r|\n]//g;
427 print FILE
" ".'$trash_folder = "' . $new_trash_folder . "\";\n";
431 ############################################################
432 # Default move to trash
433 ############################################################
434 if ($default_move_to_trash eq "true") {
435 $default_value = "y";
437 $default_value = "n";
439 print "By default, should deleted messages be moved to $new_trash_folder (y/n) [$default_value]: ";
440 $move_trash = <STDIN
>;
441 if (($move_trash =~ /^y\n/i) || (($move_trash =~ /^\n/) && ($default_value eq "y"))) {
442 print FILE
" \$default_move_to_trash = true;\n";
444 print FILE
" \$default_move_to_trash = false;\n";
449 ############################################################
451 ############################################################
452 print "What is the default sent folder [$sent_folder]: ";
453 $new_sent_folder = <STDIN
>;
454 if ($new_sent_folder eq "\n") {
455 $new_sent_folder = $sent_folder;
457 $new_sent_folder =~ s/[\r|\n]//g;
459 print FILE
" ".'$sent_folder = "' . $new_sent_folder . "\";\n";
464 ############################################################
466 ############################################################
467 print "\nSpecial folders are folders that can't be manipulated like normal\n";
468 print "user-created folders. A couple of examples of these would be the\n";
469 print "trash folder, the sent folder, etc.\n";
470 print "Special Folders:\n";
473 while ($count < @special_folders) {
474 print " $count) " . $special_folders[$count] . "\n";
477 print "[folders] command (?=help) > ";
479 $input =~ s/[\r|\n]//g;
480 while ($input ne "d") {
482 if ($input =~ /^\s*\+\s*.*/) {
483 $input =~ s/^\s*\+\s*//;
484 $special_folders[$#special_folders+1] = $input;
487 elsif ($input =~ /^\s*-\s*[0-9]?/) {
488 if ($input =~ /[0-9]+\s*$/) {
490 $rem_num =~ s/^\s*-\s*//g;
491 $rem_num =~ s/\s*$//;
493 $rem_num = $#special_folders;
497 print "You cannot remove INBOX. It is a very special folder.\n";
500 @new_special_folders = ();
501 while ($count <= $#special_folders) {
502 if ($count != $rem_num) {
503 @new_special_folders = (@new_special_folders, $special_folders[$count]);
507 @special_folders = @new_special_folders;
511 elsif ($input =~ /^\s*l\s*/) {
514 while ($count < @special_folders) {
515 print " $count) " . $special_folders[$count] . "\n";
518 } elsif ($input =~ /^\s*\?\s*/) {
519 print ".-------------------------.\n";
520 print "| + Folder (add folder) |\n";
521 print "| - N (remove folder) |\n";
522 print "| l (list folders) |\n";
523 print "| d (done) |\n";
524 print "`-------------------------'\n";
528 print "Unrecognized command.\n";
531 print "[folders] command (?=help) > ";
533 $input =~ s/[\r|\n]//g;
537 while ($count <= $#special_folders) {
538 print FILE
" \$special_folders[$count] = \"$special_folders[$count]\";\n";
543 ############################################################
544 # Use special folder color
545 ############################################################
546 if ($use_special_folder_color eq "true") {
547 $default_value = "y";
549 $default_value = "n";
551 print "\nHighlight special folders in a different color (y/n) [$default_value]: ";
552 $use_spec_folder = <STDIN
>;
553 if (($use_spec_folder =~ /^y\n/i) || (($use_spec_folder =~ /^\n/) && ($default_value eq "y"))) {
554 print FILE
" \$use_special_folder_color = true;\n";
556 print FILE
" \$use_special_folder_color = false;\n";
562 ############################################################
563 # list_special_folders_first
564 ############################################################
565 if ($list_special_folders_first eq "false") {
566 $default_value = "n";
568 $default_value = "y";
570 print "Should special folders be listed first (y/n) [$default_value]: ";
572 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
573 print FILE
" \$list_special_folders_first = true;\n";
575 print FILE
" \$list_special_folders_first = false;\n";
581 ############################################################
583 ############################################################
584 print "\nNow we will define the themes that you wish to use. If you have added\n";
585 print "a theme of your own, just follow the instructions (?) about how to add\n";
586 print "them. You can also change the default theme.\n";
587 print "[theme] command (?=help) > ";
589 $input =~ s/[\r|\n]//g;
591 while ($input ne "d") {
592 if ($input =~ /^\s*l\s*/i) {
594 while ($count <= $#theme_name) {
595 if ($count == $theme_default) {
600 $name = $theme_name[$count];
601 $num_spaces = 25 - length($name);
602 for ($i = 0; $i < $num_spaces;$i++) {
606 print " $count. $name";
607 print "($theme_path[$count])\n";
611 } elsif ($input =~ /^\s*m\s*[0-9]+/i) {
612 $old_def = $theme_default;
613 $theme_default = $input;
614 $theme_default =~ s/^\s*m\s*//;
615 if (($theme_default > $#theme_name) || ($theme_default < 0)) {
616 print "Cannot set default theme to $theme_default. That theme does not exist.\n";
617 $theme_default = $old_def;
619 } elsif ($input =~ /^\s*\+/) {
620 print "What is the name of this theme: ";
622 $name =~ s/[\r|\n]//g;
623 $theme_name[$#theme_name+1] = $name;
624 print "Be sure to put ../config/ before the filename.\n";
625 print "What file is this stored in (ex: ../config/default_theme.php): ";
627 $name =~ s/[\r|\n]//g;
628 $theme_path[$#theme_path+1] = $name;
629 } elsif ($input =~ /^\s*-\s*[0-9]?/) {
630 if ($input =~ /[0-9]+\s*$/) {
632 $rem_num =~ s/^\s*-\s*//g;
633 $rem_num =~ s/\s*$//;
635 $rem_num = $#theme_name;
637 if ($rem_num == $theme_default) {
638 print "You cannot remove the default theme!\n";
641 @new_theme_name = ();
642 @new_theme_path = ();
643 while ($count <= $#theme_name) {
644 if ($count != $rem_num) {
645 @new_theme_name = (@new_theme_name, $theme_name[$count]);
646 @new_theme_path = (@new_theme_path, $theme_path[$count]);
650 @theme_name = @new_theme_name;
651 @theme_path = @new_theme_path;
652 if ($theme_default > $rem_num) {
656 } elsif ($input =~ /^\s*\?\s*/) {
657 print ".-------------------------.\n";
658 print "| + (add theme) |\n";
659 print "| - N (remove theme) |\n";
660 print "| m N (mark default) |\n";
661 print "| l (list themes) |\n";
662 print "| d (done) |\n";
663 print "`-------------------------'\n";
665 print "[theme] command (?=help) > ";
667 $input =~ s/[\r|\n]//g;
671 print FILE
" \$theme[0][\"NAME\"] = \"$theme_name[$theme_default]\";\n";
672 print FILE
" \$theme[0][\"PATH\"] = \"$theme_path[$theme_default]\";\n";
674 while ($count < $#theme_name) {
675 if ($count != $theme_default) {
676 print FILE
" \$theme[$index][\"NAME\"] = \"$theme_name[$count]\";\n";
677 print FILE
" \$theme[$index][\"PATH\"] = \"$theme_path[$count]\";\n";
687 print "\n\nFINISHED!\n";
688 print "All changes have been written to cf.php. If you would like, I can write\n";
689 print "the changes to config.php.\n";
690 print "Overwrite config.php (y/n) [y]: ";
692 if (($autoe =~ /^y\n/i) || ($autoe =~ /^\n/)) {
693 system "mv -f cf.php config.php";