diff --git a/fHDHR/api/__init__.py b/fHDHR/api/__init__.py index 37651d9..432e74d 100644 --- a/fHDHR/api/__init__.py +++ b/fHDHR/api/__init__.py @@ -19,6 +19,8 @@ class fHDHR_API_URLs(): self.config = settings self.web = web + self.headers = {'User-Agent': "fHDHR/%s" % self.config.internal["versions"]["fHDHR"]} + # Replaced later self.client = Fillin_Client(settings, web) diff --git a/fHDHR/cli/run.py b/fHDHR/cli/run.py index 54c5e8c..96fcba4 100644 --- a/fHDHR/cli/run.py +++ b/fHDHR/cli/run.py @@ -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 fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.") time.sleep(3) - fhdhr.api.client.get("/api/startup_tasks") + fhdhr.api.client.get("/api/startup_tasks", headers=fhdhr.api.headers) # wait forever while True: diff --git a/fHDHR_web/__init__.py b/fHDHR_web/__init__.py index 2cfa7c3..9c31486 100644 --- a/fHDHR_web/__init__.py +++ b/fHDHR_web/__init__.py @@ -63,6 +63,10 @@ class fHDHR_HTTP_Server(): 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) if session["is_mobile"]: 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)) 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): return request.args.get('DeviceAuth', default=None, type=str) diff --git a/fHDHR_web/api/startup_tasks.py b/fHDHR_web/api/startup_tasks.py index cb802e9..7cad41f 100644 --- a/fHDHR_web/api/startup_tasks.py +++ b/fHDHR_web/api/startup_tasks.py @@ -25,10 +25,10 @@ class Startup_Tasks(): updatechannels = True 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 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"