added get by id and last added with -1 for clipboard
This commit is contained in:
parent
7eeba7090d
commit
4447468b77
22
client.py
22
client.py
@ -1,5 +1,6 @@
|
|||||||
import pyperclip
|
import pyperclip
|
||||||
import socketio
|
import socketio
|
||||||
|
import reauests
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -10,28 +11,17 @@ import zc.lockfile
|
|||||||
ip = 'simailadjalim.fr'
|
ip = 'simailadjalim.fr'
|
||||||
port = "9564"
|
port = "9564"
|
||||||
hostname = "WarMachine"
|
hostname = "WarMachine"
|
||||||
logfilepath = "./logs.txt"
|
|
||||||
|
username = "neotaku67"
|
||||||
|
password = "un bon mot de passe de prefererance mais en sah tant qu'il est hashe ca passe"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This script is a daemon that, on event, send and sync the clipboard with a distant one
|
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}/"
|
ip = f"http://{ip}:{port}/"
|
||||||
print(ip)
|
|
||||||
sio = socketio.Client()
|
sio = socketio.Client()
|
||||||
sio.connect(ip)
|
sio.connect(ip)
|
||||||
|
|
||||||
try:
|
|
||||||
print("[Debug] Trying to lockfile")
|
|
||||||
zc.lockfile.LockFile('/tmp/notifysync.lock')
|
|
||||||
except:
|
|
||||||
print("[Debug] Failed to lock file, another instance running, exiting")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
print("[Debug] Connected to Server .w.")
|
print("[Debug] Connected to Server .w.")
|
||||||
|
|
||||||
@ -43,14 +33,14 @@ def sendSystemNotification(title:str,content:str):
|
|||||||
subprocess.run(["notify-send",title,content])
|
subprocess.run(["notify-send",title,content])
|
||||||
|
|
||||||
@sio.event
|
@sio.event
|
||||||
def clip(data):
|
def NotificationUpdate(data):
|
||||||
content = data["content"]
|
content = data["content"]
|
||||||
clipCmd = f'echo {content} | xclip'
|
clipCmd = f'echo {content} | xclip'
|
||||||
print(f"[ClipEvent] received data from ")
|
print(f"[ClipEvent] received data from ")
|
||||||
os.system(clipCmd)
|
os.system(clipCmd)
|
||||||
|
|
||||||
@sio.event
|
@sio.event
|
||||||
def notify(data):
|
def ClipboardUpdate(data):
|
||||||
title, content = data["title"], data["content"]
|
title, content = data["title"], data["content"]
|
||||||
command = f'notify-send "{title}" "{content}"'
|
command = f'notify-send "{title}" "{content}"'
|
||||||
print(command)
|
print(command)
|
||||||
|
54
serveur.py
54
serveur.py
@ -1,9 +1,9 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
import flask_socketio
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import secrets
|
import secrets
|
||||||
import time
|
import time
|
||||||
from flask import Flask, request, render_template, json, jsonify
|
import flask_socketio
|
||||||
|
from flask import Flask, request
|
||||||
# base socket
|
# base socket
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@ -24,7 +24,7 @@ def first_run():
|
|||||||
token)")
|
token)")
|
||||||
|
|
||||||
cur.execute("CREATE TABLE NOTIFICATION(\
|
cur.execute("CREATE TABLE NOTIFICATION(\
|
||||||
id,\
|
id INTEGER PRIMARY KEY AUTOINCREMENT,\
|
||||||
date,\
|
date,\
|
||||||
machine,\
|
machine,\
|
||||||
token,\
|
token,\
|
||||||
@ -32,7 +32,7 @@ def first_run():
|
|||||||
content)")
|
content)")
|
||||||
|
|
||||||
cur.execute("CREATE TABLE CLIPBOARD(\
|
cur.execute("CREATE TABLE CLIPBOARD(\
|
||||||
id,\
|
id INTEGER PRIMARY KEY AUTOINCREMENT,\
|
||||||
date,\
|
date,\
|
||||||
machine,\
|
machine,\
|
||||||
token,\
|
token,\
|
||||||
@ -43,6 +43,7 @@ def first_run():
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
@app.route("/user", methods=['POST'])
|
@app.route("/user", methods=['POST'])
|
||||||
def auth():
|
def auth():
|
||||||
"""
|
"""
|
||||||
@ -111,11 +112,11 @@ def add_notification():
|
|||||||
return {"status": "Error, no user"}, 500
|
return {"status": "Error, no user"}, 500
|
||||||
try:
|
try:
|
||||||
notification = (date, device_name, token, title, content)
|
notification = (date, device_name, token, title, content)
|
||||||
cur.execute("INSERT INTO notification VALUES (0,?,?,?,?,?)",
|
cur.execute("INSERT INTO notification VALUES (null,?,?,?,?,?)",
|
||||||
notification)
|
notification)
|
||||||
con.commit()
|
con.commit()
|
||||||
con.close()
|
con.close()
|
||||||
socketio.emit("update", broadcast=True)
|
socketio.emit("NotificationUpdate", broadcast=True)
|
||||||
return {"status": "ok"}, 200
|
return {"status": "ok"}, 200
|
||||||
except:
|
except:
|
||||||
return {"status": "error"}, 500
|
return {"status": "error"}, 500
|
||||||
@ -155,10 +156,10 @@ def add_clipboard():
|
|||||||
return {"status": "Error, no user"}, 500
|
return {"status": "Error, no user"}, 500
|
||||||
try:
|
try:
|
||||||
clipboard = (date, device_name, token, content)
|
clipboard = (date, device_name, token, content)
|
||||||
cur.execute("INSERT INTO CLIPBOARD VALUES (0,?,?,?,?)", clipboard)
|
cur.execute("INSERT INTO CLIPBOARD VALUES (null,?,?,?,?)", clipboard)
|
||||||
con.commit()
|
con.commit()
|
||||||
con.close()
|
con.close()
|
||||||
socketio.emit("update", broadcast=True)
|
socketio.emit("ClipboardUpdate", broadcast=True)
|
||||||
return {"status": "ok"}, 200
|
return {"status": "ok"}, 200
|
||||||
except:
|
except:
|
||||||
return {"status": "error"}, 500
|
return {"status": "error"}, 500
|
||||||
@ -168,18 +169,47 @@ def add_clipboard():
|
|||||||
def get_clipboard():
|
def get_clipboard():
|
||||||
"""
|
"""
|
||||||
Le but de cet app se resume a cette fonction, elle recoit une requete
|
Le but de cet app se resume a cette fonction, elle recoit une requete
|
||||||
http et renvoie via le websocket le contenu de la requette a tout les
|
http et renvoie via le websocket le contenu de la requette a tout les
|
||||||
client.
|
client.
|
||||||
"""
|
"""
|
||||||
token = request.values.get("token")
|
token = request.values.get("token")
|
||||||
con = sqlite3.connect("database.db")
|
con = sqlite3.connect("database.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
clipboard = cur.execute("SELECT content FROM CLIPBOARD WHERE \
|
clipboard = cur.execute("SELECT content, id FROM CLIPBOARD WHERE \
|
||||||
token=?", (token, )).fetchall()
|
token=?", (token, )).fetchall()
|
||||||
return {"status": "ok", "notifications": clipboard}, 200
|
return {"status": "ok", "clipboard": clipboard}, 200
|
||||||
|
|
||||||
|
@app.route("/clipboard/<clipid>", methods=['GET'])
|
||||||
|
def get_clipboard_by_id(clipid):
|
||||||
|
"""
|
||||||
|
Le but de cet app se resume a cette fonction, elle recoit une requete
|
||||||
|
http et renvoie via le websocket le contenu de la requette a tout les
|
||||||
|
client.
|
||||||
|
"""
|
||||||
|
clipid = int(clipid)
|
||||||
|
token = request.values.get("token")
|
||||||
|
con = sqlite3.connect("database.db")
|
||||||
|
cur = con.cursor()
|
||||||
|
if clipid == -1:
|
||||||
|
clipboard = cur.execute("SELECT content,id \
|
||||||
|
FROM CLIPBOARD \
|
||||||
|
WHERE token=? \
|
||||||
|
ORDER BY id DESC \
|
||||||
|
LIMIT 1",
|
||||||
|
(token,)).fetchall()
|
||||||
|
else:
|
||||||
|
clipboard = cur.execute("SELECT content,id FROM CLIPBOARD WHERE \
|
||||||
|
token=? AND\
|
||||||
|
id=?",
|
||||||
|
(token, clipid)).fetchone()
|
||||||
|
|
||||||
|
return {"status": "ok", "clipboard": clipboard}, 200
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if True:
|
try:
|
||||||
|
f=open("database.db","r")
|
||||||
|
f.close()
|
||||||
|
except :
|
||||||
first_run()
|
first_run()
|
||||||
socketio.run(app, host="0.0.0.0", port=9564)
|
socketio.run(app, host="0.0.0.0", port=9564)
|
||||||
|
Loading…
Reference in New Issue
Block a user