KasperskyLab-TinyCheck/server/frontend/app/blueprints/misc.py

78 lines
2.5 KiB
Python
Raw Permalink Normal View History

2020-11-24 19:45:03 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess as sp
from flask import Blueprint, jsonify
2021-06-03 14:08:34 +02:00
from app.utils import read_config, delete_captures
2021-02-04 11:11:43 +01:00
import re
2021-02-04 15:47:03 +01:00
import sys
import os
2020-11-24 19:45:03 +01:00
misc_bp = Blueprint("misc", __name__)
2021-06-03 14:08:34 +02:00
@misc_bp.route("/delete-captures", methods=["GET"])
def api_delete_captures():
"""
Delete the zombies capture folders (if any)
"""
if delete_captures():
return jsonify({"message": "Captures deleted", "status": True})
else:
return jsonify({"message": "Issue while removing captures", "status": False})
2020-11-24 19:45:03 +01:00
@misc_bp.route("/reboot", methods=["GET"])
def api_reboot():
2021-02-08 16:34:32 +01:00
"""
Reboot the device
2020-11-24 19:45:03 +01:00
"""
if read_config(("frontend", "reboot_option")):
sp.Popen("shutdown -r now", shell=True)
return jsonify({"mesage": "Let's reboot."})
else:
return jsonify({"message": "Option disabled", "status": False})
@misc_bp.route("/quit", methods=["GET"])
def api_quit():
2021-02-08 16:34:32 +01:00
"""
Quit the interface (Chromium browser)
"""
if read_config(("frontend", "quit_option")):
sp.Popen('pkill -INT -f "chromium-browser"', shell=True)
return jsonify({"message": "Let's quit", "status": True})
else:
return jsonify({"message": "Option disabled", "status": False})
@misc_bp.route("/shutdown", methods=["GET"])
def api_shutdown():
2021-02-08 16:34:32 +01:00
"""
Reboot the device
"""
if read_config(("frontend", "shutdown_option")):
sp.Popen("shutdown -h now", shell=True)
return jsonify({"message": "Let's shutdown", "status": True})
else:
return jsonify({"message": "Option disabled", "status": False})
2020-11-24 19:45:03 +01:00
@misc_bp.route("/config", methods=["GET"])
def get_config():
2021-02-08 16:34:32 +01:00
"""
Get configuration keys relative to the GUI
2020-11-24 19:45:03 +01:00
"""
return jsonify({
"virtual_keyboard": read_config(("frontend", "virtual_keyboard")),
"hide_mouse": read_config(("frontend", "hide_mouse")),
"download_links": read_config(("frontend", "download_links")),
"sparklines": read_config(("frontend", "sparklines")),
"quit_option": read_config(("frontend", "quit_option")),
"shutdown_option": read_config(("frontend", "shutdown_option")),
2021-01-22 14:09:03 +01:00
"reboot_option": read_config(("frontend", "reboot_option")),
2021-02-08 16:34:32 +01:00
"iface_out": read_config(("network", "out")),
2021-06-14 10:10:24 +02:00
"user_lang": read_config(("frontend", "user_lang")),
"choose_net": read_config(("frontend", "choose_net"))
2020-11-24 19:45:03 +01:00
})