From d61d33a12addaad1e7e9b5394d5918cf81cdc628 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 1 Jun 2016 20:15:22 +0200 Subject: [PATCH] Fix handling of --delete argument in moduserprefs.sh script (#5296) --- CHANGELOG | 1 + bin/moduserprefs.sh | 4 ++-- bin/update.sh | 2 +- program/lib/Roundcube/rcube_utils.php | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 549bdee7ca8..72a77a2f2a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,7 @@ CHANGELOG Roundcube Webmail - Fix bug where "no body" alert could be displayed when sending mailvelope email - Enigma: Fix keys import from inside of an encrypted message (#5285) - Fix searching by email address in contacts with multiple addresses (#5291) +- Fix handling of --delete argument in moduserprefs.sh script (#5296) RELEASE 1.2.0 ------------- diff --git a/bin/moduserprefs.sh b/bin/moduserprefs.sh index 858d76bce8a..94f9ec29773 100755 --- a/bin/moduserprefs.sh +++ b/bin/moduserprefs.sh @@ -36,7 +36,7 @@ function print_usage() // get arguments $args = rcube_utils::get_opt(array( 'u' => 'user', - 'd' => 'delete', + 'd' => 'delete:bool', 't' => 'type', 'c' => 'config', )); @@ -45,7 +45,7 @@ if ($_SERVER['argv'][1] == 'help') { print_usage(); exit; } -else if (empty($args[0]) || (!isset($args[1]) && !$args['delete'])) { +else if (empty($args[0]) || (empty($args[1]) && empty($args['delete']))) { print "Missing required parameters.\n"; print_usage(); exit; diff --git a/bin/update.sh b/bin/update.sh index ed0d4dbe964..15a4b5725ab 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -24,7 +24,7 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; // get arguments -$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept')); +$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool')); // ask user if no version is specified if (!$opts['version']) { diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 06f4314b7ac..67421f1c98a 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -976,6 +976,16 @@ public static function words_match($haystack, $needle) public static function get_opt($aliases = array()) { $args = array(); + $bool = array(); + + // find boolean (no value) options + foreach ($aliases as $key => $alias) { + if ($pos = strpos($alias, ':')) { + $aliases[$key] = substr($alias, 0, $pos); + $bool[] = $key; + $bool[] = $aliases[$key]; + } + } for ($i=1; $i < count($_SERVER['argv']); $i++) { $arg = $_SERVER['argv'][$i]; @@ -985,10 +995,14 @@ public static function get_opt($aliases = array()) if ($arg[0] == '-') { $key = preg_replace('/^-+/', '', $arg); $sp = strpos($arg, '='); + if ($sp > 0) { $key = substr($key, 0, $sp - 2); $value = substr($arg, $sp+1); } + else if (in_array($key, $bool)) { + $value = true; + } else if (strlen($_SERVER['argv'][$i+1]) && $_SERVER['argv'][$i+1][0] != '-') { $value = $_SERVER['argv'][++$i]; }