65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
# @author andrealmeida
|
|
|
|
from pie import network_info, measure_temp_info, disk_info, memory_info, shutdown_pie
|
|
|
|
#!flask/bin/python
|
|
from flask import Flask, request, Response, redirect, render_template, url_for, jsonify
|
|
from functools import wraps
|
|
|
|
import json
|
|
|
|
app = Flask(__name__)
|
|
data = {}
|
|
|
|
def check_auth(username, password):
|
|
return username == 'admin' and password == 'admin'
|
|
|
|
def authenticate():
|
|
return Response(
|
|
'Could not verify your access level for that URL.\n'
|
|
'You have to login with proper credentials', 401,
|
|
{'WWW-Authenticate': 'Basic realm="Login Required"'})
|
|
|
|
def requires_auth(f):
|
|
@wraps(f)
|
|
def decorated(*args, **kwargs):
|
|
auth = request.authorization
|
|
if not auth or not check_auth(auth.username, auth.password):
|
|
return authenticate()
|
|
return f(*args, **kwargs)
|
|
return decorated
|
|
|
|
@app.route('/')
|
|
@requires_auth
|
|
def index():
|
|
data = network_info()
|
|
data = measure_temp_info()
|
|
data = disk_info("/")
|
|
data = memory_info()
|
|
return render_template('pie.html', data = data)
|
|
|
|
@app.route('/logout')
|
|
@requires_auth
|
|
def logout():
|
|
return authenticate()
|
|
|
|
@app.route("/readpietojson")
|
|
@requires_auth
|
|
def readpietojson():
|
|
data = network_info()
|
|
data = measure_temp_info()
|
|
data = disk_info("/")
|
|
data = memory_info()
|
|
return jsonify(data);
|
|
|
|
@app.route("/shutdown")
|
|
@requires_auth
|
|
def shutdown():
|
|
shutdown_pie()
|
|
return ;
|
|
|
|
# __main__ #
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", port="5000", debug=False)
|