database.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  20. #============================================================================
  21. from pwman.util.crypto import CryptoEngine
  22. class DatabaseException(Exception):
  23. pass
  24. class Database(object):
  25. def __init__(self):
  26. self._filtertags = []
  27. def open(self):
  28. """
  29. Open the database, by calling the _open method of the
  30. class inherited for the specific database.
  31. When done validation that the file is OK, check if it has
  32. encryption key, by calling
  33. enc = CryptoEngine.get()
  34. key = self.loadkey()
  35. """
  36. self._open()
  37. enc = CryptoEngine.get()
  38. key = self.loadkey()
  39. if key is not None:
  40. enc.set_cryptedkey(key)
  41. else:
  42. #self.changepassword()
  43. self.get_user_password()
  44. def close(self):
  45. pass
  46. def get_user_password(self):
  47. """
  48. get the databases password from the user
  49. """
  50. enc = CryptoEngine.get()
  51. newkey = enc.changepassword()
  52. return self.savekey(newkey)
  53. def changepassword(self):
  54. """
  55. Change the databases password.
  56. """
  57. enc = CryptoEngine.get()
  58. newkey = enc.changepassword()
  59. return self.savekey(newkey)
  60. def listtags(self, all=False):
  61. pass
  62. def currenttags(self):
  63. return self._filtertags
  64. def filter(self, tags):
  65. for tag in tags:
  66. if not (tag in self._filtertags):
  67. self._filtertags.append(tag)
  68. def clearfilter(self):
  69. self._filtertags = []
  70. def getnodes(self, ids):
  71. pass
  72. def addnodes(self, nodes):
  73. pass
  74. def editnode(self, id, node):
  75. pass
  76. def removenodes(self, nodes):
  77. pass
  78. def listnodes(self):
  79. pass
  80. def savekey(self, key):
  81. pass
  82. def loadkey(self):
  83. pass