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