| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -6,6 +6,9 @@ import xml.etree.ElementTree as ET | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import requests | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					# some constants | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					FILES_PATH_PREFIX = "/remote.php/dav/files/" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					VERSIONS_PATH_PREFIX = "/remote.php/dav/versions/" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					# we only need one session for the whole script | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					session = requests.Session() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -30,14 +33,16 @@ def propfind(path, auth): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					       """ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    req = requests.Request("PROPFIND", path, headers=headers, auth=auth, data=requested_data) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    resp = session.send(req.prepare()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    print(resp.text) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    return resp.text | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					def search_folder(requestreturn): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    """ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    Iterates through a folder's properties XML and returns | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    :param requestreturn: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    :return: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    Iterates through a folder's properties XML and find entries with invalid timestamps | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    :param requestreturn: The XML returned by propfind() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    :return: A tuple of two lists. The first list contains all subfolders, the second contains all FileIDs of entries | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             with an invalid timestamp. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    """ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # List to collect path of folders stored in path | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    innerfolders = [] | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -67,7 +72,8 @@ def search_folder(requestreturn): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    # this function converts the given date to unix timestamp | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    lastmodified = time.mktime( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    # 631148400 is the unix timestamp of 01.01.1990 00:00:00, because we know there is no file older than this in our nextcloud system | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    # 631148400 is the unix timestamp of 01.01.1990 00:00:00, because we know there is no file older | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    # than this in our nextcloud | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if lastmodified < 631148400: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        for fileid in p.findall('.//{http://owncloud.org/ns}fileid'): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            linkswrongtime.append(fileid.text) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -129,7 +135,7 @@ if __name__ == "__main__": | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # Prepare HTTP Basic Authentication | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    auth = requests.auth.HTTPBasicAuth(arguments.username, arguments.password) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # Prepare the path we want to use | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    mainpath = "/remote.php/dav/files/" + arguments.username + arguments.search_path | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    mainpath = FILES_PATH_PREFIX + arguments.username + arguments.search_path | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # List of all folders we need to enter | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    folders = [mainpath] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # List of all fileids with wrong time | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -147,7 +153,7 @@ if __name__ == "__main__": | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # Iterate through all fileids with wrong timestamps and check for versions with intact timestamp | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        while wrongtime: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            fileid = wrongtime.pop(0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            version_suffix = "/remote.php/dav/versions/" + arguments.username + "/versions/" + fileid | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            version_suffix = VERSIONS_PATH_PREFIX + arguments.username + "/versions/" + fileid | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            version_path = arguments.server + version_suffix | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            versions = propfind(version_path, auth) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            mrv = version_check(versions) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |