Metadata-Version: 2.5
Name: trytond_opnsense_voucher
Version: 8.0.0.3
Summary: Tryton module opnsense_voucher
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <issues@tryton-erp.eu>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
License-File: icons/LICENSE
Keywords: opnsense_voucher,tryton
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: cryptography
Requires-Dist: pillow
Requires-Dist: requests
Requires-Dist: trytond-company<8.1,>=8.0
Requires-Dist: trytond-printing-labels<8.1,>=8.0
Requires-Dist: trytond-web-user<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Description-Content-Type: text/x-rst

OPNSense WiFi Voucher
=====================

The ``opnsense_voucher`` module manages OPNsense Captive Portal WiFi
vouchers from within Tryton.  It connects to the voucher API of one or
more OPNsense firewall servers, generates voucher rolls on request,
keeps the local database synchronized with the portal server, and
prints the vouchers as labels.

Features
--------

- **Portal Servers**: Configure multiple OPNsense servers with API
  credentials, one of which can be the default server.
- **Voucher Rolls**: Generate rolls of vouchers with a validity
  duration and a date limit, and hand them out with an audit trail of
  who handed out the roll and when.
- **Voucher Tracking**: Each voucher's username, password, validity,
  start/end times, expiry time and state (unused, valid, expired) is
  mirrored locally, with a dedicated view for vouchers expiring soon.
- **Automatic Synchronization**: A cron job (hourly by default)
  synchronizes rolls and vouchers of servers with *Automatic Sync*
  enabled; stale records removed on the server are deleted locally.
- **Voucher Requests**: A request/approval workflow so that users of
  the *Requester* group can ask for vouchers, and users of the
  *Manager* group approve, ask for feedback or reject the requests.
  Requests exceeding configurable thresholds of the portal server
  (number of tickets, time horizon) require a free text explanation.
- **Label Printing**: Renders each voucher as a printable label
  (QR-code, username, password, roll reference) through the
  ``printing_labels`` module and queues it as a printing job.
- **Portal User Links**: Links each ``web.user`` portal account to the
  internal user it acts as on the HTTP routes, managed by an
  administrator; the *Link Portal Users* wizard proposes the
  unambiguous pairs.

Security Notes
--------------

- The API key and the API secret of a portal server and the passwords
  of the vouchers are **encrypted at rest** with an AES-256-GCM master
  key read from the trytond configuration (section
  ``[opnsense_voucher]``) and **never** stored in the database, so a
  database dump, a backup and an over-privileged database account only
  reveal ciphertext.  Configure ``encryption_key`` before storing
  credentials: without it the module refuses to store or read a
  credential instead of storing it unprotected.
- Only users of the *OPNsense Voucher Admin* group may read the API
  key, the API secret and the voucher passwords; Tryton removes those
  fields from the views of the *Manager* and *Requester* groups and
  refuses an explicit read or export of them.  The API client, the
  synchronization and the label printing read the credentials
  server-side.
- Upgrading an installation that stored the credentials in clear text
  requires running the migration script ``migration/8.0.0.2.py`` once,
  after configuring the master key; see the *Configuration* chapter of
  the module documentation.
- Keep *Verify SSL* enabled unless the portal server uses a
  self-signed certificate.
- Requesters see only their own voucher requests; this is enforced by
  a record rule in addition to the model access rules.
- Voucher data becomes read-only locally once the vouchers were
  created on the server; it is then managed by the portal server.
- Portal HTTP requests are authenticated through the ``web_user``
  session and mapped to an internal user **only** by an explicit link
  (``opnsense.voucher.portal.user``); the email address of a web user
  is never used to derive its identity, so a portal account cannot
  impersonate another user.  Map every portal account to a dedicated
  ``res.user`` holding only the *Requester* group.

Dependencies
------------

- Tryton modules: ``ir``, ``res``, ``company``, ``printing_labels``,
  ``web_user``.
- Python packages: ``requests`` (OPNsense API client), ``pillow``
  (label rendering) and ``cryptography`` (AES-256-GCM encryption of
  the credentials at rest).

Models
------

- ``opnsense.voucher.server`` — ``OPNSenseVoucherServer``: connection
  and behaviour configuration of an OPNsense portal server.
- ``opnsense.voucher.roll`` — ``OPNSenseVoucherRoll``: a roll of
  vouchers with validity data and hand-out audit fields.
- ``opnsense.voucher.voucher`` — ``OPNSenseVoucher``: a single
  captive portal voucher.
- ``opnsense.voucher.request`` — ``OPNSenseVoucherRequest``: a
  voucher request in the request/approval workflow.
- ``opnsense.voucher.portal.user`` — ``OPNSenseVoucherPortalUser``:
  the link between a ``web.user`` portal account and the ``res.user``
  it acts as.

Cron Jobs
---------

- ``opnsense.voucher.server|cron_sync``: runs hourly and synchronizes
  all active servers with *Automatic Sync* enabled.

Wizards
-------

- ``opnsense.voucher.roll.sync`` — *Sync Rolls*: synchronize the rolls
  of a portal server on demand.
- ``opnsense.voucher.roll.create`` — *Create Roll*: generate a new
  voucher roll directly on the portal server.
- ``opnsense.voucher.roll.print`` — *Print Roll*: render the vouchers
  of a roll as labels and queue printing jobs.
- ``opnsense.voucher.portal.user.link`` — *Link Portal Users*: propose
  and create the links between the portal accounts and the internal
  users they act as.
