nodes.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 = ""
  46. dump += "username:"+self._username+"##"
  47. dump += "password:"+self._password+"##"
  48. dump += "url:"+self._url+"##"
  49. dump += "notes:"+self._notes+"##"
  50. dump += "tags:"
  51. tagsloc = ""
  52. for tag in self._tags:
  53. tagsloc += "tag:"+tag.strip()+"**endtag**"
  54. dump += tagsloc
  55. dump = [dump]
  56. return dump
  57. def dump_to_db(self):
  58. enc = CryptoEngine.get()
  59. dump = ""
  60. dump += "username:"+enc.encrypt(self._username)+"##"
  61. dump += "password:"+enc.encrypt(self._password)+"##"
  62. dump += "url:"+enc.encrypt(self._url)+"##"
  63. dump += "notes:"+enc.encrypt(self._notes)+"##"
  64. dump += "tags:"
  65. tagsloc = ""
  66. for tag in self._tags:
  67. tagsloc += "tag:"+tag._name+"**endtag**"
  68. dump += tagsloc
  69. dump = [dump]
  70. return dump
  71. @property
  72. def password(self):
  73. """Get the current password."""
  74. enc = CryptoEngine.get()
  75. return enc.decrypt(self._password).strip()
  76. @property
  77. def username(self):
  78. """Get the current username."""
  79. enc = CryptoEngine.get()
  80. return enc.decrypt(self._username).strip()
  81. @username.setter
  82. def username(self, value):
  83. """Set the username."""
  84. enc = CryptoEngine.get()
  85. self._username = enc.encrypt(value).strip()
  86. @password.setter
  87. def password(self, value):
  88. """Set the Notes."""
  89. enc = CryptoEngine.get()
  90. self._password = enc.encrypt(value).strip()
  91. @property
  92. def tags(self):
  93. enc = CryptoEngine.get()
  94. try:
  95. return [enc.decrypt(tag) for tag in filter(None, self._tags)]
  96. except Exception:
  97. return [tag for tag in filter(None, self._tags)]
  98. @tags.setter
  99. def tags(self, value):
  100. self._tags = [tag for tag in value]
  101. @property
  102. def url(self):
  103. """Get the current url."""
  104. enc = CryptoEngine.get()
  105. return enc.decrypt(self._url).strip()
  106. @url.setter
  107. def url(self, value):
  108. """Set the Notes."""
  109. enc = CryptoEngine.get()
  110. self._url = enc.encrypt(value).strip()
  111. @property
  112. def notes(self):
  113. """Get the current notes."""
  114. enc = CryptoEngine.get()
  115. return enc.decrypt(self._notes).strip()
  116. @notes.setter
  117. def notes(self, value):
  118. """Set the Notes."""
  119. enc = CryptoEngine.get()
  120. self._notes = enc.encrypt(value).strip()
  121. class Node(object): # pragma: no cover
  122. def __init__(self, username="", password="", url="",
  123. notes="", tags=[]):
  124. """Initialise everything to null."""
  125. self._id = 0
  126. enc = CryptoEngine.get()
  127. self._username = enc.encrypt(username)
  128. self._password = enc.encrypt(password)
  129. self._url = enc.encrypt(url)
  130. self._notes = enc.encrypt(notes)
  131. self._tags = []
  132. self.set_tags(tags)
  133. def get_tags(self):
  134. tags = []
  135. enc = CryptoEngine.get()
  136. for i in self._tags:
  137. tags.append(enc.decrypt(i))
  138. return tags
  139. def set_tags(self, tags):
  140. self._tags = []
  141. enc = CryptoEngine.get()
  142. for i in tags:
  143. self._tags.append(enc.encrypt(i))
  144. def get_id(self):
  145. return self._id
  146. def set_id(self, id):
  147. self._id = id
  148. def get_username(self):
  149. """Return the username."""
  150. enc = CryptoEngine.get()
  151. return enc.decrypt(self._username)
  152. def set_username(self, username):
  153. """Set the username."""
  154. enc = CryptoEngine.get()
  155. self._username = enc.encrypt(username)
  156. def get_password(self):
  157. """Return the password."""
  158. enc = CryptoEngine.get()
  159. return enc.decrypt(self._password)
  160. def set_password(self, password):
  161. """Set the password."""
  162. enc = CryptoEngine.get()
  163. self._password = enc.encrypt(password)
  164. def get_url(self):
  165. """Return the URL."""
  166. enc = CryptoEngine.get()
  167. return enc.decrypt(self._url)
  168. def set_url(self, url):
  169. """Set the URL."""
  170. enc = CryptoEngine.get()
  171. self._url = enc.encrypt(url)
  172. def get_notes(self):
  173. """Return the Notes."""
  174. enc = CryptoEngine.get()
  175. return enc.decrypt(self._notes)
  176. def set_notes(self, notes):
  177. """Set the Notes."""
  178. enc = CryptoEngine.get()
  179. self._notes = enc.encrypt(notes)