d98b9aff126ffd6a6b115963f918863175c952f1
[squirrelmail.git] / config / conf.pl
1 #!/usr/bin/env perl
2 # conf.pl
3 #
4 # Copyright (c) 1999-2007 The SquirrelMail Project Team
5 # Licensed under the GNU GPL. For full terms see COPYING.
6 #
7 # A simple configure script to configure SquirrelMail
8 #
9 # $Id$
10 ############################################################
11 $conf_pl_version = "1.5.0";
12
13 ############################################################
14 # Check what directory we're supposed to be running in, and
15 # change there if necessary. File::Basename has been in
16 # Perl since at least 5.003_7, and nobody sane runs anything
17 # before that, but just in case.
18 ############################################################
19 my $dir;
20 if ( eval q{require "File/Basename.pm"} ) {
21 $dir = File::Basename::dirname($0);
22 chdir($dir);
23 }
24
25 ############################################################
26 # Some people try to run this as a CGI. That's wrong!
27 ############################################################
28 if ( defined( $ENV{'PATH_INFO'} )
29 || defined( $ENV{'QUERY_STRING'} )
30 || defined( $ENV{'REQUEST_METHOD'} ) ) {
31 print "Content-Type: text/html\n\n";
32 print "You must run this script from the command line.";
33 exit;
34 }
35
36 ############################################################
37 # If we got here, use Cwd to get the full directory path
38 # (the Basename stuff above will sometimes return '.' as
39 # the base directory, which is not helpful here).
40 ############################################################
41 use Cwd;
42 $dir = cwd();
43
44
45 ############################################################
46 # First, lets read in the data already in there...
47 ############################################################
48 if ( -e "config.php" ) {
49 # Make sure that file is readable
50 if (! -r "config.php") {
51 clear_screen();
52 print "WARNING:\n";
53 print "The file \"config/config.php\" was found, but you don't\n";
54 print "have rights to read it.\n";
55 print "\n";
56 print "Press enter to continue";
57 $ctu = <STDIN>;
58 exit;
59 }
60 open( FILE, "config.php" );
61 while ( $line = <FILE> ) {
62 $line =~ s/^\s+//;
63 $line =~ s/^\$//;
64 $var = $line;
65
66 $var =~ s/=/EQUALS/;
67 if ( $var =~ /^([a-z])/i ) {
68 @o = split ( /\s*EQUALS\s*/, $var );
69 if ( $o[0] eq "config_version" ) {
70 $o[1] =~ s/[\n\r]//g;
71 $o[1] =~ s/[\'\"];\s*$//;
72 $o[1] =~ s/;$//;
73 $o[1] =~ s/^[\'\"]//;
74
75 $config_version = $o[1];
76 close(FILE);
77 }
78 }
79 }
80 close(FILE);
81
82 if ( $config_version ne $conf_pl_version ) {
83 clear_screen();
84 print "WARNING:\n";
85 print " The file \"config/config.php\" was found, but it is for\n";
86 print " an older version of SquirrelMail. It is possible to still\n";
87 print " read the defaults from this file but be warned that many\n";
88 print " preferences change between versions. It is recommended that\n";
89 print " you start with a clean config.php for each upgrade that you\n";
90 print " do. To do this, just move config/config.php out of the way.\n";
91 print "\n";
92 print "Continue loading with the old config.php [y/N]? ";
93 $ctu = <STDIN>;
94
95 if ( ( $ctu !~ /^y\n/i ) || ( $ctu =~ /^\n/ ) ) {
96 exit;
97 }
98
99 print "\nDo you want me to stop warning you [y/N]? ";
100 $ctu = <STDIN>;
101 if ( $ctu =~ /^y\n/i ) {
102 $print_config_version = $conf_pl_version;
103 } else {
104 $print_config_version = $config_version;
105 }
106 } else {
107 $print_config_version = $config_version;
108 }
109
110 $config = 1;
111 open( FILE, "config.php" );
112 } elsif ( -e "config_default.php" ) {
113 open( FILE, "config_default.php" );
114 while ( $line = <FILE> ) {
115 $line =~ s/^\s+//;
116 $line =~ s/^\$//;
117 $var = $line;
118
119 $var =~ s/=/EQUALS/;
120 if ( $var =~ /^([a-z])/i ) {
121 @o = split ( /\s*EQUALS\s*/, $var );
122 if ( $o[0] eq "config_version" ) {
123 $o[1] =~ s/[\n\r]//g;
124 $o[1] =~ s/[\'\"];\s*$//;
125 $o[1] =~ s/;$//;
126 $o[1] =~ s/^[\'\"]//;
127
128 $config_version = $o[1];
129 close(FILE);
130 }
131 }
132 }
133 close(FILE);
134
135 if ( $config_version ne $conf_pl_version ) {
136 clear_screen();
137 print "WARNING:\n";
138 print " You are trying to use a 'config_default.php' from an older\n";
139 print " version of SquirrelMail. This is HIGHLY unrecommended. You\n";
140 print " should get the 'config_default.php' that matches the version\n";
141 print " of SquirrelMail that you are running. You can get this from\n";
142 print " the SquirrelMail web page by going to the following URL:\n";
143 print " http://squirrelmail.org.\n";
144 print "\n";
145 print "Continue loading with old config_default.php (a bad idea) [y/N]? ";
146 $ctu = <STDIN>;
147
148 if ( ( $ctu !~ /^y\n/i ) || ( $ctu =~ /^\n/ ) ) {
149 exit;
150 }
151
152 print "\nDo you want me to stop warning you [y/N]? ";
153 $ctu = <STDIN>;
154 if ( $ctu =~ /^y\n/i ) {
155 $print_config_version = $conf_pl_version;
156 } else {
157 $print_config_version = $config_version;
158 }
159 } else {
160 $print_config_version = $config_version;
161 }
162 $config = 2;
163 open( FILE, "config_default.php" );
164 } else {
165 print "No configuration file found. Please get config_default.php\n";
166 print "or config.php before running this again. This program needs\n";
167 print "a default config file to get default values.\n";
168 exit;
169 }
170
171 # Read and parse the current configuration file
172 # (either config.php or config_default.php).
173 while ( $line = <FILE> ) {
174 $line =~ s/^\s+//;
175 $line =~ s/^\$//;
176 $var = $line;
177
178 $var =~ s/=/EQUALS/;
179 if ( $var =~ /^([a-z])/i ) {
180 @options = split ( /\s*EQUALS\s*/, $var );
181 $options[1] =~ s/[\n\r]//g;
182 $options[1] =~ s/[\'\"];\s*$//;
183 $options[1] =~ s/;$//;
184 $options[1] =~ s/^[\'\"]//;
185 # de-escape escaped strings
186 $options[1] =~ s/\\'/'/g;
187 $options[1] =~ s/\\\\/\\/g;
188
189 if ( $options[0] =~ /^user_themes\[[0-9]+\]\[['"]PATH['"]\]/ ) {
190 $sub = $options[0];
191 $sub =~ s/\]\[['"]PATH['"]\]//;
192 $sub =~ s/.*\[//;
193 if ( -e "../css/" ) {
194 $options[1] =~ s/^\.\.\/config/\.\.\/css/;
195 }
196 $user_theme_path[$sub] = &change_to_rel_path($options[1]);
197 } elsif ( $options[0] =~ /^user_themes\[[0-9]+\]\[['"]NAME['"]\]/ ) {
198 $sub = $options[0];
199 $sub =~ s/\]\[['"]NAME['"]\]//;
200 $sub =~ s/.*\[//;
201 $user_theme_name[$sub] = $options[1];
202 } elsif ( $options[0] =~ /^icon_themes\[[0-9]+\]\[['"]PATH['"]\]/ ) {
203 $sub = $options[0];
204 $sub =~ s/\]\[['"]PATH['"]\]//;
205 $sub =~ s/.*\[//;
206 if ( -e "../images/" ) {
207 $options[1] =~ s/^\.\.\/config/\.\.\/images/;
208 }
209 $icon_theme_path[$sub] = &change_to_rel_path($options[1]);
210 } elsif ( $options[0] =~ /^icon_themes\[[0-9]+\]\[['"]NAME['"]\]/ ) {
211 $sub = $options[0];
212 $sub =~ s/\]\[['"]NAME['"]\]//;
213 $sub =~ s/.*\[//;
214 $icon_theme_name[$sub] = $options[1];
215 } elsif ( $options[0] =~ /^aTemplateSet\[[0-9]+\]\[['"]ID['"]\]/ ) {
216 $sub = $options[0];
217 $sub =~ s/\]\[['"]ID['"]\]//;
218 $sub =~ s/.*\[//;
219 if ( -e "../templates" ) {
220 $options[1] =~ s/^\.\.\/config/\.\.\/templates/;
221 }
222 $templateset_id[$sub] = $options[1];
223 ##### FIXME: This section BELOW here so old prefs files don't blow up when running conf.pl
224 ##### Remove after a month or two
225 } elsif ( $options[0] =~ /^aTemplateSet\[[0-9]+\]\[['"]PATH['"]\]/ ) {
226 $sub = $options[0];
227 $sub =~ s/\]\[['"]PATH['"]\]//;
228 $sub =~ s/.*\[//;
229 if ( -e "../templates" ) {
230 $options[1] =~ s/^\.\.\/config/\.\.\/templates/;
231 }
232 $templateset_id[$sub] = $options[1];
233 ##### FIXME: This section ABOVE here so old prefs files don't blow up when running conf.pl
234 ##### Remove after a month or two
235 } elsif ( $options[0] =~ /^aTemplateSet\[[0-9]+\]\[['"]NAME['"]\]/ ) {
236 $sub = $options[0];
237 $sub =~ s/\]\[['"]NAME['"]\]//;
238 $sub =~ s/.*\[//;
239 $templateset_name[$sub] = $options[1];
240 } elsif ( $options[0] =~ /^plugins\[[0-9]*\]/ ) {
241 $sub = $options[0];
242 $sub =~ s/\]//;
243 $sub =~ s/^plugins\[//;
244 if ($sub eq '') {
245 push @plugins, $options[1];
246 } else {
247 $plugins[$sub] = $options[1];
248 }
249 } elsif ($options[0] =~ /^fontsets\[\'[a-z]*\'\]/) {
250 # parse associative $fontsets array
251 $sub = $options[0];
252 $sub =~ s/\'\]//;
253 $sub =~ s/^fontsets\[\'//;
254 $fontsets{$sub} = $options[1];
255 } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['"]PATH|NAME['"]\]/ ) {
256 ##
257 ## $color themes are no longer supported. Please leave this
258 ## so conf.pl doesn't barf if it encounters a $theme.
259 ##
260 } elsif ( $options[0] =~ /^ldap_server\[[0-9]+\]/ ) {
261 $sub = $options[0];
262 $sub =~ s/\]//;
263 $sub =~ s/^ldap_server\[//;
264 $continue = 0;
265 while ( ( $tmp = <FILE> ) && ( $continue != 1 ) ) {
266 if ( $tmp =~ /\);\s*$/ ) {
267 $continue = 1;
268 }
269
270 if ( $tmp =~ /^\s*[\'\"]host[\'\"]/i ) {
271 $tmp =~ s/^\s*[\'\"]host[\'\"]\s*=>\s*[\'\"]//i;
272 $tmp =~ s/[\'\"],?\s*$//;
273 $tmp =~ s/[\'\"]\);\s*$//;
274 $host = $tmp;
275 } elsif ( $tmp =~ /^\s*[\'\"]base[\'\"]/i ) {
276 $tmp =~ s/^\s*[\'\"]base[\'\"]\s*=>\s*[\'\"]//i;
277 $tmp =~ s/[\'\"],?\s*$//;
278 $tmp =~ s/[\'\"]\);\s*$//;
279 $base = $tmp;
280 } elsif ( $tmp =~ /^\s*[\'\"]charset[\'\"]/i ) {
281 $tmp =~ s/^\s*[\'\"]charset[\'\"]\s*=>\s*[\'\"]//i;
282 $tmp =~ s/[\'\"],?\s*$//;
283 $tmp =~ s/[\'\"]\);\s*$//;
284 $charset = $tmp;
285 } elsif ( $tmp =~ /^\s*[\'\"]port[\'\"]/i ) {
286 $tmp =~ s/^\s*[\'\"]port[\'\"]\s*=>\s*[\'\"]?//i;
287 $tmp =~ s/[\'\"]?,?\s*$//;
288 $tmp =~ s/[\'\"]?\);\s*$//;
289 $port = $tmp;
290 } elsif ( $tmp =~ /^\s*[\'\"]maxrows[\'\"]/i ) {
291 $tmp =~ s/^\s*[\'\"]maxrows[\'\"]\s*=>\s*[\'\"]?//i;
292 $tmp =~ s/[\'\"]?,?\s*$//;
293 $tmp =~ s/[\'\"]?\);\s*$//;
294 $maxrows = $tmp;
295 } elsif ( $tmp =~ /^\s*[\'\"]filter[\'\"]/i ) {
296 $tmp =~ s/^\s*[\'\"]filter[\'\"]\s*=>\s*[\'\"]?//i;
297 $tmp =~ s/[\'\"]?,?\s*$//;
298 $tmp =~ s/[\'\"]?\);\s*$//;
299 $filter = $tmp;
300 } elsif ( $tmp =~ /^\s*[\'\"]name[\'\"]/i ) {
301 $tmp =~ s/^\s*[\'\"]name[\'\"]\s*=>\s*[\'\"]//i;
302 $tmp =~ s/[\'\"],?\s*$//;
303 $tmp =~ s/[\'\"]\);\s*$//;
304 $name = $tmp;
305 } elsif ( $tmp =~ /^\s*[\'\"]binddn[\'\"]/i ) {
306 $tmp =~ s/^\s*[\'\"]binddn[\'\"]\s*=>\s*[\'\"]//i;
307 $tmp =~ s/[\'\"],?\s*$//;
308 $tmp =~ s/[\'\"]\);\s*$//;
309 $binddn = $tmp;
310 } elsif ( $tmp =~ /^\s*[\'\"]bindpw[\'\"]/i ) {
311 $tmp =~ s/^\s*[\'\"]bindpw[\'\"]\s*=>\s*[\'\"]//i;
312 $tmp =~ s/[\'\"],?\s*$//;
313 $tmp =~ s/[\'\"]\);\s*$//;
314 $bindpw = $tmp;
315 } elsif ( $tmp =~ /^\s*[\'\"]protocol[\'\"]/i ) {
316 $tmp =~ s/^\s*[\'\"]protocol[\'\"]\s*=>\s*[\'\"]?//i;
317 $tmp =~ s/[\'\"]?,?\s*$//;
318 $tmp =~ s/[\'\"]?\);\s*$//;
319 $protocol = $tmp;
320 } elsif ( $tmp =~ /^\s*[\'\"]limit_scope[\'\"]/i ) {
321 $tmp =~ s/^\s*[\'\"]limit_scope[\'\"]\s*=>\s*[\'\"]?//i;
322 $tmp =~ s/[\'\"]?,?\s*$//;
323 $tmp =~ s/[\'\"]?\);\s*$//;
324 $limit_scope = $tmp;
325 } elsif ( $tmp =~ /^\s*[\'\"]listing[\'\"]/i ) {
326 $tmp =~ s/^\s*[\'\"]listing[\'\"]\s*=>\s*[\'\"]?//i;
327 $tmp =~ s/[\'\"]?,?\s*$//;
328 $tmp =~ s/[\'\"]?\);\s*$//;
329 $listing = $tmp;
330 } elsif ( $tmp =~ /^\s*[\'\"]writeable[\'\"]/i ) {
331 $tmp =~ s/^\s*[\'\"]writeable[\'\"]\s*=>\s*[\'\"]?//i;
332 $tmp =~ s/[\'\"]?,?\s*$//;
333 $tmp =~ s/[\'\"]?\);\s*$//;
334 $writeable = $tmp;
335 } elsif ( $tmp =~ /^\s*[\'\"]search_tree[\'\"]/i ) {
336 $tmp =~ s/^\s*[\'\"]search_tree[\'\"]\s*=>\s*[\'\"]?//i;
337 $tmp =~ s/[\'\"]?,?\s*$//;
338 $tmp =~ s/[\'\"]?\);\s*$//;
339 $search_tree = $tmp;
340 } elsif ( $tmp =~ /^\s*[\'\"]starttls[\'\"]/i ) {
341 $tmp =~ s/^\s*[\'\"]starttls[\'\"]\s*=>\s*[\'\"]?//i;
342 $tmp =~ s/[\'\"]?,?\s*$//;
343 $tmp =~ s/[\'\"]?\);\s*$//;
344 $starttls = $tmp;
345 }
346 }
347 $ldap_host[$sub] = $host;
348 $ldap_base[$sub] = $base;
349 $ldap_name[$sub] = $name;
350 $ldap_port[$sub] = $port;
351 $ldap_maxrows[$sub] = $maxrows;
352 $ldap_filter[$sub] = $filter;
353 $ldap_charset[$sub] = $charset;
354 $ldap_binddn[$sub] = $binddn;
355 $ldap_bindpw[$sub] = $bindpw;
356 $ldap_protocol[$sub] = $protocol;
357 $ldap_limit_scope[$sub] = $limit_scope;
358 $ldap_listing[$sub] = $listing;
359 $ldap_writeable[$sub] = $writeable;
360 $ldap_search_tree[$sub] = $search_tree;
361 $ldap_starttls[$sub] = $starttls;
362 } elsif ( $options[0] =~ /^(data_dir|attachment_dir|org_logo|signout_page|icon_theme_def)$/ ) {
363 ${ $options[0] } = &change_to_rel_path($options[1]);
364 } else {
365 ${ $options[0] } = $options[1];
366 }
367 }
368 }
369 close FILE;
370
371 # FIXME: unknown introduction date
372 $useSendmail = 'false' if ( lc($useSendmail) ne 'true' );
373 $sendmail_path = "/usr/sbin/sendmail" if ( !$sendmail_path );
374 $pop_before_smtp = 'false' if ( !$pop_before_smtp );
375 $default_unseen_notify = 2 if ( !$default_unseen_notify );
376 $default_unseen_type = 1 if ( !$default_unseen_type );
377 $config_use_color = 0 if ( !$config_use_color );
378 $invert_time = 'false' if ( !$invert_time );
379 $force_username_lowercase = 'false' if ( !$force_username_lowercase );
380 $optional_delimiter = "detect" if ( !$optional_delimiter );
381 $auto_create_special = 'false' if ( !$auto_create_special );
382 $default_use_priority = 'true' if ( !$default_use_priority );
383 $default_use_mdn = 'true' if ( !$default_use_mdn );
384 $delete_folder = 'false' if ( !$delete_folder );
385 $noselect_fix_enable = 'false' if ( !$noselect_fix_enable );
386 $frame_top = "_top" if ( !$frame_top );
387 $provider_uri = '' if ( !$provider_uri );
388 $provider_name = '' if ( !$provider_name || $provider_name eq 'SquirrelMail');
389 $no_list_for_subscribe = 'false' if ( !$no_list_for_subscribe );
390 $allow_charset_search = 'true' if ( !$allow_charset_search );
391 $allow_advanced_search = 0 if ( !$allow_advanced_search) ;
392 $prefs_user_field = 'user' if ( !$prefs_user_field );
393 $prefs_key_field = 'prefkey' if ( !$prefs_key_field );
394 $prefs_val_field = 'prefval' if ( !$prefs_val_field );
395 $session_name = 'SQMSESSID' if ( !$session_name );
396 $skip_SM_header = 'false' if ( !$skip_SM_header );
397 $default_use_javascript_addr_book = 'false' if (! $default_use_javascript_addr_book);
398
399 # since 1.2.0
400 $hide_sm_attributions = 'false' if ( !$hide_sm_attributions );
401 # since 1.2.5
402 $edit_identity = 'true' if ( !$edit_identity );
403 $edit_name = 'true' if ( !$edit_name );
404
405 # since 1.4.0
406 $use_smtp_tls= 'false' if ( !$use_smtp_tls);
407 $smtp_auth_mech = 'none' if ( !$smtp_auth_mech );
408 $use_imap_tls = 'false' if ( !$use_imap_tls );
409 $imap_auth_mech = 'login' if ( !$imap_auth_mech );
410
411 # since 1.5.0
412 $show_alternative_names = 'false' if ( !$show_alternative_names );
413 # $available_languages option available only in 1.5.0. removed due to $languages
414 # implementation changes. options are provided by limit_languages plugin
415 # $available_languages = 'all' if ( !$available_languages );
416 $aggressive_decoding = 'false' if ( !$aggressive_decoding );
417 # available only in 1.5.0 and 1.5.1
418 # $advanced_tree = 'false' if ( !$advanced_tree );
419 $use_php_recode = 'false' if ( !$use_php_recode );
420 $use_php_iconv = 'false' if ( !$use_php_iconv );
421
422 # since 1.5.1
423 $use_icons = 'false' if ( !$use_icons );
424 $use_iframe = 'false' if ( !$use_iframe );
425 $lossy_encoding = 'false' if ( !$lossy_encoding );
426 $allow_remote_configtest = 'false' if ( !$allow_remote_configtest );
427 $addrbook_global_table = 'global_abook' if ( !$addrbook_global_table );
428 $addrbook_global_writeable = 'false' if ( !$addrbook_global_writeable );
429 $addrbook_global_listing = 'false' if ( !$addrbook_global_listing );
430 $abook_global_file = '' if ( !$abook_global_file);
431 $abook_global_file_writeable = 'false' if ( !$abook_global_file_writeable);
432 $abook_global_file_listing = 'true' if ( !$abook_global_file_listing );
433 $encode_header_key = '' if ( !$encode_header_key );
434 $hide_auth_header = 'false' if ( !$hide_auth_header );
435 $time_zone_type = '0' if ( !$time_zone_type );
436 $prefs_user_size = 128 if ( !$prefs_user_size );
437 $prefs_key_size = 64 if ( !$prefs_key_size );
438 $prefs_val_size = 65536 if ( !$prefs_val_size );
439
440 # add qmail-inject test here for backwards compatibility
441 if ( !$sendmail_args && $sendmail_path =~ /qmail-inject/ ) {
442 $sendmail_args = '';
443 } elsif ( !$sendmail_args ) {
444 $sendmail_args = '-i -t';
445 }
446
447 $default_fontsize = '' if ( !$default_fontsize);
448 $default_fontset = '' if ( !$default_fontset);
449 if ( !%fontsets) {
450 %fontsets = ('serif', 'serif',
451 'sans', 'helvetica,arial,sans-serif',
452 'comicsans', 'comic sans ms,sans-serif',
453 'tahoma', 'tahoma,sans-serif',
454 'verasans', 'bitstream vera sans,verdana,sans-serif');
455 }
456
457 # $use_imap_tls and $use_smtp_tls are switched to integer since 1.5.1
458 $use_imap_tls = 0 if ( $use_imap_tls eq 'false');
459 $use_imap_tls = 1 if ( $use_imap_tls eq 'true');
460 $use_smtp_tls = 0 if ( $use_smtp_tls eq 'false');
461 $use_smtp_tls = 1 if ( $use_smtp_tls eq 'true');
462 # sorting options changed names and reversed values in 1.5.1
463 $disable_thread_sort = 'false' if ( !$disable_thread_sort );
464 $disable_server_sort = 'false' if ( !$disable_server_sort );
465
466 # since 1.5.2
467 $abook_file_line_length = 2048 if ( !$abook_file_line_length );
468 $config_location_base = '' if ( !$config_location_base );
469 $smtp_sitewide_user = '' if ( !$smtp_sitewide_user );
470 $smtp_sitewide_pass = '' if ( !$smtp_sitewide_pass );
471 $icon_theme_def = '' if ( !$icon_theme_def );
472 $disable_plugins = 'false' if ( !$disable_plugins );
473 $disable_plugins_user = '' if ( !$disable_plugins_user );
474 $only_secure_cookies = 'true' if ( !$only_secure_cookies );
475 $ask_user_info = 'true' if ( !$ask_user_info );
476
477 if ( $ARGV[0] eq '--install-plugin' ) {
478 print "Activating plugin " . $ARGV[1] . "\n";
479 push @plugins, $ARGV[1];
480 save_data();
481 exit(0);
482 } elsif ( $ARGV[0] eq '--remove-plugin' ) {
483 print "Removing plugin " . $ARGV[1] . "\n";
484 foreach $plugin (@plugins) {
485 if ( $plugin ne $ARGV[1] ) {
486 push @newplugins, $plugin;
487 }
488 }
489 @plugins = @newplugins;
490 save_data();
491 exit(0);
492 } elsif ( $ARGV[0] eq '--update-plugins' or $ARGV[0] eq '-u') {
493 build_plugin_hook_array();
494 exit(0);
495 } elsif ( $ARGV[0] eq '--help' or $ARGV[0] eq '-h') {
496 print "SquirrelMail Configuration Script\n";
497 print "Usage:\n";
498 print " * No arguments: initiates the configuration dialog\n";
499 print " * --install-plugin <plugin> : activates the specified plugin\n";
500 print " * --remove-plugin <plugin> : deactivates the specified plugin\n";
501 print " * --update-plugins , -u : rebuilds plugin_hooks.php according\n";
502 print " to plugins activated in config.php\n";
503 print " * --help , -h : Displays this help\n";
504 print "\n";
505 exit(0);
506 }
507
508
509
510 ####################################################################################
511
512 # used in multiple places, define once
513 $list_supported_imap_servers =
514 " bincimap = Binc IMAP server\n" .
515 " courier = Courier IMAP server\n" .
516 " cyrus = Cyrus IMAP server\n" .
517 " dovecot = Dovecot Secure IMAP server\n" .
518 " exchange = Microsoft Exchange IMAP server\n" .
519 " hmailserver = hMailServer\n" .
520 " macosx = Mac OS X Mailserver\n" .
521 " mercury32 = Mercury/32\n" .
522 " uw = University of Washington's IMAP server\n";
523
524 #####################################################################################
525 if ( $config_use_color == 1 ) {
526 $WHT = "\x1B[37;1m";
527 $NRM = "\x1B[0m";
528 } else {
529 $WHT = "";
530 $NRM = "";
531 $config_use_color = 2;
532 }
533
534 while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
535 clear_screen();
536 print $WHT. "SquirrelMail Configuration : " . $NRM;
537 if ( $config == 1 ) { print "Read: config.php"; }
538 elsif ( $config == 2 ) { print "Read: config_default.php"; }
539 print " ($print_config_version)\n";
540 print "---------------------------------------------------------\n";
541
542 if ( $menu == 0 ) {
543 print $WHT. "Main Menu --\n" . $NRM;
544 print "1. Organization Preferences\n";
545 print "2. Server Settings\n";
546 print "3. Folder Defaults\n";
547 print "4. General Options\n";
548 print "5. User Interface\n";
549 print "6. Address Books\n";
550 print "7. Message of the Day (MOTD)\n";
551 print "8. Plugins\n";
552 print "9. Database\n";
553 print "10. Language settings\n";
554 print "11. Tweaks\n";
555 print "\n";
556 print "D. Set pre-defined settings for specific IMAP servers\n";
557 print "\n";
558 } elsif ( $menu == 1 ) {
559 print $WHT. "Organization Preferences\n" . $NRM;
560 print "1. Organization Name : $WHT$org_name$NRM\n";
561 print "2. Organization Logo : $WHT$org_logo$NRM\n";
562 print "3. Org. Logo Width/Height : $WHT($org_logo_width/$org_logo_height)$NRM\n";
563 print "4. Organization Title : $WHT$org_title$NRM\n";
564 print "5. Signout Page : $WHT$signout_page$NRM\n";
565 print "6. Top Frame : $WHT$frame_top$NRM\n";
566 print "7. Provider link : $WHT$provider_uri$NRM\n";
567 print "8. Provider link text : $WHT$provider_name$NRM\n";
568
569 print "\n";
570 print "R Return to Main Menu\n";
571 } elsif ( $menu == 2 ) {
572 print $WHT. "Server Settings\n\n" . $NRM;
573 print $WHT . "General" . $NRM . "\n";
574 print "-------\n";
575 print "1. Domain : $WHT$domain$NRM\n";
576 print "2. Invert Time : $WHT$invert_time$NRM\n";
577 print "3. Sendmail or SMTP : $WHT";
578 if ( lc($useSendmail) eq 'true' ) {
579 print "Sendmail";
580 } else {
581 print "SMTP";
582 }
583 print "$NRM\n";
584 print "\n";
585
586 if ( $show_imap_settings ) {
587 print $WHT . "IMAP Settings". $NRM . "\n--------------\n";
588 print "4. IMAP Server : $WHT$imapServerAddress$NRM\n";
589 print "5. IMAP Port : $WHT$imapPort$NRM\n";
590 print "6. Authentication type : $WHT$imap_auth_mech$NRM\n";
591 print "7. Secure IMAP (TLS) : $WHT" . display_use_tls($use_imap_tls) . "$NRM\n";
592 print "8. Server software : $WHT$imap_server_type$NRM\n";
593 print "9. Delimiter : $WHT$optional_delimiter$NRM\n";
594 print "\n";
595 } elsif ( $show_smtp_settings ) {
596 if ( lc($useSendmail) eq 'true' ) {
597 print $WHT . "Sendmail" . $NRM . "\n--------\n";
598 print "4. Sendmail Path : $WHT$sendmail_path$NRM\n";
599 print "5. Sendmail arguments : $WHT$sendmail_args$NRM\n";
600 print "6. Header encryption key : $WHT$encode_header_key$NRM\n";
601 print "\n";
602 } else {
603 print $WHT . "SMTP Settings" . $NRM . "\n-------------\n";
604 print "4. SMTP Server : $WHT$smtpServerAddress$NRM\n";
605 print "5. SMTP Port : $WHT$smtpPort$NRM\n";
606 print "6. POP before SMTP : $WHT$pop_before_smtp$NRM\n";
607 print "7. SMTP Authentication : $WHT$smtp_auth_mech" . display_smtp_sitewide_userpass() ."$NRM\n";
608 print "8. Secure SMTP (TLS) : $WHT" . display_use_tls($use_smtp_tls) . "$NRM\n";
609 print "9. Header encryption key : $WHT$encode_header_key$NRM\n";
610 print "\n";
611 }
612 }
613
614 if ($show_imap_settings == 0) {
615 print "A. Update IMAP Settings : ";
616 print "$WHT$imapServerAddress$NRM:";
617 print "$WHT$imapPort$NRM ";
618 print "($WHT$imap_server_type$NRM)\n";
619 }
620 if ($show_smtp_settings == 0) {
621 if ( lc($useSendmail) eq 'true' ) {
622 print "B. Change Sendmail Config : $WHT$sendmail_path$NRM\n";
623 } else {
624 print "B. Update SMTP Settings : ";
625 print "$WHT$smtpServerAddress$NRM:";
626 print "$WHT$smtpPort$NRM\n";
627 }
628 }
629 if ( $show_smtp_settings || $show_imap_settings )
630 {
631 print "H. Hide " .
632 ($show_imap_settings ? "IMAP Server" :
633 (lc($useSendmail) eq 'true') ? "Sendmail" : "SMTP") . " Settings\n";
634 }
635
636 print "\n";
637 print "R Return to Main Menu\n";
638 } elsif ( $menu == 3 ) {
639 print $WHT. "Folder Defaults\n" . $NRM;
640 print "1. Default Folder Prefix : $WHT$default_folder_prefix$NRM\n";
641 print "2. Show Folder Prefix Option : $WHT$show_prefix_option$NRM\n";
642 print "3. Trash Folder : $WHT$trash_folder$NRM\n";
643 print "4. Sent Folder : $WHT$sent_folder$NRM\n";
644 print "5. Drafts Folder : $WHT$draft_folder$NRM\n";
645 print "6. By default, move to trash : $WHT$default_move_to_trash$NRM\n";
646 print "7. By default, move to sent : $WHT$default_move_to_sent$NRM\n";
647 print "8. By default, save as draft : $WHT$default_save_as_draft$NRM\n";
648 print "9. List Special Folders First : $WHT$list_special_folders_first$NRM\n";
649 print "10. Show Special Folders Color : $WHT$use_special_folder_color$NRM\n";
650 print "11. Auto Expunge : $WHT$auto_expunge$NRM\n";
651 print "12. Default Sub. of INBOX : $WHT$default_sub_of_inbox$NRM\n";
652 print "13. Show 'Contain Sub.' Option : $WHT$show_contain_subfolders_option$NRM\n";
653 print "14. Default Unseen Notify : $WHT$default_unseen_notify$NRM\n";
654 print "15. Default Unseen Type : $WHT$default_unseen_type$NRM\n";
655 print "16. Auto Create Special Folders : $WHT$auto_create_special$NRM\n";
656 print "17. Folder Delete Bypasses Trash : $WHT$delete_folder$NRM\n";
657 print "18. Enable /NoSelect folder fix : $WHT$noselect_fix_enable$NRM\n";
658 print "\n";
659 print "R Return to Main Menu\n";
660 } elsif ( $menu == 4 ) {
661 print $WHT. "General Options\n" . $NRM;
662 print "1. Data Directory : $WHT$data_dir$NRM\n";
663 print "2. Attachment Directory : $WHT$attachment_dir$NRM\n";
664 print "3. Directory Hash Level : $WHT$dir_hash_level$NRM\n";
665 print "4. Default Left Size : $WHT$default_left_size$NRM\n";
666 print "5. Usernames in Lowercase : $WHT$force_username_lowercase$NRM\n";
667 print "6. Allow use of priority : $WHT$default_use_priority$NRM\n";
668 print "7. Hide SM attributions : $WHT$hide_sm_attributions$NRM\n";
669 print "8. Allow use of receipts : $WHT$default_use_mdn$NRM\n";
670 print "9. Allow editing of identity : $WHT$edit_identity$NRM\n";
671 print " Allow editing of name : $WHT$edit_name$NRM\n";
672 print " Remove username from header : $WHT$hide_auth_header$NRM\n";
673 print "10. Disable server thread sort : $WHT$disable_thread_sort$NRM\n";
674 print "11. Disable server-side sorting : $WHT$disable_server_sort$NRM\n";
675 print "12. Allow server charset search : $WHT$allow_charset_search$NRM\n";
676 print "13. Allow advanced search : $WHT$allow_advanced_search$NRM\n";
677 print "14. PHP session name : $WHT$session_name$NRM\n";
678 print "15. Time zone configuration : $WHT$time_zone_type$NRM\n";
679 print "16. Location base : $WHT$config_location_base$NRM\n";
680 print "17. Only secure cookies if poss. : $WHT$only_secure_cookies$NRM\n";
681 print "\n";
682 print "R Return to Main Menu\n";
683 } elsif ( $menu == 5 ) {
684 print $WHT. "User Interface\n" . $NRM;
685 print "1. Use Icons? : $WHT$use_icons$NRM\n";
686 # print "3. Default Icon Set : $WHT$icon_theme_def$NRM\n";
687 print "2. Default font size : $WHT$default_fontsize$NRM\n";
688 print "3. Manage template sets (skins)\n";
689 print "4. Manage user themes\n";
690 print "5. Manage font sets\n";
691 print "6. Manage icon themes\n";
692
693 print "\n";
694 print "R Return to Main Menu\n";
695 } elsif ( $menu == 6 ) {
696 print $WHT. "Address Books\n" . $NRM;
697 print "1. Change LDAP Servers\n";
698 for ( $count = 0 ; $count <= $#ldap_host ; $count++ ) {
699 print " > $ldap_host[$count]\n";
700 }
701 print "2. Use Javascript address book search : $WHT$default_use_javascript_addr_book$NRM\n";
702 print "3. Global address book file : $WHT$abook_global_file$NRM\n";
703 print "4. Allow writing into global file address book : $WHT$abook_global_file_writeable$NRM\n";
704 print "5. Allow listing of global file address book : $WHT$abook_global_file_listing$NRM\n";
705 print "6. Allowed address book line length : $WHT$abook_file_line_length$NRM\n";
706 print "\n";
707 print "R Return to Main Menu\n";
708 } elsif ( $menu == 7 ) {
709 print $WHT. "Message of the Day (MOTD)\n" . $NRM;
710 print "\n$motd\n";
711 print "\n";
712 print "1 Edit the MOTD\n";
713 print "\n";
714 print "R Return to Main Menu\n";
715 } elsif ( $menu == 8 ) {
716 if (lc($disable_plugins) eq 'true' && $disable_plugins_user ne '') {
717 print $WHT. "Plugins (WARNING: All plugins are currently disabled\n for the user \"$disable_plugins_user\"!)\n" . $NRM;
718 } elsif (lc($disable_plugins) eq 'true') {
719 print $WHT. "Plugins (WARNING: All plugins are currently disabled!)\n" . $NRM;
720 } else {
721 print $WHT. "Plugins\n" . $NRM;
722 }
723 print " Installed Plugins\n";
724 $num = 0;
725 for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
726 $num = $count + 1;
727 print " $num. $plugins[$count]" . get_plugin_version($plugins[$count]) . "\n";
728 }
729 print "\n Available Plugins:\n";
730 opendir( DIR, "../plugins" );
731 @files = sort(readdir(DIR));
732 $pos = 0;
733 @unused_plugins = ();
734 for ( $i = 0 ; $i <= $#files ; $i++ ) {
735 if ( -d "../plugins/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) {
736 $match = 0;
737 for ( $k = 0 ; $k <= $#plugins ; $k++ ) {
738 if ( $plugins[$k] eq $files[$i] ) {
739 $match = 1;
740 }
741 }
742 if ( $match == 0 ) {
743 $unused_plugins[$pos] = $files[$i];
744 $pos++;
745 }
746 }
747 }
748
749 for ( $i = 0 ; $i <= $#unused_plugins ; $i++ ) {
750 $num = $num + 1;
751 print " $num. $unused_plugins[$i]" . get_plugin_version($unused_plugins[$i]) . "\n";
752 }
753 closedir DIR;
754
755 print "\n";
756 if (lc($disable_plugins) eq 'true' && $disable_plugins_user ne '') {
757 print "E Enable active plugins (all plugins currently\n disabled for the user \"$disable_plugins_user\")\n";
758 } elsif (lc($disable_plugins) eq 'true') {
759 print "E Enable active plugins (all plugins currently\n disabled)\n";
760 } else {
761 print "D Disable all plugins\n";
762 }
763 print "U Set the user for whom plugins can be disabled\n";
764 print "R Return to Main Menu\n";
765 } elsif ( $menu == 9 ) {
766 print $WHT. "Database\n" . $NRM;
767 print "1. DSN for Address Book : $WHT$addrbook_dsn$NRM\n";
768 print "2. Table for Address Book : $WHT$addrbook_table$NRM\n";
769 print "\n";
770 print "3. DSN for Preferences : $WHT$prefs_dsn$NRM\n";
771 print "4. Table for Preferences : $WHT$prefs_table$NRM\n";
772 print "5. Field for username : $WHT$prefs_user_field$NRM ($prefs_user_size)\n";
773 print "6. Field for prefs key : $WHT$prefs_key_field$NRM ($prefs_key_size)\n";
774 print "7. Field for prefs value : $WHT$prefs_val_field$NRM ($prefs_val_size)\n";
775 print "\n";
776 print "8. DSN for Global Address Book : $WHT$addrbook_global_dsn$NRM\n";
777 print "9. Table for Global Address Book : $WHT$addrbook_global_table$NRM\n";
778 print "10. Allow writing into Global Address Book : $WHT$addrbook_global_writeable$NRM\n";
779 print "11. Allow listing of Global Address Book : $WHT$addrbook_global_listing$NRM\n";
780 print "\n";
781 print "R Return to Main Menu\n";
782 } elsif ( $menu == 10 ) {
783 print $WHT. "Language settings\n" . $NRM;
784 print "1. Default Language : $WHT$squirrelmail_default_language$NRM\n";
785 print "2. Default Charset : $WHT$default_charset$NRM\n";
786 print "3. Show alternative language names : $WHT$show_alternative_names$NRM\n";
787 print "4. Enable aggressive decoding : $WHT$aggressive_decoding$NRM\n";
788 print "5. Enable lossy encoding : $WHT$lossy_encoding$NRM\n";
789 print "\n";
790 print "R Return to Main Menu\n";
791 } elsif ( $menu == 11 ) {
792 print $WHT. "Interface tweaks\n" . $NRM;
793 print "1. Display html mails in iframe : $WHT$use_iframe$NRM\n";
794 print "2. Ask user info on first login : $WHT$ask_user_info$NRM\n";
795 print "\n";
796 print $WHT. "PHP tweaks\n" . $NRM;
797 print "4. Use php recode functions : $WHT$use_php_recode$NRM\n";
798 print "5. Use php iconv functions : $WHT$use_php_iconv$NRM\n";
799 print "\n";
800 print $WHT. "Configuration tweaks\n" . $NRM;
801 print "6. Allow remote configtest : $WHT$allow_remote_configtest$NRM\n";
802 print "\n";
803 print "R Return to Main Menu\n";
804 }
805 if ( $config_use_color == 1 ) {
806 print "C Turn color off\n";
807 } else {
808 print "C Turn color on\n";
809 }
810 print "S Save data\n";
811 print "Q Quit\n";
812
813 print "\n";
814 print "Command >> " . $WHT;
815 $command = <STDIN>;
816 $command =~ s/[\n\r]//g;
817 $command =~ tr/A-Z/a-z/;
818 print "$NRM\n";
819
820 # Read the commands they entered.
821 if ( $command eq "r" ) {
822 $menu = 0;
823 } elsif ( $command eq "s" ) {
824 save_data();
825 print "Press enter to continue...";
826 $tmp = <STDIN>;
827 $saved = 1;
828 } elsif ( ( $command eq "q" ) && ( $saved == 0 ) ) {
829 print "You have not saved your data.\n";
830 print "Save? [" . $WHT . "Y" . $NRM . "/n]: ";
831 $save = <STDIN>;
832 if ( ( $save =~ /^y/i ) || ( $save =~ /^\s*$/ ) ) {
833 save_data();
834 }
835 } elsif ( $command eq "c" ) {
836 if ( $config_use_color == 1 ) {
837 $config_use_color = 2;
838 $WHT = "";
839 $NRM = "";
840 } else {
841 $config_use_color = 1;
842 $WHT = "\x1B[37;1m";
843 $NRM = "\x1B[0m";
844 }
845 } elsif ( $command eq "d" && $menu == 0 ) {
846 set_defaults();
847 } else {
848 $saved = 0;
849 if ( $menu == 0 ) {
850 if ( ( $command > 0 ) && ( $command < 12 ) ) {
851 $menu = $command;
852 }
853 } elsif ( $menu == 1 ) {
854 if ( $command == 1 ) { $org_name = command1(); }
855 elsif ( $command == 2 ) { $org_logo = command2(); }
856 elsif ( $command == 3 ) { ($org_logo_width,$org_logo_height) = command2a(); }
857 elsif ( $command == 4 ) { $org_title = command3(); }
858 elsif ( $command == 5 ) { $signout_page = command4(); }
859 elsif ( $command == 6 ) { $frame_top = command6(); }
860 elsif ( $command == 7 ) { $provider_uri = command7(); }
861 elsif ( $command == 8 ) { $provider_name = command8(); }
862
863 } elsif ( $menu == 2 ) {
864 if ( $command eq "a" ) { $show_imap_settings = 1; $show_smtp_settings = 0; }
865 elsif ( $command eq "b" ) { $show_imap_settings = 0; $show_smtp_settings = 1; }
866 elsif ( $command eq "h" ) { $show_imap_settings = 0; $show_smtp_settings = 0; }
867 elsif ( $command <= 3 ) {
868 if ( $command == 1 ) { $domain = command11(); }
869 elsif ( $command == 2 ) { $invert_time = command110(); }
870 elsif ( $command == 3 ) { $useSendmail = command14(); }
871 $show_imap_settings = 0; $show_smtp_settings = 0;
872 } elsif ( $show_imap_settings ) {
873 if ( $command == 4 ) { $imapServerAddress = command12(); }
874 elsif ( $command == 5 ) { $imapPort = command13(); }
875 elsif ( $command == 6 ) { $imap_auth_mech = command112a(); }
876 elsif ( $command == 7 ) { $use_imap_tls = command_use_tls("IMAP",$use_imap_tls); }
877 elsif ( $command == 8 ) { $imap_server_type = command19(); }
878 elsif ( $command == 9 ) { $optional_delimiter = command111(); }
879 } elsif ( $show_smtp_settings && lc($useSendmail) eq 'true' ) {
880 if ( $command == 4 ) { $sendmail_path = command15(); }
881 elsif ( $command == 5 ) { $sendmail_args = command_sendmail_args(); }
882 elsif ( $command == 6 ) { $encode_header_key = command114(); }
883 } elsif ( $show_smtp_settings ) {
884 if ( $command == 4 ) { $smtpServerAddress = command16(); }
885 elsif ( $command == 5 ) { $smtpPort = command17(); }
886 elsif ( $command == 6 ) { $pop_before_smtp = command18a(); }
887 elsif ( $command == 7 ) { $smtp_auth_mech = command112b(); }
888 elsif ( $command == 8 ) { $use_smtp_tls = command_use_tls("SMTP",$use_smtp_tls); }
889 elsif ( $command == 9 ) { $encode_header_key = command114(); }
890 }
891 } elsif ( $menu == 3 ) {
892 if ( $command == 1 ) { $default_folder_prefix = command21(); }
893 elsif ( $command == 2 ) { $show_prefix_option = command22(); }
894 elsif ( $command == 3 ) { $trash_folder = command23a(); }
895 elsif ( $command == 4 ) { $sent_folder = command23b(); }
896 elsif ( $command == 5 ) { $draft_folder = command23c(); }
897 elsif ( $command == 6 ) { $default_move_to_trash = command24a(); }
898 elsif ( $command == 7 ) { $default_move_to_sent = command24b(); }
899 elsif ( $command == 8 ) { $default_save_as_draft = command24c(); }
900 elsif ( $command == 9 ) { $list_special_folders_first = command27(); }
901 elsif ( $command == 10 ) { $use_special_folder_color = command28(); }
902 elsif ( $command == 11 ) { $auto_expunge = command29(); }
903 elsif ( $command == 12 ) { $default_sub_of_inbox = command210(); }
904 elsif ( $command == 13 ) { $show_contain_subfolders_option = command211(); }
905 elsif ( $command == 14 ) { $default_unseen_notify = command212(); }
906 elsif ( $command == 15 ) { $default_unseen_type = command213(); }
907 elsif ( $command == 16 ) { $auto_create_special = command214(); }
908 elsif ( $command == 17 ) { $delete_folder = command215(); }
909 elsif ( $command == 18 ) { $noselect_fix_enable = command216(); }
910 } elsif ( $menu == 4 ) {
911 if ( $command == 1 ) { $data_dir = command33a(); }
912 elsif ( $command == 2 ) { $attachment_dir = command33b(); }
913 elsif ( $command == 3 ) { $dir_hash_level = command33c(); }
914 elsif ( $command == 4 ) { $default_left_size = command35(); }
915 elsif ( $command == 5 ) { $force_username_lowercase = command36(); }
916 elsif ( $command == 6 ) { $default_use_priority = command37(); }
917 elsif ( $command == 7 ) { $hide_sm_attributions = command38(); }
918 elsif ( $command == 8 ) { $default_use_mdn = command39(); }
919 elsif ( $command == 9 ) { $edit_identity = command310(); }
920 elsif ( $command == 10 ) { $disable_thread_sort = command312(); }
921 elsif ( $command == 11 ) { $disable_server_sort = command313(); }
922 elsif ( $command == 12 ) { $allow_charset_search = command314(); }
923 elsif ( $command == 13 ) { $allow_advanced_search = command316(); }
924 elsif ( $command == 14 ) { $session_name = command317(); }
925 elsif ( $command == 15 ) { $time_zone_type = command318(); }
926 elsif ( $command == 16 ) { $config_location_base = command_config_location_base(); }
927 elsif ( $command == 17 ) { $only_secure_cookies = command319(); }
928 } elsif ( $menu == 5 ) {
929 if ( $command == 1 ) { $use_icons = commandB3(); }
930 # elsif ( $command == 3 ) { $icon_theme_def = commandB7(); }
931 elsif ( $command == 2 ) { $default_fontsize = command_default_fontsize(); }
932 elsif ( $command == 3 ) { $templateset_default = command_templates(); }
933 elsif ( $command == 4 ) { command_userThemes(); }
934 elsif ( $command == 5 ) { command_fontsets(); }
935 elsif ( $command == 6 ) { command_iconSets(); }
936 } elsif ( $menu == 6 ) {
937 if ( $command == 1 ) { command61(); }
938 elsif ( $command == 2 ) { command62(); }
939 elsif ( $command == 3 ) { $abook_global_file=command63(); }
940 elsif ( $command == 4 ) { command64(); }
941 elsif ( $command == 5 ) { command65(); }
942 elsif ( $command == 6 ) { command_abook_file_line_length(); }
943 } elsif ( $menu == 7 ) {
944 if ( $command == 1 ) { $motd = command71(); }
945 } elsif ( $menu == 8 ) {
946 if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
947 elsif ( $command eq "u" ) { $disable_plugins_user = command82(); }
948 elsif ( $command eq "d" ) { $disable_plugins = 'true'; }
949 elsif ( $command eq "e" ) { $disable_plugins = 'false'; }
950 } elsif ( $menu == 9 ) {
951 if ( $command == 1 ) { $addrbook_dsn = command91(); }
952 elsif ( $command == 2 ) { $addrbook_table = command92(); }
953 elsif ( $command == 3 ) { $prefs_dsn = command93(); }
954 elsif ( $command == 4 ) { $prefs_table = command94(); }
955 elsif ( $command == 5 ) { $prefs_user_field = command95(); }
956 elsif ( $command == 6 ) { $prefs_key_field = command96(); }
957 elsif ( $command == 7 ) { $prefs_val_field = command97(); }
958 elsif ( $command == 8 ) { $addrbook_global_dsn = command98(); }
959 elsif ( $command == 9 ) { $addrbook_global_table = command99(); }
960 elsif ( $command == 10 ) { $addrbook_global_writeable = command910(); }
961 elsif ( $command == 11 ) { $addrbook_global_listing = command911(); }
962 } elsif ( $menu == 10 ) {
963 if ( $command == 1 ) { $squirrelmail_default_language = commandA1(); }
964 elsif ( $command == 2 ) { $default_charset = commandA2(); }
965 elsif ( $command == 3 ) { $show_alternative_names = commandA3(); }
966 elsif ( $command == 4 ) { $aggressive_decoding = commandA4(); }
967 elsif ( $command == 5 ) { $lossy_encoding = commandA5(); }
968 } elsif ( $menu == 11 ) {
969 if ( $command == 1 ) { $use_iframe = commandB2(); }
970 elsif ( $command == 2 ) { $ask_user_info = command_ask_user_info(); }
971 elsif ( $command == 4 ) { $use_php_recode = commandB4(); }
972 elsif ( $command == 5 ) { $use_php_iconv = commandB5(); }
973 elsif ( $command == 6 ) { $allow_remote_configtest = commandB6(); }
974 }
975 }
976 }
977
978 # we exit here
979 print "\nExiting conf.pl.\n".
980 "You might want to test your configuration by browsing to\n".
981 "http://your-squirrelmail-location/src/configtest.php\n".
982 "Happy SquirrelMailing!\n\n";
983
984
985 ####################################################################################
986
987 # org_name
988 sub command1 {
989 print "We have tried to make the name SquirrelMail as transparent as\n";
990 print "possible. If you set up an organization name, most places where\n";
991 print "SquirrelMail would take credit will be credited to your organization.\n";
992 print "\n";
993 print "If your Organization Name includes a '\$', please precede it with a \\. \n";
994 print "Other '\$' will be considered the beginning of a variable that\n";
995 print "must be defined before the \$org_name is printed.\n";
996 print "\n";
997 print "[$WHT$org_name$NRM]: $WHT";
998 $new_org_name = <STDIN>;
999 if ( $new_org_name eq "\n" ) {
1000 $new_org_name = $org_name;
1001 } else {
1002 $new_org_name =~ s/[\r\n]//g;
1003 $new_org_name =~ s/\"/&quot;/g;
1004 }
1005 return $new_org_name;
1006 }
1007
1008 # org_logo
1009 sub command2 {
1010 print "Your organization's logo is an image that will be displayed at\n";
1011 print "different times throughout SquirrelMail. ";
1012 print "\n";
1013 print "Please be aware of the following: \n";
1014 print " - Relative URLs are relative to the config dir\n";
1015 print " to use the default logo, use ../images/sm_logo.png\n";
1016 print " - To specify a logo defined outside the SquirrelMail source tree\n";
1017 print " use the absolute URL the webserver would use to include the file\n";
1018 print " e.g. http://example.com/images/mylogo.gif or /images/mylogo.jpg\n";
1019 print "\n";
1020 print "[$WHT$org_logo$NRM]: $WHT";
1021 $new_org_logo = <STDIN>;
1022 if ( $new_org_logo eq "\n" ) {
1023 $new_org_logo = $org_logo;
1024 } else {
1025 $new_org_logo =~ s/[\r\n]//g;
1026 }
1027 return $new_org_logo;
1028 }
1029
1030 # org_logo_width
1031 sub command2a {
1032 print "Your organization's logo is an image that will be displayed at\n";
1033 print "different times throughout SquirrelMail. Width\n";
1034 print "and Height of your logo image. Use '0' to disable.\n";
1035 print "\n";
1036 print "Width: [$WHT$org_logo_width$NRM]: $WHT";
1037 $new_org_logo_width = <STDIN>;
1038 $new_org_logo_width =~ tr/0-9//cd; # only want digits!
1039 if ( $new_org_logo_width eq '' ) {
1040 $new_org_logo_width = $org_logo_width;
1041 }
1042 if ( $new_org_logo_width > 0 ) {
1043 print "Height: [$WHT$org_logo_height$NRM]: $WHT";
1044 $new_org_logo_height = <STDIN>;
1045 $new_org_logo_height =~ tr/0-9//cd; # only want digits!
1046 if( $new_org_logo_height eq '' ) {
1047 $new_org_logo_height = $org_logo_height;
1048 }
1049 } else {
1050 $new_org_logo_height = 0;
1051 }
1052 return ($new_org_logo_width, $new_org_logo_height);
1053 }
1054
1055 # org_title
1056 sub command3 {
1057 print "A title is what is displayed at the top of the browser window in\n";
1058 print "the titlebar. Usually this will end up looking something like:\n";
1059 print "\"Netscape: $org_title\"\n";
1060 print "\n";
1061 print "If your Organization Title includes a '\$', please precede it with a \\. \n";
1062 print "Other '\$' will be considered the beginning of a variable that\n";
1063 print "must be defined before the \$org_title is printed.\n";
1064 print "\n";
1065 print "[$WHT$org_title$NRM]: $WHT";
1066 $new_org_title = <STDIN>;
1067 if ( $new_org_title eq "\n" ) {
1068 $new_org_title = $org_title;
1069 } else {
1070 $new_org_title =~ s/[\r\n]//g;
1071 $new_org_title =~ s/\"/\'/g;
1072 }
1073 return $new_org_title;
1074 }
1075
1076 # signout_page
1077 sub command4 {
1078 print "When users click the Sign Out button they will be logged out and\n";
1079 print "then sent to signout_page. If signout_page is left empty,\n";
1080 print "(hit space and then return) they will be taken, as normal,\n";
1081 print "to the default and rather sparse SquirrelMail signout page.\n";
1082 print "\n";
1083 print "[$WHT$signout_page$NRM]: $WHT";
1084 $new_signout_page = <STDIN>;
1085 if ( $new_signout_page eq "\n" ) {
1086 $new_signout_page = $signout_page;
1087 } else {
1088 $new_signout_page =~ s/[\r\n]//g;
1089 $new_signout_page =~ s/^\s+$//g;
1090 }
1091 return $new_signout_page;
1092 }
1093
1094 # Default top frame
1095 sub command6 {
1096 print "SquirrelMail defaults to using the whole of the browser window.\n";
1097 print "This allows you to keep it within a specified frame. The default\n";
1098 print "is '_top'\n";
1099 print "\n";
1100 print "[$WHT$frame_top$NRM]: $WHT";
1101 $new_frame_top = <STDIN>;
1102 if ( $new_frame_top eq "\n" ) {
1103 $new_frame_top = '_top';
1104 } else {
1105 $new_frame_top =~ s/[\r\n]//g;
1106 $new_frame_top =~ s/^\s+$//g;
1107 }
1108 return $new_frame_top;
1109 }
1110
1111 # Default link to provider
1112 sub command7 {
1113 print "Here you can set the link on the top-right of the message list.\n";
1114 print "If empty, it will not be displayed.\n";
1115 print "\n";
1116 print "[$WHT$provider_uri$NRM]: $WHT";
1117 $new_provider_uri = <STDIN>;
1118 if ( $new_provider_uri eq "\n" ) {
1119 $new_provider_uri = '';
1120 } else {
1121 $new_provider_uri =~ s/[\r\n]//g;
1122 $new_provider_uri =~ s/^\s+$//g;
1123 }
1124 return $new_provider_uri;
1125 }
1126
1127 sub command8 {
1128 print "Here you can set the name of the link on the top-right of the message list.\n";
1129 print "The default is empty (do not display anything).'\n";
1130 print "\n";
1131 print "[$WHT$provider_name$NRM]: $WHT";
1132 $new_provider_name = <STDIN>;
1133 if ( $new_provider_name eq "\n" ) {
1134 $new_provider_name = '';
1135 } else {
1136 $new_provider_name =~ s/[\r\n]//g;
1137 $new_provider_name =~ s/^\s+$//g;
1138 $new_provider_name =~ s/\'/\\'/g;
1139 }
1140 return $new_provider_name;
1141 }
1142
1143 ####################################################################################
1144
1145 # domain
1146 sub command11 {
1147 print "The domain name is the suffix at the end of all email addresses. If\n";
1148 print "for example, your email address is jdoe\@example.com, then your domain\n";
1149 print "would be example.com.\n";
1150 print "\n";
1151 print "[$WHT$domain$NRM]: $WHT";
1152 $new_domain = <STDIN>;
1153 if ( $new_domain eq "\n" ) {
1154 $new_domain = $domain;
1155 } else {
1156 $new_domain =~ s/\s//g;
1157 }
1158 return $new_domain;
1159 }
1160
1161 # imapServerAddress
1162 sub command12 {
1163 print "This is the hostname where your IMAP server can be contacted.\n";
1164 print "[$WHT$imapServerAddress$NRM]: $WHT";
1165 $new_imapServerAddress = <STDIN>;
1166 if ( $new_imapServerAddress eq "\n" ) {
1167 $new_imapServerAddress = $imapServerAddress;
1168 } else {
1169 $new_imapServerAddress =~ s/[\r\n]//g;
1170 }
1171 return $new_imapServerAddress;
1172 }
1173
1174 # imapPort
1175 sub command13 {
1176 print "This is the port that your IMAP server is on. Usually this is 143.\n";
1177 print "[$WHT$imapPort$NRM]: $WHT";
1178 $new_imapPort = <STDIN>;
1179 if ( $new_imapPort eq "\n" ) {
1180 $new_imapPort = $imapPort;
1181 } else {
1182 $new_imapPort =~ s/[\r\n]//g;
1183 }
1184 return $new_imapPort;
1185 }
1186
1187 # useSendmail
1188 sub command14 {
1189 print "You now need to choose the method that you will use for sending\n";
1190 print "messages in SquirrelMail. You can either connect to an SMTP server\n";
1191 print "or use sendmail directly.\n";
1192 if ( lc($useSendmail) eq 'true' ) {
1193 $default_value = "1";
1194 } else {
1195 $default_value = "2";
1196 }
1197 print "\n";
1198 print " 1. Sendmail\n";
1199 print " 2. SMTP\n";
1200 print "Your choice [1/2] [$WHT$default_value$NRM]: $WHT";
1201 $use_sendmail = <STDIN>;
1202 if ( ( $use_sendmail =~ /^1\n/i )
1203 || ( ( $use_sendmail =~ /^\n/ ) && ( $default_value eq "1" ) ) ) {
1204 $useSendmail = 'true';
1205 } else {
1206 $useSendmail = 'false';
1207 }
1208 return $useSendmail;
1209 }
1210
1211 # sendmail_path
1212 sub command15 {
1213 print "Specify where the sendmail executable is located. Usually /usr/sbin/sendmail\n";
1214 print "[$WHT$sendmail_path$NRM]: $WHT";
1215 $new_sendmail_path = <STDIN>;
1216 if ( $new_sendmail_path eq "\n" ) {
1217 $new_sendmail_path = $sendmail_path;
1218 } else {
1219 $new_sendmail_path =~ s/[\r\n]//g;
1220 }
1221 return $new_sendmail_path;
1222 }
1223
1224 # Extra sendmail arguments
1225 sub command_sendmail_args {
1226 print "Specify additional sendmail program arguments.\n";
1227 print "\n";
1228 print "Make sure that arguments are supported by your sendmail program. -f argument \n";
1229 print "is added automatically by SquirrelMail scripts. Variable defaults to standard\n";
1230 print "/usr/sbin/sendmail arguments. If you use qmail-inject, nbsmtp or any other \n";
1231 print "sendmail wrapper, which does not support -i and -t arguments, set variable to\n";
1232 print "empty string or use arguments suitable for your mailer.\n";
1233 print "\n";
1234 print "[$WHT$sendmail_args$NRM]: $WHT";
1235 $new_sendmail_args = <STDIN>;
1236 if ( $new_sendmail_args eq "\n" ) {
1237 $new_sendmail_args = $sendmail_args;
1238 } else {
1239 # strip linefeeds and crs.
1240 $new_sendmail_args =~ s/[\r\n]//g;
1241 }
1242 return trim($new_sendmail_args);
1243 }
1244
1245 # smtpServerAddress
1246 sub command16 {
1247 print "This is the hostname of your SMTP server.\n";
1248 print "[$WHT$smtpServerAddress$NRM]: $WHT";
1249 $new_smtpServerAddress = <STDIN>;
1250 if ( $new_smtpServerAddress eq "\n" ) {
1251 $new_smtpServerAddress = $smtpServerAddress;
1252 } else {
1253 $new_smtpServerAddress =~ s/[\r\n]//g;
1254 }
1255 return $new_smtpServerAddress;
1256 }
1257
1258 # smtpPort
1259 sub command17 {
1260 print "This is the port to connect to for SMTP. Usually 25.\n";
1261 print "[$WHT$smtpPort$NRM]: $WHT";
1262 $new_smtpPort = <STDIN>;
1263 if ( $new_smtpPort eq "\n" ) {
1264 $new_smtpPort = $smtpPort;
1265 } else {
1266 $new_smtpPort =~ s/[\r\n]//g;
1267 }
1268 return $new_smtpPort;
1269 }
1270
1271 # pop before SMTP
1272 sub command18a {
1273 print "Do you wish to use POP3 before SMTP? Your server must\n";
1274 print "support this in order for SquirrelMail to work with it.\n";
1275
1276 $YesNo = 'n';
1277 $YesNo = 'y' if ( lc($pop_before_smtp) eq 'true' );
1278
1279 print "Use pop before SMTP (y/n) [$WHT$YesNo$NRM]: $WHT";
1280
1281 $new_pop_before_smtp = <STDIN>;
1282 $new_pop_before_smtp =~ tr/yn//cd;
1283 return 'true' if ( $new_pop_before_smtp eq "y" );
1284 return 'false' if ( $new_pop_before_smtp eq "n" );
1285 return $pop_before_smtp;
1286 }
1287
1288 # imap_server_type
1289 sub command19 {
1290 print "Each IMAP server has its own quirks. As much as we tried to stick\n";
1291 print "to standards, it doesn't help much if the IMAP server doesn't follow\n";
1292 print "the same principles. We have made some work-arounds for some of\n";
1293 print "these servers. If you would like to use them, please select your\n";
1294 print "IMAP server. If you do not wish to use these work-arounds, you can\n";
1295 print "set this to \"other\", and none will be used.\n";
1296 print $list_supported_imap_servers;
1297 print "\n";
1298 print " other = Not one of the above servers\n";
1299 print "\n";
1300 print "[$WHT$imap_server_type$NRM]: $WHT";
1301 $new_imap_server_type = <STDIN>;
1302
1303 if ( $new_imap_server_type eq "\n" ) {
1304 $new_imap_server_type = $imap_server_type;
1305 } else {
1306 $new_imap_server_type =~ s/[\r\n]//g;
1307 }
1308 return $new_imap_server_type;
1309 }
1310
1311 # invert_time
1312 sub command110 {
1313 print "Sometimes the date of messages sent is messed up (off by a few hours\n";
1314 print "on some machines). Typically this happens if the system doesn't support\n";
1315 print "tm_gmtoff. It will happen only if your time zone is \"negative\".\n";
1316 print "This most often occurs on Solaris 7 machines in the United States.\n";
1317 print "By default, this is off. It should be kept off unless problems surface\n";
1318 print "about the time that messages are sent.\n";
1319 print " no = Do NOT fix time -- almost always correct\n";
1320 print " yes = Fix the time for this system\n";
1321
1322 $YesNo = 'n';
1323 $YesNo = 'y' if ( lc($invert_time) eq 'true' );
1324
1325 print "Fix the time for this system (y/n) [$WHT$YesNo$NRM]: $WHT";
1326
1327 $new_invert_time = <STDIN>;
1328 $new_invert_time =~ tr/yn//cd;
1329 return 'true' if ( $new_invert_time eq "y" );
1330 return 'false' if ( $new_invert_time eq "n" );
1331 return $invert_time;
1332 }
1333
1334 sub command111 {
1335 print "This is the delimiter that your IMAP server uses to distinguish between\n";
1336 print "folders. For example, Cyrus uses '.' as the delimiter and a complete\n";
1337 print "folder would look like 'INBOX.Friends.Bob', while UW uses '/' and would\n";
1338 print "look like 'INBOX/Friends/Bob'. Normally this should be left at 'detect'\n";
1339 print "but if you are sure you know what delimiter your server uses, you can\n";
1340 print "specify it here.\n";
1341 print "\nTo have it autodetect the delimiter, set it to 'detect'.\n\n";
1342 print "[$WHT$optional_delimiter$NRM]: $WHT";
1343 $new_optional_delimiter = <STDIN>;
1344
1345 if ( $new_optional_delimiter eq "\n" ) {
1346 $new_optional_delimiter = $optional_delimiter;
1347 } else {
1348 $new_optional_delimiter =~ s/[\r\n]//g;
1349 }
1350 return $new_optional_delimiter;
1351 }
1352 # IMAP authentication type
1353 # Possible values: login, plain, cram-md5, digest-md5
1354 # Now offers to detect supported mechs, assuming server & port are set correctly
1355
1356 sub command112a {
1357 if ($use_imap_tls ne "0") {
1358 # 1. Script does not handle TLS.
1359 # 2. Server does not have to declare all supported authentication mechs when
1360 # STARTTLS is used. Supported mechs are declared only after STARTTLS.
1361 print "Auto-detection of login methods is unavailable when using TLS or STARTTLS.\n";
1362 } else {
1363 print "If you have already set the hostname and port number, I can try to\n";
1364 print "detect the mechanisms your IMAP server supports.\n";
1365 print "I will try to detect CRAM-MD5 and DIGEST-MD5 support. I can't test\n";
1366 print "for \"login\" or \"plain\" without knowing a username and password.\n";
1367 print "Auto-detecting is optional - you can safely say \"n\" here.\n";
1368 print "\nTry to detect supported mechanisms? [y/N]: ";
1369 $inval=<STDIN>;
1370 chomp($inval);
1371 if ($inval =~ /^y\b/i) {
1372 # Yes, let's try to detect.
1373 print "Trying to detect IMAP capabilities...\n";
1374 my $host = $imapServerAddress . ':'. $imapPort;
1375 print "CRAM-MD5:\t";
1376 my $tmp = detect_auth_support('IMAP',$host,'CRAM-MD5');
1377 if (defined($tmp)) {
1378 if ($tmp eq 'YES') {
1379 print "$WHT SUPPORTED$NRM\n";
1380 } else {
1381 print "$WHT NOT SUPPORTED$NRM\n";
1382 }
1383 } else {
1384 print $WHT . " ERROR DETECTING$NRM\n";
1385 }
1386
1387 print "DIGEST-MD5:\t";
1388 $tmp = detect_auth_support('IMAP',$host,'DIGEST-MD5');
1389 if (defined($tmp)) {
1390 if ($tmp eq 'YES') {
1391 print "$WHT SUPPORTED$NRM\n";
1392 } else {
1393 print "$WHT NOT SUPPORTED$NRM\n";
1394 }
1395 } else {
1396 print $WHT . " ERROR DETECTING$NRM\n";
1397 }
1398
1399 }
1400 }
1401 print "\nWhat authentication mechanism do you want to use for IMAP connections?\n\n";
1402 print $WHT . "login" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
1403 print $WHT . "plain" . $NRM . " - SASL PLAIN. If you need this, you already know it.\n";
1404 print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext methods.\n";
1405 print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
1406 print "\n*** YOUR IMAP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n";
1407 print "If you don't understand or are unsure, you probably want \"login\"\n\n";
1408 print "login, plain, cram-md5, or digest-md5 [$WHT$imap_auth_mech$NRM]: $WHT";
1409 $inval=<STDIN>;
1410 chomp($inval);
1411 if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || ($inval =~ /^login\b/i) || ($inval =~ /^plain\b/i)) {
1412 return lc($inval);
1413 } else {
1414 # user entered garbage or default value so nothing needs to be set
1415 return $imap_auth_mech;
1416 }
1417 }
1418
1419
1420 # SMTP authentication type
1421 # Possible choices: none, plain, cram-md5, digest-md5
1422 sub command112b {
1423 if ($use_smtp_tls ne "0") {
1424 print "Auto-detection of login methods is unavailable when using TLS or STARTTLS.\n";
1425 } elsif (eval ("use IO::Socket; 1")) {
1426 # try loading IO::Socket module
1427 print "If you have already set the hostname and port number, I can try to\n";
1428 print "automatically detect some of the mechanisms your SMTP server supports.\n";
1429 print "Auto-detection is *optional* - you can safely say \"n\" here.\n";
1430 print "\nTry to detect auth mechanisms? [y/N]: ";
1431 $inval=<STDIN>;
1432 chomp($inval);
1433 if ($inval =~ /^y\b/i) {
1434 # Yes, let's try to detect.
1435 print "Trying to detect supported methods (SMTP)...\n";
1436
1437 # Special case!
1438 # Check none by trying to relay to junk@microsoft.com
1439 $host = $smtpServerAddress . ':' . $smtpPort;
1440 my $sock = IO::Socket::INET->new($host);
1441 print "Testing none:\t\t$WHT";
1442 if (!defined($sock)) {
1443 print " ERROR TESTING\n";
1444 close $sock;
1445 } else {
1446 $got = <$sock>; # Discard greeting
1447 print $sock "HELO $domain\r\n";
1448 $got = <$sock>; # Discard
1449 print $sock "MAIL FROM:<tester\@squirrelmail.org>\r\n";
1450 $got = <$sock>; # Discard
1451 print $sock "RCPT TO:<junk\@microsoft.com\r\n";
1452 $got = <$sock>; # This is the important line
1453 if ($got =~ /^250\b/) { # SMTP will relay without auth
1454 print "SUPPORTED$NRM\n";
1455 } else {
1456 print "NOT SUPPORTED$NRM\n";
1457 }
1458 print $sock "RSET\r\n";
1459 print $sock "QUIT\r\n";
1460 close $sock;
1461 }
1462 # Try login (SquirrelMail default)
1463 print "Testing login:\t\t";
1464 $tmp=detect_auth_support('SMTP',$host,'LOGIN');
1465 if (defined($tmp)) {
1466 if ($tmp eq 'YES') {
1467 print $WHT . "SUPPORTED$NRM\n";
1468 } else {
1469 print $WHT . "NOT SUPPORTED$NRM\n";
1470 }
1471 } else {
1472 print $WHT . "ERROR DETECTING$NRM\n";
1473 }
1474
1475 # Try CRAM-MD5
1476 print "Testing CRAM-MD5:\t";
1477 $tmp=detect_auth_support('SMTP',$host,'CRAM-MD5');
1478 if (defined($tmp)) {
1479 if ($tmp eq 'YES') {
1480 print $WHT . "SUPPORTED$NRM\n";
1481 } else {
1482 print $WHT . "NOT SUPPORTED$NRM\n";
1483 }
1484 } else {
1485 print $WHT . "ERROR DETECTING$NRM\n";
1486 }
1487
1488
1489 print "Testing DIGEST-MD5:\t";
1490 $tmp=detect_auth_support('SMTP',$host,'DIGEST-MD5');
1491 if (defined($tmp)) {
1492 if ($tmp eq 'YES') {
1493 print $WHT . "SUPPORTED$NRM\n";
1494 } else {
1495 print $WHT . "NOT SUPPORTED$NRM\n";
1496 }
1497 } else {
1498 print $WHT . "ERROR DETECTING$NRM\n";
1499 }
1500 }
1501 }
1502 print "\nWhat authentication mechanism do you want to use for SMTP connections?\n";
1503 print $WHT . "none" . $NRM . " - Your SMTP server does not require authorization.\n";
1504 print $WHT . "login" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
1505 print $WHT . "plain" . $NRM . " - SASL PLAIN. You already know it if you need this.\n";
1506 print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext.\n";
1507 print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
1508 print $WHT . "\n*** YOUR SMTP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n" . $NRM;
1509 print "If you don't understand or are unsure, you probably want \"none\"\n\n";
1510 print "none, login, cram-md5, or digest-md5 [$WHT$smtp_auth_mech$NRM]: $WHT";
1511 $inval=<STDIN>;
1512 chomp($inval);
1513 if ($inval =~ /^none\b/i) {
1514 # remove sitewide smtp authentication information
1515 $smtp_sitewide_user = '';
1516 $smtp_sitewide_pass = '';
1517 # SMTP doesn't necessarily require logins
1518 return "none";
1519 } elsif ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) ||
1520 ($inval =~ /^login\b/i) || ($inval =~/^plain\b/i)) {
1521 command_smtp_sitewide_userpass($inval);
1522 return lc($inval);
1523 } elsif (trim($inval) eq '') {
1524 # user selected default value
1525 command_smtp_sitewide_userpass($smtp_auth_mech);
1526 return $smtp_auth_mech;
1527 } else {
1528 # user entered garbage
1529 return $smtp_auth_mech;
1530 }
1531 }
1532
1533 sub command_smtp_sitewide_userpass($) {
1534 # get first function argument
1535 my $auth_mech = shift(@_);
1536 my $default, $tmp;
1537 $auth_mech = lc(trim($auth_mech));
1538 if ($auth_mech eq 'none') {
1539 return;
1540 }
1541 print "SMTP authentication uses IMAP username and password by default.\n";
1542 print "\n";
1543 print "Would you like to use other login and password for all SquirrelMail \n";
1544 print "SMTP connections?";
1545 if ($smtp_sitewide_user ne '') {
1546 $default = 'y';
1547 print " [Yn]:";
1548 } else {
1549 $default = 'n';
1550 print " [yN]:";
1551 }
1552 $tmp=<STDIN>;
1553 $tmp = trim($tmp);
1554
1555 if ($tmp eq '') {
1556 $tmp = $default;
1557 } else {
1558 $tmp = lc($tmp);
1559 }
1560
1561 if ($tmp eq 'n') {
1562 $smtp_sitewide_user = '';
1563 $smtp_sitewide_pass = '';
1564 } elsif ($tmp eq 'y') {
1565 print "Enter username [$smtp_sitewide_user]:";
1566 my $new_user = <STDIN>;
1567 $new_user = trim($new_user);
1568 if ($new_user ne '') {
1569 $smtp_sitewide_user = $new_user;
1570 }
1571 if ($smtp_sitewide_user ne '') {
1572 print "If you don't enter any password, current sitewide password will be used.\n";
1573 print "If you enter space, password will be set to empty string.\n";
1574 print "Enter password:";
1575 my $new_pass = <STDIN>;
1576 if ($new_pass ne "\n") {
1577 $smtp_sitewide_pass = trim($new_pass);
1578 }
1579 } else {
1580 print "Invalid input. You must set username used for SMTP authentication.\n";
1581 print "Click enter to continue\n";
1582 $tmp = <STDIN>;
1583 }
1584 } else {
1585 print "Invalid input\n";
1586 print "Click enter to continue\n";
1587 $tmp = <STDIN>;
1588 }
1589 }
1590
1591 # Sub adds information about SMTP authentication type to menu
1592 sub display_smtp_sitewide_userpass() {
1593 my $ret = '';
1594 if ($smtp_auth_mech ne 'none') {
1595 if ($smtp_sitewide_user ne '') {
1596 $ret = ' (with custom username and password)';
1597 } else {
1598 $ret = ' (with IMAP username and password)';
1599 }
1600 }
1601 return $ret;
1602 }
1603
1604 # TLS
1605 # This sub is reused for IMAP and SMTP
1606 # Args: service name, default value
1607 sub command_use_tls {
1608 my($default_val,$service,$inval);
1609 $service=$_[0];
1610 $default_val=$_[1];
1611 print "TLS (Transport Layer Security) encrypts the traffic between server and client.\n";
1612 print "STARTTLS extensions allow to start encryption on existing plain text connection.\n";
1613 print "These options add specific PHP and IMAP server configuration requirements.\n";
1614 print "See SquirrelMail documentation about connection security.\n";
1615 print "\n";
1616 print "If your " . $service . " server is localhost, you can safely disable this.\n";
1617 print "If it is remote, you may wish to seriously consider enabling this.\n";
1618 $valid_input=0;
1619 while ($valid_input eq 0) {
1620 print "\nSelect connection security model:\n";
1621 print " 0 - Use plain text connection\n";
1622 print " 1 - Use TLS connection\n";
1623 print " 2 - Use STARTTLS extension\n";
1624 print "Select [$default_val]: ";
1625 $inval=<STDIN>;
1626 $inval=trim($inval);
1627 if ($inval =~ /^[012]$/ || $inval eq '') {
1628 $valid_input = 1;
1629 }
1630 }
1631 if ($inval ne '') {$default_val = $inval};
1632 return $default_val;
1633 }
1634
1635 # This sub is used to display human readable text for
1636 # $use_imap_tls and $use_smtp_tls values in conf.pl menu
1637 sub display_use_tls($) {
1638 my $val = shift(@_);
1639 my $ret = 'disabled';
1640 if ($val eq '2') {
1641 $ret = 'STARTTLS';
1642 } elsif ($val eq '1') {
1643 $ret = 'TLS';
1644 }
1645 return $ret;
1646 }
1647
1648 # $encode_header_key
1649 sub command114{
1650 print "Encryption key allows to hide SquirrelMail Received: headers\n";
1651 print "in outbound messages. Interface uses encryption key to encode\n";
1652 print "username, remote address and proxied address, then stores encoded\n";
1653 print "information in X-Squirrel-* headers.\n";
1654 print "\n";
1655 print "Warning: used encryption function is not bulletproof. When used\n";
1656 print "with static encryption keys, it provides only minimal security\n";
1657 print "measures and information can be decoded quickly.\n";
1658 print "\n";
1659 print "Encoded information can be decoded with decrypt_headers.php script\n";
1660 print "from SquirrelMail contrib/ directory.\n";
1661 print "\n";
1662 print "Enter encryption key: ";
1663 $new_encode_header_key = <STDIN>;
1664 if ( $new_encode_header_key eq "\n" ) {
1665 $new_encode_header_key = $encode_header_key;
1666 } else {
1667 $new_encode_header_key =~ s/[\r\n]//g;
1668 }
1669 return $new_encode_header_key;
1670 }
1671
1672 # MOTD
1673 sub command71 {
1674 print "\nYou can now create the welcome message that is displayed\n";
1675 print "every time a user logs on. You can use HTML or just plain\n";
1676 print
1677 "text. If you do not wish to have one, just make it blank.\n\n(Type @ on a blank line to exit)\n";
1678
1679 $new_motd = "";
1680 do {
1681 print "] ";
1682 $line = <STDIN>;
1683 $line =~ s/[\r\n]//g;
1684 if ( $line ne "@" ) {
1685 $line =~ s/ /\&nbsp;\&nbsp;/g;
1686 $line =~ s/\t/\&nbsp;\&nbsp;\&nbsp;\&nbsp;/g;
1687 $line =~ s/$/ /;
1688 $line =~ s/\"/\\\"/g;
1689
1690 $new_motd = $new_motd . $line;
1691 }
1692 } while ( $line ne "@" );
1693 return $new_motd;
1694 }
1695
1696 ################# PLUGINS ###################
1697
1698 sub command81 {
1699 $command =~ s/[\s\n\r]*//g;
1700 if ( $command > 0 ) {
1701 $command = $command - 1;
1702 if ( $command <= $#plugins ) {
1703 @newplugins = ();
1704 $ct = 0;
1705 while ( $ct <= $#plugins ) {
1706 if ( $ct != $command ) {
1707 @newplugins = ( @newplugins, $plugins[$ct] );
1708 }
1709 $ct++;
1710 }
1711 @plugins = @newplugins;
1712 } elsif ( $command <= $#plugins + $#unused_plugins + 1 ) {
1713 $num = $command - $#plugins - 1;
1714 @newplugins = @plugins;
1715 $ct = 0;
1716 while ( $ct <= $#unused_plugins ) {
1717 if ( $ct == $num ) {
1718 @newplugins = ( @newplugins, $unused_plugins[$ct] );
1719 }
1720 $ct++;
1721 }
1722 @plugins = @newplugins;
1723 }
1724 }
1725 return @plugins;
1726 }
1727
1728 # disable_plugins_user
1729 sub command82 {
1730 print "When all active plugins are disabled, they can be disabled only\n";
1731 print "for the one user named here. If left blank, plugins will be\n";
1732 print "disabled for ALL users. This setting has no effect if plugins\n";
1733 print "are not disabled.\n";
1734 print "\n";
1735 print "This must be the exact IMAP login name for the desired user.\n";
1736 print "\n";
1737 print "[$WHT$disable_plugins_user$NRM]: $WHT";
1738 $new_disable_plugins_user = <STDIN>;
1739 if ( $new_disable_plugins_user eq "\n" ) {
1740 $new_disable_plugins_user = $disable_plugins_user;
1741 } else {
1742 $new_disable_plugins_user =~ s/[\r\n]//g;
1743 }
1744 return $new_disable_plugins_user;
1745 }
1746
1747 ################# FOLDERS ###################
1748
1749 # default_folder_prefix
1750 sub command21 {
1751 print "Some IMAP servers (UW, for example) store mail and folders in\n";
1752 print "your user space in a separate subdirectory. This is where you\n";
1753 print "specify what that directory is.\n";
1754 print "\n";
1755 print "EXAMPLE: mail/";
1756 print "\n";
1757 print "NOTE: If you use Cyrus, or some server that would not use this\n";
1758 print " option, you must set this to 'none'.\n";
1759 print "\n";
1760 print "[$WHT$default_folder_prefix$NRM]: $WHT";
1761 $new_default_folder_prefix = <STDIN>;
1762
1763 if ( $new_default_folder_prefix eq "\n" ) {
1764 $new_default_folder_prefix = $default_folder_prefix;
1765 } else {
1766 $new_default_folder_prefix =~ s/[\r\n]//g;
1767 }
1768 if ( ( $new_default_folder_prefix =~ /^\s*$/ ) || ( $new_default_folder_prefix =~ m/^none$/i ) ) {
1769 $new_default_folder_prefix = "";
1770 } else {
1771 # add the trailing delimiter only if we know what the server is.
1772 if (($imap_server_type eq 'cyrus' and
1773 $optional_delimiter eq 'detect') or
1774 ($imap_server_type eq 'courier' and
1775 $optional_delimiter eq 'detect')) {
1776 $new_default_folder_prefix =~ s/\.*$/\./;
1777 } elsif ($imap_server_type eq 'uw' and
1778 $optional_delimiter eq 'detect') {
1779 $new_default_folder_prefix =~ s/\/*$/\//;
1780 }
1781 }
1782 return $new_default_folder_prefix;
1783 }
1784
1785 # Show Folder Prefix
1786 sub command22 {
1787 print "It is possible to set up the default folder prefix as a user\n";
1788 print "specific option, where each user can specify what their mail\n";
1789 print "folder is. If you set this to false, they will never see the\n";
1790 print "option, but if it is true, this option will appear in the\n";
1791 print "'options' section.\n";
1792 print "\n";
1793 print "NOTE: You set the default folder prefix in option '1' of this\n";
1794 print " section. That will be the default if the user doesn't\n";
1795 print " specify anything different.\n";
1796 print "\n";
1797
1798 if ( lc($show_prefix_option) eq 'true' ) {
1799 $default_value = "y";
1800 } else {
1801 $default_value = "n";
1802 }
1803 print "\n";
1804 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
1805 $new_show = <STDIN>;
1806 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1807 $show_prefix_option = 'true';
1808 } else {
1809 $show_prefix_option = 'false';
1810 }
1811 return $show_prefix_option;
1812 }
1813
1814 # Trash Folder
1815 sub command23a {
1816 print "You can now specify where the default trash folder is located.\n";
1817 print "On servers where you do not want this, you can set it to anything\n";
1818 print "and set option 6 to false.\n";
1819 print "\n";
1820 print "This is relative to where the rest of your email is kept. You do\n";
1821 print "not need to worry about their mail directory. If this folder\n";
1822 print "would be ~/mail/trash on the filesystem, you only need to specify\n";
1823 print "that this is 'trash', and be sure to put 'mail/' in option 1.\n";
1824 print "\n";
1825
1826 print "[$WHT$trash_folder$NRM]: $WHT";
1827 $new_trash_folder = <STDIN>;
1828 if ( $new_trash_folder eq "\n" ) {
1829 $new_trash_folder = $trash_folder;
1830 } else {
1831 if (check_imap_folder($new_trash_folder)) {
1832 $new_trash_folder =~ s/[\r\n]//g;
1833 } else {
1834 $new_trash_folder = $trash_folder;
1835 }
1836 }
1837 return $new_trash_folder;
1838 }
1839
1840 # Sent Folder
1841 sub command23b {
1842 print "This is where messages that are sent will be stored. SquirrelMail\n";
1843 print "by default puts a copy of all outgoing messages in this folder.\n";
1844 print "\n";
1845 print "This is relative to where the rest of your email is kept. You do\n";
1846 print "not need to worry about their mail directory. If this folder\n";
1847 print "would be ~/mail/sent on the filesystem, you only need to specify\n";
1848 print "that this is 'sent', and be sure to put 'mail/' in option 1.\n";
1849 print "\n";
1850
1851 print "[$WHT$sent_folder$NRM]: $WHT";
1852 $new_sent_folder = <STDIN>;
1853 if ( $new_sent_folder eq "\n" ) {
1854 $new_sent_folder = $sent_folder;
1855 } else {
1856 if (check_imap_folder($new_sent_folder)) {
1857 $new_sent_folder =~ s/[\r\n]//g;
1858 } else {
1859 $new_sent_folder = $sent_folder;
1860 }
1861 }
1862 return $new_sent_folder;
1863 }
1864
1865 # Draft Folder
1866 sub command23c {
1867 print "You can now specify where the default draft folder is located.\n";
1868 print "On servers where you do not want this, you can set it to anything\n";
1869 print "and set option 9 to false.\n";
1870 print "\n";
1871 print "This is relative to where the rest of your email is kept. You do\n";
1872 print "not need to worry about their mail directory. If this folder\n";
1873 print "would be ~/mail/drafts on the filesystem, you only need to specify\n";
1874 print "that this is 'drafts', and be sure to put 'mail/' in option 1.\n";
1875 print "\n";
1876
1877 print "[$WHT$draft_folder$NRM]: $WHT";
1878 $new_draft_folder = <STDIN>;
1879 if ( $new_draft_folder eq "\n" ) {
1880 $new_draft_folder = $draft_folder;
1881 } else {
1882 if (check_imap_folder($new_draft_folder)) {
1883 $new_draft_folder =~ s/[\r\n]//g;
1884 } else {
1885 $new_draft_folder = $draft_folder;
1886 }
1887 }
1888 return $new_draft_folder;
1889 }
1890
1891 # default move to trash
1892 sub command24a {
1893 print "By default, should messages get moved to the trash folder? You\n";
1894 print "can specify the default trash folder in option 3. If this is set\n";
1895 print "to false, messages will get deleted immediately without moving\n";
1896 print "to the trash folder.\n";
1897 print "\n";
1898 print "Trash folder is currently: $trash_folder\n";
1899 print "\n";
1900
1901 if ( lc($default_move_to_trash) eq 'true' ) {
1902 $default_value = "y";
1903 } else {
1904 $default_value = "n";
1905 }
1906 print "By default, move to trash (y/n) [$WHT$default_value$NRM]: $WHT";
1907 $new_show = <STDIN>;
1908 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1909 $default_move_to_trash = 'true';
1910 } else {
1911 $default_move_to_trash = 'false';
1912 }
1913 return $default_move_to_trash;
1914 }
1915
1916 # default move to sent
1917 sub command24b {
1918 print "By default, should messages get moved to the sent folder? You\n";
1919 print "can specify the default sent folder in option 4. If this is set\n";
1920 print "to false, messages will get sent and no copy will be made.\n";
1921 print "\n";
1922 print "Sent folder is currently: $sent_folder\n";
1923 print "\n";
1924
1925 if ( lc($default_move_to_sent) eq 'true' ) {
1926 $default_value = "y";
1927 } else {
1928 $default_value = "n";
1929 }
1930 print "By default, move to sent (y/n) [$WHT$default_value$NRM]: $WHT";
1931 $new_show = <STDIN>;
1932 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1933 $default_move_to_sent = 'true';
1934 } else {
1935 $default_move_to_sent = 'false';
1936 }
1937 return $default_move_to_sent;
1938 }
1939
1940 # default save as draft
1941 sub command24c {
1942 print "By default, should the save to draft option be shown? You can\n";
1943 print "specify the default drafts folder in option 5. If this is set\n";
1944 print "to false, users will not be shown the save to draft option.\n";
1945 print "\n";
1946 print "Drafts folder is currently: $draft_folder\n";
1947 print "\n";
1948
1949 if ( lc($default_move_to_draft) eq 'true' ) {
1950 $default_value = "y";
1951 } else {
1952 $default_value = "n";
1953 }
1954 print "By default, save as draft (y/n) [$WHT$default_value$NRM]: $WHT";
1955 $new_show = <STDIN>;
1956 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1957 $default_save_as_draft = 'true';
1958 } else {
1959 $default_save_as_draft = 'false';
1960 }
1961 return $default_save_as_draft;
1962 }
1963
1964 # List special folders first
1965 sub command27 {
1966 print "SquirrelMail has what we call 'special folders' that are not\n";
1967 print "manipulated and viewed like normal folders. Some examples of\n";
1968 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
1969 print "Simply asks if you want these folders listed first in the folder\n";
1970 print "listing.\n";
1971 print "\n";
1972
1973 if ( lc($list_special_folders_first) eq 'true' ) {
1974 $default_value = "y";
1975 } else {
1976 $default_value = "n";
1977 }
1978 print "\n";
1979 print "List first (y/n) [$WHT$default_value$NRM]: $WHT";
1980 $new_show = <STDIN>;
1981 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
1982 $list_special_folders_first = 'true';
1983 } else {
1984 $list_special_folders_first = 'false';
1985 }
1986 return $list_special_folders_first;
1987 }
1988
1989 # Show special folders color
1990 sub command28 {
1991 print "SquirrelMail has what we call 'special folders' that are not\n";
1992 print "manipulated and viewed like normal folders. Some examples of\n";
1993 print "these folders would be INBOX, Trash, Sent, etc. This option\n";
1994 print "wants to know if we should display special folders in a\n";
1995 print "color than the other folders.\n";
1996 print "\n";
1997
1998 if ( lc($use_special_folder_color) eq 'true' ) {
1999 $default_value = "y";
2000 } else {
2001 $default_value = "n";
2002 }
2003 print "\n";
2004 print "Show color (y/n) [$WHT$default_value$NRM]: $WHT";
2005 $new_show = <STDIN>;
2006 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2007 $use_special_folder_color = 'true';
2008 } else {
2009 $use_special_folder_color = 'false';
2010 }
2011 return $use_special_folder_color;
2012 }
2013
2014 # Auto expunge
2015 sub command29 {
2016 print "The way that IMAP handles deleting messages is as follows. You\n";
2017 print "mark the message as deleted, and then to 'really' delete it, you\n";
2018 print "expunge it. This option asks if you want to just have messages\n";
2019 print "marked as deleted, or if you want SquirrelMail to expunge the \n";
2020 print "messages too.\n";
2021 print "\n";
2022
2023 if ( lc($auto_expunge) eq 'true' ) {
2024 $default_value = "y";
2025 } else {
2026 $default_value = "n";
2027 }
2028 print "Auto expunge (y/n) [$WHT$default_value$NRM]: $WHT";
2029 $new_show = <STDIN>;
2030 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2031 $auto_expunge = 'true';
2032 } else {
2033 $auto_expunge = 'false';
2034 }
2035 return $auto_expunge;
2036 }
2037
2038 # Default sub of inbox
2039 sub command210 {
2040 print "Some IMAP servers (Cyrus) have all folders as subfolders of INBOX.\n";
2041 print "This can cause some confusion in folder creation for users when\n";
2042 print "they try to create folders and don't put it as a subfolder of INBOX\n";
2043 print "and get permission errors. This option asks if you want folders\n";
2044 print "to be subfolders of INBOX by default.\n";
2045 print "\n";
2046
2047 if ( lc($default_sub_of_inbox) eq 'true' ) {
2048 $default_value = "y";
2049 } else {
2050 $default_value = "n";
2051 }
2052 print "Default sub of INBOX (y/n) [$WHT$default_value$NRM]: $WHT";
2053 $new_show = <STDIN>;
2054 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2055 $default_sub_of_inbox = 'true';
2056 } else {
2057 $default_sub_of_inbox = 'false';
2058 }
2059 return $default_sub_of_inbox;
2060 }
2061
2062 # Show contain subfolder option
2063 sub command211 {
2064 print "Some IMAP servers (UW) make it so that there are two types of\n";
2065 print "folders. Those that contain messages, and those that contain\n";
2066 print "subfolders. If this is the case for your server, set this to\n";
2067 print "true, and it will ask the user whether the folder they are\n";
2068 print "creating contains subfolders or messages.\n";
2069 print "\n";
2070
2071 if ( lc($show_contain_subfolders_option) eq 'true' ) {
2072 $default_value = "y";
2073 } else {
2074 $default_value = "n";
2075 }
2076 print "Show option (y/n) [$WHT$default_value$NRM]: $WHT";
2077 $new_show = <STDIN>;
2078 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2079 $show_contain_subfolders_option = 'true';
2080 } else {
2081 $show_contain_subfolders_option = 'false';
2082 }
2083 return $show_contain_subfolders_option;
2084 }
2085
2086 # Default Unseen Notify
2087 sub command212 {
2088 print "This option specifies where the users will receive notification\n";
2089 print "about unseen messages by default. This is of course an option that\n";
2090 print "can be changed on a user level.\n";
2091 print " 1 = No notification\n";
2092 print " 2 = Only on the INBOX\n";
2093 print " 3 = On all folders\n";
2094 print "\n";
2095
2096 print "Which one should be default (1,2,3)? [$WHT$default_unseen_notify$NRM]: $WHT";
2097 $new_show = <STDIN>;
2098 if ( $new_show =~ /^[123]\n/i ) {
2099 $default_unseen_notify = $new_show;
2100 }
2101 $default_unseen_notify =~ s/[\r\n]//g;
2102 return $default_unseen_notify;
2103 }
2104
2105 # Default Unseen Type
2106 sub command213 {
2107 print "Here you can define the default way that unseen messages will be displayed\n";
2108 print "to the user in the folder listing on the left side.\n";
2109 print " 1 = Only unseen messages (4)\n";
2110 print " 2 = Unseen and Total messages (4/27)\n";
2111 print "\n";
2112
2113 print "Which one should be default (1,2)? [$WHT$default_unseen_type$NRM]: $WHT";
2114 $new_show = <STDIN>;
2115 if ( $new_show =~ /^[12]\n/i ) {
2116 $default_unseen_type = $new_show;
2117 }
2118 $default_unseen_type =~ s/[\r\n]//g;
2119 return $default_unseen_type;
2120 }
2121
2122 # Auto create special folders
2123 sub command214 {
2124 print "Would you like the Sent, Trash, and Drafts folders to be created\n";
2125 print "automatically print for you when a user logs in? If the user\n";
2126 print "accidentally deletes their special folders, this option will\n";
2127 print "automatically create it again for them.\n";
2128 print "\n";
2129
2130 if ( lc($auto_create_special) eq 'true' ) {
2131 $default_value = "y";
2132 } else {
2133 $default_value = "n";
2134 }
2135 print "Auto create special folders? (y/n) [$WHT$default_value$NRM]: $WHT";
2136 $new_show = <STDIN>;
2137 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2138 $auto_create_special = 'true';
2139 } else {
2140 $auto_create_special = 'false';
2141 }
2142 return $auto_create_special;
2143 }
2144
2145 # Automatically delete folders
2146 sub command215 {
2147 if ( $imap_server_type eq "uw" ) {
2148 print "UW IMAP servers will not allow folders containing mail to also contain folders.\n";
2149 print "Deleting folders will bypass the trash folder and be immediately deleted\n\n";
2150 print "If this is not the correct value for your server,\n";
2151 print "please use option D on the Main Menu to configure your server correctly.\n\n";
2152 print "Press enter to continue...\n";
2153 $new_delete = <STDIN>;
2154 $delete_folder = 'true';
2155 } else {
2156 if ( $imap_server_type eq "courier" ) {
2157 print "Courier (or Courier-IMAP) IMAP servers may not support ";
2158 print "subfolders of Trash. \n";
2159 print "Specifically, if Courier is set to always move messages to Trash, \n";
2160 print "Trash will be treated by Courier as a special folder that does not \n";
2161 print "allow subfolders. \n\n";
2162 print "Please verify your Courier configuration, and test folder deletion \n";
2163 print "when changing this setting.\n\n";
2164 }
2165
2166 print "Are subfolders of the Trash supported by your IMAP server?\n";
2167 print "If so, should deleted folders be sent to Trash?\n";
2168 print "If not, say no (deleted folders should not be sent to Trash)\n\n";
2169 # reversal of logic.
2170 # question was: Should folders be automatically deleted instead of sent to trash..
2171 # we've changed the question to make it more clear,
2172 # and are here handling that to avoid changing the answers..
2173 if ( lc($delete_folder) eq 'true' ) {
2174 $default_value = "n";
2175 } else {
2176 $default_value = "y";
2177 }
2178 print "Send deleted folders to Trash? (y/n) [$WHT$default_value$NRM]: $WHT";
2179 $new_delete = <STDIN>;
2180 if ( ( $new_delete =~ /^y\n/i ) || ( ( $new_delete =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2181 $delete_folder = 'false';
2182 } else {
2183 $delete_folder = 'true';
2184 }
2185 }
2186 return $delete_folder;
2187 }
2188
2189 #noselect fix
2190 sub command216 {
2191 print "Some IMAP servers allow subfolders to exist even if the parent\n";
2192 print "folders do not. This fixes some problems with the folder list\n";
2193 print "when this is the case, causing the /NoSelect folders to be displayed\n";
2194 print "\n";
2195
2196 if ( lc($noselect_fix_enable) eq 'true' ) {
2197 $default_value = "y";
2198 } else {
2199 $default_value = "n";
2200 }
2201 print "enable noselect fix? (y/n) [$WHT$noselect_fix_enable$NRM]: $WHT";
2202 $noselect_fix_enable = <STDIN>;
2203 if ( ( $noselect_fix_enable =~ /^y\n/i ) || ( ( $noselect_fix_enable =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2204 $noselect_fix_enable = 'true';
2205 } else {
2206 $noselect_fix_enable = 'false';
2207 }
2208 return $noselect_fix_enable;
2209 }
2210 ############# GENERAL OPTIONS #####################
2211
2212 # Data directory
2213 sub command33a {
2214 print "Specify the location for your data directory.\n";
2215 print "You need to create this directory yourself.\n";
2216 print "The path name can be absolute or relative (to the config directory).\n";
2217 print "Here are two examples:\n";
2218 print " Absolute: /var/local/squirrelmail/data/\n";
2219 print " Relative: ../data/\n";
2220 print "Relative paths to directories outside of the SquirrelMail distribution\n";
2221 print "will be converted to their absolute path equivalents in config.php.\n\n";
2222 print "Note: There are potential security risks with having a writeable directory\n";
2223 print "under the web server's root directory (ex: /home/httpd/html).\n";
2224 print "For this reason, it is recommended to put the data directory\n";
2225 print "in an alternate location of your choice. \n";
2226 print "\n";
2227
2228 print "[$WHT$data_dir$NRM]: $WHT";
2229 $new_data_dir = <STDIN>;
2230 if ( $new_data_dir eq "\n" ) {
2231 $new_data_dir = $data_dir;
2232 } else {
2233 $new_data_dir =~ s/[\r\n]//g;
2234 }
2235 if ( $new_data_dir =~ /^\s*$/ ) {
2236 $new_data_dir = "";
2237 } else {
2238 $new_data_dir =~ s/\/*$//g;
2239 $new_data_dir =~ s/$/\//g;
2240 }
2241 return $new_data_dir;
2242 }
2243
2244 # Attachment directory
2245 sub command33b {
2246 print "Path to directory used for storing attachments while a mail is\n";
2247 print "being composed. The path name can be absolute or relative (to the\n";
2248 print "config directory). Here are two examples:\n";
2249 print " Absolute: /var/local/squirrelmail/attach/\n";
2250 print " Relative: ../attach/\n";
2251 print "Relative paths to directories outside of the SquirrelMail distribution\n";
2252 print "will be converted to their absolute path equivalents in config.php.\n\n";
2253 print "Note: There are a few security considerations regarding this\n";
2254 print "directory:\n";
2255 print " 1. It should have the permission 733 (rwx-wx-wx) to make it\n";
2256 print " impossible for a random person with access to the webserver\n";
2257 print " to list files in this directory. Confidential data might\n";
2258 print " be laying around in there.\n";
2259 print " Depending on your user:group assignments, 730 (rwx-wx---)\n";
2260 print " may be possible, and more secure (e.g. root:apache)\n";
2261 print " 2. Since the webserver is not able to list the files in the\n";
2262 print " content is also impossible for the webserver to delete files\n";
2263 print " lying around there for too long.\n";
2264 print " 3. It should probably be another directory than the data\n";
2265 print " directory specified in option 3.\n";
2266 print "\n";
2267
2268 print "[$WHT$attachment_dir$NRM]: $WHT";
2269 $new_attachment_dir = <STDIN>;
2270 if ( $new_attachment_dir eq "\n" ) {
2271 $new_attachment_dir = $attachment_dir;
2272 } else {
2273 $new_attachment_dir =~ s/[\r\n]//g;
2274 }
2275 if ( $new_attachment_dir =~ /^\s*$/ ) {
2276 $new_attachment_dir = "";
2277 } else {
2278 $new_attachment_dir =~ s/\/*$//g;
2279 $new_attachment_dir =~ s/$/\//g;
2280 }
2281 return $new_attachment_dir;
2282 }
2283
2284 sub command33c {
2285 print "The directory hash level setting allows you to configure the level\n";
2286 print "of hashing that SquirrelMail employs in your data and attachment\n";
2287 print "directories. This value must be an integer ranging from 0 to 4.\n";
2288 print "When this value is set to 0, SquirrelMail will simply store all\n";
2289 print "files as normal in the data and attachment directories. However,\n";
2290 print "when set to a value from 1 to 4, a simple hashing scheme will be\n";
2291 print "used to organize the files in this directory. In short, the crc32\n";
2292 print "value for a username will be computed. Then, up to the first 4\n";
2293 print "digits of the hash, as set by this configuration value, will be\n";
2294 print "used to directory hash the files for that user in the data and\n";
2295 print "attachment directory. This allows for better performance on\n";
2296 print "servers with larger numbers of users.\n";
2297 print "\n";
2298
2299 print "[$WHT$dir_hash_level$NRM]: $WHT";
2300 $new_dir_hash_level = <STDIN>;
2301 if ( $new_dir_hash_level eq "\n" ) {
2302 $new_dir_hash_level = $dir_hash_level;
2303 } else {
2304 $new_dir_hash_level =~ s/[\r\n]//g;
2305 }
2306 if ( ( int($new_dir_hash_level) < 0 )
2307 || ( int($new_dir_hash_level) > 4 )
2308 || !( int($new_dir_hash_level) eq $new_dir_hash_level ) ) {
2309 print "Invalid Directory Hash Level.\n";
2310 print "Value must be an integer ranging from 0 to 4\n";
2311 print "Hit enter to continue.\n";
2312 $enter_key = <STDIN>;
2313
2314 $new_dir_hash_level = $dir_hash_level;
2315 }
2316
2317 return $new_dir_hash_level;
2318 }
2319
2320 sub command35 {
2321 print "This is the default size (in pixels) of the left folder list.\n";
2322 print "Default is 200, but you can set it to whatever you wish. This\n";
2323 print "is a user preference, so this will only show up as their default.\n";
2324 print "\n";
2325 print "[$WHT$default_left_size$NRM]: $WHT";
2326 $new_default_left_size = <STDIN>;
2327 if ( $new_default_left_size eq "\n" ) {
2328 $new_default_left_size = $default_left_size;
2329 } else {
2330 $new_default_left_size =~ s/[\r\n]//g;
2331 }
2332 return $new_default_left_size;
2333 }
2334
2335 sub command36 {
2336 print "Some IMAP servers only have lowercase letters in the usernames\n";
2337 print "but they still allow people with uppercase to log in. This\n";
2338 print "causes a problem with the user's preference files. This option\n";
2339 print "transparently changes all usernames to lowercase.";
2340 print "\n";
2341
2342 if ( lc($force_username_lowercase) eq 'true' ) {
2343 $default_value = "y";
2344 } else {
2345 $default_value = "n";
2346 }
2347 print "Convert usernames to lowercase (y/n) [$WHT$default_value$NRM]: $WHT";
2348 $new_show = <STDIN>;
2349 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2350 return 'true';
2351 }
2352 return 'false';
2353 }
2354
2355 sub command37 {
2356 print "";
2357 print "\n";
2358
2359 if ( lc($default_use_priority) eq 'true' ) {
2360 $default_value = "y";
2361 } else {
2362 $default_value = "n";
2363 }
2364
2365 print "Allow users to specify priority of outgoing mail (y/n) [$WHT$default_value$NRM]: $WHT";
2366 $new_show = <STDIN>;
2367 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2368 return 'true';
2369 }
2370 return 'false';
2371 }
2372
2373 sub command38 {
2374 print "";
2375 print "\n";
2376
2377 if ( lc($hide_sm_attributions) eq 'true' ) {
2378 $default_value = "y";
2379 } else {
2380 $default_value = "n";
2381 }
2382
2383 print "Hide SM attributions (y/n) [$WHT$default_value$NRM]: $WHT";
2384 $new_show = <STDIN>;
2385 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2386 return 'true';
2387 }
2388 return 'false';
2389 }
2390
2391 sub command39 {
2392 print "";
2393 print "\n";
2394
2395 if ( lc($default_use_mdn) eq 'true' ) {
2396 $default_value = "y";
2397 } else {
2398 $default_value = "n";
2399 }
2400
2401 print "Enable support for read/delivery receipt support (y/n) [$WHT$default_value$NRM]: $WHT";
2402 $new_show = <STDIN>;
2403 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2404 return 'true';
2405 }
2406 return 'false';
2407 }
2408
2409
2410 sub command310 {
2411 print " In loosely managed environments, you may want to allow users
2412 to edit their full name and email address. In strictly managed
2413 environments, you may want to force users to use the name
2414 and email address assigned to them.
2415
2416 'y' - allow a user to edit their full name and email address,
2417 'n' - users must use the assigned values.
2418
2419 ";
2420
2421 if ( lc($edit_identity) eq 'true' ) {
2422 $default_value = "y";
2423 } else {
2424 $default_value = "n";
2425 }
2426 print "Allow editing of user's identity? (y/n) [$WHT$default_value$NRM]: $WHT";
2427 $new_edit = <STDIN>;
2428 if ( ( $new_edit =~ /^y\n/i ) || ( ( $new_edit =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2429 $edit_identity = 'true';
2430 $edit_name = 'true';
2431 $hide_auth_header = command311b();
2432 } else {
2433 $edit_identity = 'false';
2434 $edit_name = command311();
2435 $hide_auth_header = command311b();
2436 }
2437 return $edit_identity;
2438 }
2439
2440 sub command311 {
2441 print " Given that users are not allowed to modify their
2442 email address, can they edit their full name?
2443
2444 ";
2445
2446 if ( lc($edit_name) eq 'true' ) {
2447 $default_value = "y";
2448 } else {
2449 $default_value = "n";
2450 }
2451 print "Allow the user to edit their full name? (y/n) [$WHT$default_value$NRM]: $WHT";
2452 $new_edit = <STDIN>;
2453 if ( ( $new_edit =~ /^y\n/i ) || ( ( $new_edit =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2454 $edit_name = 'true';
2455 } else {
2456 $edit_name = 'false';
2457 }
2458 return $edit_name;
2459 }
2460
2461 sub command311b {
2462 print " SquirrelMail adds username information to every sent email
2463 in order to prevent possible sender forging when users are allowed
2464 to change their email and/or full name.
2465
2466 You can remove user information from this header (y), if you think that
2467 it violates privacy or security.
2468
2469 Note: If users are allowed to change their email addresses,
2470 this setting will make it difficult to determine who sent what where.
2471 Use at your own risk.
2472
2473 ";
2474
2475 if ( lc($hide_auth_header) eq "true" ) {
2476 $default_value = "y";
2477 } else {
2478 $default_value = "n";
2479 }
2480 print "Remove username from email headers? (y/n) [$WHT$default_value$NRM]: $WHT";
2481 $new_header = <STDIN>;
2482 if ( ( $new_header =~ /^y\n/i ) || ( ( $new_header =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2483 $hide_auth_header = "true";
2484 } else {
2485 $hide_auth_header = "false";
2486 }
2487 return $hide_auth_header;
2488 }
2489
2490 sub command312 {
2491 print "This option allows you to disable server side thread sorting if your server \n";
2492 print "declares THREAD support, but you don't want to provide threading options \n";
2493 print "to end users or THREAD extension is broken or extension does not work with \n";
2494 print "options used by SquirrelMail. Option is not used, if THREAD extension is \n";
2495 print "not declared in IMAP CAPABILITY.\n";
2496 print "\n";
2497
2498 if ( lc($disable_thread_sort) eq 'true' ) {
2499 $default_value = "y";
2500 } else {
2501 $default_value = "n";
2502 }
2503 print "Disable server side thread sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
2504 $disable_thread_sort = <STDIN>;
2505 if ( ( $disable_thread_sort =~ /^y\n/i ) || ( ( $disable_thread_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2506 $disable_thread_sort = 'true';
2507 } else {
2508 $disable_thread_sort = 'false';
2509 }
2510 return $disable_thread_sort;
2511 }
2512
2513 sub command313 {
2514 print "This option allows you to disable server side sorting if your server declares \n";
2515 print "SORT support, but SORT extension is broken or does not work with options \n";
2516 print "used by SquirrelMail. Option is not used, if SORT extension is not declared \n";
2517 print "in IMAP CAPABILITY.\n";
2518 print "\n";
2519 print "It is strongly recommended to keep server side sorting enabled, if your ";
2520 print "IMAP server supports it.";
2521 print "\n";
2522
2523 if ( lc($disable_server_sort) eq 'true' ) {
2524 $default_value = "y";
2525 } else {
2526 $default_value = "n";
2527 }
2528 print "Disable server-side sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
2529 $disable_server_sort = <STDIN>;
2530 if ( ( $disable_server_sort =~ /^y\n/i ) || ( ( $disable_server_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2531 $disable_server_sort = 'true';
2532 } else {
2533 $disable_server_sort = 'false';
2534 }
2535 return $disable_server_sort;
2536 }
2537
2538 sub command314 {
2539 print "This option allows you to choose if SM uses charset search\n";
2540 print "Your IMAP server must support the SEARCH CHARSET command for this to work\n";
2541 print "\n";
2542
2543 if ( lc($allow_charset_search) eq 'true' ) {
2544 $default_value = "y";
2545 } else {
2546 $default_value = "n";
2547 }
2548 print "Allow charset searching? (y/n) [$WHT$default_value$NRM]: $WHT";
2549 $allow_charset_search = <STDIN>;
2550 if ( ( $allow_charset_search =~ /^y\n/i ) || ( ( $allow_charset_search =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2551 $allow_charset_search = 'true';
2552 } else {
2553 $allow_charset_search = 'false';
2554 }
2555 return $allow_charset_search;
2556 }
2557
2558 # command315 (UID support) obsoleted.
2559
2560 # advanced search option
2561 sub command316 {
2562 print "This option allows you to control the use of advanced search form.\n";
2563 print " 0 = enable basic search only\n";
2564 print " 1 = enable advanced search only\n";
2565 print " 2 = enable both\n";
2566 print "\n";
2567
2568 print "Allowed search (0,1,2)? [$WHT$allow_advanced_search$NRM]: $WHT";
2569 $new_allow_advanced_search = <STDIN>;
2570 if ( $new_allow_advanced_search =~ /^[012]\n/i ) {
2571 $allow_advanced_search = $new_allow_advanced_search;
2572 }
2573 $allow_advanced_search =~ s/[\r\n]//g;
2574 return $allow_advanced_search;
2575 }
2576
2577
2578 sub command317 {
2579 print "This option allows you to change the name of the PHP session used\n";
2580 print "by SquirrelMail. Unless you know what you are doing, you probably\n";
2581 print "don't need or want to change this from the default of SQMSESSID.\n";
2582 print "[$WHT$session_name$NRM]: $WHT";
2583 $new_session_name = <STDIN>;
2584 chomp($new_session_name);
2585 if ( $new_session_name eq "" ) {
2586 $new_session_name = $session_name;
2587 }
2588 return $new_session_name;
2589 }
2590
2591 # time zone config (since 1.5.1)
2592 sub command318 {
2593 print "This option allows you to control the use of time zones.\n";
2594 print " 0 = (default) standard, GNU C time zone names\n";
2595 print " 1 = strict, generic time zone codes with offsets\n";
2596 print " 2 = custom, GNU C time zones loaded from config/timezones.php\n";
2597 print " 3 = custom strict, generic time zone codes with offsets loaded \n";
2598 print " from config/timezones.php\n";
2599 print "See SquirrelMail documentation about format of config/timezones.php file.\n";
2600 print "\n";
2601
2602 print "Used time zone configuration (0,1,2,3)? [$WHT$time_zone_type$NRM]: $WHT";
2603 $new_time_zone_type = <STDIN>;
2604 if ( $new_time_zone_type =~ /^[0123]\n/i ) {
2605 $time_zone_type = $new_time_zone_type;
2606 } else {
2607 print "\nInvalid configuration value.\n";
2608 print "\nPress enter to continue...";
2609 $tmp = <STDIN>;
2610 }
2611 $time_zone_type =~ s/[\r\n]//g;
2612 return $time_zone_type;
2613 }
2614
2615 # set the location base for redirects (since 1.5.2)
2616 sub command_config_location_base {
2617 print "Here you can set the base part of the SquirrelMail URL.\n";
2618 print "It is normally autodetected but if that fails, use this\n";
2619 print "option to override.\n";
2620 print "It should contain only the protocol and hostname/port parts\n";
2621 print "of the URL; the full path will be appended automatically.\n\n";
2622 print "Examples:\nhttp://webmail.example.org\nhttp://webmail.example.com:8080\nhttps://webmail.example.com:6691\n\n";
2623 print "Do not add any path elements.\n";
2624
2625 print "URL base? [" .$WHT."autodetect$NRM]: $WHT";
2626 $new_config_location_base = <STDIN>;
2627 chomp($new_config_location_base);
2628 $config_location_base = $new_config_location_base;
2629
2630 return $config_location_base;
2631 }
2632
2633 # only_secure_cookies (since 1.5.2)
2634 sub command319 {
2635 print "This option allows you to specify that if a user session is initiated\n";
2636 print "under a secure (HTTPS, SSL-encrypted) connection, the cookies given to\n";
2637 print "the browser will ONLY be transmitted via a secure connection henceforth.\n\n";
2638 print "Generally this is a Good Thing, and should NOT be disabled. However,\n";
2639 print "if you intend to use the Secure Login or Show SSL Link plugins to\n";
2640 print "encrypt the user login, but not the rest of the SquirrelMail session,\n";
2641 print "this can be turned off. Think twice before doing so.\n";
2642 print "\n";
2643
2644 if ( lc($only_secure_cookies) eq 'true' ) {
2645 $default_value = "y";
2646 } else {
2647 $default_value = "n";
2648 }
2649 print "Transmit cookies only on secure connection when available? (y/n) [$WHT$default_value$NRM]: $WHT";
2650 $only_secure_cookies = <STDIN>;
2651 if ( ( $only_secure_cookies =~ /^y\n/i ) || ( ( $only_secure_cookies =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
2652 $only_secure_cookies = 'true';
2653 } else {
2654 $only_secure_cookies = 'false';
2655 }
2656 return $only_secure_cookies;
2657 }
2658
2659
2660 sub command_userThemes {
2661 print "\nDefine the user themes that you wish to use. If you have added\n";
2662 print "a theme of your own, just follow the instructions (?) about\n";
2663 print "how to add them. You can also change the default theme.\n\n";
2664
2665 print "Available user themes:\n";
2666 $count = 0;
2667 while ( $count <= $#user_theme_name ) {
2668 if ( $count == $user_theme_default ) {
2669 print " *";
2670 } else {
2671 print " ";
2672 }
2673 if ( $count < 10 ) {
2674 print " ";
2675 }
2676 $name = $user_theme_name[$count];
2677 $num_spaces = 35 - length($name);
2678 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
2679 $name = $name . " ";
2680 }
2681
2682 print " $count. $name";
2683 print "($user_theme_path[$count])\n";
2684
2685 $count++;
2686 }
2687
2688 print "\n";
2689 print ".------------------------------------.\n";
2690 print "| t (detect user themes) |\n";
2691 print "| + (add user theme) |\n";
2692 print "| - N (remove user theme) |\n";
2693 print "| m N (mark default user theme) |\n";
2694 print "| l (list user themes) |\n";
2695 print "| d (done) |\n";
2696 print "`------------------------------------'\n";
2697
2698 print "\n[user_themes] command (?=help) > ";
2699 $input = <STDIN>;
2700 $input =~ s/[\r\n]//g;
2701 while ( $input ne "d" ) {
2702 if ( $input =~ /^\s*l\s*/i ) {
2703 $count = 0;
2704 while ( $count <= $#user_theme_name ) {
2705 if ( $count == $user_theme_default ) {
2706 print " *";
2707 } else {
2708 print " ";
2709 }
2710 if ( $count < 10 ) {
2711 print " ";
2712 }
2713 $name = $user_theme_name[$count];
2714 $num_spaces = 35 - length($name);
2715 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
2716 $name = $name . " ";
2717 }
2718
2719 print " $count. $name";
2720 print "($user_theme_path[$count])\n";
2721
2722 $count++;
2723 }
2724 } elsif ( $input =~ /^\s*m\s*[0-9]+/i ) {
2725 $old_def = $user_theme_default;
2726 $user_theme_default = $input;
2727 $user_theme_default =~ s/^\s*m\s*//;
2728 if ( ( $user_theme_default > $#user_theme_name ) || ( $user_theme_default < 0 ) ) {
2729 print "Cannot set default theme to $user_theme_default. That theme does not exist.\n";
2730 $user_theme_default = $old_def;
2731 }
2732 } elsif ( $input =~ /^\s*\+/ ) {
2733 print "What is the name of this theme? ";
2734 $name = <STDIN>;
2735 $name =~ s/[\r\n]//g;
2736 $user_theme_name[ $#user_theme_name + 1 ] = $name;
2737 print "Be sure to put ../css/ before the filename.\n";
2738 print "What file is this stored in (ex: ../css/my_theme/): ";
2739 $name = <STDIN>;
2740 $name =~ s/[\r\n]//g;
2741 $user_theme_path[ $#user_theme_path + 1 ] = $name;
2742 } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
2743 if ( $input =~ /[0-9]+\s*$/ ) {
2744 $rem_num = $input;
2745 $rem_num =~ s/^\s*-\s*//g;
2746 $rem_num =~ s/\s*$//;
2747 } else {
2748 $rem_num = $#user_theme_name;
2749 }
2750 if ( $rem_num == $user_theme_default ) {
2751 print "You cannot remove the default theme!\n";
2752 } else {
2753 $count = 0;
2754 @new_theme_name = ();
2755 @new_theme_path = ();
2756 while ( $count <= $#user_theme_name ) {
2757 if ( $count != $rem_num ) {
2758 @new_theme_name = ( @new_theme_name, $user_theme_name[$count] );
2759 @new_theme_path = ( @new_theme_path, $user_theme_path[$count] );
2760 }
2761 $count++;
2762 }
2763 @user_theme_name = @new_theme_name;
2764 @user_theme_path = @new_theme_path;
2765 if ( $user_theme_default > $rem_num ) {
2766 $user_theme_default--;
2767 }
2768 }
2769 } elsif ( $input =~ /^\s*t\s*/i ) {
2770 print "\nStarting detection...\n\n";
2771
2772 opendir( DIR, "../css" );
2773 @files = readdir(DIR);
2774 $cnt = 0;
2775 while ( $cnt <= $#files ) {
2776 $filename = "../css/" . $files[$cnt] .'/';
2777 if ( $filename ne "../css/rtl.css" && -e $filename . "default.css" ) {
2778 $found = 0;
2779 for ( $x = 0 ; $x <= $#user_theme_path ; $x++ ) {
2780 if ( $user_theme_path[$x] eq $filename ) {
2781 $found = 1;
2782 }
2783 }
2784 if ( $found != 1 ) {
2785 print "** Found user theme: $filename\n";
2786 print " What is its name? ";
2787 $nm = <STDIN>;
2788 $nm =~ s/[\n\r]//g;
2789 $user_theme_name[ $#user_theme_name + 1 ] = $nm;
2790 $user_theme_path[ $#user_theme_path + 1 ] = $filename;
2791 }
2792 }
2793 $cnt++;
2794 }
2795 print "\n";
2796 for ( $cnt = 0 ; $cnt <= $#user_theme_path ; $cnt++ ) {
2797 $filename = $user_theme_path[$cnt];
2798 if ( $filename != 'none' && !( -e $filename ."/default.css" ) ) {
2799 print " Removing $filename (file not found)\n";
2800 $offset = 0;
2801 @new_user_theme_name = ();
2802 @new_user_theme_path = ();
2803 for ( $x = 0 ; $x < $#user_theme_path ; $x++ ) {
2804 if ( $user_theme_path[$x] eq $filename ) {
2805 $offset = 1;
2806 }
2807 if ( $offset == 1 ) {
2808 $new_user_theme_name[$x] = $user_theme_name[ $x + 1 ];
2809 $new_user_theme_path[$x] = $user_theme_path[ $x + 1 ];
2810 } else {
2811 $new_user_theme_name[$x] = $user_theme_name[$x];
2812 $new_user_theme_path[$x] = $user_theme_path[$x];
2813 }
2814 }
2815 @user_theme_name = @new_user_theme_name;
2816 @user_theme_path = @new_user_theme_path;
2817 }
2818 }
2819 print "\nDetection complete!\n\n";
2820
2821 closedir DIR;
2822 } elsif ( $input =~ /^\s*\?\s*/ ) {
2823 print ".------------------------------------.\n";
2824 print "| t (detect user themes) |\n";
2825 print "| + (add user theme) |\n";
2826 print "| - N (remove user theme) |\n";
2827 print "| m N (mark default user theme) |\n";
2828 print "| l (list user themes) |\n";
2829 print "| d (done) |\n";
2830 print "`------------------------------------'\n";
2831 }
2832 print "[user_themes] command (?=help) > ";
2833 $input = <STDIN>;
2834 $input =~ s/[\r\n]//g;
2835 }
2836 }
2837
2838 sub command_iconSets {
2839 print "\nDefine the icon themes that you wish to use. If you have added\n";
2840 print "a theme of your own, just follow the instructions (?) about\n";
2841 print "how to add them. You can also change the default and fallback\n";
2842 print "themes. The default theme will be used when no icon theme is\n";
2843 print "set by the user. The fallback theme will be used if an icon\n";
2844 print "cannot be found in the currently selected icon theme.\n\n";
2845
2846 print "Available icon themes:\n\n";
2847
2848 $count = 0;
2849 while ( $count <= $#icon_theme_name ) {
2850 if ( $count == $icon_theme_def ) {
2851 print " d";
2852 } else {
2853 print " ";
2854 }
2855 if ( $count eq $icon_theme_fallback ) {
2856 print "f ";
2857 } else {
2858 print " ";
2859 }
2860 if ( $count < 10 ) {
2861 print " ";
2862 }
2863 $name = $icon_theme_name[$count];
2864 $num_spaces = 35 - length($name);
2865 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
2866 $name = $name . " ";
2867 }
2868
2869 print " $count. $name";
2870 print "($icon_theme_path[$count])\n";
2871
2872 $count++;
2873 }
2874
2875 print "\n d = Default icon theme\n";
2876 print " f = Fallback icon theme\n";
2877 print "\n";
2878 print ".------------------------------------.\n";
2879 print "| t (detect icon themes) |\n";
2880 print "| + (add icon theme) |\n";
2881 print "| - N (remove icon theme) |\n";
2882 print "| m N (mark default icon theme) |\n";
2883 print "| f N (set fallback icon set) |\n";
2884 print "| l (list icon themes) |\n";
2885 print "| d (done) |\n";
2886 print "`------------------------------------'\n";
2887
2888 print "\n[icon_themes] command (?=help) > ";
2889 $input = <STDIN>;
2890 $input =~ s/[\r\n]//g;
2891 while ( $input ne "d" ) {
2892 if ( $input =~ /^\s*l\s*/i ) {
2893 $count = 0;
2894 print "\n";
2895 while ( $count <= $#icon_theme_name ) {
2896 if ( $count == $icon_theme_def ) {
2897 print " d";
2898 } else {
2899 print " ";
2900 }
2901 if ( $count eq $icon_theme_fallback ) {
2902 print "f ";
2903 } else {
2904 print " ";
2905 }
2906 $name = $icon_theme_name[$count];
2907 $num_spaces = 35 - length($name);
2908 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
2909 $name = $name . " ";
2910 }
2911
2912 print " $count. $name";
2913 print "($icon_theme_path[$count])\n";
2914
2915 $count++;
2916 }
2917 print "\n d = Default icon theme\n";
2918 print " f = Fallback icon theme\n\n";
2919 } elsif ( $input =~ /^\s*m\s*[0-9]+/i ) {
2920 $old_def = $icon_theme_def;
2921 $icon_theme_def = $input;
2922 $icon_theme_def =~ s/^\s*m\s*//;
2923 if ( ( $icon_theme_default > $#icon_theme_name ) || ( $icon_theme_default < 0 ) ) {
2924 print "Cannot set default icon theme to $icon_theme_default. That theme does not exist.\n";
2925 $icon_theme_def = $old_def;
2926 }
2927 } elsif ( $input =~ /^\s*f\s*[0-9]+/i ) {
2928 $old_fb = $icon_theme_fallback;
2929 $icon_theme_fallback = $input;
2930 $icon_theme_fallback =~ s/^\s*f\s*//;
2931 if ( ( $icon_theme_fallback > $#icon_theme_name ) || ( $icon_theme_fallback < 0 ) ) {
2932 print "Cannot set fallback icon theme to $icon_theme_fallback. That theme does not exist.\n";
2933 $icon_theme_fallback = $old_fb;
2934 }
2935 } elsif ( $input =~ /^\s*\+/ ) {
2936 print "What is the name of this icon theme? ";
2937 $name = <STDIN>;
2938 $name =~ s/[\r\n]//g;
2939 $icon_theme_name[ $#icon_theme_name + 1 ] = $name;
2940 print "Be sure to put ../images/themes/ before the filename.\n";
2941 print "What directory is this icon theme stored in (ex: ../images/themes/my_theme/)? ";
2942 $name = <STDIN>;
2943 $name =~ s/[\r\n]//g;
2944 $icon_theme_path[ $#icon_theme_path + 1 ] = $name;
2945 } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
2946 if ( $input =~ /[0-9]+\s*$/ ) {
2947 $rem_num = $input;
2948 $rem_num =~ s/^\s*-\s*//g;
2949 $rem_num =~ s/\s*$//;
2950 } else {
2951 $rem_num = $#icon_theme_name;
2952 }
2953 if ( $rem_num == $icon_theme_def ) {
2954 print "You cannot remove the default icon theme!\n";
2955 } elsif ( $rem_num == $icon_theme_fallback ) {
2956 print "You cannot remove the fallback icon theme!\n";
2957 } else {
2958 $count = 0;
2959 @new_theme_name = ();
2960 @new_theme_path = ();
2961 while ( $count <= $#icon_theme_name ) {
2962 if ( $count != $rem_num ) {
2963 @new_theme_name = ( @new_theme_name, $icon_theme_name[$count] );
2964 @new_theme_path = ( @new_theme_path, $icon_theme_path[$count] );
2965 }
2966 $count++;
2967 }
2968 @icon_theme_name = @new_theme_name;
2969 @icon_theme_path = @new_theme_path;
2970 if ( $icon_theme_def > $rem_num ) {
2971 $icon_theme_def--;
2972 }
2973 }
2974 } elsif ( $input =~ /^\s*t\s*/i ) {
2975 print "\nStarting detection...\n\n";
2976
2977 opendir( DIR, "../images/themes/" );
2978 @files = readdir(DIR);
2979 $cnt = 0;
2980 while ( $cnt <= $#files ) {
2981 $filename = "../images/themes/" . $files[$cnt] .'/';
2982 if ( -d "../images/themes/" . $files[$cnt] && $files[$cnt] !~ /^\./ && $files[$cnt] ne "CVS" ) {
2983 $found = 0;
2984 for ( $x = 0 ; $x <= $#icon_theme_path ; $x++ ) {
2985 if ( $icon_theme_path[$x] eq $filename ) {
2986 $found = 1;
2987 }
2988 }
2989 if ( $found != 1 ) {
2990 print "** Found icon theme: $filename\n";
2991 print " What is its name? ";
2992 $nm = <STDIN>;
2993 $nm =~ s/[\n\r]//g;
2994 $icon_theme_name[ $#icon_theme_name + 1 ] = $nm;
2995 $icon_theme_path[ $#icon_theme_path + 1 ] = $filename;
2996 }
2997 }
2998 $cnt++;
2999 }
3000 print "\n";
3001 for ( $cnt = 0 ; $cnt <= $#icon_theme_path ; $cnt++ ) {
3002 $filename = $icon_theme_path[$cnt];
3003 if ( $filename ne "none" && $filename ne "template" && ! -d $filename ) {
3004 print " Removing $filename (file not found)\n";
3005 $offset = 0;
3006 @new_icon_theme_name = ();
3007 @new_icon_theme_path = ();
3008 for ( $x = 0 ; $x < $#icon_theme_path ; $x++ ) {
3009 if ( $icon_theme_path[$x] eq $filename ) {
3010 $offset = 1;
3011 }
3012 if ( $offset == 1 ) {
3013 $new_icon_theme_name[$x] = $icon_theme_name[ $x + 1 ];
3014 $new_icon_theme_path[$x] = $icon_theme_path[ $x + 1 ];
3015 } else {
3016 $new_icon_theme_name[$x] = $icon_theme_name[$x];
3017 $new_icon_theme_path[$x] = $icon_theme_path[$x];
3018 }
3019 }
3020 @icon_theme_name = @new_icon_theme_name;
3021 @icon_theme_path = @new_icon_theme_path;
3022 }
3023 }
3024 print "\nDetection complete!\n\n";
3025
3026 closedir DIR;
3027 } elsif ( $input =~ /^\s*\?\s*/ ) {
3028 print ".------------------------------------.\n";
3029 print "| t (detect icon themes) |\n";
3030 print "| + (add icon theme) |\n";
3031 print "| - N (remove icon theme) |\n";
3032 print "| m N (mark default icon theme) |\n";
3033 print "| f N (set fallback icon set) |\n";
3034 print "| l (list icon themes) |\n";
3035 print "| d (done) |\n";
3036 print "`------------------------------------'\n";
3037 }
3038 print "[icon_themes] command (?=help) > ";
3039 $input = <STDIN>;
3040 $input =~ s/[\r\n]//g;
3041 }
3042 }
3043
3044 sub command_templates {
3045 print "\nDefine the template sets (skins) that you wish to use. If you have added\n";
3046 print "a template set of your own, just follow the instructions (?) about\n";
3047 print "how to add them. You can also change the default template.\n";
3048
3049 print "\n Available Templates:\n";
3050
3051 $count = 0;
3052 while ( $count <= $#templateset_name ) {
3053 if ( $templateset_id[$count] eq $templateset_default ) {
3054 print " d";
3055 } else {
3056 print " ";
3057 }
3058 if ( $templateset_id[$count] eq $templateset_fallback ) {
3059 print "f ";
3060 } else {
3061 print " ";
3062 }
3063 if ( $count < 10 ) {
3064 print " ";
3065 }
3066 $name = $templateset_name[$count];
3067 $num_spaces = 35 - length($name);
3068 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
3069 $name = $name . " ";
3070 }
3071
3072 print " $count. $name";
3073 print "($templateset_id[$count])\n";
3074
3075 $count++;
3076 }
3077 print "\n d = default template set\n"
3078 . " f = fallback template set\n\n";
3079
3080 $menu_text = ".-------------------------------------.\n"
3081 . "| t (detect template set) |\n"
3082 . "| + (add template set) |\n"
3083 . "| - N (remove template set) |\n"
3084 . "| m N (mark default template set) |\n"
3085 . "| f N (set fallback template set) |\n"
3086 . "| l (list template sets/skins) |\n"
3087 . "| d (done) |\n"
3088 . "|-------------------------------------|\n"
3089 . "| where N is a template set number |\n"
3090 . "`-------------------------------------'\n";
3091 print "\n";
3092 print $menu_text;
3093 print "\n[template set] command (?=help) > ";
3094
3095 $input = <STDIN>;
3096 $input =~ s/[\r\n]//g;
3097 while ( $input ne "d" ) {
3098
3099 # list template sets
3100 #
3101 if ( $input =~ /^\s*l\s*/i ) {
3102 $count = 0;
3103 while ( $count <= $#templateset_name ) {
3104 if ( $templateset_id[$count] eq $templateset_default ) {
3105 print " d";
3106 } else {
3107 print " ";
3108 }
3109 if ( $templateset_id[$count] eq $templateset_fallback ) {
3110 print "f ";
3111 } else {
3112 print " ";
3113 }
3114 if ( $count < 10 ) {
3115 print " ";
3116 }
3117 $name = $templateset_name[$count];
3118 $num_spaces = 35 - length($name);
3119 for ( $i = 0 ; $i < $num_spaces ; $i++ ) {
3120 $name = $name . " ";
3121 }
3122
3123 print " $count. $name";
3124 print "($templateset_id[$count])\n";
3125
3126 $count++;
3127 }
3128 print "\n d = default template set\n"
3129 . " f = fallback template set\n\n";
3130
3131 # mark default template set
3132 #
3133 } elsif ( $input =~ /^\s*m\s*[0-9]+/i ) {
3134 $old_def = $templateset_default;
3135 $input =~ s/^\s*m\s*//;
3136 $templateset_default = $templateset_id[$input];
3137 if ( $templateset_default =~ /^\s*$/ ) {
3138 print "Cannot set default template set to $input. That template set does not exist.\n";
3139 $templateset_default = $old_def;
3140 }
3141
3142 # set fallback template set
3143 #
3144 } elsif ( $input =~ /^\s*f\s*[0-9]+/i ) {
3145 $old_def = $templateset_fallback;
3146 $input =~ s/^\s*f\s*//;
3147 $templateset_fallback = $templateset_id[$input];
3148 if ( $templateset_fallback =~ /^\s*$/ ) {
3149 print "Cannot set fallback template set to $input. That template set does not exist.\n";
3150 $templateset_fallback = $old_def;
3151 }
3152
3153 # add template set
3154 #
3155 } elsif ( $input =~ /^\s*\+/ ) {
3156 print "\nWhat is the name of this template (as shown to your users): ";
3157 $name = <STDIN>;
3158 $name =~ s/[\r\n]//g;
3159 $templateset_name[ $#templateset_name + 1 ] = $name;
3160 print "\n\nThe directory name should not contain any path information\n"
3161 . "or slashes, and should be the name of the directory that the\n"
3162 . "template set is found in within the SquirrelMail templates\n"
3163 . "directory.\n\n";
3164 print "What directory is this stored in (ex: default_advanced): ";
3165 $name = <STDIN>;
3166 $name =~ s/[\r\n]//g;
3167 $templateset_id[ $#templateset_id + 1 ] = $name;
3168
3169 # detect template sets
3170 #
3171 } elsif ( $input =~ /^\s*t\s*/i ) {
3172 print "\nStarting detection...\n\n";
3173 opendir( DIR, "../templates" );
3174 @files = readdir(DIR);
3175 $cnt = 0;
3176 while ( $cnt <= $#files ) {
3177 if ( -d "../templates/" . $files[$cnt] && $files[$cnt] !~ /^\./ && $files[$cnt] ne "CVS" ) {
3178 $filename = $files[$cnt];
3179 $found = 0;
3180 for ( $x = 0 ; $x <= $#templateset_id ; $x++ ) {
3181 if ( $templateset_id[$x] eq $filename ) {
3182 $found = 1;
3183 last;
3184 }
3185 }
3186 if ( $found != 1) {
3187 print "** Found template set: $filename\n";
3188 print " What is it's name (as shown to your users)? ";
3189 $nm = <STDIN>;
3190 $nm =~ s/[\n\r]//g;
3191 $templateset_id[ $#templateset_id + 1 ] = $filename;
3192 $templateset_name[ $#templateset_name + 1 ] = $nm;
3193 }
3194 }
3195 $cnt++;
3196 }
3197 print "\n";
3198 for ( $cnt= 0 ; $cnt <= $#templateset_id ; ) {
3199 $filename = $templateset_id[$cnt];
3200 if ( !(-d change_to_rel_path('SM_PATH . \'templates/' . $filename)) ) {
3201 print " Removing \"$filename\" (template set directory not found)\n";
3202 if ( $templateset_default eq $filename ) { $templateset_default = 'default'; }
3203 if ( $templateset_fallback eq $filename ) { $templateset_fallback = 'default'; }
3204 $offset = 0;
3205 @new_templateset_name = ();
3206 @new_templateset_id = ();
3207 for ( $x = 0 ; $x < $#templateset_id ; $x++ ) {
3208 if ( $templateset_id[$x] eq $filename ) {
3209 $offset = 1;
3210 }
3211 if ( $offset == 1 ) {
3212 $new_templateset_name[$x] = $templateset_name[ $x + 1 ];
3213 $new_templateset_id[$x] = $templateset_id[ $x + 1 ];
3214 } else {
3215 $new_templateset_name[$x] = $templateset_name[$x];
3216 $new_templateset_id[$x] = $templateset_id[$x];
3217 }
3218 }
3219 @templateset_name = @new_templateset_name;
3220 @templateset_id = @new_templateset_id;
3221 } else { $cnt++; }
3222 }
3223 print "\nDetection complete!\n\n";
3224
3225 closedir DIR;
3226
3227 # remove template set
3228 #
3229 # undocumented functionality of removing last template set isn't that great
3230 #} elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
3231 } elsif ( $input =~ /^\s*-\s*[0-9]+/ ) {
3232 if ( $input =~ /[0-9]+\s*$/ ) {
3233 $rem_num = $input;
3234 $rem_num =~ s/^\s*-\s*//g;
3235 $rem_num =~ s/\s*$//;
3236 } else {
3237 $rem_num = $#templateset_name;
3238 }
3239 if ( $templateset_id[$rem_num] eq $templateset_default ) {
3240 print "You cannot remove the default template set!\n";
3241 } elsif ( $templateset_id[$rem_num] eq $templateset_fallback ) {
3242 print "You cannot remove the fallback template set!\n";
3243 } else {
3244 $count = 0;
3245 @new_templateset_name = ();
3246 @new_templateset_id = ();
3247 while ( $count <= $#templateset_name ) {
3248 if ( $count != $rem_num ) {
3249 @new_templateset_name = ( @new_templateset_name, $templateset_name[$count] );
3250 @new_templateset_id = ( @new_templateset_id, $templateset_id[$count] );
3251 }
3252 $count++;
3253 }
3254 @templateset_name = @new_templateset_name;
3255 @templateset_id = @new_templateset_id;
3256 }
3257
3258 # help
3259 #
3260 } elsif ( $input =~ /^\s*\?\s*/ ) {
3261 print $menu_text;
3262
3263 # command not understood
3264 #
3265 } else {
3266 print "Command not understood\n";
3267 }
3268
3269 print "[template set] command (?=help) > ";
3270 $input = <STDIN>;
3271 $input =~ s/[\r\n]//g;
3272 }
3273 return $templateset_default;
3274 }
3275
3276
3277 # sets default font size option
3278 sub command_default_fontsize {
3279 print "Enter default font size [$WHT$$default_fontsize$NRM]: $WHT";
3280 $new_size = <STDIN>;
3281 if ( $new_size eq "\n" ) {
3282 $new_size = $size;
3283 } else {
3284 $new_size =~ s/[\r\n]//g;
3285 }
3286 return $new_size;
3287 }
3288
3289 # controls available fontsets
3290 sub command_fontsets {
3291 # Greeting
3292 print "You can control fontsets available to end users here.\n";
3293 # set initial $input value
3294 $input = 'l';
3295 while ( $input ne "x" ) {
3296 if ( $input =~ /^\s*a\s*/i ) {
3297 # add new fontset
3298 print "\nFontset name: ";
3299 $name = <STDIN>;
3300 if (! $fontsets{trim($name)}) {
3301 print "Fontset string: ";
3302 $value = <STDIN>;
3303 $fontsets{trim($name)} = trim($value);
3304 } else {
3305 print "\nERROR: Such fontset already exists.\n";
3306 }
3307 } elsif ( $input =~ /^\s*e\s*/i ) {
3308 # edit existing fontset
3309 print "\nFontset name: ";
3310 $name = <STDIN>;
3311 if (! $fontsets{trim($name)}) {
3312 print "\nERROR: No such fontset.\n";
3313 } else {
3314 print "Fontset string [$fontsets{trim($name)}]: ";
3315 $value = <STDIN>;
3316 $fontsets{trim($name)} = trim($value);
3317 }
3318 } elsif ( $input =~ /^\s*d\s*/ ) {
3319 # delete existing fontset
3320 print "\nFontset name: ";
3321 $name = <STDIN>;
3322 if (! $fontsets{trim($name)}) {
3323 print "\nERROR: No such fontset.\n";
3324 } else {
3325 delete $fontsets{trim($name)};
3326 }
3327 } elsif ( $input =~ /^\s*l\s*/ ) {
3328 # list fontsets
3329 print "\nConfigured fontsets:\n";
3330 while (($fontset_name, $fontset_string) = each(%fontsets)) {
3331 print " $fontset_name = $fontset_string\n";
3332 }
3333 print "Default fontset: $default_fontset\n";
3334 } elsif ( $input =~ /^\s*m\s*/ ) {
3335 # set default fontset
3336 print "\nSet default fontset [$default_fontset]: ";
3337 $name = <STDIN>;
3338 if (trim($name) ne '' and ! $fontsets{trim($name)}) {
3339 print "\nERROR: No such fontset.\n";
3340 } else {
3341 $default_fontset = trim($name);
3342 }
3343 } else {
3344 # print available commands on any other input
3345 print "\nAvailable commands:\n";
3346 print " a - Adds new fontset.\n";
3347 print " d - Deletes existing fontset.\n";
3348 print " e - Edits existing fontset.\n";
3349 print " h or ? - Shows this help screen.\n";
3350 print " l - Lists available fontsets.\n";
3351 print " m - Sets default fontset.\n";
3352 print " x - Exits fontset editor mode.\n";
3353 }
3354 print "\nCommand [fontsets] (a,d,e,h,?=help,l,m,x)> ";
3355 $input = <STDIN>;
3356 $input =~ s/[\r\n]//g;
3357 }
3358 }
3359
3360 sub command61 {
3361 print "You can now define different LDAP servers.\n";
3362 print "Please ensure proper permissions for config.php when including\n";
3363 print "sensitive passwords.\n\n";
3364 print "[ldap] command (?=help) > ";
3365 $input = <STDIN>;
3366 $input =~ s/[\r\n]//g;
3367 while ( $input ne "d" ) {
3368 if ( $input =~ /^\s*l\s*/i ) {
3369 $count = 0;
3370 while ( $count <= $#ldap_host ) {
3371 print "$count. $ldap_host[$count]\n";
3372 print " base: $ldap_base[$count]\n";
3373 if ( $ldap_charset[$count] ) {
3374 print " charset: $ldap_charset[$count]\n";
3375 }
3376 if ( $ldap_port[$count] ) {
3377 print " port: $ldap_port[$count]\n";
3378 }
3379 if ( $ldap_name[$count] ) {
3380 print " name: $ldap_name[$count]\n";
3381 }
3382 if ( $ldap_maxrows[$count] ) {
3383 print " maxrows: $ldap_maxrows[$count]\n";
3384 }
3385 if ( $ldap_filter[$count] ) {
3386 print " filter: $ldap_filter[$count]\n";
3387 }
3388 if ( $ldap_binddn[$count] ) {
3389 print " binddn: $ldap_binddn[$count]\n";
3390 if ( $ldap_bindpw[$count] ) {
3391 print " bindpw: $ldap_bindpw[$count]\n";
3392 }
3393 }
3394 if ( $ldap_protocol[$count] ) {
3395 print " protocol: $ldap_protocol[$count]\n";
3396 }
3397 if ( $ldap_limit_scope[$count] ) {
3398 print " limit_scope: $ldap_limit_scope[$count]\n";
3399 }
3400 if ( $ldap_listing[$count] ) {
3401 print " listing: $ldap_listing[$count]\n";
3402 }
3403 if ( $ldap_writeable[$count] ) {
3404 print " writeable: $ldap_writeable[$count]\n";
3405 }
3406 if ( $ldap_search_tree[$count] ) {
3407 print " search_tree: $ldap_search_tree[$count]\n";
3408 }
3409 if ( $ldap_starttls[$count] ) {
3410 print " starttls: $ldap_starttls[$count]\n";
3411 }
3412
3413 print "\n";
3414 $count++;
3415 }
3416 } elsif ( $input =~ /^\s*\+/ ) {
3417 $sub = $#ldap_host + 1;
3418
3419 print "First, we need to have the hostname or the IP address where\n";
3420 print "this LDAP server resides. Example: ldap.bigfoot.com\n";
3421 print "\n";
3422 print "You can use any URI compatible with your LDAP library. Please\n";
3423 print "note that StartTLS option is not compatible with ldaps and\n";
3424 print "ldapi URIs.\n";
3425 print "hostname: ";
3426 $name = <STDIN>;
3427 $name =~ s/[\r\n]//g;
3428 $ldap_host[$sub] = $name;
3429
3430 print "\n";
3431
3432 print "Next, we need the server root (base dn). For this, an empty\n";
3433 print "string is allowed.\n";
3434 print "Example: ou=member_directory,o=netcenter.com\n";
3435 print "base: ";
3436 $name = <STDIN>;
3437 $name =~ s/[\r\n]//g;
3438 $ldap_base[$sub] = $name;
3439
3440 print "\n";
3441
3442 print "This is the TCP/IP port number for the LDAP server. Default\n";
3443 print "port is 389. This is optional. Press ENTER for default.\n";
3444 print "port: ";
3445 $name = <STDIN>;
3446 $name =~ s/[\r\n]//g;
3447 $ldap_port[$sub] = $name;
3448
3449 print "\n";
3450
3451 print "This is the charset for the server. Default is utf-8. This\n";
3452 print "is also optional. Press ENTER for default.\n";
3453 print "charset: ";
3454 $name = <STDIN>;
3455 $name =~ s/[\r\n]//g;
3456 $ldap_charset[$sub] = $name;
3457
3458 print "\n";
3459
3460 print "This is the name for the server, used to tag the results of\n";
3461 print "the search. Default it \"LDAP: hostname\". Press ENTER for default\n";
3462 print "name: ";
3463 $name = <STDIN>;
3464 $name =~ s/[\r\n]//g;
3465 $ldap_name[$sub] = $name;
3466
3467 print "\n";
3468
3469 print "You can specify the maximum number of rows in the search result.\n";
3470 print "Default value is equal to 250 rows. Press ENTER for default.\n";
3471 print "maxrows: ";
3472 $name = <STDIN>;
3473 $name =~ s/[\r\n]//g;
3474 $ldap_maxrows[$sub] = $name;
3475
3476
3477 print "\n";
3478
3479 print "If your LDAP server does not like anonymous logins, you can specify bind DN.\n";
3480 print "Default is none, anonymous bind. Press ENTER for default.\n";
3481 print "binddn: ";
3482 $name = <STDIN>;
3483 $name =~ s/[\r\n]//g;
3484 $ldap_binddn[$sub] = $name;
3485
3486 print "\n";
3487
3488 if ( $ldap_binddn[$sub] ne '' ) {
3489
3490 print "Now, please specify password for that DN.\n";
3491 print "bindpw: ";
3492 $name = <STDIN>;
3493 $name =~ s/[\r\n]//g;
3494 $ldap_bindpw[$sub] = $name;
3495
3496 print "\n";
3497 }
3498
3499 print "You can specify bind protocol version here.\n";
3500 print "Default protocol version depends on your php ldap settings.\n";
3501 print "Press ENTER for default.\n";
3502 print "protocol: ";
3503 $name = <STDIN>;
3504 $name =~ s/[\r\n]//g;
3505 $ldap_protocol[$sub] = $name;
3506
3507 print "\n";
3508
3509 print "This configuration section allows to set some rarely used\n";
3510 print "options and options specific to some LDAP implementations.\n";
3511 print "\n";
3512 print "Do you want to set advanced LDAP directory settings? (y/N):";
3513 $ldap_advanced_settings = <STDIN>;
3514 if ( $ldap_advanced_settings =~ /^y\n/i ) {
3515 $ldap_advanced_settings = 'true';
3516 } else {
3517 $ldap_advanced_settings = 'false';
3518 }
3519
3520 if ($ldap_advanced_settings eq 'true') {
3521 print "\n";
3522
3523 print "You can control LDAP directory listing here. This option can\n";
3524 print "be useful if you run small LDAP server and want to provide listing\n";
3525 print "of all addresses stored in LDAP to users of webmail interface.\n";
3526 print "Number of displayed entries is limited by maxrows setting.\n";
3527 print "\n";
3528 print "Don't enable this option for public LDAP directories.\n";
3529 print "\n";
3530 print "Allow listing of LDAP directory? (y/N):";
3531 $name = <STDIN>;
3532 if ( $name =~ /^y\n/i ) {
3533 $name = 'true';
3534 } else {
3535 $name = 'false';
3536 }
3537 $ldap_listing[$sub] = $name;
3538
3539 print "\n";
3540
3541 print "You can control write access to LDAP address book here. This option can\n";
3542 print "be useful if you run small LDAP server and want to provide writable\n";
3543 print "shared address book stored in LDAP to users of webmail interface.\n";
3544 print "\n";
3545 print "Don't enable this option for public LDAP directories.\n";
3546 print "\n";
3547 print "Allow writing to LDAP directory? (y/N):";
3548 $name = <STDIN>;
3549 if ( $name =~ /^y\n/i ) {
3550 $name = 'true';
3551 } else {
3552 $name = 'false';
3553 }
3554 $ldap_writeable[$sub] = $name;
3555
3556 print "\n";
3557
3558 print "You can specify an additional search filter.\n";
3559 print "This could be something like \"(objectclass=posixAccount)\".\n";
3560 print "No filtering is performed by default. Press ENTER for default.\n";
3561 print "filter: ";
3562 $name = <STDIN>;
3563 $name =~ s/[\r|\n]//g;
3564 $ldap_filter[$sub] = $name;
3565
3566 print "\n";
3567
3568 print "You can control search scope here.\n";
3569 print "This option is specific to Microsoft ADS implementation.\n";
3570 print "It requires use of v3 or newer LDAP protocol.\n";
3571 print "Don't enable it, if you use other LDAP server.\n";
3572 print "\n";
3573 print "Limit ldap scope? (y/N):";
3574 $name = <STDIN>;
3575 if ( $name =~ /^y\n/i ) {
3576 $name = 'true';
3577 } else {
3578 $name = 'false';
3579 }
3580 $ldap_limit_scope[$sub] = $name;
3581
3582 print "\n";
3583
3584 print "You can control ldap search type here.\n";
3585 print "Addresses can be searched in entire LDAP subtree (default)\n";
3586 print "or only first level entries are returned.\n";
3587 print "\n";
3588 print "Search entire LDAP subtree? (Y/n):";
3589 $name = <STDIN>;
3590 if ( $name =~ /^n\n/i ) {
3591 $name = 'false';
3592 } else {
3593 $name = 'true';
3594 }
3595 $ldap_search_tree[$sub] = $name;
3596
3597 print "\n";
3598
3599 print "You can control use of StartTLS on LDAP connection here.\n";
3600 print "This option requires use of v3 or newer LDAP protocol and php 4.2+.\n";
3601 print "\n";
3602 print "Use StartTLS? (y/N):";
3603 $name = <STDIN>;
3604 if ( $name =~ /^y\n/i ) {
3605 $name = 'true';
3606 } else {
3607 $name = 'false';
3608 }
3609 $ldap_starttls[$sub] = $name;
3610 }
3611 print "\n";
3612
3613 } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
3614 if ( $input =~ /[0-9]+\s*$/ ) {
3615 $rem_num = $input;
3616 $rem_num =~ s/^\s*-\s*//g;
3617 $rem_num =~ s/\s*$//;
3618 } else {
3619 $rem_num = $#ldap_host;
3620 }
3621 $count = 0;
3622 @new_ldap_host = ();
3623 @new_ldap_base = ();
3624 @new_ldap_port = ();
3625 @new_ldap_name = ();
3626 @new_ldap_charset = ();
3627 @new_ldap_maxrows = ();
3628 @new_ldap_filter = ();
3629 @new_ldap_bindpw = ();
3630 @new_ldap_binddn = ();
3631 @new_ldap_protocol = ();
3632 @new_ldap_limit_scope = ();
3633 @new_ldap_listing = ();
3634 @new_ldap_writeable = ();
3635 @new_ldap_search_tree = ();
3636 @new_ldap_starttls = ();
3637
3638 while ( $count <= $#ldap_host ) {
3639 if ( $count != $rem_num ) {
3640 @new_ldap_host = ( @new_ldap_host, $ldap_host[$count] );
3641 @new_ldap_base = ( @new_ldap_base, $ldap_base[$count] );
3642 @new_ldap_port = ( @new_ldap_port, $ldap_port[$count] );
3643 @new_ldap_name = ( @new_ldap_name, $ldap_name[$count] );
3644 @new_ldap_charset = ( @new_ldap_charset, $ldap_charset[$count] );
3645 @new_ldap_maxrows = ( @new_ldap_maxrows, $ldap_maxrows[$count] );
3646 @new_ldap_filter = ( @new_ldap_filter, $ldap_filter[$count] );
3647 @new_ldap_binddn = ( @new_ldap_binddn, $ldap_binddn[$count] );
3648 @new_ldap_bindpw = ( @new_ldap_bindpw, $ldap_bindpw[$count] );
3649 @new_ldap_protocol = ( @new_ldap_protocol, $ldap_protocol[$count] );
3650 @new_ldap_limit_scope = ( @new_ldap_limit_scope, $ldap_limit_scope[$count] );
3651 @new_ldap_listing = ( @new_ldap_listing, $ldap_listing[$count] );
3652 @new_ldap_writeable = ( @new_ldap_writeable, $ldap_writeable[$count] );
3653 @new_ldap_search_tree = ( @new_ldap_search_tree, $ldap_search_tree[$count] );
3654 @new_ldap_starttls = ( @new_ldap_starttls, $ldap_starttls[$count] );
3655 }
3656 $count++;
3657 }
3658 @ldap_host = @new_ldap_host;
3659 @ldap_base = @new_ldap_base;
3660 @ldap_port = @new_ldap_port;
3661 @ldap_name = @new_ldap_name;
3662 @ldap_charset = @new_ldap_charset;
3663 @ldap_maxrows = @new_ldap_maxrows;
3664 @ldap_filter = @new_ldap_filter;
3665 @ldap_binddn = @new_ldap_binddn;
3666 @ldap_bindpw = @new_ldap_bindpw;
3667 @ldap_protocol = @new_ldap_protocol;
3668 @ldap_limit_scope = @new_ldap_limit_scope;
3669 @ldap_listing = @new_ldap_listing;
3670 @ldap_writeable = @new_ldap_writeable;
3671 @ldap_search_tree = @new_ldap_search_tree;
3672 @ldap_starttls = @new_ldap_starttls;
3673
3674 } elsif ( $input =~ /^\s*\?\s*/ ) {
3675 print ".-------------------------.\n";
3676 print "| + (add host) |\n";
3677 print "| - N (remove host) |\n";
3678 print "| l (list hosts) |\n";
3679 print "| d (done) |\n";
3680 print "`-------------------------'\n";
3681 }
3682 print "[ldap] command (?=help) > ";
3683 $input = <STDIN>;
3684 $input =~ s/[\r\n]//g;
3685 }
3686 }
3687
3688 sub command62 {
3689 print "Some of our developers have come up with very good javascript interface\n";
3690 print "for searching through address books, however, our original goals said\n";
3691 print "that we would be 100% HTML. In order to make it possible to use their\n";
3692 print "interface, and yet stick with our goals, we have also written a plain\n";
3693 print "HTML version of the search. Here, you can choose which version to use.\n";
3694 print "\n";
3695 print "This is just the default value. It is also a user option that each\n";
3696 print "user can configure individually\n";
3697 print "\n";
3698
3699 if ( lc($default_use_javascript_addr_book) eq 'true' ) {
3700 $default_value = "y";
3701 } else {
3702 $default_use_javascript_addr_book = 'false';
3703 $default_value = "n";
3704 }
3705 print "Use javascript version by default (y/n) [$WHT$default_value$NRM]: $WHT";
3706 $new_show = <STDIN>;
3707 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
3708 $default_use_javascript_addr_book = 'true';
3709 } else {
3710 $default_use_javascript_addr_book = 'false';
3711 }
3712 return $default_use_javascript_addr_book;
3713 }
3714
3715 # global filebased address book
3716 sub command63 {
3717 print "If you want to use global file address book, then you\n";
3718 print "must set this option to a valid value. If option does\n";
3719 print "not have path elements, system assumes that file is\n";
3720 print "stored in data directory. If relative path is set, it is\n";
3721 print "relative to main SquirrelMail directory. If value is empty,\n";
3722 print "address book is not enabled.\n";
3723 print "\n";
3724
3725 print "[$WHT$abook_global_file$NRM]: $WHT";
3726 $new_abook_global_file = <STDIN>;
3727 if ( $new_abook_global_file eq "\n" ) {
3728 $new_abook_global_file = $abook_global_file;
3729 } else {
3730 $new_abook_global_file =~ s/[\r\n]//g;
3731 }
3732 return $new_abook_global_file;
3733 }
3734
3735 # writing into global filebased abook control
3736 sub command64 {
3737 print "This setting controls writing into global file address\n";
3738 print "book options. Address book file must be writeable by\n";
3739 print "webserver's user, if you want to enable this option.\n";
3740 print "\n";
3741
3742 if ( lc($abook_global_file_writeable) eq 'true' ) {
3743 $default_value = "y";
3744 } else {
3745 $abook_global_file_writeable = 'false';
3746 $default_value = "n";
3747 }
3748 print "Allow writing into global file address book (y/n) [$WHT$default_value$NRM]: $WHT";
3749 $new_show = <STDIN>;
3750 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
3751 $abook_global_file_writeable = 'true';
3752 } else {
3753 $abook_global_file_writeable = 'false';
3754 }
3755 return $abook_global_file_writeable;
3756 }
3757
3758 # listing of global filebased abook control
3759 sub command65 {
3760 print "This setting controls listing of global file address\n";
3761 print "book in addresses page.\n";
3762 print "\n";
3763
3764 if ( lc($abook_global_file_listing) eq 'true' ) {
3765 $default_value = "y";
3766 } else {
3767 $abook_global_file_listing = 'false';
3768 $default_value = "n";
3769 }
3770 print "Allow listing of global file address book (y/n) [$WHT$default_value$NRM]: $WHT";
3771 $new_show = <STDIN>;
3772 if ( ( $new_show =~ /^y\n/i ) || ( ( $new_show =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
3773 $abook_global_file_listing = 'true';
3774 } else {
3775 $abook_global_file_listing = 'false';
3776 }
3777 return $abook_global_file_listing;
3778 }
3779
3780 # controls $abook_file_line_length setting
3781 sub command_abook_file_line_length {
3782 print "This setting controls space allocated to file based address book records.\n";
3783 print "End users will be unable to save address book entry, if total entry size \n";
3784 print "(quoted address book fields + 4 delimiters + linefeed) exceeds allowed \n";
3785 print "address book length size.\n";
3786 print "\n";
3787 print "Same setting is applied to personal and global file based address books.\n";
3788 print "\n";
3789 print "It is strongly recommended to keep default setting value. Change it only\n";
3790 print "if you really want to store address book entries that are bigger than two\n";
3791 print "kilobytes (2048).\n";
3792 print "\n";
3793
3794 print "Enter allowed address book line length [$abook_file_line_length]: ";
3795 my $tmp = <STDIN>;
3796 $tmp = trim($tmp);
3797 # value is not modified, if user hits Enter or enters space
3798 if ($tmp ne '') {
3799 # make sure that input is numeric
3800 if ($tmp =~ /^\d+$/) {
3801 $abook_file_line_length = $tmp;
3802 } else {
3803 print "If you want to change this setting, you must enter number.\n";
3804 print "If you want to keep original setting - enter space.\n\n";
3805 print "Press Enter to continue...";
3806 $tmp = <STDIN>;
3807 }
3808 }
3809 }
3810
3811 sub command91 {
3812 print "If you want to store your users address book details in a database then\n";
3813 print "you need to set this DSN to a valid value. The format for this is:\n";
3814 print "mysql://user:pass\@hostname/dbname\n";
3815 print "Where mysql can be one of the databases PHP supports, the most common\n";
3816 print "of these are mysql, msql and pgsql.\n";
3817 print "Please ensure proper permissions for config.php when including\n";
3818 print "sensitive passwords.\n\n";
3819 print "If the DSN is left empty (hit space and then return) the database\n";
3820 print "related code for address books will not be used.\n";
3821 print "\n";
3822
3823 if ( $addrbook_dsn eq "" ) {
3824 $default_value = "Disabled";
3825 } else {
3826 $default_value = $addrbook_dsn;
3827 }
3828 print "[$WHT$addrbook_dsn$NRM]: $WHT";
3829 $new_dsn = <STDIN>;
3830 if ( $new_dsn eq "\n" ) {
3831 $new_dsn = "";
3832 } else {
3833 $new_dsn =~ s/[\r\n]//g;
3834 $new_dsn =~ s/^\s+$//g;
3835 }
3836 return $new_dsn;
3837 }
3838
3839 sub command92 {
3840 print "This is the name of the table you want to store the address book\n";
3841 print "data in, it defaults to 'address'\n";
3842 print "\n";
3843 print "[$WHT$addrbook_table$NRM]: $WHT";
3844 $new_table = <STDIN>;
3845 if ( $new_table eq "\n" ) {
3846 $new_table = $addrbook_table;
3847 } else {
3848 $new_table =~ s/[\r\n]//g;
3849 }
3850 return $new_table;
3851 }
3852
3853 sub command93 {
3854 print "If you want to store your users preferences in a database then\n";
3855 print "you need to set this DSN to a valid value. The format for this is:\n";
3856 print "mysql://user:pass\@hostname/dbname\n";
3857 print "Where mysql can be one of the databases PHP supports, the most common\n";
3858 print "of these are mysql, msql and pgsql.\n";
3859 print "Please ensure proper permissions for config.php when including\n";
3860 print "sensitive passwords.\n\n";
3861 print "If the DSN is left empty (hit space and then return) the database\n";
3862 print "related code for address books will not be used.\n";
3863 print "\n";
3864
3865 if ( $prefs_dsn eq "" ) {
3866 $default_value = "Disabled";
3867 } else {
3868 $default_value = $prefs_dsn;
3869 }
3870 print "[$WHT$prefs_dsn$NRM]: $WHT";
3871 $new_dsn = <STDIN>;
3872 if ( $new_dsn eq "\n" ) {
3873 $new_dsn = "";
3874 } else {
3875 $new_dsn =~ s/[\r\n]//g;
3876 $new_dsn =~ s/^\s+$//g;
3877 }
3878 return $new_dsn;
3879 }
3880
3881 sub command94 {
3882 print "This is the name of the table you want to store the preferences\n";
3883 print "data in, it defaults to 'userprefs'\n";
3884 print "\n";
3885 print "[$WHT$prefs_table$NRM]: $WHT";
3886 $new_table = <STDIN>;
3887 if ( $new_table eq "\n" ) {
3888 $new_table = $prefs_table;
3889 } else {
3890 $new_table =~ s/[\r\n]//g;
3891 }
3892 return $new_table;
3893 }
3894
3895 sub command95 {
3896 print "This is the name of the field in which you want to store the\n";
3897 print "username of the person the prefs are for. It default to 'user'\n";
3898 print "which clashes with a reserved keyword in PostgreSQL so this\n";
3899 print "will need to be changed for that database at least\n";
3900 print "\n";
3901 print "[$WHT$prefs_user_field$NRM]: $WHT";
3902 $new_field = <STDIN>;
3903 if ( $new_field eq "\n" ) {
3904 $new_field = $prefs_user_field;
3905 } else {
3906 $new_field =~ s/[\r\n]//g;
3907 }
3908 $prefs_user_size = db_pref_size($prefs_user_size);
3909 return $new_field;
3910 }
3911
3912 sub command96 {
3913 print "This is the name of the field in which you want to store the\n";
3914 print "preferences keyword. It defaults to 'prefkey'\n";
3915 print "\n";
3916 print "[$WHT$prefs_key_field$NRM]: $WHT";
3917 $new_field = <STDIN>;
3918 if ( $new_field eq "\n" ) {
3919 $new_field = $prefs_key_field;
3920 } else {
3921 $new_field =~ s/[\r\n]//g;
3922 }
3923 $prefs_key_size = db_pref_size($prefs_key_size);
3924 return $new_field;
3925 }
3926
3927 sub command97 {
3928 print "This is the name of the field in which you want to store the\n";
3929 print "preferences value. It defaults to 'prefval'\n";
3930 print "\n";
3931 print "[$WHT$prefs_val_field$NRM]: $WHT";
3932 $new_field = <STDIN>;
3933 if ( $new_field eq "\n" ) {
3934 $new_field = $prefs_val_field;
3935 } else {
3936 $new_field =~ s/[\r\n]//g;
3937 }
3938 $prefs_val_size = db_pref_size($prefs_val_size);
3939 return $new_field;
3940 }
3941
3942 # routine is used to set database field limits
3943 # it needs one argument
3944 sub db_pref_size() {
3945 my ($size) = $_[0];
3946 print "\nDatabase fields have size limits.\n";
3947 print "\n";
3948 print "What limit is set for this field? [$WHT$size$NRM]: $WHT";
3949 $new_size = <STDIN>;
3950 if ( $new_size eq "\n" ) {
3951 $new_size = $size;
3952 } else {
3953 $new_size =~ s/[\r\n]//g;
3954 }
3955 return $new_size;
3956 }
3957
3958 sub command98 {
3959 print "If you want to store your global address book in a database then\n";
3960 print "you need to set this DSN to a valid value. The format for this is:\n";
3961 print "mysql://user:pass\@hostname/dbname\n";
3962 print "Where mysql can be one of the databases PHP supports, the most common\n";
3963 print "of these are mysql, msql and pgsql.\n";
3964 print "Please ensure proper permissions for config.php when including\n";
3965 print "sensitive passwords.\n\n";
3966 print "If the DSN is left empty (hit space and then return) the database\n";
3967 print "related code for global SQL address book will not be used.\n";
3968 print "\n";
3969
3970 if ( $addrbook_global_dsn eq "" ) {
3971 $default_value = "Disabled";
3972 } else {
3973 $default_value = $addrbook_global_dsn;
3974 }
3975 print "[$WHT$addrbook_global_dsn$NRM]: $WHT";
3976 $new_dsn = <STDIN>;
3977 if ( $new_dsn eq "\n" ) {
3978 $new_dsn = "";
3979 } else {
3980 $new_dsn =~ s/[\r\n]//g;
3981 $new_dsn =~ s/^\s+$//g;
3982 }
3983 return $new_dsn;
3984 }
3985
3986 sub command99 {
3987 print "This is the name of the table you want to store the global address book\n";
3988 print "data in. Default table name is 'global_abook'. Address book uses same\n";
3989 print "database format as personal address book.\n";
3990 print "\n";
3991 print "[$WHT$addrbook_global_table$NRM]: $WHT";
3992 $new_table = <STDIN>;
3993 if ( $new_table eq "\n" ) {
3994 $new_table = $addrbook_global_table;
3995 } else {
3996 $new_table =~ s/[\r\n]//g;
3997 }
3998 return $new_table;
3999 }
4000
4001 sub command910 {
4002 print "This option controls users\' ability to add or modify records stored \n";
4003 print "in global address book\n";
4004
4005 if ( lc($addrbook_global_writeable) eq 'true' ) {
4006 $default_value = "y";
4007 } else {
4008 $default_value = "n";
4009 }
4010 print "Allow writing into global address book? (y/n) [$WHT$default_value$NRM]: $WHT";
4011 $addrbook_global_writeable = <STDIN>;
4012 if ( ( $addrbook_global_writeable =~ /^y\n/i ) || ( ( $addrbook_global_writeable =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4013 $addrbook_global_writeable = 'true';
4014 } else {
4015 $addrbook_global_writeable = 'false';
4016 }
4017 return $addrbook_global_writeable;
4018 }
4019
4020 sub command911 {
4021 print "Enable this option if you want to see listing of addresses stored \n";
4022 print "in global address book\n";
4023
4024 if ( lc($addrbook_global_listing) eq 'true' ) {
4025 $default_value = "y";
4026 } else {
4027 $default_value = "n";
4028 }
4029 print "Allow listing of global address book? (y/n) [$WHT$default_value$NRM]: $WHT";
4030 $addrbook_global_listing = <STDIN>;
4031 if ( ( $addrbook_global_listing =~ /^y\n/i ) || ( ( $addrbook_global_listing =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4032 $addrbook_global_listing = 'true';
4033 } else {
4034 $addrbook_global_listing = 'false';
4035 }
4036 return $addrbook_global_listing;
4037 }
4038
4039
4040 # Default language
4041 sub commandA1 {
4042 print "SquirrelMail attempts to set the language in many ways. If it\n";
4043 print "can not figure it out in another way, it will default to this\n";
4044 print "language. Please use the code for the desired language.\n";
4045 print "\n";
4046 print "[$WHT$squirrelmail_default_language$NRM]: $WHT";
4047 $new_squirrelmail_default_language = <STDIN>;
4048 if ( $new_squirrelmail_default_language eq "\n" ) {
4049 $new_squirrelmail_default_language = $squirrelmail_default_language;
4050 } else {
4051 $new_squirrelmail_default_language =~ s/[\r\n]//g;
4052 $new_squirrelmail_default_language =~ s/^\s+$//g;
4053 }
4054 return $new_squirrelmail_default_language;
4055 }
4056 # Default Charset
4057 sub commandA2 {
4058 print "This option controls what character set is used when sending\n";
4059 print "mail and when sending HTML to the browser. Option works only\n";
4060 print "with US English (en_US) translation. Other translations use\n";
4061 print "charsets that are set in translation settings.\n";
4062 print "\n";
4063
4064 print "[$WHT$default_charset$NRM]: $WHT";
4065 $new_default_charset = <STDIN>;
4066 if ( $new_default_charset eq "\n" ) {
4067 $new_default_charset = $default_charset;
4068 } else {
4069 $new_default_charset =~ s/[\r\n]//g;
4070 }
4071 return $new_default_charset;
4072 }
4073 # Alternative language names
4074 sub commandA3 {
4075 print "Enable this option if you want to see localized language names in\n";
4076 print "language selection box. Note, that this option can trigger\n";
4077 print "installation of foreign language support modules in some browsers.\n";
4078 print "\n";
4079
4080 if ( lc($show_alternative_names) eq 'true' ) {
4081 $default_value = "y";
4082 } else {
4083 $default_value = "n";
4084 }
4085 print "Show alternative language names? (y/n) [$WHT$default_value$NRM]: $WHT";
4086 $show_alternative_names = <STDIN>;
4087 if ( ( $show_alternative_names =~ /^y\n/i ) || ( ( $show_alternative_names =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4088 $show_alternative_names = 'true';
4089 } else {
4090 $show_alternative_names = 'false';
4091 }
4092 return $show_alternative_names;
4093 }
4094
4095 # Aggressive decoding
4096 sub commandA4 {
4097 print "Enable this option if you want to use CPU and memory intensive decoding\n";
4098 print "functions. This option allows reading multibyte charset, that are used\n";
4099 print "in Eastern Asia. SquirrelMail will try to use recode functions here,\n";
4100 print "even when you have disabled use of recode in Tweaks section.\n";
4101 print "\n";
4102
4103 if ( lc($aggressive_decoding) eq 'true' ) {
4104 $default_value = "y";
4105 } else {
4106 $default_value = "n";
4107 }
4108 print "Enable aggressive decoding? (y/n) [$WHT$default_value$NRM]: $WHT";
4109 $aggressive_decoding = <STDIN>;
4110 if ( ( $aggressive_decoding =~ /^y\n/i ) || ( ( $aggressive_decoding =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4111 $aggressive_decoding = 'true';
4112 } else {
4113 $aggressive_decoding = 'false';
4114 }
4115 return $aggressive_decoding;
4116 }
4117
4118 # Lossy encoding
4119 sub commandA5 {
4120 print "Enable this option if you want to allow lossy charset encoding in message\n";
4121 print "composition pages. This option allows charset conversions when output\n";
4122 print "charset does not support all symbols used in original charset. Symbols\n";
4123 print "unsupported by output charset will be replaced with question marks.\n";
4124 print "\n";
4125
4126 if ( lc($lossy_encoding) eq 'true' ) {
4127 $default_value = "y";
4128 } else {
4129 $default_value = "n";
4130 }
4131 print "Enable lossy encoding? (y/n) [$WHT$default_value$NRM]: $WHT";
4132 $lossy_encoding = <STDIN>;
4133 if ( ( $lossy_encoding =~ /^y\n/i ) || ( ( $lossy_encoding =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4134 $lossy_encoding = 'true';
4135 } else {
4136 $lossy_encoding = 'false';
4137 }
4138 return $lossy_encoding;
4139 }
4140
4141 # display html emails in iframe
4142 sub commandB2 {
4143 print "This option can enable html email rendering inside iframe.\n";
4144 print "Inline frames are used in order to provide sandbox environment";
4145 print "for html code included in html formated emails.";
4146 print "Option is experimental and might have glitches in some parts of code.";
4147 print "\n";
4148
4149 if ( lc($use_iframe) eq 'true' ) {
4150 $default_value = "y";
4151 } else {
4152 $default_value = "n";
4153 }
4154 print "Display html emails in iframe? (y/n) [$WHT$default_value$NRM]: $WHT";
4155 $use_iframe = <STDIN>;
4156 if ( ( $use_iframe =~ /^y\n/i ) || ( ( $use_iframe =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4157 $use_iframe = 'true';
4158 } else {
4159 $use_iframe = 'false';
4160 }
4161 return $use_iframe;
4162 }
4163
4164 # ask user info
4165 sub command_ask_user_info {
4166 print "New users need to supply their real name and email address to\n";
4167 print "send out proper mails. When this option is enabled, a user that\n";
4168 print "logs in for the first time will be redirected to the Personal\n";
4169 print "Options screen and asked to supply their personal data.\n";
4170 print "\n";
4171
4172 if ( lc($ask_user_info) eq 'true' ) {
4173 $default_value = "y";
4174 } else {
4175 $default_value = "n";
4176 }
4177 print "Ask user info? (y/n) [$WHT$default_value$NRM]: $WHT";
4178 $ask_user_info = <STDIN>;
4179 if ( ( $ask_user_info =~ /^y\n/i ) || ( ( $ask_user_info =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4180 $ask_user_info = 'true';
4181 } else {
4182 $ask_user_info = 'false';
4183 }
4184 return $ask_user_info;
4185 }
4186
4187 # use icons
4188 sub commandB3 {
4189 print "Enabling this option will cause icons to be used instead of text\n";
4190 print "markers next to each message in mailbox lists that represent\n";
4191 print "new, read, flagged, and deleted messages, as well as those that\n";
4192 print "have been replied to and forwarded. Icons are also used next to\n";
4193 print "(un)expanded folders in the folder list (Oldway = false). These\n";
4194 print "icons are quite small, but will obviously be more of a resource\n";
4195 print "drain than text markers.\n";
4196 print "\n";
4197
4198 if ( lc($use_icons) eq 'true' ) {
4199 $default_value = "y";
4200 } else {
4201 $default_value = "n";
4202 }
4203 print "Use icons? (y/n) [$WHT$default_value$NRM]: $WHT";
4204 $use_icons = <STDIN>;
4205 if ( ( $use_icons =~ /^y\n/i ) || ( ( $use_icons =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4206 $use_icons = 'true';
4207 } else {
4208 $use_icons = 'false';
4209 }
4210 return $use_icons;
4211 }
4212 # php recode
4213 sub commandB4 {
4214 print "Enable this option if you want to use php recode functions to read\n";
4215 print "emails written in charset that differs from the one that is set in\n";
4216 print "translation selected by user. Code is experimental, it might cause\n";
4217 print "errors, if email contains charset unsupported by recode or if your\n";
4218 print "php does not have recode support.\n";
4219 print "\n";
4220
4221 if ( lc($use_php_recode) eq 'true' ) {
4222 $default_value = "y";
4223 } else {
4224 $default_value = "n";
4225 }
4226 print "Use php recode functions? (y/n) [$WHT$default_value$NRM]: $WHT";
4227 $use_php_recode = <STDIN>;
4228 if ( ( $use_php_recode =~ /^y\n/i ) || ( ( $use_php_recode =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4229 $use_php_recode = 'true';
4230 } else {
4231 $use_php_recode = 'false';
4232 }
4233 return $use_php_recode;
4234 }
4235 # php iconv
4236 sub commandB5 {
4237 print "Enable this option if you want to use php iconv functions to read\n";
4238 print "emails written in charset that differs from the one that is set in\n";
4239 print "translation selected by user. Code is experimental, it works only\n";
4240 print "with translations that use utf-8 charset. Code might cause errors,\n";
4241 print "if email contains charset unsupported by iconv or if your php does\n";
4242 print "not have iconv support.\n";
4243 print "\n";
4244
4245 if ( lc($use_php_iconv) eq 'true' ) {
4246 $default_value = "y";
4247 } else {
4248 $default_value = "n";
4249 }
4250 print "Use php iconv functions? (y/n) [$WHT$default_value$NRM]: $WHT";
4251 $use_php_iconv = <STDIN>;
4252 if ( ( $use_php_iconv =~ /^y\n/i ) || ( ( $use_php_iconv =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4253 $use_php_iconv = 'true';
4254 } else {
4255 $use_php_iconv = 'false';
4256 }
4257 return $use_php_iconv;
4258 }
4259
4260 # configtest block
4261 sub commandB6 {
4262 print "Enable this option if you want to check SquirrelMail configuration\n";
4263 print "remotely with configtest.php script.\n";
4264 print "\n";
4265
4266 if ( lc($allow_remote_configtest) eq 'true' ) {
4267 $default_value = "y";
4268 } else {
4269 $default_value = "n";
4270 }
4271 print "Allow remote configuration tests? (y/n) [$WHT$default_value$NRM]: $WHT";
4272 $allow_remote_configtest = <STDIN>;
4273 if ( ( $allow_remote_configtest =~ /^y\n/i ) || ( ( $allow_remote_configtest =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
4274 $allow_remote_configtest = 'true';
4275 } else {
4276 $allow_remote_configtest = 'false';
4277 }
4278 return $allow_remote_configtest;
4279 }
4280
4281 # Default Icon theme
4282 sub commandB7 {
4283 print "You may change the path to the default icon theme to be used, if icons\n";
4284 print "have been enabled. This theme will be used when an icon cannot be\n";
4285 print "found in the current theme, or when no icon theme is specified. If\n";
4286 print "left blank, and icons are enabled, the default theme will be used\n";
4287 print "from images/themes/default/.\n";
4288 print "\n";
4289 print "To clear out an existing value, just type a space for the input.\n";
4290 print "\n";
4291 print "Please be aware of the following: \n";
4292 print " - Relative URLs are relative to the config dir\n";
4293 print " to use the icon themes directory, use ../images/themes/newtheme/\n";
4294 print " - The icon theme may be outside the SquirrelMail directory, but\n";
4295 print " it must be web accessible.\n";
4296 print "[$WHT$icon_theme_def$NRM]: $WHT";
4297 $new_icon_theme_def = <STDIN>;
4298
4299 if ( $new_icon_theme_def eq "\n" ) {
4300 $new_icon_theme_def = $icon_theme_def;
4301 } else {
4302 $new_icon_theme_def =~ s/[\r\n]//g;
4303 }
4304 $new_icon_theme_def =~ s/^\s*//;
4305 return $new_icon_theme_def;
4306 }
4307
4308 sub save_data {
4309 $tab = " ";
4310 if ( open( CF, ">config.php" ) ) {
4311 print CF "<?php\n";
4312 print CF "\n";
4313
4314 print CF "/**\n";
4315 print CF " * SquirrelMail Configuration File\n";
4316 print CF " * Created using the configure script, conf.pl\n";
4317 print CF " */\n";
4318 print CF "\n";
4319
4320 if ($print_config_version) {
4321 print CF "\$config_version = '$print_config_version';\n";
4322 }
4323 # integer
4324 print CF "\$config_use_color = $config_use_color;\n";
4325 print CF "\n";
4326
4327 # string
4328 print CF "\$org_name = \"$org_name\";\n";
4329 # string
4330 print CF "\$org_logo = " . &change_to_SM_path($org_logo) . ";\n";
4331 $org_logo_width |= 0;
4332 $org_logo_height |= 0;
4333 # string
4334 print CF "\$org_logo_width = '$org_logo_width';\n";
4335 # string
4336 print CF "\$org_logo_height = '$org_logo_height';\n";
4337 # string that can contain variables.
4338 print CF "\$org_title = \"$org_title\";\n";
4339 # string
4340 print CF "\$signout_page = " . &change_to_SM_path($signout_page) . ";\n";
4341 # string
4342 print CF "\$frame_top = '$frame_top';\n";
4343 print CF "\n";
4344
4345 print CF "\$provider_uri = '$provider_uri';\n";
4346 print CF "\n";
4347
4348 print CF "\$provider_name = '$provider_name';\n";
4349 print CF "\n";
4350
4351 # string that can contain variables
4352 print CF "\$motd = \"$motd\";\n";
4353 print CF "\n";
4354
4355 # string
4356 print CF "\$squirrelmail_default_language = '$squirrelmail_default_language';\n";
4357 # string
4358 print CF "\$default_charset = '$default_charset';\n";
4359 # boolean
4360 print CF "\$show_alternative_names = $show_alternative_names;\n";
4361 # boolean
4362 print CF "\$aggressive_decoding = $aggressive_decoding;\n";
4363 # boolean
4364 print CF "\$lossy_encoding = $lossy_encoding;\n";
4365 print CF "\n";
4366
4367 # string
4368 print CF "\$domain = '$domain';\n";
4369 # string
4370 print CF "\$imapServerAddress = '$imapServerAddress';\n";
4371 # integer
4372 print CF "\$imapPort = $imapPort;\n";
4373 # boolean
4374 print CF "\$useSendmail = $useSendmail;\n";
4375 # string
4376 print CF "\$smtpServerAddress = '$smtpServerAddress';\n";
4377 # integer
4378 print CF "\$smtpPort = $smtpPort;\n";
4379 # string
4380 print CF "\$sendmail_path = '$sendmail_path';\n";
4381 # string
4382 print CF "\$sendmail_args = '$sendmail_args';\n";
4383 # boolean
4384 # print CF "\$use_authenticated_smtp = $use_authenticated_smtp;\n";
4385 # boolean
4386 print CF "\$pop_before_smtp = $pop_before_smtp;\n";
4387 # string
4388 print CF "\$imap_server_type = '$imap_server_type';\n";
4389 # boolean
4390 print CF "\$invert_time = $invert_time;\n";
4391 # string
4392 print CF "\$optional_delimiter = '$optional_delimiter';\n";
4393 # string
4394 print CF "\$encode_header_key = '$encode_header_key';\n";
4395 print CF "\n";
4396
4397 # string
4398 print CF "\$default_folder_prefix = '$default_folder_prefix';\n";
4399 # string
4400 print CF "\$trash_folder = '$trash_folder';\n";
4401 # string
4402 print CF "\$sent_folder = '$sent_folder';\n";
4403 # string
4404 print CF "\$draft_folder = '$draft_folder';\n";
4405 # boolean
4406 print CF "\$default_move_to_trash = $default_move_to_trash;\n";
4407 # boolean
4408 print CF "\$default_move_to_sent = $default_move_to_sent;\n";
4409 # boolean
4410 print CF "\$default_save_as_draft = $default_save_as_draft;\n";
4411 # boolean
4412 print CF "\$show_prefix_option = $show_prefix_option;\n";
4413 # boolean
4414 print CF "\$list_special_folders_first = $list_special_folders_first;\n";
4415 # boolean
4416 print CF "\$use_special_folder_color = $use_special_folder_color;\n";
4417 # boolean
4418 print CF "\$auto_expunge = $auto_expunge;\n";
4419 # boolean
4420 print CF "\$default_sub_of_inbox = $default_sub_of_inbox;\n";
4421 # boolean
4422 print CF "\$show_contain_subfolders_option = $show_contain_subfolders_option;\n";
4423 # integer
4424 print CF "\$default_unseen_notify = $default_unseen_notify;\n";
4425 # integer
4426 print CF "\$default_unseen_type = $default_unseen_type;\n";
4427 # boolean
4428 print CF "\$auto_create_special = $auto_create_special;\n";
4429 # boolean
4430 print CF "\$delete_folder = $delete_folder;\n";
4431 # boolean
4432 print CF "\$noselect_fix_enable = $noselect_fix_enable;\n";
4433
4434 print CF "\n";
4435
4436 # string
4437 print CF "\$data_dir = " . &change_to_SM_path($data_dir) . ";\n";
4438 # string that can contain a variable
4439 print CF "\$attachment_dir = " . &change_to_SM_path($attachment_dir) . ";\n";
4440 # integer
4441 print CF "\$dir_hash_level = $dir_hash_level;\n";
4442 # string
4443 print CF "\$default_left_size = '$default_left_size';\n";
4444 # boolean
4445 print CF "\$force_username_lowercase = $force_username_lowercase;\n";
4446 # boolean
4447 print CF "\$default_use_priority = $default_use_priority;\n";
4448 # boolean
4449 print CF "\$hide_sm_attributions = $hide_sm_attributions;\n";
4450 # boolean
4451 print CF "\$default_use_mdn = $default_use_mdn;\n";
4452 # boolean
4453 print CF "\$edit_identity = $edit_identity;\n";
4454 # boolean
4455 print CF "\$edit_name = $edit_name;\n";
4456 # boolean
4457 print CF "\$hide_auth_header = $hide_auth_header;\n";
4458 # boolean
4459 print CF "\$disable_thread_sort = $disable_thread_sort;\n";
4460 # boolean
4461 print CF "\$disable_server_sort = $disable_server_sort;\n";
4462 # boolean
4463 print CF "\$allow_charset_search = $allow_charset_search;\n";
4464 # integer
4465 print CF "\$allow_advanced_search = $allow_advanced_search;\n";
4466 print CF "\n";
4467 # integer
4468 print CF "\$time_zone_type = $time_zone_type;\n";
4469 print CF "\n";
4470 # string
4471 print CF "\$config_location_base = '$config_location_base';\n";
4472 print CF "\n";
4473 # boolean
4474 print CF "\$disable_plugins = $disable_plugins;\n";
4475 # string
4476 print CF "\$disable_plugins_user = '$disable_plugins_user';\n";
4477 print CF "\n";
4478
4479 # all plugins are strings
4480 for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
4481 print CF "\$plugins[] = '$plugins[$ct]';\n";
4482 }
4483 print CF "\n";
4484
4485 # strings
4486 if ( $user_theme_default eq '' ) { $user_theme_default = '0'; }
4487 print CF "\$user_theme_default = $user_theme_default;\n";
4488
4489 for ( $count = 0 ; $count <= $#user_theme_name ; $count++ ) {
4490 if ($user_theme_path[$count] eq 'none') {
4491 $path = '\'none\'';
4492 } else {
4493 $path = &change_to_SM_path($user_theme_path[$count]);
4494 }
4495 print CF "\$user_themes[$count]['PATH'] = " . $path . ";\n";
4496 # escape theme name so it can contain single quotes.
4497 $esc_name = $user_theme_name[$count];
4498 $esc_name =~ s/\\/\\\\/g;
4499 $esc_name =~ s/'/\\'/g;
4500 print CF "\$user_themes[$count]['NAME'] = '$esc_name';\n";
4501 }
4502 print CF "\n";
4503
4504 if ( $icon_theme_def eq '' ) { $icon_theme_def = '0'; }
4505 print CF "\$icon_theme_def = $icon_theme_def;\n";
4506 if ( $icon_theme_fallback eq '' ) { $icon_theme_fallback = '0'; }
4507 print CF "\$icon_theme_fallback = $icon_theme_fallback;\n";
4508
4509 for ( $count = 0 ; $count <= $#icon_theme_name ; $count++ ) {
4510 $path = $icon_theme_path[$count];
4511 if ($path eq 'none' || $path eq 'template') {
4512 $path = "'".$path."'";
4513 } else {
4514 $path = &change_to_SM_path($icon_theme_path[$count]);
4515 }
4516 print CF "\$icon_themes[$count]['PATH'] = " . $path . ";\n";
4517 # escape theme name so it can contain single quotes.
4518 $esc_name = $icon_theme_name[$count];
4519 $esc_name =~ s/\\/\\\\/g;
4520 $esc_name =~ s/'/\\'/g;
4521 print CF "\$icon_themes[$count]['NAME'] = '$esc_name';\n";
4522 }
4523 print CF "\n";
4524
4525 if ( $templateset_default eq '' ) { $templateset_default = 'default'; }
4526 print CF "\$templateset_default = '$templateset_default';\n";
4527
4528 if ( $templateset_fallback eq '' ) { $templateset_fallback = 'default'; }
4529 print CF "\$templateset_fallback = '$templateset_fallback';\n";
4530
4531 for ( $count = 0 ; $count <= $#templateset_name ; $count++ ) {
4532 print CF "\$aTemplateSet[$count]['ID'] = '" . $templateset_id[$count] . "';\n";
4533 # escape theme name so it can contain single quotes.
4534 $esc_name = $templateset_name[$count];
4535 $esc_name =~ s/\\/\\\\/g;
4536 $esc_name =~ s/'/\\'/g;
4537 print CF "\$aTemplateSet[$count]['NAME'] = '$esc_name';\n";
4538 }
4539 print CF "\n";
4540
4541
4542 # integer
4543 print CF "\$default_fontsize = '$default_fontsize';\n";
4544 # string
4545 print CF "\$default_fontset = '$default_fontset';\n";
4546 print CF "\n";
4547 # assoc. array (maybe initial value should be set somewhere else)
4548 print CF '$fontsets = array();'."\n";
4549 while (($fontset_name, $fontset_value) = each(%fontsets)) {
4550 print CF "\$fontsets\['$fontset_name'\] = '$fontset_value';\n";
4551 }
4552 print CF "\n";
4553
4554 ## Address books
4555 # boolean
4556 print CF "\$default_use_javascript_addr_book = $default_use_javascript_addr_book;\n";
4557 for ( $count = 0 ; $count <= $#ldap_host ; $count++ ) {
4558 print CF "\$ldap_server[$count] = array(\n";
4559 # string
4560 print CF " 'host' => '$ldap_host[$count]',\n";
4561 # string
4562 print CF " 'base' => '$ldap_base[$count]'";
4563 if ( $ldap_name[$count] ) {
4564 print CF ",\n";
4565 # string
4566 print CF " 'name' => '$ldap_name[$count]'";
4567 }
4568 if ( $ldap_port[$count] ) {
4569 print CF ",\n";
4570 # integer
4571 print CF " 'port' => $ldap_port[$count]";
4572 }
4573 if ( $ldap_charset[$count] ) {
4574 print CF ",\n";
4575 # string
4576 print CF " 'charset' => '$ldap_charset[$count]'";
4577 }
4578 if ( $ldap_maxrows[$count] ) {
4579 print CF ",\n";
4580 # integer
4581 print CF " 'maxrows' => $ldap_maxrows[$count]";
4582 }
4583 # string
4584 if ( $ldap_filter[$count] ) {
4585 print CF ",\n";
4586 print CF " 'filter' => '$ldap_filter[$count]'";
4587 }
4588 if ( $ldap_binddn[$count] ) {
4589 print CF ",\n";
4590 # string
4591 print CF " 'binddn' => '$ldap_binddn[$count]'";
4592 if ( $ldap_bindpw[$count] ) {
4593 print CF ",\n";
4594 # string
4595 print CF " 'bindpw' => '$ldap_bindpw[$count]'";
4596 }
4597 }
4598 if ( $ldap_protocol[$count] ) {
4599 print CF ",\n";
4600 # integer
4601 print CF " 'protocol' => $ldap_protocol[$count]";
4602 }
4603 if ( $ldap_limit_scope[$count] ) {
4604 print CF ",\n";
4605 # boolean
4606 print CF " 'limit_scope' => $ldap_limit_scope[$count]";
4607 }
4608 if ( $ldap_listing[$count] ) {
4609 print CF ",\n";
4610 # boolean
4611 print CF " 'listing' => $ldap_listing[$count]";
4612 }
4613 if ( $ldap_writeable[$count] ) {
4614 print CF ",\n";
4615 # boolean
4616 print CF " 'writeable' => $ldap_writeable[$count]";
4617 }
4618 if ( $ldap_search_tree[$count] ) {
4619 print CF ",\n";
4620 # integer
4621 print CF " 'search_tree' => $ldap_search_tree[$count]";
4622 }
4623 if ( $ldap_listing[$count] ) {
4624 print CF ",\n";
4625 # boolean
4626 print CF " 'starttls' => $ldap_starttls[$count]";
4627 }
4628 print CF "\n";
4629 print CF ");\n";
4630 print CF "\n";
4631 }
4632
4633 # string
4634 print CF "\$addrbook_dsn = '$addrbook_dsn';\n";
4635 # string
4636 print CF "\$addrbook_table = '$addrbook_table';\n\n";
4637 # string
4638 print CF "\$prefs_dsn = '$prefs_dsn';\n";
4639 # string
4640 print CF "\$prefs_table = '$prefs_table';\n";
4641 # string
4642 print CF "\$prefs_user_field = '$prefs_user_field';\n";
4643 # integer
4644 print CF "\$prefs_user_size = $prefs_user_size;\n";
4645 # string
4646 print CF "\$prefs_key_field = '$prefs_key_field';\n";
4647 # integer
4648 print CF "\$prefs_key_size = $prefs_key_size;\n";
4649 # string
4650 print CF "\$prefs_val_field = '$prefs_val_field';\n";
4651 # integer
4652 print CF "\$prefs_val_size = $prefs_val_size;\n\n";
4653 # string
4654 print CF "\$addrbook_global_dsn = '$addrbook_global_dsn';\n";
4655 # string
4656 print CF "\$addrbook_global_table = '$addrbook_global_table';\n";
4657 # boolean
4658 print CF "\$addrbook_global_writeable = $addrbook_global_writeable;\n";
4659 # boolean
4660 print CF "\$addrbook_global_listing = $addrbook_global_listing;\n\n";
4661 # string
4662 print CF "\$abook_global_file = '$abook_global_file';\n";
4663 # boolean
4664 print CF "\$abook_global_file_writeable = $abook_global_file_writeable;\n\n";
4665 # boolean
4666 print CF "\$abook_global_file_listing = $abook_global_file_listing;\n\n";
4667 # integer
4668 print CF "\$abook_file_line_length = $abook_file_line_length;\n\n";
4669 # boolean
4670 print CF "\$no_list_for_subscribe = $no_list_for_subscribe;\n";
4671
4672 # string
4673 print CF "\$smtp_auth_mech = '$smtp_auth_mech';\n";
4674 print CF "\$smtp_sitewide_user = '". quote_single($smtp_sitewide_user) ."';\n";
4675 print CF "\$smtp_sitewide_pass = '". quote_single($smtp_sitewide_pass) ."';\n";
4676 # string
4677 print CF "\$imap_auth_mech = '$imap_auth_mech';\n";
4678 # boolean
4679 print CF "\$use_imap_tls = $use_imap_tls;\n";
4680 # boolean
4681 print CF "\$use_smtp_tls = $use_smtp_tls;\n";
4682 # string
4683 print CF "\$session_name = '$session_name';\n";
4684 # boolean
4685 print CF "\$only_secure_cookies = $only_secure_cookies;\n";
4686
4687 print CF "\n";
4688
4689 # boolean
4690 print CF "\$use_iframe = $use_iframe;\n";
4691 # boolean
4692 print CF "\$ask_user_info = $ask_user_info;\n";
4693 # boolean
4694 print CF "\$use_icons = $use_icons;\n";
4695 print CF "\n";
4696 # boolean
4697 print CF "\$use_php_recode = $use_php_recode;\n";
4698 # boolean
4699 print CF "\$use_php_iconv = $use_php_iconv;\n";
4700 print CF "\n";
4701 # boolean
4702 print CF "\$allow_remote_configtest = $allow_remote_configtest;\n";
4703 print CF "\n";
4704
4705 close CF;
4706
4707 print "Data saved in config.php\n";
4708
4709 build_plugin_hook_array();
4710
4711 } else {
4712 print "Error saving config.php: $!\n";
4713 }
4714 }
4715
4716 sub set_defaults {
4717 clear_screen();
4718 print $WHT. "SquirrelMail Configuration : " . $NRM;
4719 if ( $config == 1 ) { print "Read: config.php"; }
4720 elsif ( $config == 2 ) { print "Read: config_default.php"; }
4721 print "\n";
4722 print "---------------------------------------------------------\n";
4723
4724 print "While we have been building SquirrelMail, we have discovered some\n";
4725 print "preferences that work better with some servers that don't work so\n";
4726 print "well with others. If you select your IMAP server, this option will\n";
4727 print "set some pre-defined settings for that server.\n";
4728 print "\n";
4729 print "Please note that you will still need to go through and make sure\n";
4730 print "everything is correct. This does not change everything. There are\n";
4731 print "only a few settings that this will change.\n";
4732 print "\n";
4733
4734 $continue = 0;
4735 while ( $continue != 1 ) {
4736 print "Please select your IMAP server:\n";
4737 print $list_supported_imap_servers;
4738 print "\n";
4739 print " quit = Do not change anything\n";
4740 print "\n";
4741 print "Command >> ";
4742 $server = <STDIN>;
4743 $server =~ s/[\r\n]//g;
4744
4745 # variable is used to display additional messages.
4746 $message = "";
4747
4748 print "\n";
4749 if ( $server eq "cyrus" ) {
4750 $imap_server_type = "cyrus";
4751 $default_folder_prefix = "";
4752 $trash_folder = "INBOX.Trash";
4753 $sent_folder = "INBOX.Sent";
4754 $draft_folder = "INBOX.Drafts";
4755 $show_prefix_option = false;
4756 $default_sub_of_inbox = true;
4757 $show_contain_subfolders_option = false;
4758 $optional_delimiter = ".";
4759 $disp_default_folder_prefix = "<none>";
4760 $force_username_lowercase = false;
4761
4762 # Delimiter might differ if unixhierarchysep is set to yes.
4763 $message = "\nIf you have enabled unixhierarchysep, you must change delimiter and special folder names.\n";
4764
4765 $continue = 1;
4766 } elsif ( $server eq "uw" ) {
4767 $imap_server_type = "uw";
4768 $default_folder_prefix = "mail/";
4769 $trash_folder = "Trash";
4770 $sent_folder = "Sent";
4771 $draft_folder = "Drafts";
4772 $show_prefix_option = true;
4773 $default_sub_of_inbox = false;
4774 $show_contain_subfolders_option = true;
4775 $optional_delimiter = "/";
4776 $disp_default_folder_prefix = $default_folder_prefix;
4777 $delete_folder = true;
4778 $force_username_lowercase = true;
4779
4780 $continue = 1;
4781 } elsif ( $server eq "exchange" ) {
4782 $imap_server_type = "exchange";
4783 $default_folder_prefix = "";
4784 $default_sub_of_inbox = true;
4785 $trash_folder = "INBOX/Deleted Items";
4786 $sent_folder = "INBOX/Sent Items";
4787 $drafts_folder = "INBOX/Drafts";
4788 $show_prefix_option = false;
4789 $show_contain_subfolders_option = false;
4790 $optional_delimiter = "detect";
4791 $disp_default_folder_prefix = "<none>";
4792 $force_username_lowercase = true;
4793
4794 $continue = 1;
4795 } elsif ( $server eq "courier" ) {
4796 $imap_server_type = "courier";
4797 $default_folder_prefix = "INBOX.";
4798 $trash_folder = "Trash";
4799 $sent_folder = "Sent";
4800 $draft_folder = "Drafts";
4801 $show_prefix_option = false;
4802 $default_sub_of_inbox = false;
4803 $show_contain_subfolders_option = false;
4804 $optional_delimiter = ".";
4805 $disp_default_folder_prefix = $default_folder_prefix;
4806 $delete_folder = true;
4807 $force_username_lowercase = false;
4808
4809 $continue = 1;
4810 } elsif ( $server eq "macosx" ) {
4811 $imap_server_type = "macosx";
4812 $default_folder_prefix = "INBOX/";
4813 $trash_folder = "Trash";
4814 $sent_folder = "Sent";
4815 $draft_folder = "Drafts";
4816 $show_prefix_option = false;
4817 $default_sub_of_inbox = true;
4818 $show_contain_subfolders_option = false;
4819 $optional_delimiter = "detect";
4820 $allow_charset_search = false;
4821 $disp_default_folder_prefix = $default_folder_prefix;
4822
4823 $continue = 1;
4824 } elsif ( $server eq "hmailserver" ) {
4825 $imap_server_type = "hmailserver";
4826 $default_folder_prefix = "";
4827 $trash_folder = "INBOX.Trash";
4828 $sent_folder = "INBOX.Sent";
4829 $draft_folder = "INBOX.Drafts";
4830 $show_prefix_option = false;
4831 $default_sub_of_inbox = true;
4832 $show_contain_subfolders_option = false;
4833 $optional_delimiter = "detect";
4834 $allow_charset_search = false;
4835 $disp_default_folder_prefix = $default_folder_prefix;
4836 $delete_folder = false;
4837 $force_username_lowercase = false;
4838
4839 $continue = 1;
4840 } elsif ( $server eq "mercury32" ) {
4841 $imap_server_type = "mercury32";
4842 $default_folder_prefix = "";
4843 $trash_folder = "Trash";
4844 $sent_folder = "Sent";
4845 $draft_folder = "Drafts";
4846 $show_prefix_option = false;
4847 $default_sub_of_inbox = true;
4848 $show_contain_subfolders_option = true;
4849 $optional_delimiter = "detect";
4850 $delete_folder = true;
4851 $force_username_lowercase = true;
4852
4853 $continue = 1;
4854 } elsif ( $server eq "dovecot" ) {
4855 $imap_server_type = "dovecot";
4856 $default_folder_prefix = "";
4857 $trash_folder = "Trash";
4858 $sent_folder = "Sent";
4859 $draft_folder = "Drafts";
4860 $show_prefix_option = false;
4861 $default_sub_of_inbox = false;
4862 $show_contain_subfolders_option = false;
4863 $delete_folder = false;
4864 $force_username_lowercase = true;
4865 $optional_delimiter = "detect";
4866 $disp_default_folder_prefix = "<none>";
4867
4868 $continue = 1;
4869 } elsif ( $server eq "bincimap" ) {
4870 $imap_server_type = "bincimap";
4871 $default_folder_prefix = "INBOX/";
4872 $trash_folder = "Trash";
4873 $sent_folder = "Sent";
4874 $draft_folder = "Drafts";
4875 $show_prefix_option = false;
4876 $default_sub_of_inbox = false;
4877 $show_contain_subfolders_option = false;
4878 $delete_folder = true;
4879 $force_username_lowercase = false;
4880 $optional_delimiter = "detect";
4881 $disp_default_folder_prefix = $default_folder_prefix;
4882
4883 # Default folder prefix depends on used depot.
4884 $message = "\nIf you use IMAPdir depot, you must set default folder prefix to empty string.\n";
4885
4886 $continue = 1;
4887 } elsif ( $server eq "quit" ) {
4888 $continue = 1;
4889 } else {
4890 $disp_default_folder_prefix = $default_folder_prefix;
4891 print "Unrecognized server: $server\n";
4892 print "\n";
4893 }
4894
4895 print " imap_server_type = $imap_server_type\n";
4896 print " default_folder_prefix = $disp_default_folder_prefix\n";
4897 print " trash_folder = $trash_folder\n";
4898 print " sent_folder = $sent_folder\n";
4899 print " draft_folder = $draft_folder\n";
4900 print " show_prefix_option = $show_prefix_option\n";
4901 print " default_sub_of_inbox = $default_sub_of_inbox\n";
4902 print "show_contain_subfolders_option = $show_contain_subfolders_option\n";
4903 print " optional_delimiter = $optional_delimiter\n";
4904 print " delete_folder = $delete_folder\n";
4905 print " force_username_lowercase = $force_username_lowercase\n";
4906
4907 print "$message";
4908 }
4909 print "\nPress enter to continue...";
4910 $tmp = <STDIN>;
4911 }
4912
4913 # This subroutine corrects relative paths to ensure they
4914 # will work within the SM space. If the path falls within
4915 # the SM directory tree, the SM_PATH variable will be
4916 # prepended to the path, if not, then the path will be
4917 # converted to an absolute path, e.g.
4918 # '../images/logo.gif' --> SM_PATH . 'images/logo.gif'
4919 # '../../someplace/data' --> '/absolute/path/someplace/data'
4920 # 'images/logo.gif' --> SM_PATH . 'config/images/logo.gif'
4921 # '/absolute/path/logo.gif' --> '/absolute/path/logo.gif'
4922 # 'http://whatever/' --> 'http://whatever'
4923 # $some_var/path --> "$some_var/path"
4924 sub change_to_SM_path() {
4925 my ($old_path) = @_;
4926 my $new_path = '';
4927 my @rel_path;
4928 my @abs_path;
4929 my $subdir;
4930
4931 # If the path is absolute, don't bother.
4932 return "\'" . $old_path . "\'" if ( $old_path eq '');
4933 return "\'" . $old_path . "\'" if ( $old_path =~ /^(\/|http)/ );
4934 return "\'" . $old_path . "\'" if ( $old_path =~ /^\w:\// );
4935 return $old_path if ( $old_path =~ /^\'(\/|http)/ );
4936 return $old_path if ( $old_path =~ /^\'\w:\// );
4937 return $old_path if ( $old_path =~ /^SM_PATH/);
4938
4939 if ( $old_path =~ /^\$/ ) {
4940 # check if it's a single var, or a $var/path combination
4941 # if it's $var/path, enclose in ""
4942 if ( $old_path =~ /\// ) {
4943 return '"'.$old_path.'"';
4944 }
4945 return $old_path;
4946 }
4947
4948 # Remove remaining '
4949 $old_path =~ s/\'//g;
4950
4951 # For relative paths, split on '../'
4952 @rel_path = split(/\.\.\//, $old_path);
4953
4954 if ( $#rel_path > 1 ) {
4955 # more than two levels away. Make it absolute.
4956 @abs_path = split(/\//, $dir);
4957
4958 # Lop off the relative pieces of the absolute path..
4959 for ( $i = 0; $i <= $#rel_path; $i++ ) {
4960 pop @abs_path;
4961 shift @rel_path;
4962 }
4963 push @abs_path, @rel_path;
4964 $new_path = "\'" . join('/', @abs_path) . "\'";
4965 } elsif ( $#rel_path > 0 ) {
4966 # it's within the SM tree, prepend SM_PATH
4967 $new_path = $old_path;
4968 $new_path =~ s/^\.\.\//SM_PATH . \'/;
4969 $new_path .= "\'";
4970 } else {
4971 # Last, it's a relative path without any leading '.'
4972 # Prepend SM_PATH and config, since the paths are
4973 # relative to the config directory
4974 $new_path = "SM_PATH . \'config/" . $old_path . "\'";
4975 }
4976 return $new_path;
4977 }
4978
4979
4980 # Change SM_PATH to admin-friendly version, e.g.:
4981 # SM_PATH . 'images/logo.gif' --> '../images/logo.gif'
4982 # SM_PATH . 'config/some.php' --> 'some.php'
4983 # '/absolute/path/logo.gif' --> '/absolute/path/logo.gif'
4984 # 'http://whatever/' --> 'http://whatever'
4985 sub change_to_rel_path() {
4986 my ($old_path) = @_;
4987 my $new_path = $old_path;
4988
4989 if ( $old_path =~ /^SM_PATH/ ) {
4990 # FIXME: the following replacement loses the opening quote mark!
4991 $new_path =~ s/^SM_PATH . \'/\.\.\//;
4992 $new_path =~ s/\.\.\/config\///;
4993 }
4994
4995 return $new_path;
4996 }
4997
4998 # Attempts to auto-detect if a specific auth mechanism is supported.
4999 # Called by 'command112a' and 'command112b'
5000 # ARGS: service-name (IMAP or SMTP), host:port, mech-name (ie. CRAM-MD5)
5001 sub detect_auth_support {
5002 # Try loading IO::Socket
5003 unless (eval("use IO::Socket; 1")) {
5004 print "Perl IO::Socket module is not available.";
5005 return undef;
5006 }
5007 # Misc setup
5008 my $service = shift;
5009 my $host = shift;
5010 my $mech = shift;
5011 # Sanity checks
5012 if ((!defined($service)) or (!defined($host)) or (!defined($mech))) {
5013 # Error - wrong # of args
5014 print "BAD ARGS!\n";
5015 return undef;
5016 }
5017
5018 if ($service eq 'SMTP') {
5019 $cmd = "AUTH $mech\r\n";
5020 $logout = "QUIT\r\n";
5021 } elsif ($service eq 'IMAP') {
5022 $cmd = "A01 AUTHENTICATE $mech\n";
5023 $logout = "C01 LOGOUT\n";
5024 } else {
5025 # unknown service - whoops.
5026 return undef;
5027 }
5028
5029 # Get this show on the road
5030 my $sock=IO::Socket::INET->new($host);
5031 if (!defined($sock)) {
5032 # Connect failed
5033 return undef;
5034 }
5035 my $discard = <$sock>; # Server greeting/banner - who cares..
5036
5037 if ($service eq 'SMTP') {
5038 # Say hello first..
5039 print $sock "HELO $domain\r\n";
5040 $discard = <$sock>; # Yeah yeah, you're happy to see me..
5041 }
5042 print $sock $cmd;
5043
5044 my $response = <$sock>;
5045 chomp($response);
5046 if (!defined($response)) {
5047 return undef;
5048 }
5049
5050 # So at this point, we have a response, and it is (hopefully) valid.
5051 if ($service eq 'SMTP') {
5052 if (!($response =~ /^334/)) {
5053 # Not supported
5054 print $sock $logout;
5055 close $sock;
5056 return 'NO';
5057 }
5058 } elsif ($service eq 'IMAP') {
5059 if ($response =~ /^A01/) {
5060 # Not supported
5061 print $sock $logout;
5062 close $sock;
5063 return 'NO';
5064 }
5065 } else {
5066 # Unknown service - this shouldn't be able to happen.
5067 close $sock;
5068 return undef;
5069 }
5070
5071 # If it gets here, the mech is supported
5072 print $sock "*\n"; # Attempt to cancel authentication
5073 print $sock $logout; # Try to log out, but we don't really care if this fails
5074 close $sock;
5075 return 'YES';
5076 }
5077
5078 # trims whitespace
5079 # Example code from O'Reilly Perl Cookbook
5080 sub trim {
5081 my @out = @_;
5082 for (@out) {
5083 s/^\s+//;
5084 s/\s+$//;
5085 }
5086 return wantarray ? @out : $out[0];
5087 }
5088
5089 sub clear_screen() {
5090 if ( $^O =~ /^mswin/i) {
5091 system "cls";
5092 } else {
5093 system "clear";
5094 }
5095 }
5096
5097 # checks IMAP mailbox name. Refuses to accept 8bit folders
5098 # returns 0 (folder name is not correct) or 1 (folder name is correct)
5099 sub check_imap_folder($) {
5100 my $folder_name = shift(@_);
5101
5102 if ($folder_name =~ /[\x80-\xFFFF]/) {
5103 print "Folder name contains 8bit characters. Configuration utility requires\n";
5104 print "UTF7-IMAP encoded folder names.\n";
5105 print "Press enter to continue...";
5106 my $tmp = <STDIN>;
5107 return 0;
5108 } elsif ($folder_name =~ /[&\*\%]/) {
5109 # check for ampersand and list-wildcards
5110 print "Folder name contains special UTF7-IMAP characters.\n";
5111 print "Are you sure that folder name is correct? (yN): ";
5112 my $tmp = <STDIN>;
5113 $tmp = lc(trim($tmp));
5114 if ($tmp =~ /^y$/) {
5115 return 1;
5116 } else {
5117 return 0;
5118 }
5119 } else {
5120 return 1;
5121 }
5122 }
5123
5124 # quotes string written in single quotes
5125 sub quote_single($) {
5126 my $string = shift(@_);
5127 $string =~ s/\'/\\'/g;
5128 return $string;
5129 }
5130
5131 # determine a plugin's version number
5132 #
5133 # parses the setup.php file, looking for the
5134 # version string in the <plugin>_info() or the
5135 # <plugin>_version functions.
5136 #
5137 sub get_plugin_version() {
5138
5139 my $plugin_name = shift(@_);
5140
5141 $setup_file = '../plugins/' . $plugin_name . '/setup.php';
5142 if ( -e "$setup_file" ) {
5143 # Make sure that file is readable
5144 if (! -r "$setup_file") {
5145 print "\n";
5146 print "WARNING:\n";
5147 print "The file \"$setup_file\" was found, but you don't\n";
5148 print "have rights to read it. The plugin \"";
5149 print $plugin_name . "\" may not work correctly until you fix this.\n";
5150 print "\nPress enter to continue";
5151 $ctu = <STDIN>;
5152 print "\n";
5153 next;
5154 }
5155
5156 $version = ' ';
5157 # FIXME: grep the file instead of reading it into memory?
5158 $whole_file = '';
5159 open( FILE, "$setup_file" );
5160 while ( $line = <FILE> ) {
5161 $whole_file .= $line;
5162 }
5163 close(FILE);
5164
5165 # ideally, there is a version in the <plugin>_info function...
5166 #
5167 if ($whole_file =~ /('version'\s*=>\s*['"](.*?)['"])/) {
5168 $version .= $2;
5169
5170 # this assumes there is only one function that returns
5171 # a static string in the setup file
5172 #
5173 } elsif ($whole_file =~ /(return\s*['"](.*?)['"])/) {
5174 $version .= $2;
5175 }
5176
5177 return $version;
5178
5179 } else {
5180 print "\n";
5181 print "WARNING:\n";
5182 print "The file \"$setup_file\" was not found.\n";
5183 print "The plugin \"" . $plugin_name;
5184 print "\" may not work correctly until you fix this.\n";
5185 print "\nPress enter to continue";
5186 $ctu = <STDIN>;
5187 print "\n";
5188 next;
5189 }
5190
5191 }
5192
5193 # parses the setup.php files for all activated plugins and
5194 # builds static plugin hooks array so we don't have to load
5195 # ALL plugins are runtime and build the hook array on every
5196 # page request
5197 #
5198 # hook array is saved in config/plugin_hooks.php
5199 #
5200 # Note the $verbose variable at the top of this routine
5201 # can be set to zero to quiet it down.
5202 #
5203 # NOTE/FIXME: we aren't necessarily interested in writing
5204 # a full-blown PHP parsing engine, so plenty
5205 # of assumptions are included herein about the
5206 # coding of the plugin setup files, and things
5207 # like commented out curly braces or other
5208 # such oddities can break this in a bad way.
5209 #
5210 sub build_plugin_hook_array() {
5211
5212 $verbose = 1;
5213
5214 if ($verbose) {
5215 print "\n\n";
5216 }
5217
5218 if ( open( HOOKFILE, ">plugin_hooks.php" ) ) {
5219 print HOOKFILE "<?php\n";
5220 print HOOKFILE "\n";
5221
5222 print HOOKFILE "/**\n";
5223 print HOOKFILE " * SquirrelMail Plugin Hook Registration File\n";
5224 print HOOKFILE " * Auto-generated using the configure script, conf.pl\n";
5225 print HOOKFILE " */\n";
5226 print HOOKFILE "\n";
5227 print HOOKFILE "global \$squirrelmail_plugin_hooks;\n";
5228 print HOOKFILE "\n";
5229
5230 PLUGIN: for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
5231
5232 if ($verbose) {
5233 print "Activating plugin \"" . $plugins[$ct] . "\"...\n";
5234 }
5235
5236 $setup_file = '../plugins/' . $plugins[$ct] . '/setup.php';
5237 if ( -e "$setup_file" ) {
5238 # Make sure that file is readable
5239 if (! -r "$setup_file") {
5240 print "\n";
5241 print "WARNING:\n";
5242 print "The file \"$setup_file\" was found, but you don't\n";
5243 print "have rights to read it. The plugin \"";
5244 print $plugins[$ct] . "\" will not be activated until you fix this.\n";
5245 print "\nPress enter to continue";
5246 $ctu = <STDIN>;
5247 print "\n";
5248 next;
5249 }
5250 open( FILE, "$setup_file" );
5251 $inside_init_fxn = 0;
5252 $brace_count = 0;
5253 while ( $line = <FILE> ) {
5254
5255 # throw away lines until we get to target function
5256 #
5257 if (!$inside_init_fxn
5258 && $line !~ /^\s*function\s*squirrelmail_plugin_init_/i) {
5259 next;
5260 }
5261 $inside_init_fxn = 1;
5262
5263
5264 # count open braces
5265 #
5266 if ($line =~ /{/) {
5267 $brace_count++;
5268 }
5269
5270
5271 # count close braces
5272 #
5273 if ($line =~ /}/) {
5274 $brace_count--;
5275
5276 # leaving <plugin>_init() function...
5277 if ($brace_count == 0) {
5278 close(FILE);
5279 next PLUGIN;
5280 }
5281
5282 }
5283
5284
5285 # throw away lines that are not exactly one "brace set" deep
5286 #
5287 if ($brace_count > 1) {
5288 next;
5289 }
5290
5291
5292 # also not interested in lines that are not
5293 # hook registration points
5294 #
5295 if ($line !~ /^\s*\$squirrelmail_plugin_hooks/i) {
5296 next;
5297 }
5298
5299
5300 # if $line does not have an ending semicolon,
5301 # we need to recursively read in subsequent
5302 # lines until we find one
5303 while ( $line !~ /;\s*$/ ) {
5304 $line =~ s/[\n\r]\s*$//;
5305 $line .= <FILE>;
5306 }
5307
5308
5309 $line =~ s/^\s+//;
5310 $line =~ s/^\$//;
5311 $var = $line;
5312
5313 $var =~ s/=/EQUALS/;
5314 if ( $var =~ /^([a-z])/i ) {
5315 @options = split ( /\s*EQUALS\s*/, $var );
5316 $options[1] =~ s/[\n\r]//g;
5317 $options[1] =~ s/[\'\"];\s*$//;
5318 $options[1] =~ s/;$//;
5319 $options[1] =~ s/^[\'\"]//;
5320 # de-escape escaped strings
5321 $options[1] =~ s/\\'/'/g;
5322 $options[1] =~ s/\\\\/\\/g;
5323
5324 if ( $options[0] =~ /^squirrelmail_plugin_hooks\s*\[\s*['"]([a-z0-9 \/._*-]+)['"]\s*\]\s*\[\s*['"]([0-9a-z._-]+)['"]\s*\]/i ) {
5325 $hook_name = $1;
5326 $hooked_plugin_name = $2;
5327 # Note: if we wanted to stop plugins from registering
5328 # a *different* plugin on a hook, we could catch
5329 # it here, however this has actually proven to be
5330 # a useful *feature*
5331 #if ($hooked_plugin_name ne $plugins[$ct]) {
5332 # print "...plugin is tring to hook in under different name...\n";
5333 #}
5334
5335 #FIXME: do we want to count the number of hook registrations for each plugin and warn if a plugin doesn't have any?
5336 # hook registration has been found!
5337 if ($verbose) {
5338 if ($hooked_plugin_name ne $plugins[$ct]) {
5339 print " registering on hook \"" . $hook_name . "\" (as \"$hooked_plugin_name\" plugin)\n";
5340 } else {
5341 print " registering on hook \"" . $hook_name . "\"\n";
5342 }
5343 }
5344 $line =~ s/ {2,}/ /g;
5345 $line =~ s/=/\n =/;
5346 print HOOKFILE "\$$line";
5347
5348 }
5349
5350 }
5351
5352 }
5353 close(FILE);
5354
5355 } else {
5356 print "\n";
5357 print "WARNING:\n";
5358 print "The file \"$setup_file\" was not found.\n";
5359 print "The plugin \"" . $plugins[$ct];
5360 print "\" will not be activated until you fix this.\n";
5361 print "\nPress enter to continue";
5362 $ctu = <STDIN>;
5363 print "\n";
5364 next;
5365 }
5366
5367 }
5368
5369 print HOOKFILE "\n\n";
5370 close(HOOKFILE);
5371 # if ($verbose) {
5372 print "\nDone activating plugins; registration data saved in plugin_hooks.php\n\n";
5373 # }
5374
5375 } else {
5376
5377 print "\n";
5378 print "WARNING:\n";
5379 print "The file \"plugin_hooks.php\" was not able to be written to.\n";
5380 print "No plugins will be activated until you fix this.\n";
5381 print "\nPress enter to continue";
5382 $ctu = <STDIN>;
5383 print "\n";
5384
5385 }
5386
5387 }