-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclone1.py
executable file
·42 lines (36 loc) · 1.15 KB
/
clone1.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
#! /usr/bin/python3
import subprocess, sys, string, os, shutil
from zipfile import ZipFile
from os.path import basename
url = sys.argv[1]
WHITELIST = string.ascii_letters + "."
DIR = "/home/zip"
def check_url(url):
prefix = 0
if url.startswith('http://'):
prefix = 7
elif url.startswith('https://'):
prefix = 8
else:
return False
for l in url[prefix:]:
if l not in WHITELIST:
return False
return True
if check_url(url):
name = basename(url)
# Clone the site
p1 = subprocess.Popen(['wget', '-nc', '-r', '-l', 'inf', '--no-remove-listing', '-q', '-P', '/tmp', url])
p1.wait()
# Create a zip file
with ZipFile(f'/tmp/{name}.zip', 'w') as zipObj:
for folderName, subfolders, filenames in os.walk(f"/tmp/{name}"):
for filename in filenames:
filePath = os.path.join(folderName, filename)
zipObj.write(filePath, basename(filePath))
# Move file to right folder
shutil.move(f"/tmp/{name}.zip", f"{DIR}/{name}.zip")
os.chmod(f"{DIR}/{name}.zip", 0o777)
shutil.rmtree(f"/tmp/{name}")
else:
print('[!] Invalid URL')