added a configure script
[squirrelmail.git] / config / conf.pl
1 #!/usr/bin/perl
2 # conf.pl
3 # Written March 26, 2000
4 # Luke Ehresman (lehresma@css.tayloru.edu)
5 #
6 # A simple configure script to configure squirrelmail
7 ############################################################
8 $WHT = "\x1B[37;1m";
9 $NRM = "\x1B[0m";
10
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";
16 print "\n";
17
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");
24 } else {
25 print "No config file found. Reading from config_defaults.php.\n\n";
26 open (FILE, "config_default.php");
27 }
28
29 # Reads and parses the current configuration file (either
30 # config.php or config_default.php).
31
32 while ($line = <FILE>) {
33 if ($line =~ /^\s+\$/) {
34 $line =~ s/^\s+\$//;
35 $var = $line;
36
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;
43
44 if ($options[0] =~ /^special_folders/) {
45 if ($options[0] =~ /\[.*\]$/) {
46 $sub = $options[0];
47 $sub =~ s/\]$//;
48 $sub = substr ($sub, @sub-1, 1);
49
50 $special_folders[$sub] = $options[1];
51 }
52 } elsif ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) {
53 $sub = $options[0];
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"\]/) {
58 $sub = $options[0];
59 $sub =~ s/\]\["NAME"\]//;
60 $sub = substr ($sub, @sub-1, 1);
61 $theme_name[$sub] = $options[1];
62 } else {
63 ${$options[0]} = $options[1];
64 }
65 }
66 }
67 }
68
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";
72
73 print "\n-------------------------------------------------.\n";
74 print " General Information )\n";
75 print "-------------------------------------------------'\n";
76 ############################################################
77 # Organization Name
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;
83 } else {
84 $new_org_name =~ s/[\r|\n]//g;
85 }
86 print FILE " ".'$org_name = "' . $new_org_name . "\";\n";
87
88
89
90 ############################################################
91 # Organization Logo
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;
97 } else {
98 $new_org_logo =~ s/[\r|\n]//g;
99 }
100 print FILE " ".'$org_logo = "' . $new_org_logo . "\";\n";
101
102
103
104
105 ############################################################
106 # Organization Title
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;
112 } else {
113 $new_org_title =~ s/[\r|\n]//g;
114 }
115 print FILE " ".'$org_title = "' . $new_org_title . "\";\n";
116
117
118
119 print "\n-------------------------------------------------.\n";
120 print " Server Information )\n";
121 print "-------------------------------------------------'\n";
122 ############################################################
123 # IMAP Server
124 ############################################################
125 print "Where is the IMAP server [$imapServerAddress]: ";
126 $new_imapServerAddress = <STDIN>;
127 if ($new_imapServerAddress eq "\n") {
128 $new_imapServerAddress = $imapServerAddress;
129 } else {
130 $new_imapServerAddress =~ s/[\r|\n]//g;
131 }
132 print FILE " ".'$imapServerAddress = "' . $new_imapServerAddress . "\";\n";
133
134
135
136 ############################################################
137 # IMAP Port
138 ############################################################
139 print "The port for your IMAP server [$imapPort]: ";
140 $new_imapPort = <STDIN>;
141 if ($new_imapPort eq "\n") {
142 $new_imapPort = $imapPort;
143 } else {
144 $new_imapPort =~ s/[\r|\n]//g;
145 }
146 print FILE " ".'$imapPort = ' . $new_imapPort . ";\n";
147
148
149
150 ############################################################
151 # DOMAIN
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;
157 } else {
158 $new_domain =~ s/[\r|\n]//g;
159 }
160 print FILE " ".'$domain = "' . $new_domain . "\";\n";
161
162
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";
171 } else {
172 $default_value = "y";
173 }
174 print "Use SMTP (y/n) [$default_value]: ";
175 $use_smtp = <STDIN>;
176 if (($use_smtp =~ /^y\n/i) || (($use_smtp =~ /^\n/) && ($default_value eq "y"))) {
177 ############################################################
178 # SMTP Server
179 ############################################################
180 print " What is the SMTP server [$smtpServerAddress]: ";
181 $new_smtpServerAddress = <STDIN>;
182 if ($new_smtpServerAddress eq "\n") {
183 $new_smtpServerAddress = $smtpServerAddress;
184 } else {
185 $new_smtpServerAddress =~ s/[\r|\n]//g;
186 }
187 print FILE " ".'$smtpServerAddress = "' . $new_smtpServerAddress . "\";\n";
188
189
190
191 ############################################################
192 # SMTP Port
193 ############################################################
194 print " The port for your SMTP server [$smtpPort]: ";
195 $new_smtpPort = <STDIN>;
196 if ($new_smtpPort eq "\n") {
197 $new_smtpPort = $smtpPort;
198 } else {
199 $new_smtpPort =~ s/[\r|\n]//g;
200 }
201 print FILE " ".'$smtpPort = ' . $new_smtpPort . ";\n";
202 } else {
203 ############################################################
204 # Sendmail Path
205 ############################################################
206 if ($sendmail_path[0] !~ /./) {
207 $sendmail_path = "/usr/sbin/sendmail";
208 }
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;
213 } else {
214 $new_sendmail_path =~ s/[\r|\n]//g;
215 }
216 print FILE " ".'$useSendmail'." = true;\n";
217 print FILE " ".'$sendmail_path = "' . $new_sendmail_path . "\";\n";
218 }
219
220
221
222 print "\n-------------------------------------------------.\n";
223 print " General Options )\n";
224 print "-------------------------------------------------'\n";
225 ###############################################################
226 # MOTD
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";
231 do {
232 print "] ";
233 $line = <STDIN>;
234 $line =~ s/[\r|\n]//g;
235 $line =~ s/ /\&nbsp;\&nbsp;/g;
236 if ($line ne "@") {
237 $new_motd = $new_motd . $line;
238 }
239 } while ($line ne "@");
240 print FILE " ".'$motd = "'.$new_motd."\";\n";
241
242
243 ############################################################
244 # AUTO EXPUNGE
245 ############################################################
246 if ($auto_expunge eq "false") {
247 $default_value = "n";
248 } else {
249 $default_value = "y";
250 }
251 print "Should we automatically expunge deleted messages (y/n) [$default_value]: ";
252 $autoe = <STDIN>;
253 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
254 print FILE " \$auto_expunge = true;\n";
255 } else {
256 print FILE " \$auto_expunge = false;\n";
257 }
258
259
260 ############################################################
261 # default_sub_of_inbox
262 ############################################################
263 if ($default_sub_of_inbox eq "false") {
264 $default_value = "n";
265 } else {
266 $default_value = "y";
267 }
268 print "By default, are new folders subfolders of INBOX (y/n) [$default_value]: ";
269 $autoe = <STDIN>;
270 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
271 print FILE " \$default_sub_of_inbox = true;\n";
272 } else {
273 print FILE " \$default_sub_of_inbox = false;\n";
274 }
275
276
277
278
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";
289 } else {
290 $default_value = "y";
291 }
292 print "Show the option to contain subfolders (y/n) [$default_value]: ";
293 $autoe = <STDIN>;
294 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
295 print FILE " \$show_contain_subfolders_option = true;\n";
296 } else {
297 print FILE " \$show_contain_subfolders_option = false;\n";
298 }
299
300
301
302
303
304 ############################################################
305 # auto_forward
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";
311 } else {
312 $default_value = "y";
313 }
314 print "Automatically forward where possible (y/n) [$default_value]: ";
315 $autoe = <STDIN>;
316 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
317 print FILE " \$auto_forward = true;\n";
318 } else {
319 print FILE " \$auto_forward = false;\n";
320 }
321
322
323
324
325 ############################################################
326 # DEFAULT CHARSET
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;
336 } else {
337 $new_default_charset =~ s/[\r|\n]//g;
338 }
339 print FILE " ".'$default_charset = "' . $new_default_charset . "\";\n";
340
341
342
343
344 ############################################################
345 # DATA DIRECTORY
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;
361 } else {
362 $new_data_dir =~ s/[\r|\n]//g;
363 }
364 print FILE " ".'$data_dir = "' . $new_data_dir . "\";\n";
365
366
367
368
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;
387 } else {
388 $new_attachment_dir =~ s/[\r|\n]//g;
389 }
390 print FILE " ".'$attachment_dir = "' . $new_attachment_dir . "\";\n";
391
392
393
394
395 ############################################################
396 # DEFAULT LEFT SIZE
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;
402 } else {
403 $new_default_left_size =~ s/[\r|\n]//g;
404 }
405 print FILE " ".'$default_left_size = "' . $new_default_left_size . "\";\n";
406
407
408
409
410
411
412
413 print "\n-------------------------------------------------.\n";
414 print " Special Folders )\n";
415 print "-------------------------------------------------'\n";
416
417 ############################################################
418 # Trash folder
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;
424 } else {
425 $new_trash_folder =~ s/[\r|\n]//g;
426 }
427 print FILE " ".'$trash_folder = "' . $new_trash_folder . "\";\n";
428
429
430
431 ############################################################
432 # Default move to trash
433 ############################################################
434 if ($default_move_to_trash eq "true") {
435 $default_value = "y";
436 } else {
437 $default_value = "n";
438 }
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";
443 } else {
444 print FILE " \$default_move_to_trash = false;\n";
445 }
446
447
448
449 ############################################################
450 # Sent folder
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;
456 } else {
457 $new_sent_folder =~ s/[\r|\n]//g;
458 }
459 print FILE " ".'$sent_folder = "' . $new_sent_folder . "\";\n";
460
461
462
463
464 ############################################################
465 # Special Folders
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";
471 $count = 0;
472 print "\n";
473 while ($count < @special_folders) {
474 print " $count) " . $special_folders[$count] . "\n";
475 $count++;
476 }
477 print "[folders] command (?=help) > ";
478 $input = <STDIN>;
479 $input =~ s/[\r|\n]//g;
480 while ($input ne "d") {
481 ## ADD
482 if ($input =~ /^\s*\+\s*.*/) {
483 $input =~ s/^\s*\+\s*//;
484 $special_folders[$#special_folders+1] = $input;
485 }
486
487 elsif ($input =~ /^\s*-\s*[0-9]?/) {
488 if ($input =~ /[0-9]+\s*$/) {
489 $rem_num = $input;
490 $rem_num =~ s/^\s*-\s*//g;
491 $rem_num =~ s/\s*$//;
492 } else {
493 $rem_num = $#special_folders;
494 }
495
496 if ($rem_num == 0) {
497 print "You cannot remove INBOX. It is a very special folder.\n";
498 } else {
499 $count = 0;
500 @new_special_folders = ();
501 while ($count <= $#special_folders) {
502 if ($count != $rem_num) {
503 @new_special_folders = (@new_special_folders, $special_folders[$count]);
504 }
505 $count++;
506 }
507 @special_folders = @new_special_folders;
508 }
509 }
510
511 elsif ($input =~ /^\s*l\s*/) {
512 $count = 0;
513 print "\n";
514 while ($count < @special_folders) {
515 print " $count) " . $special_folders[$count] . "\n";
516 $count++;
517 }
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";
525 }
526
527 else {
528 print "Unrecognized command.\n";
529 }
530
531 print "[folders] command (?=help) > ";
532 $input = <STDIN>;
533 $input =~ s/[\r|\n]//g;
534 }
535
536 $count = 0;
537 while ($count <= $#special_folders) {
538 print FILE " \$special_folders[$count] = \"$special_folders[$count]\";\n";
539 $count++;
540 }
541
542
543 ############################################################
544 # Use special folder color
545 ############################################################
546 if ($use_special_folder_color eq "true") {
547 $default_value = "y";
548 } else {
549 $default_value = "n";
550 }
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";
555 } else {
556 print FILE " \$use_special_folder_color = false;\n";
557 }
558
559
560
561
562 ############################################################
563 # list_special_folders_first
564 ############################################################
565 if ($list_special_folders_first eq "false") {
566 $default_value = "n";
567 } else {
568 $default_value = "y";
569 }
570 print "Should special folders be listed first (y/n) [$default_value]: ";
571 $autoe = <STDIN>;
572 if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) {
573 print FILE " \$list_special_folders_first = true;\n";
574 } else {
575 print FILE " \$list_special_folders_first = false;\n";
576 }
577
578
579
580
581 ############################################################
582 # Themes
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) > ";
588 $input = <STDIN>;
589 $input =~ s/[\r|\n]//g;
590 $theme_default = 0;
591 while ($input ne "d") {
592 if ($input =~ /^\s*l\s*/i) {
593 $count = 0;
594 while ($count <= $#theme_name) {
595 if ($count == $theme_default) {
596 print " *";
597 } else {
598 print " ";
599 }
600 $name = $theme_name[$count];
601 $num_spaces = 25 - length($name);
602 for ($i = 0; $i < $num_spaces;$i++) {
603 $name = $name . " ";
604 }
605
606 print " $count. $name";
607 print "($theme_path[$count])\n";
608
609 $count++;
610 }
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;
618 }
619 } elsif ($input =~ /^\s*\+/) {
620 print "What is the name of this theme: ";
621 $name = <STDIN>;
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): ";
626 $name = <STDIN>;
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*$/) {
631 $rem_num = $input;
632 $rem_num =~ s/^\s*-\s*//g;
633 $rem_num =~ s/\s*$//;
634 } else {
635 $rem_num = $#theme_name;
636 }
637 if ($rem_num == $theme_default) {
638 print "You cannot remove the default theme!\n";
639 } else {
640 $count = 0;
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]);
647 }
648 $count++;
649 }
650 @theme_name = @new_theme_name;
651 @theme_path = @new_theme_path;
652 if ($theme_default > $rem_num) {
653 $theme_default--;
654 }
655 }
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";
664 }
665 print "[theme] command (?=help) > ";
666 $input = <STDIN>;
667 $input =~ s/[\r|\n]//g;
668 }
669
670 $count = 0;
671 print FILE " \$theme[0][\"NAME\"] = \"$theme_name[$theme_default]\";\n";
672 print FILE " \$theme[0][\"PATH\"] = \"$theme_path[$theme_default]\";\n";
673 $index = 1;
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";
678 $index++;
679 }
680 $count++;
681 }
682
683 print FILE "\n?>\n";
684 close FILE;
685
686
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]: ";
691 $autoe = <STDIN>;
692 if (($autoe =~ /^y\n/i) || ($autoe =~ /^\n/)) {
693 system "mv -f cf.php config.php";
694 }
695
696