init
This commit is contained in:
54 files changed
+4604
No files matched your search
@@ -0,0 +1,115 @@
|
||||
# مدار · Madar
|
||||
|
||||
A Persian, RTL feature playground for Eitaa apps and mini apps. PHP 8.2+, vanilla JavaScript and CSS; no database, frontend build, cron job or persistent application server required on the host.
|
||||
|
||||
## Project structure
|
||||
|
||||
```text
|
||||
bootstrap/
|
||||
autoload.php PSR-4-compatible autoloader and helper loading
|
||||
app.php Application startup
|
||||
config/
|
||||
app.php Committed, non-secret defaults
|
||||
local.example.php Example local overrides
|
||||
local.php Optional private overrides (ignored)
|
||||
public/ The ONLY web document root
|
||||
index.php Page entry point
|
||||
api.php JSON API entry point
|
||||
sample.php Postcard download entry point
|
||||
assets/ Browser JavaScript, CSS and font
|
||||
resources/views/ Page and postcard templates
|
||||
app/
|
||||
Application.php Constructs and connects dependencies
|
||||
Config.php Loads and validates configuration
|
||||
Eitaa/Client.php Outbound EitaaYar HTTPS calls
|
||||
Http/
|
||||
Controllers/DemoController.php
|
||||
Request.php HTTP, TLS, CSRF and JSON validation
|
||||
Response.php Headers, JSON and safe error responses
|
||||
HttpException.php Intentional client-facing errors
|
||||
Security/
|
||||
InitDataValidator.php Signature, freshness and identity validation
|
||||
RateLimiter.php Locked, persistent request quotas
|
||||
Session.php Session lifecycle and authenticated identity
|
||||
Support/helpers.php base_path(), storage_path(), view(), e()
|
||||
storage/
|
||||
secrets/token.txt App token (ignored, private)
|
||||
sessions/ PHP session files (ignored)
|
||||
cache/ Rate-limit state (ignored)
|
||||
scripts/package.php Credential-free deployment archive
|
||||
tests/ Security, HTTP and browser checks
|
||||
composer.json PHP requirements, PSR-4 metadata and scripts
|
||||
```
|
||||
|
||||
Classes use the `App\` namespace, strict types and explicit constructor dependencies. The application owns dependency construction; controllers return data, responses handle HTTP output, and templates handle presentation. Request globals are confined to the HTTP request adapter and session state to the session class. Loading the autoloader for CLI tests does not start a session or send headers.
|
||||
|
||||
Composer is optional. The included autoloader keeps cPanel deployment self-contained. `composer.json` declares the same PSR-4 mapping for editors and tools; `composer test`, `composer serve` and `composer package` are conveniences for the PHP commands below.
|
||||
|
||||
## cPanel deployment
|
||||
|
||||
1. Choose **64-bit PHP 8.2 or later** in MultiPHP Manager, with `curl`, `json`, `hash`, `openssl` and `session` enabled.
|
||||
2. Enable a valid SSL certificate through SSL/TLS Status / AutoSSL.
|
||||
3. Upload the project to a directory such as `/home/CPANEL_USER/app/`. In **Domains**, set the domain's document root to **`/home/CPANEL_USER/app/public`**. If your provider restricts document-root changes for the main domain, ask them to configure it or use an addon domain/subdomain with that document root.
|
||||
4. Place the token in `/home/CPANEL_USER/app/storage/secrets/token.txt`, without quotes. Set the file to **0600** and `storage/secrets`, `storage/sessions` and `storage/cache` to **0700**. PHP must run as the owning cPanel account and be able to write to sessions and cache. Do not use 0777.
|
||||
5. If needed, copy `config/local.example.php` to `config/local.php`. Use 0600 for a local config containing secrets. Keep `allow_local_http` **false** on the host. Configuration precedence is defaults → local overrides; the token prefers `EITAA_APP_TOKEN`, then the configured token, then `storage/secrets/token.txt`.
|
||||
6. Open the final HTTPS URL directly, for example `https://example.com/index.php`, and register that exact URL in EitaaYar. The supplied documentation requires no redirect in the launch URL.
|
||||
7. Open the app from Eitaa. Authentication runs automatically. Test permissions, then intentionally send yourself one message.
|
||||
|
||||
No `.htaccess` files or rewrite rules are needed: endpoints are real PHP files. The web server must serve **only `public/`**, use `index.php` as its directory index and have directory listings disabled in its configuration. Never expose the repository root, `app/`, `config/`, `storage/`, or the deployment ZIP. Do not merge the entire project into an existing `public_html` web root.
|
||||
|
||||
Build the package with:
|
||||
|
||||
```sh
|
||||
php scripts/package.php
|
||||
```
|
||||
|
||||
`dist/madar-cpanel.zip` preserves the project layout, including `public/`. Extract into the project directory and configure its public document root as above. The archive includes only application code, templates, assets, non-secret configuration and empty storage placeholders. It excludes tokens, local overrides, runtime data, tests and local documentation sources. Transfer the token separately to the private storage location.
|
||||
|
||||
## Security
|
||||
|
||||
- Token storage stays outside the web root and is ignored by Git. Tokens never appear in HTML, JS, API URLs or the deployment archive.
|
||||
- PHP validates raw launch data using HMAC-SHA256 and constant-time comparison. Duplicate or ambiguous keys, expired launches and dates too far in the future are rejected. Default launch lifetime: five minutes, with 30 seconds of clock tolerance.
|
||||
- Sessions use strict mode, ID regeneration, HTTP-only cookies and an absolute one-hour expiry. HTTPS cookies use `Secure; SameSite=None` for embedding. API requests require a session-bound CSRF header. Native Eitaa is preferable when a browser blocks third-party cookies.
|
||||
- Message recipients come exclusively from the verified session user. The Eitaa service enforces write permission. Limits are five send attempts per user per hour and 100 per installation per hour; failed attempts also count. Locked file storage enforces quotas across sessions.
|
||||
- Signed contacts require a fresh signature and a `contact.user_id` matching the session user. Contact details appear only in that page, not persistent application logs.
|
||||
- Outbound calls use fixed HTTPS endpoints, TLS verification, POST bodies, timeouts and no redirects. Raw upstream errors, credentials, paths and exception traces are not sent to the browser.
|
||||
- Optional remote authenticity checking is available in the demo or through `verify_on_login`. It is single-use and must run within 60 seconds of launch; success is cached for that launch in the session. Local HMAC validation alone permits reuse of stolen valid launch data within its short lifetime. Enable mandatory verification if single-use login is required.
|
||||
- IP checking uses `REMOTE_ADDR`; forwarding headers are not trusted. Configure proxy/CDN handling and HTTPS detection at the web server, or disable optional `verify_ip` if appropriate.
|
||||
- Apps running under the same cPanel account may read each other's private files. Separate hosting accounts provide stronger isolation. Rotate the token if it was previously publicly accessible.
|
||||
|
||||
## Development and verification
|
||||
|
||||
```sh
|
||||
php -S 127.0.0.1:8080 -t public
|
||||
php tests/security.php
|
||||
php tests/http.php
|
||||
node --check public/assets/app.js
|
||||
```
|
||||
|
||||
Visit `http://127.0.0.1:8080` for browser preview. Production TLS enforcement can stay enabled: preview works, while authenticated APIs reject HTTP. For deliberate loopback API development, set `allow_local_http` to true in the ignored local config.
|
||||
|
||||
HTTP tests create a temporary isolated installation with a fake token and explicit loopback HTTP permission. They never load your real token or contact Eitaa. They require permission to bind a local port.
|
||||
|
||||
Optional browser checks require Playwright and Chromium, with the preview server running:
|
||||
|
||||
```sh
|
||||
PLAYWRIGHT_MODULE=/path/to/playwright/index.mjs node tests/browser.mjs
|
||||
```
|
||||
|
||||
Override `CHROMIUM_PATH` or `APP_URL` if necessary. Tests cover browser preview, responsive layouts and a simulated Eitaa bridge; they do not prove native device support.
|
||||
|
||||
## Brand assets
|
||||
|
||||
The abstract orbit identity includes SVG originals, PNG app icons up to 1024px, multi-size ICO/SVG favicons, an Apple touch icon, a maskable home-screen icon and a 1200×630 share image. Open `brand.html` for previews and downloads; [BRANDING.md](BRANDING.md) documents colors and exports. The icon has no letters or initials.
|
||||
|
||||
Set `public_url` in `config/local.php` to the deployed HTTPS base URL (including any subdirectory) to enable absolute social-preview metadata. Icons and the manifest work without this setting. `php scripts/branding.php` regenerates the exports on a development machine with librsvg and ImageMagick; cPanel only needs the prebuilt assets.
|
||||
|
||||
## Feature coverage
|
||||
|
||||
The app provides 22 experiment cards, light/dark themes, live sensor visualizations, search and an in-memory event console. [FEATURES.md](FEATURES.md) maps documented features to their demos. Browser dialog previews are explicitly labeled; authentication, messages, sensors and native permissions are never fabricated.
|
||||
|
||||
The official SDK is loaded directly from `https://developer.eitaa.com/eitaa-web-app.js`, before application scripts. Fullscreen dispatch supports both documented `FullScreen` and current `Fullscreen` spelling. Contact callbacks support either a signed string or the current event object's `response` string.
|
||||
|
||||
Commented documentation placeholders for cloud storage, biometrics, location, device/secure storage, stories and emoji statuses are not presented as implemented APIs. Message credit purchases, balances and application management belong in EitaaYar.
|
||||
|
||||
After deployment, verify on real Eitaa Android and desktop clients: login, native buttons, contact/permissions, authenticity within a minute, one intentional message, sensors, fullscreen/safe areas, QR and downloads.
|
||||
Reference in new issue
Block a user