added notification functionality

master
git 2021-02-10 20:57:57 +01:00
parent 529ebba77b
commit c35f39bba5
2 changed files with 16 additions and 2 deletions

View File

@ -1,11 +1,16 @@
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
Flask-Cors==3.0.10
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
mysql-connector-python==8.0.23
protobuf==3.14.0
requests==2.25.1
six==1.15.0
urllib3==1.26.3
wakeonlan==1.1.6
Werkzeug==1.0.1

View File

@ -4,6 +4,7 @@ import configparser
import mysql.connector
import datetime
from wakeonlan import send_magic_packet
import requests
app = Flask(__name__)
@ -26,6 +27,13 @@ def verifyapikey(apikey, config):
return False
def notify(config, message, var):
url = config['url'][message]
url = url.replace('XXXXXX', var)
requests.get(url)
return
@app.route('/wakeup', methods=['POST'])
def wakeup():
if verifyapikey(request.values['apikey'], config):
@ -37,11 +45,12 @@ def wakeup():
cursor.close()
db.close()
send_magic_packet(macaddr[0])
notify(config, 'wol_notify_url', request.values['device_name'])
return jsonify(result='success', timestamp=datetime.datetime.now())
return jsonify(result='wrong api key')
if __name__ == '__main__':
config = configparser.ConfigParser()
config = configparser.ConfigParser(interpolation=None)
config.read('config.ini')
app.run(host='0.0.0.0', debug=True)
app.run(host='0.0.0.0')