Skip to content

Commit

Permalink
Added expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
yoprogramo committed Oct 18, 2021
1 parent c2a389e commit 8b5668d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
24 changes: 20 additions & 4 deletions nomorepass/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def __init__(self,server=None,apikey=None):
self.grantUrl = self.base+"/api/grant.php"
self.pingUrl = self.base+"/api/ping.php"
self.stopped = False
self.expiry = None

def getQrText (self,site):
data = urllib.parse.urlencode({'site': site}).encode("utf-8")
params = {'site': site}
if self.expiry!=None:
params['expiry'] = self.expiry
data = urllib.parse.urlencode(params).encode("utf-8")
req = urllib.request.Request(self.getidUrl,data)
req.add_header('User-Agent', 'NoMorePass-IoT/1.0')
if (self.apikey!=None):
Expand Down Expand Up @@ -85,7 +89,10 @@ def getQrNomorekeys (self,site, user, password, type, extra):
print (body)
if (response["resultado"]=="ok"):
token = response["token"]
param = urllib.parse.urlencode({'site': site}).encode("utf-8")
params = {'site': site}
if self.expiry!=None:
params['expiry'] = self.expiry
param = urllib.parse.urlencode(params).encode("utf-8")
req = urllib.request.Request(self.getidUrl,param)
req.add_header('User-Agent', 'NoMorePass-IoT/1.0')
if (self.apikey!=None):
Expand Down Expand Up @@ -203,7 +210,10 @@ def getQrSend (self,site, user, password, extra):
print (body)
if (response["resultado"]=="ok"):
token = response["token"]
param = urllib.parse.urlencode({'site': site}).encode("utf-8")
params = {'site': site}
if self.expiry!=None:
params['expiry'] = self.expiry
param = urllib.parse.urlencode(params).encode("utf-8")
req = urllib.request.Request(self.getidUrl,param)
req.add_header('User-Agent', 'NoMorePass-IoT/1.0')
if (self.apikey!=None):
Expand Down Expand Up @@ -277,7 +287,10 @@ def sendRemotePassToDevice (self,cloud,deviceid,secret,username,password):
if cloudurl==None:
cloudurl = "https://api.nmkeys.com/extern/send_ticket"
token = secret
param = urllib.parse.urlencode({'site': 'Send remote pass'}).encode("utf-8")
params = {'site': 'Send remote pass'}
if self.expiry!=None:
params['expiry'] = self.expiry
param = urllib.parse.urlencode(params).encode("utf-8")
req = urllib.request.Request(self.getidUrl,param)
req.add_header('User-Agent', 'NoMorePass-IoT/1.0')
if (self.apikey!=None):
Expand Down Expand Up @@ -318,3 +331,6 @@ def sendRemotePassToDevice (self,cloud,deviceid,secret,username,password):
else:
return "error calling getid"

def setExpiry(self, expiry):
self.expiry = expiry

4 changes: 4 additions & 0 deletions testlocal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/env python

from nomorepass.core import NoMorePass
from datetime import datetime
import qrcode

apikey='FREEAPIKEY' # Change by your own nomorepass apikey

nmp = NoMorePass('api.nomorepass.com',apikey)
now = datetime.now()
timestamp = datetime.timestamp(now)+30 # 30 secs expiry
nmp.setExpiry(timestamp)
qrtext = nmp.getQrText ('misitio')
print (qrtext)
img = qrcode.make(qrtext)
Expand Down
14 changes: 11 additions & 3 deletions testnmk.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#!/usr/bin/env python

from nomorepass.core import NoMorePass
from datetime import datetime
import qrcode

apikey='FREEAPIKEY' # Change by your own nomorepass apikey

nmp = NoMorePass('api.nomorepass.com',apikey)
qrtext = nmp.getQrNomorekeys ("TestSoundKey","key","Secret key","SOUNDKEY",{'extra': {'secret': '1234567890123456'}})
now = datetime.now()
timestamp = datetime.timestamp(now)+30 # 30 secs expiry
nmp.setExpiry(timestamp)
qrtext = nmp.getQrNomorekeys ("TestBLEKey","key","12345ABCD","BLEKEY",{'host': 'A0EI3ADYTM', 'extra': {}})
print (qrtext)
img = qrcode.make(qrtext)
img.show()
res = nmp.send()
print(res)
if ('error' in res):
print ("Error: "+res["error"])
else:
print ("Password received")
print ("Please, close the qr window")
if ('reason' in res):
print ("Failed: "+res["reason"])
else:
print ("Password received")
print ("Please, close the qr window")

0 comments on commit 8b5668d

Please sign in to comment.