Files
FileRise/app.py
Sergey Svinolobov 2ccb8f55fe initial commit
2024-06-24 16:02:24 -04:00

26 lines
773 B
Python

from flask import Flask, request, jsonify
import subprocess
app = Flask(__name__)
def authenticate(username, password):
command = f"echo {password} | su -c 'whoami' {username}"
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)
return result.stdout.strip() == username
except subprocess.CalledProcessError:
return False
@app.route('/auth', methods=['POST'])
def auth():
data = request.json
username = data.get('username')
password = data.get('password')
if authenticate(username, password):
return jsonify({"authenticated": True}), 200
else:
return jsonify({"authenticated": False}), 401
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7000)