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