nodes.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 import CryptoEngine
  23. class NewNode(object):
  24. #def __init__(self, username="", password="", url="", notes="", tags=""):
  25. # """Initialise everything to null."""
  26. #
  27. # self._id = 0
  28. # self._username = username
  29. # self._password = password
  30. # self._url = url
  31. # self._notes = notes
  32. # self._tags = tags
  33. def __str__(self): # pragma: no cover
  34. enc = CryptoEngine.get()
  35. try:
  36. tags = ', '.join([enc.decrypt(tag).strip() for tag in filter(None,
  37. self._tags)])
  38. except Exception:
  39. tags = ', '.join([tag.strip() for tag in filter(None, self._tags)])
  40. user = enc.decrypt(self._username).strip()
  41. url = enc.decrypt(self._url).strip()
  42. return '{0}@{1}\t{2}'.format(user, url,
  43. tags)
  44. def dump_edit_to_db(self):
  45. dump = u""
  46. dump += u"username:"+self._username.decode()+u"##"
  47. dump += u"password:"+self._password.decode()+u"##"
  48. dump += u"url:"+self._url.decode()+u"##"
  49. dump += u"notes:"+self._notes.decode()+u"##"
  50. dump += u"tags:"
  51. tagsloc = u""
  52. for tag in self._tags:
  53. if isinstance(tag, str):
  54. tagsloc += u"tag:"+tag.strip()+u"**endtag**"
  55. else:
  56. tagsloc += u"tag:"+tag._name.decode()+u"**endtag**"
  57. dump += tagsloc
  58. dump = [dump]
  59. return dump
  60. @property
  61. def password(self):
  62. """Get the current password."""
  63. enc = CryptoEngine.get()
  64. return enc.decrypt(self._password).strip()
  65. @property
  66. def username(self):
  67. """Get the current username."""
  68. enc = CryptoEngine.get()
  69. return enc.decrypt(self._username).strip()
  70. @username.setter
  71. def username(self, value):
  72. """Set the username."""
  73. enc = CryptoEngine.get()
  74. self._username = enc.encrypt(value).strip()
  75. @password.setter
  76. def password(self, value):
  77. """Set the Notes."""
  78. enc = CryptoEngine.get()
  79. self._password = enc.encrypt(value).strip()
  80. @property
  81. def tags(self):
  82. enc = CryptoEngine.get()
  83. try:
  84. return [enc.decrypt(tag) for tag in filter(None, self._tags)]
  85. except Exception:
  86. return [tag for tag in filter(None, self._tags)]
  87. @tags.setter
  88. def tags(self, value):
  89. self._tags = [tag for tag in value]
  90. @property
  91. def url(self):
  92. """Get the current url."""
  93. enc = CryptoEngine.get()
  94. return enc.decrypt(self._url).strip()
  95. @url.setter
  96. def url(self, value):
  97. """Set the Notes."""
  98. enc = CryptoEngine.get()
  99. self._url = enc.encrypt(value).strip()
  100. @property
  101. def notes(self):
  102. """Get the current notes."""
  103. enc = CryptoEngine.get()
  104. return enc.decrypt(self._notes).strip()
  105. @notes.setter
  106. def notes(self, value):
  107. """Set the Notes."""
  108. enc = CryptoEngine.get()
  109. self._notes = enc.encrypt(value).strip()
  110. class Node(object): # pragma: no cover
  111. def __init__(self, username="", password="", url="",
  112. notes="", tags=[]):
  113. """Initialise everything to null."""
  114. self._id = 0
  115. enc = CryptoEngine.get()
  116. self._username = enc.encrypt(username)
  117. self._password = enc.encrypt(password)
  118. self._url = enc.encrypt(url)
  119. self._notes = enc.encrypt(notes)
  120. self._tags = []
  121. self.set_tags(tags)
  122. def get_tags(self):
  123. tags = []
  124. enc = CryptoEngine.get()
  125. for i in self._tags:
  126. tags.append(enc.decrypt(i))
  127. return tags
  128. def set_tags(self, tags):
  129. self._tags = []
  130. enc = CryptoEngine.get()
  131. for i in tags:
  132. self._tags.append(enc.encrypt(i))
  133. def get_id(self):
  134. return self._id
  135. def set_id(self, id):
  136. self._id = id
  137. def get_username(self):
  138. """Return the username."""
  139. enc = CryptoEngine.get()
  140. return enc.decrypt(self._username)
  141. def set_username(self, username):
  142. """Set the username."""
  143. enc = CryptoEngine.get()
  144. self._username = enc.encrypt(username)
  145. def get_password(self):
  146. """Return the password."""
  147. enc = CryptoEngine.get()
  148. return enc.decrypt(self._password)
  149. def set_password(self, password):
  150. """Set the password."""
  151. enc = CryptoEngine.get()
  152. self._password = enc.encrypt(password)
  153. def get_url(self):
  154. """Return the URL."""
  155. enc = CryptoEngine.get()
  156. return enc.decrypt(self._url)
  157. def set_url(self, url):
  158. """Set the URL."""
  159. enc = CryptoEngine.get()
  160. self._url = enc.encrypt(url)
  161. def get_notes(self):
  162. """Return the Notes."""
  163. enc = CryptoEngine.get()
  164. return enc.decrypt(self._notes)
  165. def set_notes(self, notes):
  166. """Set the Notes."""
  167. enc = CryptoEngine.get()
  168. self._notes = enc.encrypt(notes)