diff options
Diffstat (limited to 'session.py')
-rw-r--r-- | session.py | 40 |
1 files changed, 5 insertions, 35 deletions
@@ -36,20 +36,6 @@ def get_desktop_dir(): ) -class ServerThread(threading.Thread): - def __init__(self, app, port: int): - super().__init__() - self.srv = make_server("127.0.0.1", port, app) - self.ctx = app.app_context() - self.ctx.push() - - def run(self): - self.srv.serve_forever() - - def shutdown(self): - self.srv.shutdown() - - class Session: #: Session is running STATUS_RUNNING = "running" @@ -57,13 +43,15 @@ class Session: #: Remote has joined the session STATUS_JOINED = "active" - def __init__(self, mockup_session: bool): + def __init__(self, trigger_port: int, mockup_session: bool = False): + self.trigger_token = secrets.token_urlsafe(20) + self.trigger_port = trigger_port self.done_jobs = [] self.mockup_session = mockup_session self.desktop_dir = get_desktop_dir() + self.desktop_dir = get_desktop_dir() self._generate_password() self._start_vnc() - self._start_trigger_service() self._register_session() self.status_text = self.STATUS_RUNNING @@ -135,25 +123,7 @@ class Session: self.api_token = secrets.token_urlsafe(10) self.pin = int(random_digits(5)) - def _start_trigger_service(self): - self.trigger_port = port_for.select_random() - self.trigger_token = secrets.token_urlsafe(20) - - app = Flask(__name__) - - @app.route("/", methods=["POST"]) - def trigger(): - json = request.json - if json.get("token", "") == self.trigger_token: - self._trigger() - return "Successful triggered" - else: - return abort(403) - - self.trigger_thread = ServerThread(app=app, port=self.trigger_port) - self.trigger_thread.start() - - def _trigger(self): + def trigger(self): """Event triggered by Django.""" print("Triggered") self.pull() |