Skip to content

Custom Authentication Configuration

The Custom Authentication Configuration file allows system administrators to implement advanced security and authentication controls that are not available through the standard web interface. These settings control IP-based access restrictions, account masquerading for troubleshooting, and XML API access.

Location and Setup

The custom authentication configuration is managed through a PHP file located in your installation:

~/admin/com/custom/authentication.php

Initial Setup

  1. Navigate to the custom directory:

    Terminal window
    cd ~/admin/com/custom/
  2. Copy the example file to create your configuration:

    Terminal window
    cp authentication.example.php authentication.php
  3. Edit the file with your preferred text editor:

    Terminal window
    nano authentication.php
  4. Set appropriate file permissions:

    Terminal window
    chmod 640 authentication.php

Configuration Structure

The configuration file uses a PHP array structure with predefined keys:

<?php
$custom = [
'admin_allow_ip' => [],
'admin_allow_ip_enabled' => false,
'regularuser_allow_ip' => [],
'regularuser_allow_ip_enabled' => false,
'enable_masquerade' => true,
'masquerade_token_separator' => '::',
'enable_xmlapi' => false,
'xmlapi_admin_only' => true
];

IP Restriction for System Administrators

Restrict System Administrator login to specific IP addresses for enhanced security.

Configuration Options

admin_allow_ip

An array of IP addresses allowed to login as System Administrator.

Example:

'admin_allow_ip' => [
'127.0.0.1', // Localhost
'192.168.1.100', // Static office IP
'10.0.0.0/8', // Private network range
gethostbyname('vpn.yourcompany.com') // Dynamic hostname
],

Supported formats:

  • Single IP addresses: '192.168.1.100'
  • CIDR notation: '10.0.0.0/8' (if supported by your implementation)
  • Dynamic IPs via DNS: gethostbyname('hostname.com')

admin_allow_ip_enabled

Boolean flag to enable/disable IP restrictions for System Administrators.

Values:

  • true - Enable IP restrictions (only IPs in admin_allow_ip can login as admin)
  • false - Disable IP restrictions (default behavior)

Example Configuration

// Restrict admin login to office and VPN IPs only
'admin_allow_ip' => [
'203.0.113.50', // Office static IP
'203.0.113.51', // Backup office IP
gethostbyname('vpn.example.com') // VPN gateway
],
'admin_allow_ip_enabled' => true,

Use Cases

Scenario 1: Office-only admin access

'admin_allow_ip' => ['203.0.113.50'],
'admin_allow_ip_enabled' => true,

Scenario 2: Multiple offices and VPN

'admin_allow_ip' => [
'203.0.113.50', // New York office
'198.51.100.25', // London office
gethostbyname('vpn.company.com') // Corporate VPN
],
'admin_allow_ip_enabled' => true,

IP Restriction for Regular Users

Similar to admin restrictions, but applies to all non-administrator user accounts.

Configuration Options

regularuser_allow_ip

An array of IP addresses allowed for regular user login.

regularuser_allow_ip_enabled

Boolean flag to enable/disable IP restrictions for regular users.

Example Configuration

// Restrict all regular users to company network only
'regularuser_allow_ip' => [
'10.0.0.0/8', // Internal network
gethostbyname('vpn.company.com') // VPN access
],
'regularuser_allow_ip_enabled' => true,

Account Masquerading Debug Feature

Account masquerading allows System Administrators to login as another user for troubleshooting purposes without knowing their password.

How It Works

When enabled, a System Administrator can login using a special username format:

adminusername::targetusername

The system will:

  1. Verify the admin’s credentials
  2. Verify the admin has System Administrator privileges (admintype = 'a')
  3. If valid, log them in as the target user
  4. All actions are performed as the target user

Configuration Options

enable_masquerade

Enable or disable the masquerading feature.

Values:

  • true - Enable masquerading (default)
  • false - Disable masquerading

masquerade_token_separator

The character sequence that separates admin username from target username.

Default: ::

Custom example:

'masquerade_token_separator' => '##', // Use admin##targetuser format

Example Usage

Configuration:

'enable_masquerade' => true,
'masquerade_token_separator' => '::',

Login scenario:

  • Admin username: sysadmin
  • Admin password: SecureP@ss123
  • Target user: john.doe

Login as target user:

  1. Navigate to the login page
  2. Enter username: sysadmin::john.doe
  3. Enter password: SecureP@ss123 (admin’s password, not john.doe’s)
  4. You are now logged in as john.doe

Security Considerations

Disabling Masquerading

For production environments where this feature is not needed:

'enable_masquerade' => false,

XML API Access Control

Control whether the XML API authentication is available system-wide.

Configuration Option

enable_xmlapi

Global enable/disable switch for XML API authentication.

Values:

  • true - XML API authentication enabled
  • false - XML API authentication disabled system-wide (default)

xmlapi_admin_only

