mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 09:56:57 -05:00
Add Detection of Internal API calls
This commit is contained in:
parent
e7e4ddcade
commit
2cf0f3d891
@ -19,6 +19,8 @@ class fHDHR_API_URLs():
|
|||||||
self.config = settings
|
self.config = settings
|
||||||
self.web = web
|
self.web = web
|
||||||
|
|
||||||
|
self.headers = {'User-Agent': "fHDHR/%s" % self.config.internal["versions"]["fHDHR"]}
|
||||||
|
|
||||||
# Replaced later
|
# Replaced later
|
||||||
self.client = Fillin_Client(settings, web)
|
self.client = Fillin_Client(settings, web)
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
|
|||||||
# Perform some actions now that HTTP Server is running
|
# Perform some actions now that HTTP Server is running
|
||||||
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
|
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
fhdhr.api.client.get("/api/startup_tasks")
|
fhdhr.api.client.get("/api/startup_tasks", headers=fhdhr.api.headers)
|
||||||
|
|
||||||
# wait forever
|
# wait forever
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@ -63,6 +63,10 @@ class fHDHR_HTTP_Server():
|
|||||||
|
|
||||||
def before_request(self):
|
def before_request(self):
|
||||||
|
|
||||||
|
session["is_internal_api"] = self.detect_internal_api(request)
|
||||||
|
if session["is_internal_api"]:
|
||||||
|
self.fhdhr.logger.debug("Client is using internal API call.")
|
||||||
|
|
||||||
session["is_mobile"] = self.detect_mobile(request)
|
session["is_mobile"] = self.detect_mobile(request)
|
||||||
if session["is_mobile"]:
|
if session["is_mobile"]:
|
||||||
self.fhdhr.logger.debug("Client is a mobile device.")
|
self.fhdhr.logger.debug("Client is a mobile device.")
|
||||||
@ -79,6 +83,15 @@ class fHDHR_HTTP_Server():
|
|||||||
self.fhdhr.logger.debug("Client %s requested %s Closing" % (request.method, request.path))
|
self.fhdhr.logger.debug("Client %s requested %s Closing" % (request.method, request.path))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def detect_internal_api(self, request):
|
||||||
|
user_agent = request.headers.get('User-Agent')
|
||||||
|
if not user_agent:
|
||||||
|
return False
|
||||||
|
elif str(user_agent).lower().startswith("fhdhr"):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def detect_deviceauth(self, request):
|
def detect_deviceauth(self, request):
|
||||||
return request.args.get('DeviceAuth', default=None, type=str)
|
return request.args.get('DeviceAuth', default=None, type=str)
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,10 @@ class Startup_Tasks():
|
|||||||
updatechannels = True
|
updatechannels = True
|
||||||
|
|
||||||
if updatechannels:
|
if updatechannels:
|
||||||
self.fhdhr.api.client.get(self.channel_update_url)
|
self.fhdhr.api.client.get(self.channel_update_url, headers=self.fhdhr.api.headers)
|
||||||
|
|
||||||
# Hit EPG Update API
|
# Hit EPG Update API
|
||||||
for epg_method in self.fhdhr.device.epg.epg_methods:
|
for epg_method in self.fhdhr.device.epg.epg_methods:
|
||||||
self.fhdhr.api.client.get("%s?sorurce=%s" % (self.epg_update_url, epg_method))
|
self.fhdhr.api.client.get("%s?sorurce=%s" % (self.epg_update_url, epg_method), headers=self.fhdhr.api.headers)
|
||||||
|
|
||||||
return "Success"
|
return "Success"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user