mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-09 16:22:48 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e66da62db3 | ||
|
|
c06a97378c | ||
|
|
33cb8d987d |
@@ -14,7 +14,7 @@ location /auth {
|
|||||||
proxy_pass_request_headers off;
|
proxy_pass_request_headers off;
|
||||||
# Pass info about the request
|
# Pass info about the request
|
||||||
proxy_set_header X-Original-Method $request_method;
|
proxy_set_header X-Original-Method $request_method;
|
||||||
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
|
proxy_set_header X-Original-URL $request_uri;
|
||||||
proxy_set_header X-Server-Port $server_port;
|
proxy_set_header X-Server-Port $server_port;
|
||||||
proxy_set_header Content-Length "";
|
proxy_set_header Content-Length "";
|
||||||
# Pass along auth related info
|
# Pass along auth related info
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "Upgrade";
|
proxy_set_header Connection "Upgrade";
|
||||||
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
|
proxy_set_header X-Original-URL $request_uri;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_set_header X-Forwarded-Host $http_host;
|
proxy_set_header X-Forwarded-Host $http_host;
|
||||||
proxy_set_header X-Forwarded-URI $request_uri;
|
proxy_set_header X-Forwarded-URI $request_uri;
|
||||||
|
|||||||
@@ -41,6 +41,20 @@ class PushNotification:
|
|||||||
ttl: int = 0
|
ttl: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
def _build_web_pushers(user: str, subs: list[dict[str, Any]]) -> list[WebPusher]:
|
||||||
|
"""Build pushers for a user's stored subscriptions, skipping unusable ones."""
|
||||||
|
pushers: list[WebPusher] = []
|
||||||
|
|
||||||
|
for sub in subs:
|
||||||
|
# WebPusher decodes the stored keys and raises on malformed ones
|
||||||
|
try:
|
||||||
|
pushers.append(WebPusher(sub))
|
||||||
|
except Exception:
|
||||||
|
logger.warning("Skipping invalid notification subscription for %s", user)
|
||||||
|
|
||||||
|
return pushers
|
||||||
|
|
||||||
|
|
||||||
class WebPushClient(Communicator):
|
class WebPushClient(Communicator):
|
||||||
"""Frigate wrapper for webpush client."""
|
"""Frigate wrapper for webpush client."""
|
||||||
|
|
||||||
@@ -82,9 +96,9 @@ class WebPushClient(Communicator):
|
|||||||
User.select(User.username, User.notification_tokens).dicts().iterator()
|
User.select(User.username, User.notification_tokens).dicts().iterator()
|
||||||
)
|
)
|
||||||
for user in users:
|
for user in users:
|
||||||
self.web_pushers[user["username"]] = []
|
self.web_pushers[user["username"]] = _build_web_pushers(
|
||||||
for sub in user["notification_tokens"]:
|
user["username"], user["notification_tokens"]
|
||||||
self.web_pushers[user["username"]].append(WebPusher(sub))
|
)
|
||||||
|
|
||||||
# notification and auth config updater
|
# notification and auth config updater
|
||||||
self.global_config_subscriber = ConfigSubscriber("config/")
|
self.global_config_subscriber = ConfigSubscriber("config/")
|
||||||
@@ -142,10 +156,7 @@ class WebPushClient(Communicator):
|
|||||||
User.username == user
|
User.username == user
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
self.web_pushers[user] = []
|
self.web_pushers[user] = _build_web_pushers(user, user_subs)
|
||||||
|
|
||||||
for sub in user_subs:
|
|
||||||
self.web_pushers[user].append(WebPusher(sub))
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Cleaned up {len(expired)} notification subscriptions for {user}"
|
f"Cleaned up {len(expired)} notification subscriptions for {user}"
|
||||||
|
|||||||
@@ -170,12 +170,7 @@ class CustomStateClassificationProcessor(DeferredRealtimeProcessorApi):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def process_frame(self, frame_data: dict[str, Any], frame: np.ndarray) -> None:
|
def process_frame(self, frame_data: dict[str, Any], frame: np.ndarray) -> None:
|
||||||
if (
|
if not self.model_config.name or not self.model_config.state_config:
|
||||||
not self.model_config.name
|
|
||||||
or not self.model_config.state_config
|
|
||||||
or not self.tensor_input_details
|
|
||||||
or not self.tensor_output_details
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.metrics and self.model_config.name in self.metrics.classification_cps:
|
if self.metrics and self.model_config.name in self.metrics.classification_cps:
|
||||||
@@ -515,12 +510,7 @@ class CustomObjectClassificationProcessor(DeferredRealtimeProcessorApi):
|
|||||||
return best_label, avg_score
|
return best_label, avg_score
|
||||||
|
|
||||||
def process_frame(self, obj_data: dict[str, Any], frame: np.ndarray) -> None:
|
def process_frame(self, obj_data: dict[str, Any], frame: np.ndarray) -> None:
|
||||||
if (
|
if not self.model_config.name or not self.model_config.object_config:
|
||||||
not self.model_config.name
|
|
||||||
or not self.model_config.object_config
|
|
||||||
or not self.tensor_input_details
|
|
||||||
or not self.tensor_output_details
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.metrics and self.model_config.name in self.metrics.classification_cps:
|
if self.metrics and self.model_config.name in self.metrics.classification_cps:
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
"""Tests for push notification subscription validation."""
|
"""Tests for push notification subscription validation."""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
from base64 import urlsafe_b64encode
|
||||||
|
|
||||||
from frigate.api.notification import _validate_push_endpoint, _validate_subscription
|
from frigate.api.notification import _validate_push_endpoint, _validate_subscription
|
||||||
|
from frigate.comms.webpush import _build_web_pushers
|
||||||
|
|
||||||
VALID_ENDPOINTS = [
|
VALID_ENDPOINTS = [
|
||||||
"https://fcm.googleapis.com/fcm/send/dGhpcy1pcy1hLXRva2Vu",
|
"https://fcm.googleapis.com/fcm/send/dGhpcy1pcy1hLXRva2Vu",
|
||||||
@@ -148,3 +150,16 @@ class TestValidateSubscription(unittest.TestCase):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
class TestBuildWebPushers(unittest.TestCase):
|
||||||
|
def test_skips_subscriptions_with_malformed_keys(self):
|
||||||
|
bad = _subscription(VALID_ENDPOINTS[0])
|
||||||
|
good = _subscription(VALID_ENDPOINTS[0])
|
||||||
|
good["keys"]["p256dh"] = urlsafe_b64encode(b"\x04" + bytes(64)).decode()
|
||||||
|
|
||||||
|
with self.assertLogs("frigate.comms.webpush", level="WARNING"):
|
||||||
|
pushers = _build_web_pushers("viewer", [bad, good])
|
||||||
|
|
||||||
|
self.assertEqual(len(pushers), 1)
|
||||||
|
self.assertEqual(pushers[0].receiver_key, b"\x04" + bytes(64))
|
||||||
|
|||||||
Reference in New Issue
Block a user