diff --git a/sites/all/modules/munin/README.txt b/sites/all/modules/munin/README.txt
index 217b31f..2eb8beb 100644
--- a/sites/all/modules/munin/README.txt
+++ b/sites/all/modules/munin/README.txt
@@ -1,18 +1,21 @@
-; $Id: README.txt,v 1.1.2.1 2009/10/02 08:58:49 mcgo Exp $
 Munin Drupal plugin
 Author:   McGo (Mirko Haaser)
 Website:  http://drupalist.de
 
+Refactored by thebuckst0p (http://newleafdigital.com) April 2011:
+ - Drush integration instead of DB credentials in scripts
+ - Active plugins saved in settings
+
+
 WHAT IS THIS?
 This module acts as a plugin generator for munin [1]. It uses
 #a gui that lets you choose which information will be shown
-in the statistics. With these information, the module generates
+in the statistics. With this information, the module generates
 a shell script that you can directly use as a plugin for munin
 
 ATTENTION!
-The shell script stores the mysql credentials for your site.
-So you might not want to give every user the permission to
-create settings.
+The shell script requires Drush (http://drupal.org/project/drush) to work.
+Database credentials are NO LONGER STORED in the shell scripts.
 
 INSTALLATION
 1. Drop the module in sites/all/modules/contrib/
@@ -20,14 +23,14 @@ INSTALLATION
 3. If you want to use the defaults, shipped with this module
    enable the munin default module as well.
 4. Go to admin/settings/munin and choose which statistics
-   you want to see in your munin setup later and hit the
-   button
-5. There will be at least one script that is generated for
+   you want to see in your munin setup.
+5. Save, then view the Scripts tab.
+   There will be at least one script that is generated for
    you. If you selected values from different categories,
    you will see one script for each category.
 6. Copy the script and create a file (name doesn't matter)
    in your munin plugins directory. This should be placed
-   in /etc/munin/plugins
+   in /etc/munin/plugins. (Can also be a symlink.)
 7. Make the script executable
 8. Restart the munin-node /etc/init.d/munin-node restart
 9. Wait some minutes (10-20) and check your new statistics
diff --git a/sites/all/modules/munin/munin_api.info b/sites/all/modules/munin/munin_api.info
index c260bfa..f30c62b 100644
--- a/sites/all/modules/munin/munin_api.info
+++ b/sites/all/modules/munin/munin_api.info
@@ -1,4 +1,3 @@
-; $Id: munin_api.info,v 1.1 2009/10/02 08:36:25 mcgo Exp $
 name = Munin API
 description = This module contains the munin monitoring API for generating munin plugin files
 package = Munin
diff --git a/sites/all/modules/munin/munin_api.module b/sites/all/modules/munin/munin_api.module
index 713b66b..fe22312 100644
--- a/sites/all/modules/munin/munin_api.module
+++ b/sites/all/modules/munin/munin_api.module
@@ -1,6 +1,4 @@
 <?php
-// $Id: munin_api.module,v 1.1 2009/10/02 08:36:25 mcgo Exp $
-
 /**
  * @file
  * The munin module API.
@@ -20,12 +18,29 @@ function munin_api_menu() {
   $items['admin/settings/munin'] = array(
     'title' => 'Munin Plugin',
     'description' => "Generate a munin plugin shell script with this gui.",
-    'page callback' => '_munin_api_generate',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('munin_settings_form'),
+    'access arguments' => array('generate munin plugin'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['admin/settings/munin/plugins'] = array(
+    'title' => 'Plugins',
     'access arguments' => array('generate munin plugin'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
   );
+
+  $items['admin/settings/munin/scripts'] = array(
+    'title' => 'Scripts',
+    'page callback' => 'munin_scripts',
+    'access arguments' => array('generate munin plugin'),
+    'type' => MENU_LOCAL_TASK,
+  );
+
   return $items;
 }
 
+
 /**
  * Implementation of hook_theme().
  */
@@ -46,63 +61,64 @@ function munin_api_perm() {
 
 
 /**
- * The page callback to show the generation form
+ * load the plugin definitions
+ *
+ * @param $only_active if TRUE, remove inactive plugins
  */
-function _munin_api_generate() {
-  if (isset($_REQUEST['valid']) && $_REQUEST['valid'] == 1) {
-    $plugins = _munin_api_parse_selection($_REQUEST['plugins']);
-    return theme('munin_api_script', $plugins);
-  }
-  else {
-    return drupal_get_form('_munin_api_generate_form');
+function _munin_plugin_definitions($only_active = FALSE) {
+  $plugins = module_invoke_all('muninplugin');
+  // Let other modules alter the definition.
+  // @todo this should use drupal_alter()!
+  module_invoke_all('muninplugin_alter', &$plugins);
+  
+  if ($only_active) {
+    $plugin_defaults = variable_get('munin_plugins', array());
+
+    foreach ($plugin_defaults as $key => $value) {
+      foreach ($value as $name => $active) {
+        // remove if inactive
+        if ($active != 1) unset($plugins[$key][$name]);
+      }
+      // remove group if none left
+      if (count($plugins[$key]) == 0) unset($plugins[$key]);
+    }
   }
+  
+  return $plugins;
 }
 
-/**
- * The form that helps you generate the shell script
- */
-function _munin_api_generate_form() {
-  $form = array();
-
-  $mapi = _munin_api_render_mapielement();
 
-  $form['configuration'] = $mapi;
-
-  if ($mapi['valid']['#value'] == 1) {
-    $form['control'] = array(
-      '#type' => 'submit',
-      '#value' => t('Generate the script'),
-    );
-  }
-
-  return $form;
-}
 
 /**
- * Calls the munin api hook and returns a fapi array
+ * settings form / page callback
  */
-function _munin_api_render_mapielement() {
-  // Call the API Hooks
-  $plugins = module_invoke_all('muninplugin');
-  // Let other modules alter the definition.
-  module_invoke_all('muninplugin_alter', &$plugins);
+function munin_settings_form() {
+  $form = array();
+  
+  // helper
+  $form['help'] = array(
+    '#value' => '<p>' . t('Save this form, then go to the !scripts tab to copy the shell script code.', 
+        array('!scripts' => l('Scripts', 'admin/settings/munin/scripts'))) . '</p>',
+  );
+  
+  // saved plugin configs [on/off]
+  $plugin_defaults = variable_get('munin_plugins', array());
+  
+  // full plugin definitions
+  $plugins = _munin_plugin_definitions();
 
   if (count($plugins) == 0) {
     $form['message'] = array(
       '#type' => 'markup',
       '#value' => t('There are currently no munin plugin definitions available. Please enable a module that defines some munin plugin configurations.'),
     );
-    $form['valid'] = array(
-      '#type' => 'hidden',
-      '#value' => 0,
-    );
   }
   else {
-    $form['plugins'] = array('#tree' => TRUE);
+    $form['munin_plugins'] = array('#tree' => TRUE);
     foreach($plugins as $category => $definition) {
       // There are some meta elements describing the category
       // All remaining elements are definitions.
-      $form['plugins'][$category] = array(
+      $form['munin_plugins'][$category] = array(
         '#type' => 'fieldset',
         '#title' => $definition['#title'],
         '#description' => $definition['#description'],
@@ -114,143 +130,116 @@ function _munin_api_render_mapielement() {
         // category. Each of them represents an item in the
         // munin graph element. Let the user choose.
         if (drupal_substr($key, 0 ,1) != '#') {
-          $form['plugins'][$category][$key] = array(
+          $form['munin_plugins'][$category][$key] = array(
             '#type' => 'checkbox',
             '#title' => $value['#label'],
             '#description' => $value['#description'],
+            '#default_value' => $plugin_defaults[$category][$key],
           );
         }
       }
     }
-    $form['valid'] = array(
-      '#type' => 'hidden',
-      '#value' => 1,
-    );
   }
-  return $form;
-}
-
-
-/**
- * Parsing the selected plugins
- */
-function _munin_api_parse_selection($values) {
-  $return = array();
-
-  $plugins = module_invoke_all('muninplugin');
-  module_invoke_all('muninplugin_alter', &$plugins);
 
-  foreach ($values as $key => $value) {
-    foreach ($value as $name => $active) {
-      if ($active == 1) {
-        $return[$key][$name] = $plugins[$key][$name];
-      }
-      unset($plugins[$key][$name]);
-    }
-    if (count($return[$key]) > 0) $return[$key]['#meta'] = $plugins[$key];
-  }
-
-  $return['#header']['db'] = _munin_api_decoded_dburl();
-
-  return $return;
+  // drush path
+  $form['munin_drush_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to Drush'),
+    '#default_value' => variable_get('munin_drush_path', 'drush'),
+    '#required' => TRUE,
+  );
+  
+  
+  // go to the scripts after saving
+  $form['#redirect'] = 'admin/settings/munin/scripts';
+  
+  // save settings automatically
+  return system_settings_form($form);
 }
 
-/**
- * Decode the DB url
- */
-function _munin_api_decoded_dburl() {
-  global $db_url;
-  $step1 = explode('@', $db_url);
-
-  $step2 = explode('/',$step1[1]);
-  $host = $step2[0];
-  $database = $step2[1];
-
-  $step3 = explode('//', $step1[0]);
-  $step4 = explode(':', $step3[1]);
-  $user = $step4[0];
-  $pass = $step4[1];
 
-  return array('db_user' => $user, 'db_pass' => $pass, 'db_host' => $host, 'db_dbase' => $database);
-}
 
 /**
- * Renders the file
+ * Theme the generated script(s)
+ *
+ * @param plugins active and flattened plugins
  */
-function _munin_api_renderscript($values) {
-
-}
+function theme_munin_api_script($plugins) {
 
-/**
- * Renders the header of the script
- */
-function _munin_api_renderheader($header, $meta, $values) {
-  $output = '';
+  foreach($plugins as $group_key => $group_values) {
+    if (is_array($group_values)) {    // not group #meta
 
-  foreach ($values as $key => $value) {
-    $configstring .= '<br>'.$key.'.label '.$value['#label'];
-    $configstring .= '<br>'.$key.'.type '.$value['#type'];
-  }
+      $output .= "<br><br><h3>". t('Save this script as !filename in your munin plugins directory (/etc/munin/plugins)', 
+        array('!filename' => 'drupal-' . $group_key . '.sh')) . "</h3>";
 
-  $output .= '<pre>
+      $output .= "<div class='munin_script' id='munin_script_" . $group_key . "'>";
+      
+      // HEADER
+      
+      $output .= '<pre>
 #!/bin/bash
 # Drupal munin plugin - This script was generated by the munin Drupal module.
 
 # Variables
-CONF_MYSQL_USER="'.$header['db']['db_user'].'"
-CONF_MYSQL_PASS="'.$header['db']['db_pass'].'"
-CONF_DATABASE="'.$header['db']['db_dbase'].'"
+DRUSH_CMD="' . variable_get('munin_drush_path', 'drush') . '"
 
 # config settings
 case $1 in
   config)
     cat <<\'EOM\'
-graph_title '.$meta['#title'].'
-graph_vlabel '.$meta['#vlabel'].'
-graph_category Drupal'.$configstring.'
+graph_title ' . $group_values['#title'] . '
+graph_vlabel ' . $group_values['#vlabel'] . '
+graph_category Drupal';
+
+    // info on each plugin in the group
+    foreach ($group_values as $key => $definition) {
+      if (is_array($definition)) {
+        $output .= '<br>' . $key . '.label ' . $definition['#label'];
+        $output .= '<br>' . $key . '.type ' . $definition['#type'];      
+      }
+    }
+
+    $output .= '
 EOM
   exit 0;;
 esac</pre>';
-  return $output;
-}
 
-/**
- * Render a single line of the shell script
- */
-function _munin_api_renderelements($definition) {
-  $line = '';
-
-  foreach ($definition as $key => $value) {
-    $line .= '<pre>
-# Stats for '.$value['#label'].'
-# '.$value['#description'].'
-echo "'.db_prefix_tables($value['#statement']).'" | mysql --user=$CONF_MYSQL_USER --password=$CONF_MYSQL_PASS --database $CONF_DATABASE | tail -n+2 | {
-  read VALUE ; echo "'.$key.'.value $VALUE.00"
+      // each plugin's stats
+      foreach($group_values as $plugin_key => $definition) {
+        if (is_array($definition)) {  // not plugin #meta
+          
+          $output .= '<pre>
+# Stats for ' . $definition['#label'] . '
+# ' . $definition['#description'] . '
+$DRUSH sql-query "' . db_prefix_tables($definition['#statement']) . '" | tail -n+2 | {
+  read VALUE ; echo "' . $plugin_key . '.value $VALUE.00"
 }</pre>';
+        }
+      }
+
+      $output .= "</div>";
+    }
   }
 
-  return $line;
+  return $output;
 }
 
+
 /**
- * Theme the generated script(s)
+ * page callback of rendered scripts
  */
-function theme_munin_api_script($plugins) {
+function munin_scripts() {
+  $output = '';
+  
   drupal_add_css(drupal_get_path('module', 'munin_api').'/munin.css', 'module');
-  $header = $plugins['#header'];
-  unset ($plugins['#header']);
-
-  foreach ($plugins as $key => $value) {
-    $meta = $value['#meta'];
-    unset ($value['#meta']);
-
-    $output .= "<br><br><h3>". t('Save this script as !filename in your munin plugins directory (/etc/munin/plugins)', array('!filename' => 'drupal-'.$key.'.sh'))."</h3>";
-    $output .= "<div class='munin_script' id='munin_script_".$key."'>";
-    $output .= _munin_api_renderheader($header, $meta, $value);
-    $output .= _munin_api_renderelements($value);
-    $output .= "</div>";
-  }
-
-
+  
+  $active_plugins = _munin_plugin_definitions(TRUE);    // only active
+  
+  $output .= '<p>' . t('You can modify the plugins used on the !settings page.', 
+      array('!settings' => l('Settings', 'admin/settings/munin'))) . '</p>';
+  
+  $output .= theme('munin_api_script', $active_plugins);
+  
   return $output;
 }
+
diff --git a/sites/all/modules/munin/munin_default.info b/sites/all/modules/munin/munin_default.info
index b8f627e..7d557cf 100644
--- a/sites/all/modules/munin/munin_default.info
+++ b/sites/all/modules/munin/munin_default.info
@@ -1,4 +1,3 @@
-; $Id: munin_default.info,v 1.1 2009/10/02 08:36:25 mcgo Exp $
 name = Munin Default Plugins
 description = Provides default plugins for the munin monitoring tool
 package = Munin
diff --git a/sites/all/modules/munin/munin_default.module b/sites/all/modules/munin/munin_default.module
index 0e730fa..8f8799b 100644
--- a/sites/all/modules/munin/munin_default.module
+++ b/sites/all/modules/munin/munin_default.module
@@ -1,7 +1,4 @@
 <?php
-
-// $Id: munin_default.module,v 1.1.2.3 2009/10/14 19:39:02 mcgo Exp $
-
 /**
  * @file
  * Default munin plugin configurations
@@ -77,5 +74,3 @@ function munin_default_muninplugin_alter(&$plugins) {
   // This hook is used to alter existing plugins.
 }
 
-
-?>
