Skip to content

Commit

Permalink
Merge pull request #25 from ThaaoBlues/main
Browse files Browse the repository at this point in the history
1.7.0
  • Loading branch information
ThaaoBlues authored Jun 30, 2022
2 parents 838b9b8 + 1c535d5 commit 86855c7
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ static/
copypasta.build
output
output/*
copypasta.exe
copypasta.exe
*.build
*.dist
6 changes: 4 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
from ast import literal_eval

from util import *

def send_text_scan(text):
r = requests.post("http://127.0.0.1:21987/upload",json={"type" : "text", "content" : f"{text}"})
Expand Down Expand Up @@ -40,4 +40,6 @@ def send_url(url):
#send_file("static/qr.jpeg")
#send_text_scan("test of text scan")
#send_wifi("This_is_a_wifi_name","wpa","password")
#send_url("https://www.google.com")
#send_url("https://www.google.com")

check_templates_update()
18 changes: 15 additions & 3 deletions copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ def process(process_id):
copy(get_history_file_by_id(int(request.args.get("scan_id")))['content'])


if process_id == "[OPEN VIDEO]":
file_path = request.args.get('file_path')


# try to secure the file path
# if suspicious path, just go home
if (not path.exists(file_path)) or (not file_path.startswith("static/files_hist/")) or (".." in file_path):
return redirect("/")


return render_template("video_preview.html",file_path=file_path)
else:
return abort(403)

Expand Down Expand Up @@ -526,6 +537,7 @@ def upload():

store_to_history({ "file_type" : f"{file_type}", "date" : f"{time}","text" : f"{file_content}"})


open_browser_if_settings_okay("http://127.0.0.1:21987/scan_preview")


Expand Down Expand Up @@ -631,9 +643,9 @@ def upload():
file.save(full_path)
store_to_history({"file_name" : f"{file.filename}","file_type" : f"{file_type}","date" : f"{time}","path" : f"{full_path}"})


open_browser_if_settings_okay(f"{COPYPASTA_URL}/image_preview?image_id={get_history_file_last_id()}")

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"})

else:
Expand Down
9 changes: 5 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ <h1>Last files/data sent :</h1>
//videos
}else if(videos_ext.includes(obj.file_type)){

var open_file_icon = "<button type=\"button\" class=\"btn btn-primary\" onclick=\"request_and_notify('Opening video...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button>";

tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-film\"></i></div></td><td><div style=\"margin-top:15px;\">title:"+obj.file_name+"</td></div><td><div style=\"margin-top:15px;\">"+open_folder_icon+"<br>"+open_file_icon+delete_file_icon+"</div></td></tr>";
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"request_and_notify('Opening video...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button>";

var play_video_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"window.open('/process/[OPEN VIDEO]?file_path="+obj.path+"')\"><i class=\"bi bi-play\"></i></button>";
tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-film\"></i></div></td><td><div style=\"margin-top:15px;\">title:"+obj.file_name+"</td></div><td><div style=\"margin-top:15px;\">"+play_video_icon+open_file_icon+"<br>"+open_folder_icon+delete_file_icon+"</div></td></tr>";

//audio
}else if(audios_ext.includes(obj.file_type)){
Expand Down Expand Up @@ -265,7 +266,7 @@ <h1>Last files/data sent :</h1>

//random file
}else{
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary\" onclick=\"request_and_notify('Opening file...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button> ";
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"request_and_notify('Opening file...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button> ";

tab_element = "<tr><td>"+obj.date+"</td><td>"+obj.file_name+"</td><td>"+open_folder_icon+"<br>"+open_file_icon+delete_file_icon+"</td></tr>";
}
Expand Down
2 changes: 1 addition & 1 deletion templates/scan_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif %}
{% endwith %}

<title translate="no">CopyPasta/scan preview</title>
<title translate="no">CopyPasta/Scan preview</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
Expand Down
78 changes: 78 additions & 0 deletions templates/video_preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="fr">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title translate="no">CopyPasta/Video</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.2/font/bootstrap-icons.css" integrity="sha384-eoTu3+HydHRBIjnCVwsFyCpUDZHZSFKEJD0mc3ZqSBSb6YhZzRHeiomAUWCstIWo" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">

<div class="container-fluid">
<a class="navbar-brand" href="/" translate="no">CopyPasta</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link active" name="over" href="/process/[HOME]">Main menu</a>
</li>
<li>
<div id="google_translate_element"></div>
</li>
</ul>
</div>
</div>

</nav>


<div class="text-center">
<video controls width="800" height="600"> <source src="/{{file_path}}"></video>
</div>







<style>
.btn-primary, .btn-primary:hover, .btn-primary:active, .btn-primary:visited, .btn-outline-primary {
background-color: #009c74 !important;
border-color: #009c74;
color: white;
}

.bg-primary{
background-color: #009c74 !important;
border-color: #009c74;
color: #009c74;
}


.sep_left{
border-left: 1px solid #ffffff;
margin-left: 10px;
}

</style>


<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
document.getElementsByTagName("body")[0].style = "";

}
</script>
</body>
77 changes: 77 additions & 0 deletions unins000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": "auto-py-to-exe-configuration_v1",
"pyinstallerOptions": [
{
"optionDest": "noconfirm",
"value": true
},
{
"optionDest": "filenames",
"value": "G:/Mon Drive/dev/projects/CopyPasta/unins000.py"
},
{
"optionDest": "onefile",
"value": true
},
{
"optionDest": "console",
"value": true
},
{
"optionDest": "icon_file",
"value": "G:/Mon Drive/dev/projects/CopyPasta/favicon.ico"
},
{
"optionDest": "ascii",
"value": false
},
{
"optionDest": "clean_build",
"value": false
},
{
"optionDest": "strip",
"value": false
},
{
"optionDest": "noupx",
"value": false
},
{
"optionDest": "disable_windowed_traceback",
"value": false
},
{
"optionDest": "embed_manifest",
"value": true
},
{
"optionDest": "uac_admin",
"value": true
},
{
"optionDest": "uac_uiaccess",
"value": false
},
{
"optionDest": "win_private_assemblies",
"value": false
},
{
"optionDest": "win_no_prefer_redirects",
"value": false
},
{
"optionDest": "bootloader_ignore_signals",
"value": false
},
{
"optionDest": "argv_emulation",
"value": false
}
],
"nonPyinstallerOptions": {
"increaseRecursionLimit": true,
"manualArguments": ""
}
}
19 changes: 14 additions & 5 deletions unins000.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
from shutil import rmtree
from os import remove
from getpass import getuser
from sys import argv
# for pyinstaller
import pywintypes

APP_PATH = "C:/Program Files/CopyPasta"

try:
remove("launcher.exe")
remove(f"{APP_PATH}/launcher.exe")
except:
pass

try:
rmtree("copypasta")
rmtree(f"{APP_PATH}/copypasta",ignore_errors=True)
except Exception as e:
print(e)


try:
user = getuser()
remove(f"C:\\Users\\{user}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\CopyPasta.lnk")
del user
except Exception as e:
print(e)

try:
user = getuser()
remove(f"C:\\Users\\{user}\\Desktop\\CopyPasta.lnk")
remove(f"C:\\Users\\Public\\Desktop\\CopyPasta.lnk")
except Exception as e:
print(e)

try:
remove("unins000.exe")
remove(argv[0])
except Exception as e:
print(e)




40 changes: 24 additions & 16 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from platform import system



TEMPLATES_FILES = ["favicon.ico","index.html","scan_preview.html","img_preview.html","video_preview.html"]


def notify_desktop(title,text):
# initialize
toaster = ToastNotifier()
Expand Down Expand Up @@ -58,6 +62,15 @@ def make_qr_url():


def check_templates_update():

# check templates integrity
for ele in TEMPLATES_FILES:
if not path.exists(f"templates/{ele}"):
download_templates()
return


# check 10 startup rule
with open("static/update.Blue","r") as f:
n = int(f.read())
if n == 10:
Expand Down Expand Up @@ -111,21 +124,11 @@ def is_server_already_running():
def download_templates():

#get the templates
r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/index.html",allow_redirects=True)
with open("templates/index.html","wb") as f:
f.write(r.content)

r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/scan_preview.html",allow_redirects=True)
with open("templates/scan_preview.html","wb") as f:
f.write(r.content)

r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/img_preview.html",allow_redirects=True)
with open("templates/img_preview.html","wb") as f:
f.write(r.content)

r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/favicon.ico",allow_redirects=True)
with open("static/favicon.ico","wb") as f:
f.write(r.content)
for ele in TEMPLATES_FILES:

r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/{ele}",allow_redirects=True)
with open(f"templates/{ele}","wb") as f:
f.write(r.content)

with open("static/update.Blue","w") as f:
f.write("1")
Expand Down Expand Up @@ -319,4 +322,9 @@ def remove_copypasta_port_redirect():
run("netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.0.0.1 connectport=80 connectaddress=127.0.0.1")
except:
# feature that may crash sometimes, not essential
pass
pass


def is_image(file_type:str):

return file_type in ["jpeg","jpg","png","ico","gif","apng","avif","gif","jfif","pjpeg","pjp","svg","webp"]
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.4
1.7.0

0 comments on commit 86855c7

Please sign in to comment.