nodes.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 = []
  32. self.set_tags(tags)
  33. def dump_edit_to_db(self):
  34. enc = CryptoEngine.get()
  35. dump = ""
  36. dump += "username:"+self._username+"##"
  37. dump += "password:"+self._password+"##"
  38. dump += "url:"+self._url+"##"
  39. dump += "notes:"+self._notes+"##"
  40. dump += "tags:"
  41. tagsloc = ""
  42. for tag in self._tags:
  43. if isinstance(tag, str):
  44. tagsloc += "tag:"+tag.strip()+"**endtag**"
  45. else:
  46. tagsloc += "tag:"+tag.get_name()+"**endtag**"
  47. dump += tagsloc
  48. dump = [dump]
  49. return dump
  50. def dump_to_db(self):
  51. enc = CryptoEngine.get()
  52. dump = ""
  53. dump += "username:"+enc.encrypt(self._username)+"##"
  54. dump += "password:"+enc.encrypt(self._password)+"##"
  55. dump += "url:"+enc.encrypt(self._url)+"##"
  56. dump += "notes:"+enc.encrypt(self._notes)+"##"
  57. dump += "tags:"
  58. tagsloc = ""
  59. for tag in self._tags:
  60. if isinstance(tag, str):
  61. tagsloc += "tag:"+tag.strip()+"**endtag**"
  62. else:
  63. tagsloc += "tag:"+tag.get_name()+"**endtag**"
  64. dump += tagsloc
  65. dump = [dump]
  66. return dump
  67. def get_tags(self):
  68. tags = []
  69. for tag in self._tags:
  70. tags.append(tag)
  71. return tags
  72. def set_tags(self, tags):
  73. """
  74. this method expects a list of tag instances.
  75. hence feed it with them.
  76. fixed! the method parse_node_string in
  77. SQLiteDatabase returns a dictionary,
  78. but a also, Tags instances..."""
  79. self._tags = []
  80. for tag in tags:
  81. self._tags.append(tag)
  82. # self._tags.append(tag._name)
  83. def get_id(self):
  84. return self._id
  85. def set_id(self, id):
  86. self._id = id
  87. def get_username(self):
  88. """
  89. Return the username.
  90. This solution with strip is horribly assuming that
  91. the username does not containg space as the last character.
  92. The same is also true for the password.
  93. """
  94. enc = CryptoEngine.get()
  95. return enc.decrypt(self._username).strip()
  96. def set_username(self, username):
  97. """Set the username."""
  98. enc = CryptoEngine.get()
  99. self._username = enc.encrypt(username)
  100. def get_password(self):
  101. """Return the password."""
  102. enc = CryptoEngine.get()
  103. return enc.decrypt(self._password).strip()
  104. def set_password(self, password):
  105. """Set the password."""
  106. enc = CryptoEngine.get()
  107. self._password = enc.encrypt(password).strip()
  108. def get_url(self):
  109. """Return the URL."""
  110. enc = CryptoEngine.get()
  111. return enc.decrypt(self._url).strip()
  112. def set_url(self, url):
  113. """Set the URL."""
  114. enc = CryptoEngine.get()
  115. self._url = enc.encrypt(url)
  116. def get_notes(self):
  117. """Return the Notes."""
  118. enc = CryptoEngine.get()
  119. return enc.decrypt(self._notes)
  120. def set_notes(self, notes):
  121. """Set the Notes."""
  122. enc = CryptoEngine.get()
  123. self._notes = enc.encrypt(notes)
  124. class Node(object):
  125. def __init__(self, username="", password="", url="",
  126. notes="", tags=[]):
  127. """Initialise everything to null."""
  128. self._id = 0
  129. enc = CryptoEngine.get()
  130. self._username = enc.encrypt(username)
  131. self._password = enc.encrypt(password)
  132. self._url = enc.encrypt(url)
  133. self._notes = enc.encrypt(notes)
  134. self._tags = []
  135. self.set_tags(tags)
  136. def get_tags(self):
  137. tags = []
  138. enc = CryptoEngine.get()
  139. for i in self._tags:
  140. tags.append(enc.decrypt(i))
  141. return tags
  142. def set_tags(self, tags):
  143. self._tags = []
  144. enc = CryptoEngine.get()
  145. for i in tags:
  146. self._tags.append(enc.encrypt(i))
  147. def get_id(self):
  148. return self._id
  149. def set_id(self, id):
  150. self._id = id
  151. def get_username(self):
  152. """Return the username."""
  153. enc = CryptoEngine.get()
  154. return enc.decrypt(self._username)
  155. def set_username(self, username):
  156. """Set the username."""
  157. enc = CryptoEngine.get()
  158. self._username = enc.encrypt(username)
  159. def get_password(self):
  160. """Return the password."""
  161. enc = CryptoEngine.get()
  162. return enc.decrypt(self._password)
  163. def set_password(self, password):
  164. """Set the password."""
  165. enc = CryptoEngine.get()
  166. self._password = enc.encrypt(password)
  167. def get_url(self):
  168. """Return the URL."""
  169. enc = CryptoEngine.get()
  170. return enc.decrypt(self._url)
  171. def set_url(self, url):
  172. """Set the URL."""
  173. enc = CryptoEngine.get()
  174. self._url = enc.encrypt(url)
  175. def get_notes(self):
  176. """Return the Notes."""
  177. enc = CryptoEngine.get()
  178. return enc.decrypt(self._notes)
  179. def set_notes(self, notes):
  180. """Set the Notes."""
  181. enc = CryptoEngine.get()
  182. self._notes = enc.encrypt(notes)