Added Previous and Next for digest parts. Let me know if it works okay.
[squirrelmail.git] / config / conf.pl
index 7b983e33c1e34e68ce0460198d18eafb8256e0bc..b981d6a4db3a7c443e72431818146d9082daecee 100755 (executable)
@@ -14,9 +14,9 @@ $conf_pl_version = "1.2.0";
 # Perl since at least 5.003_7, and nobody sane runs anything
 # before that, but just in case.
 ############################################################
-
+my $dir;
 if ( eval q{require "File/Basename.pm"} ) {
-    my $dir = File::Basename::dirname($0);
+    $dir = File::Basename::dirname($0);
     chdir($dir);
 }
 
@@ -31,6 +31,14 @@ if ( defined( $ENV{'PATH_INFO'} )
     exit;
     }
 
+############################################################
+# If we got here, use Cwd to get the full directory path
+# (the Basename stuff above will sometimes return '.' as
+# the base directory, which is not helpful here). 
+############################################################
+use Cwd;
+$dir = cwd();
+
 ############################################################              
 # First, lets read in the data already in there...
 ############################################################              
@@ -149,7 +157,7 @@ if ( -e "config.php" ) {
 # Read and parse the current configuration file
 # (either config.php or config_default.php).
 while ( $line = <FILE> ) {
-    $line =~ s/^\s+//;
+    $line =~ s/^\s+//; 
     $line =~ s/^\$//;
     $var = $line;
 
@@ -168,7 +176,7 @@ while ( $line = <FILE> ) {
             if ( -e "../themes" ) {
                 $options[1] =~ s/^\.\.\/config/\.\.\/themes/;
             }
-            $theme_path[$sub] = $options[1];
+            $theme_path[$sub] = &change_to_rel_path($options[1]);
         } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]NAME['|"]\]/ ) {
             $sub = $options[0];
             $sub =~ s/\]\[['|"]NAME['|"]\]//;
@@ -227,6 +235,8 @@ while ( $line = <FILE> ) {
             $ldap_port[$sub]    = $port;
             $ldap_maxrows[$sub] = $maxrows;
             $ldap_charset[$sub] = $charset;
+        } elsif ( $options[0] =~ /^(data_dir|attachment_dir|theme_css|org_logo|signout_page)$/ ) {
+            ${ $options[0] } = &change_to_rel_path($options[1]);
         } else {
             ${ $options[0] } = $options[1];
         }
@@ -284,6 +294,15 @@ if ( !$noselect_fix_enable ) {
 if ( !$frame_top ) {
     $frame_top = "_top";
 }
+
+if ( !$provider_uri ) {
+    $provider_uri = "http://www.squirrelmail.org/";
+}
+
+if ( !$provider_name ) {
+    $provider_name = "SquirrelMail";
+}
+
 if ( !$edit_identity ) {
     $edit_identity = "true";
 }
@@ -299,7 +318,9 @@ if ( !$allow_server_sort ) {
 if ( !$uid_support ) {
     $uid_support = 'true';
 }
-
+if ( !$no_list_for_subscribe ) {
+    $no_list_for_subscribe = 'false';
+}
 if ( !$allow_charset_search ) {
     $allow_charset_search = 'true';
 }
@@ -371,6 +392,9 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print "5.  Signout Page           : $WHT$signout_page$NRM\n";
         print "6.  Default Language       : $WHT$squirrelmail_default_language$NRM\n";
         print "7.  Top Frame              : $WHT$frame_top$NRM\n";
+        print "8.  Provider link          : $WHT$provider_uri$NRM\n";
+        print "9.  Provider name          : $WHT$provider_name$NRM\n";
+
         print "\n";
         print "R   Return to Main Menu\n";
     } elsif ( $menu == 2 ) {
@@ -574,6 +598,9 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
             elsif ( $command == 5 ) { $signout_page                  = command4(); }
             elsif ( $command == 6 ) { $squirrelmail_default_language = command5(); }
             elsif ( $command == 7 ) { $frame_top                     = command6(); }
+            elsif ( $command == 8 ) { $provider_uri                  = command7(); }
+            elsif ( $command == 9 ) { $provider_name                 = command8(); }
+
         } elsif ( $menu == 2 ) {
             if    ( $command == 1 )  { $domain                 = command11(); }
             elsif ( $command == 2 )  { $imapServerAddress      = command12(); }
@@ -668,8 +695,10 @@ sub command1 {
 sub command2 {
     print "Your organization's logo is an image that will be displayed at\n";
     print "different times throughout SquirrelMail.  This is asking for the\n";
-    print "literal (/usr/local/squirrelmail/images/logo.jpg) or relative\n";
-    print "(../images/logo.jpg) path to your logo.\n";
+    print "literal (/usr/local/squirrelmail/images/logo.png) or relative\n";
+    print "(../images/logo.png) path to your logo.\n";
+    print "Relative paths to files outside the SquirrelMail distribution\n";
+    print "will be converted to their absolute path equivalents in config.php.\n";
     print "\n";
     print "[$WHT$org_logo$NRM]: $WHT";
     $new_org_logo = <STDIN>;
@@ -775,6 +804,37 @@ sub command6 {
     return $new_frame_top;
 }
 
+# Default link to provider
+sub command7 {
+    print "Here you can set the link on the right of the page.\n";
+    print "The default is 'http://www.squirrelmail.org/'\n";
+    print "\n";
+    print "[$WHT$provider_uri$NRM]: $WHT";
+    $new_provider_uri = <STDIN>;
+    if ( $new_provider_uri eq "\n" ) {
+        $new_provider_uri = 'http://www.squirrelmail.org/';
+    } else {
+        $new_provider_uri =~ s/[\r|\n]//g;
+        $new_provider_uri =~ s/^\s+$//g;
+    }
+    return $new_provider_uri;
+}
+
+sub command8 {
+    print "Here you can set the name of the link on the right of the page.\n";
+    print "The default is 'SquirrelMail/'\n";
+    print "\n";
+    print "[$WHT$provider_name$NRM]: $WHT";
+    $new_provider_name = <STDIN>;
+    if ( $new_provider_name eq "\n" ) {
+        $new_provider_name = 'SquirrelMail';
+    } else {
+        $new_provider_name =~ s/[\r|\n]//g;
+        $new_provider_name =~ s/^\s+$//g;
+    }
+    return $new_provider_name;
+}
+
 ####################################################################################
 
 # domain
@@ -1526,6 +1586,8 @@ sub command33a {
     print "are two examples:\n";
     print "  Absolute:    /usr/local/squirrelmail/data/\n";
     print "  Relative:    ../data/\n";
+    print "Relative paths to directories outside of the SquirrelMail distribution\n";
+    print "will be converted to their absolute path equivalents in config.php.\n";
     print "\n";
 
     print "[$WHT$data_dir$NRM]: $WHT";
@@ -1558,6 +1620,8 @@ sub command33b {
     print "      lying around there for too long.\n";
     print "  3.  It should probably be another directory than the data\n";
     print "      directory specified in option 3.\n";
+    print "Relative paths to directories outside of the SquirrelMail distribution\n";
+    print "will be converted to their absolute path equivalents in config.php.\n";
     print "\n";
 
     print "[$WHT$attachment_dir$NRM]: $WHT";
@@ -1973,6 +2037,9 @@ sub command42 {
     print "\n";
     print "To clear out an existing value, just type a space for the input.\n";
     print "\n";
+    print "Relative links to files outside the SquirrelMail distribution\n";
+    print "will be converted to their absolute path equivalents in config.php.\n";
+    print "\n";
     print "[$WHT$theme_css$NRM]: $WHT";
     $new_theme_css = <STDIN>;
 
@@ -2289,7 +2356,7 @@ sub save_data {
        # string
         print CF "\$org_name      = \"$org_name\";\n";
         # string
-       print CF "\$org_logo      = '$org_logo';\n";
+       print CF "\$org_logo      = " . &change_to_SM_path($org_logo) . ";\n";
         $org_logo_width |= 0;
         $org_logo_height |= 0;
        # string
@@ -2299,11 +2366,17 @@ sub save_data {
        # string that can contain variables.
         print CF "\$org_title     = \"$org_title\";\n";
        # string
-        print CF "\$signout_page  = '$signout_page';\n";
+        print CF "\$signout_page  = " . &change_to_SM_path($signout_page) . ";\n";
        # string
         print CF "\$frame_top     = '$frame_top';\n";
         print CF "\n";
 
+        print CF "\$provider_uri     = '$provider_uri';\n";
+        print CF "\n";
+
+        print CF "\$provider_name     = '$provider_name';\n";
+        print CF "\n";
+
        # string that can contain variables
         print CF "\$motd = \"$motd\";\n";
         print CF "\n";
@@ -2380,9 +2453,9 @@ sub save_data {
        # string
         print CF "\$default_charset          = '$default_charset';\n";
        # string
-        print CF "\$data_dir                 = '$data_dir';\n";
+        print CF "\$data_dir                 = " . &change_to_SM_path($data_dir) . ";\n";
        # string that can contain a variable
-        print CF "\$attachment_dir           = \"$attachment_dir\";\n";
+        print CF "\$attachment_dir           = " . &change_to_SM_path($attachment_dir) . ";\n";
        # integer
         print CF "\$dir_hash_level           = $dir_hash_level;\n";
        # string
@@ -2416,12 +2489,12 @@ sub save_data {
         print CF "\n";
 
        # strings
-        print CF "\$theme_css = '$theme_css';\n";
+        print CF "\$theme_css = " . &change_to_SM_path($theme_css) . ";\n";
        if ( $theme_default eq '' ) { $theme_default = '0'; }
         print CF "\$theme_default = $theme_default;\n";
 
         for ( $count = 0 ; $count <= $#theme_name ; $count++ ) {
-            print CF "\$theme[$count]['PATH'] = '$theme_path[$count]';\n";
+            print CF "\$theme[$count]['PATH'] = " . &change_to_SM_path($theme_path[$count]) . ";\n";
             print CF "\$theme[$count]['NAME'] = '$theme_name[$count]';\n";
         }
         print CF "\n";
@@ -2478,7 +2551,7 @@ sub save_data {
        # string
         print CF "\$prefs_val_field = '$prefs_val_field';\n";
        # boolean
-       print CF "\$no_list_for_subscribe = '$no_list_for_subscribe';\n";
+       print CF "\$no_list_for_subscribe = $no_list_for_subscribe;\n";
         print CF "\n";
 
         print CF "/**\n";
@@ -2617,3 +2690,68 @@ sub set_defaults {
     print "\nPress any key to continue...";
     $tmp = <STDIN>;
 }
+
+############################################################
+# This subroutine corrects relative paths to ensure they
+# will work within the SM space. If the path falls within
+# the SM directory tree, the SM_PATH variable will be 
+# prepended to the path, if not, then the path will be
+# converted to an absolute path.
+############################################################
+sub change_to_SM_path() {
+    my ($old_path) = @_;
+    my $new_path = '';
+    my @rel_path;
+    my @abs_path;
+    my $subdir;
+
+    # If the path is absolute, don't bother.
+    return "\'" . $old_path . "\'"  if ( $old_path eq '');
+    return "\'" . $old_path . "\'"  if ( $old_path =~ /^\// );
+    return $old_path                if ( $old_path =~ /^SM_PATH/ );
+
+    # For relative paths, split on '../'
+    @rel_path = split(/\.\.\//, $old_path);
+
+    if ( $#rel_path > 1 ) {
+        # more than two levels away. Make it absolute.
+        @abs_path = split(/\//, $dir);
+        foreach $subdir (@rel_path) {
+            if ($subdir eq '') {
+                pop @abs_path;
+            } else {
+                push @abs_path, $subdir;
+            }
+        }
+        foreach $subdir (@abs_path) {
+            $new_path .= $subdir . '/';
+        }
+    } elsif ( $#rel_path > 0 ) {
+        # it's within the SM tree, prepend SM_PATH
+        $new_path = $old_path;
+        $new_path =~ s/^\.\.\//SM_PATH . \'/;
+        $new_path .= '\'';
+    } else {
+        # Last, it's a relative path without any leading '.'
+        # Prepend SM_PATH  (no substitution required)
+        $new_path = "SM_PATH . \'" . $old_path . "\'";
+    }
+
+  return $new_path;
+}
+
+sub change_to_rel_path() {
+    my ($old_path) = @_;
+    my $new_path = '';
+
+    return $old_path if ( $old_path eq '');
+    return $old_path if ( $old_path =~ /^\// );
+    return $old_path if ( $old_path =~ /^\.\./ );
+
+    if ( $old_path =~ /^SM_PATH/ ) {
+        $new_path = $old_path;
+        $new_path =~ s/^SM_PATH . \'/\.\.\//;
+    }
+
+    return $new_path;
+}