nodes.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #============================================================================
  20. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  21. #============================================================================
  22. from pwman.util.crypto_engine import CryptoEngine
  23. class NewNode(object):
  24. def __str__(self): # pragma: no cover
  25. enc = CryptoEngine.get()
  26. try:
  27. tags = ', '.join([enc.decrypt(tag).strip() for tag in filter(None,
  28. self._tags)])
  29. except Exception:
  30. tags = ', '.join([tag.strip() for tag in filter(None, self._tags)])
  31. user = enc.decrypt(self._username).strip()
  32. url = enc.decrypt(self._url).strip()
  33. return '{0}@{1}\t{2}'.format(user, url,
  34. tags)
  35. def dump_edit_to_db(self):
  36. dump = u""
  37. try:
  38. dump += u"username:"+self._username.decode()+u"##"
  39. except AttributeError:
  40. dump += u"username:"+self._username+u"##"
  41. try:
  42. dump += u"password:"+self._password.decode()+u"##"
  43. except AttributeError:
  44. dump += u"password:"+self._password+u"##"
  45. try:
  46. dump += u"url:"+self._url.decode()+u"##"
  47. except AttributeError:
  48. dump += u"url:"+self._url+u"##"
  49. try:
  50. dump += u"notes:"+self._notes.decode()+u"##"
  51. except AttributeError:
  52. dump += u"notes:"+self._notes+u"##"
  53. dump += u"tags:"
  54. tagsloc = u""
  55. for tag in self._tags:
  56. if isinstance(tag, str):
  57. tagsloc += u"tag:"+tag.strip()+u"**endtag**"
  58. if isinstance(tag, bytes):
  59. try:
  60. tagsloc += u"tag:"+tag.decode()+u"**endtag**"
  61. except:
  62. tagsloc += u"tag:"+tag+u"**endtag**"
  63. else:
  64. tagsloc += u'tag:'+tag._name+u'**endtag**'
  65. dump += tagsloc
  66. dump = [dump]
  67. return dump
  68. @property
  69. def password(self):
  70. """Get the current password."""
  71. enc = CryptoEngine.get()
  72. return enc.decrypt(self._password).strip()
  73. @property
  74. def username(self):
  75. """Get the current username."""
  76. enc = CryptoEngine.get()
  77. return enc.decrypt(self._username).strip()
  78. @username.setter
  79. def username(self, value):
  80. """Set the username."""
  81. enc = CryptoEngine.get()
  82. self._username = enc.encrypt(value).strip()
  83. @password.setter
  84. def password(self, value):
  85. """Set the Notes."""
  86. enc = CryptoEngine.get()
  87. self._password = enc.encrypt(value).strip()
  88. @property
  89. def tags(self):
  90. enc = CryptoEngine.get()
  91. try:
  92. return [enc.decrypt(tag) for tag in filter(None, self._tags)]
  93. except Exception:
  94. return [tag for tag in filter(None, self._tags)]
  95. @tags.setter
  96. def tags(self, value):
  97. self._tags = [tag for tag in value]
  98. @property
  99. def url(self):
  100. """Get the current url."""
  101. enc = CryptoEngine.get()
  102. return enc.decrypt(self._url).strip()
  103. @url.setter
  104. def url(self, value):
  105. """Set the Notes."""
  106. enc = CryptoEngine.get()
  107. self._url = enc.encrypt(value).strip()
  108. @property
  109. def notes(self):
  110. """Get the current notes."""
  111. enc = CryptoEngine.get()
  112. return enc.decrypt(self._notes).strip()
  113. @notes.setter
  114. def notes(self, value):
  115. """Set the Notes."""
  116. enc = CryptoEngine.get()
  117. self._notes = enc.encrypt(value).strip()