nodes.py 5.8 KB

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