# Copyright Trimble Inc 2022
#
# See the companion file fuzzProxy.py which creates "FuzzURLs.txt". This
# script replays the URLs to a receiver, e.g. if you used fuzzProxy.py and 
# managed to crash the receiver, you can replay the same URLs to see if 
# an update fixes the problem.
#
# No error checking, assumes admin:password - if this is useful, extend it!


import RXTools as rx
import sys

if(len(sys.argv) != 2):
  print('Need IP address')
  sys.exit()

IPAddr = sys.argv[1]
print(IPAddr)

with open('FuzzURLs.txt','r') as fid:
  numLinks = 0
  for line in fid:
    line = line.strip()
    
    # Deal with "CACHEDIR"
    tokens = line.split('/')
    url = tokens[0]
    for thisToken in tokens[1:]:
      if('CACHEDIR' not in thisToken):
        # New firmware may have changed the "CACHE" string, remove as it is 
        # not necessary
        url += '/' + thisToken
    try:
      ret = rx.SendHttpGet(IPAddr,url,'admin','password',verbose=False)
    except:
      print('Problem with:',url)

    if( (numLinks % 10) == 0):
      print(numLinks)
    numLinks += 1

