Skip to content
Snippets Groups Projects
Commit f113c564 authored by Recolic's avatar Recolic :house_with_garden:
Browse files

.add-dockerfile

parent a6ffcb7e
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,3 @@ curl "http://localhost:8080/mO0c7JlqE1n5r/smsget" ...@@ -33,7 +33,3 @@ curl "http://localhost:8080/mO0c7JlqE1n5r/smsget"
curl "http://localhost:8080/mO0c7JlqE1n5r/smsdel" curl "http://localhost:8080/mO0c7JlqE1n5r/smsdel"
``` ```
# pip3 install web.py
#
# Run this program like: python this.py 30801
# Usage: curl "http://localhost:30801/mO0c7JlqE1n5r/smsget"
# Usage: curl "http://localhost:30801/mO0c7JlqE1n5r/smsdel"
# Modified: no telegram notify
from usim800 import sim800
import sys
def sms_get_or_del(get_or_del):
# Param: True for get, False for del
# Return: message
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
if get_or_del:
res_dict = gsm.sms.readAll()
result_str = ""
if len(res_dict) == 0:
result_str = "No SMS on this SIM."
else:
result_str = "SIM <b>17386011111</b><br />"
for k in res_dict:
num, sender, time, body = [res_dict[k][index] for index in [0,2,4,5]]
result_str += '<b>{}</b> {} {} {}<br />'.format(num, sender, time, body)
# with open('/tmp/debug', 'wb+') as f:
# f.write(result_str.encode("utf-8", "ignore"))
return result_str[-4000:] # Max: 4096 chars
else:
gsm.sms.deleteAllReadMsg()
return "Deleted all message on SIM"
def send_666_to_12306():
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
print('Test send 666 to 12306...')
gsm.sms.send('12306','666')
# import json,requests # callback: telegram api
# def telegram_notify(msg):
# url = "https://maker.ifttt.com/trigger/recolxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# payload = {
# "value1": msg
# }
# headers = {
# "Content-Type": "application/json"
# }
# requests.post(url, data=json.dumps(payload), headers=headers)
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, uri):
if not uri.startswith('mO0c7JlqE1n5r'):
return "Wrong API key"
try:
action = uri.split('/')[1].lower()
if action == "smsget":
get_or_del = True
elif action == "smsdel":
get_or_del = False
elif action == "send12306":
send_666_to_12306()
return "Sent 666 to 12306, success"
else:
return "Wrong API usage. Expect smsget/smsdel"
msg = sms_get_or_del(get_or_del)
# telegram_notify(msg)
return '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' + "Done. Result:<br />" + msg
except Exception as e:
raise
# return "API Error: " + str(e)
if __name__ == "__main__":
app.run()
docker/apiserver.py
\ No newline at end of file
# docker image for sms-remote-access
```
docker build -t recolic/sms --build-arg R_SEC_HMSAPI_KEY=$R_SEC_HMSAPI_KEY .
docker run -d --restart always --log-opt max-size=10M --name rsms --device=/dev/ttyUSB0 -p 30801:30801 recolic/sms
```
# pip3 install web.py
#
# Run this program like: python this.py 30801
# Usage: curl "http://localhost:30801/_PLACEHOLDER_APIKEY_/smsget"
# Usage: curl "http://localhost:30801/_PLACEHOLDER_APIKEY_/smsdel"
# Modified: no telegram notify
from usim800 import sim800
import sys
def sms_get_or_del(get_or_del):
# Param: True for get, False for del
# Return: message
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
if get_or_del:
res_dict = gsm.sms.readAll()
result_str = ""
if len(res_dict) == 0:
result_str = "No SMS on this SIM."
else:
result_str = "SIM <b>17386011111</b><br />"
for k in res_dict:
num, sender, time, body = [res_dict[k][index] for index in [0,2,4,5]]
result_str += '<b>{}</b> {} {} {}<br />'.format(num, sender, time, body)
# with open('/tmp/debug', 'wb+') as f:
# f.write(result_str.encode("utf-8", "ignore"))
return result_str[-4000:] # Max: 4096 chars
else:
gsm.sms.deleteAllReadMsg()
return "Deleted all message on SIM"
def send_666_to_12306():
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
print('Test send 666 to 12306...')
gsm.sms.send('12306','666')
# import json,requests # callback: telegram api
# def telegram_notify(msg):
# url = "https://maker.ifttt.com/trigger/recolxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# payload = {
# "value1": msg
# }
# headers = {
# "Content-Type": "application/json"
# }
# requests.post(url, data=json.dumps(payload), headers=headers)
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, uri):
if not uri.startswith('_PLACEHOLDER_APIKEY_'):
return "Wrong API key"
try:
action = uri.split('/')[1].lower()
if action == "smsget":
get_or_del = True
elif action == "smsdel":
get_or_del = False
elif action == "send12306":
send_666_to_12306()
return "Sent 666 to 12306, success"
else:
return "Wrong API usage. Expect smsget/smsdel"
msg = sms_get_or_del(get_or_del)
# telegram_notify(msg)
return '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' + "Done. Result:<br />" + msg
except Exception as e:
raise
# return "API Error: " + str(e)
if __name__ == "__main__":
app.run()
from ubuntu:22.04
label org.opencontainers.image.authors="docker.pub@me.recolic.net"
arg DEBIAN_FRONTEND=noninteractive
arg R_SEC_HMSAPI_KEY=PleaseChangeMe
run apt update && apt install -y python3 python3-pip wget
# For sms-remote-access, requires --device=/dev/ttyUSB0
run pip install web.py usim800
# # For door-watchdog, requires --device=/dev/tty0
# run pip install smartrent pytz
copy apiserver.py /
run sed -i s/_PLACEHOLDER_APIKEY_/${R_SEC_HMSAPI_KEY}/g /apiserver.py
# Download latest version of usim800, not published to pip yet
run wget https://raw.githubusercontent.com/Bhagyarsh/usim800/master/usim800/Sms/sms.py -O /tmp/sms.py && \
find /usr -name sms.py -exec cp /tmp/sms.py '{}' ';'
cmd python3 /apiserver.py 30801
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment