Make shutdown slug use http basic auth also, so the shutdown command doesnt fail with a 401

This commit is contained in:
Micah Lee 2019-05-20 20:01:14 -07:00
parent b667fcc4f8
commit 3229211422
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -5,6 +5,7 @@ import queue
import socket import socket
import sys import sys
import tempfile import tempfile
import requests
from distutils.version import LooseVersion as Version from distutils.version import LooseVersion as Version
from urllib.request import urlopen from urllib.request import urlopen
@ -131,6 +132,8 @@ class Web(object):
def get_pw(username): def get_pw(username):
if username == 'onionshare': if username == 'onionshare':
return self.slug return self.slug
elif username == 'shutdown':
return self.shutdown_slug
else: else:
return None return None
@ -293,14 +296,8 @@ class Web(object):
# Reset any slug that was in use # Reset any slug that was in use
self.slug = None self.slug = None
# To stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown # To stop flask, load http://shutdown:[shutdown_slug]@127.0.0.1/[shutdown_slug]/shutdown
# (We're putting the shutdown_slug in the path as well to make routing simpler)
if self.running: if self.running:
try: requests.get('http://127.0.0.1:{}/{}/shutdown'.format(port, self.shutdown_slug),
s = socket.socket() auth=requests.auth.HTTPBasicAuth('shutdown', self.shutdown_slug))
s.connect(('127.0.0.1', port))
s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(self.shutdown_slug))
except:
try:
urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, self.shutdown_slug)).read()
except:
pass