Fix nfc-list lines

This commit is contained in:
jarjar 2023-05-31 20:37:13 +02:00
parent e6ca31fbec
commit 215187874c

View File

@ -24,7 +24,7 @@ def runCommand(command):
### Partie Flask (Serveur Web)
app = Flask('__name__', static_folder="res")
app.config['DEBUG'] = False
app.config['DEBUG'] = True
# Page principal
@ -52,9 +52,9 @@ def detectBadge():
time.sleep(2)
stdout = stdout.decode("utf-8")
lines = stdout.split('\n')
if "Interface opened" in lines[1]:
if "Interface opened" in lines[0]:
if len(lines) > 6:
badge_type = lines[4].replace(' ', ' ')
badge_type = lines[3].replace(' ', ' ')
if '00 04' in badge_type:
result = {'status': 'OK'}
break
@ -76,11 +76,12 @@ def readBadge():
time.sleep(2)
stdout = stdout.decode("utf-8")
lines = stdout.split('\n')
if "Interface opened" in lines[1]:
print(lines)
if "Interface opened" in lines[0]:
if len(lines) > 6:
badge_type = lines[4].replace(' ', ' ')
badge_type = lines[3].replace(' ', ' ')
if '00 04' in badge_type:
badge_UID = lines[5].replace('UID (NFCID1): ', '').replace(' ', '')
badge_UID = lines[4].replace('UID (NFCID1): ', '').replace(' ', '')
# Si un dump existe déjà pour cet UID et qu'il est complet
if ((os.path.isfile('%s/%s.dmp' % (DUMPS_DIR, badge_UID))) and (os.path.getsize('%s/%s.dmp' % (DUMPS_DIR, badge_UID)))) == 1024:
result = {'status': 'OK', 'UID': badge_UID}
@ -134,9 +135,9 @@ def copyBadge(uid):
time.sleep(2)
stdout = stdout.decode("utf-8")
lines = stdout.split('\n')
if "Interface opened" in lines[1]:
if "Interface opened" in lines[0]:
if len(lines) > 6:
badge_type = lines[4].replace(' ', ' ')
badge_type = lines[3].replace(' ', ' ')
if '00 04' in badge_type:
stdout, stderr, status_code = runCommand('mfoc -P 500 -O %s/new.dmp' % DUMPS_DIR)
time.sleep(2)