Skip to content

Latest commit

 

History

History
131 lines (105 loc) · 4.9 KB

CONTRIBUTING.md

File metadata and controls

131 lines (105 loc) · 4.9 KB

Contributing

Thanks for wanting to contribute. This project exists because Ubiquiti's official API doesn't (yet) expose Policy-Based Routing endpoints, so the tool takes a pragmatic route: uses the official Integration API where it can, falls back to the reverse-engineered classic API only where necessary.

Ways to contribute

  • Bug reports — open a GitHub issue with your Network app version, UDR model, exact steps, and the log detail JSON if the failure is a sync error
  • Preset additions — new services in app/presets.py are welcome; please include an ASN mapping if a clean one exists (single ASN owned by the service, not a shared cloud provider) or a domain list as fallback
  • Schema discoveries — if you get a HTTP 400 from a Network firmware version we don't yet support, use the "Discover schema" button on the Routing page and share the returned JSON so we can align the payload
  • Documentation — the README, SECURITY.md, and inline module docstrings all benefit from more eyes

Development setup

git clone https://github.com/<your-fork>/unifi-routes-manager.git
cd unifi-routes-manager

# Backend
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

# Frontend assets (Tailwind is compiled)
npm install
npm run build       # or `npm run watch` for live reload

# Run
export DATA_DIR=./dev-data
mkdir -p "$DATA_DIR"
flask --app wsgi run --debug --port 8080

Open http://127.0.0.1:8080 and complete the first-run setup wizard.

Testing your changes

There's no formal test suite yet — the code is verified by end-to-end smoke tests during development. If you're changing anything under sync.py or unifi.py, please describe how you tested against a real UDR in your PR (what firmware version, what auth mode, what the log detail showed).

Code style

  • Python: standard PEP 8, use type hints on new function signatures
  • No new runtime dependencies without discussion in an issue first — the goal is a small, auditable footprint (currently ~12 direct deps)
  • Templates: keep the existing Tailwind + HTMX + Alpine.js patterns rather than introducing a heavier framework
  • Every new state-changing HTML form MUST include {{ csrf_token() }}

Pull request process

  1. Open an issue first for anything larger than a small fix, so we can agree on the approach before you invest time
  2. Keep PRs focused — one logical change per PR
  3. Update the README / SECURITY.md if user-visible behavior changes
  4. Add a CHANGELOG.md entry under "Unreleased"

Adding a new preset

Presets live in app/presets.py. Structure:

{
    "id": "unique_short_id",
    "name": "Human Readable Name",
    "description": "One-line description shown in the library",
    "category": "streaming",  # or ai, finance, security, gaming, etc.
    "recommended": False,     # True only if the service clearly benefits from PBR
    "warning": None,          # If domain-only or ASN is shared, explain here
    "asns": [
        {"asn": 12345, "description": "Clean ownership only"},
    ],
    "cidrs": [
        {"cidr": "203.0.113.0/24", "description": "Well-known static block"},
    ],
    "domains": [
        {"domain": "example.com", "description": "Main domain"},
    ],
    "feeds": [
        {"url": "https://example.com/ips.txt", "fmt": "plain_text",
         "description": "Official IP list published by the operator"},
    ],
    "enable_ipv6": True,
}

Rules of thumb:

  • Prefer URL feeds if the operator publishes one — most reliable data source. Check the vendor's docs for "IP ranges", "firewall allowlist", or similar.
  • ASN only if the service owns it (check via whois AS12345). Never include Cloudflare, AWS, Azure, GCP, or Fastly ASNs — they carry traffic for thousands of services and would over-match.
  • Domains are the fallback when neither feed nor clean ASN exists. Note that many services rotate DNS heavily — flag with warning if you know the DNS is unreliable.
  • Mark recommended: True only when there's a concrete reason PBR helps (VPN detection, geo-restrictions, MFA challenges), not just because the service exists.

Adding a feed parser format

If a service publishes IP lists in a new format, add a parser in app/feeds.py:

def _parse_myformat(body: bytes) -> tuple[list[str], list[str]]:
    """Return (v4_cidrs, v6_cidrs) — deduplication + validation handled later."""
    data = json.loads(body)   # or parse however the format works
    v4 = [entry["prefix"] for entry in data if ":" not in entry["prefix"]]
    v6 = [entry["prefix"] for entry in data if ":" in entry["prefix"]]
    return v4, v6

PARSERS["myformat"] = _parse_myformat

Then add it to format_choices() so it shows up in the UI dropdown, and update the <select> in templates/groups/edit.html.

License

By contributing, you agree that your contributions will be licensed under the same MIT License that covers the project.