diff --git a/copypasta.py b/copypasta.py index a64d99c..bd33e2f 100644 --- a/copypasta.py +++ b/copypasta.py @@ -13,6 +13,7 @@ from flaskwebgui import FlaskUI from image_proc import start_image_proc from text_proc import start_text_proc +from util import get_private_ip #init flask app and secret key @@ -82,7 +83,8 @@ def home(): dates.reverse() #render the html with the history - return render_template("index.html",hist = a, len = len(a),dates=dates) + qr_url = "static/qr.jpeg" + return render_template("index.html",hist = a, len = len(a),dates=dates,qr_url = qr_url) @@ -117,7 +119,7 @@ def settings(): @app.route("/image_preview") def img_preview(): - return render_template("img_preview.html") + return render_template("img_preview.html",img_url="static\imgscan.jpeg") #scan preview @@ -160,7 +162,9 @@ def process(process_id): with open("static/scan.Blue","r") as f: copy(f.read()) flash("Scan copied in your clipboard :D") - return render_template("scan_preview.html") + f.close() + with open("static/scan.Blue","r") as f: + return render_template("scan_preview.html",scan = f.read().replace("/n","
")) #copy an image to the clipboard with a win32 api if process_id == "[COPY IMG]": @@ -174,7 +178,7 @@ def process(process_id): win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data) win32clipboard.CloseClipboard() - return render_template("img_preview.html") + return render_template("img_preview.html",img_url="..\static\imgscan.jpeg") #empty the history files if process_id == "[DEL HISTORY]": @@ -184,14 +188,27 @@ def process(process_id): return redirect("/[SETTINGS]") + if process_id == "[HOME]": + #read history files, convert it to an array and reverse it to have the most recent first + with open("static/hist.Blue","r") as f: + a = f.read() + a = a.split("=") + a.reverse() + with open("static/dates.Blue","r") as f: + dates=f.read().split("\n") + dates.reverse() + #render the html with the history + qr_url = "../static/qr.jpeg" + return render_template("index.html",hist = a, len = len(a),dates=dates,qr_url = qr_url) + if __name__ == "__main__": #make sure we are in the right path - chdir(path.abspath(__file__).replace("main.py","").replace("main.exe","").replace("copypasta.exe","")) + chdir(path.abspath(__file__).replace("main.py","").replace("main.exe","").replace("copypasta.exe","").replace("copypasta.py","")) #get the ip (pray that this is the right one and not some virutal machines) - ip = str(socket.gethostbyname(socket.gethostname())) + ip = get_private_ip() #create a qr code containing the ip with google chart api r = get("https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl="+ip,allow_redirects=True) diff --git a/image_proc.py b/image_proc.py index d37cd2c..68011f0 100644 --- a/image_proc.py +++ b/image_proc.py @@ -9,7 +9,7 @@ from random import randint import win32clipboard from io import BytesIO - +from os import remove, path app = Flask(__name__) @@ -28,7 +28,7 @@ def init_flask(): #image preview when the user send a picture @app.route("/") def img_preview(): - return render_template("img_preview.html") + return render_template("img_preview.html",img_url="static\imgscan.jpeg") #processes @@ -41,22 +41,20 @@ def process(process_id): attachment_filename='imgscan'+str(randint(0,167645454))+'.jpeg', as_attachment=True) - #empty the scan temporary file - if process_id == "[CLEAR SCAN]": - open("static/scan.Blue","w") - with open("static/scan.Blue","r") as f: - return render_template("scan_preview.html",scan = f.read().replace("/n","
")) + if process_id == "[HOME]": + #read history files, convert it to an array and reverse it to have the most recent first + with open("static/hist.Blue","r") as f: + a = f.read() + a = a.split("=") + a.reverse() + with open("static/dates.Blue","r") as f: + dates=f.read().split("\n") + dates.reverse() - #copy the scan temporary file to clipboard - if process_id == "[COPY SCAN]": - with open("static/scan.Blue","r") as f: - copy(f.read()) - - flash("Scan copied in your clipboard :D") + #render the html with the history + qr_url = "../static/qr.jpeg" + return render_template("index.html",hist = a, len = len(a),dates=dates,qr_url = qr_url) - with open("static/scan.Blue","r") as f: - return render_template("scan_preview.html",scan = f.read().replace("/n","
")) - #copy an image to the clipboard with a win32 api if process_id == "[COPY IMG]": output = BytesIO() @@ -69,7 +67,7 @@ def process(process_id): win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data) win32clipboard.CloseClipboard() - return render_template("img_preview.html") + return render_template("img_preview.html",img_url="..\static\imgscan.jpeg") #empty the history files if process_id == "[DEL HISTORY]": @@ -98,13 +96,9 @@ def image_process(): #receive the image and store it to bytearray while True: - b = cli.recv(1024) + b = cli.recv(9999) - print(b) - stdout.flush() - if (b == b""): - print("[OUICECIESTUNEFINFLAG]") stdout.flush() break diff --git a/launcher.py b/launcher.py index 7a7506e..40f0cc1 100644 --- a/launcher.py +++ b/launcher.py @@ -3,7 +3,7 @@ from getpass import getuser import psutil -chdir("main") +chdir("copypasta") run(["start","copypasta.exe"],shell=True) @@ -25,4 +25,5 @@ def winEnumHandler(hwnd, ctx): window_starts = lambda title: [(hwnd,full_title) for (hwnd,full_title) in all_titles if full_title.startswith(title)] all_matching_windows = window_starts('CopyPasta') if len(all_matching_windows) < 1: - run(["taskkill","copypasta.exe"]) \ No newline at end of file + for _ in range(len(all_matching_windows)): + run(["taskkill","copypasta.exe"]) \ No newline at end of file diff --git a/templates/img_preview.html b/templates/img_preview.html index 04ed792..4e448cd 100644 --- a/templates/img_preview.html +++ b/templates/img_preview.html @@ -6,10 +6,10 @@ CopyPasta - Your beautiful picture :D + Your beautiful picture :D - +