Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/controllers/login_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/auth/phone_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"fmt"
"net/http"
"net/url"
"regexp"
"strconv"

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/domru/apiWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pkg/domru/constants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions pkg/domru/helpers/upstream_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/reverseproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tokenmanagement/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
10 changes: 7 additions & 3 deletions templates/home.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

<div class="resp-table-row">
<div class="table-body-cell">Камера:</div>
<div class="table-body-cell">{{ (index $.Cameras.Data $index).ID }}</div>
<div class="table-body-cell">{{ $cameraId }}</div>
</div>
<div class="resp-table-row">
<div class="table-body-cell">Адрес:</div>
Expand Down
Loading