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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Added:
- **Internet schedule** (new page). Turn the internet off at set times of the week for chosen people (all their devices) or single devices: bedtime on school nights, study time, meal times. One click starts from a ready plan ("School nights", "Every night", "Study time", "Meal times"); a schedule can have several times, a time can run past midnight, and dates can be marked as days off (holidays, Eid). **Bonus time** gives a few extra minutes without changing the schedule. **Always allowed** sites (a school platform, a study site) keep working during every schedule. While a schedule is on, the device's card shows when the internet comes back, the home network (printer, shared drives, the dashboard) keeps working, and the cut is done by the gateway itself, so it works on any phone, tablet, TV or console with no app. Each device gets its end time in the system kernel, so it comes back online on time even if the gateway service restarts or stops. Sites on the "always allowed" list only open on devices that look names up through the gateway; a phone with Private DNS (or a browser with secure DNS) turned on keeps them blocked during a schedule. Contributed by @amr-elgharip2006. Closes #32.

Fixed:
- **Share** (files sent between devices at home) can no longer fill the gateway's disk: one file can be up to 4 GB, all shared files together up to 16 GB, and the gateway always keeps 1 GB free for itself. A file that does not fit is refused with a clear message instead of being half-saved. Contributed by @compnew2006.
- The guest waiting page: entering a guest code now also works when the same browser is logged in to the dashboard, the "start browsing" button gets the focus after approval, hidden parts stay hidden, and the pulsing animation stops for people who turned off motion on their device. Contributed by @compnew2006.
- Website block/allow rules were rebuilt every time the gateway started, so their numbers changed on each restart. They are now kept as they are. If an older version was interrupted in the middle of that rebuild (for example by a power cut), the rules it left behind are put back on the next start instead of being lost. Contributed by @compnew2006.

