Added pointer to Russian version.
[squirrelmail.git] / config / conf.pl
CommitLineData
bbd30ac8 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
11print "\n\n--------------------------------------------------------\n";
12print "SquirrelMail version 0.4 -- Configure script\n";
13print "by SquirrelMail Development Team\n";
14print "http://squirrelmail.sourceforge.net\n";
15print "--------------------------------------------------------\n";
16print "\n";
17
18############################################################
19# First, lets read in the data already in there...
20############################################################
21if ( -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
32while ($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
69open (FILE, ">cf.php");
70print FILE "<?\n\t/** SquirrelMail configure script\n";
71print FILE " ** Created using the configure script, config.pl.\n\t **/\n\n";
72
73print "\n-------------------------------------------------.\n";
74print " General Information )\n";
75print "-------------------------------------------------'\n";
76############################################################
77# Organization Name
78############################################################
79print $WHT."What is the name of your organization [$org_name]: $NRM";
80$new_org_name = <STDIN>;
81if ($new_org_name eq "\n") {
82 $new_org_name = $org_name;
83} else {
84 $new_org_name =~ s/[\r|\n]//g;
85}
86print FILE " ".'$org_name = "' . $new_org_name . "\";\n";
87
88
89
90############################################################
91# Organization Logo
92############################################################
93print $WHT."Where is the logo for your organization [$org_logo]: $NRM";
94$new_org_logo = <STDIN>;
95if ($new_org_logo eq "\n") {
96 $new_org_logo = $org_logo;
97} else {
98 $new_org_logo =~ s/[\r|\n]//g;
99}
100print FILE " ".'$org_logo = "' . $new_org_logo . "\";\n";
101
102
103
104
105############################################################
106# Organization Title
107############################################################
108print "The title of the web page [$org_title]: ";
109$new_org_title = <STDIN>;
110if ($new_org_title eq "\n") {
111 $new_org_title = $org_title;
112} else {
113 $new_org_title =~ s/[\r|\n]//g;
114}
115print FILE " ".'$org_title = "' . $new_org_title . "\";\n";
116
117
118
119print "\n-------------------------------------------------.\n";
120print " Server Information )\n";
121print "-------------------------------------------------'\n";
122############################################################
123# IMAP Server
124############################################################
125print "Where is the IMAP server [$imapServerAddress]: ";
126$new_imapServerAddress = <STDIN>;
127if ($new_imapServerAddress eq "\n") {
128 $new_imapServerAddress = $imapServerAddress;
129} else {
130 $new_imapServerAddress =~ s/[\r|\n]//g;
131}
132print FILE " ".'$imapServerAddress = "' . $new_imapServerAddress . "\";\n";
133
134
135
136############################################################
137# IMAP Port
138############################################################
139print "The port for your IMAP server [$imapPort]: ";
140$new_imapPort = <STDIN>;
141if ($new_imapPort eq "\n") {
142 $new_imapPort = $imapPort;
143} else {
144 $new_imapPort =~ s/[\r|\n]//g;
145}
146print FILE " ".'$imapPort = ' . $new_imapPort . ";\n";
147
148
149
150############################################################
151# DOMAIN
152############################################################
153print "What is your domain name (ex: usa.om.org) [$domain]: ";
154$new_domain = <STDIN>;
155if ($new_domain eq "\n") {
156 $new_domain = $domain;
157} else {
158 $new_domain =~ s/[\r|\n]//g;
159}
160print FILE " ".'$domain = "' . $new_domain . "\";\n";
161
162
163############################################################
164# USE SMTP OR SENDMAIL?
165############################################################
166print "\nYou now need to choose the method that you will use for sending\n";
167print "messages in SquirrelMail. You can either connect to an SMTP server\n";
168print "or use sendmail directly.\n";
169if ($useSendmail eq "true") {
170 $default_value = "n";
171} else {
172 $default_value = "y";
173}
174print "Use SMTP (y/n) [$default_value]: ";
175$use_smtp = <STDIN>;
176if (($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
222print "\n-------------------------------------------------.\n";
223print " General Options )\n";
224print "-------------------------------------------------'\n";
225###############################################################
226# MOTD
227###############################################################
228print "\nYou can now create the welcome message that is displayed\n";
229print "every time a user logs on. You can use HTML or just plain\n";
230print "text.\n\n(Type @ on a blank line to exit)\n";
231do {
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 "@");
240print FILE " ".'$motd = "'.$new_motd."\";\n";
241
242
243############################################################
244# AUTO EXPUNGE
245############################################################
246if ($auto_expunge eq "false") {
247 $default_value = "n";
248} else {
249 $default_value = "y";
250}
251print "Should we automatically expunge deleted messages (y/n) [$default_value]: ";
252$autoe = <STDIN>;
253if (($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############################################################
263if ($default_sub_of_inbox eq "false") {
264 $default_value = "n";
265} else {
266 $default_value = "y";
267}
268print "By default, are new folders subfolders of INBOX (y/n) [$default_value]: ";
269$autoe = <STDIN>;
270if (($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############################################################
282print "\nSome IMAP daemons (UW) handle folders weird. They only allow a\n";
283print "folder to contain either messages or subfolders. Not both at the\n";
284print "same time. This option controls whether or not to display an \n";
285print "option during folder creation letting them choose if this folder\n";
286print "contains messages or folders.\n";
287if ($show_contain_subfolders_option eq "false") {
288 $default_value = "n";
289} else {
290 $default_value = "y";
291}
292print "Show the option to contain subfolders (y/n) [$default_value]: ";
293$autoe = <STDIN>;
294if (($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############################################################
307print "\nThis option decides whether or not to use META tags to forward\n";
308print "users past some of the notification screens\n";
309if ($auto_forward eq "false") {
310 $default_value = "n";
311} else {
312 $default_value = "y";
313}
314print "Automatically forward where possible (y/n) [$default_value]: ";
315$autoe = <STDIN>;
316if (($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############################################################
328print "\nThis option controls what character set is used when sending mail\n";
329print "and when sending HTMl to the browser. Do not set this to US-ASCII,\n";
330print "use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R,\n";
331print "since this implementation is faster than the alternatives.\n";
332print "Default charset [$default_charset]: ";
333$new_default_charset = <STDIN>;
334if ($new_default_charset eq "\n") {
335 $new_default_charset = $default_charset;
336} else {
337 $new_default_charset =~ s/[\r|\n]//g;
338}
339print FILE " ".'$default_charset = "' . $new_default_charset . "\";\n";
340
341
342
343
344############################################################
345# DATA DIRECTORY
346############################################################
347print "\nIt is a possible security hole to have a writable directory\n";
348print "under the web server's root directory (ex: /home/httpd/html).\n";
349print "For this reason, it is possible to put the data directory\n";
350print "anywhere you would like. The path name can be absolute or\n";
351print "relative (to the config directory). It doesn't matter. Here are\n";
352print "two examples:\n";
353print " Absolute:\n";
354print " /usr/local/squirrelmail/data/;\n";
355print " Relative (to the config directory):\n";
356print " ../data/;\n";
357print "Where is the data directory [$data_dir]: ";
358$new_data_dir = <STDIN>;
359if ($new_data_dir eq "\n") {
360 $new_data_dir = $data_dir;
361} else {
362 $new_data_dir =~ s/[\r|\n]//g;
363}
364print FILE " ".'$data_dir = "' . $new_data_dir . "\";\n";
365
366
367
368
369############################################################
370# ATTACHMENT DIRECTORY
371############################################################
372print "\nPath to directory used for storing attachments while a mail is\n";
373print "being sent. There are a few security considerations regarding this\n";
374print "directory:\n";
375print " - It should have the permission 733 (rwx-wx-wx) to make it\n";
376print " impossible for a random person with access to the webserver to\n";
377print " list files in this directory. Confidential data might be laying\n";
378print " around there\n";
379print " - Since the webserver is not able to list the files in the content\n";
380print " is also impossible for the webserver to delete files lying around\n";
381print " there for too long.\n";
382print " - It should probably be another directory than data_dir.\n";
383print "Where is the attachment directory [$attachment_dir]: ";
384$new_attachment_dir = <STDIN>;
385if ($new_attachment_dir eq "\n") {
386 $new_attachment_dir = $attachment_dir;
387} else {
388 $new_attachment_dir =~ s/[\r|\n]//g;
389}
390print FILE " ".'$attachment_dir = "' . $new_attachment_dir . "\";\n";
391
392
393
394
395############################################################
396# DEFAULT LEFT SIZE
397############################################################
398print "What is the default left folder list size (pixels) [$default_left_size]: ";
399$new_default_left_size = <STDIN>;
400if ($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}
405print FILE " ".'$default_left_size = "' . $new_default_left_size . "\";\n";
406
407
408
409
410
411
412
413print "\n-------------------------------------------------.\n";
414print " Special Folders )\n";
415print "-------------------------------------------------'\n";
416
417############################################################
418# Trash folder
419############################################################
420print "What is the default trash folder [$trash_folder]: ";
421$new_trash_folder = <STDIN>;
422if ($new_trash_folder eq "\n") {
423 $new_trash_folder = $trash_folder;
424} else {
425 $new_trash_folder =~ s/[\r|\n]//g;
426}
427print FILE " ".'$trash_folder = "' . $new_trash_folder . "\";\n";
428
429
430
431############################################################
432# Default move to trash
433############################################################
434if ($default_move_to_trash eq "true") {
435 $default_value = "y";
436} else {
437 $default_value = "n";
438}
439print "By default, should deleted messages be moved to $new_trash_folder (y/n) [$default_value]: ";
440$move_trash = <STDIN>;
441if (($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############################################################
452print "What is the default sent folder [$sent_folder]: ";
453$new_sent_folder = <STDIN>;
454if ($new_sent_folder eq "\n") {
455 $new_sent_folder = $sent_folder;
456} else {
457 $new_sent_folder =~ s/[\r|\n]//g;
458}
459print FILE " ".'$sent_folder = "' . $new_sent_folder . "\";\n";
460
461
462
463
464############################################################
465# Special Folders
466############################################################
467print "\nSpecial folders are folders that can't be manipulated like normal\n";
468print "user-created folders. A couple of examples of these would be the\n";
469print "trash folder, the sent folder, etc.\n";
470print "Special Folders:\n";
471$count = 0;
472print "\n";
473while ($count < @special_folders) {
474 print " $count) " . $special_folders[$count] . "\n";
475 $count++;
476}
477print "[folders] command (?=help) > ";
478$input = <STDIN>;
479$input =~ s/[\r|\n]//g;
480while ($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;
537while ($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############################################################
546if ($use_special_folder_color eq "true") {
547 $default_value = "y";
548} else {
549 $default_value = "n";
550}
551print "\nHighlight special folders in a different color (y/n) [$default_value]: ";
552$use_spec_folder = <STDIN>;
553if (($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############################################################
565if ($list_special_folders_first eq "false") {
566 $default_value = "n";
567} else {
568 $default_value = "y";
569}
570print "Should special folders be listed first (y/n) [$default_value]: ";
571$autoe = <STDIN>;
572if (($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############################################################
584print "\nNow we will define the themes that you wish to use. If you have added\n";
585print "a theme of your own, just follow the instructions (?) about how to add\n";
586print "them. You can also change the default theme.\n";
587print "[theme] command (?=help) > ";
588$input = <STDIN>;
589$input =~ s/[\r|\n]//g;
590$theme_default = 0;
591while ($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;
671print FILE " \$theme[0][\"NAME\"] = \"$theme_name[$theme_default]\";\n";
672print FILE " \$theme[0][\"PATH\"] = \"$theme_path[$theme_default]\";\n";
673$index = 1;
674while ($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
683print FILE "\n?>\n";
684close FILE;
685
686
687print "\n\nFINISHED!\n";
688print "All changes have been written to cf.php. If you would like, I can write\n";
689print "the changes to config.php.\n";
690print "Overwrite config.php (y/n) [y]: ";
691$autoe = <STDIN>;
692if (($autoe =~ /^y\n/i) || ($autoe =~ /^\n/)) {
693 system "mv -f cf.php config.php";
694}
695
696