mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 00:24:00 +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 os.path
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from brmdoor_adduser import addUidAuth
|
from brmdoor_adduser import addUidAuth, addNdefAuth
|
||||||
from create_authenticator_db import createTables
|
from create_authenticator_db import createTables
|
||||||
|
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 3:
|
parser = OptionParser()
|
||||||
print "import_jendasap_cards.py <cards_from_sap.txt> <destination.sqlite>"
|
parser.add_option("-d", "--desfire", dest="use_desfire",
|
||||||
print "This will generate and COMPLETELY OVERWRITE the UID table in destination.sqlite"
|
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"
|
print "This is useful for initial import, but for individual cards use brmdoor_adduser.py"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
destSqliteFname = sys.argv[2]
|
if options.use_desfire:
|
||||||
srcCardsFname = sys.argv[1]
|
destTable = "authorized_desfires"
|
||||||
|
importFunc = addNdefAuth
|
||||||
|
else:
|
||||||
|
destTable = "authorized_uids"
|
||||||
|
importFunc = addUidAuth
|
||||||
|
|
||||||
|
destSqliteFname = args[1]
|
||||||
|
srcCardsFname = args[0]
|
||||||
nickUidList = []
|
nickUidList = []
|
||||||
with file(srcCardsFname) as f:
|
with file(srcCardsFname) as f:
|
||||||
lineNo = 0
|
lineNo = 0
|
||||||
|
@ -35,14 +50,14 @@ if __name__ == "__main__":
|
||||||
conn = sqlite3.connect(destSqliteFname)
|
conn = sqlite3.connect(destSqliteFname)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
if dbExists:
|
if dbExists:
|
||||||
cursor.execute("DELETE FROM authorized_uids")
|
cursor.execute("DELETE FROM %s" % destTable)
|
||||||
else:
|
else:
|
||||||
createTables(cursor)
|
createTables(cursor)
|
||||||
|
|
||||||
for (nick, uid) in nickUidList:
|
for (nick, uid) in nickUidList:
|
||||||
addUidAuth(cursor, uid, nick)
|
importFunc(cursor, uid, nick)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
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