Restricts XML API access to administrator accounts only, even when a non-admin user has a valid XML token.

Values:

  • true - Only admin users can access the XML API (default)
  • false - Non-admin users with a valid XML token can also access the XML API

Example Configuration

Disable XML API completely:

'enable_xmlapi' => false,

Enable XML API for admin users only (default behavior):

'enable_xmlapi' => true,
'xmlapi_admin_only' => true,

Enable XML API for all users with valid tokens:

'enable_xmlapi' => true,
'xmlapi_admin_only' => false,

Complete Configuration Examples

Maximum Security Configuration

<?php
/**
* High-security configuration for production environment
* - Admin access restricted to office IP only
* - Regular users restricted to internal network
* - Masquerading disabled
* - XML API disabled
*/
$custom = [
'admin_allow_ip' => [
'203.0.113.50', // Office static IP
],
'admin_allow_ip_enabled' => true,
'regularuser_allow_ip' => [
'10.0.0.0/8', // Internal network
],
'regularuser_allow_ip_enabled' => true,
'enable_masquerade' => false,
'masquerade_token_separator' => '::',
'enable_xmlapi' => false,
'xmlapi_admin_only' => true
];

Development/Staging Configuration

<?php
/**
* Flexible configuration for development environment
* - No IP restrictions
* - Masquerading enabled for testing
* - XML API enabled for all users
*/
$custom = [
'admin_allow_ip' => [],
'admin_allow_ip_enabled' => false,
'regularuser_allow_ip' => [],
'regularuser_allow_ip_enabled' => false,
'enable_masquerade' => true,
'masquerade_token_separator' => '::',
'enable_xmlapi' => true,
'xmlapi_admin_only' => false
];

Remote Work Configuration

<?php
/**
* Configuration for distributed team with VPN
* - Admin access from VPN only
* - Regular users from anywhere (MFA required separately)
* - Masquerading disabled
* - XML API enabled for admins only
*/
$custom = [
'admin_allow_ip' => [
gethostbyname('vpn.company.com'),
],
'admin_allow_ip_enabled' => true,
'regularuser_allow_ip' => [],
'regularuser_allow_ip_enabled' => false,
'enable_masquerade' => false,
'masquerade_token_separator' => '::',
'enable_xmlapi' => true,
'xmlapi_admin_only' => true
];

Troubleshooting

Problem: Locked Out of Admin Account

Symptom: Cannot login as System Administrator

Cause: admin_allow_ip_enabled is true but your IP is not in admin_allow_ip

Solution:

  1. Access server via SSH or file manager
  2. Edit ~/admin/com/custom/authentication.php
  3. Set 'admin_allow_ip_enabled' => false,
  4. Or add your IP to admin_allow_ip array
  5. Save and try logging in again

Problem: All Users Locked Out

Symptom: No one can login (admin or regular users)

Cause: Both IP restriction features enabled with empty arrays

Solution:

  1. Temporarily rename the file:
    Terminal window
    mv ~/admin/com/custom/authentication.php ~/admin/com/custom/authentication.php.disabled
  2. Login normally
  3. Fix the configuration
  4. Rename back:
    Terminal window
    mv ~/admin/com/custom/authentication.php.disabled ~/admin/com/custom/authentication.php

Problem: Masquerading Not Working

Symptom: Login fails when using admin::user format

Possible causes and solutions:

  1. Masquerading is disabled

    • Check: 'enable_masquerade' => true
  2. Wrong separator

    • Check the masquerade_token_separator value
    • Use the correct separator (default is ::)
  3. Not a System Administrator

    • Masquerading only works for users with admintype = 'a'
    • Regular admins cannot masquerade
  4. Target user doesn’t exist

    • Verify the target username is correct and active

Problem: XML API Not Working

Symptom: XML API requests fail with authentication error

Possible causes:

  1. Global XML API disabled

    • Check: 'enable_xmlapi' => true
  2. Admin-only mode is enabled

    • Check: 'xmlapi_admin_only' => true blocks non-admin users even with a valid token
    • Set to false to allow non-admin users
  3. User doesn’t have XML API permission

    • Enable in user account settings separately
  4. IP restrictions blocking request

    • Check if request IP is in allowed list

For additional security configurations, see:

Best Practices

  1. Always maintain a backup before modifying authentication settings
  2. Test in development first before applying to production
  3. Document your IP addresses with comments in the file
  4. Use version control to track changes to authentication.php
  5. Review access logs regularly when using IP restrictions
  6. Disable masquerading in production unless actively needed
  7. Consider using VPN instead of static IP lists for remote access
  8. Audit masquerade usage if enabled in production environments

File Permissions

Ensure proper file permissions for security:

Terminal window
# Recommended permissions (read-write for owner, read for group, none for others)
chmod 640 ~/admin/com/custom/authentication.php
# Ensure proper ownership
chown www-data:www-data ~/admin/com/custom/authentication.php