Expand Down
11 changes: 7 additions & 4 deletions Structure_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,12 @@ The Local Share subsystem (`quota/local_share.py`, `web/share.html`, and the das

- **Elimination of `python-multipart` Overhead**:
Unlike standard form-data endpoints which require third-party C/Rust parsers or external libraries, file uploads leverage pure raw HTTP streaming via Starlette's `request.stream()`:
- Network bytes flow in 64 KB chunks directly from the incoming socket to disk (`data/local_share/<id>/<safe_name>`).
- Total process RAM usage remains $< 1\,\text{MB}$ regardless of whether transferring a small document or a 20 GB multi-file ISO/video.
- The application reads the request in chunks and writes directly to the gateway cache (`data/local_share/<id>/<safe_name>`). It does not buffer the entire file.
- Raw client requests set the sanitized URI-encoded filename via `X-Filename: <encoded_name>` and standard `Content-Type`.
- **Storage limits**:
- Each uploaded file, uncompressed folder member, and generated ZIP is limited to 4 GiB. Stored files, concurrent uploads, in-progress folder archives, and temporary download bundles share a 16 GiB cache limit. Payload writes also stop when they would leave less than 1 GiB free on the cache filesystem (the database, logs and updates live on the same disk).
- Limits are checked during streaming and ZIP creation, including the ZIP directory written at finalization. The API returns HTTP 413 and discards the rejected partial file or archive. After a folder upload fails, start a new folder session.
- Cache usage includes payload files already present at startup. Unfinished folder sessions held by the running process are discarded after 30 minutes of inactivity at the next cleanup pass.
- **Atomic Index Persistence**:
- Metadata is persisted in `data/local_share/index.json`.
- Mutating operations (`save_file_stream`, `delete_file`, `save_text`, `cleanup_expired`) are synchronized behind an `asyncio.Lock()`.
Expand All @@ -1200,7 +1203,7 @@ The Local Share subsystem (`quota/local_share.py`, `web/share.html`, and the das
- Household devices connected to the router's Wi-Fi or Ethernet LAN can freely upload, download, and share notes without requiring administrative credentials or session tokens.
- Requesters arriving from external WAN addresses (in Strong WAN mode) are automatically denied with `403 Forbidden` unless possessing a cryptographically signed HMAC admin session cookie (`COOKIE_NAME`).
- **CSRF & WAF Immunity on LAN**:
- LAN requests bypass strict WAN WAF body-size caps, enabling full-bandwidth gigabit file transfers without triggering false-positive rate-limit bans.
- LAN requests bypass WAN WAF body-size checks. Local Share enforces its storage limits independently.

### 3. Client Experience & Standalone Web Portal

Expand Down Expand Up @@ -1255,7 +1258,7 @@ The Local Share subsystem (`quota/local_share.py`, `web/share.html`, and the das
- **`Content-Length` only for single files**:
A multi-file/folder send is a ZIP the *sender* builds on the fly; it is larger than the sum of the announced file sizes. `GET /api/share/live/download/{id}` therefore omits `Content-Length` for names ending in `.zip` (chunked body); with a too-small length the server aborted the body and browsers reported a cancelled download. [`tests/test_local_share.py`]
- **50 MB Live Direct Transfer Safety Clamp**:
To protect low-memory mobile browser engines from memory pressure or prolonged connection hangs during live Wi-Fi streaming, a strict $50\,\text{MB}$ payload limit is enforced. Both frontend interfaces (`initiateDashSendDirect`, `initiateSendDirect`, and multi-folder staging confirm) calculate total payload size upfront and immediately warn users via friendly toast notices if exceeded. The backend WebSocket relay endpoint (`/api/share/live/ws`) additionally enforces this ceiling on `transfer-request` messages, rejecting payloads $> 50\,\text{MB}$ with a descriptive `transfer-error` response. Larger files and folders are routed to standard Local Share upload.
To protect low-memory mobile browser engines from memory pressure or prolonged connection hangs during live Wi-Fi streaming, a strict $50\,\text{MB}$ payload limit is enforced. Both frontend interfaces (`initiateDashSendDirect`, `initiateSendDirect`, and multi-folder staging confirm) calculate total payload size upfront and immediately warn users via friendly toast notices if exceeded. The backend WebSocket relay endpoint (`/api/share/live/ws`) additionally enforces this ceiling on `transfer-request` messages, rejecting payloads $> 50\,\text{MB}$ with a descriptive `transfer-error` response. Larger files and folders are routed to standard Local Share upload, subject to its storage limits.

---

Expand Down
18 changes: 16 additions & 2 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
from quota.history_analytics import get_history_analytics, get_live_traffic_analytics
from quota.local_share import (
MAX_LIVE_DIRECT_BYTES,
FolderUploadBusy,
FolderUploadNotFound,
LocalShareManager,
ShareLimitExceeded,
detect_device_name,
sanitize_filename,
)
Expand Down Expand Up @@ -1205,14 +1208,25 @@ async def list_shared_items(request: Request) -> dict[str, Any]:
data["server_host"] = request.headers.get("host") or request.url.netloc or "router.local"
return data

@app.exception_handler(ShareLimitExceeded)
async def _local_share_limit(_request: Request, exc: ShareLimitExceeded) -> JSONResponse:
return JSONResponse({"detail": str(exc)}, status_code=413)

@app.exception_handler(FolderUploadNotFound)
async def _local_share_missing_folder(_request: Request, exc: FolderUploadNotFound) -> JSONResponse:
return JSONResponse({"detail": str(exc)}, status_code=404)

@app.exception_handler(FolderUploadBusy)
async def _local_share_busy_folder(_request: Request, exc: FolderUploadBusy) -> JSONResponse:
return JSONResponse({"detail": str(exc)}, status_code=409)

@app.post("/api/share/upload", dependencies=[Depends(_require_local_share_access)])
async def upload_share_file(
request: Request,
ttl: int = 7200,
) -> dict[str, Any]:
"""Stream an uploaded file to the local share cache with automatic TTL.
Uses pure request streaming — zero dependencies on python-multipart and
minimal memory overhead for multi-gigabyte transfers.
Upload limits apply to received bytes even without Content-Length.
"""
raw_name = request.headers.get("x-filename") or request.query_params.get("filename") or "shared_file"
try:
Expand Down
Loading
Loading