danb35 / deploy-freenas

Python script to automate deploying TLS certificates to FreeNAS servers
GNU General Public License v3.0
202 stars 56 forks source link

Error reloading WebUI! 405: Method Not Allowed #38

Closed sirmicrochip closed 3 years ago

sirmicrochip commented 3 years ago

Hi Dan,

I moved this week to a new Truenas server and i'm currently setting up a Lets Encrypt certificate with acme.sh and deploy-freenas again.

I have used the same settings in the deploy_config file as i used on my old server. (i only changed the paths for my key and fullchain files)

when i run the script i get the following output:

[root@takarabako: ]$ ./deploy_freenas.py Certificate import successful Certificate list successful Setting active certificate successful Deleting certificate letsencrypt-2021-04-17-234247 successful Error reloading WebUI! 405: Method Not Allowed

Unfortunately the WebUI does not reload and returns a 405.

i have installed the latest version of deploy-freenas. i run TrueNAS-12.0-U3 (my previous server had TrueNAS-12.0-U2.1)

I tried various changes in the deploy_config settings for host, fqdn, verify, protocol and port, but all options give the same output. It looks like the problem is not the connection to the api since the new certificate is added and such.

Please let me know if you need any output or config settings.

Kind regards, Frank

danb35 commented 3 years ago

This looks like an upstream bug. See: https://jira.ixsystems.com/browse/NAS-110243

wyattmcgehee commented 3 years ago

Hi Dan! Your script is immensely useful. I'm on mobile, so can't test this, but I think something like this would work as a workaround. Gets the system version string, and if -U3, does a put instead of a get. I think that's what you were talking about in your linked bug.

# Reload nginx with new cert
# If everything goes right, the request fails with a ConnectionError
try:
  r = session.get(
    PROTOCOL + FREENAS_ADDRESS + ':' + PORT + '/api/v2.0/system/version'
  )
  if r.text == "TrueNAS-12.0-U3":
    r = session.put(
      PROTOCOL + FREENAS_ADDRESS + ':' + PORT + '/api/v2.0/system/general/ui_restart',
      verify=VERIFY
    )
  else:
    r = session.get(
      PROTOCOL + FREENAS_ADDRESS + ':' + PORT + '/api/v2.0/system/general/ui_restart',
      verify=VERIFY
    )
  # If we've arrived here, something went wrong
  print ("Error reloading WebUI!")
  print (r.text)
  sys.exit(1)
except requests.exceptions.ConnectionError:
  print ("Reloading WebUI successful")
  print ("deploy_freenas.py executed successfully")
danb35 commented 3 years ago

Thanks for the suggestion, but I think I'm going to need to do it a little differently. Discussion at that bug (and in this thread) indicates that it's a deliberate change that they somehow didn't understand would break things, but they aren't going to revert it--so just checking for -U3 won't do, as -U4 and subsequent versions are expected to behave the same way (until they change it again without warning).

I think the logic is going to need to go like this:

It might be better to invert those two and try the POST first; I'm not sure if that would make a difference. Edit: I think it would be easier that way. Here's what I've come up with with a little banging around, let me test and see how it works:

# Reload nginx with new cert
# If everything goes right in 12.0-U3 and later, it returns 200
# If everything goes right with an earlier release, the request
# fails with a ConnectionError
r = session.post(
  PROTOCOL + FREENAS_ADDRESS + ':' + PORT + '/api/v2.0/system/general/ui_restart',
  verify=VERIFY
)
if r.status_code == 200:
  print ("Reloading WebUI successful")
  print ("deploy_freenas.py executed successfully")
  sys.exit(0)
elif r.status_code != 405:
  print ("Error reloading WebUI!")
  print (r.text)
  sys.exit(1)
else:
  try:
    r = session.get(
      PROTOCOL + FREENAS_ADDRESS + ':' + PORT + '/api/v2.0/system/general/ui_restart',
      verify=VERIFY
    )
    # If we've arrived here, something went wrong
    print ("Error reloading WebUI!")
    print (r.text)
    sys.exit(1)
  except requests.exceptions.ConnectionError:
    print ("Reloading WebUI successful")
    print ("deploy_freenas.py executed successfully")