Advertisement
Guest User

Untitled

a guest
Jul 1st, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import requests
  2. import urllib3
  3.  
  4. # Suppress InsecureRequestWarning
  5. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  6.  
  7. def get_json(url):
  8. response = requests.get(url, verify=False)
  9. return response.json()
  10.  
  11. def download_file(url, sid, file_path):
  12. headers = {'Cookie': f'id={sid}'}
  13. response = requests.post(url, headers=headers, verify=False)
  14. if response.status_code == 200:
  15. with open(file_path, 'wb') as file:
  16. file.write(response.content)
  17. print(f"File successfully downloaded to: {file_path}")
  18. else:
  19. print("Failed to download the file.")
  20.  
  21. def main():
  22. host = "xxx"
  23. user = "xxx"
  24. password = "xxx."
  25.  
  26. # Login and obtain session ID
  27. login_url = f"https://{host}/webapi/auth.cgi?api=SYNO.API.Auth&method=login&version=3&account={user}&passwd={password}&session=FileStation&format=sid"
  28. login_response = get_json(login_url)
  29.  
  30. print(f"Login response: {login_response}")
  31.  
  32. if "data" in login_response and "sid" in login_response["data"]:
  33. sid = login_response["data"]["sid"]
  34. print(f"Login successful. Session ID: {sid}")
  35.  
  36. # URL to download the file
  37. download_url = f"https://{host}/webapi/entry.cgi?api=SYNO.ActiveBackupOffice365&method=download_file&version=1&SynoHash=bWP_dbnWIHl-lmFtCp1qNIvpoRwSrA.NzI&SynoToken=.vLMwHcu.wwuE"
  38. file_path = "C:\\scripts\\ActiveBackup_Activity_Log.csv"
  39.  
  40. # Download the file
  41. download_file(download_url, sid, file_path)
  42.  
  43. # Logout
  44. logout_url = f"https://{host}/webapi/auth.cgi?api=SYNO.API.Auth&method=logout&version=3&session=FileStation&_sid={sid}"
  45. logout_response = get_json(logout_url)
  46. if logout_response["success"]:
  47. print("Logout successful.")
  48. else:
  49. print("Logout failed.")
  50. else:
  51. print("Login failed. Check the username, password, or API endpoints.")
  52.  
  53. if __name__ == "__main__":
  54. main()
  55.  
Tags: Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement