From 3be3bdbb5d77acae08b24251b76cf4eed73215fc Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 28 Jan 2023 16:03:13 +0100 Subject: [PATCH] v1 --- README.md | 3 +++ client.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ serveur.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 README.md create mode 100644 client.py create mode 100644 serveur.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..91a4fc7 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# BloatProject + +Syncro de notification mon phone et mon pc + up checker \ No newline at end of file diff --git a/client.py b/client.py new file mode 100644 index 0000000..c19cfd7 --- /dev/null +++ b/client.py @@ -0,0 +1,49 @@ +import pyperclip +import socketio +import os +import subprocess +# standard Python + +# to put in a conf file +ip = 'simailadjalim.fr' +port = "9564" +hostname = "WarMachine" +logfilepath = "./logs.txt" + +""" +This script is a daemon that, on event, send and sync the clipboard with a distant one +""" + +def dechiffreCePutainDeMessage(message : str) -> str: + """ + """ + + +ip = f"http://{ip}:{port}/" +print(ip) +sio = socketio.Client() +sio.connect(ip) +print("[Debug] Connected to Server .w.") + +def sendSystemNotification(title:str,content:str): + """ + Une fonction pour 1. rendre le truc plus secure et + eviter que thomas face des rce sur mon pc .w. lmao + """ + subprocess.run(["notify-send",title,content]) + +@sio.event +def clip(data): + content = data["content"] + clipCmd = f'echo {content} | xclip' + print(f"[ClipEvent] received data from ") + os.system(clipCmd) + +@sio.event +def notify(data): + title, content = data["title"], data["content"] + command = f'notify-send "{title}" "{content}"' + print(command) + os.system(command) + +sio.wait() diff --git a/serveur.py b/serveur.py new file mode 100644 index 0000000..322c6e7 --- /dev/null +++ b/serveur.py @@ -0,0 +1,38 @@ +#!/bin/python +from flask import Flask, request, render_template, json, jsonify +import flask_socketio +# base socket + +app = Flask(__name__) +socketio = flask_socketio.SocketIO(app) + + +@app.route("/notify", methods=['POST']) +def notify(): + """ + Le but de cet app se resume a cette fonction, elle recoit une requette http et renvoie via le websocket + le contenu de la requette a tout les client. + """ + data = {} + data["ip"] = request.remote_addr + print(request.remote_addr) + data['title'] = request.form['title'] + data['content'] = request.form['content'] + print(f"""[Debug] Sending to all clients notification event""") + socketio.emit("notify", data, broadcast=True) + return "true" , 200 + +@app.route("/clip", methods=['POST']) +def clip(): + """ + pareil qu'en haut mais pour le clipboard .w. + """ + data = {} + data["ip"] = request.remote_addr + data['content'] = request.form['content'] + print(f"""[Debug] Sending to all clients clipboard event""") + socketio.emit("clip", data, broadcast=True) + return "true" , 200 + +if __name__ == '__main__': + socketio.run(app, host="0.0.0.0", port = 9564)