Skip to content

Commit

Permalink
Merge pull request #32 from ThaaoBlues/main
Browse files Browse the repository at this point in the history
V1.9.1
  • Loading branch information
ThaaoBlues authored Apr 1, 2023
2 parents f2c218b + 9c0e216 commit 05037c8
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 39 deletions.
47 changes: 20 additions & 27 deletions copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from re import findall



# socket io for real time speeeeeed
from flask_socketio import SocketIO
# necessary to compile -__(°-°)__-
Expand All @@ -34,6 +35,9 @@
from random import choice
from string import printable

# instances discovery server
#from discovery_server import Server as DiscoveryServer

#init flask app and secret key
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
Expand Down Expand Up @@ -274,7 +278,7 @@ def change_tab_settings(json_data:dict):


# open files explorer into the the copypasta directory
socketio.on("[OPEN_FILES_EXPLORER]")
@socketio.on("[OPEN_FILES_EXPLORER]")
def open_files_explorer(json_data:dict):

Process(target=startfile,args=(f"{APP_PATH}/static/files_hist",)).start()
Expand All @@ -283,7 +287,7 @@ def open_files_explorer(json_data:dict):


# open a file with default app
socketio.on("[OPEN_FILE]")
@socketio.on("[OPEN_FILE]")
def open_file(json_data:dict):


Expand All @@ -300,7 +304,7 @@ def open_file(json_data:dict):



socketio.on("[COPY_WIFI_PW]")
@socketio.on("[COPY_WIFI_PW]")
def copy_wifi_pw(json_data:dict):


Expand All @@ -318,7 +322,7 @@ def copy_wifi_pw(json_data:dict):


# copy text scan content
socketio.on("[COPY_CONTENT]")
@socketio.on("[COPY_CONTENT]")
def copy_text_scan_content(json_data:dict):


Expand Down Expand Up @@ -378,9 +382,6 @@ def change_accepting_uploads(json_data:dict):
else:
socketio.emit("[NOTIFY_USER]",{"msg":"CopyPasta is now refusing incoming files !"})




#processes
@app.route("/process/<process_id>")
def process(process_id):
Expand Down Expand Up @@ -613,7 +614,6 @@ def upload():
notify_desktop("New scan Incoming !", "Click to open CopyPasta")

socketio.emit("[NOTIFY_USER]",{"msg":"New scan Incoming !"})
socketio.emit("fill_history_tab",get_history_json())


if r != None:
Expand Down Expand Up @@ -661,15 +661,12 @@ def upload():
open_browser_if_settings_okay("http://127.0.0.1:21987/scan_preview")


return jsonify({"upload_status" : "true"})

elif file_type == "keystrokes":


keystrokes = r['text']
send_keystrokes(keystrokes)

return jsonify({"upload_status" : "true"})

elif file_type == "wifi":

Expand All @@ -679,54 +676,40 @@ def upload():

store_to_history({"file_type" : "wifi", "ssid" : f"{ssid}","password" : f"{password}", "enctype" : f"{enctype}", "date" : f"{time}"})

return jsonify({"upload_status" : "true"})


elif file_type == "isbn":

isbn = r

store_to_history({"file_type" : "isbn", "content" : f"{isbn}", "date" :f"{time}","isbn_lookup":identify_product(isbn)})

return jsonify({"upload_status" : "true"})


elif file_type == "email":

store_to_history({"file_type" : "email","addr" : f"{r['address']}", "subject" : f"{r['subject']}", "content" : f"{r['content']}", "date" : f"{time}"})

return jsonify({"upload_status" : "true"})


elif file_type == "url":

store_to_history({"file_type" : "url","url" : f"{r}", "date" : f"{time}"})

return jsonify({"upload_status" : "true"})

elif file_type == "phone":

store_to_history({"file_type" : "phone","phone_number" : f"{r}", "date" : f"{time}"})

return jsonify({"upload_status" : "true"})

elif file_type == "sms":

store_to_history({"file_type" : "sms","phone_number" : f"{r['number']}", "content": f"{r['content']}", "date" : f"{time}"})

return jsonify({"upload_status" : "true"})

elif file_type == "location":
lat = r['lattitude']
long = r['longitude']

store_to_history({"file_type" : "location", "lat" : f"{lat}", "long" : f"{long}", "date" : f"{time}"})

elif file_type == "contact":

store_to_history({"file_type" : "contact", "first_name" : f"{r['firstName']}", "name" : f"{r['name']}", "organization" : f"{r['organization']}", "job" : f"{r['title']}"})


else:

return jsonify({"upload_status" : "false","Error" : "unknown type"}), 400
Expand Down Expand Up @@ -765,8 +748,12 @@ def upload():

