From 15f1adade6a6980679090c3616374cb1331a532c Mon Sep 17 00:00:00 2001 From: Moleus Date: Wed, 5 Nov 2025 14:17:29 +0300 Subject: [PATCH 1/4] fix go template indices --- templates/home.html.tmpl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/templates/home.html.tmpl b/templates/home.html.tmpl index ee8d885..4ac31b6 100644 --- a/templates/home.html.tmpl +++ b/templates/home.html.tmpl @@ -80,14 +80,18 @@ {{ range $index, $ac := $placeEl.Place.AccessControls }} {{$snapshotUrl := getSnapshotUrl $.BaseURL $placeEl.Place.ID $ac.ID }} {{$streamUrl := "Camera for this index not found ;("}} - {{ with (index $.Cameras.Data $index) }} - {{$streamUrl = getCameraStreamUrl $.BaseURL .ID }} + {{$cameraId := ""}} + {{ if lt $index (len $.Cameras.Data) }} + {{ with (index $.Cameras.Data $index) }} + {{$streamUrl = getCameraStreamUrl $.BaseURL .ID }} + {{$cameraId = printf "№ %d" .ID }} + {{ end }} {{ end }} {{$openDoorUrl := getOpenDoorUrl $.BaseURL $placeEl.Place.ID $ac.ID }}
Камера:
-
№ {{ (index $.Cameras.Data $index).ID }}
+
{{ $cameraId }}
Адрес:
From a12c0754d78ba8094266a502a813dfec2ee212f2 Mon Sep 17 00:00:00 2001 From: Moleus Date: Wed, 5 Nov 2025 14:17:45 +0300 Subject: [PATCH 2/4] fix(proxy): forward host header --- pkg/reverseproxy/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/reverseproxy/main.go b/pkg/reverseproxy/main.go index 9f013db..e49158e 100644 --- a/pkg/reverseproxy/main.go +++ b/pkg/reverseproxy/main.go @@ -22,6 +22,7 @@ func (p *ReverseProxy) ProxyRequestHandler() func(http.ResponseWriter, *http.Req // Step 1: rewrite URL req.URL.Scheme = p.target.Scheme req.URL.Host = p.target.Host + req.Host = p.target.Host // CRITICAL: Set Host header for upstream (fixes 403 errors) req.RequestURI = "" resp, err := p.Client.Do(req) From 44b12fbb60e586e6d51c752e36c2812f8a08f941 Mon Sep 17 00:00:00 2001 From: Moleus Date: Wed, 5 Nov 2025 14:18:22 +0300 Subject: [PATCH 3/4] fix(auth): url encode + sign number --- pkg/auth/phone_number.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/auth/phone_number.go b/pkg/auth/phone_number.go index 55ef423..62d7ebe 100644 --- a/pkg/auth/phone_number.go +++ b/pkg/auth/phone_number.go @@ -3,6 +3,7 @@ package auth import ( "fmt" "net/http" + "net/url" "regexp" "strconv" @@ -57,7 +58,8 @@ func (a *PhoneNumberAuthenticator) isPhoneNumberValid() bool { } func (a *PhoneNumberAuthenticator) requestConfirmationCode(account models.Account) error { - confirmURL := fmt.Sprintf("%s/auth/v2/confirmation/%s", constants.BaseUrl, a.phoneNumber) + // Properly encode phone number for URL (+ becomes %2B) + confirmURL := fmt.Sprintf("%s/auth/v2/confirmation/%s", constants.BaseUrl, url.PathEscape(a.phoneNumber)) if account.AccountID == nil { return fmt.Errorf("account id is nil. Account: %v", account) } @@ -74,7 +76,8 @@ func (a *PhoneNumberAuthenticator) requestConfirmationCode(account models.Accoun } func (a *PhoneNumberAuthenticator) sendConfirmationCode(smsCode string, account models.Account) (models.AuthenticationResponse, error) { - confirmURL := fmt.Sprintf("%s/auth/v3/auth/%s/confirmation", constants.BaseUrl, a.phoneNumber) + // Properly encode phone number for URL (+ becomes %2B) + confirmURL := fmt.Sprintf("%s/auth/v3/auth/%s/confirmation", constants.BaseUrl, url.PathEscape(a.phoneNumber)) if account.ProfileID == nil { return models.AuthenticationResponse{}, fmt.Errorf("profile id is nil. Account: %v", account) } From dd2870da1b09792cde79d4de01845d5bd0219cf8 Mon Sep 17 00:00:00 2001 From: Moleus Date: Wed, 5 Nov 2025 14:19:23 +0300 Subject: [PATCH 4/4] fix(upstream): update domru domain --- cmd/controllers/login_accounts.go | 2 +- main.go | 2 +- pkg/auth/phone_number.go | 4 ++-- pkg/domru/apiWrapper.go | 5 +++-- pkg/domru/constants/main.go | 4 +--- pkg/domru/helpers/upstream_request.go | 9 +++++---- pkg/tokenmanagement/main.go | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/controllers/login_accounts.go b/cmd/controllers/login_accounts.go index 99e78f5..bc55bd5 100644 --- a/cmd/controllers/login_accounts.go +++ b/cmd/controllers/login_accounts.go @@ -38,7 +38,7 @@ func (h *Handler) SelectAccountHandler(w http.ResponseWriter, r *http.Request) { authenticator := auth.NewPhoneNumberAuthenticator(phoneNumber) requestErr := authenticator.RequestSmsCode(selectedAccount) if requestErr != nil { - http.Error(w, fmt.Sprintf("Failed to request confirmation code: %v", err), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("Failed to request confirmation code: %v", requestErr), http.StatusInternalServerError) return } diff --git a/main.go b/main.go index f4c15ce..bab77dc 100644 --- a/main.go +++ b/main.go @@ -91,7 +91,7 @@ func main() { handlers := controllers.NewHandlers(templateFs, credentialsStore, domruAPI) handlers.Logger = logger - upstream, err := url.Parse(constants.BaseUrl) + upstream, err := url.Parse(constants.BaseURL) if err != nil { log.Fatal(err) } diff --git a/pkg/auth/phone_number.go b/pkg/auth/phone_number.go index 62d7ebe..80ef2cd 100644 --- a/pkg/auth/phone_number.go +++ b/pkg/auth/phone_number.go @@ -59,7 +59,7 @@ func (a *PhoneNumberAuthenticator) isPhoneNumberValid() bool { func (a *PhoneNumberAuthenticator) requestConfirmationCode(account models.Account) error { // Properly encode phone number for URL (+ becomes %2B) - confirmURL := fmt.Sprintf("%s/auth/v2/confirmation/%s", constants.BaseUrl, url.PathEscape(a.phoneNumber)) + confirmURL := fmt.Sprintf("%s/auth/v2/confirmation/%s", constants.BaseURL, url.PathEscape(a.phoneNumber)) if account.AccountID == nil { return fmt.Errorf("account id is nil. Account: %v", account) } @@ -77,7 +77,7 @@ func (a *PhoneNumberAuthenticator) requestConfirmationCode(account models.Accoun func (a *PhoneNumberAuthenticator) sendConfirmationCode(smsCode string, account models.Account) (models.AuthenticationResponse, error) { // Properly encode phone number for URL (+ becomes %2B) - confirmURL := fmt.Sprintf("%s/auth/v3/auth/%s/confirmation", constants.BaseUrl, url.PathEscape(a.phoneNumber)) + confirmURL := fmt.Sprintf("%s/auth/v3/auth/%s/confirmation", constants.BaseURL, url.PathEscape(a.phoneNumber)) if account.ProfileID == nil { return models.AuthenticationResponse{}, fmt.Errorf("profile id is nil. Account: %v", account) } diff --git a/pkg/domru/apiWrapper.go b/pkg/domru/apiWrapper.go index 8bba203..3a7a9e4 100644 --- a/pkg/domru/apiWrapper.go +++ b/pkg/domru/apiWrapper.go @@ -21,7 +21,7 @@ type APIWrapper struct { } func NewDomruAPI(authClient myhttp.HTTPClient) *APIWrapper { - return &APIWrapper{authClient: authClient, baseURL: constants.BaseUrl, Logger: slog.Default()} + return &APIWrapper{authClient: authClient, baseURL: constants.BaseURL, Logger: slog.Default()} } func (w *APIWrapper) LoginWithPassword(accountID, password string) (models.AuthenticationResponse, error) { @@ -79,7 +79,8 @@ func (w *APIWrapper) RequestFinances() (models.FinancesResponse, error) { func (w *APIWrapper) RequestAccounts(phone string) ([]models.Account, error) { var accounts []models.Account - loginURL := fmt.Sprintf("%s/auth/v2/login/%s", w.baseURL, phone) + // Properly encode phone number for URL (+ becomes %2B) + loginURL := fmt.Sprintf("%s/auth/v2/login/%s", w.baseURL, url.PathEscape(phone)) err := helpers.NewUpstreamRequest(loginURL).Send(http.MethodGet, &accounts) if err != nil { return nil, fmt.Errorf("request accounts: %w", err) diff --git a/pkg/domru/constants/main.go b/pkg/domru/constants/main.go index 588a607..b8819af 100644 --- a/pkg/domru/constants/main.go +++ b/pkg/domru/constants/main.go @@ -3,13 +3,11 @@ package constants import "fmt" const ( - BaseUrl = "https://myhome.novotelecom.ru" + BaseURL = "https://myhome.proptech.ru" USERAGENT_TEMPLATE = "Google sdkgphone64x8664 | Android 14 | erth | 8.9.2 (8090200)" API_HA_NETWORK = "http://supervisor/network/info" - API_AUTH = "https://api-auth.domru.ru/v1/person/auth" - API_AUTH_LOGIN = "%s/auth/v2/login/%s" API_AUTH_CONFIRMATION = "%s/auth/v2/confirmation/%s" API_AUTH_CONFIRMATION_SMS = "%s/auth/v2/auth/%s/confirmation" diff --git a/pkg/domru/helpers/upstream_request.go b/pkg/domru/helpers/upstream_request.go index 74add29..9c653f0 100644 --- a/pkg/domru/helpers/upstream_request.go +++ b/pkg/domru/helpers/upstream_request.go @@ -15,10 +15,11 @@ import ( ) var defaultHeaders = map[string]string{ - "user-agent": "Google sdkgphone64x8664 | Android 14 | erth | 8.9.2 (8090200) | | null | 10c99d90-9899-4a25-926f-067b34bc4a7f | null", - "content-type": "application/json; charset=UTF-8", - "connection": "Keep-Alive", - "accept-encoding": "gzip", + "user-agent": "Google sdkgphone64x8664 | Android 14 | erth | 8.9.2 (8090200) | | null | 10c99d90-9899-4a25-926f-067b34bc4a7f | null", + "content-type": "application/json; charset=UTF-8", + "connection": "Keep-Alive", + // Note: Don't set "accept-encoding" manually. Go's http.Client automatically handles gzip + // compression/decompression when you let it manage the Accept-Encoding header. } type UpstreamError struct { diff --git a/pkg/tokenmanagement/main.go b/pkg/tokenmanagement/main.go index 7685950..e7835bb 100644 --- a/pkg/tokenmanagement/main.go +++ b/pkg/tokenmanagement/main.go @@ -51,7 +51,7 @@ func (v *ValidTokenProvider) RefreshToken() error { } var refreshTokenResponse models.AuthenticationResponse - refreshURL := fmt.Sprintf(constants.API_REFRESH_SESSION, constants.BaseUrl) + refreshURL := fmt.Sprintf(constants.API_REFRESH_SESSION, constants.BaseURL) err = helpers.NewUpstreamRequest(refreshURL, helpers.WithHeader("Bearer", credentials.RefreshToken), helpers.WithHeader("Operator", fmt.Sprint(credentials.OperatorID)),