-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·154 lines (117 loc) · 4.99 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
import requests
import argparse
import tomllib
import os
URL = "https://0x0.st"
TERMS_PRIVACY = """
Maximum file size: 512.0 MiB
Not allowed: application/x-dosexec, application/x-executable, application/x-sharedlib, application/x-hdf5, application/java-archive, application/vnd.android.package-archive, application/x-rar, application/vnd.microsoft.portable-executable
TERMS OF SERVICE
----------------
0x0.st is NOT a platform for:
* piracy
* pornography and gore
* extremist material of any kind
* malware / botnet C&C
* anything related to crypto currencies
* backups (yes, this includes your minecraft stuff, seriously
people have been dumping terabytes of it here for years)
* CI build artifacts
* doxxing, database dumps containing personal information
* anything illegal under German law
Uploads found to be in violation of these rules will be removed,
and the originating IP address blocked from further uploads.
Note that Tor exit nodes are blocked by the firewall due to frequent
rule violations.
PRIVACY POLICY
--------------
For the purpose of moderation, the following is stored with each
uploaded file:
* IP address
* User agent string
This site generally does not log requests, but may enable logging
if necessary for purposes such as threat mitigation.
No data is shared with third parties.
"""
def oneTimeSetup() -> None:
# Does the config file already exist?
if os.path.exists(os.path.expanduser("~/.0x0py")):
# If so, check if the user has agreed to the terms
with open(os.path.expanduser("~/.0x0py"), "rb") as f:
dict = tomllib.load(f)
if dict["termsAgree"]:
# If so, go to main
main()
exit()
# If not, then do everything below
# Make config file in home directory
with open(os.path.expanduser("~/.0x0py"), "w") as f:
f.write("""
# This checks whether the user has agreed to https://0x0.st's terms of service.
# Its also a checker to see if the first time setup has been run.
termsAgree = false
""")
print(f"""
Welcome to 0x0py! This is a simple command line tool to upload files to https://0x0.st.
Please agree to the Terms of Service and Privacy Policy below.
{TERMS_PRIVACY}
""")
# Ask user to agree to terms
while True:
termsAgree = input("Do you agree to the Terms of Service and Privacy Policy? (y/n): ")
if termsAgree.lower() == "y":
# Change config file to reflect that user has agreed to terms
with open(os.path.expanduser("~/.0x0py"), "r") as f:
contents = f.readlines()
# Replace False with True
for i, line in enumerate(contents):
if "termsAgree" in line:
contents[i] = "termsAgree = true\n"
break
contents = [line for line in contents if termsAgree not in line]
with open(os.path.expanduser("~/.0x0py"), "w") as f:
f.writelines(contents)
break
elif termsAgree.lower() == "n":
print("You must agree to the Terms of Service and Privacy Policy to use this tool.")
exit()
else:
print("Invalid input. Please enter 'y' or 'n'.")
# Go to main
main()
def parseArgs() -> argparse.Namespace:
"""
Takes the command line arguments, 'file' being a required one, and parses them, then returns them to main().
Dev Note: argparse isnt as bad as i remember - ArykDev xD
"""
parser = argparse.ArgumentParser(
prog="0x0py",
description="A simple command line tool to upload files to https://0x0.st.",
epilog="Made with blood, sweat, and tears by @ArykDev"
)
parser.add_argument("file", help="The file to upload.")
parser.add_argument("-u", "--url", help="Upload a remote URL instead of a file.")
args = parser.parse_args()
return args
def post() -> str:
"""
Final step! This function creates the POST request with the file and sends it off to 0x0.st
If everything goes well, we'll recieve a response with the link to the file.
"""
# Parse the command line arguments
args = parseArgs()
# Open the file in binary mode
with open(args.file, "rb") as f:
# Figure out file retention period using 0x0.st's formula
retention = round(30 + (-365 + 30) * pow(((os.path.getsize(args.file) / 1048576) / 512 - 1), 3))
# Make the POST request
response = requests.post(URL, files={"file": f})
# Print the response
return response.text, retention
def main() -> None:
response, retention = post()
print(f"Your file has been uploaded to {response}")
print(f"Your file will be deleted in approximately {retention} days.")
if __name__ == "__main__":
oneTimeSetup()