if is_image(file_type):
open_browser_if_settings_okay(f"{COPYPASTA_URL}/image_preview?image_id={get_history_file_last_id()}")

return jsonify({"upload_status" : "true"})



socketio.emit("fill_history_tab",get_history_json())

return jsonify({"upload_status" : "true"})



Expand Down Expand Up @@ -872,7 +859,13 @@ def client():

Process(target=open_link_process, args=(COPYPASTA_URL,)).start()




if not is_server_already_running():

#d_server = DiscoveryServer()
#d_server.start()

socketio.run(app,host="0.0.0.0",port=21987)

Expand Down
69 changes: 69 additions & 0 deletions discovery_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from util import get_private_ip
import socket
from json import loads
from multiprocessing import Process


class Server():





def __init__(self) -> None:
"""
a simple server responding to udb ping on port 21988
and sending ping requests to discover others copypasta instances on the local network
"""

self.port = 21987

self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)



def response_loop(self,PORT:int,sock:socket.socket):



msg = ("[PONG FLAG]{ip_addr:\""+get_private_ip() +"\"}").encode("utf-8")

PORT = 21988
sock.bind(('',21988))

while True:
if sock.recv(1024) == b"ping":
sock.sendto(msg, ("255.255.255.255", PORT))


def start(self):

Process(target=self.response_loop,args=(self.port,self.sock)).start()


def discover_instances(self) -> set:
"""
returns a set of tuples (ip_addr,hostname)
that corresponds to all copypasta instances running on the local network
"""

ret = set()

self.sock.sendto(b"ping", ("255.255.255.255", self.port))

resp = self.sock.recv(1024).decode("utf-8")

if resp.startswith("[PONG FLAG]"):
resp = loads(resp.replace("[PONG_FLAG]",""))
ret.add((resp["ip_addr"],socket.gethostbyaddr(resp["ip_addr"])))


return ret








8 changes: 1 addition & 7 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from zipfile import ZipFile
from os import path, chdir, remove,mkdir,environ
import sys
from util import create_shortcut, notify_desktop
from util import notify_desktop

# to fix pyinstaller error
import pywintypes
Expand Down Expand Up @@ -132,12 +132,6 @@ def move_launcher():
f.write(get("https://github.com/CopyPastaOfficial/CopyPasta/releases/latest/download/launcher.exe").content)
f.close()

# 2
create_shortcut(path="C:\\Users\\Public\\Desktop\\CopyPasta.lnk",target="C:\\Program Files\\CopyPasta\\launcher.exe",wDir="C:\\Program Files\\CopyPasta\\",icon="C:\\Program Files\\CopyPasta\\copypasta\\static\\favicon.ico")

#3
create_shortcut(path=f"C:\\Users\\{getuser()}\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\CopyPasta.lnk",target="C:\\Program Files\\CopyPasta\\launcher.exe",wDir="C:\\Program Files\\CopyPasta\\",icon="C:\\Program Files\\CopyPasta\\copypasta\\static\\favicon.ico")


if __name__ == "__main__":

Expand Down
2 changes: 1 addition & 1 deletion production.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- copypasta icon

- nuitka :
- python -m nuitka .\copypasta.py --follow-imports --plugin-enable=multiprocessing --onefile --windows-disable-console
```python -m nuitka .\copypasta.py --follow-imports --standalone --windows-disable-console```

## compile copypasta with pyinstaller :

Expand Down
3 changes: 1 addition & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@ <h1>Last files/data sent :</h1>


var n_elements = 0;

function fill_history_tab(init,json){

console.log(json);


var json = json.history;

var elements = [];
Expand Down
33 changes: 33 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from socket import *
from requests import get
from json import loads

PORT = 21988

#print(get("http://127.0.0.1:21987/api/ping").text)

HTTP_REQ = b"GET /api/ping HTTP/1.1\r\nHost:www.example.com\r\n\r\n"

def t1():
s = socket(AF_INET,SOCK_DGRAM)

s.bind(('',0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto(HTTP_REQ,('<broadcast>',PORT))
print("packet sent")
print(s.recv(10))

def t2():
with socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP) as sock:
sock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
sock.sendto(b"ping", ("255.255.255.255", PORT))

resp = sock.recv(1024).decode("utf-8")

if resp.startswith("[PONG FLAG]"):
resp = loads(resp.replace("[PONG_FLAG]",""))
print(resp["ip_addr"])



t2()
4 changes: 3 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,6 @@ def change_accepting_uploads_state():

config["accepting_uploads"] = not config["accepting_uploads"]

f.write(dumps(config))
f.write(dumps(config))


2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0
1.9.1

0 comments on commit 05037c8

Please sign in to comment.