app.py
from flask import Flask from flask import request import subprocess app = Flask('flaskshell') @app.route('/create') def get_status(): command_ls = "touch fichero_touch" try: result_ls = subprocess.check_output( [command_ls], shell=True) except Exception as e: print (e) return 'Fail' return 'Success' if __name__ == '__main__': app.run()
levantamos el servidor:
python app.py
Si lanzamos este comando, ejecuta el comando, en este caso fichero_touch
curl http://127.0.0.1:5000/create
app_post.py
from flask import Flask from flask import request import subprocess app = Flask('flaskshell') @app.route('/usuario' , methods = ['POST']) def get_variables(): fichero=request.form.get('fichero') command = "touch " + fichero try: result_ls = subprocess.check_output( [command], shell=True) except Exception as e: print (e) return result_ls return 'Success' if __name__ == '__main__': app.run()
Levantamos el servidor:
python3 app_post.py
Si ejecutamos este comando, nos crea el fichero que le pasemos en la variable fichero, en este caso fichero_prueba.txt
curl -X POST http://127.0.0.1:5000/usuario -d "fichero=fichero_prueba.txt"
app_post.py
from flask import Flask from flask import request import subprocess app = Flask('flaskshell') @app.route('/usuario' , methods = ['POST']) def get_variables(): user=request.form.get('user') password=request.form.get('password') command = 'radtest ' + user + ' ' + password + ' ' + '10.103.0.6 0 testing123-1' print (command) try: result_ls = subprocess.check_output( [command], shell=True) except Exception as e: print (e) return result_ls return 'Success' if __name__ == '__main__': app.run()
Levantamos el servidor:
python3 app_post.py
Si ejecutamos este comando hace un login contra servidor radius con user bob y password hello:
curl -X POST http://127.0.0.1:5000/usuario -d "user=bob&password=hello"
Escuchar en todas las ips:
app.run(host= '0.0.0.0')