Quick adjustment to conf.pl adding option for PHP session name.
[squirrelmail.git] / config / conf.pl
1 #!/usr/bin/env perl
2 # conf.pl
3 # Luke Ehresman (luke@squirrelmail.org)
4 #
5 # A simple configure script to configure squirrelmail
6 #
7 # $Id$
8 ############################################################
9 $conf_pl_version = "1.2.0";
10
11 ############################################################
12 # Check what directory we're supposed to be running in, and
13 # change there if necessary. File::Basename has been in
14 # Perl since at least 5.003_7, and nobody sane runs anything
15 # before that, but just in case.
16 ############################################################
17 my $dir;
18 if ( eval q{require "File/Basename.pm"} ) {
19 $dir = File::Basename::dirname($0);
20 chdir($dir);
21 }
22
23 ############################################################
24 # Some people try to run this as a CGI. That's wrong!
25 ############################################################
26 if ( defined( $ENV{'PATH_INFO'} )
27 || defined( $ENV{'QUERY_STRING'} )
28 || defined( $ENV{'REQUEST_METHOD'} ) ) {
29 print "Content-Type: text/html\n\n";
30 print "You must run this script from the command line.";
31 exit;
32 }
33
34 ############################################################
35 # If we got here, use Cwd to get the full directory path
36 # (the Basename stuff above will sometimes return '.' as
37 # the base directory, which is not helpful here).
38 ############################################################
39 use Cwd;
40 $dir = cwd();
41
42 ############################################################
43 # First, lets read in the data already in there...
44 ############################################################
45 if ( -e "config.php" ) {
46 open( FILE, "config.php" );
47 while ( $line = <FILE> ) {
48 $line =~ s/^\s+//;
49 $line =~ s/^\$//;
50 $var = $line;
51
52 $var =~ s/=/EQUALS/;
53 if ( $var =~ /^([a-z]|[A-Z])/ ) {
54 @o = split ( /\s*EQUALS\s*/, $var );
55 if ( $o[0] eq "config_version" ) {
56 $o[1] =~ s/[\n|\r]//g;
57 $o[1] =~ s/[\'|\"];\s*$//;
58 $o[1] =~ s/;$//;
59 $o[1] =~ s/^[\'|\"]//;
60
61 $config_version = $o[1];
62 close(FILE);
63 }
64 }
65 }
66 close(FILE);
67
68 if ( $config_version ne $conf_pl_version ) {
69 system "clear";
70 print $WHT. "WARNING:\n" . $NRM;
71 print " The file \"config/config.php\" was found, but it is for\n";
72 print " an older version of SquirrelMail. It is possible to still\n";
73 print " read the defaults from this file but be warned that many\n";
74 print " preferences change between versions. It is recommended that\n";
75 print " you start with a clean config.php for each upgrade that you\n";
76 print " do. To do this, just move config/config.php out of the way.\n";
77 print "\n";
78 print "Continue loading with the old config.php [y/N]? ";
79 $ctu = <STDIN>;
80
81 if ( ( $ctu !~ /^y\n/i ) || ( $ctu =~ /^\n/ ) ) {
82 exit;
83 }
84
85 print "\nDo you want me to stop warning you [y/N]? ";
86 $ctu = <STDIN>;
87 if ( $ctu =~ /^y\n/i ) {
88 $print_config_version = $conf_pl_version;
89 } else {
90 $print_config_version = $config_version;
91 }
92 } else {
93 $print_config_version = $config_version;
94 }
95
96 $config = 1;
97 open( FILE, "config.php" );
98 } elsif ( -e "config_default.php" ) {
99 open( FILE, "config_default.php" );
100 while ( $line = <FILE> ) {
101 $line =~ s/^\s+//;
102 $line =~ s/^\$//;
103 $var = $line;
104
105 $var =~ s/=/EQUALS/;
106 if ( $var =~ /^([a-z]|[A-Z])/ ) {
107 @o = split ( /\s*EQUALS\s*/, $var );
108 if ( $o[0] eq "config_version" ) {
109 $o[1] =~ s/[\n|\r]//g;
110 $o[1] =~ s/[\'|\"];\s*$//;
111 $o[1] =~ s/;$//;
112 $o[1] =~ s/^[\'|\"]//;
113
114 $config_version = $o[1];
115 close(FILE);
116 }
117 }
118 }
119 close(FILE);
120
121 if ( $config_version ne $conf_pl_version ) {
122 system "clear";
123 print $WHT. "WARNING:\n" . $NRM;
124 print " You are trying to use a 'config_default.php' from an older\n";
125 print " version of SquirrelMail. This is HIGHLY unrecommended. You\n";
126 print " should get the 'config_default.php' that matches the version\n";
127 print " of SquirrelMail that you are running. You can get this from\n";
128 print " the SquirrelMail web page by going to the following URL:\n";
129 print " http://www.squirrelmail.org.\n";
130 print "\n";
131 print "Continue loading with old config_default.php (a bad idea) [y/N]? ";
132 $ctu = <STDIN>;
133
134 if ( ( $ctu !~ /^y\n/i ) || ( $ctu =~ /^\n/ ) ) {
135 exit;
136 }
137
138 print "\nDo you want me to stop warning you [y/N]? ";
139 $ctu = <STDIN>;
140 if ( $ctu =~ /^y\n/i ) {
141 $print_config_version = $conf_pl_version;
142 } else {
143 $print_config_version = $config_version;
144 }
145 } else {
146 $print_config_version = $config_version;
147 }
148 $config = 2;
149 open( FILE, "config_default.php" );
150 } else {
151 print "No configuration file found. Please get config_default.php\n";
152 print "or config.php before running this again. This program needs\n";
153 print "a default config file to get default values.\n";
154 exit;
155 }
156
157 # Read and parse the current configuration file
158 # (either config.php or config_default.php).
159 while ( $line = <FILE> ) {
160 $line =~ s/^\s+//;
161 $line =~ s/^\$//;
162 $var = $line;
163
164 $var =~ s/=/EQUALS/;
165 if ( $var =~ /^([a-z]|[A-Z])/ ) {
166 @options = split ( /\s*EQUALS\s*/, $var );
167 $options[1] =~ s/[\n|\r]//g;
168 $options[1] =~ s/[\'|\"];\s*$//;
169 $options[1] =~ s/;$//;
170 $options[1] =~ s/^[\'|\"]//;
171
172 if ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]PATH['|"]\]/ ) {
173 $sub = $options[0];
174 $sub =~ s/\]\[['|"]PATH['|"]\]//;
175 $sub =~ s/.*\[//;
176 if ( -e "../themes" ) {
177 $options[1] =~ s/^\.\.\/config/\.\.\/themes/;
178 }
179 $theme_path[$sub] = &change_to_rel_path($options[1]);
180 } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]NAME['|"]\]/ ) {
181 $sub = $options[0];
182 $sub =~ s/\]\[['|"]NAME['|"]\]//;
183 $sub =~ s/.*\[//;
184 $theme_name[$sub] = $options[1];
185 } elsif ( $options[0] =~ /^plugins\[[0-9]+\]/ ) {
186 $sub = $options[0];
187 $sub =~ s/\]//;
188 $sub =~ s/^plugins\[//;
189 $plugins[$sub] = $options[1];
190 } elsif ( $options[0] =~ /^ldap_server\[[0-9]+\]/ ) {
191 $sub = $options[0];
192 $sub =~ s/\]//;
193 $sub =~ s/^ldap_server\[//;
194 $continue = 0;
195 while ( ( $tmp = <FILE> ) && ( $continue != 1 ) ) {
196 if ( $tmp =~ /\);\s*$/ ) {
197 $continue = 1;
198 }
199
200 if ( $tmp =~ /^\s*[\'|\"]host[\'|\"]/i ) {
201 $tmp =~ s/^\s*[\'|\"]host[\'|\"]\s*=>\s*[\'|\"]//i;
202 $tmp =~ s/[\'|\"],?\s*$//;
203 $tmp =~ s/[\'|\"]\);\s*$//;
204 $host = $tmp;
205 } elsif ( $tmp =~ /^\s*[\'|\"]base[\'|\"]/i ) {
206 $tmp =~ s/^\s*[\'|\"]base[\'|\"]\s*=>\s*[\'|\"]//i;
207 $tmp =~ s/[\'|\"],?\s*$//;
208 $tmp =~ s/[\'|\"]\);\s*$//;
209 $base = $tmp;
210 } elsif ( $tmp =~ /^\s*[\'|\"]charset[\'|\"]/i ) {
211 $tmp =~ s/^\s*[\'|\"]charset[\'|\"]\s*=>\s*[\'|\"]//i;
212 $tmp =~ s/[\'|\"],?\s*$//;
213 $tmp =~ s/[\'|\"]\);\s*$//;
214 $charset = $tmp;
215 } elsif ( $tmp =~ /^\s*[\'|\"]port[\'|\"]/i ) {
216 $tmp =~ s/^\s*[\'|\"]port[\'|\"]\s*=>\s*[\'|\"]?//i;
217 $tmp =~ s/[\'|\"]?,?\s*$//;
218 $tmp =~ s/[\'|\"]?\);\s*$//;
219 $port = $tmp;
220 } elsif ( $tmp =~ /^\s*[\'|\"]maxrows[\'|\"]/i ) {
221 $tmp =~ s/^\s*[\'|\"]maxrows[\'|\"]\s*=>\s*[\'|\"]?//i;
222 $tmp =~ s/[\'|\"]?,?\s*$//;
223 $tmp =~ s/[\'|\"]?\);\s*$//;
224 $maxrows = $tmp;
225 } elsif ( $tmp =~ /^\s*[\'|\"]name[\'|\"]/i ) {
226 $tmp =~ s/^\s*[\'|\"]name[\'|\"]\s*=>\s*[\'|\"]//i;
227 $tmp =~ s/[\'|\"],?\s*$//;
228 $tmp =~ s/[\'|\"]\);\s*$//;
229 $name = $tmp;
230 }
231 }
232 $ldap_host[$sub] = $host;
233 $ldap_base[$sub] = $base;
234 $ldap_name[$sub] = $name;
235 $ldap_port[$sub] = $port;
236 $ldap_maxrows[$sub] = $maxrows;
237 $ldap_charset[$sub] = $charset;
238 } elsif ( $options[0] =~ /^(data_dir|attachment_dir|theme_css|org_logo|signout_page)$/ ) {
239 ${ $options[0] } = &change_to_rel_path($options[1]);
240 } else {
241 ${ $options[0] } = $options[1];
242 }
243 }
244 }
245 close FILE;
246 if ( $useSendmail ne "true" ) {
247 $useSendmail = "false";
248 }
249 if ( !$sendmail_path ) {
250 $sendmail_path = "/usr/sbin/sendmail";
251 }
252 if ( !$pop_before_smtp ) {
253 $pop_before_smtp = "false";
254 }
255 if ( !$default_unseen_notify ) {
256 $default_unseen_notify = 2;
257 }
258 if ( !$default_unseen_type ) {
259 $default_unseen_type = 1;
260 }
261 if ( !$config_use_color ) {
262 $config_use_color = 0;
263 }
264 if ( !$invert_time ) {
265 $invert_time = "false";
266 }
267 if ( !$force_username_lowercase ) {
268 $force_username_lowercase = "false";
269 }
270 if ( !$optional_delimiter ) {
271 $optional_delimiter = "detect";
272 }
273 if ( !$auto_create_special ) {
274 $auto_create_special = "false";
275 }
276 if ( !$default_use_priority ) {
277 $default_use_priority = "true";
278 }
279 if ( !$hide_sm_attributions ) {
280 $hide_sm_attributions = "false";
281 }
282 if ( !$default_use_mdn ) {
283 $default_use_mdn = "true";
284 }
285 if ( !$delete_folder ) {
286 $delete_folder = "false";
287 }
288 if ( !$noselect_fix_enable ) {
289 $noselect_fix_enable = "false";
290 }
291 if ( !$frame_top ) {
292 $frame_top = "_top";
293 }
294
295 if ( !$provider_uri ) {
296 $provider_uri = "http://www.squirrelmail.org/";
297 }
298
299 if ( !$provider_name ) {
300 $provider_name = "SquirrelMail";
301 }
302
303 if ( !$edit_identity ) {
304 $edit_identity = "true";
305 }
306 if ( !$edit_name ) {
307 $edit_name = "true";
308 }
309 if ( !$allow_thread_sort ) {
310 $allow_thread_sort = 'false';
311 }
312 if ( !$allow_server_sort ) {
313 $allow_server_sort = 'false';
314 }
315 if ( !$uid_support ) {
316 $uid_support = 'true';
317 }
318 if ( !$no_list_for_subscribe ) {
319 $no_list_for_subscribe = 'false';
320 }
321 if ( !$allow_charset_search ) {
322 $allow_charset_search = 'true';
323 }
324 if ( !$prefs_user_field ) {
325 $prefs_user_field = 'user';
326 }
327 if ( !$prefs_key_field ) {
328 $prefs_key_field = 'prefkey';
329 }
330 if ( !$prefs_val_field ) {
331 $prefs_val_field = 'prefval';
332 }
333
334 if ( !$use_smtp_tls) {
335 $use_smtp_tls= 'false';
336 }
337
338 if ( !$smtp_auth_mech ) {
339 $smtp_auth_mech = 'none';
340 }
341
342 if ( !$use_imap_tls ) {
343 $use_imap_tls = 'false';
344 }
345
346 if ( !$imap_auth_mech ) {
347 $imap_auth_mech = 'plain';
348 }
349
350 if (!$session_name ) {
351 $session_name = 'SQMSESSID';
352 }
353
354 if ( $ARGV[0] eq '--install-plugin' ) {
355 print "Activating plugin " . $ARGV[1] . "\n";
356 push @plugins, $ARGV[1];
357 save_data();
358 exit(0);
359 } elsif ( $ARGV[0] eq '--remove-plugin' ) {
360 print "Removing plugin " . $ARGV[1] . "\n";
361 foreach $plugin (@plugins) {
362 if ( $plugin ne $ARGV[1] ) {
363 push @newplugins, $plugin;
364 }
365 }
366 @plugins = @newplugins;
367 save_data();
368 exit(0);
369 }
370
371 #####################################################################################
372 if ( $config_use_color == 1 ) {
373 $WHT = "\x1B[37;1m";
374 $NRM = "\x1B[0m";
375 } else {
376 $WHT = "";
377 $NRM = "";
378 $config_use_color = 2;
379 }
380
381 while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
382 system "clear";
383 print $WHT. "SquirrelMail Configuration : " . $NRM;
384 if ( $config == 1 ) { print "Read: config.php"; }
385 elsif ( $config == 2 ) { print "Read: config_default.php"; }
386 print " ($print_config_version)\n";
387 print "---------------------------------------------------------\n";
388
389 if ( $menu == 0 ) {
390 print $WHT. "Main Menu --\n" . $NRM;
391 print "1. Organization Preferences\n";
392 print "2. Server Settings\n";
393 print "3. Folder Defaults\n";
394 print "4. General Options\n";
395 print "5. Themes\n";
396 print "6. Address Books (LDAP)\n";
397 print "7. Message of the Day (MOTD)\n";
398 print "8. Plugins\n";
399 print "9. Database\n";
400 print "\n";
401 print "D. Set pre-defined settings for specific IMAP servers\n";
402 print "\n";
403 } elsif ( $menu == 1 ) {
404 print $WHT. "Organization Preferences\n" . $NRM;
405 print "1. Organization Name : $WHT$org_name$NRM\n";
406 print "2. Organization Logo : $WHT$org_logo$NRM\n";
407 print "3. Org. Logo Width/Height : $WHT($org_logo_width/$org_logo_height)$NRM\n";
408 print "4. Organization Title : $WHT$org_title$NRM\n";
409 print "5. Signout Page : $WHT$signout_page$NRM\n";
410 print "6. Default Language : $WHT$squirrelmail_default_language$NRM\n";
411 print "7. Top Frame : $WHT$frame_top$NRM\n";
412 print "8. Provider link : $WHT$provider_uri$NRM\n";
413 print "9. Provider name : $WHT$provider_name$NRM\n";
414
415 print "\n";
416 print "R Return to Main Menu\n";
417 } elsif ( $menu == 2 ) {
418 print $WHT. "Server Settings\n\n" . $NRM;
419 print $WHT . "General" . $NRM . "\n";
420 print "-------\n";
421 print "1. Domain : $WHT$domain$NRM\n";
422 print "2. Invert Time : $WHT$invert_time$NRM\n";
423 print "3. Sendmail or SMTP : $WHT";
424 if ( lc($useSendmail) eq "true" ) {
425 print "Sendmail";
426 } else {
427 print "SMTP";
428 }
429 print "$NRM\n";
430 print "\n";
431
432 if ( $show_imap_settings ) {
433 print $WHT . "IMAP Settings". $NRM . "\n--------------\n";
434 print "4. IMAP Server : $WHT$imapServerAddress$NRM\n";
435 print "5. IMAP Port : $WHT$imapPort$NRM\n";
436 print "6. Authentication type : $WHT$imap_auth_mech$NRM\n";
437 print "7. Secure IMAP (TLS) : $WHT$use_imap_tls$NRM\n";
438 print "8. Server software : $WHT$imap_server_type$NRM\n";
439 print "9. Delimiter : $WHT$optional_delimiter$NRM\n";
440 print "\n";
441 } elsif ( $show_smtp_settings ) {
442 if ( lc($useSendmail) eq "true" ) {
443 print $WHT . "Sendmail" . $NRM . "\n--------\n";
444 print "4. Sendmail Path : $WHT$sendmail_path$NRM\n";
445 print "\n";
446 } else {
447 print $WHT . "SMTP Settings" . $NRM . "\n-------------\n";
448 print "4. SMTP Server : $WHT$smtpServerAddress$NRM\n";
449 print "5. SMTP Port : $WHT$smtpPort$NRM\n";
450 print "6. POP before SMTP : $WHT$pop_before_smtp$NRM\n";
451 print "7. SMTP Authentication : $WHT$smtp_auth_mech$NRM\n";
452 print "8. Secure SMTP (TLS) : $WHT$use_smtp_tls$NRM\n";
453 print "\n";
454 }
455 }
456
457 if ($show_imap_settings == 0) {
458 print "A. Update IMAP Settings : ";
459 print "$WHT$imapServerAddress$NRM:";
460 print "$WHT$imapPort$NRM ";
461 print "($WHT$imap_server_type$NRM)\n";
462 }
463 if ($show_smtp_settings == 0) {
464 if ( lc($useSendmail) eq "true" ) {
465 print "B. Change Sendmail Config : $WHT$sendmail_path$NRM\n";
466 } else {
467 print "B. Update SMTP Settings : ";
468 print "$WHT$smtpServerAddress$NRM:";
469 print "$WHT$smtpPort$NRM\n";
470 }
471 }
472 if ( $show_smtp_settings || $show_imap_settings )
473 {
474 print "H. Hide " .
475 ($show_imap_settings ? "IMAP Server" :
476 (lc($useSendmail) eq "true") ? "Sendmail" : "SMTP") . " Settings\n";
477 }
478
479 print "\n";
480 print "R Return to Main Menu\n";
481 } elsif ( $menu == 3 ) {
482 print $WHT. "Folder Defaults\n" . $NRM;
483 print "1. Default Folder Prefix : $WHT$default_folder_prefix$NRM\n";
484 print "2. Show Folder Prefix Option : $WHT$show_prefix_option$NRM\n";
485 print "3. Trash Folder : $WHT$trash_folder$NRM\n";
486 print "4. Sent Folder : $WHT$sent_folder$NRM\n";
487 print "5. Drafts Folder : $WHT$draft_folder$NRM\n";
488 print "6. By default, move to trash : $WHT$default_move_to_trash$NRM\n";
489 print "7. By default, move to sent : $WHT$default_move_to_sent$NRM\n";
490 print "8. By default, save as draft : $WHT$default_save_as_draft$NRM\n";
491 print "9. List Special Folders First : $WHT$list_special_folders_first$NRM\n";
492 print "10. Show Special Folders Color : $WHT$use_special_folder_color$NRM\n";
493 print "11. Auto Expunge : $WHT$auto_expunge$NRM\n";
494 print "12. Default Sub. of INBOX : $WHT$default_sub_of_inbox$NRM\n";
495 print "13. Show 'Contain Sub.' Option : $WHT$show_contain_subfolders_option$NRM\n";
496 print "14. Default Unseen Notify : $WHT$default_unseen_notify$NRM\n";
497 print "15. Default Unseen Type : $WHT$default_unseen_type$NRM\n";
498 print "16. Auto Create Special Folders : $WHT$auto_create_special$NRM\n";
499 print "17. Don't move folders into Trash : $WHT$delete_folder$NRM\n";
500 print "18. Enable /NoSelect folder fix : $WHT$noselect_fix_enable$NRM\n";
501 print "\n";
502 print "R Return to Main Menu\n";
503 } elsif ( $menu == 4 ) {
504 print $WHT. "General Options\n" . $NRM;
505 print "1. Default Charset : $WHT$default_charset$NRM\n";
506 print "2. Data Directory : $WHT$data_dir$NRM\n";
507 print "3. Attachment Directory : $WHT$attachment_dir$NRM\n";
508 print "4. Directory Hash Level : $WHT$dir_hash_level$NRM\n";
509 print "5. Default Left Size : $WHT$default_left_size$NRM\n";
510 print "6. Usernames in Lowercase : $WHT$force_username_lowercase$NRM\n";
511 print "7. Allow use of priority : $WHT$default_use_priority$NRM\n";
512 print "8. Hide SM attributions : $WHT$hide_sm_attributions$NRM\n";
513 print "9. Allow use of receipts : $WHT$default_use_mdn$NRM\n";
514 print "10. Allow editing of identity : $WHT$edit_identity$NRM\n";
515 print "11. Allow server thread sort : $WHT$allow_thread_sort$NRM\n";
516 print "12. Allow server-side sorting : $WHT$allow_server_sort$NRM\n";
517 if ( lc($edit_identity) eq "false" ) {
518 print "13. Allow editing of name : $WHT$edit_name$NRM\n";
519 }
520 print "14. Allow server charset search : $WHT$allow_charset_search$NRM\n";
521 print "15. Enable UID support : $WHT$uid_support$NRM\n";
522 print "16. PHP session name : $WHT$session_name$NRM\n";
523 print "\n";
524 print "R Return to Main Menu\n";
525 } elsif ( $menu == 5 ) {
526 print $WHT. "Themes\n" . $NRM;
527 print "1. Change Themes\n";
528 for ( $count = 0 ; $count <= $#theme_name ; $count++ ) {
529 print " > $theme_name[$count]\n";
530 }
531 print "2. CSS File : $WHT$theme_css$NRM\n";
532 print "\n";
533 print "R Return to Main Menu\n";
534 } elsif ( $menu == 6 ) {
535 print $WHT. "Address Books (LDAP)\n" . $NRM;
536 print "1. Change Servers\n";
537 for ( $count = 0 ; $count <= $#ldap_host ; $count++ ) {
538 print " > $ldap_host[$count]\n";
539 }
540 print
541 "2. Use Javascript Address Book Search : $WHT$default_use_javascript_addr_book$NRM\n";
542 print "\n";
543 print "R Return to Main Menu\n";
544 } elsif ( $menu == 7 ) {
545 print $WHT. "Message of the Day (MOTD)\n" . $NRM;
546 print "\n$motd\n";
547 print "\n";
548 print "1 Edit the MOTD\n";
549 print "\n";
550 print "R Return to Main Menu\n";
551 } elsif ( $menu == 8 ) {
552 print $WHT. "Plugins\n" . $NRM;
553 print " Installed Plugins\n";
554 $num = 0;
555 for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
556 $num = $count + 1;
557 print " $num. $plugins[$count]\n";
558 }
559 print "\n Available Plugins:\n";
560 opendir( DIR, "../plugins" );
561 @files = readdir(DIR);
562 $pos = 0;
563 @unused_plugins = ();
564 for ( $i = 0 ; $i <= $#files ; $i++ ) {
565 if ( -d "../plugins/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) {
566 $match = 0;
567 for ( $k = 0 ; $k <= $#plugins ; $k++ ) {
568 if ( $plugins[$k] eq $files[$i] ) {
569 $match = 1;
570 }
571 }
572 if ( $match == 0 ) {
573 $unused_plugins[$pos] = $files[$i];
574 $pos++;
575 }
576 }
577 }
578
579 for ( $i = 0 ; $i <= $#unused_plugins ; $i++ ) {
580 $num = $num + 1;
581 print " $num. $unused_plugins[$i]\n";
582 }
583 closedir DIR;
584
585 print "\n";
586 print "R Return to Main Menu\n";
587 } elsif ( $menu == 9 ) {
588 print $WHT. "Database\n" . $NRM;
589 print "1. DSN for Address Book : $WHT$addrbook_dsn$NRM\n";
590 print "2. Table for Address Book : $WHT$addrbook_table$NRM\n";
591 print "\n";
592 print "3. DSN for Preferences : $WHT$prefs_dsn$NRM\n";
593 print "4. Table for Preferences : $WHT$prefs_table$NRM\n";
594 print "5. Field for username : $WHT$prefs_user_field$NRM\n";
595 print "6. Field for prefs key : $WHT$prefs_key_field$NRM\n";
596 print "7. Field for prefs value : $WHT$prefs_val_field$NRM\n";
597 print "\n";
598 print "R Return to Main Menu\n";
599 }
600 if ( $config_use_color == 1 ) {
601 print "C. Turn color off\n";
602 } else {
603 print "C. Turn color on\n";
604 }
605 print "S Save data\n";
606 print "Q Quit\n";
607
608 print "\n";
609 print "Command >> " . $WHT;
610 $command = <STDIN>;
611 $command =~ s/[\n|\r]//g;
612 $command =~ tr/A-Z/a-z/;
613 print "$NRM\n";
614
615 # Read the commands they entered.
616 if ( $command eq "r" ) {
617 $menu = 0;
618 } elsif ( $command eq "s" ) {
619 save_data();
620 print "Press enter to continue...";
621 $tmp = <STDIN>;
622 $saved = 1;
623 } elsif ( ( $command eq "q" ) && ( $saved == 0 ) ) {
624 print "You have not saved your data.\n";
625 print "Save? [" . $WHT . "Y" . $NRM . "/n]: ";
626 $save = <STDIN>;
627 if ( ( $save =~ /^y/i ) || ( $save =~ /^\s*$/ ) ) {
628 save_data();
629 }
630 } elsif ( $command eq "c" ) {
631 if ( $config_use_color == 1 ) {
632 $config_use_color = 2;
633 $WHT = "";
634 $NRM = "";
635 } else {
636 $config_use_color = 1;
637 $WHT = "\x1B[37;1m";
638 $NRM = "\x1B[0m";
639 }
640 } elsif ( $command eq "d" && $menu == 0 ) {
641 set_defaults();
642 } else {
643 $saved = 0;
644 if ( $menu == 0 ) {
645 if ( ( $command > 0 ) && ( $command < 10 ) ) {
646 $menu = $command;
647 }
648 } elsif ( $menu == 1 ) {
649 if ( $command == 1 ) { $org_name = command1(); }
650 elsif ( $command == 2 ) { $org_logo = command2(); }
651 elsif ( $command == 3 ) { ($org_logo_width,$org_logo_height) = command2a(); }
652 elsif ( $command == 4 ) { $org_title = command3(); }
653 elsif ( $command == 5 ) { $signout_page = command4(); }
654 elsif ( $command == 6 ) { $squirrelmail_default_language = command5(); }
655 elsif ( $command == 7 ) { $frame_top = command6(); }
656 elsif ( $command == 8 ) { $provider_uri = command7(); }
657 elsif ( $command == 9 ) { $provider_name = command8(); }
658
659 } elsif ( $menu == 2 ) {
660 if ( $command eq "a" ) { $show_imap_settings = 1; $show_smtp_settings = 0; }
661 elsif ( $command eq "b" ) { $show_imap_settings = 0; $show_smtp_settings = 1; }
662 elsif ( $command eq "h" ) { $show_imap_settings = 0; $show_smtp_settings = 0; }
663 elsif ( $command <= 3 ) {
664 if ( $command == 1 ) { $domain = command11(); }
665 elsif ( $command == 2 ) { $invert_time = command110(); }
666 elsif ( $command == 3 ) { $useSendmail = command14(); }
667 $show_imap_settings = 0; $show_smtp_settings = 0;
668 } elsif ( $show_imap_settings ) {
669 if ( $command == 4 ) { $imapServerAddress = command12(); }
670 elsif ( $command == 5 ) { $imapPort = command13(); }
671 elsif ( $command == 6 ) { $imap_auth_mech = command112a(); }
672 elsif ( $command == 7 ) { $use_imap_tls = command113("IMAP",$use_imap_tls); }
673 elsif ( $command == 8 ) { $imap_server_type = command19(); }
674 elsif ( $command == 9 ) { $optional_delimiter = command111(); }
675 } elsif ( $show_smtp_settings && lc($useSendmail) eq "true" ) {
676 if ( $command == 4 ) { $sendmail_path = command15(); }
677 } elsif ( $show_smtp_settings ) {
678 if ( $command == 4 ) { $smtpServerAddress = command16(); }
679 elsif ( $command == 5 ) { $smtpPort = command17(); }
680 elsif ( $command == 6 ) { $pop_before_smtp = command18a(); }
681 elsif ( $command == 7 ) { $smtp_auth_mech = command112b(); }
682 elsif ( $command == 8 ) { $use_smtp_tls = command113("SMTP",$use_smtp_tls); }
683 }
684 } elsif ( $menu == 3 ) {
685 if ( $command == 1 ) { $default_folder_prefix = command21(); }
686 elsif ( $command == 2 ) { $show_prefix_option = command22(); }
687 elsif ( $command == 3 ) { $trash_folder = command23a(); }
688 elsif ( $command == 4 ) { $sent_folder = command23b(); }
689 elsif ( $command == 5 ) { $draft_folder = command23c(); }
690 elsif ( $command == 6 ) { $default_move_to_trash = command24a(); }
691 elsif ( $command == 7 ) { $default_move_to_sent = command24b(); }
692 elsif ( $command == 8 ) { $default_save_as_draft = command24c(); }
693 elsif ( $command == 9 ) { $list_special_folders_first = command27(); }
694 elsif ( $command == 10 ) { $use_special_folder_color = command28(); }
695 elsif ( $command == 11 ) { $auto_expunge = command29(); }
696 elsif ( $command == 12 ) { $default_sub_of_inbox = command210(); }
697 elsif ( $command == 13 ) { $show_contain_subfolders_option = command211(); }
698 elsif ( $command == 14 ) { $default_unseen_notify = command212(); }
699 elsif ( $command == 15 ) { $default_unseen_type = command213(); }
700 elsif ( $command == 16 ) { $auto_create_special = command214(); }
701 elsif ( $command == 17 ) { $delete_folder = command215(); }
702 elsif ( $command == 18 ) { $noselect_fix_enable = command216(); }
703 } elsif ( $menu == 4 ) {
704 if ( $command == 1 ) { $default_charset = command31(); }
705 elsif ( $command == 2 ) { $data_dir = command33a(); }
706 elsif ( $command == 3 ) { $attachment_dir = command33b(); }
707 elsif ( $command == 4 ) { $dir_hash_level = command33c(); }
708 elsif ( $command == 5 ) { $default_left_size = command35(); }
709 elsif ( $command == 6 ) { $force_username_lowercase = command36(); }
710 elsif ( $command == 7 ) { $default_use_priority = command37(); }
711 elsif ( $command == 8 ) { $hide_sm_attributions = command38(); }
712 elsif ( $command == 9 ) { $default_use_mdn = command39(); }
713 elsif ( $command == 10 ) { $edit_identity = command310(); }
714 elsif ( $command == 11 ) { $allow_thread_sort = command312(); }
715 elsif ( $command == 12 ) { $allow_server_sort = command313(); }
716 elsif ( $command == 13 ) { $edit_name = command311(); }
717 elsif ( $command == 14 ) { $allow_charset_search = command314(); }
718 elsif ( $command == 15 ) { $uid_support = command315(); }
719 elsif ( $command == 16 ) { $session_name = command316(); }
720 } elsif ( $menu == 5 ) {
721 if ( $command == 1 ) { command41(); }
722 elsif ( $command == 2 ) { $theme_css = command42(); }
723 } elsif ( $menu == 6 ) {
724 if ( $command == 1 ) { command61(); }
725 elsif ( $command == 2 ) { command62(); }
726 } elsif ( $menu == 7 ) {
727 if ( $command == 1 ) { $motd = command71(); }
728 } elsif ( $menu == 8 ) {
729 if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
730 } elsif ( $menu == 9 ) {
731 if ( $command == 1 ) { $addrbook_dsn = command91(); }
732 elsif ( $command == 2 ) { $addrbook_table = command92(); }
733 elsif ( $command == 3 ) { $prefs_dsn = command93(); }
734 elsif ( $command == 4 ) { $prefs_table = command94(); }
735 elsif ( $command == 5 ) { $prefs_user_field = command95(); }
736 elsif ( $command == 6 ) { $prefs_key_field = command96(); }
737 elsif ( $command == 7 ) { $prefs_val_field = command97(); }
738 }
739 }
740 }
741
742 ####################################################################################
743
744 # org_name
745 sub command1 {
746 print "We have tried to make the name SquirrelMail as transparent as\n";
747 print "possible. If you set up an organization name, most places where\n";
748 print "SquirrelMail would take credit will be credited to your organization.\n";
749 print "\n";
750 print "[$WHT$org_name$NRM]: $WHT";
751 $new_org_name = <STDIN>;
752 if ( $new_org_name eq "\n" ) {
753 $new_org_name = $org_name;
754 } else {
755 $new_org_name =~ s/[\r|\n]//g;
756 $new_org_name =~ s/\"/&quot;/g;
757 }
758 return $new_org_name;
759 }
760
761 # org_logo
762 sub command2 {
763 print "Your organization's logo is an image that will be displayed at\n";
764 print "different times throughout SquirrelMail. This is asking for the\n";
765 print "literal (/usr/local/squirrelmail/images/logo.png) or relative\n";
766 print "(../images/logo.png) path to your logo.\n";
767 print "Relative paths to files outside the SquirrelMail distribution\n";
768 print "will be converted to their absolute path equivalents in config.php.\n";
769 print "\n";
770 print "[$WHT$org_logo$NRM]: $WHT";
771 $new_org_logo = <STDIN>;
772 if ( $new_org_logo eq "\n" ) {
773 $new_org_logo = $org_logo;
774 } else {
775 $new_org_logo =~ s/[\r|\n]//g;
776 }
777 return $new_org_logo;
778 }
779
780 # org_logo_width
781 sub command2a {
782 print "Your organization's logo is an image that will be displayed at\n";
783 print "different times throughout SquirrelMail. Width\n";
784 print "and Height of your logo image. Use '0' to disable.\n";
785 print "\n";
786 print "Width: [$WHT$org_logo_width$NRM]: $WHT";
787 $new_org_logo_width = <STDIN>;
788 $new_org_logo_width =~ tr/0-9//cd; # only want digits!
789 if ( $new_org_logo_width eq '' ) {
790 $new_org_logo_width = $org_logo_width;
791 }
792 if ( $new_org_logo_width > 0 ) {
793 print "Height: [$WHT$org_logo_height$NRM]: $WHT";
794 $new_org_logo_height = <STDIN>;
795 $new_org_logo_height =~ tr/0-9//cd; # only want digits!
796 if( $new_org_logo_height eq '' ) {
797 $new_org_logo_height = $org_logo_height;
798 }
799 } else {
800 $new_org_logo_height = 0;
801 }
802 return ($new_org_logo_width, $new_org_logo_height);
803 }
804
805 # org_title
806 sub command3 {
807 print "A title is what is displayed at the top of the browser window in\n";
808 print "the titlebar. Usually this will end up looking something like:\n";
809 print "\"Netscape: $org_title\"\n";
810 print "\n";
811 print "[$WHT$org_title$NRM]: $WHT";
812 $new_org_title = <STDIN>;
813 if ( $new_org_title eq "\n" ) {
814 $new_org_title = $org_title;
815 } else {
816 $new_org_title =~ s/[\r|\n]//g;
817 $new_org_title =~ s/\"/\'/g;
818 }
819 return $new_org_title;
820 }
821
822 # signout_page
823 sub command4 {
824 print "When users click the Sign Out button they will be logged out and\n";
825 print "then sent to signout_page. If signout_page is left empty,\n";
826 print "(hit space and then return) they will be taken, as normal,\n";
827 print "to the default and rather sparse SquirrelMail signout page.\n";
828 print "\n";
829 print "[$WHT$signout_page$NRM]: $WHT";
830 $new_signout_page = <STDIN>;
831 if ( $new_signout_page eq "\n" ) {
832 $new_signout_page = $signout_page;
833 } else {
834 $new_signout_page =~ s/[\r|\n]//g;
835 $new_signout_page =~ s/^\s+$//g;
836 }
837 return $new_signout_page;
838 }
839
840 # Default language
841 sub command5 {
842 print "SquirrelMail attempts to set the language in many ways. If it\n";
843 print "can not figure it out in another way, it will default to this\n";
844 print "language. Please use the code for the desired language.\n";
845 print "\n";
846 print "[$WHT$squirrelmail_default_language$NRM]: $WHT";
847 $new_signout_page = <STDIN>;
848 if ( $new_signout_page eq "\n" ) {
849 $new_signout_page = $squirrelmail_default_language;
850 } else {
851 $new_signout_page =~ s/[\r|\n]//g;
852 $new_signout_page =~ s/^\s+$//g;
853 }
854 return $new_signout_page;
855 }
856
857 # Default top frame
858 sub command6 {
859 print "SquirrelMail defaults to using the whole of the browser window.\n";
860 print "This allows you to keep it within a specified frame. The default\n";
861 print "is '_top'\n";
862 print "\n";
863 print "[$WHT$frame_top$NRM]: $WHT";
864 $new_frame_top = <STDIN>;
865 if ( $new_frame_top eq "\n" ) {
866 $new_frame_top = '_top';
867 } else {
868 $new_frame_top =~ s/[\r|\n]//g;
869 $new_frame_top =~ s/^\s+$//g;
870 }
871 return $new_frame_top;
872 }
873
874 # Default link to provider
875 sub command7 {
876 print "Here you can set the link on the right of the page.\n";
877 print "The default is 'http://www.squirrelmail.org/'\n";
878 print "\n";
879 print "[$WHT$provider_uri$NRM]: $WHT";
880 $new_provider_uri = <STDIN>;
881 if ( $new_provider_uri eq "\n" ) {
882 $new_provider_uri = 'http://www.squirrelmail.org/';
883 } else {
884 $new_provider_uri =~ s/[\r|\n]//g;
885 $new_provider_uri =~ s/^\s+$//g;
886 }
887 return $new_provider_uri;
888 }
889
890 sub command8 {
891 print "Here you can set the name of the link on the right of the page.\n";
892 print "The default is 'SquirrelMail/'\n";
893 print "\n";
894 print "[$WHT$provider_name$NRM]: $WHT";
895 $new_provider_name = <STDIN>;
896 if ( $new_provider_name eq "\n" ) {
897 $new_provider_name = 'SquirrelMail';
898 } else {
899 $new_provider_name =~ s/[\r|\n]//g;
900 $new_provider_name =~ s/^\s+$//g;
901 }
902 return $new_provider_name;
903 }
904
905 ####################################################################################
906
907 # domain
908 sub command11 {
909 print "The domain name is the suffix at the end of all email addresses. If\n";
910 print "for example, your email address is jdoe\@myorg.com, then your domain\n";
911 print "would be myorg.com.\n";
912 print "\n";
913 print "[$WHT$domain$NRM]: $WHT";
914 $new_domain = <STDIN>;
915 if ( $new_domain eq "\n" ) {
916 $new_domain = $domain;
917 } else {
918 $new_domain =~ s/[\r|\n]//g;
919 }
920 return $new_domain;
921 }
922
923 # imapServerAddress
924 sub command12 {
925 print "This is the hostname where your IMAP server can be contacted.\n";
926 print "[$WHT$imapServerAddress$NRM]: $WHT";
927 $new_imapServerAddress = <STDIN>;
928 if ( $new_imapServerAddress eq "\n" ) {
929 $new_imapServerAddress = $imapServerAddress;
930 } else {
931 $new_imapServerAddress =~ s/[\r|\n]//g;
932 }
933 return $new_imapServerAddress;
934 }
935
936 # imapPort
937 sub command13 {
938 print "This is the port that your IMAP server is on. Usually this is 143.\n";
939 print "[$WHT$imapPort$NRM]: $WHT";
940 $new_imapPort = <STDIN>;
941 if ( $new_imapPort eq "\n" ) {
942 $new_imapPort = $imapPort;
943 } else {
944 $new_imapPort =~ s/[\r|\n]//g;
945 }
946 return $new_imapPort;
947 }
948
949 # useSendmail
950 sub command14 {
951 print "You now need to choose the method that you will use for sending\n";
952 print "messages in SquirrelMail. You can either connect to an SMTP server\n";
953 print "or use sendmail directly.\n";
954 if ( lc($useSendmail) eq "true" ) {
955 $default_value = "1";
956 } else {
957 $default_value = "2";
958 }
959 print "\n";
960 print " 1. Sendmail\n";
961 print " 2. SMTP\n";
962 print "Your choice [1/2] [$WHT$default_value$NRM]: $WHT";
963 $use_sendmail = <STDIN>;
964 if ( ( $use_sendmail =~ /^1\n/i )
965 || ( ( $use_sendmail =~ /^\n/ ) && ( $default_value eq "1" ) ) ) {
966 $useSendmail = "true";
967 } else {
968 $useSendmail = "false";
969 }
970 return $useSendmail;
971 }
972
973 # sendmail_path
974 sub command15 {
975 if ( $sendmail_path[0] !~ /./ ) {
976 $sendmail_path = "/usr/sbin/sendmail";
977 }
978 print "Specify where the sendmail executable is located. Usually /usr/sbin/sendmail\n";
979 print "[$WHT$sendmail_path$NRM]: $WHT";
980 $new_sendmail_path = <STDIN>;
981 if ( $new_sendmail_path eq "\n" ) {
982 $new_sendmail_path = $sendmail_path;
983 } else {
984 $new_sendmail_path =~ s/[\r|\n]//g;
985 }
986 return $new_sendmail_path;
987 }
988
989 # smtpServerAddress
990 sub command16 {
991 print "This is the hostname of your SMTP server.\n";
992 print "[$WHT$smtpServerAddress$NRM]: $WHT";
993 $new_smtpServerAddress = <STDIN>;
994 if ( $new_smtpServerAddress eq "\n" ) {
995 $new_smtpServerAddress = $smtpServerAddress;
996 } else {
997 $new_smtpServerAddress =~ s/[\r|\n]//g;
998 }
999 return $new_smtpServerAddress;
1000 }
1001
1002 # smtpPort
1003 sub command17 {
1004 print "This is the port to connect to for SMTP. Usually 25.\n";
1005 print "[$WHT$smtpPort$NRM]: $WHT";
1006 $new_smtpPort = <STDIN>;
1007 if ( $new_smtpPort eq "\n" ) {
1008 $new_smtpPort = $smtpPort;
1009 } else {
1010 $new_smtpPort =~ s/[\r|\n]//g;
1011 }
1012 return $new_smtpPort;
1013 }
1014
1015 # authenticated server
1016 sub command18 {
1017 return;
1018 # This sub disabled by tassium - it has been replaced with smtp_auth_mech
1019 print "Do you wish to use an authenticated SMTP server? Your server must\n";
1020 print "support this in order for SquirrelMail to work with it. We implemented\n";
1021 print "it according to RFC 2554.\n";
1022
1023 $YesNo = 'n';
1024 $YesNo = 'y' if ( lc($use_authenticated_smtp) eq "true" );
1025
1026 print "Use authenticated SMTP server (y/n) [$WHT$YesNo$NRM]: $WHT";
1027
1028 $new_use_authenticated_smtp = <STDIN>;
1029 $new_use_authenticated_smtp =~ tr/yn//cd;
1030 return "true" if ( $new_use_authenticated_smtp eq "y" );
1031 return "false" if ( $new_use_authenticated_smtp eq "n" );
1032 return $use_authenticated_smtp;
1033 }
1034
1035 # pop before SMTP
1036 sub command18a {
1037 print "Do you wish to use POP3 before SMTP? Your server must\n";
1038 print "support this in order for SquirrelMail to work with it.\n";
1039
1040 $YesNo = 'n';
1041 $YesNo = 'y' if ( lc($pop_before_smtp) eq "true" );
1042
1043 print "Use pop before SMTP (y/n) [$WHT$YesNo$NRM]: $WHT";
1044
1045 $new_pop_before_smtp = <STDIN>;
1046 $new_pop_before_smtp =~ tr/yn//cd;
1047 return "true" if ( $new_pop_before_smtp eq "y" );
1048 return "false" if ( $new_pop_before_smtp eq "n" );
1049 return $pop_before_smtp;
1050 }
1051
1052 # imap_server_type
1053 sub command19 {
1054 print "Each IMAP server has its own quirks. As much as we tried to stick\n";
1055 print "to standards, it doesn't help much if the IMAP server doesn't follow\n";
1056 print "the same principles. We have made some work-arounds for some of\n";
1057 print "these servers. If you would like to use them, please select your\n";
1058 print "IMAP server. If you do not wish to use these work-arounds, you can\n";
1059 print "set this to \"other\", and none will be used.\n";
1060 print " cyrus = Cyrus IMAP server\n";
1061 print " uw = University of Washington's IMAP server\n";
1062 print " exchange = Microsoft Exchange IMAP server\n";
1063 print " courier = Courier IMAP server\n";
1064 print " macosx = Mac OS X Mailserver\n";
1065 print " other = Not one of the above servers\n";
1066 print "[$WHT$imap_server_type$NRM]: $WHT";
1067 $new_imap_server_type = <STDIN>;
1068
1069 if ( $new_imap_server_type eq "\n" ) {
1070 $new_imap_server_type = $imap_server_type;
1071 } else {
1072 $new_imap_server_type =~ s/[\r|\n]//g;
1073 }
1074 return $new_imap_server_type;
1075 }
1076
1077 # invert_time
1078 sub command110 {
1079 print "Sometimes the date of messages sent is messed up (off by a few hours\n";
1080 print "on some machines). Typically this happens if the system doesn't support\n";
1081 print "tm_gmtoff. It will happen only if your time zone is \"negative\".\n";
1082 print "This most often occurs on Solaris 7 machines in the United States.\n";
1083 print "By default, this is off. It should be kept off unless problems surface\n";
1084 print "about the time that messages are sent.\n";
1085 print " no = Do NOT fix time -- almost always correct\n";
1086 print " yes = Fix the time for this system\n";
1087
1088 $YesNo = 'n';
1089 $YesNo = 'y' if ( lc($invert_time) eq "true" );
1090
1091 print "Fix the time for this system (y/n) [$WHT$YesNo$NRM]: $WHT";
1092
1093 $new_invert_time = <STDIN>;
1094 $new_invert_time =~ tr/yn//cd;
1095 return "true" if ( $new_invert_time eq "y" );
1096 return "false" if ( $new_invert_time eq "n" );
1097 return $invert_time;
1098 }
1099
1100 sub command111 {
1101 print "This is the delimiter that your IMAP server uses to distinguish between\n";
1102 print "folders. For example, Cyrus uses '.' as the delimiter and a complete\n";
1103 print "folder would look like 'INBOX.Friends.Bob', while UW uses '/' and would\n";
1104 print "look like 'INBOX/Friends/Bob'. Normally this should be left at 'detect'\n";
1105 print "but if you are sure you know what delimiter your server uses, you can\n";
1106 print "specify it here.\n";
1107 print "\nTo have it autodetect the delimiter, set it to 'detect'.\n\n";
1108 print "[$WHT$optional_delimiter$NRM]: $WHT";
1109 $new_optional_delimiter = <STDIN>;
1110
1111 if ( $new_optional_delimiter eq "\n" ) {
1112 $new_optional_delimiter = $optional_delimiter;
1113 } else {
1114 $new_optional_delimiter =~ s/[\r|\n]//g;
1115 }
1116 return $new_optional_delimiter;
1117 }
1118 # IMAP authentication type
1119 # Possible values: plain, cram-md5, digest-md5
1120 # Now offers to detect supported mechs, assuming server & port are set correctly
1121
1122 sub command112a {
1123 print "If you have already set the hostname and port number, I can try to\n";
1124 print "detect the mechanisms your IMAP server supports.\n";
1125 print "I will try to detect CRAM-MD5 and DIGEST-MD5 support. I can't test\n";
1126 print "for \"plain\" without knowing a username and password.\n";
1127 print "Auto-detecting is optional - you can safely say \"n\" here.\n";
1128 print "\nTry to detect supported mechanisms? [y/N]: ";
1129 $inval=<STDIN>;
1130 chomp($inval);
1131 if ($inval =~ /^y\b/i) {
1132 # Yes, let's try to detect.
1133 print "Trying to detect IMAP capabilities...\n";
1134 my $host = $imapServerAddress . ':'. $imapPort;
1135 print "CRAM-MD5:\t";
1136 my $tmp = detect_auth_support('IMAP',$host,'CRAM-MD5');
1137 if (defined($tmp)) {
1138 if ($tmp eq 'YES') {
1139 print "$WHT SUPPORTED$NRM\n";
1140 } else {
1141 print "$WHT NOT SUPPORTED$NRM\n";
1142 }
1143 } else {
1144 print $WHT . " ERROR DETECTING$NRM\n";
1145 }
1146
1147 print "DIGEST-MD5:\t";
1148 $tmp = detect_auth_support('IMAP',$host,'DIGEST-MD5');
1149 if (defined($tmp)) {
1150 if ($tmp eq 'YES') {
1151 print "$WHT SUPPORTED$NRM\n";
1152 } else {
1153 print "$WHT NOT SUPPORTED$NRM\n";
1154 }
1155 } else {
1156 print $WHT . " ERROR DETECTING$NRM\n";
1157 }
1158
1159 }
1160 print "\nWhat authentication mechanism do you want to use for IMAP connections?\n\n";
1161 print $WHT . "plain" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
1162 print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext.\n";
1163 print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
1164 print "\n*** YOUR IMAP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n";
1165 print "If you don't understand or are unsure, you probably want \"plain\"\n\n";
1166 print "plain, cram-md5, or digest-md5 [$WHT$imap_auth_mech$NRM]: $WHT";
1167 $inval=<STDIN>;
1168 chomp($inval);
1169 if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || ($inval =~ /^plain\b/i)) {
1170 return lc($inval);
1171 } else {
1172 # user entered garbage or default value so nothing needs to be set
1173 return $imap_auth_mech;
1174 }
1175 }
1176
1177
1178 # SMTP authentication type
1179 # Possible choices: none, plain, cram-md5, digest-md5
1180 sub command112b {
1181 print "If you have already set the hostname and port number, I can try to\n";
1182 print "automatically detect the mechanisms your SMTP server supports.\n";
1183 print "Auto-detection is *optional* - you can safely say \"n\" here.\n";
1184 print "\nTry to detect auth mechanisms? [y/N]: ";
1185 $inval=<STDIN>;
1186 chomp($inval);
1187 if ($inval =~ /^y\b/i) {
1188 # Yes, let's try to detect.
1189 print "Trying to detect supported methods (SMTP)...\n";
1190
1191 # Special case!
1192 # Check none by trying to relay to junk@birdbrained.org
1193 $host = $smtpServerAddress . ':' . $smtpPort;
1194 use IO::Socket;
1195 my $sock = IO::Socket::INET->new($host);
1196 print "Testing none:\t\t$WHT";
1197 if (!defined($sock)) {
1198 print " ERROR TESTING\n";
1199 close $sock;
1200 } else {
1201 print $sock "mail from: tester\@squirrelmail.org\n";
1202 $got = <$sock>; # Discard
1203 print $sock "rcpt to: junk\@birdbrained.org\n";
1204 $got = <$sock>; # This is the important line
1205 if ($got =~ /^250\b/) { # SMTP will relay without auth
1206 print "SUPPORTED$NRM\n";
1207 } else {
1208 print "NOT SUPPORTED$NRM\n";
1209 }
1210 print $sock "rset\n";
1211 print $sock "quit\n";
1212 close $sock;
1213 }
1214 # Try plain (SquirrelMail default)
1215 print "Testing plain:\t\t";
1216 $tmp=detect_auth_support('SMTP',$host,'LOGIN');
1217 if (defined($tmp)) {
1218 if ($tmp eq 'YES') {
1219 print $WHT . "SUPPORTED$NRM\n";
1220 } else {
1221 print $WHT . "NOT SUPPORTED$NRM\n";
1222 }
1223 } else {
1224 print $WHT . "ERROR DETECTING$NRM\n";
1225 }
1226
1227 # Try CRAM-MD5
1228 print "Testing CRAM-MD5:\t";
1229 $tmp=detect_auth_support('SMTP',$host,'CRAM-MD5');
1230 if (defined($tmp)) {
1231 if ($tmp eq 'YES') {
1232 print $WHT . "SUPPORTED$NRM\n";
1233 } else {
1234 print $WHT . "NOT SUPPORTED$NRM\n";
1235 }
1236 } else {
1237 print $WHT . "ERROR DETECTING$NRM\n";
1238 }
1239
1240
1241 print "Testing DIGEST-MD5:\t";
1242 $tmp=detect_auth_support('SMTP',$host,'DIGEST-MD5');
1243 if (defined($tmp)) {
1244 if ($tmp eq 'YES') {
1245 print $WHT . "SUPPORTED$NRM\n";
1246 } else {
1247 print $WHT . "NOT SUPPORTED$NRM\n";
1248 }
1249 } else {
1250 print $WHT . "ERROR DETECTING$NRM\n";
1251 }
1252 }
1253 print "\tWhat authentication mechanism do you want to use for SMTP connections?\n";
1254 print $WHT . "none" . $NRM . " - Your SMTP server does not require authorization.\n";
1255 print $WHT . "plain" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
1256 print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext.\n";
1257 print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
1258 print "\n*** YOUR SMTP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n";
1259 print "If you don't understand or are unsure, you probably want \"none\"\n\n";
1260 print "none, plain, cram-md5, or digest-md5 [$WHT$smtp_auth_mech$NRM]: $WHT";
1261 $inval=<STDIN>;
1262 chomp($inval);
1263 if ($inval =~ /^none\b/i) {
1264 # SMTP doesn't necessarily require logins
1265 return "none";
1266 }
1267 if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) ||
1268 ($inval =~ /^plain\b/i)) {
1269 return lc($inval);
1270 } else {
1271 # user entered garbage, or default value so nothing needs to be set
1272 return $smtp_auth_mech;
1273 }
1274 }
1275
1276 # TLS
1277 # This sub is reused for IMAP and SMTP
1278 # Args: service name, default value
1279 sub command113 {
1280 my($default_val,$service,$inval);
1281 $service=$_[0];
1282 $default_val=$_[1];
1283 print "TLS (Transport Layer Security) encrypts the traffic between server and client.\n";
1284 print "If you're familiar with SSL, you get the idea.\n";
1285 print "To use this feature, your " . $service . " server must offer TLS\n";
1286 print "capability, plus PHP 4.3.x with OpenSSL support.\n";
1287 print "\nIf your " . $service . " server is localhost, you can safely disable this.\n";
1288 print "If it is remote, you may wish to seriously consider enabling this.\n";
1289 print "Enable TLS (y/n) [$WHT";
1290 if ($default_val eq "true") {
1291 print "y";
1292 } else {
1293 print "n";
1294 }
1295 print "$NRM]: $WHT";
1296 $inval=<STDIN>;
1297 $inval =~ tr/yn//cd;
1298 return "true" if ( $inval eq "y" );
1299 return "false" if ( $inval eq "n" );
1300 return $default_val;
1301
1302
1303 }
1304
1305
1306 # MOTD
1307 sub command71 {
1308 print "\nYou can now create the welcome message that is displayed\n";
1309 print "every time a user logs on. You can use HTML or just plain\n";
1310 print
1311 "text. If you do not wish to have one, just make it blank.\n\n(Type @ on a blank line to exit)\n";
1312
1313 $new_motd = "";
1314 do {
1315 print "] ";
1316 $line = <STDIN>;
1317 $line =~ s/[\r|\n]//g;
1318 if ( $line ne "@" ) {
1319 $line =~ s/ /\&nbsp;\&nbsp;/g;
1320 $line =~ s/\t/\&nbsp;\&nbsp;\&nbsp;\&nbsp;/g;
1321 $line =~ s/$/ /;
1322 $line =~ s/\"/&quot;/g;
1323
1324 $new_motd = $new_motd . $line;
1325 }
1326 } while ( $line ne "@" );
1327 return $new_motd;
1328 }
1329
1330 ################# PLUGINS ###################
1331
1332 sub command81 {
1333 $command =~ s/[\s|\n|\r]*//g;
1334 if ( $command > 0 ) {
1335 $command = $command - 1;
1336 if ( $command <= $#plugins ) {
1337 @newplugins = ();
1338 $ct = 0;
1339 while ( $ct <= $#plugins ) {
1340 if ( $ct != $command ) {
1341 @newplugins = ( @newplugins, $plugins[$ct] );
1342 }
1343 $ct++;
1344 }
1345 @plugins = @newplugins;
1346 } elsif ( $command <= $#plugins + $#unused_plugins + 1 ) {
1347 $num = $command - $#plugins - 1;
1348 @newplugins = @plugins;
1349 $ct = 0;
1350 while ( $ct <= $#unused_plugins ) {
1351 if ( $ct == $num ) {
1352 @newplugins = ( @newplugins, $unused_plugins[$ct] );
1353 }
1354 $ct++;
1355 }
1356 @plugins = @newplugins;
1357 }
1358 }
1359 return @plugins;
1360 }
1361
1362 ################# FOLDERS ###################
1363
1364 # default_folder_prefix
1365 sub command21 {
1366 print "Some IMAP servers (UW, for example) store mail and folders in\n";
1367 print "your user space in a separate subdirectory. This is where you\n";
1368 print "specify what that directory is.\n";
1369 print "\n";
1370 print "EXAMPLE: mail/";
1371 print "\n";
1372 print "NOTE: If you use Cyrus, or some server that would not use this\n";
1373 print " option, you must set this to 'none'.\n";
1374 print "\n";
1375 print "[$WHT$default_folder_prefix$NRM]: $WHT";
1376 $new_default_folder_prefix = <STDIN>;
1377
1378 if ( $new_default_folder_prefix eq "\n" ) {
1379 $new_default_folder_prefix = $default_folder_prefix;
1380 } else {
1381 $new_default_folder_prefix =~ s/[\r\n]//g;
1382 }
1383 if ( ( $new_default_folder_prefix =~ /^\s*$/ ) || ( $new_default_folder_prefix =~ m/^none$/i ) ) {
1384 $new_default_folder_prefix = "";
1385 } else {
1386 # add the trailing delimiter only if we know what the server is.
1387 if (($imap_server_type eq 'cyrus' and
1388 $optional_delimiter eq 'detect') or
1389 ($imap_server_type eq 'courier' and
1390 $optional_delimiter eq 'detect')) {
1391 $new_default_folder_prefix =~ s/\.*$/\./;
1392 } elsif ($imap_server_type eq 'uw' and
1393 $optional_delimiter eq 'detect') {
1394 $new_default_folder_prefix =~ s/\/*$/\//;
1395 }
1396 }
1397 return $new_default_folder_prefix;
1398 }
1399
1400 # Show Folder Prefix
1401 sub command22 {
1402 print "It is possible to set up the default folder prefix as a user\n";
1403 print "specific option, where each user can specify what their mail\n";
1404 print "folder is. If you set this to false, they will never see the\n";
1405 print "option, but if it is true, this option will appear in the\n";
1406 print "'options' section.\n";
1407 print "\n";
1408 print "NOTE: You set the default folder prefix in option '1' of this\n";
1409 print " section. That will be the default if the user doesn't\n";
1410 print " specify anything different.\n";
1411 print "\n";
1412
1413 if ( lc($show_prefix_option) eq "true" ) {
1414 $default_value = "y";
1415 } else {
1416 $default_value = "n";
1417 }
1418 print "\n";
1419 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
1420 $new_show = <STDIN>;
1421 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1422 $show_prefix_option = "true";
1423 } else {
1424 $show_prefix_option = "false";
1425 }
1426 return $show_prefix_option;
1427 }
1428
1429 # Trash Folder
1430 sub command23a {
1431 print "You can now specify where the default trash folder is located.\n";
1432 print "On servers where you do not want this, you can set it to anything\n";
1433 print "and set option 6 to false.\n";
1434 print "\n";
1435 print "This is relative to where the rest of your email is kept. You do\n";
1436 print "not need to worry about their mail directory. If this folder\n";
1437 print "would be ~/mail/trash on the filesystem, you only need to specify\n";
1438 print "that this is 'trash', and be sure to put 'mail/' in option 1.\n";
1439 print "\n";
1440
1441 print "[$WHT$trash_folder$NRM]: $WHT";
1442 $new_trash_folder = <STDIN>;
1443 if ( $new_trash_folder eq "\n" ) {
1444 $new_trash_folder = $trash_folder;
1445 } else {
1446 $new_trash_folder =~ s/[\r|\n]//g;
1447 }
1448 return $new_trash_folder;
1449 }
1450
1451 # Sent Folder
1452 sub command23b {
1453 print "This is where messages that are sent will be stored. SquirrelMail\n";
1454 print "by default puts a copy of all outgoing messages in this folder.\n";
1455 print "\n";
1456 print "This is relative to where the rest of your email is kept. You do\n";
1457 print "not need to worry about their mail directory. If this folder\n";
1458 print "would be ~/mail/sent on the filesystem, you only need to specify\n";
1459 print "that this is 'sent', and be sure to put 'mail/' in option 1.\n";
1460 print "\n";
1461
1462 print "[$WHT$sent_folder$NRM]: $WHT";
1463 $new_sent_folder = <STDIN>;
1464 if ( $new_sent_folder eq "\n" ) {
1465 $new_sent_folder = $sent_folder;
1466 } else {
1467 $new_sent_folder =~ s/[\r|\n]//g;
1468 }
1469 return $new_sent_folder;
1470 }
1471
1472 # Draft Folder
1473 sub command23c {
1474 print "You can now specify where the default draft folder is located.\n";
1475 print "On servers where you do not want this, you can set it to anything\n";
1476 print "and set option 9 to false.\n";
1477 print "\n";
1478 print "This is relative to where the rest of your email is kept. You do\n";
1479 print "not need to worry about their mail directory. If this folder\n";
1480 print "would be ~/mail/drafts on the filesystem, you only need to specify\n";
1481 print "that this is 'drafts', and be sure to put 'mail/' in option 1.\n";
1482 print "\n";
1483
1484 print "[$WHT$draft_folder$NRM]: $WHT";
1485 $new_draft_folder = <STDIN>;
1486 if ( $new_draft_folder eq "\n" ) {
1487 $new_draft_folder = $draft_folder;
1488 } else {
1489 $new_draft_folder =~ s/[\r|\n]//g;
1490 }
1491 return $new_draft_folder;
1492 }
1493
1494 # default move to trash
1495 sub command24a {
1496 print "By default, should messages get moved to the trash folder? You\n";
1497 print "can specify the default trash folder in option 3. If this is set\n";
1498 print "to false, messages will get deleted immediately without moving\n";
1499 print "to the trash folder.\n";
1500 print "\n";
1501 print "Trash folder is currently: $trash_folder\n";
1502 print "\n";
1503
1504 if ( lc($default_move_to_trash) eq "true" ) {
1505 $default_value = "y";
1506 } else {
1507 $default_value = "n";
1508 }
1509 print "By default, move to trash (y/n) [$WHT$default_value$NRM]: $WHT";
1510 $new_show = <STDIN>;
1511 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1512 $default_move_to_trash = "true";
1513 } else {
1514 $default_move_to_trash = "false";
1515 }
1516 return $default_move_to_trash;
1517 }
1518
1519 # default move to sent
1520 sub command24b {
1521 print "By default, should messages get moved to the sent folder? You\n";
1522 print "can specify the default sent folder in option 4. If this is set\n";
1523 print "to false, messages will get sent and no copy will be made.\n";
1524 print "\n";
1525 print "Sent folder is currently: $sent_folder\n";
1526 print "\n";
1527
1528 if ( lc($default_move_to_sent) eq "true" ) {
1529 $default_value = "y";
1530 } else {
1531 $default_value = "n";
1532 }
1533 print "By default, move to sent (y/n) [$WHT$default_value$NRM]: $WHT";
1534 $new_show = <STDIN>;
1535 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1536 $default_move_to_sent = "true";
1537 } else {
1538 $default_move_to_sent = "false";
1539 }
1540 return $default_move_to_sent;
1541 }
1542
1543 # default save as draft
1544 sub command24c {
1545 print "By default, should the save to draft option be shown? You can\n";
1546 print "specify the default drafts folder in option 5. If this is set\n";
1547 print "to false, users will not be shown the save to draft option.\n";
1548 print "\n";
1549 print "Drafts folder is currently: $draft_folder\n";
1550 print "\n";
1551
1552 if ( lc($default_move_to_draft) eq "true" ) {
1553 $default_value = "y";
1554 } else {
1555 $default_value = "n";
1556 }
1557 print "By default, save as draft (y/n) [$WHT$default_value$NRM]: $WHT";
1558 $new_show = <STDIN>;
1559 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1560 $default_save_as_draft = "true";
1561 } else {
1562 $default_save_as_draft = "false";
1563 }
1564 return $default_save_as_draft;
1565 }
1566
1567 # List special folders first
1568 sub command27 {
1569 print "SquirrelMail has what we call 'special folders' that are not\n";
1570 print "manipulated and viewed like normal folders. Some examples of\n";
1571 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
1572 print "Simply asks if you want these folders listed first in the folder\n";
1573 print "listing.\n";
1574 print "\n";
1575
1576 if ( lc($list_special_folders_first) eq "true" ) {
1577 $default_value = "y";
1578 } else {
1579 $default_value = "n";
1580 }
1581 print "\n";
1582 print "List first (y/n) [$WHT$default_value$NRM]: $WHT";
1583 $new_show = <STDIN>;
1584 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1585 $list_special_folders_first = "true";
1586 } else {
1587 $list_special_folders_first = "false";
1588 }
1589 return $list_special_folders_first;
1590 }
1591
1592 # Show special folders color
1593 sub command28 {
1594 print "SquirrelMail has what we call 'special folders' that are not\n";
1595 print "manipulated and viewed like normal folders. Some examples of\n";
1596 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
1597 print "wants to know if we should display special folders in a\n";
1598 print "color than the other folders.\n";
1599 print "\n";
1600
1601 if ( lc($use_special_folder_color) eq "true" ) {
1602 $default_value = "y";
1603 } else {
1604 $default_value = "n";
1605 }
1606 print "\n";
1607 print "Show color (y/n) [$WHT$default_value$NRM]: $WHT";
1608 $new_show = <STDIN>;
1609 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1610 $use_special_folder_color = "true";
1611 } else {
1612 $use_special_folder_color = "false";
1613 }
1614 return $use_special_folder_color;
1615 }
1616
1617 # Auto expunge
1618 sub command29 {
1619 print "The way that IMAP handles deleting messages is as follows. You\n";
1620 print "mark the message as deleted, and then to 'really' delete it, you\n";
1621 print "expunge it. This option asks if you want to just have messages\n";
1622 print "marked as deleted, or if you want SquirrelMail to expunge the \n";
1623 print "messages too.\n";
1624 print "\n";
1625
1626 if ( lc($auto_expunge) eq "true" ) {
1627 $default_value = "y";
1628 } else {
1629 $default_value = "n";
1630 }
1631 print "Auto expunge (y/n) [$WHT$default_value$NRM]: $WHT";
1632 $new_show = <STDIN>;
1633 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1634 $auto_expunge = "true";
1635 } else {
1636 $auto_expunge = "false";
1637 }
1638 return $auto_expunge;
1639 }
1640
1641 # Default sub of inbox
1642 sub command210 {
1643 print "Some IMAP servers (Cyrus) have all folders as subfolders of INBOX.\n";
1644 print "This can cause some confusion in folder creation for users when\n";
1645 print "they try to create folders and don't put it as a subfolder of INBOX\n";
1646 print "and get permission errors. This option asks if you want folders\n";
1647 print "to be subfolders of INBOX by default.\n";
1648 print "\n";
1649
1650 if ( lc($default_sub_of_inbox) eq "true" ) {
1651 $default_value = "y";
1652 } else {
1653 $default_value = "n";
1654 }
1655 print "Default sub of INBOX (y/n) [$WHT$default_value$NRM]: $WHT";
1656 $new_show = <STDIN>;
1657 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1658 $default_sub_of_inbox = "true";
1659 } else {
1660 $default_sub_of_inbox = "false";
1661 }
1662 return $default_sub_of_inbox;
1663 }
1664
1665 # Show contain subfolder option
1666 sub command211 {
1667 print "Some IMAP servers (UW) make it so that there are two types of\n";
1668 print "folders. Those that contain messages, and those that contain\n";
1669 print "subfolders. If this is the case for your server, set this to\n";
1670 print "true, and it will ask the user whether the folder they are\n";
1671 print "creating contains subfolders or messages.\n";
1672 print "\n";
1673
1674 if ( lc($show_contain_subfolders_option) eq "true" ) {
1675 $default_value = "y";
1676 } else {
1677 $default_value = "n";
1678 }
1679 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
1680 $new_show = <STDIN>;
1681 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1682 $show_contain_subfolders_option = "true";
1683 } else {
1684 $show_contain_subfolders_option = "false";
1685 }
1686 return $show_contain_subfolders_option;
1687 }
1688
1689 # Default Unseen Notify
1690 sub command212 {
1691 print "This option specifies where the users will receive notification\n";
1692 print "about unseen messages by default. This is of course an option that\n";
1693 print "can be changed on a user level.\n";
1694 print " 1 = No notification\n";
1695 print " 2 = Only on the INBOX\n";
1696 print " 3 = On all folders\n";
1697 print "\n";
1698
1699 print "Which one should be default (1,2,3)? [$WHT$default_unseen_notify$NRM]: $WHT";
1700 $new_show = <STDIN>;
1701 if ( $new_show =~ /^[1|2|3]\n/i ) {
1702 $default_unseen_notify = $new_show;
1703 }
1704 $default_unseen_notify =~ s/[\r|\n]//g;
1705 return $default_unseen_notify;
1706 }
1707
1708 # Default Unseen Type
1709 sub command213 {
1710 print "Here you can define the default way that unseen messages will be displayed\n";
1711 print "to the user in the folder listing on the left side.\n";
1712 print " 1 = Only unseen messages (4)\n";
1713 print " 2 = Unseen and Total messages (4/27)\n";
1714 print "\n";
1715
1716 print "Which one should be default (1,2)? [$WHT$default_unseen_type$NRM]: $WHT";
1717 $new_show = <STDIN>;
1718 if ( $new_show =~ /^[1|2]\n/i ) {
1719 $default_unseen_type = $new_show;
1720 }
1721 $default_unseen_type =~ s/[\r|\n]//g;
1722 return $default_unseen_type;
1723 }
1724
1725 # Auto create special folders
1726 sub command214 {
1727 print "Would you like the Sent, Trash, and Drafts folders to be created\n";
1728 print "automatically print for you when a user logs in? If the user\n";
1729 print "accidentally deletes their special folders, this option will\n";
1730 print "automatically create it again for them.\n";
1731 print "\n";
1732
1733 if ( lc($auto_create_special) eq "true" ) {
1734 $default_value = "y";
1735 } else {
1736 $default_value = "n";
1737 }
1738 print "Auto create special folders? (y/n) [$WHT$default_value$NRM]: $WHT";
1739 $new_show = <STDIN>;
1740 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1741 $auto_create_special = "true";
1742 } else {
1743 $auto_create_special = "false";
1744 }
1745 return $auto_create_special;
1746 }
1747
1748 # Auto create special folders
1749 sub command215 {
1750 print "Would you like to automatically completely delete any deleted\n";
1751 print "folders? If not then they will be moved to the Trash folder\n";
1752 print "and can be deleted from there\n";
1753 print "\n";
1754
1755 if ( lc($delete_folder) eq "true" ) {
1756 $default_value = "y";
1757 } else {
1758 $default_value = "n";
1759 }
1760 print "Auto delete folders? (y/n) [$WHT$default_value$NRM]: $WHT";
1761 $new_delete = <STDIN>;
1762 if ( ( $new_delete =~ /^y\n/i ) || ( ( $new_delete =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1763 $delete_folder = "true";
1764 } else {
1765 $delete_folder = "false";
1766 }
1767 return $delete_folder;
1768 }
1769
1770 #noselect fix
1771 sub command216 {
1772 print "Some IMAP server allow subfolders to exist even if the parent\n";
1773 print "folders do not. This fixes some problems with the folder list\n";
1774 print "when this is the case, causing the /NoSelect folders to be displayed\n";
1775 print "\n";
1776
1777 if ( lc($noselect_fix_enable) eq "true" ) {
1778 $default_value = "y";
1779 } else {
1780 $default_value = "n";
1781 }
1782 print "enable noselect fix? (y/n) [$WHT$noselect_fix_enable$NRM]: $WHT";
1783 $noselect_fix_enable = <STDIN>;
1784 if ( ( $noselect_fix_enable =~ /^y\n/i ) || ( ( $noselect_fix_enable =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1785 $noselect_fix_enable = "true";
1786 } else {
1787 $noselect_fix_enable = "false";
1788 }
1789 return $noselect_fix_enable;
1790 }
1791 ############# GENERAL OPTIONS #####################
1792
1793 # Default Charset
1794 sub command31 {
1795 print "This option controls what character set is used when sending\n";
1796 print "mail and when sending HTML to the browser. Do not set this\n";
1797 print "to US-ASCII, use ISO-8859-1 instead. For cyrillic, it is best\n";
1798 print "to use KOI8-R, since this implementation is faster than most\n";
1799 print "of the alternatives\n";
1800 print "\n";
1801
1802 print "[$WHT$default_charset$NRM]: $WHT";
1803 $new_default_charset = <STDIN>;
1804 if ( $new_default_charset eq "\n" ) {
1805 $new_default_charset = $default_charset;
1806 } else {
1807 $new_default_charset =~ s/[\r|\n]//g;
1808 }
1809 return $new_default_charset;
1810 }
1811
1812 # Data directory
1813 sub command33a {
1814 print "It is a possible security hole to have a writable directory\n";
1815 print "under the web server's root directory (ex: /home/httpd/html).\n";
1816 print "For this reason, it is possible to put the data directory\n";
1817 print "anywhere you would like. The path name can be absolute or\n";
1818 print "relative (to the config directory). It doesn't matter. Here\n";
1819 print "are two examples:\n";
1820 print " Absolute: /usr/local/squirrelmail/data/\n";
1821 print " Relative: ../data/\n";
1822 print "Relative paths to directories outside of the SquirrelMail distribution\n";
1823 print "will be converted to their absolute path equivalents in config.php.\n";
1824 print "\n";
1825
1826 print "[$WHT$data_dir$NRM]: $WHT";
1827 $new_data_dir = <STDIN>;
1828 if ( $new_data_dir eq "\n" ) {
1829 $new_data_dir = $data_dir;
1830 } else {
1831 $new_data_dir =~ s/[\r|\n]//g;
1832 }
1833 if ( $new_data_dir =~ /^\s*$/ ) {
1834 $new_data_dir = "";
1835 } else {
1836 $new_data_dir =~ s/\/*$//g;
1837 $new_data_dir =~ s/$/\//g;
1838 }
1839 return $new_data_dir;
1840 }
1841
1842 # Attachment directory
1843 sub command33b {
1844 print "Path to directory used for storing attachments while a mail is\n";
1845 print "being sent. There are a few security considerations regarding this\n";
1846 print "directory:\n";
1847 print " 1. It should have the permission 733 (rwx-wx-wx) to make it\n";
1848 print " impossible for a random person with access to the webserver\n";
1849 print " to list files in this directory. Confidential data might\n";
1850 print " be laying around in there.\n";
1851 print " 2. Since the webserver is not able to list the files in the\n";
1852 print " content is also impossible for the webserver to delete files\n";
1853 print " lying around there for too long.\n";
1854 print " 3. It should probably be another directory than the data\n";
1855 print " directory specified in option 3.\n";
1856 print "Relative paths to directories outside of the SquirrelMail distribution\n";
1857 print "will be converted to their absolute path equivalents in config.php.\n";
1858 print "\n";
1859
1860 print "[$WHT$attachment_dir$NRM]: $WHT";
1861 $new_attachment_dir = <STDIN>;
1862 if ( $new_attachment_dir eq "\n" ) {
1863 $new_attachment_dir = $attachment_dir;
1864 } else {
1865 $new_attachment_dir =~ s/[\r|\n]//g;
1866 }
1867 if ( $new_attachment_dir =~ /^\s*$/ ) {
1868 $new_attachment_dir = "";
1869 } else {
1870 $new_attachment_dir =~ s/\/*$//g;
1871 $new_attachment_dir =~ s/$/\//g;
1872 }
1873 return $new_attachment_dir;
1874 }
1875
1876 sub command33c {
1877 print "The directory hash level setting allows you to configure the level\n";
1878 print "of hashing that Squirremail employs in your data and attachment\n";
1879 print "directories. This value must be an integer ranging from 0 to 4.\n";
1880 print "When this value is set to 0, Squirrelmail will simply store all\n";
1881 print "files as normal in the data and attachment directories. However,\n";
1882 print "when set to a value from 1 to 4, a simple hashing scheme will be\n";
1883 print "used to organize the files in this directory. In short, the crc32\n";
1884 print "value for a username will be computed. Then, up to the first 4\n";
1885 print "digits of the hash, as set by this configuration value, will be\n";
1886 print "used to directory hash the files for that user in the data and\n";
1887 print "attachment directory. This allows for better performance on\n";
1888 print "servers with larger numbers of users.\n";
1889 print "\n";
1890
1891 print "[$WHT$dir_hash_level$NRM]: $WHT";
1892 $new_dir_hash_level = <STDIN>;
1893 if ( $new_dir_hash_level eq "\n" ) {
1894 $new_dir_hash_level = $dir_hash_level;
1895 } else {
1896 $new_dir_hash_level =~ s/[\r|\n]//g;
1897 }
1898 if ( ( int($new_dir_hash_level) < 0 )
1899 || ( int($new_dir_hash_level) > 4 )
1900 || !( int($new_dir_hash_level) eq $new_dir_hash_level ) ) {
1901 print "Invalid Directory Hash Level.\n";
1902 print "Value must be an integer ranging from 0 to 4\n";
1903 print "Hit enter to continue.\n";
1904 $enter_key = <STDIN>;
1905
1906 $new_dir_hash_level = $dir_hash_level;
1907 }
1908
1909 return $new_dir_hash_level;
1910 }
1911
1912 sub command35 {
1913 print "This is the default size (in pixels) of the left folder list.\n";
1914 print "Default is 200, but you can set it to whatever you wish. This\n";
1915 print "is a user preference, so this will only show up as their default.\n";
1916 print "\n";
1917 print "[$WHT$default_left_size$NRM]: $WHT";
1918 $new_default_left_size = <STDIN>;
1919 if ( $new_default_left_size eq "\n" ) {
1920 $new_default_left_size = $default_left_size;
1921 } else {
1922 $new_default_left_size =~ s/[\r|\n]//g;
1923 }
1924 return $new_default_left_size;
1925 }
1926
1927 sub command36 {
1928 print "Some IMAP servers only have lowercase letters in the usernames\n";
1929 print "but they still allow people with uppercase to log in. This\n";
1930 print "causes a problem with the user's preference files. This option\n";
1931 print "transparently changes all usernames to lowercase.";
1932 print "\n";
1933
1934 if ( lc($force_username_lowercase) eq "true" ) {
1935 $default_value = "y";
1936 } else {
1937 $default_value = "n";
1938 }
1939 print "Convert usernames to lowercase (y/n) [$WHT$default_value$NRM]: $WHT";
1940 $new_show = <STDIN>;
1941 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1942 return "true";
1943 }
1944 return "false";
1945 }
1946
1947 sub command37 {
1948 print "";
1949 print "\n";
1950
1951 if ( lc($default_use_priority) eq "true" ) {
1952 $default_value = "y";
1953 } else {
1954 $default_value = "n";
1955 }
1956
1957 print "Allow users to specify priority of outgoing mail (y/n) [$WHT$default_value$NRM]: $WHT";
1958 $new_show = <STDIN>;
1959 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1960 return "true";
1961 }
1962 return "false";
1963 }
1964
1965 sub command38 {
1966 print "";
1967 print "\n";
1968
1969 if ( lc($default_hide_attribution) eq "true" ) {
1970 $default_value = "y";
1971 } else {
1972 $default_value = "n";
1973 }
1974
1975 print "Hide SM attributions (y/n) [$WHT$default_value$NRM]: $WHT";
1976 $new_show = <STDIN>;
1977 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1978 return "true";
1979 }
1980 return "false";
1981 }
1982
1983 sub command39 {
1984 print "";
1985 print "\n";
1986
1987 if ( lc($default_use_mdn) eq "true" ) {
1988 $default_value = "y";
1989 } else {
1990 $default_value = "n";
1991 }
1992
1993 print "Enable support for read/delivery receipt support (y/n) [$WHT$default_value$NRM]: $WHT";
1994 $new_show = <STDIN>;
1995 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1996 return "true";
1997 }
1998 return "false";
1999 }
2000
2001 sub command310 {
2002 print "This allows you to prevent the editing of the users name and";
2003 print "email address. This is mainly useful when used with the";
2004 print "retrieveuserdata plugin\n";
2005 print "\n";
2006
2007 if ( lc($edit_identity) eq "true" ) {
2008 $default_value = "y";
2009 } else {
2010 $default_value = "n";
2011 }
2012 print "Allow editing? (y/n) [$WHT$default_value$NRM]: $WHT";
2013 $new_edit = <STDIN>;
2014 if ( ( $new_edit =~ /^y\n/i ) || ( ( $new_edit =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2015 $edit_identity = "true";
2016 } else {
2017 $edit_identity = "false";
2018 }
2019 return $edit_identity;
2020 }
2021
2022 sub command311 {
2023 print "This option allows you to choose if the user can edit their full name";
2024 print "even when you don't want them to change their username\n";
2025 print "\n";
2026
2027 if ( lc($edit_name) eq "true" ) {
2028 $default_value = "y";
2029 } else {
2030 $default_value = "n";
2031 }
2032 print "Allow editing of the users full name? (y/n) [$WHT$default_value$NRM]: $WHT";
2033 $new_edit = <STDIN>;
2034 if ( ( $new_edit =~ /^y\n/i ) || ( ( $new_edit =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2035 $edit_name = "true";
2036 } else {
2037 $edit_name = "false";
2038 }
2039 return $edit_name;
2040 }
2041
2042 sub command312 {
2043 print "This option allows you to choose if users can use thread sorting\n";
2044 print "Your IMAP server must support the THREAD command for this to work\n";
2045 print "PHP versions later than 4.0.3 recommended\n";
2046 print "\n";
2047
2048 if ( lc($allow_thread_sort) eq "true" ) {
2049 $default_value = "y";
2050 } else {
2051 $default_value = "n";
2052 }
2053 print "Allow server side thread sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
2054 $allow_thread_sort = <STDIN>;
2055 if ( ( $allow_thread_sort =~ /^y\n/i ) || ( ( $allow_thread_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2056 $allow_thread_sort = "true";
2057 } else {
2058 $allow_thread_sort = "false";
2059 }
2060 return $allow_thread_sort;
2061 }
2062
2063 sub command313 {
2064 print "This option allows you to choose if SM uses server-side sorting\n";
2065 print "Your IMAP server must support the SORT command for this to work\n";
2066 print "\n";
2067
2068 if ( lc($allow_server_sort) eq "true" ) {
2069 $default_value = "y";
2070 } else {
2071 $default_value = "n";
2072 }
2073 print "Allow server-side sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
2074 $allow_server_sort = <STDIN>;
2075 if ( ( $allow_server_sort =~ /^y\n/i ) || ( ( $allow_server_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2076 $allow_server_sort = "true";
2077 } else {
2078 $allow_server_sort = "false";
2079 }
2080 return $allow_server_sort;
2081 }
2082
2083 sub command314 {
2084 print "This option allows you to choose if SM uses charset search\n";
2085 print "Your IMAP server must support the SEARCH CHARSET command for this to work\n";
2086 print "\n";
2087
2088 if ( lc($allow_charset_search) eq "true" ) {
2089 $default_value = "y";
2090 } else {
2091 $default_value = "n";
2092 }
2093 print "Allow charset searching? (y/n) [$WHT$default_value$NRM]: $WHT";
2094 $allow_charset_search = <STDIN>;
2095 if ( ( $allow_charset_search =~ /^y\n/i ) || ( ( $allow_charset_search =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2096 $allow_charset_search = "true";
2097 } else {
2098 $allow_charset_search = "false";
2099 }
2100 return $allow_charset_search;
2101 }
2102
2103 sub command315 {
2104 print "This option allows you to enable unique identifier (UID) support.\n";
2105 print "\n";
2106
2107 if ( lc($uid_support) eq "true" ) {
2108 $default_value = "y";
2109 } else {
2110 $default_value = "n";
2111 }
2112 print "Enable Unique identifier (UID) support? (y/n) [$WHT$default_value$NRM]: $WHT";
2113 $uid_support = <STDIN>;
2114 if ( ( $uid_support =~ /^y\n/i ) || ( ( $uid_support =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2115 $uid_support = "true";
2116 } else {
2117 $uid_support = "false";
2118 }
2119 return $uid_support;
2120 }
2121
2122 sub command316 {
2123 print "This option allows you to change the name of the PHP session used\n";
2124 print "by SquirrelMail. Unless you know what you are doing, you probably\n";
2125 print "don't need or want to change this from the default of SQMSESSID.\n";
2126 print "[$WHT$session_name$NRM]: $WHT";
2127 $new_session_name = <STDIN>;
2128 chomp($new_session_name);
2129 if ( $new_session_name eq "\n" ) {
2130 $new_session_name = $session_name;
2131 }
2132 return $new_session_name;
2133 }
2134
2135
2136
2137 sub command41 {
2138 print "\nNow we will define the themes that you wish to use. If you have added\n";
2139 print "a theme of your own, just follow the instructions (?) about how to add\n";
2140 print "them. You can also change the default theme.\n";
2141 print "[theme] command (?=help) > ";
2142 $input = <STDIN>;
2143 $input =~ s/[\r|\n]//g;
2144 while ( $input ne "d" ) {
2145 if ( $input =~ /^\s*l\s*/i ) {
2146 $count = 0;
2147 while ( $count <= $#theme_name ) {
2148 if ( $count == $theme_default ) {
2149 print " *";
2150 } else {
2151 print " ";
2152 }
2153 $name = $theme_name[$count];
2154 $num_spaces = 25 - length($name);
2155 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
2156 $name = $name . " ";
2157 }
2158
2159 print " $count. $name";
2160 print "($theme_path[$count])\n";
2161
2162 $count++;
2163 }
2164 } elsif ( $input =~ /^\s*m\s*[0-9]+/i ) {
2165 $old_def = $theme_default;
2166 $theme_default = $input;
2167 $theme_default =~ s/^\s*m\s*//;
2168 if ( ( $theme_default > $#theme_name ) || ( $theme_default < 0 ) ) {
2169 print "Cannot set default theme to $theme_default. That theme does not exist.\n";
2170 $theme_default = $old_def;
2171 }
2172 } elsif ( $input =~ /^\s*\+/ ) {
2173 print "What is the name of this theme: ";
2174 $name = <STDIN>;
2175 $name =~ s/[\r|\n]//g;
2176 $theme_name[ $#theme_name + 1 ] = $name;
2177 print "Be sure to put ../themes/ before the filename.\n";
2178 print "What file is this stored in (ex: ../themes/default_theme.php): ";
2179 $name = <STDIN>;
2180 $name =~ s/[\r|\n]//g;
2181 $theme_path[ $#theme_path + 1 ] = $name;
2182 } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
2183 if ( $input =~ /[0-9]+\s*$/ ) {
2184 $rem_num = $input;
2185 $rem_num =~ s/^\s*-\s*//g;
2186 $rem_num =~ s/\s*$//;
2187 } else {
2188 $rem_num = $#theme_name;
2189 }
2190 if ( $rem_num == $theme_default ) {
2191 print "You cannot remove the default theme!\n";
2192 } else {
2193 $count = 0;
2194 @new_theme_name = ();
2195 @new_theme_path = ();
2196 while ( $count <= $#theme_name ) {
2197 if ( $count != $rem_num ) {
2198 @new_theme_name = ( @new_theme_name, $theme_name[$count] );
2199 @new_theme_path = ( @new_theme_path, $theme_path[$count] );
2200 }
2201 $count++;
2202 }
2203 @theme_name = @new_theme_name;
2204 @theme_path = @new_theme_path;
2205 if ( $theme_default > $rem_num ) {
2206 $theme_default--;
2207 }
2208 }
2209 } elsif ( $input =~ /^\s*t\s*/i ) {
2210 print "\nStarting detection...\n\n";
2211
2212 opendir( DIR, "../themes" );
2213 @files = grep { /\.php$/i } readdir(DIR);
2214 $cnt = 0;
2215 while ( $cnt <= $#files ) {
2216 $filename = "../themes/" . $files[$cnt];
2217 if ( $filename ne "../themes/index.php" ) {
2218 $found = 0;
2219 for ( $x = 0 ; $x <= $#theme_path ; $x++ ) {
2220 if ( $theme_path[$x] eq $filename ) {
2221 $found = 1;
2222 }
2223 }
2224 if ( $found != 1 ) {
2225 print "** Found theme: $filename\n";
2226 print " What is its name? ";
2227 $nm = <STDIN>;
2228 $nm =~ s/[\n|\r]//g;
2229 $theme_name[ $#theme_name + 1 ] = $nm;
2230 $theme_path[ $#theme_path + 1 ] = $filename;
2231 }
2232 }
2233 $cnt++;
2234 }
2235 print "\n";
2236 for ( $cnt = 0 ; $cnt <= $#theme_path ; $cnt++ ) {
2237 $filename = $theme_path[$cnt];
2238 if ( !( -e $filename ) ) {
2239 print " Removing $filename (file not found)\n";
2240 $offset = 0;
2241 @new_theme_name = ();
2242 @new_theme_path = ();
2243 for ( $x = 0 ; $x < $#theme_path ; $x++ ) {
2244 if ( $theme_path[$x] eq $filename ) {
2245 $offset = 1;
2246 }
2247 if ( $offset == 1 ) {
2248 $new_theme_name[$x] = $theme_name[ $x + 1 ];
2249 $new_theme_path[$x] = $theme_path[ $x + 1 ];
2250 } else {
2251 $new_theme_name[$x] = $theme_name[$x];
2252 $new_theme_path[$x] = $theme_path[$x];
2253 }
2254 }
2255 @theme_name = @new_theme_name;
2256 @theme_path = @new_theme_path;
2257 }
2258 }
2259 print "\nDetection complete!\n\n";
2260
2261 closedir DIR;
2262 } elsif ( $input =~ /^\s*\?\s*/ ) {
2263 print ".-------------------------.\n";
2264 print "| t (detect themes) |\n";
2265 print "| + (add theme) |\n";
2266 print "| - N (remove theme) |\n";
2267 print "| m N (mark default) |\n";
2268 print "| l (list themes) |\n";
2269 print "| d (done) |\n";
2270 print "`-------------------------'\n";
2271 }
2272 print "[theme] command (?=help) > ";
2273 $input = <STDIN>;
2274 $input =~ s/[\r|\n]//g;
2275 }
2276 }
2277
2278 # Theme - CSS file
2279 sub command42 {
2280 print "You may specify a cascading style-sheet (CSS) file to be included\n";
2281 print "on each html page generated by SquirrelMail. The CSS file is useful\n";
2282 print "for specifying a site-wide font. If you're not familiar with CSS\n";
2283 print "files, leave this blank.\n";
2284 print "\n";
2285 print "To clear out an existing value, just type a space for the input.\n";
2286 print "\n";
2287 print "Relative links to files outside the SquirrelMail distribution\n";
2288 print "will be converted to their absolute path equivalents in config.php.\n";
2289 print "\n";
2290 print "[$WHT$theme_css$NRM]: $WHT";
2291 $new_theme_css = <STDIN>;
2292
2293 if ( $new_theme_css eq "\n" ) {
2294 $new_theme_css = $theme_css;
2295 } else {
2296 $new_theme_css =~ s/[\r|\n]//g;
2297 }
2298 $new_theme_css =~ s/^\s*//;
2299 return $new_theme_css;
2300 }
2301
2302 sub command61 {
2303 print "You can now define different LDAP servers.\n";
2304 print "[ldap] command (?=help) > ";
2305 $input = <STDIN>;
2306 $input =~ s/[\r|\n]//g;
2307 while ( $input ne "d" ) {
2308 if ( $input =~ /^\s*l\s*/i ) {
2309 $count = 0;
2310 while ( $count <= $#ldap_host ) {
2311 print "$count. $ldap_host[$count]\n";
2312 print " base: $ldap_base[$count]\n";
2313 if ( $ldap_charset[$count] ) {
2314 print " charset: $ldap_charset[$count]\n";
2315 }
2316 if ( $ldap_port[$count] ) {
2317 print " port: $ldap_port[$count]\n";
2318 }
2319 if ( $ldap_name[$count] ) {
2320 print " name: $ldap_name[$count]\n";
2321 }
2322 if ( $ldap_maxrows[$count] ) {
2323 print " maxrows: $ldap_maxrows[$count]\n";
2324 }
2325 print "\n";
2326 $count++;
2327 }
2328 } elsif ( $input =~ /^\s*\+/ ) {
2329 $sub = $#ldap_host + 1;
2330
2331 print "First, we need to have the hostname or the IP address where\n";
2332 print "this LDAP server resides. Example: ldap.bigfoot.com\n";
2333 print "hostname: ";
2334 $name = <STDIN>;
2335 $name =~ s/[\r|\n]//g;
2336 $ldap_host[$sub] = $name;
2337
2338 print "\n";
2339
2340 print "Next, we need the server root (base dn). For this, an empty\n";
2341 print "string is allowed.\n";
2342 print "Example: ou=member_directory,o=netcenter.com\n";
2343 print "base: ";
2344 $name = <STDIN>;
2345 $name =~ s/[\r|\n]//g;
2346 $ldap_base[$sub] = $name;
2347
2348 print "\n";
2349
2350 print "This is the TCP/IP port number for the LDAP server. Default\n";
2351 print "port is 389. This is optional. Press ENTER for default.\n";
2352 print "port: ";
2353 $name = <STDIN>;
2354 $name =~ s/[\r|\n]//g;
2355 $ldap_port[$sub] = $name;
2356
2357 print "\n";
2358
2359 print "This is the charset for the server. Default is utf-8. This\n";
2360 print "is also optional. Press ENTER for default.\n";
2361 print "charset: ";
2362 $name = <STDIN>;
2363 $name =~ s/[\r|\n]//g;
2364 $ldap_charset[$sub] = $name;
2365
2366 print "\n";
2367
2368 print "This is the name for the server, used to tag the results of\n";
2369 print "the search. Default it \"LDAP: hostname\". Press ENTER for default\n";
2370 print "name: ";
2371 $name = <STDIN>;
2372 $name =~ s/[\r|\n]//g;
2373 $ldap_name[$sub] = $name;
2374
2375 print "\n";
2376
2377 print "You can specify the maximum number of rows in the search result.\n";
2378 print "Default is unlimited. Press ENTER for default.\n";
2379 print "maxrows: ";
2380 $name = <STDIN>;
2381 $name =~ s/[\r|\n]//g;
2382 $ldap_maxrows[$sub] = $name;
2383
2384 print "\n";
2385
2386 } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
2387 if ( $input =~ /[0-9]+\s*$/ ) {
2388 $rem_num = $input;
2389 $rem_num =~ s/^\s*-\s*//g;
2390 $rem_num =~ s/\s*$//;
2391 } else {
2392 $rem_num = $#ldap_host;
2393 }
2394 $count = 0;
2395 @new_ldap_host = ();
2396 @new_ldap_base = ();
2397 @new_ldap_port = ();
2398 @new_ldap_name = ();
2399 @new_ldap_charset = ();
2400 @new_ldap_maxrows = ();
2401
2402 while ( $count <= $#ldap_host ) {
2403 if ( $count != $rem_num ) {
2404 @new_ldap_host = ( @new_ldap_host, $ldap_host[$count] );
2405 @new_ldap_base = ( @new_ldap_base, $ldap_base[$count] );
2406 @new_ldap_port = ( @new_ldap_port, $ldap_port[$count] );
2407 @new_ldap_name = ( @new_ldap_name, $ldap_name[$count] );
2408 @new_ldap_charset = ( @new_ldap_charset, $ldap_charset[$count] );
2409 @new_ldap_maxrows = ( @new_ldap_maxrows, $ldap_maxrows[$count] );
2410 }
2411 $count++;
2412 }
2413 @ldap_host = @new_ldap_host;
2414 @ldap_base = @new_ldap_base;
2415 @ldap_port = @new_ldap_port;
2416 @ldap_name = @new_ldap_name;
2417 @ldap_charset = @new_ldap_charset;
2418 @ldap_maxrows = @new_ldap_maxrows;
2419 } elsif ( $input =~ /^\s*\?\s*/ ) {
2420 print ".-------------------------.\n";
2421 print "| + (add host) |\n";
2422 print "| - N (remove host) |\n";
2423 print "| l (list hosts) |\n";
2424 print "| d (done) |\n";
2425 print "`-------------------------'\n";
2426 }
2427 print "[ldap] command (?=help) > ";
2428 $input = <STDIN>;
2429 $input =~ s/[\r|\n]//g;
2430 }
2431 }
2432
2433 sub command62 {
2434 print "Some of our developers have come up with very good javascript interface\n";
2435 print "for searching through address books, however, our original goals said\n";
2436 print "that we would be 100% HTML. In order to make it possible to use their\n";
2437 print "interface, and yet stick with our goals, we have also written a plain\n";
2438 print "HTML version of the search. Here, you can choose which version to use.\n";
2439 print "\n";
2440 print "This is just the default value. It is also a user option that each\n";
2441 print "user can configure individually\n";
2442 print "\n";
2443
2444 if ( lc($default_use_javascript_addr_book) eq "true" ) {
2445 $default_value = "y";
2446 } else {
2447 $default_use_javascript_addr_book = "false";
2448 $default_value = "n";
2449 }
2450 print "Use javascript version by default (y/n) [$WHT$default_value$NRM]: $WHT";
2451 $new_show = <STDIN>;
2452 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2453 $default_use_javascript_addr_book = "true";
2454 } else {
2455 $default_use_javascript_addr_book = "false";
2456 }
2457 return $default_use_javascript_addr_book;
2458 }
2459
2460 sub command91 {
2461 print "If you want to store your users address book details in a database then\n";
2462 print "you need to set this DSN to a valid value. The format for this is:\n";
2463 print "mysql://user:pass\@hostname/dbname\n";
2464 print "Where mysql can be one of the databases PHP supports, the most common\n";
2465 print "of these are mysql, msql and pgsql\n";
2466 print "If the DSN is left empty (hit space and then return) the database\n";
2467 print "related code for address books will not be used\n";
2468 print "\n";
2469
2470 if ( $addrbook_dsn eq "" ) {
2471 $default_value = "Disabled";
2472 } else {
2473 $default_value = $addrbook_dsn;
2474 }
2475 print "[$WHT$addrbook_dsn$NRM]: $WHT";
2476 $new_dsn = <STDIN>;
2477 if ( $new_dsn eq "\n" ) {
2478 $new_dsn = "";
2479 } else {
2480 $new_dsn =~ s/[\r|\n]//g;
2481 $new_dsn =~ s/^\s+$//g;
2482 }
2483 return $new_dsn;
2484 }
2485
2486 sub command92 {
2487 print "This is the name of the table you want to store the address book\n";
2488 print "data in, it defaults to 'address'\n";
2489 print "\n";
2490 print "[$WHT$addrbook_table$NRM]: $WHT";
2491 $new_table = <STDIN>;
2492 if ( $new_table eq "\n" ) {
2493 $new_table = $addrbook_table;
2494 } else {
2495 $new_table =~ s/[\r|\n]//g;
2496 }
2497 return $new_table;
2498 }
2499
2500 sub command93 {
2501 print "If you want to store your users preferences in a database then\n";
2502 print "you need to set this DSN to a valid value. The format for this is:\n";
2503 print "mysql://user:pass\@hostname/dbname\n";
2504 print "Where mysql can be one of the databases PHP supports, the most common\n";
2505 print "of these are mysql, msql and pgsql\n";
2506 print "If the DSN is left empty (hit space and then return) the database\n";
2507 print "related code for address books will not be used\n";
2508 print "\n";
2509
2510 if ( $prefs_dsn eq "" ) {
2511 $default_value = "Disabled";
2512 } else {
2513 $default_value = $prefs_dsn;
2514 }
2515 print "[$WHT$prefs_dsn$NRM]: $WHT";
2516 $new_dsn = <STDIN>;
2517 if ( $new_dsn eq "\n" ) {
2518 $new_dsn = "";
2519 } else {
2520 $new_dsn =~ s/[\r|\n]//g;
2521 $new_dsn =~ s/^\s+$//g;
2522 }
2523 return $new_dsn;
2524 }
2525
2526 sub command94 {
2527 print "This is the name of the table you want to store the preferences\n";
2528 print "data in, it defaults to 'userprefs'\n";
2529 print "\n";
2530 print "[$WHT$prefs_table$NRM]: $WHT";
2531 $new_table = <STDIN>;
2532 if ( $new_table eq "\n" ) {
2533 $new_table = $prefs_table;
2534 } else {
2535 $new_table =~ s/[\r|\n]//g;
2536 }
2537 return $new_table;
2538 }
2539
2540 sub command95 {
2541 print "This is the name of the field in which you want to store the\n";
2542 print "username of the person the prefs are for. It default to 'user'\n";
2543 print "which clashes with a reserved keyword in PostgreSQL so this\n";
2544 print "will need to be changed for that database at least\n";
2545 print "\n";
2546 print "[$WHT$prefs_user_field$NRM]: $WHT";
2547 $new_field = <STDIN>;
2548 if ( $new_field eq "\n" ) {
2549 $new_field = $prefs_user_field;
2550 } else {
2551 $new_field =~ s/[\r|\n]//g;
2552 }
2553 return $new_field;
2554 }
2555
2556 sub command96 {
2557 print "This is the name of the field in which you want to store the\n";
2558 print "preferences keyword. It defaults to 'prefkey'\n";
2559 print "\n";
2560 print "[$WHT$prefs_key_field$NRM]: $WHT";
2561 $new_field = <STDIN>;
2562 if ( $new_field eq "\n" ) {
2563 $new_field = $prefs_key_field;
2564 } else {
2565 $new_field =~ s/[\r|\n]//g;
2566 }
2567 return $new_field;
2568 }
2569
2570 sub command97 {
2571 print "This is the name of the field in which you want to store the\n";
2572 print "preferences value. It defaults to 'prefval'\n";
2573 print "\n";
2574 print "[$WHT$prefs_val_field$NRM]: $WHT";
2575 $new_field = <STDIN>;
2576 if ( $new_field eq "\n" ) {
2577 $new_field = $prefs_val_field;
2578 } else {
2579 $new_field =~ s/[\r|\n]//g;
2580 }
2581 return $new_field;
2582 }
2583
2584 sub save_data {
2585 $tab = " ";
2586 if ( open( CF, ">config.php" ) ) {
2587 print CF "<?php\n";
2588 print CF "\n";
2589
2590 print CF "/**\n";
2591 print CF " * SquirrelMail Configuration File\n";
2592 print CF " * Created using the configure script, conf.pl\n";
2593 print CF " */\n";
2594 print CF "\n";
2595
2596 if ($print_config_version) {
2597 print CF "\$config_version = '$print_config_version';\n";
2598 }
2599 # integer
2600 print CF "\$config_use_color = $config_use_color;\n";
2601 print CF "\n";
2602
2603 # string
2604 print CF "\$org_name = \"$org_name\";\n";
2605 # string
2606 print CF "\$org_logo = " . &change_to_SM_path($org_logo) . ";\n";
2607 $org_logo_width |= 0;
2608 $org_logo_height |= 0;
2609 # string
2610 print CF "\$org_logo_width = '$org_logo_width';\n";
2611 # string
2612 print CF "\$org_logo_height = '$org_logo_height';\n";
2613 # string that can contain variables.
2614 print CF "\$org_title = \"$org_title\";\n";
2615 # string
2616 print CF "\$signout_page = " . &change_to_SM_path($signout_page) . ";\n";
2617 # string
2618 print CF "\$frame_top = '$frame_top';\n";
2619 print CF "\n";
2620
2621 print CF "\$provider_uri = '$provider_uri';\n";
2622 print CF "\n";
2623
2624 print CF "\$provider_name = '$provider_name';\n";
2625 print CF "\n";
2626
2627 # string that can contain variables
2628 print CF "\$motd = \"$motd\";\n";
2629 print CF "\n";
2630
2631 # string
2632 print CF "\$squirrelmail_default_language = '$squirrelmail_default_language';\n";
2633 print CF "\n";
2634
2635 # string
2636 print CF "\$domain = '$domain';\n";
2637 # string
2638 print CF "\$imapServerAddress = '$imapServerAddress';\n";
2639 # integer
2640 print CF "\$imapPort = $imapPort;\n";
2641 # boolean
2642 print CF "\$useSendmail = $useSendmail;\n";
2643 # string
2644 print CF "\$smtpServerAddress = '$smtpServerAddress';\n";
2645 # integer
2646 print CF "\$smtpPort = $smtpPort;\n";
2647 # string
2648 print CF "\$sendmail_path = '$sendmail_path';\n";
2649 # boolean
2650 # print CF "\$use_authenticated_smtp = $use_authenticated_smtp;\n";
2651 # boolean
2652 print CF "\$pop_before_smtp = $pop_before_smtp;\n";
2653 # string
2654 print CF "\$imap_server_type = '$imap_server_type';\n";
2655 # boolean
2656 print CF "\$invert_time = $invert_time;\n";
2657 # string
2658 print CF "\$optional_delimiter = '$optional_delimiter';\n";
2659 print CF "\n";
2660
2661 # string
2662 print CF "\$default_folder_prefix = '$default_folder_prefix';\n";
2663 # string
2664 print CF "\$trash_folder = '$trash_folder';\n";
2665 # string
2666 print CF "\$sent_folder = '$sent_folder';\n";
2667 # string
2668 print CF "\$draft_folder = '$draft_folder';\n";
2669 # boolean
2670 print CF "\$default_move_to_trash = $default_move_to_trash;\n";
2671 # boolean
2672 print CF "\$default_move_to_sent = $default_move_to_sent;\n";
2673 # boolean
2674 print CF "\$default_save_as_draft = $default_save_as_draft;\n";
2675 # boolean
2676 print CF "\$show_prefix_option = $show_prefix_option;\n";
2677 # boolean
2678 print CF "\$list_special_folders_first = $list_special_folders_first;\n";
2679 # boolean
2680 print CF "\$use_special_folder_color = $use_special_folder_color;\n";
2681 # boolean
2682 print CF "\$auto_expunge = $auto_expunge;\n";
2683 # boolean
2684 print CF "\$default_sub_of_inbox = $default_sub_of_inbox;\n";
2685 # boolean
2686 print CF "\$show_contain_subfolders_option = $show_contain_subfolders_option;\n";
2687 # integer
2688 print CF "\$default_unseen_notify = $default_unseen_notify;\n";
2689 # integer
2690 print CF "\$default_unseen_type = $default_unseen_type;\n";
2691 # boolean
2692 print CF "\$auto_create_special = $auto_create_special;\n";
2693 # boolean
2694 print CF "\$delete_folder = $delete_folder;\n";
2695 # boolean
2696 print CF "\$noselect_fix_enable = $noselect_fix_enable;\n";
2697
2698 print CF "\n";
2699
2700 # string
2701 print CF "\$default_charset = '$default_charset';\n";
2702 # string
2703 print CF "\$data_dir = " . &change_to_SM_path($data_dir) . ";\n";
2704 # string that can contain a variable
2705 print CF "\$attachment_dir = " . &change_to_SM_path($attachment_dir) . ";\n";
2706 # integer
2707 print CF "\$dir_hash_level = $dir_hash_level;\n";
2708 # string
2709 print CF "\$default_left_size = '$default_left_size';\n";
2710 # boolean
2711 print CF "\$force_username_lowercase = $force_username_lowercase;\n";
2712 # boolean
2713 print CF "\$default_use_priority = $default_use_priority;\n";
2714 # boolean
2715 print CF "\$hide_sm_attributions = $hide_sm_attributions;\n";
2716 # boolean
2717 print CF "\$default_use_mdn = $default_use_mdn;\n";
2718 # boolean
2719 print CF "\$edit_identity = $edit_identity;\n";
2720 # boolean
2721 print CF "\$edit_name = $edit_name;\n";
2722 # boolean
2723 print CF "\$allow_thread_sort = $allow_thread_sort;\n";
2724 # boolean
2725 print CF "\$allow_server_sort = $allow_server_sort;\n";
2726 # boolean
2727 print CF "\$allow_charset_search = $allow_charset_search;\n";
2728 # boolean
2729 print CF "\$uid_support = $uid_support;\n";
2730 print CF "\n";
2731
2732 # all plugins are strings
2733 for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
2734 print CF "\$plugins[$ct] = '$plugins[$ct]';\n";
2735 }
2736 print CF "\n";
2737
2738 # strings
2739 print CF "\$theme_css = " . &change_to_SM_path($theme_css) . ";\n";
2740 if ( $theme_default eq '' ) { $theme_default = '0'; }
2741 print CF "\$theme_default = $theme_default;\n";
2742
2743 for ( $count = 0 ; $count <= $#theme_name ; $count++ ) {
2744 print CF "\$theme[$count]['PATH'] = " . &change_to_SM_path($theme_path[$count]) . ";\n";
2745 print CF "\$theme[$count]['NAME'] = '$theme_name[$count]';\n";
2746 }
2747 print CF "\n";
2748
2749 if ( $default_use_javascript_addr_book ne "true" ) {
2750 $default_use_javascript_addr_book = "false";
2751 }
2752
2753 # boolean
2754 print CF "\$default_use_javascript_addr_book = $default_use_javascript_addr_book;\n";
2755 for ( $count = 0 ; $count <= $#ldap_host ; $count++ ) {
2756 print CF "\$ldap_server[$count] = array(\n";
2757 # string
2758 print CF " 'host' => '$ldap_host[$count]',\n";
2759 # string
2760 print CF " 'base' => '$ldap_base[$count]'";
2761 if ( $ldap_name[$count] ) {
2762 print CF ",\n";
2763 # string
2764 print CF " 'name' => '$ldap_name[$count]'";
2765 }
2766 if ( $ldap_port[$count] ) {
2767 print CF ",\n";
2768 # integer
2769 print CF " 'port' => $ldap_port[$count]";
2770 }
2771 if ( $ldap_charset[$count] ) {
2772 print CF ",\n";
2773 # string
2774 print CF " 'charset' => '$ldap_charset[$count]'";
2775 }
2776 if ( $ldap_maxrows[$count] ) {
2777 print CF ",\n";
2778 # integer
2779 print CF " 'maxrows' => $ldap_maxrows[$count]";
2780 }
2781 print CF "\n";
2782 print CF ");\n";
2783 print CF "\n";
2784 }
2785
2786 # string
2787 print CF "\$addrbook_dsn = '$addrbook_dsn';\n";
2788 # string
2789 print CF "\$addrbook_table = '$addrbook_table';\n\n";
2790 # string
2791 print CF "\$prefs_dsn = '$prefs_dsn';\n";
2792 # string
2793 print CF "\$prefs_table = '$prefs_table';\n";
2794 # string
2795 print CF "\$prefs_user_field = '$prefs_user_field';\n";
2796 # string
2797 print CF "\$prefs_key_field = '$prefs_key_field';\n";
2798 # string
2799 print CF "\$prefs_val_field = '$prefs_val_field';\n";
2800 # boolean
2801 print CF "\$no_list_for_subscribe = $no_list_for_subscribe;\n";
2802
2803 # string
2804 print CF "\$smtp_auth_mech = '$smtp_auth_mech';\n";
2805 print CF "\$imap_auth_mech = '$imap_auth_mech';\n";
2806 # boolean
2807 print CF "\$use_imap_tls = $use_imap_tls;\n";
2808 print CF "\$use_smtp_tls = $use_smtp_tls;\n";
2809
2810 print CF "\$session_name = '$session_name';\n";
2811
2812 print CF "\n";
2813 print CF "\@include SM_PATH . 'config/config_local.php';\n";
2814
2815 print CF "\n/**\n";
2816 print CF " * Make sure there are no characters after the PHP closing\n";
2817 print CF " * tag below (including newline characters and whitespace).\n";
2818 print CF " * Otherwise, that character will cause the headers to be\n";
2819 print CF " * sent and regular output to begin, which will majorly screw\n";
2820 print CF " * things up when we try to send more headers later.\n";
2821 print CF " */\n";
2822 print CF "?>";
2823
2824 close CF;
2825
2826 print "Data saved in config.php\n";
2827 } else {
2828 print "Error saving config.php: $!\n";
2829 }
2830 }
2831
2832 sub set_defaults {
2833 system "clear";
2834 print $WHT. "SquirrelMail Configuration : " . $NRM;
2835 if ( $config == 1 ) { print "Read: config.php"; }
2836 elsif ( $config == 2 ) { print "Read: config_default.php"; }
2837 print "\n";
2838 print "---------------------------------------------------------\n";
2839
2840 print "While we have been building SquirrelMail, we have discovered some\n";
2841 print "preferences that work better with some servers that don't work so\n";
2842 print "well with others. If you select your IMAP server, this option will\n";
2843 print "set some pre-defined settings for that server.\n";
2844 print "\n";
2845 print "Please note that you will still need to go through and make sure\n";
2846 print "everything is correct. This does not change everything. There are\n";
2847 print "only a few settings that this will change.\n";
2848 print "\n";
2849
2850 $continue = 0;
2851 while ( $continue != 1 ) {
2852 print "Please select your IMAP server:\n";
2853 print " cyrus = Cyrus IMAP server\n";
2854 print " uw = University of Washington's IMAP server\n";
2855 print " exchange = Microsoft Exchange IMAP server\n";
2856 print " courier = Courier IMAP server\n";
2857 print " macosx = Mac OS X Mailserver\n";
2858 print " quit = Do not change anything\n";
2859 print "Command >> ";
2860 $server = <STDIN>;
2861 $server =~ s/[\r|\n]//g;
2862
2863 print "\n";
2864 if ( $server eq "cyrus" ) {
2865 $imap_server_type = "cyrus";
2866 $default_folder_prefix = "";
2867 $trash_folder = "INBOX.Trash";
2868 $sent_folder = "INBOX.Sent";
2869 $draft_folder = "INBOX.Drafts";
2870 $show_prefix_option = false;
2871 $default_sub_of_inbox = true;
2872 $show_contain_subfolders_option = false;
2873 $optional_delimiter = ".";
2874 $disp_default_folder_prefix = "<none>";
2875
2876 $continue = 1;
2877 } elsif ( $server eq "uw" ) {
2878 $imap_server_type = "uw";
2879 $default_folder_prefix = "mail/";
2880 $trash_folder = "Trash";
2881 $sent_folder = "Sent";
2882 $draft_folder = "Drafts";
2883 $show_prefix_option = true;
2884 $default_sub_of_inbox = false;
2885 $show_contain_subfolders_option = true;
2886 $optional_delimiter = "/";
2887 $disp_default_folder_prefix = $default_folder_prefix;
2888
2889 $continue = 1;
2890 } elsif ( $server eq "exchange" ) {
2891 $imap_server_type = "exchange";
2892 $default_folder_prefix = "";
2893 $default_sub_of_inbox = true;
2894 $trash_folder = "INBOX/Deleted Items";
2895 $sent_folder = "INBOX/Sent Items";
2896 $drafts_folder = "INBOX/Drafts";
2897 $show_prefix_option = false;
2898 $show_contain_subfolders_option = false;
2899 $optional_delimiter = "detect";
2900 $disp_default_folder_prefix = "<none>";
2901
2902 $continue = 1;
2903 } elsif ( $server eq "courier" ) {
2904 $imap_server_type = "courier";
2905 $default_folder_prefix = "INBOX.";
2906 $trash_folder = "Trash";
2907 $sent_folder = "Sent";
2908 $draft_folder = "Drafts";
2909 $show_prefix_option = false;
2910 $default_sub_of_inbox = false;
2911 $show_contain_subfolders_option = false;
2912 $optional_delimiter = ".";
2913 $disp_default_folder_prefix = $default_folder_prefix;
2914
2915 $continue = 1;
2916 } elsif ( $server eq "macosx" ) {
2917 $imap_server_type = "macosx";
2918 $default_folder_prefix = "INBOX/";
2919 $trash_folder = "Trash";
2920 $sent_folder = "Sent";
2921 $draft_folder = "Drafts";
2922 $show_prefix_option = false;
2923 $default_sub_of_inbox = true;
2924 $show_contain_subfolders_option = false;
2925 $optional_delimiter = "detect";
2926 $allow_charset_search = false;
2927 $disp_default_folder_prefix = $default_folder_prefix;
2928
2929 $continue = 1;
2930 } elsif ( $server eq "quit" ) {
2931 $continue = 1;
2932 } else {
2933 $disp_default_folder_prefix = $default_folder_prefix;
2934 print "Unrecognized server: $server\n";
2935 print "\n";
2936 }
2937
2938 print " imap_server_type = $imap_server_type\n";
2939 print " default_folder_prefix = $disp_default_folder_prefix\n";
2940 print " trash_folder = $trash_folder\n";
2941 print " sent_folder = $sent_folder\n";
2942 print " draft_folder = $draft_folder\n";
2943 print " show_prefix_option = $show_prefix_option\n";
2944 print " default_sub_of_inbox = $default_sub_of_inbox\n";
2945 print "show_contain_subfolders_option = $show_contain_subfolders_option\n";
2946 print " optional_delimiter = $optional_delimiter\n";
2947 }
2948 print "\nPress any key to continue...";
2949 $tmp = <STDIN>;
2950 }
2951
2952 ############################################################
2953 # This subroutine corrects relative paths to ensure they
2954 # will work within the SM space. If the path falls within
2955 # the SM directory tree, the SM_PATH variable will be
2956 # prepended to the path, if not, then the path will be
2957 # converted to an absolute path.
2958 ############################################################
2959 sub change_to_SM_path() {
2960 my ($old_path) = @_;
2961 my $new_path = '';
2962 my @rel_path;
2963 my @abs_path;
2964 my $subdir;
2965
2966 # If the path is absolute, don't bother.
2967 return "\'" . $old_path . "\'" if ( $old_path eq '');
2968 return "\'" . $old_path . "\'" if ( $old_path =~ /^\// );
2969 return $old_path if ( $old_path =~ /^\$/);
2970 return $old_path if ( $old_path =~ /^SM_PATH/ );
2971
2972 # For relative paths, split on '../'
2973 @rel_path = split(/\.\.\//, $old_path);
2974
2975 if ( $#rel_path > 1 ) {
2976 # more than two levels away. Make it absolute.
2977 @abs_path = split(/\//, $dir);
2978 foreach $subdir (@rel_path) {
2979 if ($subdir eq '') {
2980 pop @abs_path;
2981 } else {
2982 push @abs_path, $subdir;
2983 }
2984 }
2985 foreach $subdir (@abs_path) {
2986 $new_path .= $subdir . '/';
2987 }
2988 } elsif ( $#rel_path > 0 ) {
2989 # it's within the SM tree, prepend SM_PATH
2990 $new_path = $old_path;
2991 $new_path =~ s/^\.\.\//SM_PATH . \'/;
2992 $new_path .= '\'';
2993 } else {
2994 # Last, it's a relative path without any leading '.'
2995 # Prepend SM_PATH (no substitution required)
2996 $new_path = "SM_PATH . \'" . $old_path . "\'";
2997 }
2998
2999 return $new_path;
3000 }
3001
3002 sub change_to_rel_path() {
3003 my ($old_path) = @_;
3004 my $new_path = '';
3005
3006 return $old_path if ( $old_path eq '');
3007 return $old_path if ( $old_path =~ /^\$/ );
3008 return $old_path if ( $old_path =~ /^\// );
3009 return $old_path if ( $old_path =~ /^\.\./ );
3010
3011 if ( $old_path =~ /^SM_PATH/ ) {
3012 $new_path = $old_path;
3013 $new_path =~ s/^SM_PATH . \'/\.\.\//;
3014 }
3015
3016 return $new_path;
3017 }
3018
3019 sub detect_auth_support {
3020 # Attempts to auto-detect if a specific auth mechanism is supported.
3021 # Called by 'command112a' and 'command112b'
3022 # ARGS: service-name (IMAP or SMTP), host:port, mech-name (ie. CRAM-MD5)
3023
3024 # Misc setup
3025 use IO::Socket;
3026 my $service = shift;
3027 my $host = shift;
3028 my $mech = shift;
3029 # Sanity checks
3030 if ((!defined($service)) or (!defined($host)) or (!defined($mech))) {
3031 # Error - wrong # of args
3032 print "BAD ARGS!\n";
3033 return undef;
3034 }
3035
3036 if ($service eq 'SMTP') {
3037 $cmd = "AUTH $mech\n";
3038 $logout = "QUIT\n";
3039 } elsif ($service eq 'IMAP') {
3040 $cmd = "A01 AUTHENTICATE $mech\n";
3041 $logout = "C01 LOGOUT\n";
3042 } else {
3043 # unknown service - whoops.
3044 return undef;
3045 }
3046
3047 # Get this show on the road
3048 my $sock=IO::Socket::INET->new($host);
3049 if (!defined($sock)) {
3050 # Connect failed
3051 return undef;
3052 }
3053 my $discard = <$sock>; # Server greeting/banner - who cares..
3054 print $sock $cmd;
3055
3056 my $response = <$sock>;
3057 if (!defined($response)) {
3058 return undef;
3059 }
3060
3061 # So at this point, we have a response, and it is (hopefully) valid.
3062 if ($service eq 'SMTP') {
3063 if (($response =~ /^535/) or ($response =~/^502/)) {
3064 # Not supported
3065 close $sock;
3066 return 'NO';
3067 }
3068 } elsif ($service eq 'IMAP') {
3069 if ($response =~ /^A01/) {
3070 # Not supported
3071 close $sock;
3072 return 'NO';
3073 }
3074 } else {
3075 # Unknown service - this shouldn't be able to happen.
3076 close $sock;
3077 return undef;
3078 }
3079
3080 # If it gets here, the mech is supported
3081 print $sock "*\n"; # Attempt to cancel authentication
3082 print $sock $logout; # Try to log out, but we don't really care if this fails
3083 close $sock;
3084 return 'YES';
3085 }