You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.1 KiB
79 lines
3.1 KiB
import requests
|
|
import xml.etree.ElementTree as ET
|
|
import sys
|
|
|
|
# Prepare and send the propfind request return xml string
|
|
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
|
|
|
|
# Function iterates through the given xml which contains all files and folders in the provided path
|
|
def search_folder(requestreturn):
|
|
# List to collect path of folders stored in path
|
|
innerfolders = []
|
|
# List to collect path of files with wrong timestamp
|
|
linkswrongtime = []
|
|
# First folder provided in the xml file is always the folder we are currently in.
|
|
# To prevent searching this folder twice, or ending in a loop, we can not store this folder in the folderlist again.
|
|
firstfolder = True
|
|
# Name of files are stored as an string. But we can check the timestamp of the file after we can check the name,
|
|
# so it needs to be stored temporary in case the timestamp is wrong
|
|
temp = "this is sa temporary storage"
|
|
# Get a xml tree
|
|
tree = ET.ElementTree(ET.fromstring(requestreturn))
|
|
# Find all responses in the tree, those contain the fielpath, lasttimemodified, typeoffile etc.
|
|
for resp in tree.findall('.//{DAV:}response'):
|
|
# Here we can get the filpath out of href and get further information in prop (lastimemodified, typeoffile, etc.)
|
|
for p in resp:
|
|
# In case p.text is not none, it contains the filepath
|
|
if not(p.text is None):
|
|
if (p.text[-1] == '/'):
|
|
# If the current object is a folder, check it its not first folder
|
|
if not(firstfolder):
|
|
innerfolders.append(p.text)
|
|
else:
|
|
firstfolder = False
|
|
break
|
|
else:
|
|
temp = p.text
|
|
# In case p.text is none, it contains the further information
|
|
else:
|
|
# Find time last modfied and check if the year is before 1990
|
|
for time in p.findall('.//{DAV:}getlastmodified'):
|
|
year = time.text.split(' ')
|
|
if int(year[3]) < 1990:
|
|
linkswrongtime.append(temp)
|
|
return [innerfolders, linkswrongtime]
|
|
|
|
# Enter username and password to enter nextcloud via webdav
|
|
user = sys.argv[1]
|
|
passw = sys.argv[2]
|
|
auth = requests.auth.HTTPBasicAuth(user,passw)
|
|
# Prepare the path we want to use
|
|
prefix_path = "https://kingsx.cs.uni-saarland.de"
|
|
mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
|
|
# List of all folderpaths we need to enter
|
|
folders = [mainpath]
|
|
# List of all filepaths with wrong time
|
|
wrongtime = []
|
|
|
|
# Iterate through all folders and check for wrong timestamps
|
|
while folders:
|
|
path_suffix = folders.pop(0)
|
|
path = prefix_path + str(path_suffix)
|
|
r = propfind(path,auth)
|
|
res = search_folder(r)
|
|
# Append all found folders and files with wrong timestamps to global list
|
|
folders = folders + res[0]
|
|
wrongtime = wrongtime + res[1]
|
|
|
|
# Print out the list of all the filenames with the wrong time
|
|
print(wrongtime)
|
|
|
|
# By now just storage of suffix used to enter version files via FILEID
|
|
version_suffix = "/remote.php/dav/versions/USER/versions/FILEID"
|