mac.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # ============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. # ============================================================================
  17. # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
  18. # ============================================================================
  19. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  20. # ============================================================================
  21. # pylint: disable=I0011
  22. from __future__ import print_function
  23. import time
  24. # all mac os related classes
  25. from pwman.ui.cli import PwmanCli
  26. from pwman.ui import tools
  27. from pwman.util.crypto_engine import CryptoEngine
  28. # pylint: disable=R0904
  29. class PwmanCliMac(PwmanCli):
  30. """
  31. inherit from PwmanCli, override the right functions...
  32. """
  33. def do_copy(self, args):
  34. ids = self._get_ids(args)
  35. if len(ids) > 1:
  36. print("Can only 1 password at a time...")
  37. return None
  38. nodes = self._db.getnodes(ids)
  39. ce = CryptoEngine.get()
  40. for node in nodes:
  41. password = ce.decrypt(node[2])
  42. tools.text_to_mcclipboard(password)
  43. flushtimeout = self.config.get_value('Global', 'cp_timeout')
  44. flushtimeout = flushtimeout or 10
  45. print("erasing in {} sec...".format(flushtimeout))
  46. time.sleep(int(flushtimeout))
  47. tools.text_to_mcclipboard("")
  48. def do_cp(self, args):
  49. self.do_copy(args)
  50. def do_open(self, args):
  51. ids = self._get_ids(args)
  52. if not args:
  53. self.help_open()
  54. return
  55. if len(ids) > 1:
  56. print("Can open only 1 link at a time ...")
  57. return None
  58. ce = CryptoEngine.get()
  59. nodes = self._db.getnodes(ids)
  60. for node in nodes:
  61. url = ce.decrypt(node[3])
  62. if not url.startswith(("http://", "https://")):
  63. url = "https://" + url
  64. tools.open_url(url, macosx=True)
  65. def do_o(self, args):
  66. self.do_open(args)
  67. ##
  68. # Help functions
  69. ##
  70. def help_open(self):
  71. self.usage("open <ID>")
  72. print("Launch default browser with 'open url',\n"
  73. "the url must contain http:// or https://.")
  74. def help_o(self):
  75. self.help_open()
  76. def help_copy(self):
  77. self.usage("copy <ID>")
  78. print("Copy password to Cocoa clipboard using pbcopy")
  79. def help_cp(self):
  80. self.help_copy()