RoundCube Webmail
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | This file is part of the Roundcube Webmail client |
  6. | |
  7. | Copyright (C) The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Bulk-change settings stored in user preferences |
  15. +-----------------------------------------------------------------------+
  16. | Author: Thomas Bruederli <roundcube@gmail.com> |
  17. +-----------------------------------------------------------------------+
  18. */
  19. define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
  20. require_once INSTALL_PATH.'program/include/clisetup.php';
  21. function print_usage()
  22. {
  23. print "Usage: moduserprefs.sh [options] pref-name [pref-value]\n";
  24. print "Options:\n";
  25. print " --user=user-id User ID in local database\n";
  26. print " --config=path Location of additional configuration file\n";
  27. print " --delete Unset the given preference\n";
  28. print " --type=type Pref-value type: int, bool, string\n";
  29. }
  30. // get arguments
  31. $args = rcube_utils::get_opt([
  32. 'u' => 'user',
  33. 'd' => 'delete:bool',
  34. 't' => 'type',
  35. 'c' => 'config',
  36. ]);
  37. if (empty($_SERVER['argv'][1]) || $_SERVER['argv'][1] == 'help') {
  38. print_usage();
  39. exit;
  40. }
  41. else if (empty($args[0]) || (empty($args[1]) && empty($args['delete']))) {
  42. print "Missing required parameters.\n";
  43. print_usage();
  44. exit;
  45. }
  46. $pref_name = trim($args[0]);
  47. $pref_value = !empty($args['delete']) ? null : trim($args[1]);
  48. if ($pref_value === null) {
  49. $args['type'] = null;
  50. }
  51. if (!empty($args['config'])) {
  52. $rcube = rcube::get_instance();
  53. $rcube->config->load_from_file($args['config']);
  54. }
  55. $type = isset($args['type']) ? $args['type'] : null;
  56. $user = isset($args['user']) ? $args['user'] : null;
  57. rcmail_utils::mod_pref($pref_name, $pref_value, $user, $type);