print "The file \"config/config.php\" was found, but you don't\n";
print "have rights to read it.\n";
print "\n";
- print "Press any key to continue";
+ print "Press enter to continue";
$ctu = <STDIN>;
exit;
}
$smtp_sitewide_user = '' if ( !$smtp_sitewide_user );
$smtp_sitewide_pass = '' if ( !$smtp_sitewide_pass );
$icon_theme_def = '' if ( !$icon_theme_def );
+$disable_plugins = 'false' if ( !$disable_plugins );
+$disable_plugins_user = '' if ( !$disable_plugins_user );
if ( $ARGV[0] eq '--install-plugin' ) {
print "Activating plugin " . $ARGV[1] . "\n";
@plugins = @newplugins;
save_data();
exit(0);
+} elsif ( $ARGV[0] eq '--update-plugins' or $ARGV[0] eq '-u') {
+ build_plugin_hook_array();
+ exit(0);
+} elsif ( $ARGV[0] eq '--help' or $ARGV[0] eq '-h') {
+ print "SquirrelMail Configuration Script\n";
+ print "Usage:\n";
+ print " * No arguments: initiates the configuration dialog\n";
+ print " * --install-plugin <plugin> : activates the specified plugin\n";
+ print " * --remove-plugin <plugin> : deactivates the specified plugin\n";
+ print " * --update-plugins , -u : rebuilds plugin_hooks.php according\n";
+ print " to plugins activated in config.php\n";
+ print " * --help , -h : Displays this help\n";
+ print "\n";
+ exit(0);
}
#####################################################################################
print "\n";
print "R Return to Main Menu\n";
} elsif ( $menu == 8 ) {
- print $WHT. "Plugins\n" . $NRM;
+ if (lc($disable_plugins) eq 'true' && $disable_plugins_user ne '') {
+ print $WHT. "Plugins (WARNING: All plugins are currently disabled\n for the user \"$disable_plugins_user\"!)\n" . $NRM;
+ } elsif (lc($disable_plugins) eq 'true') {
+ print $WHT. "Plugins (WARNING: All plugins are currently disabled!)\n" . $NRM;
+ } else {
+ print $WHT. "Plugins\n" . $NRM;
+ }
print " Installed Plugins\n";
$num = 0;
for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
closedir DIR;
print "\n";
+ if (lc($disable_plugins) eq 'true' && $disable_plugins_user ne '') {
+ print "E Enable active plugins (all plugins currently\n disabled for the user \"$disable_plugins_user\")\n";
+ } elsif (lc($disable_plugins) eq 'true') {
+ print "E Enable active plugins (all plugins currently\n disabled)\n";
+ } else {
+ print "D Disable all plugins\n";
+ }
+ print "U Set the user for whom plugins can be disabled\n";
print "R Return to Main Menu\n";
} elsif ( $menu == 9 ) {
print $WHT. "Database\n" . $NRM;
} elsif ( $menu == 7 ) {
if ( $command == 1 ) { $motd = command71(); }
} elsif ( $menu == 8 ) {
- if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
+ if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
+ elsif ( $command eq "u" ) { $disable_plugins_user = command82(); }
+ elsif ( $command eq "d" ) { $disable_plugins = 'true'; }
+ elsif ( $command eq "e" ) { $disable_plugins = 'false'; }
} elsif ( $menu == 9 ) {
if ( $command == 1 ) { $addrbook_dsn = command91(); }
elsif ( $command == 2 ) { $addrbook_table = command92(); }
}
} else {
print "Invalid input. You must set username used for SMTP authentication.\n";
- print "Click any key to continue\n";
+ print "Click enter to continue\n";
$tmp = <STDIN>;
}
} else {
print "Invalid input\n";
- print "Click any key to continue\n";
+ print "Click enter to continue\n";
$tmp = <STDIN>;
}
}
return @plugins;
}
+# disable_plugins_user
+sub command82 {
+ print "When all active plugins are disabled, they can be disabled only\n";
+ print "for the one user named here. If left blank, plugins will be\n";
+ print "disabled for ALL users. This setting has no effect if plugins\n";
+ print "are not disabled.\n";
+ print "\n";
+ print "This must be the exact IMAP login name for the desired user.\n";
+ print "\n";
+ print "[$WHT$disable_plugins_user$NRM]: $WHT";
+ $new_disable_plugins_user = <STDIN>;
+ if ( $new_disable_plugins_user eq "\n" ) {
+ $new_disable_plugins_user = $disable_plugins_user;
+ } else {
+ $new_disable_plugins_user =~ s/[\r\n]//g;
+ }
+ return $new_disable_plugins_user;
+}
+
################# FOLDERS ###################
# default_folder_prefix
print "Deleting folders will bypass the trash folder and be immediately deleted\n\n";
print "If this is not the correct value for your server,\n";
print "please use option D on the Main Menu to configure your server correctly.\n\n";
- print "Press any key to continue...\n";
+ print "Press enter to continue...\n";
$new_delete = <STDIN>;
$delete_folder = 'true';
} else {
# string
print CF "\$config_location_base = '$config_location_base';\n";
print CF "\n";
+ # boolean
+ print CF "\$disable_plugins = $disable_plugins;\n";
+ # string
+ print CF "\$disable_plugins_user = '$disable_plugins_user';\n";
+ print CF "\n";
# all plugins are strings
for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
close CF;
print "Data saved in config.php\n";
+
+ build_plugin_hook_array();
+
} else {
print "Error saving config.php: $!\n";
}
if ($folder_name =~ /[\x80-\xFFFF]/) {
print "Folder name contains 8bit characters. Configuration utility requires\n";
print "UTF7-IMAP encoded folder names.\n";
- print "Press any key to continue...";
+ print "Press enter to continue...";
my $tmp = <STDIN>;
return 0;
} elsif ($folder_name =~ /[&\*\%]/) {
$string =~ s/\'/\\'/g;
return $string;
}
+
+# parses the setup.php files for all activated plugins and
+# builds static plugin hooks array so we don't have to load
+# ALL plugins are runtime and build the hook array on every
+# page request
+#
+# hook array is saved in config/plugin_hooks.php
+#
+# Note the $verbose variable at the top of this routine
+# can be set to zero to quiet it down.
+#
+# NOTE/FIXME: we aren't necessarily interested in writing
+# a full-blown PHP parsing engine, so plenty
+# of assumptions are included herein about the
+# coding of the plugin setup files, and things
+# like commented out curly braces or other
+# such oddities can break this in a bad way.
+#
+sub build_plugin_hook_array() {
+
+ $verbose = 1;
+
+ if ($verbose) {
+ print "\n\n";
+ }
+
+ if ( open( HOOKFILE, ">plugin_hooks.php" ) ) {
+ print HOOKFILE "<?php\n";
+ print HOOKFILE "\n";
+
+ print HOOKFILE "/**\n";
+ print HOOKFILE " * SquirrelMail Plugin Hook Registration File\n";
+ print HOOKFILE " * Auto-generated using the configure script, conf.pl\n";
+ print HOOKFILE " */\n";
+ print HOOKFILE "\n";
+ print HOOKFILE "global \$squirrelmail_plugin_hooks;\n";
+ print HOOKFILE "\n";
+
+PLUGIN: for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
+
+ if ($verbose) {
+ print "Activating plugin \"" . $plugins[$ct] . "\"...\n";
+ }
+
+ $setup_file = '../plugins/' . $plugins[$ct] . '/setup.php';
+ if ( -e "$setup_file" ) {
+ # Make sure that file is readable
+ if (! -r "$setup_file") {
+ print "\n";
+ print "WARNING:\n";
+ print "The file \"$setup_file\" was found, but you don't\n";
+ print "have rights to read it. The plugin \"";
+ print $plugins[$ct] . "\" will not be activated until you fix this.\n";
+ print "\nPress enter to continue";
+ $ctu = <STDIN>;
+ print "\n";
+ next;
+ }
+ open( FILE, "$setup_file" );
+ $inside_init_fxn = 0;
+ $brace_count = 0;
+ while ( $line = <FILE> ) {
+
+ # throw away lines until we get to target function
+ #
+ if (!$inside_init_fxn
+ && $line !~ /^\s*function\s*squirrelmail_plugin_init_/i) {
+ next;
+ }
+ $inside_init_fxn = 1;
+
+
+ # count open braces
+ #
+ if ($line =~ /{/) {
+ $brace_count++;
+ }
+
+
+ # count close braces
+ #
+ if ($line =~ /}/) {
+ $brace_count--;
+
+ # leaving <plugin>_init() function...
+ if ($brace_count == 0) {
+ close(FILE);
+ next PLUGIN;
+ }
+
+ }
+
+
+ # throw away lines that are not exactly one "brace set" deep
+ #
+ if ($brace_count > 1) {
+ next;
+ }
+
+
+ # also not interested in lines that are not
+ # hook registration points
+ #
+ if ($line !~ /^\s*\$squirrelmail_plugin_hooks/i) {
+ next;
+ }
+
+
+ # if $line does not have an ending semicolon,
+ # we need to recursively read in subsequent
+ # lines until we find one
+ while ( $line !~ /;\s*$/ ) {
+ $line =~ s/[\n\r]\s*$//;
+ $line .= <FILE>;
+ }
+
+
+ $line =~ s/^\s+//;
+ $line =~ s/^\$//;
+ $var = $line;
+
+ $var =~ s/=/EQUALS/;
+ if ( $var =~ /^([a-z])/i ) {
+ @options = split ( /\s*EQUALS\s*/, $var );
+ $options[1] =~ s/[\n\r]//g;
+ $options[1] =~ s/[\'\"];\s*$//;
+ $options[1] =~ s/;$//;
+ $options[1] =~ s/^[\'\"]//;
+ # de-escape escaped strings
+ $options[1] =~ s/\\'/'/g;
+ $options[1] =~ s/\\\\/\\/g;
+
+ if ( $options[0] =~ /^squirrelmail_plugin_hooks\s*\[\s*['"]([a-z0-9 \/._*-]+)['"]\s*\]\s*\[\s*['"]([0-9a-z._-]+)['"]\s*\]/i ) {
+ $hook_name = $1;
+ $hooked_plugin_name = $2;
+ # Note: if we wanted to stop plugins from registering
+ # a *different* plugin on a hook, we could catch
+ # it here, however this has actually proven to be
+ # a useful *feature*
+ #if ($hooked_plugin_name ne $plugins[$ct]) {
+ # print "...plugin is tring to hook in under different name...\n";
+ #}
+
+#FIXME: do we want to count the number of hook registrations for each plugin and warn if a plugin doesn't have any?
+ # hook registration has been found!
+ if ($verbose) {
+ if ($hooked_plugin_name ne $plugins[$ct]) {
+ print " registering on hook \"" . $hook_name . "\" (as \"$hooked_plugin_name\" plugin)\n";
+ } else {
+ print " registering on hook \"" . $hook_name . "\"\n";
+ }
+ }
+ $line =~ s/ {2,}/ /g;
+ $line =~ s/=/\n =/;
+ print HOOKFILE "\$$line";
+
+ }
+
+ }
+
+ }
+ close(FILE);
+
+ } else {
+ print "\n";
+ print "WARNING:\n";
+ print "The file \"$setup_file\" was not found.\n";
+ print "The plugin \"" . $plugins[$ct];
+ print "\" will not be activated until you fix this.\n";
+ print "\nPress enter to continue";
+ $ctu = <STDIN>;
+ print "\n";
+ next;
+ }
+
+ }
+
+ print HOOKFILE "\n\n";
+ close(HOOKFILE);
+# if ($verbose) {
+ print "\nDone activating plugins; registration data saved in plugin_hooks.php\n\n";
+# }
+
+ } else {
+
+ print "\n";
+ print "WARNING:\n";
+ print "The file \"plugin_hooks.php\" was not able to be written to.\n";
+ print "No plugins will be activated until you fix this.\n";
+ print "\nPress enter to continue";
+ $ctu = <STDIN>;
+ print "\n";
+
+ }
+
+}
+