Adding plugins on/off switch, which disables plugins completely (optionally for only...
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 16 Nov 2006 12:25:48 +0000 (12:25 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 16 Nov 2006 12:25:48 +0000 (12:25 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11959 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
config/conf.pl
config/config_default.php
include/init.php

index 6e04ac7f0a776ba9493613e03fdcdfd328f84d1c..9c9b99bc5c395860eb474071a00b2926ba4249c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -157,6 +157,8 @@ Version 1.5.2 - CVS
   - Added PHP pspell extension support to squirrelspell plugin.
   - Add CEST and MEST (non-standard) timezone codes for +0200.
   - Add support for SpamAssassin's X-Spam-Status header (#1589520).
   - Added PHP pspell extension support to squirrelspell plugin.
   - Add CEST and MEST (non-standard) timezone codes for +0200.
   - Add support for SpamAssassin's X-Spam-Status header (#1589520).
+  - Added plugin on/off switch, which completely disables all plugins
+    (optionally for one named user, otherwise for all users).
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------
index 894a2b19666a8c2b806e3737e83ca06434f35653..4d6f4972958c47d61e3f723fe5c0766823f11b73 100755 (executable)
@@ -469,6 +469,8 @@ $config_location_base = ''             if ( !$config_location_base );
 $smtp_sitewide_user = ''               if ( !$smtp_sitewide_user );
 $smtp_sitewide_pass = ''               if ( !$smtp_sitewide_pass );
 $icon_theme_def = ''                   if ( !$icon_theme_def );
 $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";
 
 if ( $ARGV[0] eq '--install-plugin' ) {
     print "Activating plugin " . $ARGV[1] . "\n";
@@ -692,7 +694,13 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
         print "\n";
         print "R   Return to Main Menu\n";
     } elsif ( $menu == 8 ) {
         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++ ) {
         print "  Installed Plugins\n";
         $num = 0;
         for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
@@ -726,6 +734,14 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
         closedir DIR;
 
         print "\n";
         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;
         print "R   Return to Main Menu\n";
     } elsif ( $menu == 9 ) {
         print $WHT. "Database\n" . $NRM;
@@ -906,7 +922,10 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
         } elsif ( $menu == 7 ) {
             if ( $command == 1 ) { $motd = command71(); }
         } elsif ( $menu == 8 ) {
         } 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(); }
         } elsif ( $menu == 9 ) {
             if    ( $command == 1 ) { $addrbook_dsn     = command91(); }
             elsif ( $command == 2 ) { $addrbook_table   = command92(); }
@@ -1690,6 +1709,25 @@ sub command81 {
     return @plugins;
 }
 
     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
 ################# FOLDERS ###################
 
 # default_folder_prefix
@@ -4367,6 +4405,11 @@ sub save_data {
         # string
         print CF "\$config_location_base     = '$config_location_base';\n";
         print CF "\n";
         # 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++ ) {
 
         # all plugins are strings
         for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
index 57215877c987d7189ea5d659a3c1bb79ee8fba5d..93b5fdac65cdba12c9e18c60fdc667edbdf04307 100644 (file)
@@ -883,6 +883,18 @@ $motd = "";
 // Add list of enabled plugins here
 
 
 // Add list of enabled plugins here
 
 
+/**
+ * To disable all plugins regardless of any that are installed 
+ * above, turn on $disable_plugins.  To disable them ONLY for 
+ * one user, put that username into $disable_plugins_user.
+ * @global boolean $disable_plugins
+ * @global string $disable_plugins_user
+ * @since 1.5.2
+ */
+$disable_plugins = false;
+$disable_plugins_user = '';
+
+
 /*** Database ***/
 /**
  * Read doc/database.txt in order to get more information
 /*** Database ***/
 /**
  * Read doc/database.txt in order to get more information
index 0d42d40a8c3e9dd03038e28b038e13ea21cdd7f3..d4abef04aeaf6bd6138c513902b32aa87fd138c2 100644 (file)
@@ -226,10 +226,27 @@ $version = '1.5.2 [CVS]';
  */
 $SQM_INTERNAL_VERSION = array(1,5,2);
 
  */
 $SQM_INTERNAL_VERSION = array(1,5,2);
 
+
+/* if plugins are disabled only for one user and 
+ * the current user is NOT that user, turn them
+ * back on
+ */
+sqgetGlobalVar('username',$username,SQ_SESSION);
+if ($disable_plugins && !empty($disable_plugins_user)
+ && $username != $disable_plugins_user) {
+    $disable_plugins = false;
+}
+
+/* remove all plugins if they are disabled */
+if ($disable_plugins) {
+   $plugins = array();
+}
+
+
 /**
  * Include Compatibility plugin if available.
  */
 /**
  * Include Compatibility plugin if available.
  */
-if (file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
+if (!$disable_plugins && file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
     include_once(SM_PATH . 'plugins/compatibility/functions.php');
 
 /**
     include_once(SM_PATH . 'plugins/compatibility/functions.php');
 
 /**
@@ -239,7 +256,7 @@ if (file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
  * and let the hook calls include only the plugins needed.
  */
 $squirrelmail_plugin_hooks = array();
  * and let the hook calls include only the plugins needed.
  */
 $squirrelmail_plugin_hooks = array();
-if (file_exists(SM_PATH . 'config/plugin_hooks.php')) {
+if (!$disable_plugins && file_exists(SM_PATH . 'config/plugin_hooks.php')) {
     require(SM_PATH . 'config/plugin_hooks.php');
 }
 
     require(SM_PATH . 'config/plugin_hooks.php');
 }
 
@@ -423,6 +440,7 @@ switch ($sInitLocation) {
             exit;
         }
 
             exit;
         }
 
+//FIXME: remove next line if the placement of the copy of this line above does not prove to be problematic
         sqgetGlobalVar('username',$username,SQ_SESSION);
         sqgetGlobalVar('authz',$authz,SQ_SESSION);
 
         sqgetGlobalVar('username',$username,SQ_SESSION);
         sqgetGlobalVar('authz',$authz,SQ_SESSION);