mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-07 16:14:01 +02:00
Option to import desfires
This commit is contained in:
parent
7e5f4a3603
commit
374ba4df5d
1 changed files with 24 additions and 9 deletions
|
@ -5,18 +5,33 @@ import os
|
|||
import os.path
|
||||
import sqlite3
|
||||
|
||||
from brmdoor_adduser import addUidAuth
|
||||
from brmdoor_adduser import addUidAuth, addNdefAuth
|
||||
from create_authenticator_db import createTables
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print "import_jendasap_cards.py <cards_from_sap.txt> <destination.sqlite>"
|
||||
print "This will generate and COMPLETELY OVERWRITE the UID table in destination.sqlite"
|
||||
parser = OptionParser()
|
||||
parser.add_option("-d", "--desfire", dest="use_desfire",
|
||||
help="import Desfire table", action="store_true", default=False)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if len(args) < 2:
|
||||
print "import_jendasap_cards.py [--desfire] <cards_from_sap.txt> <destination.sqlite>"
|
||||
print "This will generate and COMPLETELY OVERWRITE the UID/Desfire table in destination.sqlite"
|
||||
print "This is useful for initial import, but for individual cards use brmdoor_adduser.py"
|
||||
sys.exit(1)
|
||||
|
||||
destSqliteFname = sys.argv[2]
|
||||
srcCardsFname = sys.argv[1]
|
||||
if options.use_desfire:
|
||||
destTable = "authorized_desfires"
|
||||
importFunc = addNdefAuth
|
||||
else:
|
||||
destTable = "authorized_uids"
|
||||
importFunc = addUidAuth
|
||||
|
||||
destSqliteFname = args[1]
|
||||
srcCardsFname = args[0]
|
||||
nickUidList = []
|
||||
with file(srcCardsFname) as f:
|
||||
lineNo = 0
|
||||
|
@ -35,14 +50,14 @@ if __name__ == "__main__":
|
|||
conn = sqlite3.connect(destSqliteFname)
|
||||
cursor = conn.cursor()
|
||||
if dbExists:
|
||||
cursor.execute("DELETE FROM authorized_uids")
|
||||
cursor.execute("DELETE FROM %s" % destTable)
|
||||
else:
|
||||
createTables(cursor)
|
||||
|
||||
for (nick, uid) in nickUidList:
|
||||
addUidAuth(cursor, uid, nick)
|
||||
importFunc(cursor, uid, nick)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print "Converted %d nick-uid pairs into authorized_uids table" % (len(nickUidList),)
|
||||
print "Converted %d nick-uid pairs into %s table" % (len(nickUidList), destTable)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue