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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The complete inventory, including what is deliberately not implemented, is in
|---|---|---|
| Zero-write | `torrent inspect/verify`, `storage probe/map`, `seed discover/plan`, `client status/list`, ordinary `site` reads and `site bonus review`, `reconcile report`, and every `plan`, `status`, `list`, and `inspect` subcommand | None. Reads can still update atime, hydrate offline placeholders, or be recorded by the remote side. |
| Private store | `metafile store init/import`, `storage profile create`, `storage index refresh/refresh-discover`, `reconcile refresh-report`, `site bonus exchange prepare` | The explicit command itself. Owner-only and no-clobber; not encrypted. |
| Tracker-visible | `site metafile fetch` (one GET), `site bonus exchange submit` (at most one POST), `site login` (one POST and one verifying GET) | `--acknowledge-site-effect`, `--acknowledge-bonus-exchange`; `site login` is the command itself, with the cookie written only to a pipe or owner-only file |
| Tracker-visible | `site metafile fetch` (one GET), `site bonus exchange submit` (at most one POST), `site login` (one POST and one verifying GET) | `--acknowledge-site-effect`, `--acknowledge-bonus-exchange`; `site login` is the command itself, with the cookie saved only to an owner-only file or a pipe |
| Target filesystem | `seed materialize run/resume/abandon` | `--acknowledge-filesystem-write`, `--acknowledge-abandon` |
| Downloader | `client adopt/activate/stop/remove run/resume` | `--acknowledge-client-add`, `--acknowledge-client-recheck`, `--acknowledge-client-stop`, `--acknowledge-client-removal`; repeats, re-adds, and observation-only adoption have their own flags |
| Source deletion | `seed retire run/resume`, `seed retire parent-cleanup run/resume` | `--acknowledge-source-deletion`, `--acknowledge-empty-parent-removal` |
Expand Down Expand Up @@ -130,8 +130,10 @@ stdin; interactive TTY input is refused, and the cookie is never persisted:
printf '%s' "$TJUPT_COOKIE" | ptctl site status --cookie-stdin tjupt
```

For TJUPT, `site login --credential-bundle-stdin tjupt` can issue that cookie
from the account password and two-step code instead; see
For TJUPT, `ptctl site login tjupt` can issue that cookie instead: it prompts
for the username, the hidden password, and the two-step code, then saves the
cookie to an owner-only file and prints its path. Scripts and agents use
`--credential-bundle-stdin`; see `ptctl help login` and
[Site reads and bonus exchange](docs/guide/sites.md).

M-Team uses an API key from 控制台 → 实验室 → 建立存取令牌 instead of a cookie,
Expand Down
10 changes: 6 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ Capabilities are small and explicit:
- `auth.login_effectful`

`auth.login_effectful` (`site.SessionLoginer`) signs in with an account
password and optional one-time code, read from one stdin bundle, and returns a
verified cookie credential that ptctl writes only to a non-terminal stdout and
never stores. It sends one login request and at most one verifying read, never
retries, and reports a refusal only by a fixed stop reason.
password and optional one-time code, typed at hidden terminal prompts or read
from one stdin bundle, and returns a verified cookie credential. The CLI saves
it to an owner-only file, by default under the user config directory, or
writes it to a non-terminal stdout, and never reads it back on its own. It
sends one login request and at most one verifying read, never retries, and
reports a refusal only by a fixed stop reason.

Site-specific form or action writes live under narrow namespaced typed ports
and durable action schemas. They are not forced into universal fields. The effectful
Expand Down
16 changes: 12 additions & 4 deletions docs/AUTOMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Every JSON result is a single object on stdout, indented with two spaces:
|---|---|
| General | `version` |
| Site reads | `site.descriptor.list` (`site list`, `site capabilities`), `site.session`, `site.account`, `site.torrent.list`, `site.torrent.detail`, `site.bonus.catalog`, `site.bonus.offer_review` |
| Site login | `site.login` |
| Bonus exchange | `site.bonus.exchange.prepare`, `site.bonus.exchange.submit`, `site.bonus.exchange.status`, `site.bonus.exchange.operation_list`, `site.bonus.exchange.prune`, `site.bonus.exchange.forget` |
| Site metafiles | `site.metafile.fetch`, `site.metafile.binding.list`, `site.metafile.binding.inspect` |
| Metafiles | `metafile.manifest` (`torrent inspect`), `content.verification` (`torrent verify`), `metafile.store.init`, `metafile.store.import`, `metafile.store.inspect` |
Expand Down Expand Up @@ -104,15 +105,22 @@ Per-command details are in
| `--credential-bundle-stdin` | `site bonus exchange submit` for sites that confirm with the account password (TJUPT) | `{"schema":"ptctl.credentials/v1","site_cookie":"...","site_password":"..."}` |
| `--credential-bundle-stdin` | `site login` | `{"schema":"ptctl.credentials/v1","site_username":"...","site_password":"...","site_totp":"123456"}`; `site_totp` is optional |

- An interactive terminal on stdin is refused; the secret must be piped.
- An interactive terminal on stdin is refused; the secret must be piped. The
exception is `site login` without `--credential-bundle-stdin`, which is for
people: it prompts on the terminal with the password and code hidden, and
exits `2` when stdin is not a terminal. Agents always pass the bundle.
- Single secrets are limited to 64 KiB and the bundle to 128 KiB. The bundle is
strict JSON: unknown, duplicate, or missing fields are rejected.
- Site reads, metafile fetch, and reconciliation validate usage, capabilities,
and local inputs before reading stdin.
- Credentials stay in memory. They are never persisted, printed, or forwarded
in error text. The one exception is the session cookie `site login` issues:
it is written to stdout, which must be a pipe or an owner-only file, so the
caller decides where it is kept.
in error text. The one exception is the session cookie `site login` issues.
With `--cookie-file PATH` it is saved to that owner-only file, and
`--output json` then reports a `site.login` object with `cookie_file` and
`session_expires_at` but not the cookie. With the bundle and no
`--cookie-file`, it is written to stdout, which must be a pipe or an
owner-only file. Without the bundle, it is saved under the user config
directory. `ptctl help login` documents every flag.
- `ptctl site capabilities SITE` lists the authentication methods a site
accepts: `cookie_header` takes `--cookie-stdin`, `api_key_header` takes
`--api-key-stdin`. Omitting the flag names the one the site needs.
Expand Down
12 changes: 7 additions & 5 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ deliberately does not. For step-by-step usage, see the
- an explicitly acknowledged TJUPT metafile fetch for one remote ID, using one
bounded GET with no redirect or retry and publishing the strictly validated
exact response only into an initialized private metafile store;
- TJUPT password login with an optional six-digit two-step code from one strict
stdin bundle: one non-retried login POST, recognized refusal pages reported
as fixed stop reasons with the site's remaining-attempts count, and one
verifying read that must name the same account before the new session cookie
is written to a pipe or owner-only stdout;
- TJUPT password login with an optional six-digit two-step code, typed at
hidden terminal prompts by default or passed as one strict stdin bundle by
scripts and agents: one non-retried login POST, recognized refusal pages
reported as fixed stop reasons with the site's remaining-attempts count, and
one verifying read that must name the same account before the new session
cookie is saved to an owner-only file or written to a pipe or owner-only
stdout, with an optional `site.login` JSON report;
- an experimental M-Team session check, account snapshot (username, uploaded
and downloaded bytes, ratio, and bonus), and first-page torrent search with
seeders, leechers, and promotion factors, through one read-only POST per
Expand Down
15 changes: 12 additions & 3 deletions docs/THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,16 @@ the site issued a session cookie. Because TJUPT blocks the client IP after ten
failed logins, a failed or ambiguous login is never retried, the site's own
remaining-attempts count is surfaced when its page states one, and the
two-step page, which echoes the password in a hidden field, is cleared after
classification. The issued cookie is written only to a pipe or an owner-only
stdout file and is kept only after the verifying read names the same account.
classification. The issued cookie is kept only after the verifying read names
the same account. It is then renamed into place from an owner-only temporary
file created before the login request, so an unwritable destination never
costs an attempt and a failed login leaves an earlier cookie file untouched.
Without a cookie file it goes only to a pipe or an owner-only stdout file. The
interactive default reads the password and one-time code from the terminal
with echo turned off before each prompt appears (input typed ahead of a prompt
can still be echoed), restores echo if interrupted, and saves the cookie under the
user config directory, which no command reads back implicitly; a terminal is
accepted only there, never with `--credential-bundle-stdin`.
The M-Team adapter sends at most one bounded POST per command to one of two
read-only JSON API endpoints (`member/profile` and `torrent/search`), with a
non-replayable body of at most 16 KiB, and never retries. HTTP 429 is terminal. There is no cross-process limiter in the alpha, so
Expand Down Expand Up @@ -1501,7 +1509,8 @@ upgrade storage, client, path, or private-variant proof.
### Supply chain

The runtime uses the Go standard library plus `golang.org/x/sys` for audited
OS-specific filesystem security primitives. GitHub Actions are pinned to full
OS-specific filesystem security primitives and echo-off terminal input, and
`golang.org/x/net/html` for site page parsing. GitHub Actions are pinned to full
commit SHAs and receive read-only repository permission. Tests construct
synthetic metafiles; real tracker artifacts are forbidden.

Expand Down
17 changes: 10 additions & 7 deletions docs/TJUPT_ADAPTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ response details do not cross the CLI boundary.

### Login

`site login --credential-bundle-stdin tjupt` implements
`auth.login_effectful`, declared only on the default origin. Usage, the
session length, and stdout safety are checked before stdin is read; the bundle
then carries `site_username`, `site_password`, and an optional `site_totp`,
which TJUPT requires to be exactly six digits. Command usage, output, and stop
reasons are in the [sites guide](guide/sites.md).
`site login tjupt` implements `auth.login_effectful`, declared only on the
default origin. Usage, the session length, and the cookie destination are
checked before the command prompts on the terminal or, with
`--credential-bundle-stdin`, reads stdin. Either way the credentials are a
username, a password, and an optional two-step code, which TJUPT requires to
be exactly six digits. Command usage, output, and stop reasons are in the
[sites guide](guide/sites.md) and `ptctl help login`.

TJUPT's `login.php` posts `username`, `password`, and `logout` (the session
length in days: 1, 7, 14, 30, or 90) to `takelogin.php`. An account with
Expand Down Expand Up @@ -304,7 +305,9 @@ TJUPT blocks the client IP after ten failed logins, so a failed login is never
retried. In October 2026 a login without a code returned the two-step page
with all ten attempts still offered, and a login with a code from a password
manager issued a seven-day `access_token` in two requests that `site status`
and `site account` then accepted.
and `site account` then accepted. The interactive default did the same on a
terminal: neither hidden answer appeared in the terminal output, and
`site status` accepted the cookie file it saved.

## Fixtures

Expand Down
87 changes: 64 additions & 23 deletions docs/guide/sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,73 @@ seeders, leechers, snatches, and promotion when the results table has its
usual shape; otherwise a result keeps only its name and size.

Instead of copying the cookie out of a browser, `site login` can sign in with
the account password and write a new session cookie for the commands above.
It takes one strict `ptctl.credentials/v1` bundle on stdin with
`site_username`, `site_password`, and, for an account with two-step
verification, the current one-time code in `site_totp`. Stdout must be a pipe
or an owner-only file: the command refuses a terminal, a device, or a file
other users can read. One way to build the bundle without putting a secret in
argv, here with the 1Password CLI supplying the code:
the account password and save a new session cookie for the commands above.
Run it in a terminal and answer the prompts:

```console
$ ptctl site login tjupt
Signing in to TJUPT / 北洋园PT with one login request; failed logins count toward the site's lockout.
Username: alice
Password (hidden):
Two-step code (hidden; press Enter if none):
site login succeeded: site=tjupt username=alice session_expires=2026-10-23T08:00:00Z requests=2
session cookie saved to /home/alice/.config/ptctl/sessions/tjupt.cookie (owner-only)
use it with: ptctl site status --cookie-stdin tjupt < '/home/alice/.config/ptctl/sessions/tjupt.cookie'
```

The password and the two-step code are not echoed. Press Enter at the code
prompt when the account has no two-step verification; spaces inside a code are
ignored. Ctrl+C at a prompt quits without sending anything. The cookie is saved
to `ptctl/sessions/SITE.cookie` under the user config directory (`~/.config` on
Linux, `~/Library/Application Support` on macOS, `%AppData%` on Windows),
readable only by you, and replaced atomically by the next login. No command
reads it automatically; pass it on stdin as the last line shows.
`--cookie-file PATH` saves it somewhere else, and `--session-days` picks the
session length the site offers (TJUPT: 1, 7, 14, 30, or 90; default 7).
`ptctl help login` describes every flag.

Scripts and agents pass the credentials instead with `--credential-bundle-stdin`,
as one strict `ptctl.credentials/v1` bundle on stdin: `site_username`,
`site_password`, and, for an account with two-step verification, the current
one-time code in `site_totp`. A terminal on stdin is then refused. With
`--cookie-file` the cookie goes to that file and `--output json` reports a
`site.login` object, without the cookie, on stdout. Without `--cookie-file` the
cookie line and nothing else goes to stdout, which must be a pipe or an
owner-only file, and `--output json` is refused. One way to build the bundle
without putting a secret in argv, here with the 1Password CLI supplying the
code:

```bash
(umask 077
jq -n --arg user "$TJUPT_USER" \
--rawfile password "$PASSWORD_FILE" \
--rawfile totp <(op item get "$TJUPT_ITEM" --otp) \
'{schema: "ptctl.credentials/v1",
site_username: $user,
site_password: ($password | rtrimstr("\n")),
site_totp: ($totp | rtrimstr("\n"))}' | \
ptctl site login --credential-bundle-stdin tjupt > "$COOKIE_FILE")
jq -n --arg user "$TJUPT_USER" \
--rawfile password "$PASSWORD_FILE" \
--rawfile totp <(op item get "$TJUPT_ITEM" --otp) \
'{schema: "ptctl.credentials/v1",
site_username: $user,
site_password: ($password | rtrimstr("\n")),
site_totp: ($totp | rtrimstr("\n"))}' | \
ptctl site login --credential-bundle-stdin --cookie-file "$COOKIE_FILE" --output json tjupt

ptctl site status --cookie-stdin tjupt < "$COOKIE_FILE"
```

Leave out `site_totp` when the account has no two-step verification.
`--session-days` picks the session length the site offers (TJUPT: 1, 7, 14, 30,
or 90; default 7). On success, stdout holds only the cookie line and stderr
reports `site login succeeded: site=tjupt username=... session_expires=...
requests=2`.
```json
{
"schema": "ptctl.dev/v1",
"kind": "site.login",
"data": {
"site_id": "tjupt",
"username": "alice",
"session_days": 7,
"session_expires_at": "2026-10-23T08:00:00Z",
"cookie_file": "/home/alice/tjupt.cookie",
"requests_attempted": 2
}
}
```

Leave out `site_totp` when the account has no two-step verification. In text
mode, stderr reports `site login succeeded: site=tjupt username=...
session_expires=... requests=2` and, with a cookie file, where it was saved.

Login sends one POST and never retries. If the site issues a session cookie,
ptctl waits two seconds and makes one read with it, and keeps the cookie only
Expand All @@ -71,7 +111,7 @@ if that read shows the same signed-in account. Otherwise it exits `1` with
| Reason | Meaning |
|---|---|
| `login_credentials_rejected` | The site refused the username or password. |
| `login_two_factor_required` | The account needs a one-time code and the bundle had none. |
| `login_two_factor_required` | The account needs a one-time code and none was given. |
| `login_two_factor_rejected` | The one-time code was wrong or expired. |
| `login_response_unrecognized` | The site answered with a page ptctl does not recognize. |
| `login_session_unverified` | A cookie was issued, but the verifying read did not show the same signed-in account. The cookie is discarded. |
Expand All @@ -80,7 +120,8 @@ if that read shows the same signed-in account. Otherwise it exits `1` with
TJUPT blocks the client IP after ten failed logins. When the page states how
many attempts are left, the error line ends with `(the site reports N login
attempts left before it blocks this IP)`. Fix the input before trying again,
and never loop `site login`. Usage errors exit `2` before stdin is read.
and never loop `site login`. Usage errors exit `2` before any prompt or stdin
read. A failed login leaves an earlier cookie file untouched.

M-Team reads use a site-issued API key instead of a cookie, passed with
`--api-key-stdin` under the same stdin-only rules. `status`, `account`, and
Expand Down
9 changes: 7 additions & 2 deletions internal/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func (a *app) helpTopic(args []string) error {
fmt.Fprint(a.stdout, `Configuration (explicit inputs; no automatic discovery)

pt cli does not search your home/project directories for configuration or credentials.
There is no --config file or saved downloader-login profile.
There is no --config file or saved downloader-login profile. The one thing
saved by default is the session cookie from an interactive 'pt site login',
under the user config directory; no command reads it back automatically
(see 'pt help login').

Downloader reads:
--driver qbittorrent|transmission (default: qbittorrent)
Expand Down Expand Up @@ -72,6 +75,8 @@ report is read-only. The separate refresh-report command writes a storage-index

Details: pt help reconcile report | pt help config
`)
case "login", "site login":
fmt.Fprint(a.stdout, siteLoginHelp)
case "version":
return a.version([]string{"--help"})
case "torrent inspect":
Expand All @@ -85,7 +90,7 @@ Details: pt help reconcile report | pt help config
case "reconcile report":
return a.reconcileCommand([]string{"report", "--help"})
default:
return usageError("unknown help topic; use torrent, client, reconcile, config, version, or 'pt help' for the complete command list")
return usageError("unknown help topic; use torrent, client, reconcile, login, config, version, or 'pt help' for the complete command list")
}
return nil
}
2 changes: 2 additions & 0 deletions internal/cli/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func jsonKind(data any) string {
return typed.kind
case domain.BonusCatalog:
return "site.bonus.catalog"
case siteLoginReport:
return "site.login"
case *metafile.MetaInfo:
return "metafile.manifest"
case metafileStoreReport:
Expand Down
Loading
Loading