Nextcloud crawler via WebDav
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
import requests
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def propfind(path,auth):
|
||||||
|
headers = {"Depth":"1"}
|
||||||
|
req = r = requests.Request("PROPFIND", path, headers=headers, auth=auth)
|
||||||
|
prepped = req.prepare()
|
||||||
|
|
||||||
|
s = requests.Session()
|
||||||
|
resp = s.send(prepped)
|
||||||
|
return resp.text
|
||||||
|
|
||||||
|
def search_folder(requestreturn):
|
||||||
|
innerfolders = []
|
||||||
|
linkswrongtime = []
|
||||||
|
firstfolder = True
|
||||||
|
temp = "this is sa temporary storage"
|
||||||
|
tree = ET.ElementTree(ET.fromstring(requestreturn))
|
||||||
|
for resp in tree.findall('.//{DAV:}response'):
|
||||||
|
for p in resp:
|
||||||
|
if not(p.text is None):
|
||||||
|
if (p.text[-1] == '/'):
|
||||||
|
if not(firstfolder):
|
||||||
|
innerfolders.append(p.text)
|
||||||
|
else:
|
||||||
|
firstfolder = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
temp = p.text
|
||||||
|
else:
|
||||||
|
for time in p.findall('.//{DAV:}getlastmodified'):
|
||||||
|
year = time.text.split(' ')
|
||||||
|
if int(year[3]) < 1990:
|
||||||
|
linkswrongtime.append(temp)
|
||||||
|
return [innerfolders, linkswrongtime]
|
||||||
|
|
||||||
|
user = sys.arcv[1]
|
||||||
|
passw = sys.arcv[2]
|
||||||
|
auth = requests.auth.HTTPBasicAuth(user,passw)
|
||||||
|
prefix_path = "https://kingsx.cs.uni-saarland.de"
|
||||||
|
mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
|
||||||
|
folders = [mainpath]
|
||||||
|
wrongtime = []
|
||||||
|
|
||||||
|
while folders:
|
||||||
|
path_suffix = folders.pop(0)
|
||||||
|
path = prefix_path + str(path_suffix)
|
||||||
|
r = propfind(path,auth)
|
||||||
|
res = search_folder(r)
|
||||||
|
folders = folders + res[0]
|
||||||
|
wrongtime = wrongtime + res[1]
|
||||||
|
|
||||||
|
print(wrongtime)
|
||||||
|
|
||||||
|
version_suffix = "/remote.php/dav/versions/USER/versions/FILEID"
|
||||||
Reference in New Issue
Block a user