Skip to content

Commit

Permalink
Added debug mode for easy authentication
Browse files Browse the repository at this point in the history
See doc
  • Loading branch information
ukdtom committed Feb 13, 2016
1 parent c6ff580 commit 130391f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Binary file modified Contents/Code/Docs/webtools-README_DEVS.odt
Binary file not shown.
10 changes: 9 additions & 1 deletion Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
VERSION = '2.2'
AUTHTOKEN = ''
SECRETKEY = ''
DEBUGMODE = False


#********** Imports needed *********
Expand All @@ -33,6 +34,13 @@
#********** Initialize *********
def Start():
global SECRETKEY
global VERSION
global DEBUGMODE
# Switch to debug mode if needed
debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
DEBUGMODE = os.path.isfile(debugFile)
if DEBUGMODE:
VERSION = VERSION + ' ****** WARNING Debug mode on *********'
PLUGIN_VERSION = VERSION
print("******** Started %s on %s **********" %(NAME + ' V' + PLUGIN_VERSION, Platform.OS))
Log.Debug("******* Started %s on %s ***********" %(NAME + ' V' + PLUGIN_VERSION, Platform.OS))
Expand All @@ -45,7 +53,7 @@ def Start():

# Get the secret key used to access the PMS framework ********** FUTURE USE ***************
SECRETKEY = genSecretKeyAsStr()
startWeb(SECRETKEY)
startWeb(SECRETKEY, VERSION, DEBUGMODE)

####################################################################################################
# Generate secret key
Expand Down
25 changes: 17 additions & 8 deletions Contents/Code/webSrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def get(self):

def post(self):
global AUTHTOKEN
# Allow no password when in debug mode
if DEBUGMODE:
self.allow()
Log.Info('All is good, we are authenticated')
self.redirect('/')

# Let's start by checking if the server is online
if plexTV().auth2myPlex():
token = ''
Expand Down Expand Up @@ -166,10 +172,13 @@ def get(self, **params):
self.write(webTools().getVersion())

class webTools2Handler(BaseHandler):
# Disable auth when debug
def prepare(self):
if DEBUGMODE:
self.set_secure_cookie(NAME, Hash.MD5(Dict['SharedSecret']+Dict['password']), expires_days = None)

#******* GET REQUEST *********
@authenticated
# print '********** AUTH DISABLED WebSRV WebTools2 GET'

# Get Request
def get(self, **params):
module = self.get_argument('module', 'missing')
Expand Down Expand Up @@ -212,7 +221,6 @@ def get(self, **params):

#******* POST REQUEST *********
@authenticated
# print '********** AUTH DISABLED WebSRV WebTools2 POST'
def post(self, **params):
module = self.get_argument('module', 'missing')
if module == 'missing':
Expand All @@ -238,7 +246,6 @@ def post(self, **params):

#******* DELETE REQUEST *********
@authenticated
# print '********** AUTH DISABLED WebSRV WebTools2 DELETE'
def delete(self, **params):
module = self.get_argument('module', 'missing')
if module == 'missing':
Expand All @@ -258,8 +265,6 @@ def delete(self, **params):

#******* PUT REQUEST *********
@authenticated
# print '********** AUTH DISABLED WebSRV WebTools2 PUT'

def put(self, **params):
module = self.get_argument('module', 'missing')
if module == 'missing':
Expand Down Expand Up @@ -337,10 +342,14 @@ def stopWeb():
Log.Debug('Asked Tornado to exit')

''' Main call '''
def startWeb(secretKey):
global SECRETKEY
def startWeb(secretKey, version, debugmode):
global SECRETKEY
# Set the secret key for use by other calls in the future maybe?
SECRETKEY = secretKey
global VERSION
VERSION = version
global DEBUGMODE
DEBUGMODE = debugmode
stopWeb()
Log.Debug('tornado is handling the following URI: %s' %(handlers))
t = threading.Thread(target=start_tornado)
Expand Down

0 comments on commit 130391f

Please sign in to comment.