|
|
import os |
|
|
import subprocess |
|
|
import time |
|
|
|
|
|
|
|
|
os.environ["DISPLAY"] = ":99" |
|
|
|
|
|
import base64 |
|
|
from flask import Flask, request, jsonify |
|
|
from flask_cors import CORS |
|
|
import pyautogui |
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
CORS(app) |
|
|
|
|
|
SCREEN_WIDTH = 1024 |
|
|
SCREEN_HEIGHT = 768 |
|
|
pyautogui.FAILSAFE = False |
|
|
|
|
|
@app.route('/') |
|
|
def home(): |
|
|
return "Botisbot Cloud PC (Fluxbox Edition) Ready!" |
|
|
|
|
|
@app.route('/snapshot', methods=['GET']) |
|
|
def get_snapshot(): |
|
|
try: |
|
|
|
|
|
|
|
|
filename = "/tmp/screen.jpg" |
|
|
|
|
|
|
|
|
subprocess.run(["scrot", "-z", "-o", "-q", "50", filename], check=True) |
|
|
|
|
|
|
|
|
with open(filename, "rb") as image_file: |
|
|
b64 = base64.b64encode(image_file.read()).decode('utf-8') |
|
|
|
|
|
return jsonify({"screenshot": b64}) |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Snapshot Error: {e}") |
|
|
|
|
|
return jsonify({"error": str(e)}), 500 |
|
|
|
|
|
@app.route('/interact', methods=['POST']) |
|
|
def interact(): |
|
|
data = request.json |
|
|
action = data.get('action') |
|
|
|
|
|
try: |
|
|
if action == 'tap': |
|
|
x = int(data.get('x') * SCREEN_WIDTH) |
|
|
y = int(data.get('y') * SCREEN_HEIGHT) |
|
|
pyautogui.click(x, y) |
|
|
|
|
|
elif action == 'type': |
|
|
pyautogui.write(data.get('text')) |
|
|
|
|
|
elif action == 'key': |
|
|
k = data.get('key').lower() |
|
|
if k == 'enter': pyautogui.press('enter') |
|
|
elif k == 'backspace': pyautogui.press('backspace') |
|
|
|
|
|
elif action == 'scroll': |
|
|
pyautogui.scroll(-5) |
|
|
|
|
|
elif action == 'open_terminal': |
|
|
subprocess.Popen(["xterm", "&"]) |
|
|
|
|
|
elif action == 'open_browser': |
|
|
subprocess.Popen(["chromium-browser", "--no-sandbox"]) |
|
|
|
|
|
return jsonify({"status": "ok"}) |
|
|
except Exception as e: |
|
|
return jsonify({"error": str(e)}), 500 |
|
|
|
|
|
if __name__ == '__main__': |
|
|
app.run(host='0.0.0.0', port=7860, threaded=True) |