PostfixAdmin Documentation

repository·master·Indexed 22 days ago

https://github.com/postfixadmin/postfixadmin

A web-based management interface for Postfix mail servers that allows administrators and users to manage domains, mailboxes, aliases, and quotas via SQLite, MySQL, or PostgreSQL backends. Features include support for DKIM storage, TOTP challenges, Application Specific Passwords, and integration with Dovecot, Courier, and Cyrus IMAP. Includes documentation on post-action hooks, Rspamd DKIM hooks, and a SquirrelMail plugin using the XMLRPC protocol.

Tokens
18.7K
Snippets
46
Records
83
Agent score
73%

What's inside PostfixAdmin

  1. Overview of PostfixAdmin

    master
    PostfixAdmin is an open source, web-based interface designed to manage domains, mailboxes, aliases, and other mail-related configurations on a Postfix-based mail server. It acts as a management layer that integrates with mail servers and database backends to automate user and domain administration.
  2. Overview of the SquirrelMail PostfixAdmin Plugin

    master

    The PostfixAdmin SquirrelMail plugin allows users to manage their email settings directly from within the SquirrelMail webmail interface. Users can perform the following tasks:

    • Vacation Mode: Turn vacation auto-responders on or off and manage vacation messages.
    • Password Management: Change their email passwords.
    • Forwarding Rules: Set up and manage virtual alias forwarding rules.
  3. PostfixAdmin Features

    master

    PostfixAdmin provides several administrative and user-facing features:

    Administrative Features

    • Unlimited domains, aliases, and mailboxes.
    • Optional storage quota support.
    • Optional password expiry (beta).
    • Multiple password hashing formats.
    • Support for Domain Key (DKIM) storage.
    • Optional XMLRPC-based API.
    • Support for TOTP challenges (with optional IP address-based exemptions).
    • Support for Application Specific Passwords (allowing multiple passwords per mailbox).

    User Features

    • User login and password management.
    • Vacation / Autoresponder / Out Of Office setup.
    • Integration with webmail clients like Squirrelmail or Roundcube via plugins.
    • Retrieval of mail from a remote POP3 server via fetchmail.
  4. How Virtual Vacation works

    master

    Virtual Vacation (an 'out of office' automated response) operates as a service within Postfix's master.cf configuration.

    Workflow:

    1. When a user marks themselves as 'away', an alias is added to their account.
    2. This alias sends a copy of all incoming mail to a specific vacation service (e.g., user#domain.com@autoreply.domain.com).
    3. Mail sent to the @autoreply.domain.com domain is intercepted by the vacation.pl script.
    4. The script sends an automated reply based on configured settings. By default, a reply is only sent once per message.
  5. Naming policy for custom fields and tables

    master

    To prevent collisions with future PostfixAdmin updates, follow these naming conventions:

    Extra fields in existing tables:

    • Prefix field names with x_.
    • Prefix any new indexes with x_ (or tablename_x_ on PostgreSQL).
    • Avoid unique indexes and foreign keys where possible to simplify future schema changes.

    Extra tables:

    • Prefix table names with x_.
    • Inside custom tables, you may use any names for fields and indexes.
    • On PostgreSQL, index and unique-key names must start with x_ (e.g., x_tablename_) because they are scoped to the schema.
    • Consider including created, modified, and active columns to match core tables.
  6. Add custom fields to PostfixAdmin entities using `*_struct_hook`

    master

    You can add, modify, or remove fields from PostfixAdmin's built-in entities (domains, mailboxes, aliases, etc.) without modifying the core source code. This is achieved by using *_struct_hook configuration callbacks.

    When a Handler is constructed, it looks for a configuration key named after its database table plus _struct_hook. If a valid function name is provided, the Handler passes its $struct array through that function. The Handler then automatically builds the SQL queries and the web UI (add, edit, and list forms) based on the modified $struct.

    // Example of how the internal logic works
    $struct_hook = Config::read($this->db_table . '_struct_hook');
    if (!empty($struct_hook) && is_string($struct_hook) && $struct_hook != 'NO' && function_exists($struct_hook)) {
        $this->struct = $struct_hook($this->struct);
    }
  7. Use the `dovecot:METHOD` hashing approach

    master

    If PostfixAdmin does not natively support a specific format, you can use the dovecot:METHOD syntax. This instructs PostfixAdmin to use the doveadm system binary to generate the hash.

    Pros:

    • Minimal dependency on PostfixAdmin/PHP code.
    • Guaranteed compatibility with Dovecot.

    Cons:

    • Requires proc_open() to be enabled in PHP.
    • Requires doveadm to be installed and accessible by the web server.
    • May encounter permission or SELinux issues.

    Example: If in doubt, try dovecot:SHA512.

  8. How translation files are structured in PostfixAdmin

    master

    PostfixAdmin uses PHP files for translations, located in the languages/ directory with a .lang extension (e.g., languages/en.lang). The file languages/en.lang serves as the canonical English source.

    Each translation file must start with <?php and contains an array of $PALANG assignments. Files must be UTF-8 encoded and may use htmlentities for special characters.

    <?php
    $PALANG['key'] = 'text';
  9. How the SquirrelMail PostfixAdmin Plugin communicates

    master

    The plugin does not require direct access to the PostfixAdmin database. Instead, it communicates with PostfixAdmin using the XMLRPC protocol.

    Security Requirement: Because the plugin uses XMLRPC, all traffic to the XMLRPC interface must be encrypted (e.g., via HTTPS). This encryption must be configured by the server administrator.

  10. How Handler classes work in PostfixAdmin

    master

    Handler classes extend PFAHandler and provide a standardized way to manage database entities. Creating a Handler automatically enables support for:

    • list.php: List and search views.
    • edit.php: Create and edit forms.
    • delete.php: Deletion logic.
    • editactive.php: Toggling active status.
    • postfixadmin-cli: Command-line interface access.

    Lifecycle of a Handler

    1. Instantiation: list.php or edit.php creates the instance: new FooHandler($new, $username, $is_admin).
    2. Initialization: The constructor calls initStruct() and initMsg(), and sets up $allowed_domains.
    3. Edit Flow: For existing items, init($id) loads the data. When saving, set($values) validates input, and save() writes to the database.
    4. Save Flow: save() executes preSave(), performs the SQL INSERT/UPDATE, and then executes postSave().
    5. List Flow: getList($condition) triggers build_select_query() $\rightarrow$ read_from_db() $\rightarrow$ read_from_db_postprocess().
  11. PostfixAdmin Integration and Compatibility

    master

    PostfixAdmin is designed to work within a standard mail stack. It integrates with:

    • Mail Servers: Postfix and IMAP/POP3 servers (such as Dovecot or Courier).
    • Database Backends: Choose one of SQLite, MySQL, or PostgreSQL.
    • Optional Components: Fetchmail (for retrieving mail from remote POP3 servers).
  12. Setup a Database

    master

    Create a database for PostfixAdmin. Below are the command-line instructions for common database types:

    MySQL/MariaDB

    CREATE DATABASE postfix;
    CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'choose_a_password';
    GRANT ALL PRIVILEGES ON `postfix` . * TO 'postfix'@'localhost';
    FLUSH PRIVILEGES;

    PostgreSQL

    CREATE USER postfix WITH PASSWORD 'whatever';
    CREATE DATABASE postfix OWNER postfix ENCODING 'unicode';

    SQLite Create a directory and a database file, ensuring the web server user (e.g., www-data) has write permissions to both:

    mkdir /srv/postfixadmin/database
    touch /srv/postfixadmin/database/postfixadmin.db
    sudo chown -R www-data:www-data /srv/postfixadmin/database