added blue theme
[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 ############################################################
12 # First, lets read in the data already in there...
13 ############################################################
14 if ( -e "config.php") {
15 $config = 1;
16 open (FILE, "config.php");
17 } elsif (-e "config_default.php") {
18 $config = 2;
19 open (FILE, "config_default.php");
20 } else {
21 print "No configuration file found. Please get config_default.php or\n";
22 print "config.php before running this again. This program needs a\n";
23 print "default config file to get default values.\n";
24 exit;
25 }
26
27 # Reads and parses the current configuration file (either
28 # config.php or config_default.php).
29
30 while ($line = <FILE>) {
31 if ($line =~ /^\s+\$/) {
32 $line =~ s/^\s+\$//;
33 $var = $line;
34
35 if ($var =~ /^([a-z]|[A-Z])/) {
36 @options = split(/\s*=\s*/, $var);
37 $options[1] =~ s/[\n|\r]//g;
38 $options[1] =~ s/^"//g;
39 $options[1] =~ s/;.*$//g;
40 $options[1] =~ s/"$//g;
41
42 if ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) {
43 $sub = $options[0];
44 $sub =~ s/\]\["PATH"\]//;
45 $sub = substr ($sub, @sub-1, 1);
46 $theme_path[$sub] = $options[1];
47 } elsif ($options[0] =~ /^theme\[[0-9]+\]\["NAME"\]/) {
48 $sub = $options[0];
49 $sub =~ s/\]\["NAME"\]//;
50 $sub = substr ($sub, @sub-1, 1);
51 $theme_name[$sub] = $options[1];
52 } elsif ($options[0] =~ /^ldap_server\[[0-9]+\]/) {
53 $sub = $options[0];
54 $sub = substr ($sub, length($sub)-2, 1);
55 $continue = 0;
56 while (($tmp = <FILE>) && ($continue != 1)) {
57 if ($tmp =~ /\);\s*$/) {
58 $continue = 1;
59 }
60
61 if ($tmp =~ /^\s*"host"/i) {
62 $tmp =~ s/^\s*"host"\s*=>\s*"//i;
63 $tmp =~ s/",\s*$//;
64 $tmp =~ s/"\);\s*$//;
65 $host = $tmp;
66 } elsif ($tmp =~ /^\s*"base"/i) {
67 $tmp =~ s/^\s*"base"\s*=>\s*"//i;
68 $tmp =~ s/",\s*$//;
69 $tmp =~ s/"\);\s*$//;
70 print $tmp."\n";
71 $base = $tmp;
72 } elsif ($tmp =~ /^\s*"charset"/i) {
73 $tmp =~ s/^\s*"charset"\s*=>\s*"//i;
74 $tmp =~ s/",\s*$//;
75 $tmp =~ s/"\);\s*$//;
76 $charset = $tmp;
77 } elsif ($tmp =~ /^\s*"port"/i) {
78 $tmp =~ s/^\s*"port"\s*=>\s*"//i;
79 $tmp =~ s/",\s*$//;
80 $tmp =~ s/"\);\s*$//;
81 $port = $tmp;
82 } elsif ($tmp =~ /^\s*"maxrows"/i) {
83 $tmp =~ s/^\s*"maxrows"\s*=>\s*"//i;
84 $tmp =~ s/",\s*$//;
85 $tmp =~ s/"\);\s*$//;
86 $maxrows = $tmp;
87 } elsif ($tmp =~ /^\s*"name"/i) {
88 $tmp =~ s/^\s*"name"\s*=>\s*"//i;
89 $tmp =~ s/",\s*$//;
90 $tmp =~ s/"\);\s*$//;
91 $name = $tmp;
92 }
93 }
94 $ldap_host[$sub] = $host;
95 $ldap_base[$sub] = $base;
96 $ldap_name[$sub] = $name;
97 $ldap_port[$sub] = $port;
98 $ldap_maxrows[$sub] = $maxrows;
99 $ldap_charset[$sub] = $charset;
100 } else {
101 ${$options[0]} = $options[1];
102 }
103 }
104 }
105 }
106 if ($useSendmail ne "true") {
107 $useSendmail = "false";
108 }
109 if (!$sendmail_path) {
110 $sendmail_path = "/usr/sbin/sendmail";
111 }
112
113 #####################################################################################
114
115 while (($command ne "q") && ($command ne "Q")) {
116 system "clear";
117 if ($menu == 0) {
118 print $WHT."SquirrelMail Configuration : ".$NRM;
119 if ($config == 1) { print "Read: config.php"; }
120 elsif ($config == 2) { print "Read: config_default.php"; }
121 print "\n";
122
123 print $WHT."Main Menu --\n".$NRM;
124 print "1. Organization Preferences\n";
125 print "2. Server Settings\n";
126 print "3. Folder Defaults\n";
127 print "4. General Options\n";
128 print "5. Themes\n";
129 print "6. Address Books (LDAP)\n";
130 print "7. Message of the Day (MOTD)\n";
131 print "\n";
132 print "D. Set pre-defined settings for specific IMAP servers\n";
133 print "\n";
134 } elsif ($menu == 1) {
135 print $WHT."Organization Preferences\n".$NRM;
136 print "1. Organization Name : $WHT$org_name$NRM\n";
137 print "2. Organization Logo : $WHT$org_logo$NRM\n";
138 print "3. Organization Title : $WHT$org_title$NRM\n";
139 print "\n";
140 print "R Return to Main Menu\n";
141 } elsif ($menu == 2) {
142 print $WHT."Server Settings\n".$NRM;
143 print "1. Domain : $WHT$domain$NRM\n";
144 print "2. IMAP Server : $WHT$imapServerAddress$NRM\n";
145 print "3. IMAP Port : $WHT$imapPort$NRM\n";
146 print "4. Use Sendmail : $WHT$useSendmail$NRM\n";
147 if ($useSendmail eq "true") {
148 print "5. Sendmail Path : $WHT$sendmail_path$NRM\n";
149 } else {
150 print "6. SMTP Server : $WHT$smtpServerAddress$NRM\n";
151 print "7. SMTP Port : $WHT$smtpPort$NRM\n";
152 }
153 print "8. Server : $WHT$imap_server_type$NRM\n";
154 print "\n";
155 print "R Return to Main Menu\n";
156 } elsif ($menu == 3) {
157 print $WHT."Folder Defaults\n".$NRM;
158 print "1. Default Folder Prefix : $WHT$default_folder_prefix$NRM\n";
159 print "2. Show Folder Prefix Option : $WHT$show_prefix_option$NRM\n";
160 print "3. Trash Folder : $WHT$trash_folder$NRM\n";
161 print "4. Sent Folder : $WHT$sent_folder$NRM\n";
162 print "5. By default, move to trash : $WHT$default_move_to_trash$NRM\n";
163 print "6. By default, move to sent : $WHT$default_move_to_sent$NRM\n";
164 print "7. List Special Folders First : $WHT$list_special_folders_first$NRM\n";
165 print "8. Show Special Folders Color : $WHT$use_special_folder_color$NRM\n";
166 print "9. Auto Expunge : $WHT$auto_expunge$NRM\n";
167 print "10. Default Sub. of INBOX : $WHT$default_sub_of_inbox$NRM\n";
168 print "11. Show 'Contain Sub.' Option : $WHT$show_contain_subfolders_option$NRM\n";
169 print "\n";
170 print "R Return to Main Menu\n";
171 } elsif ($menu == 4) {
172 print $WHT."General Options\n".$NRM;
173 print "1. Default Charset : $WHT$default_charset$NRM\n";
174 print "2. Auto Forward : $WHT$auto_forward$NRM\n";
175 print "3. Data Directory : $WHT$data_dir$NRM\n";
176 print "4. Attachment Directory : $WHT$attachment_dir$NRM\n";
177 print "5. Default Left Size : $WHT$default_left_size$NRM\n";
178 print "\n";
179 print "R Return to Main Menu\n";
180 } elsif ($menu == 5) {
181 print $WHT."Themes\n".$NRM;
182 print "1. Change Themes\n";
183 for ($count = 0; $count <= $#theme_name; $count++) {
184 print " > $theme_name[$count]\n";
185 }
186 print "\n";
187 print "R Return to Main Menu\n";
188 } elsif ($menu == 6) {
189 print $WHT."Address Books (LDAP)\n".$NRM;
190 print "1. Change Servers\n";
191 for ($count = 0; $count <= $#ldap_host; $count++) {
192 print " > $ldap_host[$count]\n";
193 }
194 print "\n";
195 print "R Return to Main Menu\n";
196 } elsif ($menu == 7) {
197 print $WHT."Message of the Day (MOTD)\n".$NRM;
198 print "\n$motd\n";
199 print "\n";
200 print "1 Edit the MOTD\n";
201 print "\n";
202 print "R Return to Main Menu\n";
203 }
204 print "S Save data\n";
205 print "Q Quit\n";
206
207 print "\n";
208 print "Command >> ".$WHT;
209 $command = <STDIN>;
210 $command =~ s/[\n|\r]//g;
211 print "$NRM\n";
212
213 # Read the commands they entered.
214 if (($command eq "R") || ($command eq "r")) {
215 $menu = 0;
216 } elsif (($command eq "s") || ($command eq "S")) {
217 save_data ();
218 print "Data saved in config.php\n";
219 print "Press any key to continue...";
220 $tmp = <STDIN>;
221 $saved = 1;
222 } elsif ((($command eq "q") || ($command eq "Q")) && ($saved == 0)) {
223 print "You have not saved your data.\n";
224 print "Save? (y/n) [".$WHT."y".$NRM."]: ";
225 $save = <STDIN>;
226 if (($save =~ /^y/i) || ($save =~ /^\s*$/)) {
227 save_data ();
228 }
229 } elsif (($command eq "d") || ($command eq "D")) {
230 set_defaults ();
231 } else {
232 $saved = 0;
233 if ($menu == 0) {
234 if (($command > 0) && ($command < 8)) {
235 $menu = $command;
236 }
237 } elsif ($menu == 1) {
238 if ($command == 1) { $org_name = command1 (); }
239 elsif ($command == 2) { $org_logo = command2 (); }
240 elsif ($command == 3) { $org_title = command3 (); }
241 } elsif ($menu == 2) {
242 if ($command == 1) { $domain = command11 (); }
243 elsif ($command == 2) { $imapServerAddress = command12 (); }
244 elsif ($command == 3) { $imapPort = command13 (); }
245 elsif ($command == 4) { $useSendmail = command14 (); }
246 elsif ($command == 5) { $sendmail_path = command15 (); }
247 elsif ($command == 6) { $smtpServerAddress = command16 (); }
248 elsif ($command == 7) { $smtpPort = command17 (); }
249 elsif ($command == 8) { $imap_server_type = command18 (); }
250 } elsif ($menu == 3) {
251 if ($command == 1) { $default_folder_prefix = command21 (); }
252 elsif ($command == 2) { $show_prefix_option = command22 (); }
253 elsif ($command == 3) { $trash_folder = command23 (); }
254 elsif ($command == 4) { $sent_folder = command24 (); }
255 elsif ($command == 5) { $default_move_to_trash = command25 (); }
256 elsif ($command == 6) { $default_move_to_sent = command26 (); }
257 elsif ($command == 7) { $list_special_folders_first = command27 (); }
258 elsif ($command == 8) { $use_special_folder_color = command28 (); }
259 elsif ($command == 9) { $auto_expunge = command29 (); }
260 elsif ($command == 10){ $default_sub_of_inbox = command210(); }
261 elsif ($command == 11){ $show_contain_subfolders_option = command211(); }
262 } elsif ($menu == 4) {
263 if ($command == 1) { $default_charset = command31 (); }
264 elsif ($command == 2) { $auto_forward = command32 (); }
265 elsif ($command == 3) { $data_dir = command33 (); }
266 elsif ($command == 4) { $attachment_dir = command34 (); }
267 elsif ($command == 5) { $default_left_size = command35 (); }
268 } elsif ($menu == 5) {
269 if ($command == 1) {
270 command41 ();
271 }
272 } elsif ($menu == 6) {
273 if ($command == 1) { command61(); }
274 } elsif ($menu == 7) {
275 if ($command == 1) { $motd = command71 (); $motd =~ s/"/\\"/g;}
276 }
277 }
278 }
279
280 ####################################################################################
281
282 # org_name
283 sub command1 {
284 print "We have tried to make the name SquirrelMail as transparent as\n";
285 print "possible. If you set up an organization name, most places where\n";
286 print "SquirrelMail would take credit will be credited to your organization.\n";
287 print "\n";
288 print "[$WHT$org_name$NRM]: $WHT";
289 $new_org_name = <STDIN>;
290 if ($new_org_name eq "\n") {
291 $new_org_name = $org_name;
292 } else {
293 $new_org_name =~ s/[\r|\n]//g;
294 }
295 return $new_org_name;
296 }
297
298
299 # org_logo
300 sub command2 {
301 print "Your organization's logo is an image that will be displayed at\n";
302 print "different times throughout SquirrelMail. This is asking for the\n";
303 print "literal (/usr/local/squirrelmail/images/logo.jpg) or relative\n";
304 print "(../images/logo.jpg) path to your logo.\n";
305 print "\n";
306 print "[$WHT$org_logo$NRM]: $WHT";
307 $new_org_logo = <STDIN>;
308 if ($new_org_logo eq "\n") {
309 $new_org_logo = $org_logo;
310 } else {
311 $new_org_logo =~ s/[\r|\n]//g;
312 }
313 return $new_org_logo;
314 }
315
316 # org_title
317 sub command3 {
318 print "A title is what is displayed at the top of the browser window in\n";
319 print "the titlebar. Usually this will end up looking something like:\n";
320 print "\"Netscape: $org_title\"\n";
321 print "\n";
322 print "[$WHT$org_title$NRM]: $WHT";
323 $new_org_title = <STDIN>;
324 if ($new_org_title eq "\n") {
325 $new_org_title = $org_title;
326 } else {
327 $new_org_title =~ s/[\r|\n]//g;
328 }
329 return $new_org_title;
330 }
331
332 ####################################################################################
333
334 # domain
335 sub command11 {
336 print "The domain name is the suffix at the end of all email messages. If\n";
337 print "for example, your email address is jdoe\@myorg.com, then your domain\n";
338 print "would be myorg.com.\n";
339 print "\n";
340 print "[$WHT$domain$NRM]: $WHT";
341 $new_domain = <STDIN>;
342 if ($new_domain eq "\n") {
343 $new_domain = $domain;
344 } else {
345 $new_domain =~ s/[\r|\n]//g;
346 }
347 return $new_domain;
348 }
349
350 # imapServerAddress
351 sub command12 {
352 print "This is the address where your IMAP server resides.\n";
353 print "[$WHT$imapServerAddress$NRM]: $WHT";
354 $new_imapServerAddress = <STDIN>;
355 if ($new_imapServerAddress eq "\n") {
356 $new_imapServerAddress = $imapServerAddress;
357 } else {
358 $new_imapServerAddress =~ s/[\r|\n]//g;
359 }
360 return $new_imapServerAddress;
361 }
362
363 # imapPort
364 sub command13 {
365 print "This is the port that your IMAP server is on. Usually this is 143.\n";
366 print "[$WHT$imapPort$NRM]: $WHT";
367 $new_imapPort = <STDIN>;
368 if ($new_imapPort eq "\n") {
369 $new_imapPort = $imapPort;
370 } else {
371 $new_imapPort =~ s/[\r|\n]//g;
372 }
373 return $new_imapPort;
374 }
375
376 # useSendmail
377 sub command14 {
378 print "You now need to choose the method that you will use for sending\n";
379 print "messages in SquirrelMail. You can either connect to an SMTP server\n";
380 print "or use sendmail directly.\n";
381 if ($useSendmail eq "true") {
382 $default_value = "y";
383 } else {
384 $default_value = "n";
385 }
386 print "\n";
387 print "Use Sendmail (y/n) [$WHT$default_value$NRM]: $WHT";
388 $use_sendmail = <STDIN>;
389 if (($use_sendmail =~ /^y\n/i) || (($use_sendmail =~ /^\n/) && ($default_value eq "y"))) {
390 $useSendmail = "true";
391 } else {
392 $useSendmail = "false";
393 }
394 return $useSendmail;
395 }
396
397 # sendmail_path
398 sub command15 {
399 if ($sendmail_path[0] !~ /./) {
400 $sendmail_path = "/usr/sbin/sendmail";
401 }
402 print "Specify where the sendmail executable is located. Usually /usr/sbin/sendmail\n";
403 print "[$WHT$sendmail_path$NRM]: $WHT";
404 $new_sendmail_path = <STDIN>;
405 if ($new_sendmail_path eq "\n") {
406 $new_sendmail_path = $sendmail_path;
407 } else {
408 $new_sendmail_path =~ s/[\r|\n]//g;
409 }
410 return $new_sendmail_path;
411 }
412
413 # smtpServerAddress
414 sub command16 {
415 print "This is the location of your SMTP server.\n";
416 print "[$WHT$smtpServerAddress$NRM]: $WHT";
417 $new_smtpServerAddress = <STDIN>;
418 if ($new_smtpServerAddress eq "\n") {
419 $new_smtpServerAddress = $smtpServerAddress;
420 } else {
421 $new_smtpServerAddress =~ s/[\r|\n]//g;
422 }
423 return $new_smtpServerAddress;
424 }
425
426 # smtpPort
427 sub command17 {
428 print "This is the port to connect to for SMTP. Usually 25.\n";
429 print "[$WHT$smtpPort$NRM]: $WHT";
430 $new_smtpPort = <STDIN>;
431 if ($new_smtpPort eq "\n") {
432 $new_smtpPort = $smtpPort;
433 } else {
434 $new_smtpPort =~ s/[\r|\n]//g;
435 }
436 return $new_smtpPort;
437 }
438 # imap_server_type
439 sub command18 {
440 print "Eash IMAP server has its own quirks. As much as we tried to stick\n";
441 print "to standards, it doesn't help much if the IMAP server doesn't follow\n";
442 print "the same principles. We have made some work-arounds for some of\n";
443 print "these servers. If you would like to use them, please select your\n";
444 print "IMAP server. If you do not wish to use these work-arounds, you can\n";
445 print "set this to \"other\", and none will be used.\n";
446 print " cyrus = Cyrus IMAP server\n";
447 print " uw = University of Washington's IMAP server\n";
448 print " exchange = Microsoft Exchange IMAP server\n";
449 print " courier = Courier IMAP server\n";
450 print "[$WHT$imap_server_type$NRM]: $WHT";
451 $new_imap_server_type = <STDIN>;
452 if ($new_imap_server_type eq "\n") {
453 $new_imap_server_type = $imap_server_type;
454 } else {
455 $new_imap_server_type =~ s/[\r|\n]//g;
456 }
457 return $new_imap_server_type;
458 }
459
460 # MOTD
461 sub command71 {
462 print "\nYou can now create the welcome message that is displayed\n";
463 print "every time a user logs on. You can use HTML or just plain\n";
464 print "text.\n\n(Type @ on a blank line to exit)\n";
465 do {
466 print "] ";
467 $line = <STDIN>;
468 $line =~ s/[\r|\n]//g;
469 $line =~ s/ /\&nbsp;\&nbsp;/g;
470 if ($line ne "@") {
471 $new_motd = $new_motd . $line;
472 }
473 } while ($line ne "@");
474 return $new_motd;
475 }
476
477 ################# FOLDERS ###################
478
479 # default_folder_prefix
480 sub command21 {
481 print "Some IMAP servers (UW, for example) store mail and folders in\n";
482 print "your user space in a separate subdirectory. This is where you\n";
483 print "specify what that directory is.\n";
484 print "\n";
485 print "EXAMPLE: mail/";
486 print "\n";
487 print "NOTE: If you use Cyrus, or some server that would not use this\n";
488 print " option, you must set this to 'none'.\n";
489 print "\n";
490 print "[$WHT$default_folder_prefix$NRM]: $WHT";
491 $new_default_folder_prefix = <STDIN>;
492 if ($new_default_folder_prefix eq "\n") {
493 $new_default_folder_prefix = $default_folder_prefix;
494 } else {
495 $new_default_folder_prefix =~ s/[\r|\n]//g;
496 }
497 if (($new_default_folder_prefix =~ /^\s*$/) || ($new_default_folder_prefix =~ /none/i)) {
498 $new_default_folder_prefix = "";
499 } else {
500 $new_default_folder_prefix =~ s/\/*$//g;
501 $new_default_folder_prefix =~ s/$/\//g;
502 }
503 return $new_default_folder_prefix;
504 }
505
506 # Show Folder Prefix
507 sub command22 {
508 print "It is possible to set up the default folder prefix as a user\n";
509 print "specific option, where each user can specify what their mail\n";
510 print "folder is. If you set this to false, they will never see the\n";
511 print "option, but if it is true, this option will appear in the\n";
512 print "'options' section.\n";
513 print "\n";
514 print "NOTE: You set the default folder prefix in option '1' of this\n";
515 print " section. That will be the default if the user doesn't\n";
516 print " specify anything different.\n";
517 print "\n";
518
519 if ($show_prefix_option eq "true") {
520 $default_value = "y";
521 } else {
522 $default_value = "n";
523 }
524 print "\n";
525 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
526 $new_show = <STDIN>;
527 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
528 $show_prefix_option = "true";
529 } else {
530 $show_prefix_option = "false";
531 }
532 return $show_prefix_option;
533 }
534
535 # Trash Folder
536 sub command23 {
537 print "You can now specify where the default trash folder is located.\n";
538 print "On servers where you do not want this, you can set it to anything\n";
539 print "and set option 7 to false.\n";
540 print "\n";
541 print "This is relative to where the rest of your email is kept. You do\n";
542 print "not need to worry about their mail directory. If this folder\n";
543 print "would be ~/mail/trash on the filesystem, you only need to specify\n";
544 print "that this is 'trash', and be sure to put 'mail/' in option 1.\n";
545 print "\n";
546
547 print "[$WHT$trash_folder$NRM]: $WHT";
548 $new_trash_folder = <STDIN>;
549 if ($new_trash_folder eq "\n") {
550 $new_trash_folder = $trash_folder;
551 } else {
552 $new_trash_folder =~ s/[\r|\n]//g;
553 }
554 return $new_trash_folder;
555 }
556
557 # Sent Folder
558 sub command24 {
559 print "This is where messages that are sent will be stored. SquirrelMail\n";
560 print "by default puts a copy of all outgoing messages in this folder.\n";
561 print "\n";
562 print "This is relative to where the rest of your email is kept. You do\n";
563 print "not need to worry about their mail directory. If this folder\n";
564 print "would be ~/mail/sent on the filesystem, you only need to specify\n";
565 print "that this is 'sent', and be sure to put 'mail/' in option 1.\n";
566 print "\n";
567
568 print "[$WHT$sent_folder$NRM]: $WHT";
569 $new_sent_folder = <STDIN>;
570 if ($new_sent_folder eq "\n") {
571 $new_sent_folder = $sent_folder;
572 } else {
573 $new_sent_folder =~ s/[\r|\n]//g;
574 }
575 return $new_sent_folder;
576 }
577
578 # default move to trash
579 sub command25 {
580 print "By default, should messages get moved to the trash folder? You\n";
581 print "can specify the default trash folder in option 3. If this is set\n";
582 print "to false, messages will get deleted immediately without moving\n";
583 print "to the trash folder.\n";
584 print "\n";
585 print "Trash folder is currently: $trash_folder\n";
586 print "\n";
587
588 if ($default_move_to_trash eq "true") {
589 $default_value = "y";
590 } else {
591 $default_value = "n";
592 }
593 print "By default, move to trash (y/n) [$WHT$default_value$NRM]: $WHT";
594 $new_show = <STDIN>;
595 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
596 $default_move_to_trash = "true";
597 } else {
598 $default_move_to_trash = "false";
599 }
600 return $default_move_to_trash;
601 }
602
603 # default move to sent
604 sub command26 {
605 print "By default, should messages get moved to the sent folder? You\n";
606 print "can specify the default sent folder in option 4. If this is set\n";
607 print "to false, messages will get deleted immediately without moving\n";
608 print "to the sent folder.\n";
609 print "\n";
610 print "Trash folder is currently: $sent_folder\n";
611 print "\n";
612
613 if ($default_move_to_sent eq "true") {
614 $default_value = "y";
615 } else {
616 $default_value = "n";
617 }
618 print "By default, move to sent (y/n) [$WHT$default_value$NRM]: $WHT";
619 $new_show = <STDIN>;
620 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
621 $default_move_to_sent = "true";
622 } else {
623 $default_move_to_sent = "false";
624 }
625 return $default_move_to_sent;
626 }
627
628 # List special folders first
629 sub command27 {
630 print "SquirrelMail has what we call 'special folders' that are not\n";
631 print "manipulated and viewed like normal folders. Some examples of\n";
632 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
633 print "Simply asks if you want these folders listed first in the folder\n";
634 print "listing.\n";
635 print "\n";
636
637 if ($list_special_folders_first eq "true") {
638 $default_value = "y";
639 } else {
640 $default_value = "n";
641 }
642 print "\n";
643 print "List first (y/n) [$WHT$default_value$NRM]: $WHT";
644 $new_show = <STDIN>;
645 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
646 $list_special_folders_first = "true";
647 } else {
648 $list_special_folders_first = "false";
649 }
650 return $list_special_folders_first;
651 }
652
653 # Show special folders color
654 sub command28 {
655 print "SquirrelMail has what we call 'special folders' that are not\n";
656 print "manipulated and viewed like normal folders. Some examples of\n";
657 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
658 print "wants to know if we should display special folders in a\n";
659 print "color than the other folders.\n";
660 print "\n";
661
662 if ($use_special_folder_color eq "true") {
663 $default_value = "y";
664 } else {
665 $default_value = "n";
666 }
667 print "\n";
668 print "Show color (y/n) [$WHT$default_value$NRM]: $WHT";
669 $new_show = <STDIN>;
670 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
671 $use_special_folder_color = "true";
672 } else {
673 $use_special_folder_color = "false";
674 }
675 return $use_special_folder_color;
676 }
677
678 # Auto expunge
679 sub command29 {
680 print "The way that IMAP handles deleting messages is as follows. You\n";
681 print "mark the message as deleted, and then to 'really' delete it, you\n";
682 print "expunge it. This option asks if you want to just have messages\n";
683 print "marked as deleted, or if you want SquirrelMail to expunge the \n";
684 print "messages too.\n";
685 print "\n";
686
687 if ($auto_expunge eq "true") {
688 $default_value = "y";
689 } else {
690 $default_value = "n";
691 }
692 print "Auto expunge (y/n) [$WHT$default_value$NRM]: $WHT";
693 $new_show = <STDIN>;
694 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
695 $auto_expunge = "true";
696 } else {
697 $auto_expunge = "false";
698 }
699 return $auto_expunge;
700 }
701
702 # Default sub of inbox
703 sub command210 {
704 print "Some IMAP servers (Cyrus) have all folders as subfolders of INBOX.\n";
705 print "This can cause some confusion in folder creation for users when\n";
706 print "they try to create folders and don't put it as a subfolder of INBOX\n";
707 print "and get permission errors. This option asks if you want folders\n";
708 print "to be subfolders of INBOX by default.\n";
709 print "\n";
710
711 if ($default_sub_of_inbox eq "true") {
712 $default_value = "y";
713 } else {
714 $default_value = "n";
715 }
716 print "Default sub of INBOX (y/n) [$WHT$default_value$NRM]: $WHT";
717 $new_show = <STDIN>;
718 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
719 $default_sub_of_inbox = "true";
720 } else {
721 $default_sub_of_inbox = "false";
722 }
723 return $default_sub_of_inbox;
724 }
725
726 # Show contain subfolder option
727 sub command211 {
728 print "Some IMAP servers (UW) make it so that there are two types of\n";
729 print "folders. Those that contain messages, and those that contain\n";
730 print "subfolders. If this is the case for your server, set this to\n";
731 print "true, and it will ask the user whether the folder they are\n";
732 print "creating contains subfolders or messages.\n";
733 print "\n";
734
735 if ($show_contain_subfolders_option eq "true") {
736 $default_value = "y";
737 } else {
738 $default_value = "n";
739 }
740 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
741 $new_show = <STDIN>;
742 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
743 $show_contain_subfolders_option = "true";
744 } else {
745 $show_contain_subfolders_option = "false";
746 }
747 return $show_contain_subfolders_option;
748 }
749
750 ############# GENERAL OPTIONS #####################
751
752 # Default Charset
753 sub command31 {
754 print "This option controls what character set is used when sending\n";
755 print "mail and when sending HTML to the browser. Do not set this\n";
756 print "to US-ASCII, use ISO-8859-1 instead. For cyrillic, it is best\n";
757 print "to use KOI8-R, since this implementation is faster than most\n";
758 print "of the alternatives\n";
759 print "\n";
760
761 print "[$WHT$default_charset$NRM]: $WHT";
762 $new_default_charset = <STDIN>;
763 if ($new_default_charset eq "\n") {
764 $new_default_charset = $default_charset;
765 } else {
766 $new_default_charset =~ s/[\r|\n]//g;
767 }
768 return $new_default_charset;
769 }
770
771 # Auto Forward
772 sub command32 {
773 print "There are some places that we will automatically forward the user\n";
774 print "rather than display pointless messages like 'Message sent!' or\n";
775 print "stuff like that. Use this or not?\n";
776 print "\n";
777 print "NOTE: This is not working currently as we are trying to find a\n";
778 print " better way to handle this. This option really doesn't do\n";
779 print " much.\n";
780 print "\n";
781
782 if ($auto_forward eq "true") {
783 $default_value = "y";
784 } else {
785 $default_value = "n";
786 }
787 print "Auto forward (y/n) [$WHT$default_value$NRM]: $WHT";
788 $new_show = <STDIN>;
789 if (($new_show =~ /^y\n/i) || (($new_show =~ /^\n/) && ($default_value eq "y"))) {
790 $auto_forward = "true";
791 } else {
792 $auto_forward = "false";
793 }
794 return $auto_forward;
795 }
796
797 # Data directory
798 sub command33 {
799 print "It is a possible security hole to have a writable directory\n";
800 print "under the web server's root directory (ex: /home/httpd/html).\n";
801 print "For this reason, it is possible to put the data directory\n";
802 print "anywhere you would like. The path name can be absolute or\n";
803 print "relative (to the config directory). It doesn't matter. Here\n";
804 print "are two examples:\n";
805 print " Absolute: /usr/local/squirrelmail/data/\n";
806 print " Relative: ../data/\n";
807 print "\n";
808
809 print "[$WHT$data_dir$NRM]: $WHT";
810 $new_data_dir = <STDIN>;
811 if ($new_data_dir eq "\n") {
812 $new_data_dir = $data_dir;
813 } else {
814 $new_data_dir =~ s/[\r|\n]//g;
815 }
816 if ($new_data_dir =~ /^\s*$/) {
817 $new_data_dir = "";
818 } else {
819 $new_data_dir =~ s/\/*$//g;
820 $new_data_dir =~ s/$/\//g;
821 }
822 return $new_data_dir;
823 }
824
825 # Attachment directory
826 sub command34 {
827 print "Path to directory used for storing attachments while a mail is\n";
828 print "being sent. There are a few security considerations regarding this\n";
829 print "directory:\n";
830 print " 1. It should have the permission 733 (rwx-wx-wx) to make it\n";
831 print " impossible for a random person with access to the webserver\n";
832 print " to list files in this directory. Confidential data might\n";
833 print " be laying around in there.\n";
834 print " 2. Since the webserver is not able to list the files in the\n";
835 print " content is also impossible for the webserver to delete files\n";
836 print " lying around there for too long.\n";
837 print " 3. It should probably be another directory than the data\n";
838 print " directory specified in option 3.\n";
839 print "\n";
840
841 print "[$WHT$attachment_dir$NRM]: $WHT";
842 $new_attachment_dir = <STDIN>;
843 if ($new_attachment_dir eq "\n") {
844 $new_attachment_dir = $attachment_dir;
845 } else {
846 $new_attachment_dir =~ s/[\r|\n]//g;
847 }
848 if ($new_attachment_dir =~ /^\s*$/) {
849 $new_attachment_dir = "";
850 } else {
851 $new_attachment_dir =~ s/\/*$//g;
852 $new_attachment_dir =~ s/$/\//g;
853 }
854 return $new_attachment_dir;
855 }
856
857
858 sub command35 {
859 print "This is the default size (in pixels) of the left folder list.\n";
860 print "Default is 200, but you can set it to whatever you wish. This\n";
861 print "is a user preference, so this will only show up as their default.\n";
862 print "\n";
863 print "[$WHT$default_left_size$NRM]: $WHT";
864 $new_default_left_size = <STDIN>;
865 if ($new_default_left_size eq "\n") {
866 $new_default_left_size = $default_left_size;
867 } else {
868 $new_default_left_size =~ s/[\r|\n]//g;
869 }
870 return $new_default_left_size;
871 }
872
873
874 sub command41 {
875 print "\nNow we will define the themes that you wish to use. If you have added\n";
876 print "a theme of your own, just follow the instructions (?) about how to add\n";
877 print "them. You can also change the default theme.\n";
878 print "[theme] command (?=help) > ";
879 $input = <STDIN>;
880 $input =~ s/[\r|\n]//g;
881 while ($input ne "d") {
882 if ($input =~ /^\s*l\s*/i) {
883 $count = 0;
884 while ($count <= $#theme_name) {
885 if ($count == $theme_default) {
886 print " *";
887 } else {
888 print " ";
889 }
890 $name = $theme_name[$count];
891 $num_spaces = 25 - length($name);
892 for ($i = 0; $i < $num_spaces;$i++) {
893 $name = $name . " ";
894 }
895
896 print " $count. $name";
897 print "($theme_path[$count])\n";
898
899 $count++;
900 }
901 } elsif ($input =~ /^\s*m\s*[0-9]+/i) {
902 $old_def = $theme_default;
903 $theme_default = $input;
904 $theme_default =~ s/^\s*m\s*//;
905 if (($theme_default > $#theme_name) || ($theme_default < 0)) {
906 print "Cannot set default theme to $theme_default. That theme does not exist.\n";
907 $theme_default = $old_def;
908 }
909 } elsif ($input =~ /^\s*\+/) {
910 print "What is the name of this theme: ";
911 $name = <STDIN>;
912 $name =~ s/[\r|\n]//g;
913 $theme_name[$#theme_name+1] = $name;
914 print "Be sure to put ../config/ before the filename.\n";
915 print "What file is this stored in (ex: ../config/default_theme.php): ";
916 $name = <STDIN>;
917 $name =~ s/[\r|\n]//g;
918 $theme_path[$#theme_path+1] = $name;
919 } elsif ($input =~ /^\s*-\s*[0-9]?/) {
920 if ($input =~ /[0-9]+\s*$/) {
921 $rem_num = $input;
922 $rem_num =~ s/^\s*-\s*//g;
923 $rem_num =~ s/\s*$//;
924 } else {
925 $rem_num = $#theme_name;
926 }
927 if ($rem_num == $theme_default) {
928 print "You cannot remove the default theme!\n";
929 } else {
930 $count = 0;
931 @new_theme_name = ();
932 @new_theme_path = ();
933 while ($count <= $#theme_name) {
934 if ($count != $rem_num) {
935 @new_theme_name = (@new_theme_name, $theme_name[$count]);
936 @new_theme_path = (@new_theme_path, $theme_path[$count]);
937 }
938 $count++;
939 }
940 @theme_name = @new_theme_name;
941 @theme_path = @new_theme_path;
942 if ($theme_default > $rem_num) {
943 $theme_default--;
944 }
945 }
946 } elsif ($input =~ /^\s*\?\s*/) {
947 print ".-------------------------.\n";
948 print "| + (add theme) |\n";
949 print "| - N (remove theme) |\n";
950 print "| m N (mark default) |\n";
951 print "| l (list themes) |\n";
952 print "| d (done) |\n";
953 print "`-------------------------'\n";
954 }
955 print "[theme] command (?=help) > ";
956 $input = <STDIN>;
957 $input =~ s/[\r|\n]//g;
958 }
959 }
960
961
962 sub command61 {
963 print "You can now define different LDAP servers.\n";
964 print "[ldap] command (?=help) > ";
965 $input = <STDIN>;
966 $input =~ s/[\r|\n]//g;
967 while ($input ne "d") {
968 if ($input =~ /^\s*l\s*/i) {
969 $count = 0;
970 while ($count <= $#ldap_host) {
971 print "$count. $ldap_host[$count]\n";
972 print " base: $ldap_base[$count]\n";
973 if ($ldap_charset[$count]) {
974 print " charset: $ldap_charset[$count]\n";
975 }
976 if ($ldap_port[$count]) {
977 print " port: $ldap_port[$count]\n";
978 }
979 if ($ldap_name[$count]) {
980 print " name: $ldap_name[$count]\n";
981 }
982 if ($ldap_maxrows[$count]) {
983 print " maxrows: $ldap_maxrows[$count]\n";
984 }
985 print "\n";
986 $count++;
987 }
988 } elsif ($input =~ /^\s*\+/) {
989 $sub = $#ldap_host + 1;
990
991 print "First, we need to have the hostname or the IP address where\n";
992 print "this LDAP server resides. Example: ldap.bigfoot.com\n";
993 print "hostname: ";
994 $name = <STDIN>;
995 $name =~ s/[\r|\n]//g;
996 $ldap_host[$sub] = $name;
997
998 print "\n";
999
1000 print "Next, we need the server root (base dn). For this, an empty\n";
1001 print "string is allowed.\n";
1002 print "Example: ou=member_directory,o=netcenter.com\n";
1003 print "base: ";
1004 $name = <STDIN>;
1005 $name =~ s/[\r|\n]//g;
1006 $ldap_base[$sub] = $name;
1007
1008 print "\n";
1009
1010 print "This is the TCP/IP port number for the LDAP server. Default\n";
1011 print "port is 389. This is optional. Press ENTER for default.\n";
1012 print "port: ";
1013 $name = <STDIN>;
1014 $name =~ s/[\r|\n]//g;
1015 $ldap_port[$sub] = $name;
1016
1017 print "\n";
1018
1019 print "This is the charset for the server. Default is utf-8. This\n";
1020 print "is also optional. Press ENTER for default.\n";
1021 print "charset: ";
1022 $name = <STDIN>;
1023 $name =~ s/[\r|\n]//g;
1024 $ldap_charset[$sub] = $name;
1025
1026 print "\n";
1027
1028 print "This is the name for the server, used to tag the results of\n";
1029 print "the search. Default it \"LDAP: hostname\". Press ENTER for default\n";
1030 print "name: ";
1031 $name = <STDIN>;
1032 $name =~ s/[\r|\n]//g;
1033 $ldap_name[$sub] = $name;
1034
1035 print "\n";
1036
1037 print "You can specify the maximum number of rows in the search result.\n";
1038 print "Default is unlimited. Press ENTER for default.\n";
1039 print "maxrows: ";
1040 $name = <STDIN>;
1041 $name =~ s/[\r|\n]//g;
1042 $ldap_maxrows[$sub] = $name;
1043
1044 print "\n";
1045
1046 } elsif ($input =~ /^\s*-\s*[0-9]?/) {
1047 if ($input =~ /[0-9]+\s*$/) {
1048 $rem_num = $input;
1049 $rem_num =~ s/^\s*-\s*//g;
1050 $rem_num =~ s/\s*$//;
1051 } else {
1052 $rem_num = $#ldap_host;
1053 }
1054 $count = 0;
1055 @new_ldap_host = ();
1056 @new_ldap_base = ();
1057 @new_ldap_port = ();
1058 @new_ldap_name = ();
1059 @new_ldap_charset = ();
1060 @new_ldap_maxrows = ();
1061 while ($count <= $#ldap_host) {
1062 if ($count != $rem_num) {
1063 @new_ldap_host = (@new_ldap_host, $ldap_host[$count]);
1064 @new_ldap_base = (@new_ldap_base, $ldap_base[$count]);
1065 @new_ldap_port = (@new_ldap_port, $ldap_port[$count]);
1066 @new_ldap_name = (@new_ldap_name, $ldap_name[$count]);
1067 @new_ldap_charset = (@new_ldap_charset, $ldap_charset[$count]);
1068 @new_ldap_maxrows = (@new_ldap_maxrows, $ldap_maxrows[$count]);
1069 }
1070 $count++;
1071 }
1072 @ldap_host = @new_ldap_host;
1073 @ldap_base = @new_ldap_base;
1074 @ldap_port = @new_ldap_port;
1075 @ldap_name = @new_ldap_name;
1076 @ldap_charset = @new_ldap_charset;
1077 @ldap_maxrows = @new_ldap_maxrows;
1078 } elsif ($input =~ /^\s*\?\s*/) {
1079 print ".-------------------------.\n";
1080 print "| + (add host) |\n";
1081 print "| - N (remove host) |\n";
1082 print "| l (list hosts) |\n";
1083 print "| d (done) |\n";
1084 print "`-------------------------'\n";
1085 }
1086 print "[ldap] command (?=help) > ";
1087 $input = <STDIN>;
1088 $input =~ s/[\r|\n]//g;
1089 }
1090 }
1091
1092
1093
1094 sub save_data {
1095 open (FILE, ">config.php");
1096
1097 print FILE "<?\n\t/** SquirrelMail configuration\n";
1098 print FILE "\t ** Created using the configure script, conf.pl\n\t **/\n\n";
1099
1100 print FILE "\t\$org_name = \"$org_name\";\n";
1101 print FILE "\t\$org_logo = \"$org_logo\";\n";
1102 print FILE "\t\$org_title = \"$org_title\";\n";
1103
1104 print FILE "\n";
1105
1106 print FILE "\t\$domain = \"$domain\";\n";
1107 print FILE "\t\$imapServerAddress = \"$imapServerAddress\";\n";
1108 print FILE "\t\$imapPort = $imapPort;\n";
1109 print FILE "\t\$useSendmail = $useSendmail;\n";
1110 print FILE "\t\$smtpServerAddress = \"$smtpServerAddress\";\n";
1111 print FILE "\t\$smtpPort = $smtpPort;\n";
1112 print FILE "\t\$sendmailPath = \"$sendmail_path\";\n";
1113 print FILE "\t\$imap_server_type = \"$imap_server_type\";\n";
1114
1115 print FILE "\n";
1116
1117 print FILE "\t\$default_folder_prefix = \"$default_folder_prefix\";\n";
1118 print FILE "\t\$trash_folder = \"$trash_folder\";\n";
1119 print FILE "\t\$sent_folder = \"$sent_folder\";\n";
1120 print FILE "\t\$default_move_to_trash = $default_move_to_trash;\n";
1121 print FILE "\t\$default_move_to_sent = $default_move_to_sent;\n";
1122 print FILE "\t\$show_prefix_option = $show_prefix_option;\n";
1123 print FILE "\t\$list_special_folders_first = $list_special_folders_first;\n";
1124 print FILE "\t\$use_special_folder_color = $use_special_folder_color;\n";
1125 print FILE "\t\$auto_expunge = $auto_expunge;\n";
1126 print FILE "\t\$default_sub_of_inbox = $default_sub_of_inbox;\n";
1127 print FILE "\t\$show_contain_subfolders_option = $show_contain_subfolders_option;\n";
1128 print FILE "\n";
1129
1130 print FILE "\t\$default_charset = \"$default_charset\";\n";
1131 print FILE "\t\$auto_forward = $auto_forward;\n";
1132 print FILE "\t\$data_dir = \"$data_dir\";\n";
1133 print FILE "\t\$attachment_dir = \"$attachment_dir\";\n";
1134 print FILE "\t\$default_left_size = $default_left_size;\n";
1135
1136 print FILE "\n";
1137
1138 for ($count=0; $count <= $#theme_name; $count++) {
1139 print FILE "\t\$theme[$count][\"PATH\"] = \"$theme_path[$count]\";\n";
1140 print FILE "\t\$theme[$count][\"NAME\"] = \"$theme_name[$count]\";\n";
1141 }
1142
1143 print FILE "\n";
1144
1145 for ($count=0; $count <= $#ldap_host; $count++) {
1146 print FILE "\t\$ldap_server[$count] = Array(\n";
1147 print FILE "\t\t\t\"host\" => \"$ldap_host[$count]\",\n";
1148 print FILE "\t\t\t\"base\" => \"$ldap_base[$count]\"";
1149 if ($ldap_name[$count]) {
1150 print FILE ",\n\t\t\t\"name\" => \"$ldap_name[$count]\"";
1151 }
1152 if ($ldap_port[$count]) {
1153 print FILE ",\n\t\t\t\"port\" => \"$ldap_port[$count]\"";
1154 }
1155 if ($ldap_charset[$count]) {
1156 print FILE ",\n\t\t\t\"charset\" => \"$ldap_charset[$count]\"";
1157 }
1158 if ($ldap_maxrows[$count]) {
1159 print FILE ",\n\t\t\t\"maxrows\" => \"$ldap_maxrows[$count]\"";
1160 }
1161 print FILE ");\n\n";
1162 }
1163
1164 print FILE "\t\$motd = \"$motd\";\n";
1165
1166 print FILE "?>\n";
1167 close FILE;
1168 }
1169
1170 sub set_defaults {
1171 system "clear";
1172 print "While we have been building SquirrelMail, we have discovered some\n";
1173 print "preferences that work better with some servers that don't work so\n";
1174 print "well with others. If you select your IMAP server, this option will\n";
1175 print "set some pre-defined settings for that server.\n";
1176 print "\n";
1177 print "Please note that you will still need to go through and make sure\n";
1178 print "everything is correct. This does not change everything. There are\n";
1179 print "only a few settings that thils will change.\n";
1180 print "\n";
1181
1182 $continue = 0;
1183 while ($continue != 1) {
1184 print "Please select your IMAP server:\n";
1185 print " cyrus = Cyrus IMAP server\n";
1186 print " uw = University of Washington's IMAP server\n";
1187 print " exchange = Microsoft Exchange IMAP server\n";
1188 print " courier = Courier IMAP server\n";
1189 print " quit = Do not change anything\n";
1190 print "Command >> ";
1191 $server = <STDIN>;
1192 $server =~ s/[\r|\n]//g;
1193
1194 if ($server eq "cyrus") {
1195 $default_folder_prefix = "";
1196 $trash_folder = "INBOX.Trash";
1197 $sent_folder = "INBOX.Sent";
1198 $show_prefix_option = false;
1199 $default_sub_of_inbox = true;
1200 $show_contain_subfolders_option = false;
1201 $imap_server_type = "cyrus";
1202
1203 $continue = 1;
1204 } elsif ($server eq "uw") {
1205 $default_folder_prefix = "mail/";
1206 $trash_folder = "Trash";
1207 $sent_folder = "Sent";
1208 $show_prefix_option = true;
1209 $default_sub_of_inbox = false;
1210 $show_contain_subfolders_option = true;
1211 $imap_server_type = "uw";
1212
1213 $continue = 1;
1214 } elsif ($server eq "exchange") {
1215 $default_folder_prefix = "INBOX/";
1216 $default_sub_of_inbox = true;
1217 $trash_folder = "INBOX/Deleted Items";
1218 $sent_folder = "INBOX/Sent Items";
1219 $show_prefix_option = false;
1220 $show_contain_subfolders_option = false;
1221
1222 $imap_server_type = "exchange";
1223
1224 $continue = 1;
1225 } elsif ($server eq "courier") {
1226 $imap_server_type = "courier";
1227
1228 $continue = 1;
1229 } elsif ($server eq "quit") {
1230 $continue = 1;
1231 } else {
1232 print "Unrecognized server: $server\n";
1233 print "\n";
1234 }
1235 }
1236 }