Streamd v0.2.0: rename, modules panel, stable/beta channels
All checks were successful
release / build-and-upload (push) Successful in 7m5s
All checks were successful
release / build-and-upload (push) Successful in 7m5s
- Rename product/host binary to streamd (drm compat copy still shipped) - Go module path streamd; STREAMD_* env aliases; agent UA streamd-agent - Panel Modules store + agent pull sync (modstore / modsync) - Rolling stable + beta download tags; README/docs channel curl blocks - Release notes in docs/releases/v0.2.0.md attached by Forgejo Actions
This commit is contained in:
parent
066e018749
commit
da8e1123ec
140 changed files with 2949 additions and 851 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# agent
|
||||
|
||||
Always-on credentials refresher, hosted by the single binary as `drm agent`.
|
||||
Always-on credentials refresher, hosted by the single binary as `streamd agent`.
|
||||
|
||||
```text
|
||||
apps/agent/
|
||||
|
|
@ -26,30 +26,33 @@ expire by themselves if the agent dies.
|
|||
|
||||
```bash
|
||||
# terminal 1 — control plane
|
||||
./bin/drm serve --bind 127.0.0.1:8083 --data .cache/streamd
|
||||
./bin/streamd serve --bind 127.0.0.1:8083 --data .cache/streamd
|
||||
|
||||
# terminal 2 — agent (operator API key from streamd Settings → API keys)
|
||||
export STREAMD_API_KEY=ndk_…
|
||||
# or legacy: export STREAMD_TOKEN=…
|
||||
./bin/drm agent run --config apps/agent/agent.yaml
|
||||
./bin/streamd agent run --config apps/agent/agent.yaml
|
||||
```
|
||||
|
||||
```bash
|
||||
./bin/drm agent status
|
||||
./bin/drm agent devices
|
||||
./bin/drm agent enqueue --stream tg4-ioi --reason manual
|
||||
./bin/drm agent cancel --job 3
|
||||
./bin/streamd agent status
|
||||
./bin/streamd agent devices
|
||||
./bin/streamd agent enqueue --stream tg4-ioi --reason manual
|
||||
./bin/streamd agent cancel --job 3
|
||||
```
|
||||
|
||||
App modules are discovered under `modules/`. The agent drives whichever module a
|
||||
stream names and contains no provider logic.
|
||||
With `sync_modules: true` (default in the sample config), the agent **pulls**
|
||||
provider modules from the streamd Modules page into `<data_dir>/modules/`. You do
|
||||
not need a hand-maintained `modules/` tree on each agent host. The agent drives
|
||||
whichever module a stream names and contains no provider logic.
|
||||
|
||||
## Config
|
||||
|
||||
`agent.yaml` — `streamd_url`, **`api_key`** (preferred) or `token` (alias), or
|
||||
env `STREAMD_API_KEY` / `STREAMD_TOKEN`. Also: `poll_interval_sec`, `workers`,
|
||||
`max_attempts`, `capture_wait_sec`, `devices` (empty = any authorised device),
|
||||
`wvd`, `user_agent`, `agent_id`, `data_dir`.
|
||||
`wvd`, `user_agent`, `agent_id`, `data_dir`, `sync_modules`, `modules_dir`
|
||||
(default `<data_dir>/modules`), `modules_sync_interval_sec`, `modules_prune`.
|
||||
|
||||
Create the key in the streamd dashboard (role **operator**). The legacy shared
|
||||
`--token` / `STREAMD_TOKEN` still works but is meant for migration only.
|
||||
|
|
@ -59,10 +62,10 @@ Create the key in the streamd dashboard (role **operator**). The legacy shared
|
|||
## Build
|
||||
|
||||
```bash
|
||||
go -C apps/cli build -o ../../bin/drm .
|
||||
go -C apps/cli build -o ../../bin/streamd .
|
||||
|
||||
# cross-compile
|
||||
GOOS=darwin GOARCH=arm64 go -C apps/cli build -o ../../bin/drm .
|
||||
GOOS=darwin GOARCH=arm64 go -C apps/cli build -o ../../bin/streamd .
|
||||
```
|
||||
|
||||
**Full guide: [docs/streamd.md](../../docs/streamd.md)**
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@ workers: 1 # concurrent ADB jobs
|
|||
max_attempts: 5
|
||||
capture_wait_sec: 180
|
||||
devices: [] # empty = all adb "device" serials; never installs apps
|
||||
# Push local modules/<name>/module.yaml to streamd when missing or SHA differs.
|
||||
# Pull modules from the streamd panel into the local cache (package.zip + yaml).
|
||||
sync_modules: true
|
||||
# modules_dir: modules # optional override (default: repo modules/)
|
||||
# modules_dir: # optional; default <data_dir>/modules
|
||||
# modules_sync_interval_sec: 300
|
||||
# modules_prune: false # delete local modules absent from the panel
|
||||
# Required for key fetch. Relative paths resolve from the repo root
|
||||
# (DRM-Decryption/), not from C:\Users\admin\Programming\.
|
||||
wvd:
|
||||
|
|
|
|||
|
|
@ -12,14 +12,15 @@ import (
|
|||
"syscall"
|
||||
"text/tabwriter"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"drmdecryption/apps/agent/internal/config"
|
||||
"drmdecryption/apps/agent/internal/device"
|
||||
"drmdecryption/apps/agent/internal/modsync"
|
||||
"drmdecryption/apps/agent/internal/poller"
|
||||
"drmdecryption/apps/agent/internal/queue"
|
||||
"drmdecryption/apps/agent/internal/worker"
|
||||
"drmdecryption/apps/agent/internal/wsclient"
|
||||
"streamd/apps/agent/internal/client"
|
||||
"streamd/apps/agent/internal/config"
|
||||
"streamd/apps/agent/internal/device"
|
||||
"streamd/apps/agent/internal/modsync"
|
||||
"streamd/apps/agent/internal/poller"
|
||||
"streamd/apps/agent/internal/queue"
|
||||
"streamd/apps/agent/internal/worker"
|
||||
"streamd/apps/agent/internal/wsclient"
|
||||
"streamd/modhost"
|
||||
)
|
||||
|
||||
// Run dispatches an agent subcommand. args[0] is the subcommand name.
|
||||
|
|
@ -137,15 +138,25 @@ func runCmd(sub string, args []string) {
|
|||
}
|
||||
go p.Loop(stop)
|
||||
|
||||
// Prefer the panel-synced modules cache for capture jobs.
|
||||
if cfg.ModulesDir != "" {
|
||||
if err := modhost.SetModulesDir(cfg.ModulesDir); err != nil {
|
||||
log.Fatalf("modules dir: %v", err)
|
||||
}
|
||||
log.Printf("modules dir %s", cfg.ModulesDir)
|
||||
}
|
||||
|
||||
var ms *modsync.Syncer
|
||||
if cfg.SyncModules {
|
||||
ms := &modsync.Syncer{
|
||||
ms = &modsync.Syncer{
|
||||
API: api,
|
||||
ModulesDir: cfg.ModulesDir,
|
||||
Interval: cfg.ModulesSyncInterval(),
|
||||
Prune: cfg.ModulesPrune,
|
||||
Log: log.Default(),
|
||||
}
|
||||
go ms.Loop(stop)
|
||||
log.Printf("modules sync enabled interval=%s", cfg.ModulesSyncInterval())
|
||||
log.Printf("modules pull sync enabled interval=%s dir=%s", cfg.ModulesSyncInterval(), cfg.ModulesDir)
|
||||
}
|
||||
|
||||
ws := wsclient.New(cfg.StreamdURL, cfg.Token, cfg.AgentID, log.Default())
|
||||
|
|
@ -171,6 +182,16 @@ func runCmd(sub string, args []string) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
ws.OnModulesChanged = func(name, reason string) {
|
||||
if ms == nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
if err := ms.Once(); err != nil {
|
||||
log.Printf("modules sync after change to %s: %v", name, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
go ws.Loop()
|
||||
|
||||
for i := 0; i < cfg.Workers; i++ {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
module drmdecryption/apps/agent
|
||||
module streamd/apps/agent
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
drmdecryption v0.0.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.34.5
|
||||
streamd v0.0.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -15,11 +15,10 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
)
|
||||
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
|
|
@ -14,8 +12,6 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh
|
|||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac h1:pNA9PRXGPFURORAsI3IqfQJ4RLsRXqghCFdvypd/4GY=
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac/go.mod h1:Iue6g6iirlfLoVi/DYCi5/x0h/bAOuWF3dULTKpt2Vo=
|
||||
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
|
||||
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
@ -23,8 +19,6 @@ golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
|||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
|
||||
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -180,9 +181,13 @@ func (c *Client) PostEvent(streamID int64, kind, message string, detail map[stri
|
|||
|
||||
// ModuleInfo is one modules/<name>/ entry from GET /api/modules.
|
||||
type ModuleInfo struct {
|
||||
Name string `json:"name"`
|
||||
HasYAML bool `json:"has_yaml"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
Name string `json:"name"`
|
||||
HasYAML bool `json:"has_yaml"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
HasPackage bool `json:"has_package"`
|
||||
PackageSHA256 string `json:"package_sha256,omitempty"`
|
||||
Arches []string `json:"arches,omitempty"`
|
||||
SizeBytes int64 `json:"size_bytes,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ListModules() ([]ModuleInfo, error) {
|
||||
|
|
@ -199,30 +204,64 @@ func (c *Client) ListModules() ([]ModuleInfo, error) {
|
|||
return wrap.Modules, nil
|
||||
}
|
||||
|
||||
// PutModuleYAML uploads raw module.yaml bytes for name (Content-Type text/yaml).
|
||||
func (c *Client) PutModuleYAML(name string, yamlBytes []byte) error {
|
||||
req, err := http.NewRequest(http.MethodPut, c.BaseURL+"/api/modules/"+name, bytes.NewReader(yamlBytes))
|
||||
// GetModuleYAML downloads raw module.yaml bytes for name.
|
||||
func (c *Client) GetModuleYAML(name string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, c.BaseURL+"/api/modules/"+name+"/yaml", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.setHeaders(req)
|
||||
resp, err := c.HTTP.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
|
||||
if resp.StatusCode >= 300 {
|
||||
return nil, c.statusError(http.MethodGet, "/api/modules/"+name+"/yaml", resp, body)
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// DownloadModulePackage writes the module zip to destPath.
|
||||
func (c *Client) DownloadModulePackage(name, destPath string) error {
|
||||
req, err := http.NewRequest(http.MethodGet, c.BaseURL+"/api/modules/"+name+"/package", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "text/yaml")
|
||||
c.setHeaders(req)
|
||||
resp, err := c.HTTP.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||
if resp.StatusCode >= 300 {
|
||||
return c.statusError(http.MethodPut, "/api/modules/"+name, resp, body)
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||
return c.statusError(http.MethodGet, "/api/modules/"+name+"/package", resp, body)
|
||||
}
|
||||
return nil
|
||||
tmp := destPath + ".partial"
|
||||
f, err := os.OpenFile(tmp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, copyErr := io.Copy(f, io.LimitReader(resp.Body, 100<<20))
|
||||
closeErr := f.Close()
|
||||
if copyErr != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return copyErr
|
||||
}
|
||||
if closeErr != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return closeErr
|
||||
}
|
||||
_ = os.Remove(destPath)
|
||||
return os.Rename(tmp, destPath)
|
||||
}
|
||||
|
||||
func (c *Client) setHeaders(req *http.Request) {
|
||||
ua := c.UserAgent
|
||||
if ua == "" {
|
||||
ua = "drm-agent/" + Version
|
||||
ua = "streamd-agent/" + Version
|
||||
}
|
||||
req.Header.Set("User-Agent", ua)
|
||||
if c.Token != "" {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"drmdecryption/repo"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
|
@ -27,10 +27,11 @@ type Config struct {
|
|||
WVD string `yaml:"wvd"` // path to .wvd device file (required for key fetch)
|
||||
UserAgent string `yaml:"user_agent"`
|
||||
AgentID string `yaml:"agent_id"`
|
||||
// SyncModules pushes local modules/<name>/module.yaml to streamd when missing/stale.
|
||||
// SyncModules pulls modules from streamd into the local cache when missing/stale.
|
||||
SyncModules bool `yaml:"sync_modules"`
|
||||
ModulesDir string `yaml:"modules_dir"` // empty = repo modules/
|
||||
ModulesDir string `yaml:"modules_dir"` // empty = <data_dir>/modules
|
||||
ModulesSyncIntervalSec int `yaml:"modules_sync_interval_sec"`
|
||||
ModulesPrune bool `yaml:"modules_prune"` // remove local modules absent from panel
|
||||
// OnDemandPriority lets a capture that streamd pushed — a viewer waking
|
||||
// an on-demand stream, or a scheduled event about to start — jump ahead
|
||||
// of routine refreshes in the queue.
|
||||
|
|
@ -124,7 +125,9 @@ func applyDefaults(cfg Config, root string) Config {
|
|||
if cfg.WVD != "" && !filepath.IsAbs(cfg.WVD) {
|
||||
cfg.WVD = filepath.Join(root, cfg.WVD)
|
||||
}
|
||||
if cfg.ModulesDir != "" && !filepath.IsAbs(cfg.ModulesDir) {
|
||||
if cfg.ModulesDir == "" {
|
||||
cfg.ModulesDir = filepath.Join(cfg.DataDir, "modules")
|
||||
} else if !filepath.IsAbs(cfg.ModulesDir) {
|
||||
cfg.ModulesDir = filepath.Join(root, cfg.ModulesDir)
|
||||
}
|
||||
if cfg.ModulesSyncIntervalSec <= 0 {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"streamd/adb"
|
||||
)
|
||||
|
||||
// Pool tracks free/busy ADB devices. Never installs apps.
|
||||
|
|
|
|||
|
|
@ -1,26 +1,32 @@
|
|||
// Package modsync pushes local modules/<name>/module.yaml to streamd
|
||||
// when the remote copy is missing or the SHA-256 differs.
|
||||
// Package modsync pulls provider modules from streamd into a local cache.
|
||||
// The panel is the source of truth: agents download package.zip when the
|
||||
// package hash changes, and module.yaml alone when only YAML changed.
|
||||
package modsync
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"streamd/apps/agent/internal/client"
|
||||
"streamd/modhost"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Syncer compares local module.yaml files to streamd and PUTs updates.
|
||||
// Syncer keeps the local modules cache aligned with streamd.
|
||||
type Syncer struct {
|
||||
API *client.Client
|
||||
ModulesDir string // empty = modhost.ModulesDir(repo.Root())
|
||||
ModulesDir string // empty = <data_dir>/modules resolved by caller, or modhost default
|
||||
Interval time.Duration
|
||||
Prune bool // remove local modules absent from the panel
|
||||
Log *log.Logger
|
||||
}
|
||||
|
||||
|
|
@ -31,15 +37,10 @@ func (s *Syncer) modulesDir() string {
|
|||
return modhost.ModulesDir(repo.Root())
|
||||
}
|
||||
|
||||
// Once uploads every local module.yaml that is missing or stale on streamd.
|
||||
// Once pulls every remote module that is missing or stale locally.
|
||||
func (s *Syncer) Once() error {
|
||||
dir := s.modulesDir()
|
||||
ents, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
s.logf("modules sync: no local dir %s", dir)
|
||||
return nil
|
||||
}
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -47,42 +48,139 @@ func (s *Syncer) Once() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
byName := make(map[string]client.ModuleInfo, len(remote))
|
||||
seen := map[string]struct{}{}
|
||||
for _, m := range remote {
|
||||
byName[m.Name] = m
|
||||
seen[m.Name] = struct{}{}
|
||||
if err := s.syncOne(dir, m); err != nil {
|
||||
s.logf("modules sync: %s: %v", m.Name, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if s.Prune {
|
||||
s.pruneLocal(dir, seen)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Syncer) syncOne(dir string, m client.ModuleInfo) error {
|
||||
modDir := filepath.Join(dir, m.Name)
|
||||
localPkg := localSHA(filepath.Join(modDir, "package.sha256"))
|
||||
localYAML := ""
|
||||
if raw, err := os.ReadFile(filepath.Join(modDir, "module.yaml")); err == nil {
|
||||
sum := sha256.Sum256(raw)
|
||||
localYAML = hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
needPackage := m.HasPackage && (localPkg == "" || !strings.EqualFold(localPkg, m.PackageSHA256))
|
||||
needYAML := m.HasYAML && (localYAML == "" || !strings.EqualFold(localYAML, m.YAMLSHA256))
|
||||
|
||||
if !needPackage && !needYAML {
|
||||
return nil
|
||||
}
|
||||
|
||||
if needPackage {
|
||||
if !m.HasPackage {
|
||||
return fmt.Errorf("panel has no package.zip")
|
||||
}
|
||||
if err := s.pullPackage(modDir, m); err != nil {
|
||||
return err
|
||||
}
|
||||
s.logf("modules sync: pulled package %s", m.Name)
|
||||
// Package extract includes yaml; refresh localYAML check.
|
||||
if raw, err := os.ReadFile(filepath.Join(modDir, "module.yaml")); err == nil {
|
||||
sum := sha256.Sum256(raw)
|
||||
localYAML = hex.EncodeToString(sum[:])
|
||||
needYAML = m.HasYAML && !strings.EqualFold(localYAML, m.YAMLSHA256)
|
||||
} else {
|
||||
needYAML = m.HasYAML
|
||||
}
|
||||
}
|
||||
|
||||
if needYAML {
|
||||
raw, err := s.API.GetModuleYAML(m.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(modDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := atomicWrite(filepath.Join(modDir, "module.yaml"), raw, 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
s.logf("modules sync: updated yaml %s", m.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Syncer) pullPackage(modDir string, m client.ModuleInfo) error {
|
||||
if err := os.MkdirAll(modDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
zipPath := filepath.Join(modDir, "package.zip")
|
||||
if err := s.API.DownloadModulePackage(m.Name, zipPath); err != nil {
|
||||
return err
|
||||
}
|
||||
sum, err := fileSHA256(zipPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m.PackageSHA256 != "" && !strings.EqualFold(sum, m.PackageSHA256) {
|
||||
return fmt.Errorf("package sha mismatch: got %s want %s", sum, m.PackageSHA256)
|
||||
}
|
||||
|
||||
extractDir := filepath.Join(modDir, ".extract-tmp")
|
||||
_ = os.RemoveAll(extractDir)
|
||||
if err := os.MkdirAll(extractDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(extractDir)
|
||||
|
||||
if err := unzipSafe(zipPath, extractDir); err != nil {
|
||||
return err
|
||||
}
|
||||
// Flatten a single top-level folder (bbc/...) into extractDir root.
|
||||
if err := flattenSingleRoot(extractDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := promoteHostBinary(extractDir, m.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Move extracted contents into modDir (keep package.zip + sha sidecar).
|
||||
ents, err := os.ReadDir(extractDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, e := range ents {
|
||||
src := filepath.Join(extractDir, e.Name())
|
||||
dst := filepath.Join(modDir, e.Name())
|
||||
_ = os.RemoveAll(dst)
|
||||
if err := os.Rename(src, dst); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return atomicWrite(filepath.Join(modDir, "package.sha256"), []byte(sum+"\n"), 0o644)
|
||||
}
|
||||
|
||||
func (s *Syncer) pruneLocal(dir string, keep map[string]struct{}) {
|
||||
ents, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, e := range ents {
|
||||
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
name := e.Name()
|
||||
yamlPath := filepath.Join(dir, name, "module.yaml")
|
||||
raw, err := os.ReadFile(yamlPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
s.logf("modules sync: read %s: %v", yamlPath, err)
|
||||
if _, ok := keep[e.Name()]; ok {
|
||||
continue
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
localSHA := hex.EncodeToString(sum[:])
|
||||
rm, ok := byName[name]
|
||||
if ok && rm.HasYAML && strings.EqualFold(rm.YAMLSHA256, localSHA) {
|
||||
path := filepath.Join(dir, e.Name())
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
s.logf("modules sync: prune %s: %v", e.Name(), err)
|
||||
continue
|
||||
}
|
||||
if err := s.API.PutModuleYAML(name, raw); err != nil {
|
||||
s.logf("modules sync: PUT %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
if !ok || !rm.HasYAML {
|
||||
s.logf("modules sync: uploaded %s (new)", name)
|
||||
} else {
|
||||
s.logf("modules sync: updated %s", name)
|
||||
}
|
||||
s.logf("modules sync: pruned %s", e.Name())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Loop runs Once immediately, then on Interval until stop closes.
|
||||
|
|
@ -119,3 +217,161 @@ func (s *Syncer) logf(format string, args ...any) {
|
|||
}
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func localSHA(path string) string {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
func fileSHA256(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
func atomicWrite(path string, data []byte, mode os.FileMode) error {
|
||||
tmp := path + ".tmp"
|
||||
if err := os.WriteFile(tmp, data, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(tmp, path); err != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unzipSafe(zipPath, destDir string) error {
|
||||
r, err := zip.OpenReader(zipPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
absDest, err := filepath.Abs(destDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range r.File {
|
||||
name := strings.ReplaceAll(f.Name, "\\", "/")
|
||||
name = strings.TrimPrefix(name, "./")
|
||||
if name == "" || strings.HasPrefix(name, "__MACOSX/") || strings.HasSuffix(name, ".DS_Store") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(name, "..") {
|
||||
return fmt.Errorf("zip slip: %s", f.Name)
|
||||
}
|
||||
target := filepath.Join(destDir, filepath.FromSlash(name))
|
||||
absTarget, err := filepath.Abs(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, err := filepath.Rel(absDest, absTarget)
|
||||
if err != nil || strings.HasPrefix(rel, "..") {
|
||||
return fmt.Errorf("zip slip: %s", f.Name)
|
||||
}
|
||||
if f.FileInfo().IsDir() || strings.HasSuffix(name, "/") {
|
||||
if err := os.MkdirAll(target, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mode := os.FileMode(0o644)
|
||||
if f.Mode()&0o111 != 0 {
|
||||
mode = 0o755
|
||||
}
|
||||
out, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
|
||||
if err != nil {
|
||||
_ = rc.Close()
|
||||
return err
|
||||
}
|
||||
_, copyErr := io.Copy(out, rc)
|
||||
_ = out.Close()
|
||||
_ = rc.Close()
|
||||
if copyErr != nil {
|
||||
return copyErr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenSingleRoot(dir string) error {
|
||||
ents, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var dirs []os.DirEntry
|
||||
var files []os.DirEntry
|
||||
for _, e := range ents {
|
||||
if strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
if e.IsDir() {
|
||||
dirs = append(dirs, e)
|
||||
} else {
|
||||
files = append(files, e)
|
||||
}
|
||||
}
|
||||
if len(files) > 0 || len(dirs) != 1 {
|
||||
return nil
|
||||
}
|
||||
root := filepath.Join(dir, dirs[0].Name())
|
||||
inner, err := os.ReadDir(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, e := range inner {
|
||||
src := filepath.Join(root, e.Name())
|
||||
dst := filepath.Join(dir, e.Name())
|
||||
if err := os.Rename(src, dst); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return os.RemoveAll(root)
|
||||
}
|
||||
|
||||
func promoteHostBinary(modDir, name string) error {
|
||||
want := name
|
||||
if runtime.GOOS == "windows" {
|
||||
want += ".exe"
|
||||
}
|
||||
dest := filepath.Join(modDir, ".bin", want)
|
||||
if st, err := os.Stat(dest); err == nil && !st.IsDir() {
|
||||
return nil
|
||||
}
|
||||
src := filepath.Join(modDir, ".bin", runtime.GOOS+"-"+runtime.GOARCH, want)
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return nil // soft: host arch may be missing
|
||||
}
|
||||
defer in.Close()
|
||||
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, copyErr := io.Copy(out, in)
|
||||
closeErr := out.Close()
|
||||
if copyErr != nil {
|
||||
return copyErr
|
||||
}
|
||||
return closeErr
|
||||
}
|
||||
|
|
|
|||
154
apps/agent/internal/modsync/sync_test.go
Normal file
154
apps/agent/internal/modsync/sync_test.go
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
package modsync
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"streamd/apps/agent/internal/client"
|
||||
)
|
||||
|
||||
func TestPullPackageThenYAMLOnly(t *testing.T) {
|
||||
arch := runtime.GOOS + "-" + runtime.GOARCH
|
||||
binName := "demo"
|
||||
if runtime.GOOS == "windows" {
|
||||
binName += ".exe"
|
||||
}
|
||||
zip1 := mustZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: a\n"),
|
||||
".bin/" + arch + "/" + binName: []byte("bin-v1"),
|
||||
})
|
||||
sum1 := sha256.Sum256(zip1)
|
||||
pkgSHA1 := hex.EncodeToString(sum1[:])
|
||||
yaml1SHA := sha256Hex([]byte("package: a\n"))
|
||||
|
||||
zip2 := mustZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: a\n"),
|
||||
".bin/" + arch + "/" + binName: []byte("bin-v2"),
|
||||
})
|
||||
sum2 := sha256.Sum256(zip2)
|
||||
pkgSHA2 := hex.EncodeToString(sum2[:])
|
||||
|
||||
yamlEdited := []byte("package: a\nchannels: {}\n")
|
||||
yamlEditedSHA := sha256Hex(yamlEdited)
|
||||
|
||||
state := struct {
|
||||
pkg []byte
|
||||
pkgSHA string
|
||||
yaml []byte
|
||||
yamlSHA string
|
||||
}{pkg: zip1, pkgSHA: pkgSHA1, yaml: []byte("package: a\n"), yamlSHA: yaml1SHA}
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.URL.Path == "/api/modules" && r.Method == http.MethodGet:
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"modules": []map[string]any{{
|
||||
"name": "demo",
|
||||
"has_yaml": true,
|
||||
"yaml_sha256": state.yamlSHA,
|
||||
"has_package": true,
|
||||
"package_sha256": state.pkgSHA,
|
||||
}},
|
||||
})
|
||||
case r.URL.Path == "/api/modules/demo/package":
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
_, _ = w.Write(state.pkg)
|
||||
case r.URL.Path == "/api/modules/demo/yaml":
|
||||
w.Header().Set("Content-Type", "text/yaml")
|
||||
_, _ = w.Write(state.yaml)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
dir := t.TempDir()
|
||||
api := &client.Client{BaseURL: srv.URL, HTTP: srv.Client()}
|
||||
s := &Syncer{API: api, ModulesDir: dir}
|
||||
|
||||
if err := s.Once(); err != nil {
|
||||
t.Fatalf("first sync: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "demo", "module.yaml")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
promoted := filepath.Join(dir, "demo", ".bin", binName)
|
||||
if b, err := os.ReadFile(promoted); err != nil || string(b) != "bin-v1" {
|
||||
t.Fatalf("promoted binary: %v %q", err, b)
|
||||
}
|
||||
|
||||
// YAML-only change on panel.
|
||||
state.yaml = yamlEdited
|
||||
state.yamlSHA = yamlEditedSHA
|
||||
if err := s.Once(); err != nil {
|
||||
t.Fatalf("yaml sync: %v", err)
|
||||
}
|
||||
raw, _ := os.ReadFile(filepath.Join(dir, "demo", "module.yaml"))
|
||||
if !bytes.Equal(raw, yamlEdited) {
|
||||
t.Fatalf("yaml not updated: %s", raw)
|
||||
}
|
||||
if b, _ := os.ReadFile(promoted); string(b) != "bin-v1" {
|
||||
t.Fatalf("binary should be unchanged after yaml-only sync, got %q", b)
|
||||
}
|
||||
|
||||
// Package change.
|
||||
state.pkg = zip2
|
||||
state.pkgSHA = pkgSHA2
|
||||
state.yaml = []byte("package: a\n")
|
||||
state.yamlSHA = yaml1SHA
|
||||
if err := s.Once(); err != nil {
|
||||
t.Fatalf("package sync: %v", err)
|
||||
}
|
||||
if b, _ := os.ReadFile(promoted); string(b) != "bin-v2" {
|
||||
t.Fatalf("binary not updated: %q", b)
|
||||
}
|
||||
}
|
||||
|
||||
func mustZip(t *testing.T, files map[string][]byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
for name, body := range files {
|
||||
w, err := zw.Create(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.Write(body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func sha256Hex(b []byte) string {
|
||||
sum := sha256.Sum256(b)
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func TestUnzipSlip(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
w, _ := zw.Create("../evil")
|
||||
_, _ = w.Write([]byte("x"))
|
||||
_ = zw.Close()
|
||||
zipPath := filepath.Join(dir, "bad.zip")
|
||||
_ = os.WriteFile(zipPath, buf.Bytes(), 0o644)
|
||||
err := unzipSafe(zipPath, filepath.Join(dir, "out"))
|
||||
if err == nil || !strings.Contains(err.Error(), "slip") {
|
||||
t.Fatalf("want zip slip error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"drmdecryption/apps/agent/internal/queue"
|
||||
"streamd/apps/agent/internal/client"
|
||||
"streamd/apps/agent/internal/queue"
|
||||
)
|
||||
|
||||
type Poller struct {
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/phonecap"
|
||||
"drmdecryption/repo"
|
||||
"streamd/modhost"
|
||||
"streamd/phonecap"
|
||||
"streamd/repo"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"drmdecryption/apps/agent/internal/device"
|
||||
"drmdecryption/apps/agent/internal/poller"
|
||||
"drmdecryption/apps/agent/internal/queue"
|
||||
"streamd/apps/agent/internal/client"
|
||||
"streamd/apps/agent/internal/device"
|
||||
"streamd/apps/agent/internal/poller"
|
||||
"streamd/apps/agent/internal/queue"
|
||||
)
|
||||
|
||||
type Worker struct {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"streamd/apps/agent/internal/client"
|
||||
)
|
||||
|
||||
// Message is one push from streamd.
|
||||
|
|
@ -42,6 +42,9 @@ type Client struct {
|
|||
// OnStreamChanged is called when a stream was edited, so the agent can
|
||||
// re-poll instead of waiting out its interval.
|
||||
OnStreamChanged func(name, reason string)
|
||||
// OnModulesChanged is called when the panel uploaded/edited/deleted a
|
||||
// module, so the agent can pull without waiting for the sync interval.
|
||||
OnModulesChanged func(name, reason string)
|
||||
|
||||
stop chan struct{}
|
||||
}
|
||||
|
|
@ -111,7 +114,7 @@ func (c *Client) session() error {
|
|||
if c.AgentID != "" {
|
||||
hdr.Set("X-Agent-ID", c.AgentID)
|
||||
}
|
||||
hdr.Set("User-Agent", "drm-agent/"+client.Version)
|
||||
hdr.Set("User-Agent", "streamd-agent/"+client.Version)
|
||||
dialer := websocket.Dialer{HandshakeTimeout: 10 * time.Second}
|
||||
conn, resp, err := dialer.Dial(u.String(), hdr)
|
||||
if err != nil {
|
||||
|
|
@ -190,6 +193,11 @@ func (c *Client) handle(msg Message) {
|
|||
if c.OnStreamChanged != nil {
|
||||
c.OnStreamChanged(msg.StreamName, msg.Reason)
|
||||
}
|
||||
case "modules_changed":
|
||||
c.Log.Printf("ws: modules changed module=%s reason=%s", msg.StreamName, msg.Reason)
|
||||
if c.OnModulesChanged != nil {
|
||||
c.OnModulesChanged(msg.StreamName, msg.Reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# capture
|
||||
|
||||
One-shot phone MITM capture, hosted by the single binary as `drm capture`.
|
||||
One-shot phone MITM capture, hosted by the single binary as `streamd capture`.
|
||||
|
||||
```text
|
||||
apps/capture/
|
||||
|
|
@ -8,17 +8,17 @@ apps/capture/
|
|||
```
|
||||
|
||||
```bash
|
||||
./bin/drm capture # passive: play anything
|
||||
./bin/drm capture --app rte # launch, navigate by hand
|
||||
./bin/drm capture --app rte --channel rteone --auto-play \
|
||||
./bin/streamd capture # passive: play anything
|
||||
./bin/streamd capture --app rte # launch, navigate by hand
|
||||
./bin/streamd capture --app rte --channel rteone --auto-play \
|
||||
--wvd data/device.wvd # fully automated
|
||||
```
|
||||
|
||||
Writes `outputs/<app>/<stamp>/` plus `latest/`. App modules are compiled in, so
|
||||
there is no modules directory to point at; `drm modules` lists what is available.
|
||||
there is no modules directory to point at; `streamd modules` lists what is available.
|
||||
|
||||
**Full guide: [docs/capture.md](../../docs/capture.md)** — device setup, flags,
|
||||
discovering a new app, and troubleshooting.
|
||||
|
||||
The catalog lookup that used to be a separate `tg4info` binary is now the
|
||||
provider-agnostic `drm catalog` (`apps/cli/catalogcmd`).
|
||||
provider-agnostic `streamd catalog` (`apps/cli/catalogcmd`).
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@ import (
|
|||
"time"
|
||||
"unicode"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/app"
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/phonecap"
|
||||
"drmdecryption/repo"
|
||||
"streamd/adb"
|
||||
"streamd/app"
|
||||
"streamd/modcfg"
|
||||
"streamd/modhost"
|
||||
"streamd/phonecap"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Run performs one capture. Providers live under modules/<name>/ and are built
|
||||
// and executed by modhost — they are not linked into drm.exe.
|
||||
// and executed by modhost — they are not linked into streamd.
|
||||
func Run(args []string) error {
|
||||
args = normalizeArgs(args)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
module drmdecryption/apps/capture
|
||||
module streamd/apps/capture
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require drmdecryption v0.0.0
|
||||
require streamd v0.0.0
|
||||
|
||||
require (
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
require gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
|
|
|
|||
|
|
@ -1,11 +1,3 @@
|
|||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac h1:pNA9PRXGPFURORAsI3IqfQJ4RLsRXqghCFdvypd/4GY=
|
||||
go.starlark.net v0.0.0-20260930220527-d7438c5a85ac/go.mod h1:Iue6g6iirlfLoVi/DYCi5/x0h/bAOuWF3dULTKpt2Vo=
|
||||
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"drmdecryption/apps/capture/capturecmd"
|
||||
"streamd/apps/capture/capturecmd"
|
||||
)
|
||||
|
||||
func TestCaptureRejectsChannelAsApp(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"drmdecryption/session"
|
||||
"streamd/modhost"
|
||||
"streamd/repo"
|
||||
"streamd/session"
|
||||
)
|
||||
|
||||
// Run performs a catalog lookup for one channel.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
module drmdecryption/apps/cli
|
||||
module streamd/apps/cli
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
drmdecryption v0.0.0
|
||||
drmdecryption/apps/agent v0.0.0
|
||||
drmdecryption/apps/capture v0.0.0
|
||||
drmdecryption/apps/proxy v0.0.0
|
||||
drmdecryption/apps/streamd v0.0.0
|
||||
streamd v0.0.0
|
||||
streamd/apps/agent v0.0.0
|
||||
streamd/apps/capture v0.0.0
|
||||
streamd/apps/proxy v0.0.0
|
||||
streamd/apps/streamd v0.0.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -26,9 +26,9 @@ require (
|
|||
)
|
||||
|
||||
replace (
|
||||
drmdecryption => ../pkg
|
||||
drmdecryption/apps/agent => ../agent
|
||||
drmdecryption/apps/capture => ../capture
|
||||
drmdecryption/apps/proxy => ../proxy
|
||||
drmdecryption/apps/streamd => ../streamd
|
||||
streamd => ../pkg
|
||||
streamd/apps/agent => ../agent
|
||||
streamd/apps/capture => ../capture
|
||||
streamd/apps/proxy => ../proxy
|
||||
streamd/apps/streamd => ../streamd
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
// Command drm is the single entry point for the toolchain: phone capture,
|
||||
// Command streamd is the single entry point for the toolchain: phone capture,
|
||||
// catalog lookups, the always-on agent, the streamd control plane and the
|
||||
// on-device MITM. Providers live under modules/<name>/ and are discovered,
|
||||
// built, and executed by the host — they are not linked into this binary.
|
||||
// A drm.exe copy of this binary is still shipped for one release as a compat alias.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
@ -13,14 +14,14 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/apps/agent/agentcmd"
|
||||
"drmdecryption/apps/capture/capturecmd"
|
||||
"drmdecryption/apps/cli/catalogcmd"
|
||||
"drmdecryption/apps/cli/modulescmd"
|
||||
"drmdecryption/apps/proxy/proxyctlcmd"
|
||||
"drmdecryption/apps/streamd/servecmd"
|
||||
"drmdecryption/bootstrap"
|
||||
"drmdecryption/modhost"
|
||||
"streamd/apps/agent/agentcmd"
|
||||
"streamd/apps/capture/capturecmd"
|
||||
"streamd/apps/cli/catalogcmd"
|
||||
"streamd/apps/cli/modulescmd"
|
||||
"streamd/apps/proxy/proxyctlcmd"
|
||||
"streamd/apps/streamd/servecmd"
|
||||
"streamd/bootstrap"
|
||||
"streamd/modhost"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -39,12 +40,12 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
} else if err := modhost.ApplyEnvModulesDir(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "[!] DRM_MODULES_DIR:", err)
|
||||
fmt.Fprintln(os.Stderr, "[!] STREAMD_MODULES_DIR / DRM_MODULES_DIR:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Materialise apps/, bin/, modules/, outputs/, … next to this exe when
|
||||
// missing so a lone downloaded drm.exe becomes a GitHub-like install tree.
|
||||
// missing so a lone downloaded streamd.exe becomes a usable install tree.
|
||||
if cmd != "help" && cmd != "-h" && cmd != "--help" {
|
||||
if err := bootstrap.EnsureAndLogFor(cmd); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "[!] bootstrap:", err)
|
||||
|
|
@ -102,23 +103,25 @@ func peelGlobalFlags(args []string) (modulesDir string, rest []string) {
|
|||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprint(os.Stderr, `drm — DRM capture / restream toolchain
|
||||
fmt.Fprint(os.Stderr, `streamd — capture / restream toolchain
|
||||
|
||||
Usage:
|
||||
drm [--modules-dir DIR] modules
|
||||
drm [--modules-dir DIR] capture --app NAME [--channel ID | --all] [--wvd PATH]
|
||||
drm [--modules-dir DIR] catalog --app NAME --channel ID [--keys] [--json]
|
||||
drm agent run|status|devices|enqueue|cancel [--config …]
|
||||
drm serve [--bind …] [--data …] [--token …]
|
||||
drm proxy build|push|install-ca|start|stop|reset|discover|pull|clear-proxy|transparent
|
||||
streamd [--modules-dir DIR] modules
|
||||
streamd [--modules-dir DIR] capture --app NAME [--channel ID | --all] [--wvd PATH]
|
||||
streamd [--modules-dir DIR] catalog --app NAME --channel ID [--keys] [--json]
|
||||
streamd agent run|status|devices|enqueue|cancel [--config …]
|
||||
streamd serve [--bind …] [--data …] [--token …]
|
||||
streamd proxy build|push|install-ca|start|stop|reset|discover|pull|clear-proxy|transparent
|
||||
|
||||
Global flags:
|
||||
--modules-dir DIR provider folder (default: <install>/modules, or $DRM_MODULES_DIR)
|
||||
--modules-dir DIR provider folder (default: <install>/modules, or $STREAMD_MODULES_DIR)
|
||||
|
||||
Providers live under modules/<name>/ (Go source + module-publish.yaml).
|
||||
Local module.yaml holds secrets and is never published; release zips ship
|
||||
module-publish.yaml renamed to module.yaml. The host builds modules on demand.
|
||||
|
||||
A drm binary may still be shipped as an identical compatibility copy.
|
||||
|
||||
Run any subcommand with --help for its own flags.
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"sort"
|
||||
"text/tabwriter"
|
||||
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"streamd/modhost"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Run prints external modules under modules/.
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ One Go package per streaming app. Every module is **compiled into the binary**
|
|||
there is no plugin loading and no modules directory to point a binary at.
|
||||
|
||||
```text
|
||||
apps/modules/ Go module: drmdecryption/modules
|
||||
go.mod replace drmdecryption => ../pkg
|
||||
apps/modules/ Go module: streamd/modules
|
||||
go.mod replace streamd => ../pkg
|
||||
all/all.go blank-imports every module — the link point
|
||||
provider/ shared base: values loading, channel aliases, durations
|
||||
<name>/*.go TRACKED: the app's logic
|
||||
|
|
@ -37,7 +37,7 @@ Values arrive by **flag → environment → module.yaml → Go default**, and on
|
|||
mechanical defaults (timeouts, DASH timescales, card geometry) live in code:
|
||||
|
||||
```bash
|
||||
./bin/drm catalog --app tg4 --channel ioi --tg4.policy-key BCpkAD...
|
||||
./bin/streamd catalog --app tg4 --channel ioi --tg4.policy-key BCpkAD...
|
||||
export TG4_POLICY_KEY=BCpkAD... # same thing
|
||||
```
|
||||
|
||||
|
|
@ -46,9 +46,9 @@ export TG4_POLICY_KEY=BCpkAD... # same thing
|
|||
1. Create `apps/modules/myapp/` with `config.go` and `myapp.go`
|
||||
2. Register from `init()`: `appreg.Register(Name, New)` and
|
||||
`appreg.RegisterFlags(bindFlags)`
|
||||
3. Add one line to `all/all.go`: `_ "drmdecryption/modules/myapp"`
|
||||
3. Add one line to `all/all.go`: `_ "streamd/modules/myapp"`
|
||||
4. Create `apps/modules/myapp/module.yaml` with your values
|
||||
5. `go -C apps/cli build -o ../../bin/drm .` then `./bin/drm modules`
|
||||
5. `go -C apps/cli build -o ../../bin/streamd .` then `./bin/streamd modules`
|
||||
|
||||
**Authoring guide: [docs/modules.md](../../docs/modules.md)** — the full contract,
|
||||
`uiflow` reference, optional capability interfaces, and a checklist.
|
||||
|
|
@ -59,9 +59,9 @@ export TG4_POLICY_KEY=BCpkAD... # same thing
|
|||
## Run
|
||||
|
||||
```bash
|
||||
./bin/drm modules # what is compiled in
|
||||
./bin/drm capture --app rte --channel rteone --auto-play
|
||||
./bin/drm capture --app bbc --channel bbcone # transparent MITM; play on phone; MPD only
|
||||
./bin/drm catalog --app tg4 --channel ioi --keys --wvd data/device.wvd
|
||||
./bin/drm agent run --config apps/agent/agent.yaml
|
||||
./bin/streamd modules # what is compiled in
|
||||
./bin/streamd capture --app rte --channel rteone --auto-play
|
||||
./bin/streamd capture --app bbc --channel bbcone # transparent MITM; play on phone; MPD only
|
||||
./bin/streamd catalog --app tg4 --channel ioi --keys --wvd data/device.wvd
|
||||
./bin/streamd agent run --config apps/agent/agent.yaml
|
||||
```
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
package all
|
||||
|
||||
import (
|
||||
_ "drmdecryption/modules/bbc"
|
||||
_ "drmdecryption/modules/rte"
|
||||
_ "drmdecryption/modules/tg4"
|
||||
_ "streamd/modules/bbc"
|
||||
_ "streamd/modules/rte"
|
||||
_ "streamd/modules/tg4"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"flag"
|
||||
"testing"
|
||||
|
||||
appreg "drmdecryption/app"
|
||||
appreg "streamd/app"
|
||||
)
|
||||
|
||||
// Every module must be constructible with no module.yaml present — a fresh clone
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package bbc
|
|||
import (
|
||||
"testing"
|
||||
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"regexp"
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
)
|
||||
|
||||
// Name is the module id (--app bbc).
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
// openExplorePage taps the Explore bottom-nav tab and waits for the channel rail.
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package c4
|
|||
import (
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
)
|
||||
|
||||
// Name is the module id (--app c4).
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func (a *App) openLiveTab(c *adb.Client) error {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
module drmdecryption/modules
|
||||
module streamd/modules
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require drmdecryption v0.0.0
|
||||
require streamd v0.0.0
|
||||
|
||||
require gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package itv
|
|||
import (
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
)
|
||||
|
||||
// Name is the module id (--app itv).
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
// openLiveTab taps bottom-nav Live. Accessibility desc is obfuscated as "Lyve";
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package my5
|
|||
import (
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
)
|
||||
|
||||
// Name is the module id (--app my5).
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func (a *App) appFocused(c *adb.Client) bool {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/phonecap"
|
||||
"drmdecryption/repo"
|
||||
"streamd/capture"
|
||||
"streamd/modcfg"
|
||||
"streamd/phonecap"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Common is the part of a module.yaml that every module has. Modules embed it in
|
||||
|
|
@ -57,7 +57,7 @@ func (b *Base) ConfigPath() string { return b.cfg.Path }
|
|||
func (b *Base) ConfigLoaded() bool { return b.cfg.Loaded }
|
||||
|
||||
// ProxyBin resolves the on-device MITM binary. Empty means “auto” (caller uses
|
||||
// proxy.FindLocalBin — next to drm.exe, then repo bin/).
|
||||
// proxy.FindLocalBin — next to streamd, then repo bin/).
|
||||
func (b *Base) ProxyBin() string {
|
||||
if b.common.ProxyBin != "" {
|
||||
return modcfg.Resolve(b.common.ProxyBin)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package rte
|
|||
import (
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// Name is the module id (--app rte).
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"drmdecryption/mpd"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// The rewriter must publish a usable manifest from the KID alone — this is the
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"drmdecryption/mpd"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/mpd"
|
||||
appreg "streamd/app"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// Compile-time proof the plugin satisfies every interface the host expects.
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"regexp"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
// openLiveTab taps the bottom-nav Live tab and waits for channel chips.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/brightcove"
|
||||
"drmdecryption/session"
|
||||
appreg "streamd/app"
|
||||
"streamd/brightcove"
|
||||
"streamd/session"
|
||||
)
|
||||
|
||||
// playbackConfig is the app's remote config blob. It is decoded generically: the
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package tg4
|
|||
import (
|
||||
"time"
|
||||
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
// Name is the module id (--app tg4).
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/brightcove"
|
||||
"drmdecryption/repo"
|
||||
"drmdecryption/session"
|
||||
"drmdecryption/wvkey"
|
||||
"streamd/brightcove"
|
||||
"streamd/repo"
|
||||
"streamd/session"
|
||||
"streamd/wvkey"
|
||||
)
|
||||
|
||||
// EnrichWithKeys fetches the HLS master, extracts the Widevine PSSH and resolves
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
// openLivePage navigates to the Live page: if a menu entry is visible tap it,
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/modules/provider"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/uiflow"
|
||||
"streamd/adb"
|
||||
appreg "streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/modules/provider"
|
||||
"streamd/mpd"
|
||||
"streamd/uiflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package tg4
|
|||
import (
|
||||
"testing"
|
||||
|
||||
appreg "drmdecryption/app"
|
||||
"drmdecryption/modcfg"
|
||||
"drmdecryption/modules/provider"
|
||||
appreg "streamd/app"
|
||||
"streamd/modcfg"
|
||||
"streamd/modules/provider"
|
||||
)
|
||||
|
||||
// Compile-time proof the plugin satisfies every interface the host expects.
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
# pkg — shared Go libraries
|
||||
|
||||
Imported by `apps/capture`, `apps/agent`, `apps/streamd`, `apps/proxy`, `apps/cli`
|
||||
and `apps/modules` as module `drmdecryption` via:
|
||||
and `apps/modules` as module `streamd` via:
|
||||
|
||||
```go
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
```
|
||||
|
||||
## Packages
|
||||
|
|
@ -34,4 +34,4 @@ provider values live in that module's gitignored `module.yaml`.
|
|||
go -C apps/pkg test ./...
|
||||
```
|
||||
|
||||
No binary of its own — everything ships in `bin/drm`, built from `apps/cli`.
|
||||
No binary of its own — everything ships in `bin/streamd`, built from `apps/cli`.
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import (
|
|||
"sort"
|
||||
"sync"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/session"
|
||||
"streamd/adb"
|
||||
"streamd/capture"
|
||||
"streamd/mpd"
|
||||
"streamd/session"
|
||||
)
|
||||
|
||||
// Channel is a named live target inside an app (e.g. rteone).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Package bootstrap materialises a GitHub-like install tree next to drm.exe
|
||||
// Package bootstrap materialises a GitHub-like install tree next to streamd
|
||||
// so a single downloaded binary can create apps/, bin/, outputs/, etc. on first run.
|
||||
package bootstrap
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ var embedded embed.FS
|
|||
const minProxyBytes = 100_000 // stub ELF is tiny; real proxy-android-arm64 is ~9MB
|
||||
|
||||
// InstallRoot is the directory that should contain apps/, bin/, outputs/.
|
||||
// If drm.exe lives in …/bin/, the parent is the root; otherwise the exe directory.
|
||||
// If streamd lives in …/bin/, the parent is the root; otherwise the exe directory.
|
||||
func InstallRoot() (string, error) {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
|
|
@ -91,27 +91,34 @@ func Ensure(root string) (created []string, err error) {
|
|||
return created, err
|
||||
}
|
||||
|
||||
// If drm is not already under bin/, copy/link a drm.exe there for 1:1 layout.
|
||||
if err := ensureBinDrm(root); err != nil {
|
||||
// If streamd is not already under bin/, copy it there for 1:1 layout.
|
||||
// Also keep a drm.exe compat copy for one release when missing.
|
||||
if err := ensureBinHost(root); err != nil {
|
||||
return created, err
|
||||
}
|
||||
return created, nil
|
||||
}
|
||||
|
||||
func ensureBinDrm(root string) error {
|
||||
func ensureBinHost(root string) error {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
exe, _ = filepath.EvalSymlinks(exe)
|
||||
dest := filepath.Join(root, "bin", "drm.exe")
|
||||
if sameFile(exe, dest) {
|
||||
if err := copyExeIfMissing(exe, filepath.Join(root, "bin", "streamd.exe")); err != nil {
|
||||
return err
|
||||
}
|
||||
return copyExeIfMissing(exe, filepath.Join(root, "bin", "drm.exe"))
|
||||
}
|
||||
|
||||
func copyExeIfMissing(src, dest string) error {
|
||||
if sameFile(src, dest) {
|
||||
return nil
|
||||
}
|
||||
if st, err := os.Stat(dest); err == nil && !st.IsDir() {
|
||||
return nil
|
||||
}
|
||||
data, err := os.ReadFile(exe)
|
||||
data, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -154,7 +161,7 @@ func EnsureAndLogFor(cmd string) error {
|
|||
}
|
||||
proxy := filepath.Join(root, "bin", "proxy-android-arm64")
|
||||
if st, err := os.Stat(proxy); err != nil || st.Size() < minProxyBytes {
|
||||
fmt.Fprintf(os.Stderr, "[!] missing bin/proxy-android-arm64 — place it next to drm or use a release build that embeds it\n")
|
||||
fmt.Fprintf(os.Stderr, "[!] missing bin/proxy-android-arm64 — place it next to streamd or use a release build that embeds it\n")
|
||||
}
|
||||
// Providers live under modules/; only warn when the command needs them.
|
||||
needsModules := cmd == "" || cmd == "modules" || cmd == "capture" || cmd == "catalog" || cmd == "agent" || cmd == "serve"
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
# Null DRM
|
||||
# Streamd
|
||||
|
||||
Host binary **`drm`** + providers under **`modules/`**.
|
||||
Host binary **`streamd`** + providers under **`modules/`**.
|
||||
|
||||
## Quick start
|
||||
|
||||
1. Download `drm` (`v*` release) and module zips (`modules-v*` release).
|
||||
1. Download `streamd` (`v*` release) and module zips (`modules-v*` release).
|
||||
2. Unzip providers into `modules/<name>/` and edit `module.yaml` (secrets only).
|
||||
3. `drm proxy install-ca --reinject`
|
||||
4. `drm capture --app bbc --channel bbcone --wait 120`
|
||||
5. `drm proxy reset` when finished.
|
||||
3. `streamd proxy install-ca --reinject`
|
||||
4. `streamd capture --app bbc --channel bbcone --wait 120`
|
||||
5. `streamd proxy reset` when finished.
|
||||
|
||||
```text
|
||||
drm modules
|
||||
|
|
@ -17,6 +17,6 @@ drm catalog --app NAME --channel ID [--keys] [--json]
|
|||
drm proxy install-ca --reinject | reset | transparent --package PKG
|
||||
```
|
||||
|
||||
`--modules-dir DIR` or `$DRM_MODULES_DIR` selects another modules folder.
|
||||
`--modules-dir DIR` or `$STREAMD_MODULES_DIR` selects another modules folder.
|
||||
|
||||
Full docs: https://git.nulldrm.com/nulldrm/Null-DRM-Official
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
module drmdecryption
|
||||
module streamd
|
||||
|
||||
go 1.25.0
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# External modules
|
||||
|
||||
Each subdirectory is a provider the `drm` host discovers, builds, and runs.
|
||||
Each subdirectory is a provider the `streamd` host discovers, builds, and runs.
|
||||
|
||||
```
|
||||
modules/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
module drmdecryption
|
||||
module streamd
|
||||
|
||||
go 1.25.0
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"streamd/adb"
|
||||
)
|
||||
|
||||
// Hints tell the waiter which fields / log tags mean a capture is complete.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
module drmdecryption
|
||||
module streamd
|
||||
|
||||
go 1.25.0
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"streamd/modhost"
|
||||
"streamd/repo"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ type Module struct {
|
|||
Dir string // absolute path to modules/<name>
|
||||
}
|
||||
|
||||
// ModulesDir returns the modules directory (honours --modules-dir / DRM_MODULES_DIR).
|
||||
// ModulesDir returns the modules directory (honours --modules-dir / STREAMD_MODULES_DIR / DRM_MODULES_DIR).
|
||||
func ModulesDir(root string) string {
|
||||
return EffectiveModulesDir(root)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Package modhost discovers, builds, and runs external provider modules that
|
||||
// live under modules/<name>/ (Go source + module.yaml), outside drm.exe.
|
||||
// live under modules/<name>/ (Go source + module.yaml), outside streamd.
|
||||
package modhost
|
||||
|
||||
import "drmdecryption/capture"
|
||||
import "streamd/capture"
|
||||
|
||||
// ProtocolVersion is bumped when describe/launch/autoplay CLI contract changes.
|
||||
const ProtocolVersion = 1
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/session"
|
||||
"streamd/adb"
|
||||
"streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/mpd"
|
||||
"streamd/session"
|
||||
)
|
||||
|
||||
// RemoteApp implements app.App by calling an external module binary.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"drmdecryption/repo"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -13,7 +13,7 @@ var (
|
|||
modulesDirOV string // absolute path override for the modules directory
|
||||
)
|
||||
|
||||
// SetModulesDir overrides where providers are discovered (drm --modules-dir).
|
||||
// SetModulesDir overrides where providers are discovered (streamd --modules-dir).
|
||||
// Empty clears the override. Relative paths are resolved against the process cwd.
|
||||
func SetModulesDir(dir string) error {
|
||||
rootMu.Lock()
|
||||
|
|
@ -38,7 +38,7 @@ func ModulesDirOverride() string {
|
|||
}
|
||||
|
||||
// EffectiveModulesDir is the directory that Discover/Open scan.
|
||||
// Prefer --modules-dir / DRM_MODULES_DIR; else <root>/modules.
|
||||
// Prefer --modules-dir / STREAMD_MODULES_DIR / DRM_MODULES_DIR; else <root>/modules.
|
||||
func EffectiveModulesDir(root string) string {
|
||||
if ov := ModulesDirOverride(); ov != "" {
|
||||
return ov
|
||||
|
|
@ -49,12 +49,16 @@ func EffectiveModulesDir(root string) string {
|
|||
return filepath.Join(root, "modules")
|
||||
}
|
||||
|
||||
// ApplyEnvModulesDir sets the override from DRM_MODULES_DIR when no flag was set.
|
||||
// ApplyEnvModulesDir sets the override from STREAMD_MODULES_DIR (preferred) or
|
||||
// DRM_MODULES_DIR when no flag was set.
|
||||
func ApplyEnvModulesDir() error {
|
||||
if ModulesDirOverride() != "" {
|
||||
return nil
|
||||
}
|
||||
v := os.Getenv("DRM_MODULES_DIR")
|
||||
v := os.Getenv("STREAMD_MODULES_DIR")
|
||||
if v == "" {
|
||||
v = os.Getenv("DRM_MODULES_DIR")
|
||||
}
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/app"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/proxy"
|
||||
"drmdecryption/repo"
|
||||
"drmdecryption/session"
|
||||
"drmdecryption/wvkey"
|
||||
"streamd/adb"
|
||||
"streamd/app"
|
||||
"streamd/capture"
|
||||
"streamd/proxy"
|
||||
"streamd/repo"
|
||||
"streamd/session"
|
||||
"streamd/wvkey"
|
||||
)
|
||||
|
||||
// DefaultCAHash is the subject hash of the bundled MITM CA, used when an app
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/repo"
|
||||
"streamd/adb"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
//go:embed embedded/tproxy_iptables.sh
|
||||
var embeddedTProxyScript []byte
|
||||
|
||||
// ensureTProxyScript pushes the iptables helper to the phone.
|
||||
// Prefers the source-tree copy; falls back to the copy embedded in drm.exe
|
||||
// Prefers the source-tree copy; falls back to the copy embedded in streamd
|
||||
// so a portable release zip does not need apps/proxy/device/.
|
||||
func ensureTProxyScript(c *adb.Client) error {
|
||||
candidates := []string{
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/repo"
|
||||
"streamd/adb"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -225,7 +225,7 @@ func PushAndStart(c *adb.Client, localBin string, extraArgs ...string) error {
|
|||
}
|
||||
|
||||
// FindLocalBin returns the on-device MITM binary.
|
||||
// Search order: next to this drm.exe (release zip layout), then under the repo.
|
||||
// Search order: next to this streamd binary (release zip layout), then under the repo.
|
||||
func FindLocalBin(root string) string {
|
||||
if root == "" {
|
||||
root = repo.Root()
|
||||
|
|
@ -322,11 +322,11 @@ func generateMITMCA(certPath, keyPath string) error {
|
|||
return err
|
||||
}
|
||||
// Unique CN so Android subject_hash_old differs per install (filename HASH.0).
|
||||
cn := fmt.Sprintf("Null DRM Capture CA %x", serial.Bytes()[:8])
|
||||
cn := fmt.Sprintf("Streamd Capture CA %x", serial.Bytes()[:8])
|
||||
tmpl := &x509.Certificate{
|
||||
SerialNumber: serial,
|
||||
Subject: pkix.Name{
|
||||
Organization: []string{"Null DRM MITM CA"},
|
||||
Organization: []string{"Streamd MITM CA"},
|
||||
CommonName: cn,
|
||||
},
|
||||
NotBefore: time.Now().Add(-time.Hour),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
//
|
||||
// Search order:
|
||||
// 1. Walk up from the current working directory
|
||||
// 2. Walk up from drm.exe (if the exe lives in bin/, start at the parent)
|
||||
// 2. Walk up from streamd (if the exe lives in bin/, start at the parent)
|
||||
func Root() string {
|
||||
if root := findRoot(wd()); root != "" {
|
||||
return root
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"streamd/adb"
|
||||
)
|
||||
|
||||
// Pick selects among several matching nodes.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ license URLs, manifests and auth headers.
|
|||
|
||||
```text
|
||||
apps/proxy/
|
||||
proxyctlcmd/ host CLI, hosted by bin/drm as `drm proxy`
|
||||
proxyctlcmd/ host CLI, hosted by bin/streamd as `streamd proxy`
|
||||
device/ linux/arm64 MITM source (module: appproxy)
|
||||
rteproxy-ca.crt MITM CA (subject hash 6c3578b4)
|
||||
```
|
||||
|
|
@ -17,8 +17,8 @@ working.
|
|||
## Build
|
||||
|
||||
```bash
|
||||
go -C apps/cli build -o ../../bin/drm . # host CLI
|
||||
./bin/drm proxy build # cross-compile the device binary
|
||||
go -C apps/cli build -o ../../bin/streamd . # host CLI
|
||||
./bin/streamd proxy build # cross-compile the device binary
|
||||
```
|
||||
|
||||
`proxy build` compiles `device/` for linux/arm64 into
|
||||
|
|
@ -28,20 +28,20 @@ go -C apps/cli build -o ../../bin/drm . # host CLI
|
|||
|
||||
```bash
|
||||
# trust the MITM CA (needs Magisk; mounts into the system store)
|
||||
./bin/drm proxy install-ca --reinject
|
||||
./bin/drm proxy reinject-ca # mount only, CA already pushed
|
||||
./bin/streamd proxy install-ca --reinject
|
||||
./bin/streamd proxy reinject-ca # mount only, CA already pushed
|
||||
|
||||
# structured capture proxy
|
||||
./bin/drm proxy start --install-ca --reinject
|
||||
./bin/drm proxy stop
|
||||
./bin/streamd proxy start --install-ca --reinject
|
||||
./bin/streamd proxy stop
|
||||
|
||||
# record everything while you explore an unknown app
|
||||
./bin/drm proxy discover --install-ca --reinject
|
||||
./bin/drm proxy discover --force-stop <package> # so it inherits the CA mount
|
||||
./bin/streamd proxy discover --install-ca --reinject
|
||||
./bin/streamd proxy discover --force-stop <package> # so it inherits the CA mount
|
||||
|
||||
# pull artifacts without re-running, and release the phone
|
||||
./bin/drm proxy pull
|
||||
./bin/drm proxy clear-proxy
|
||||
./bin/streamd proxy pull
|
||||
./bin/streamd proxy clear-proxy
|
||||
```
|
||||
|
||||
Always clear the proxy when done, or the phone keeps pointing at a dead listener.
|
||||
|
|
@ -53,7 +53,7 @@ phone can stay on NordVPN UK; nothing sets `http_proxy`.
|
|||
|
||||
```bash
|
||||
# leave UK VPN connected on the phone, then:
|
||||
./bin/drm proxy transparent --package bbc.iplayer.android --reinject
|
||||
./bin/streamd proxy transparent --package bbc.iplayer.android --reinject
|
||||
# open the app / play — Ctrl+C stops iptables and pulls files
|
||||
```
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ Force-stop the target app once after CA reinject so it inherits the Magisk CA mo
|
|||
|
||||
The device binary cannot read an app module's values file, so a module's
|
||||
manifest-scoring hosts are passed to it as flags (`--match`, `--score-host`,
|
||||
`--score-deny`). `drm capture` does this automatically.
|
||||
`--score-deny`). `streamd capture` does this automatically.
|
||||
|
||||
## Artifacts
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module drmdecryption/apps/proxy
|
||||
module streamd/apps/proxy
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require drmdecryption v0.0.0
|
||||
require streamd v0.0.0
|
||||
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/proxy"
|
||||
"drmdecryption/repo"
|
||||
"streamd/adb"
|
||||
"streamd/proxy"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Run dispatches a proxy subcommand. args[0] is the subcommand name.
|
||||
|
|
@ -130,7 +130,7 @@ func buildCmd(args []string) {
|
|||
|
||||
if _, err := os.Stat(deviceDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "proxy build needs the full source tree (apps/proxy/device).\n")
|
||||
fmt.Fprintf(os.Stderr, "For a release zip, put proxy-android-arm64 next to drm.exe instead — no Go build required.\n")
|
||||
fmt.Fprintf(os.Stderr, "For a release zip, put proxy-android-arm64 next to streamd instead — no Go build required.\n")
|
||||
fmt.Fprintf(os.Stderr, "Missing: %s\n", deviceDir)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# streamd
|
||||
|
||||
Control plane: REST API, SQLite, dashboard and media supervisor. Hosted by the
|
||||
single binary as `drm serve`.
|
||||
single binary as `streamd serve`.
|
||||
|
||||
```text
|
||||
apps/streamd/
|
||||
|
|
@ -17,7 +17,7 @@ apps/streamd/
|
|||
## Run
|
||||
|
||||
```bash
|
||||
./bin/drm serve --bind 127.0.0.1:8083 --data .cache/streamd
|
||||
./bin/streamd serve --bind 127.0.0.1:8083 --data .cache/streamd
|
||||
```
|
||||
|
||||
`--bind` defaults to **`127.0.0.1:8083`** (loopback). Binding `0.0.0.0` (or any
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
module drmdecryption/apps/streamd
|
||||
module streamd/apps/streamd
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
drmdecryption v0.0.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
modernc.org/sqlite v1.34.5
|
||||
streamd v0.0.0
|
||||
)
|
||||
|
||||
replace drmdecryption => ../pkg
|
||||
replace streamd => ../pkg
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/deps"
|
||||
"drmdecryption/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/deps"
|
||||
"streamd/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/modstore"
|
||||
)
|
||||
|
||||
type Supervisor interface {
|
||||
|
|
@ -56,7 +57,11 @@ type Handler struct {
|
|||
Deps deps.Status
|
||||
WWWRoot string // data/www — used to report variant playlist health
|
||||
LogRoot string // data/logs — source for the log tail endpoints
|
||||
Log *slog.Logger
|
||||
DataDir string // streamd --data root
|
||||
Modules *modstore.Store
|
||||
// ModulesNotify is set when the hub supports module change pushes.
|
||||
ModulesNotify ModulesNotifier
|
||||
Log *slog.Logger
|
||||
}
|
||||
|
||||
func (h *Handler) Mount(mux *http.ServeMux) {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package api
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/mpd"
|
||||
"drmdecryption/repo"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/modhost"
|
||||
"streamd/mpd"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// appInfo describes one modules/<name>/ provider to the dashboard, so the UI
|
||||
|
|
@ -16,6 +16,7 @@ type appInfo struct {
|
|||
Channels []channelInfo `json:"channels"`
|
||||
Rewriter string `json:"rewriter"`
|
||||
HasConfig bool `json:"has_config"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type channelInfo struct {
|
||||
|
|
@ -23,7 +24,9 @@ type channelInfo struct {
|
|||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
// apps answers GET /api/apps: which providers exist under modules/.
|
||||
// apps answers GET /api/apps: which providers exist under the panel modules store.
|
||||
// A single module that fails to describe is skipped with an error field rather
|
||||
// than failing the whole list (bad uploads must not blank the stream pickers).
|
||||
func (h *Handler) apps(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
writeErr(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
|
|
@ -33,13 +36,27 @@ func (h *Handler) apps(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
out := []appInfo{}
|
||||
listed, err := modhost.ListAll(repo.Root())
|
||||
mods, err := modhost.Discover(repo.Root())
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
for _, L := range listed {
|
||||
d := L.Desc
|
||||
for _, m := range mods {
|
||||
bin, err := modhost.EnsureBuilt(m)
|
||||
if err != nil {
|
||||
out = append(out, appInfo{Name: m.Name, Channels: []channelInfo{}, Rewriter: "none", Error: err.Error()})
|
||||
h.logger().Warn("module describe skipped", "module", m.Name, "err", err)
|
||||
continue
|
||||
}
|
||||
d, err := modhost.RunDescribe(bin)
|
||||
if err != nil {
|
||||
out = append(out, appInfo{Name: m.Name, Channels: []channelInfo{}, Rewriter: "none", Error: err.Error()})
|
||||
h.logger().Warn("module describe skipped", "module", m.Name, "err", err)
|
||||
continue
|
||||
}
|
||||
if d.Name == "" {
|
||||
d.Name = m.Name
|
||||
}
|
||||
info := appInfo{Name: d.Name, Channels: []channelInfo{}, Rewriter: "none"}
|
||||
for _, ch := range d.Channels {
|
||||
info.Channels = append(info.Channels, channelInfo{ID: ch.ID, Label: ch.Label})
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/mpd"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// MountControl adds the bulk, duplicate, probe, settings and schedule routes.
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/logfile"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/logfile"
|
||||
)
|
||||
|
||||
// logSources maps a caller-supplied source name to the log file suffix the
|
||||
|
|
|
|||
|
|
@ -1,93 +1,160 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/modstore"
|
||||
)
|
||||
|
||||
// moduleInfo is one modules/<name>/ entry for agent sync.
|
||||
type moduleInfo struct {
|
||||
Name string `json:"name"`
|
||||
HasYAML bool `json:"has_yaml"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
// ModulesNotifier pushes module change events to agents and the dashboard.
|
||||
type ModulesNotifier interface {
|
||||
NotifyModulesChanged(name, reason string)
|
||||
}
|
||||
|
||||
var moduleNameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
|
||||
func (h *Handler) modStore() *modstore.Store {
|
||||
if h.Modules != nil {
|
||||
return h.Modules
|
||||
}
|
||||
root := filepath.Join(h.DataDir, "modules")
|
||||
return modstore.New(root)
|
||||
}
|
||||
|
||||
func (h *Handler) notifyModules(name, reason string) {
|
||||
if h.ModulesNotify != nil {
|
||||
h.ModulesNotify.NotifyModulesChanged(name, reason)
|
||||
return
|
||||
}
|
||||
// Hub also implements Notifier; prefer the dedicated method when available.
|
||||
if n, ok := h.Notifier.(ModulesNotifier); ok {
|
||||
n.NotifyModulesChanged(name, reason)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) modules(w http.ResponseWriter, r *http.Request) {
|
||||
path := strings.TrimPrefix(r.URL.Path, "/api/modules")
|
||||
path = strings.Trim(path, "/")
|
||||
|
||||
// Module metadata describes the provider plugins installed on this host,
|
||||
// so even reading it needs a principal.
|
||||
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case path == "" && r.Method == http.MethodGet:
|
||||
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
|
||||
return
|
||||
}
|
||||
h.listModules(w, r)
|
||||
case path == "upload" && r.Method == http.MethodPost:
|
||||
h.uploadModule(w, r)
|
||||
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodGet:
|
||||
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
|
||||
return
|
||||
}
|
||||
h.getModule(w, r, path)
|
||||
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodPut:
|
||||
h.putModule(w, r, path)
|
||||
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodDelete:
|
||||
h.deleteModule(w, r, path)
|
||||
case strings.HasSuffix(path, "/yaml") && r.Method == http.MethodGet:
|
||||
name := strings.TrimSuffix(path, "/yaml")
|
||||
name = strings.Trim(name, "/")
|
||||
h.getModuleYAML(w, r, name)
|
||||
case strings.HasSuffix(path, "/package") && r.Method == http.MethodGet:
|
||||
name := strings.TrimSuffix(path, "/package")
|
||||
name = strings.Trim(name, "/")
|
||||
h.getModulePackage(w, r, name)
|
||||
default:
|
||||
writeErr(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) listModules(w http.ResponseWriter, r *http.Request) {
|
||||
root := repo.Root()
|
||||
dir := modhost.ModulesDir(root)
|
||||
ents, err := os.ReadDir(dir)
|
||||
list, err := h.modStore().List()
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"modules": []moduleInfo{}})
|
||||
return
|
||||
}
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
out := []moduleInfo{}
|
||||
for _, e := range ents {
|
||||
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
info := moduleYAMLInfo(filepath.Join(dir, e.Name()), e.Name())
|
||||
out = append(out, info)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"modules": out})
|
||||
writeJSON(w, http.StatusOK, map[string]any{"modules": list})
|
||||
}
|
||||
|
||||
func (h *Handler) getModule(w http.ResponseWriter, r *http.Request, name string) {
|
||||
if !moduleNameRe.MatchString(name) {
|
||||
if !modstore.NameRe.MatchString(name) {
|
||||
writeErr(w, http.StatusBadRequest, "invalid module name")
|
||||
return
|
||||
}
|
||||
info := moduleYAMLInfo(filepath.Join(modhost.ModulesDir(repo.Root()), name), name)
|
||||
writeJSON(w, http.StatusOK, info)
|
||||
info := h.modStore().Info(name)
|
||||
if !info.HasYAML && !info.HasPackage {
|
||||
writeErr(w, http.StatusNotFound, "module not found")
|
||||
return
|
||||
}
|
||||
out := map[string]any{"module": info}
|
||||
if r.URL.Query().Get("include") == "yaml" {
|
||||
// YAML may hold secrets — operator+.
|
||||
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
|
||||
return
|
||||
}
|
||||
raw, err := h.modStore().ReadYAML(name)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
out["yaml"] = string(raw)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
func (h *Handler) getModuleYAML(w http.ResponseWriter, r *http.Request, name string) {
|
||||
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
|
||||
return
|
||||
}
|
||||
if !modstore.NameRe.MatchString(name) {
|
||||
writeErr(w, http.StatusBadRequest, "invalid module name")
|
||||
return
|
||||
}
|
||||
raw, err := h.modStore().ReadYAML(name)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/yaml; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(raw)
|
||||
}
|
||||
|
||||
func (h *Handler) getModulePackage(w http.ResponseWriter, r *http.Request, name string) {
|
||||
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
|
||||
return
|
||||
}
|
||||
if !modstore.NameRe.MatchString(name) {
|
||||
writeErr(w, http.StatusBadRequest, "invalid module name")
|
||||
return
|
||||
}
|
||||
f, _, err := h.modStore().OpenPackage(name)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
modTime := time.Time{}
|
||||
if st, err := f.Stat(); err == nil {
|
||||
modTime = st.ModTime()
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+name+`.zip"`)
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
http.ServeContent(w, r, name+".zip", modTime, f)
|
||||
}
|
||||
|
||||
func (h *Handler) putModule(w http.ResponseWriter, r *http.Request, name string) {
|
||||
// Writing a module.yaml changes how streams are captured on this host:
|
||||
// operator, and recorded.
|
||||
p, ok := auth.Guard(w, r, auth.RoleOperator)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if !moduleNameRe.MatchString(name) {
|
||||
if !modstore.NameRe.MatchString(name) {
|
||||
writeErr(w, http.StatusBadRequest, "invalid module name")
|
||||
return
|
||||
}
|
||||
|
|
@ -104,47 +171,84 @@ func (h *Handler) putModule(w http.ResponseWriter, r *http.Request, name string)
|
|||
writeErr(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if len(strings.TrimSpace(string(yamlBytes))) == 0 {
|
||||
writeErr(w, http.StatusBadRequest, "empty module.yaml")
|
||||
|
||||
info, err := h.modStore().WriteYAML(name, yamlBytes)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
modDir := filepath.Join(modhost.ModulesDir(repo.Root()), name)
|
||||
if err := os.MkdirAll(modDir, 0o755); err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
dest := filepath.Join(modDir, "module.yaml")
|
||||
tmp := dest + ".tmp"
|
||||
if err := os.WriteFile(tmp, yamlBytes, 0o644); err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if err := os.Rename(tmp, dest); err != nil {
|
||||
_ = os.Remove(tmp)
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
info := moduleYAMLInfo(modDir, name)
|
||||
h.audit(r, p, http.StatusOK, "uploaded module.yaml for "+name)
|
||||
h.audit(r, p, http.StatusOK, "updated module.yaml for "+name)
|
||||
h.logger().Info("module.yaml updated", "module", name, "by", p.Actor(), "sha256", info.YAMLSHA256)
|
||||
h.notifyModules(name, "yaml_updated")
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
"module": info,
|
||||
})
|
||||
}
|
||||
|
||||
func moduleYAMLInfo(modDir, name string) moduleInfo {
|
||||
info := moduleInfo{Name: name}
|
||||
b, err := os.ReadFile(filepath.Join(modDir, "module.yaml"))
|
||||
if err != nil {
|
||||
return info
|
||||
func (h *Handler) deleteModule(w http.ResponseWriter, r *http.Request, name string) {
|
||||
p, ok := auth.Guard(w, r, auth.RoleOperator)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
sum := sha256.Sum256(b)
|
||||
info.HasYAML = true
|
||||
info.YAMLSHA256 = hex.EncodeToString(sum[:])
|
||||
return info
|
||||
if !modstore.NameRe.MatchString(name) {
|
||||
writeErr(w, http.StatusBadRequest, "invalid module name")
|
||||
return
|
||||
}
|
||||
if err := h.modStore().Delete(name); err != nil {
|
||||
writeErr(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
h.audit(r, p, http.StatusOK, "deleted module "+name)
|
||||
h.logger().Info("module deleted", "module", name, "by", p.Actor())
|
||||
h.notifyModules(name, "deleted")
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (h *Handler) uploadModule(w http.ResponseWriter, r *http.Request) {
|
||||
p, ok := auth.Guard(w, r, auth.RoleOperator)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := r.ParseMultipartForm(modstore.MaxPackageBytes + (1 << 20)); err != nil {
|
||||
writeErr(w, http.StatusBadRequest, "multipart: "+err.Error())
|
||||
return
|
||||
}
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
file, hdr, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadRequest, "missing file field")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
if hdr.Size > modstore.MaxPackageBytes {
|
||||
writeErr(w, http.StatusBadRequest, "zip too large")
|
||||
return
|
||||
}
|
||||
raw, err := io.ReadAll(io.LimitReader(file, modstore.MaxPackageBytes+1))
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if int64(len(raw)) > modstore.MaxPackageBytes {
|
||||
writeErr(w, http.StatusBadRequest, "zip too large")
|
||||
return
|
||||
}
|
||||
info, err := h.modStore().InstallZip(raw, name)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
h.audit(r, p, http.StatusOK, "uploaded module package "+info.Name)
|
||||
h.logger().Info("module package uploaded",
|
||||
"module", info.Name, "by", p.Actor(),
|
||||
"package_sha256", info.PackageSHA256, "arches", info.Arches)
|
||||
h.notifyModules(info.Name, "uploaded")
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
"module": info,
|
||||
})
|
||||
}
|
||||
|
||||
// extractModuleYAML accepts raw YAML or JSON {"yaml":"..."}.
|
||||
|
|
@ -163,7 +267,6 @@ func extractModuleYAML(contentType string, body []byte) ([]byte, error) {
|
|||
}
|
||||
return []byte(wrap.YAML), nil
|
||||
default:
|
||||
// text/yaml, application/x-yaml, or bare body
|
||||
return body, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// stalePlaylistS is how old a playlist may get before the output counts as
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/httpx"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/httpx"
|
||||
)
|
||||
|
||||
// Handler serves the auth routes: login/logout/me, user administration, API
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/httpx"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/repo"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// Status is the resolved path for each tool after Ensure.
|
||||
|
|
@ -202,7 +202,7 @@ func httpGet(url string) (*http.Response, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", "null-drm-streamd/1.0")
|
||||
req.Header.Set("User-Agent", "streamd/1.0")
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/httpx"
|
||||
"drmdecryption/apps/streamd/internal/tsfanout"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/httpx"
|
||||
"streamd/apps/streamd/internal/tsfanout"
|
||||
)
|
||||
|
||||
// Supervisor is the subset of the media supervisor the gate needs.
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/auth"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/tsfanout"
|
||||
"streamd/apps/streamd/internal/auth"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/tsfanout"
|
||||
)
|
||||
|
||||
// fakeSup records what the gate asked for, and can pretend a stream comes up.
|
||||
|
|
|
|||
622
apps/streamd/internal/modstore/modstore.go
Normal file
622
apps/streamd/internal/modstore/modstore.go
Normal file
|
|
@ -0,0 +1,622 @@
|
|||
// Package modstore keeps provider modules under the streamd data directory.
|
||||
// Operators upload release-style zips; agents pull package.zip + module.yaml.
|
||||
package modstore
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxPackageBytes = 100 << 20 // 100 MiB
|
||||
manifestName = "manifest.json"
|
||||
packageName = "package.zip"
|
||||
yamlName = "module.yaml"
|
||||
)
|
||||
|
||||
var NameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
|
||||
|
||||
// Info is one module's metadata for the API and agent sync.
|
||||
type Info struct {
|
||||
Name string `json:"name"`
|
||||
HasYAML bool `json:"has_yaml"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
HasPackage bool `json:"has_package"`
|
||||
PackageSHA256 string `json:"package_sha256,omitempty"`
|
||||
Arches []string `json:"arches,omitempty"`
|
||||
SizeBytes int64 `json:"size_bytes,omitempty"`
|
||||
UploadedAt string `json:"uploaded_at,omitempty"`
|
||||
YAMLUpdatedAt string `json:"yaml_updated_at,omitempty"`
|
||||
}
|
||||
|
||||
type Manifest struct {
|
||||
Name string `json:"name"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
PackageSHA256 string `json:"package_sha256,omitempty"`
|
||||
Arches []string `json:"arches,omitempty"`
|
||||
SizeBytes int64 `json:"size_bytes,omitempty"`
|
||||
UploadedAt string `json:"uploaded_at,omitempty"`
|
||||
YAMLUpdatedAt string `json:"yaml_updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// Store is the on-disk module library under <data>/modules.
|
||||
type Store struct {
|
||||
Root string
|
||||
}
|
||||
|
||||
func New(root string) *Store {
|
||||
return &Store{Root: root}
|
||||
}
|
||||
|
||||
func (s *Store) modulesDir() string {
|
||||
return s.Root
|
||||
}
|
||||
|
||||
func (s *Store) modDir(name string) string {
|
||||
return filepath.Join(s.Root, name)
|
||||
}
|
||||
|
||||
func (s *Store) Ensure() error {
|
||||
return os.MkdirAll(s.Root, 0o755)
|
||||
}
|
||||
|
||||
// List returns every module directory under the store.
|
||||
func (s *Store) List() ([]Info, error) {
|
||||
ents, err := os.ReadDir(s.Root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []Info{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
out := make([]Info, 0, len(ents))
|
||||
for _, e := range ents {
|
||||
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
if !NameRe.MatchString(e.Name()) {
|
||||
continue
|
||||
}
|
||||
out = append(out, s.Info(e.Name()))
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Info loads manifest + checks for yaml/package files.
|
||||
func (s *Store) Info(name string) Info {
|
||||
info := Info{Name: name}
|
||||
if !NameRe.MatchString(name) {
|
||||
return info
|
||||
}
|
||||
dir := s.modDir(name)
|
||||
m, err := s.readManifest(dir)
|
||||
if err == nil {
|
||||
info.YAMLSHA256 = m.YAMLSHA256
|
||||
info.PackageSHA256 = m.PackageSHA256
|
||||
info.Arches = append([]string(nil), m.Arches...)
|
||||
info.SizeBytes = m.SizeBytes
|
||||
info.UploadedAt = m.UploadedAt
|
||||
info.YAMLUpdatedAt = m.YAMLUpdatedAt
|
||||
info.HasYAML = m.YAMLSHA256 != ""
|
||||
info.HasPackage = m.PackageSHA256 != ""
|
||||
}
|
||||
// Prefer live file hashes when present so a hand-edited yaml still shows.
|
||||
if b, err := os.ReadFile(filepath.Join(dir, yamlName)); err == nil {
|
||||
info.HasYAML = true
|
||||
sum := sha256.Sum256(b)
|
||||
info.YAMLSHA256 = hex.EncodeToString(sum[:])
|
||||
}
|
||||
if st, err := os.Stat(filepath.Join(dir, packageName)); err == nil && !st.IsDir() {
|
||||
info.HasPackage = true
|
||||
if info.PackageSHA256 == "" {
|
||||
if sum, err := fileSHA256(filepath.Join(dir, packageName)); err == nil {
|
||||
info.PackageSHA256 = sum
|
||||
}
|
||||
}
|
||||
if info.SizeBytes == 0 {
|
||||
info.SizeBytes = st.Size()
|
||||
}
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
// ReadYAML returns module.yaml bytes.
|
||||
func (s *Store) ReadYAML(name string) ([]byte, error) {
|
||||
if !NameRe.MatchString(name) {
|
||||
return nil, fmt.Errorf("invalid module name")
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(s.modDir(name), yamlName))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("module %s: no module.yaml", name)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// WriteYAML atomically replaces module.yaml and updates the manifest.
|
||||
func (s *Store) WriteYAML(name string, yamlBytes []byte) (Info, error) {
|
||||
if !NameRe.MatchString(name) {
|
||||
return Info{}, fmt.Errorf("invalid module name")
|
||||
}
|
||||
if len(strings.TrimSpace(string(yamlBytes))) == 0 {
|
||||
return Info{}, fmt.Errorf("empty module.yaml")
|
||||
}
|
||||
dir := s.modDir(name)
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
dest := filepath.Join(dir, yamlName)
|
||||
if err := atomicWrite(dest, yamlBytes, 0o644); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
sum := sha256.Sum256(yamlBytes)
|
||||
now := time.Now().UTC().Format(time.RFC3339)
|
||||
m, _ := s.readManifest(dir)
|
||||
m.Name = name
|
||||
m.YAMLSHA256 = hex.EncodeToString(sum[:])
|
||||
m.YAMLUpdatedAt = now
|
||||
if m.UploadedAt == "" {
|
||||
m.UploadedAt = now
|
||||
}
|
||||
if err := s.writeManifest(dir, m); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
return s.Info(name), nil
|
||||
}
|
||||
|
||||
// OpenPackage returns a ReadCloser for package.zip plus size.
|
||||
func (s *Store) OpenPackage(name string) (*os.File, int64, error) {
|
||||
if !NameRe.MatchString(name) {
|
||||
return nil, 0, fmt.Errorf("invalid module name")
|
||||
}
|
||||
path := filepath.Join(s.modDir(name), packageName)
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, 0, fmt.Errorf("module %s: no package.zip", name)
|
||||
}
|
||||
return nil, 0, err
|
||||
}
|
||||
st, err := f.Stat()
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return nil, 0, err
|
||||
}
|
||||
return f, st.Size(), nil
|
||||
}
|
||||
|
||||
// Delete removes the module directory.
|
||||
func (s *Store) Delete(name string) error {
|
||||
if !NameRe.MatchString(name) {
|
||||
return fmt.Errorf("invalid module name")
|
||||
}
|
||||
dir := s.modDir(name)
|
||||
if _, err := os.Stat(dir); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("module %s not found", name)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
// InstallZip stores zipBytes as package.zip, extracts into the module dir,
|
||||
// promotes the host-arch binary, and writes the manifest.
|
||||
// nameHint may be empty; the zip layout is used to infer the name.
|
||||
func (s *Store) InstallZip(zipBytes []byte, nameHint string) (Info, error) {
|
||||
if len(zipBytes) == 0 {
|
||||
return Info{}, fmt.Errorf("empty zip")
|
||||
}
|
||||
if int64(len(zipBytes)) > MaxPackageBytes {
|
||||
return Info{}, fmt.Errorf("zip exceeds %d byte limit", MaxPackageBytes)
|
||||
}
|
||||
|
||||
name, entries, err := inspectZip(zipBytes, nameHint)
|
||||
if err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
if !NameRe.MatchString(name) {
|
||||
return Info{}, fmt.Errorf("invalid module name %q", name)
|
||||
}
|
||||
|
||||
if err := s.Ensure(); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
dir := s.modDir(name)
|
||||
tmpDir, err := os.MkdirTemp(s.Root, "."+name+".tmp-*")
|
||||
if err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if err := extractZipEntries(zipBytes, entries, tmpDir); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
if err := promoteHostBinary(tmpDir, name); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
yamlPath := filepath.Join(tmpDir, yamlName)
|
||||
if _, err := os.Stat(yamlPath); err != nil {
|
||||
return Info{}, fmt.Errorf("zip missing module.yaml")
|
||||
}
|
||||
arches := detectArches(tmpDir, name)
|
||||
pkgSum := sha256.Sum256(zipBytes)
|
||||
yamlRaw, err := os.ReadFile(yamlPath)
|
||||
if err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
yamlSum := sha256.Sum256(yamlRaw)
|
||||
now := time.Now().UTC().Format(time.RFC3339)
|
||||
m := Manifest{
|
||||
Name: name,
|
||||
YAMLSHA256: hex.EncodeToString(yamlSum[:]),
|
||||
PackageSHA256: hex.EncodeToString(pkgSum[:]),
|
||||
Arches: arches,
|
||||
SizeBytes: int64(len(zipBytes)),
|
||||
UploadedAt: now,
|
||||
YAMLUpdatedAt: now,
|
||||
}
|
||||
if err := s.writeManifest(tmpDir, m); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
if err := atomicWrite(filepath.Join(tmpDir, packageName), zipBytes, 0o644); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
|
||||
// Replace the live module dir.
|
||||
backup := dir + ".bak"
|
||||
_ = os.RemoveAll(backup)
|
||||
if _, err := os.Stat(dir); err == nil {
|
||||
if err := os.Rename(dir, backup); err != nil {
|
||||
return Info{}, err
|
||||
}
|
||||
}
|
||||
if err := os.Rename(tmpDir, dir); err != nil {
|
||||
_ = os.Rename(backup, dir)
|
||||
return Info{}, err
|
||||
}
|
||||
_ = os.RemoveAll(backup)
|
||||
return s.Info(name), nil
|
||||
}
|
||||
|
||||
type zipEntry struct {
|
||||
// Rel is the path relative to the module root inside the zip (forward slashes).
|
||||
Rel string
|
||||
File *zip.File
|
||||
}
|
||||
|
||||
func inspectZip(zipBytes []byte, nameHint string) (name string, entries []zipEntry, err error) {
|
||||
zr, err := zip.NewReader(newBytesReaderAt(zipBytes), int64(len(zipBytes)))
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("open zip: %w", err)
|
||||
}
|
||||
return inspectZipReader(zr, nameHint)
|
||||
}
|
||||
|
||||
type bytesReaderAt struct{ b []byte }
|
||||
|
||||
func newBytesReaderAt(b []byte) *bytesReaderAt { return &bytesReaderAt{b: b} }
|
||||
|
||||
func (r *bytesReaderAt) ReadAt(p []byte, off int64) (int, error) {
|
||||
if off < 0 {
|
||||
return 0, errors.New("negative offset")
|
||||
}
|
||||
if off >= int64(len(r.b)) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
n := copy(p, r.b[off:])
|
||||
if n < len(p) {
|
||||
return n, io.EOF
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func inspectZipReader(zr *zip.Reader, nameHint string) (string, []zipEntry, error) {
|
||||
hint := strings.TrimSpace(nameHint)
|
||||
if hint != "" && !NameRe.MatchString(hint) {
|
||||
return "", nil, fmt.Errorf("invalid module name %q", hint)
|
||||
}
|
||||
|
||||
prefix := ""
|
||||
topDirs := map[string]struct{}{}
|
||||
hasRootFile := false
|
||||
|
||||
for _, f := range zr.File {
|
||||
name := strings.ReplaceAll(f.Name, "\\", "/")
|
||||
name = strings.TrimPrefix(name, "./")
|
||||
if name == "" || strings.HasPrefix(name, "__MACOSX/") || strings.HasSuffix(name, ".DS_Store") {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(name, "/")
|
||||
if len(parts) > 0 && parts[0] != "" {
|
||||
if f.FileInfo().IsDir() || len(parts) > 1 {
|
||||
topDirs[parts[0]] = struct{}{}
|
||||
}
|
||||
if len(parts) == 1 && !f.FileInfo().IsDir() {
|
||||
hasRootFile = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case hint != "":
|
||||
prefix = ""
|
||||
// If every entry is under hint/, strip it.
|
||||
allUnder := true
|
||||
for _, f := range zr.File {
|
||||
n := strings.ReplaceAll(f.Name, "\\", "/")
|
||||
n = strings.TrimPrefix(n, "./")
|
||||
if n == "" || strings.HasPrefix(n, "__MACOSX/") {
|
||||
continue
|
||||
}
|
||||
if n != hint && !strings.HasPrefix(n, hint+"/") {
|
||||
allUnder = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if allUnder {
|
||||
prefix = hint + "/"
|
||||
}
|
||||
case hasRootFile:
|
||||
// Flat zip: module.yaml at root. Name must be provided or inferred from binary.
|
||||
prefix = ""
|
||||
case len(topDirs) == 1:
|
||||
for d := range topDirs {
|
||||
prefix = d + "/"
|
||||
if hint == "" {
|
||||
hint = d
|
||||
}
|
||||
}
|
||||
default:
|
||||
return "", nil, fmt.Errorf("cannot infer module name from zip; pass name= or use a single top-level folder")
|
||||
}
|
||||
|
||||
if hint == "" {
|
||||
// Try to infer from .bin/<arch>/<name> or .bin/<name>.
|
||||
for _, f := range zr.File {
|
||||
n := strings.ReplaceAll(f.Name, "\\", "/")
|
||||
n = strings.TrimPrefix(n, "./")
|
||||
if prefix != "" {
|
||||
if !strings.HasPrefix(n, prefix) {
|
||||
continue
|
||||
}
|
||||
n = strings.TrimPrefix(n, prefix)
|
||||
}
|
||||
base := filepath.Base(n)
|
||||
base = strings.TrimSuffix(base, ".exe")
|
||||
if strings.HasPrefix(n, ".bin/") && NameRe.MatchString(base) && base != ".bin" {
|
||||
hint = base
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if hint == "" {
|
||||
return "", nil, fmt.Errorf("cannot infer module name from zip; pass name=")
|
||||
}
|
||||
if !NameRe.MatchString(hint) {
|
||||
return "", nil, fmt.Errorf("invalid module name %q", hint)
|
||||
}
|
||||
|
||||
var entries []zipEntry
|
||||
for _, f := range zr.File {
|
||||
n := strings.ReplaceAll(f.Name, "\\", "/")
|
||||
n = strings.TrimPrefix(n, "./")
|
||||
if n == "" || strings.HasPrefix(n, "__MACOSX/") || strings.HasSuffix(n, ".DS_Store") {
|
||||
continue
|
||||
}
|
||||
rel := n
|
||||
if prefix != "" {
|
||||
if !strings.HasPrefix(n, prefix) {
|
||||
continue
|
||||
}
|
||||
rel = strings.TrimPrefix(n, prefix)
|
||||
}
|
||||
if rel == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(rel, "..") {
|
||||
return "", nil, fmt.Errorf("zip slip: %s", f.Name)
|
||||
}
|
||||
entries = append(entries, zipEntry{Rel: rel, File: f})
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
return "", nil, fmt.Errorf("zip has no files for module %s", hint)
|
||||
}
|
||||
return hint, entries, nil
|
||||
}
|
||||
|
||||
func extractZipEntries(zipBytes []byte, entries []zipEntry, destDir string) error {
|
||||
_ = zipBytes // entries already hold openable *zip.File from the same buffer
|
||||
for _, e := range entries {
|
||||
target := filepath.Join(destDir, filepath.FromSlash(e.Rel))
|
||||
// Zip-slip: ensure target stays under destDir.
|
||||
if !isUnder(destDir, target) {
|
||||
return fmt.Errorf("zip slip: %s", e.Rel)
|
||||
}
|
||||
if e.File.FileInfo().IsDir() || strings.HasSuffix(e.Rel, "/") {
|
||||
if err := os.MkdirAll(target, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
rc, err := e.File.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mode := e.File.Mode()
|
||||
if mode&0o111 != 0 {
|
||||
mode = 0o755
|
||||
} else {
|
||||
mode = 0o644
|
||||
}
|
||||
err = copyToFile(target, rc, mode)
|
||||
_ = rc.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isUnder(root, path string) bool {
|
||||
absRoot, err1 := filepath.Abs(root)
|
||||
absPath, err2 := filepath.Abs(path)
|
||||
if err1 != nil || err2 != nil {
|
||||
return false
|
||||
}
|
||||
rel, err := filepath.Rel(absRoot, absPath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return rel == "." || (!strings.HasPrefix(rel, "..") && !filepath.IsAbs(rel))
|
||||
}
|
||||
|
||||
func copyToFile(dest string, r io.Reader, mode os.FileMode) error {
|
||||
tmp := dest + ".partial"
|
||||
f, err := os.OpenFile(tmp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, copyErr := io.Copy(f, r)
|
||||
closeErr := f.Close()
|
||||
if copyErr != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return copyErr
|
||||
}
|
||||
if closeErr != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return closeErr
|
||||
}
|
||||
_ = os.Remove(dest)
|
||||
return os.Rename(tmp, dest)
|
||||
}
|
||||
|
||||
func promoteHostBinary(modDir, name string) error {
|
||||
want := name
|
||||
if runtime.GOOS == "windows" {
|
||||
want += ".exe"
|
||||
}
|
||||
dest := filepath.Join(modDir, ".bin", want)
|
||||
if fileExists(dest) {
|
||||
return nil
|
||||
}
|
||||
archDir := filepath.Join(modDir, ".bin", runtime.GOOS+"-"+runtime.GOARCH)
|
||||
src := filepath.Join(archDir, want)
|
||||
if !fileExists(src) {
|
||||
// Soft: describe may fail later; zip install still succeeds.
|
||||
return nil
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
return copyToFile(dest, in, 0o755)
|
||||
}
|
||||
|
||||
func detectArches(modDir, name string) []string {
|
||||
binRoot := filepath.Join(modDir, ".bin")
|
||||
ents, err := os.ReadDir(binRoot)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
seen := map[string]struct{}{}
|
||||
var arches []string
|
||||
add := func(a string) {
|
||||
if _, ok := seen[a]; ok {
|
||||
return
|
||||
}
|
||||
seen[a] = struct{}{}
|
||||
arches = append(arches, a)
|
||||
}
|
||||
for _, e := range ents {
|
||||
if e.IsDir() {
|
||||
sub := e.Name() // e.g. windows-amd64
|
||||
if strings.Contains(sub, "-") {
|
||||
add(sub)
|
||||
}
|
||||
continue
|
||||
}
|
||||
base := strings.TrimSuffix(e.Name(), ".exe")
|
||||
if base == name {
|
||||
add(runtime.GOOS + "-" + runtime.GOARCH)
|
||||
}
|
||||
}
|
||||
sort.Strings(arches)
|
||||
return arches
|
||||
}
|
||||
|
||||
func (s *Store) readManifest(dir string) (Manifest, error) {
|
||||
var m Manifest
|
||||
b, err := os.ReadFile(filepath.Join(dir, manifestName))
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return m, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (s *Store) writeManifest(dir string, m Manifest) error {
|
||||
b, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b = append(b, '\n')
|
||||
return atomicWrite(filepath.Join(dir, manifestName), b, 0o644)
|
||||
}
|
||||
|
||||
func atomicWrite(path string, data []byte, mode os.FileMode) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := path + ".tmp"
|
||||
if err := os.WriteFile(tmp, data, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(tmp, path); err != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fileSHA256(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
func fileExists(p string) bool {
|
||||
st, err := os.Stat(p)
|
||||
return err == nil && !st.IsDir()
|
||||
}
|
||||
149
apps/streamd/internal/modstore/modstore_test.go
Normal file
149
apps/streamd/internal/modstore/modstore_test.go
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
package modstore
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func makeZip(t *testing.T, files map[string][]byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
for name, body := range files {
|
||||
w, err := zw.Create(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.Write(body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func TestInstallZipFlatAndYAMLOnly(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
|
||||
arch := runtime.GOOS + "-" + runtime.GOARCH
|
||||
binName := "demo"
|
||||
if runtime.GOOS == "windows" {
|
||||
binName += ".exe"
|
||||
}
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: com.example\nchannels: {}\n"),
|
||||
".bin/" + arch + "/" + binName: []byte("fake-binary"),
|
||||
".bin/linux-amd64/demo": []byte("linux-bin"),
|
||||
})
|
||||
|
||||
info, err := s.InstallZip(zipBytes, "demo")
|
||||
if err != nil {
|
||||
t.Fatalf("InstallZip: %v", err)
|
||||
}
|
||||
if info.Name != "demo" || !info.HasYAML || !info.HasPackage {
|
||||
t.Fatalf("info = %+v", info)
|
||||
}
|
||||
if info.PackageSHA256 == "" || info.YAMLSHA256 == "" {
|
||||
t.Fatalf("missing hashes: %+v", info)
|
||||
}
|
||||
pkgHash := info.PackageSHA256
|
||||
yamlHash := info.YAMLSHA256
|
||||
|
||||
// Host binary should be promoted.
|
||||
promoted := filepath.Join(root, "demo", ".bin", binName)
|
||||
if !fileExists(promoted) {
|
||||
t.Fatalf("expected promoted binary at %s", promoted)
|
||||
}
|
||||
|
||||
// YAML-only update must not change package hash.
|
||||
info2, err := s.WriteYAML("demo", []byte("package: com.example\nchannels:\n one: {label: One}\n"))
|
||||
if err != nil {
|
||||
t.Fatalf("WriteYAML: %v", err)
|
||||
}
|
||||
if info2.PackageSHA256 != pkgHash {
|
||||
t.Fatalf("package hash changed on yaml edit: %s -> %s", pkgHash, info2.PackageSHA256)
|
||||
}
|
||||
if info2.YAMLSHA256 == yamlHash {
|
||||
t.Fatal("yaml hash should change after edit")
|
||||
}
|
||||
|
||||
raw, err := s.ReadYAML("demo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(raw), "one:") {
|
||||
t.Fatalf("yaml not updated: %s", raw)
|
||||
}
|
||||
|
||||
f, size, err := s.OpenPackage("demo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if size != int64(len(zipBytes)) {
|
||||
t.Fatalf("package size %d want %d", size, len(zipBytes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstallZipTopLevelFolder(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"bbc/module.yaml": []byte("package: bbc.iplayer.android\n"),
|
||||
"bbc/.bin/linux-amd64/bbc": []byte("bin"),
|
||||
"bbc/.bin/windows-amd64/bbc.exe": []byte("winbin"),
|
||||
})
|
||||
info, err := s.InstallZip(zipBytes, "")
|
||||
if err != nil {
|
||||
t.Fatalf("InstallZip: %v", err)
|
||||
}
|
||||
if info.Name != "bbc" {
|
||||
t.Fatalf("name=%q", info.Name)
|
||||
}
|
||||
list, err := s.List()
|
||||
if err != nil || len(list) != 1 || list[0].Name != "bbc" {
|
||||
t.Fatalf("list=%v err=%v", list, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestZipSlipRejected(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
w, err := zw.Create("../evil.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = w.Write([]byte("x"))
|
||||
_ = zw.Close()
|
||||
_, err = s.InstallZip(buf.Bytes(), "demo")
|
||||
if err == nil {
|
||||
t.Fatal("expected zip-slip error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: x\n"),
|
||||
})
|
||||
if _, err := s.InstallZip(zipBytes, "xmod"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Delete("xmod"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "xmod")); !os.IsNotExist(err) {
|
||||
t.Fatalf("dir still present: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"log/slog"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// Supervisor is the subset of the media supervisor the scheduler needs.
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package supervisor
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"drmdecryption/app"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
"streamd/app"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/modhost"
|
||||
"streamd/repo"
|
||||
)
|
||||
|
||||
// streamSettings are the downloader and packager knobs for one stream. They
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package supervisor
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"drmdecryption/adb"
|
||||
"drmdecryption/app"
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/capture"
|
||||
"drmdecryption/mpd"
|
||||
"streamd/adb"
|
||||
"streamd/app"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/capture"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// fakeApp stands in for a compiled-in app module: the supervisor must take its
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// These tests run the real ffmpeg against the real generated command line.
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/logfile"
|
||||
"drmdecryption/apps/streamd/internal/tsfanout"
|
||||
"drmdecryption/mpd"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/logfile"
|
||||
"streamd/apps/streamd/internal/tsfanout"
|
||||
"streamd/mpd"
|
||||
)
|
||||
|
||||
// Media runs N_m3u8DL-RE plus one ffmpeg packager per variant, publishing into
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// Packager defaults. These were literals in the ffmpeg command line before
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// quote and backslash as values, so the test source stays readable where it
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// Stub marks streams as starting/stopped without spawning media workers.
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"drmdecryption/apps/streamd/internal/db"
|
||||
"drmdecryption/apps/streamd/internal/logfile"
|
||||
"streamd/apps/streamd/internal/db"
|
||||
"streamd/apps/streamd/internal/logfile"
|
||||
)
|
||||
|
||||
type variantProc struct {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@
|
|||
<span class="ico" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 4h12M2 8h12M2 12h8"/></svg></span>
|
||||
Streams
|
||||
</a>
|
||||
<a href="#/modules" data-nav="/modules">
|
||||
<span class="ico" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M3 3.5h4.5v4.5H3zM8.5 3.5H13v4.5H8.5zM3 8.5h4.5V13H3zM8.5 8.5H13V13H8.5z"/></svg></span>
|
||||
Modules
|
||||
</a>
|
||||
<a href="#/schedule" data-nav="/schedule">
|
||||
<span class="ico" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5.5"/><path d="M8 5v3.5l2.5 1.5"/></svg></span>
|
||||
Schedule
|
||||
|
|
@ -81,7 +85,7 @@
|
|||
<form id="login-form" class="auth-card">
|
||||
<span class="logo big" aria-hidden="true"></span>
|
||||
<h2 id="gate-title">Sign in to streamd</h2>
|
||||
<p class="auth-sub">Null DRM restream control</p>
|
||||
<p class="auth-sub">Streamd control plane</p>
|
||||
<p id="gate-note" class="hint"></p>
|
||||
<label id="setup-row" hidden>Setup token
|
||||
<input name="setup_token" autocomplete="off" spellcheck="false" />
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue