diff --git a/requirements.txt b/requirements.txt index c26e8d7..25559bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/app.py b/src/app.py index caadc29..0a4cfb7 100644 --- a/src/app.py +++ b/src/app.py @@ -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) \ No newline at end of file + app.run(host='0.0.0.0') \ No newline at end of file