Skip to content

Commit

Permalink
More accurate ip selection, Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues authored Feb 20, 2021
1 parent 8eefb16 commit 6518b14
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 54 deletions.
29 changes: 23 additions & 6 deletions copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)



Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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","<br>"))

#copy an image to the clipboard with a win32 api
if process_id == "[COPY IMG]":
Expand All @@ -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]":
Expand All @@ -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)
Expand Down
38 changes: 16 additions & 22 deletions image_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from random import randint
import win32clipboard
from io import BytesIO

from os import remove, path

app = Flask(__name__)

Expand All @@ -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
Expand All @@ -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","<br>"))
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","<br>"))

#copy an image to the clipboard with a win32 api
if process_id == "[COPY IMG]":
output = BytesIO()
Expand All @@ -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]":
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from getpass import getuser
import psutil

chdir("main")
chdir("copypasta")
run(["start","copypasta.exe"],shell=True)


Expand All @@ -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"])
for _ in range(len(all_matching_windows)):
run(["taskkill","copypasta.exe"])
4 changes: 2 additions & 2 deletions templates/img_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<title>CopyPasta</title>
</head>
<body>
<img src="static/imgscan.jpeg" alt="Your beautiful picture :D" class="center" style="margin-top: 50px;">
<img src="{{img_url}}" alt="Your beautiful picture :D" class="center" style="margin-top: 50px;">
<button id="button" class="center" onclick="window.location='/process/[DOWNLOAD IMG]'" >Download Image</button>
<button id="button" class="center" onclick="window.location='/process/[COPY IMG]'" >Copy Image</button>
<button id="button" class="center" onclick="window.location='/'">Main menu</button>
<button id="button" class="center" onclick="window.location='/process/[HOME]'">Main menu</button>
</body>

<style>
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<br>
<h1 style="color: white; margin-left: auto;">Scan the QR code with your CopyPasta app and begin sending whatever the fuck you want ;D</h1>
<br>
<img src="static/qr.jpeg" alt="Scan me :D" class="center">
<img src="{{qr_url}}" alt="Scan me :D" class="center">
<br>
<h2 style="color: white;">History :</h2>
<table >
Expand Down
2 changes: 1 addition & 1 deletion templates/scan_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div id="wrapper">
<button id="button" onclick="window.location='/process/[CLEAR SCAN]'" style="margin-left: 30px;">Clear scan</button>
<button id="button" onclick="window.location='/process/[COPY SCAN]'" style="margin-left: 30px;">Copy scan</button>
<button id="button" onclick="window.location='/'" style="margin-left: 30px;">Main menu</button>
<button id="button" onclick="window.location='/process/[HOME]'" style="margin-left: 30px;">Main menu</button>

<form id="paper" method="POST" action="">

Expand Down
2 changes: 1 addition & 1 deletion templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>
<button id="button" class="center" onclick="window.location='/process/[DEL HISTORY]'" >Delete history</button>
<button id="button" class="center" onclick="window.location='/'" >Main menu</button>
<button id="button" class="center" onclick="window.location='/process/[HOME]'" >Main menu</button>

</body>
{% with messages = get_flashed_messages() %}
Expand Down
35 changes: 16 additions & 19 deletions text_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ def scan_preview():
@app.route("/process/<process_id>")
def process(process_id):

#download the image received
if process_id == "[DOWNLOAD IMG]":
return send_file('static/imgscan.jpeg',
attachment_filename='imgscan'+str(randint(0,167645454))+'.jpeg',
as_attachment=True)

#empty the scan temporary file
if process_id == "[CLEAR SCAN]":
Expand All @@ -63,21 +58,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")
with open("static/scan.Blue","r") as f:
return render_template("scan_preview.html",scan = f.read().replace("/n","<br>"))

#copy an image to the clipboard with a win32 api
if process_id == "[COPY IMG]":
output = BytesIO()
image = Image.open("static/imgscan.jpeg")
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()

return render_template("img_preview.html")

#empty the history files
if process_id == "[DEL HISTORY]":
Expand All @@ -86,6 +69,20 @@ def process(process_id):
flash("Your scan History has been deleted :D")
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)




Expand Down
17 changes: 17 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import socket


def get_private_ip():
"""
get all the private ips linked to your machine and return the one linked to your context
:return: a string containing the private ip used on your machine
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]





0 comments on commit 6518b14

Please sign in to comment.