Community input wanted: A tool-agnostic API for IPFire

I’m currently developing an API for IPFire that originated from my Home Assistant integration, HA-IPFire. I’m considering turning it into an independent, open, tool-agnostic project. Before defining its scope, I’d like to find out whether an API like this would be of interest to the IPFire community and how it should be designed.

Which areas should it cover? Which information should be read-only, and which settings or actions should the API allow users to change or trigger? Are there existing IPFire interfaces, conventions, or technical requirements I should take into account? I’m considering JSON as the data format and OpenAPI as a machine-readable specification, but I’m open to other suggestions.

I’d also be interested in any requirements around authentication, permissions, versioning, installation, and maintenance, and whether collaboration with or eventual integration into the IPFire project might be possible.

The current state of the API is available in the HA-IPFire Git repository, where you can review it and try installing it for testing.

I like being able to see what’s going on from anywhere without having to login to the firewall. played around a bit and came up with this, just needs moved to a different server and not be hosted on the firewall.

Hello Frank,
This is a neat and useful addition to IPFire.
For me, these areas are at inetrest:

  • anything that is certificate expiration related - like OpenVPN client package about to expire, or, if the cert used by Apache to start is about to expire (in case that ACME/Let’s Encrypt/Step-CA/local certificate authority is used).

Ex: I use an ACME integration with STEP-CA:

 /etc/init.d/apache start
Starting Apache daemon...
WARNING: Certificate needs renewal or is missing, issuing cert via ACME step-ca...[WARN]

  • network speed: card max capability and negotiated speed. These are very useful in a mixed environment where some drivers do not play nice with each other (I had a lot of issued between 1Gb/s cards and Intel 226V 2,5 Gb/s cards - solution being to set the Intel 226V params to advertise max 1Gb/s speed - see solution below)
# red0 Intel I226-V: allow only 1G for red0 port, disable 2.5G
if ip link show red0 > /dev/null 2>&1; then /usr/sbin/ethtool -s red0 autoneg on advertise 0x20 || true; fi

# green0p0 Intel I226-V: allow only 1G for Meraki MR33 AP port, disable 2.5G
if ip link show green0p0 > /dev/null 2>&1; then /usr/sbin/ethtool -s green0p0 autoneg on advertise 0x20 || true; fi

  • if UPS is installed, grab from UPS service the main status params of the UPS - for apcupsd that would be cgi-bin/apcupsd.cgi: battery capacity, runtime remaining, and ups load

Hello everyone,

As announced, I have separated the IPFire API from HA-IPFire and published it as a standalone project:

Since the separation, the API has been extended. It now provides information about configured network interfaces and their link speeds, Apache and OpenVPN certificate status, and the status of apcupsd when that add-on is installed.

The GitHub repository includes documentation in both English and German. Feedback and suggestions for other useful API data are welcome.

Best regards,
Frank

I think this is a great addition to IPFire! Big thank you! I’m a GitOps fan and Everything as Code so it would be fantastic if in the future this can eventually expand to a state where a Terraform or OpenTofu provider can be built around the API, then provisioning an IPFire instance from scratch is just one tofu apply away. Automated reconciliation would also be straightforward so that you know what’s in your git repo matches what you have in IPFire

Thank you very much for the kind words and for sharing your vision!

I really like the idea of integrating IPFire into a GitOps workflow with Terraform or OpenTofu. However, api.cgi is still a long way from being ready for something like that.

The API can and should grow over time, and I see this as a possible long-term direction. That said, development will have to happen in small, incremental steps. I still need to learn more about the relevant technologies and concepts, and unfortunately, my spare time is rather limited.

I can’t promise if or when we will reach that point, but I’m happy to see that there is interest in taking IPFire’s API in this direction. Thanks again for the encouragement!

This sounds great !
Retired software engineer here.. would be happy to contribute/collaborate.
I’d like to be able to see the DHCP leased devices/status on the home assistance dashboard. Also some representation/summary of each log , and firewall interface traffic.

Thank you very much for the feedback and the offer to contribute. That would be very welcome!

The API already reports whether the DHCP service is running and provides traffic counters for the RED interface. Details on DHCP leases and traffic counters for the configured interfaces would be useful additions. That shouldn’t be too difficult to implement in the API.

I’m not quite sure what you mean by “log summaries.” Could you provide a little more information? Which IPFire logs and what specific information would be relevant to you?

I’ll add these ideas to the list of possible API extensions. Contributions and collaboration are very welcome!

Follow-up: You mentioned that you’d be happy to help with the project. Which parts would you be interested in? For example, API design or implementation, the Home Assistant integration, testing, or documentation?

Thanks for the quick reply. Since you appear to be online, let’s meet.

I have started a Zoom session - please join in the next 15 minutes:

A small update to the IPFire API: it now reports DHCP leases, cumulative RX/TX byte counters for configured network interfaces, and whether IPFire has marked a reboot as required after an update.

The API and README files have been updated. The changes are available in the IPFire-API repository.

Here is the php code Ive been playing with on the lan network that reads from the API, maybe someone will find it useful.

<?php
/**
 * IPFire WUI Dashboard
 */

// CONFIGURATION
$api_url  = 'https://IPFIRE IP ADDRESS:444/cgi-bin/NAME_OF_API.cgi';
$username = 'admin';
$password = '';

function fetch_ipfire_data(string $url, string $user, string $pass): string
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 6);

    $response = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($http_code !== 200 || !$response) {
        return json_encode(['error' => "HTTP {$http_code} - Unable to connect"]);
    }
    return $response;
}

function format_bytes($bytes, $precision = 2) {
    $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    return round($bytes / pow(1024, $pow), $precision) . ' ' . $units[$pow];
}

// Handle async live polling requests
if (isset($_GET['action']) && $_GET['action'] === 'poll') {
    header('Content-Type: application/json');
    echo fetch_ipfire_data($api_url, $username, $password);
    exit;
}

$raw_json = fetch_ipfire_data($api_url, $username, $password);
$data = json_decode($raw_json, true);
$has_error = isset($data['error']) || !$data;

$sys = $data['system'] ?? [];
$conn = $data['connection'] ?? [];
$traffic = $data['traffic'] ?? [];
$net = $data['network']['interfaces'] ?? [];
$neighbors = $data['network']['neighbors'] ?? [];
$routes = $data['network']['routes'] ?? [];
$dhcp_leases = $data['dhcp']['leases'] ?? [];
$services = $data['services'] ?? [];
$addons = $data['addons'] ?? [];
$certs = $data['certificates'] ?? [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?= htmlspecialchars($conn['external_hostname'] ?? 'IPFire') ?> - Status</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Source+Code+Pro:wght@400;600&display=swap" rel="stylesheet">
	<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0"></script>
    <style>
        :root {
            --ipf-bg: #eceff1;
            --ipf-card: #ffffff;
            --ipf-text: #263238;
            --ipf-muted: #607d8b;
            --ipf-border: #cfd8dc;
            --ipf-primary: #bf360c;
            --ipf-header-bg: #37474f;
            --ipf-nav-bg: #263238;
            --ipf-green: #2e7d32;
            --ipf-green-bg: #e8f5e9;
            --ipf-red: #c62828;
            --ipf-red-bg: #ffebee;
            --ipf-blue: #1565c0;
        }

        * { box-sizing: border-box; }
        body {
            margin: 0;
            padding: 0;
            background-color: var(--ipf-bg);
            color: var(--ipf-text);
            font-family: 'Open Sans', sans-serif;
            font-size: 13px;
            line-height: 1.5;
        }

        #header {
            background-color: var(--ipf-header-bg);
            color: #ffffff;
            padding: 10px 24px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        #header h1 {
            font-size: 16px;
            margin: 0;
            font-weight: 600;
            letter-spacing: 0.5px;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        #header .logo-badge {
            background-color: var(--ipf-primary);
            color: #fff;
            padding: 2px 8px;
            border-radius: 3px;
            font-size: 12px;
            font-weight: 800;
            letter-spacing: 1px;
        }

        #traffic-bar {
            background-color: var(--ipf-nav-bg);
            color: #cfd8dc;
            padding: 6px 24px;
            font-size: 12px;
            display: flex;
            justify-content: flex-end;
            gap: 16px;
            border-bottom: 2px solid var(--ipf-primary);
        }
        #traffic-bar span { font-weight: 600; color: #fff; font-family: 'Source Code Pro', monospace; }

        .wrapper {
            max-width: 1440px;
            margin: 20px auto;
            padding: 0 16px;
        }

        .alert-box {
            background-color: var(--ipf-red-bg);
            border-left: 4px solid var(--ipf-red);
            padding: 12px 16px;
            margin-bottom: 20px;
            border-radius: 2px;
            color: var(--ipf-red);
            font-weight: 600;
        }

        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
            gap: 16px;
        }

        .ipf-box {
            background: var(--ipf-card);
            border: 1px solid var(--ipf-border);
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            margin-bottom: 16px;
        }
        .ipf-box header {
            background: #f7f9fa;
            border-bottom: 1px solid var(--ipf-border);
            padding: 8px 14px;
        }
        .ipf-box header h2 {
            margin: 0;
            font-size: 13px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--ipf-header-bg);
        }
        .ipf-box-body {
            padding: 10px;
            flex-grow: 1;
        }

        table.ipf-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 12px;
        }
        table.ipf-table tr {
            border-bottom: 1px solid #eceff1;
        }
        table.ipf-table tr:nth-child(even) {
            background-color: #fafbfc;
        }
        table.ipf-table tr:last-child {
            border-bottom: none;
        }
        table.ipf-table td,
        table.ipf-table th {
            padding: 6px 12px;
            text-align: left;
        }
        table.ipf-table td.key {
            color: var(--ipf-muted);
            font-weight: 600;
            width: 38%;
            border-right: 1px solid #eceff1;
        }
        table.ipf-table td.val {
            text-align: right;
            font-family: 'Source Code Pro', monospace;
            font-size: 11.5px;
            word-break: break-all;
        }

        .badge {
            display: inline-block;
            padding: 1px 6px;
            border-radius: 2px;
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
        }
        .badge-online { background-color: var(--ipf-green-bg); color: var(--ipf-green); border: 1px solid #a5d6a7; }
        .badge-offline { background-color: var(--ipf-red-bg); color: var(--ipf-red); border: 1px solid #ef9a9a; }

        .metric-cards {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            border-bottom: 1px solid var(--ipf-border);
            background: #fafbfc;
        }
        .metric-cell {
            padding: 10px;
            text-align: center;
            border-right: 1px solid var(--ipf-border);
        }
        .metric-cell:last-child { border-right: none; }
        .metric-cell .label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--ipf-muted); }
        .metric-cell .value { font-size: 14px; font-weight: 700; color: var(--ipf-text); margin-top: 2px; }

        #footer {
            max-width: 1440px;
            margin: 20px auto;
            padding: 10px 16px;
            font-size: 11px;
            color: var(--ipf-muted);
            border-top: 1px solid var(--ipf-border);
            display: flex;
            justify-content: space-between;
        }
        #footer a { color: var(--ipf-muted); text-decoration: none; }
        #footer a:hover { text-decoration: underline; }

        .scrollable {
            max-height: 300px;
            overflow-y: auto;
            border: 1px solid var(--ipf-border);
            border-radius: 4px;
        }
        .scrollable th {
            text-align: center;
            font-weight: 600;
            background-color: #f0f4f5;
        }
        .neighbor-box, .dhcp-box {
            grid-column: 1 / -1;
        }
        @media (max-width: 768px) {
            .dashboard-grid {
                grid-template-columns: 1fr;
            }
        }

		@media (max-width: 768px) {
			/* 1. Layout Grid: Allow boxes to be full width */
		.dashboard-grid {
		grid-template-columns: 1fr !important;
        gap: 12px;
    }

    
    .wrapper { padding: 0 8px; margin: 12px auto; }
    #header, #traffic-bar { padding: 8px 12px; }

   
    #header { flex-direction: column; align-items: flex-start; gap: 4px; }
    #header h1 { font-size: 15px; flex-wrap: wrap; }
    #header small { font-size: 11px; opacity: 0.8; }

    
    #traffic-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        font-size: 11px;
    }
    #traffic-bar div { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
    #traffic-bar span { font-size: 11px; }

    
    .metric-cards {
        grid-template-columns: 1fr !important;
    }
    .metric-cell { border-right: none; border-bottom: 1px solid var(--ipf-border); padding: 8px; }
    .metric-cell:last-child { border-bottom: none; }

    
    .ipf-box-body {
        overflow-x: auto;          /* Enable scroll on container */
        -webkit-overflow-scrolling: touch;
    }
    table.ipf-table {
        min-width: 600px;          /* Force layout width, let container scroll */
        white-space: nowrap;       /* Prevent cell wrapping */
    }
    table.ipf-table td, table.ipf-table th {
        padding: 8px 10px;
        font-size: 11px;
    }

   
    #trafficChart {
        width: 100% !important;
        height: auto !important;
        max-width: 100%;
        display: block;
    }

    
    .badge { white-space: nowrap; font-size: 10px; padding: 1px 5px; }

   
    #footer { flex-direction: column; gap: 6px; text-align: center; padding: 12px 8px; }
}

@media (max-width: 480px) {
    html { font-size: 12px; } /* Base rem drop */
    .ipf-box header h2 { font-size: 11px; }
    table.ipf-table td.key { width: 35%; min-width: 80px; }
    table.ipf-table td.val { font-size: 10px; }
}

    </style>
</head>
<body>

<header id="header">
    <h1>
        <span class="logo-badge">IPFire_</span>
        <?= htmlspecialchars($conn['external_hostname'] ?? 'IPFire Appliance') ?>
    </h1>
    <div><small><?= htmlspecialchars($sys['version'] ?? '') ?></small></div>
</header>

<div id="traffic-bar">
    <div>RED Traffic: In <span id="red-rx-rate">--</span> &nbsp;•&nbsp; Out <span id="red-tx-rate">--</span></div>
</div>

<div class="wrapper">
    <?php if ($has_error): ?>
        <div class="alert-box">
            Failed to communicate with IPFire device at <code><?= htmlspecialchars($api_url) ?></code>. Check authentication credentials and network connectivity.
        </div>
    <?php endif; ?>

    <div class="dashboard-grid">

        <!-- System Information -->
        <div class="ipf-box">
            <header><h2>System Information</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <tr><td class="key">Core Release</td><td class="val"><?= htmlspecialchars($sys['version'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Pakfire Version</td><td class="val"><?= htmlspecialchars($sys['pakfire_version'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Kernel Release</td><td class="val"><?= htmlspecialchars($sys['kernel_version'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Architecture</td><td class="val"><?= htmlspecialchars($sys['architecture'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Hardware</td><td class="val"><?= htmlspecialchars(($sys['vendor'] ?? '') . ' ' . ($sys['model'] ?? '')) ?></td></tr>
                    <tr><td class="key">CPU</td><td class="val"><?= htmlspecialchars($sys['cpu_model'] ?? 'N/A') ?> (<?= $sys['cpu_count'] ?? 1 ?> cores)</td></tr>
                    <tr><td class="key">Virtual</td><td class="val"><?= $sys['virtual'] ? 'Yes' : 'No' ?></td></tr>
                    <tr><td class="key">System Memory</td><td class="val"><?= isset($sys['memory']['total']) ? format_bytes($sys['memory']['total']) : 'N/A' ?></td></tr>
                    <tr><td class="key">Root Filesystem</td><td class="val"><?= isset($sys['disk']['root']['total']) ? format_bytes($sys['disk']['root']['total']) : 'N/A' ?> (<?= $sys['disk']['root']['use_percent'] ?? 0 ?>% used)</td></tr>
                    <tr><td class="key">Reboot Required</td><td class="val"><?= $sys['reboot_required'] ? '<strong style="color:#c62828;">YES</strong>' : 'No' ?></td></tr>
                    <tr><td class="key">Updates Available</td><td class="val"><?= ($sys['package_updates'] ?? 0) . ' packages' ?></td></tr>
                </table>
            </div>
        </div>

        <!-- Connection Status -->
        <div class="ipf-box">
            <header><h2>External Connection (RED)</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <tr>
                        <td class="key">Status</td>
                        <td class="val">
                            <span class="badge <?= ($conn['state'] ?? '') === 'connected' ? 'badge-online' : 'badge-offline' ?>">
                                <?= htmlspecialchars(ucfirst($conn['state'] ?? 'down')) ?>
                            </span>
                        </td>
                    </tr>
                    <tr><td class="key">Internet IP</td><td class="val"><?= htmlspecialchars($conn['external_ip'] ?? '0.0.0.0') ?></td></tr>
                    <tr><td class="key">Hostname</td><td class="val"><?= htmlspecialchars($conn['external_hostname'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Connected Since</td><td class="val"><?= htmlspecialchars($conn['duration_text'] ?? '0s') ?></td></tr>
                    <tr>
                        <td class="key">Fireinfo Profile</td>
                        <td class="val">
                            <?php if (!empty($conn['profile'])): ?>
                                <a href="https://fireinfo.ipfire.org/profile/<?= htmlspecialchars($conn['profile']) ?>" target="_blank" style="color:var(--ipf-blue);">View Profile</a>
                            <?php else: ?>
                                Disabled
                            <?php endif; ?>
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        <!-- Network Interfaces -->
        <div class="ipf-box">
            <header><h2>Network Interfaces</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <?php foreach(['red' => 'RED', 'green' => 'GREEN', 'blue' => 'BLUE', 'orange' => 'ORANGE'] as $iface => $label):
                        if (!isset($net[$iface]) || $net[$iface] === null || $net[$iface] === false):
                            continue;
                        endif;
                    ?>
                    <tr><td class="key"><?= $label ?> Driver</td><td class="val"><?= htmlspecialchars($net[$iface]['driver'] ?? 'N/A') ?> (<?= htmlspecialchars($net[$iface]['driver_version'] ?? '') ?>)</td></tr>
                    <tr><td class="key"><?= $label ?> Device</td><td class="val"><?= htmlspecialchars($net[$iface]['device'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key"><?= $label ?> Speed</td><td class="val"><?= $net[$iface]['speed_mbps'] ?? 0 ?> Mbps</td></tr>
                    <tr><td class="key"><?= $label ?> Duplex</td><td class="val"><?= htmlspecialchars($net[$iface]['duplex'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key"><?= $label ?> Link Detected</td><td class="val"><?= $net[$iface]['link_detected'] ? 'Yes' : 'No' ?></td></tr>
                    <tr><td class="key"><?= $label ?> Firmware</td><td class="val"><?= htmlspecialchars($net[$iface]['firmware_version'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key"><?= $label ?> RX Bytes</td><td class="val"><?= number_format($net[$iface]['rx_bytes'] ?? 0) ?></td></tr>
                    <tr><td class="key"><?= $label ?> TX Bytes</td><td class="val"><?= number_format($net[$iface]['tx_bytes'] ?? 0) ?></td></tr>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>

        <!-- Traffic Metrics -->
        <div class="ipf-box">
            <header><h2>Traffic Metrics</h2></header>
            <div class="ipf-box-body">
                <div class="metric-cards">
                    <div class="metric-cell">
                        <div class="label">Incoming</div>
                        <div class="value"><?= format_bytes($traffic['rx_bytes'] ?? 0) ?></div>
                    </div>
                    <div class="metric-cell">
                        <div class="label">Outgoing</div>
                        <div class="value"><?= format_bytes($traffic['tx_bytes'] ?? 0) ?></div>
                    </div>
                    <div class="metric-cell">
                        <div class="label">Total</div>
                        <div class="value"><?= format_bytes(($traffic['rx_bytes'] ?? 0) + ($traffic['tx_bytes'] ?? 0)) ?></div>
                    </div>

                </div>
									<!-- Traffic Graph Canvas (added after metric-cards) -->
					<div style="width:100%;max-width:100%;background:#fafbfc;border:1px solid var(--ipf-border);border-radius:6px;padding:12px;margin-top:12px;">
						<canvas id="trafficChart" style="background:#fafbfc;border-radius:6px;display:block;margin:auto;"></canvas>
					</div>
                <table class="ipf-table">
                    <tr><td class="key">RX Bytes</td><td class="val"><?= number_format($traffic['rx_bytes'] ?? 0) ?></td></tr>
                    <tr><td class="key">TX Bytes</td><td class="val"><?= number_format($traffic['tx_bytes'] ?? 0) ?></td></tr>
                </table>
            </div>
        </div>

        <!-- Core Services -->
        <div class="ipf-box">
            <header><h2>Core Services</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <?php foreach ($services as $srv => $active): ?>
                    <tr>
                        <td class="key"><?= strtoupper(str_replace('_', ' ', $srv)) ?></td>
                        <td class="val">
                            <span class="badge <?= $active ? 'badge-online' : 'badge-offline' ?>">
                                <?= $active ? 'Running' : 'Stopped' ?>
                            </span>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>

        <!-- Add-on Services -->
        <div class="ipf-box">
            <header><h2>Add-on Services</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <?php foreach ($addons as $addon => $info):
                        $isRunning = !empty($info['running']);
                    ?>
                    <tr>
                        <td class="key"><?= htmlspecialchars($addon) ?></td>
                        <td class="val">
                            <span class="badge <?= $isRunning ? 'badge-online' : 'badge-offline' ?>">
                                <?= $isRunning ? 'Running' : 'Stopped' ?>
                            </span>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>

        <!-- Certificates -->
        <div class="ipf-box">
            <header><h2>Certificates</h2></header>
            <div class="ipf-box-body">
                <table class="ipf-table">
                    <?php if (isset($certs['apache'])): ?>
                    <tr><td class="key">Apache Cert Status</td><td class="val"><?= htmlspecialchars($certs['apache']['status'] ?? 'Unknown') ?></td></tr>
                    <tr><td class="key">Subject</td><td class="val"><?= htmlspecialchars($certs['apache']['subject'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Issuer</td><td class="val"><?= htmlspecialchars($certs['apache']['issuer'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Valid From</td><td class="val"><?= htmlspecialchars($certs['apache']['not_before'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Valid To</td><td class="val"><?= htmlspecialchars($certs['apache']['not_after'] ?? 'N/A') ?></td></tr>
                    <tr><td class="key">Days Remaining</td><td class="val"><?= $certs['apache']['remaining_days'] ?? 'N/A' ?></td></tr>
                    <?php if (isset($certs['apache']['remaining'])): ?>
                        <tr><td class="key">Years</td><td class="val"><?= $certs['apache']['remaining']['years'] ?? '' ?></td></tr>
                        <tr><td class="key">Months</td><td class="val"><?= $certs['apache']['remaining']['months'] ?? '' ?></td></tr>
                        <tr><td class="key">Days</td><td class="val"><?= $certs['apache']['remaining']['days'] ?? '' ?></td></tr>
                    <?php endif; ?>
                    <?php endif; ?>
                    
                    <?php if (isset($certs['openvpn']) && isset($certs['openvpn']['clients']) && count($certs['openvpn']['clients'])): ?>
                        <tr><td class="key">OpenVPN Clients</td><td class="val"><?= count($certs['openvpn']['clients']) ?></td></tr>
                    <?php endif; ?>
                </table>
            </div>
        </div>

        <!-- Network Routes -->
        <div class="ipf-box">
            <header><h2>Network Routes</h2></header>
            <div class="ipf-box-body">
                <div class="scrollable">
                    <table class="ipf-table">
                        <thead>
                            <tr>
                                <th>Destination</th>
                                <th>Via</th>
                                <th>Device</th>
                                <th>Raw</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($routes as $route): ?>
                            <tr>
                                <td><?= htmlspecialchars($route['destination'] ?? '-') ?></td>
                                <td><?= htmlspecialchars($route['via'] ?? '-') ?></td>
                                <td><?= htmlspecialchars($route['device'] ?? '-') ?></td>
                                <td style="font-family:'Source Code Pro',monospace;font-size:11px;"><?= htmlspecialchars($route['raw'] ?? '-') ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- Neighbor Peers -->
        <div class="ipf-box">
            <header><h2>Neighbor Peers</h2></header>
            <div class="ipf-box-body">
                <div class="scrollable">
                    <table class="ipf-table">
                        <thead>
                            <tr>
                                <th>Device</th>
                                <th>Address</th>
                                <th>State</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($neighbors as $neighbor): ?>
                            <tr>
                                <td><?= htmlspecialchars($neighbor['device'] ?? '-') ?></td>
                                <td><?= htmlspecialchars($neighbor['address'] ?? '-') ?></td>
                                <td class="<?= $neighbor['state'] === 'failed' ? 'badge-offline' : ($neighbor['state'] === 'delay' ? '' : 'badge-online') ?>">
                                    <?= htmlspecialchars(ucfirst($neighbor['state'] ?? 'unknown')) ?>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- DHCP Leases -->
        <div class="ipf-box">
            <header><h2>DHCP Leases</h2></header>
            <div class="ipf-box-body">
                <div class="scrollable">
                    <table class="ipf-table">
                        <thead>
                            <tr>
                                <th>MAC Address</th>
                                <th>IP Address</th>
                                <th>Hostname</th>
                                <th>Status</th>
                                <th>Expires</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($dhcp_leases as $lease): ?>
                            <tr>
                                <td><?= htmlspecialchars($lease['mac_address'] ?? '-') ?></td>
                                <td><?= htmlspecialchars($lease['ip_address'] ?? '-') ?></td>
                                <td><?= htmlspecialchars($lease['hostname'] ?? '-') ?></td>
                                <td>
                                    <span class="badge <?= $lease['expired'] ? 'badge-offline' : 'badge-online' ?>">
                                        <?= $lease['expired'] ? 'Expired' : 'Active' ?>
                                    </span>
                                </td>
                                <td><?= htmlspecialchars($lease['expires_at'] ?? '-') ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

    </div>
</div>

<footer id="footer">
    <div><strong>IPFire Appliance Dashboard</strong></div>
    <div>
        <a href="https://www.ipfire.org/" target="_blank">IPFire.org</a> &bull;
        <a href="https://www.ipfire.org/donate" target="_blank">Donate</a>
    </div>
</footer>

<script>
(function() {
    // Init values from PHP
    let lastRx = <?= (float)($traffic['rx_bytes'] ?? 0) ?>;
    let lastTx = <?= (float)($traffic['tx_bytes'] ?? 0) ?>;
    let lastTime = Date.now();

    // Chart.js init
    const ctx = document.getElementById('trafficChart').getContext('2d');
    const trafficChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: [],
            datasets: [
                {
                    label: 'RX',
                    borderColor: '#2e7d32',
                    backgroundColor: 'rgba(46,125,50,0.2)',
                    fill: true,
                    tension: 0.2,
                    data: []
                },
                {
                    label: 'TX',
                    borderColor: '#1565c0',
                    backgroundColor: 'rgba(21,101,192,0.2)',
                    fill: true,
                    tension: 0.2,
                    data: []
                }
            ]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            animation: { duration: 0 },
            scales: {
                y: {
                    title: { display: true, text: 'Bytes' },
                    ticks: { stepSize: 1000000 }
                }
            },
            plugins: {
                legend: { position: 'top' }
            }
        }
    });

    // Keep only last 30 data points
    const maxPoints = 30;
    let pointCount = 0;

    async function updateBandwidth() {
        try {
            const response = await fetch('?action=poll', { cache: 'no-store' });
            if (!response.ok) return;
            const json = await response.json();
            if (!json.traffic) return;

            const now = Date.now();
            const curRx = json.traffic.rx_bytes;
            const curTx = json.traffic.tx_bytes;

            const elapsed = (now - lastTime) / 1000;
            if (elapsed > 0) {
                const diffRx = Math.max(0, curRx - lastRx);
                const diffTx = Math.max(0, curTx - lastTx);

                // Update real-time text (Mbit/s)
                const rxMbit = ((diffRx * 8) / (elapsed * 1000000)).toFixed(2);
                const txMbit = ((diffTx * 8) / (elapsed * 1000000)).toFixed(2);
                document.getElementById('red-rx-rate').textContent = rxMbit + ' Mbit/s';
                document.getElementById('red-tx-rate').textContent = txMbit + ' Mbit/s';

                // Feed Chart.js
                const label = 't' + pointCount;
                trafficChart.data.labels.push(label);
                trafficChart.data.datasets[0].data.push(diffRx);
                trafficChart.data.datasets[1].data.push(diffTx);

                if (trafficChart.data.labels.length > maxPoints) {
                    trafficChart.data.labels.shift();
                    trafficChart.data.datasets.forEach(ds => ds.data.shift());
                }
                trafficChart.update('quiet'); // 'quiet' avoids redraw animation
            }

            lastRx = curRx;
            lastTx = curTx;
            lastTime = now;
        } catch (err) {
            console.warn('Real-time metric poller failed', err);
        }
    }

    // Poll every 2.5 seconds
    setInterval(updateBandwidth, 2500);
})();
</script>

</script>
</body>
</html>

Thanks for sharing the code!

A note about TLS verification: In the example code, CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST are both set to false. This means the IPFire web server’s certificate is not verified. While this may seem convenient when using a self-signed certificate, it also makes the connection vulnerable to man-in-the-middle attacks.

A better approach is to trust the IPFire certificate or its issuing CA on the web server and keep verification enabled:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

If needed, you can specify the certificate or CA file with CURLOPT_CAINFO. The hostname in the URL must also match the hostname in the certificate.

Hi everyone,

IPFire-API 0.2.0 is now available:

This release adds an update overview with the pending IPFire core and package updates reported by Pakfire. It also adds an authenticated API action to start the combined update process and report its status.

I don’t currently have access to an IPFire system, so I haven’t been able to test the update installation flow on a live router. If anyone is willing to try it, feedback would be very welcome. Please make sure you have a working backup and are prepared to install all updates currently listed by Pakfire before using the new action.

The API documentation in the repository describes the new fields and request. Please report any issues or suggestions here.

A tested version of the IPFire API with new features is now available on GitHub: IPFire-API 0.2.5.

The API reports available Core and package updates, including their versions, and includes the API script revision in its response. Updates can also be started remotely through the API. The release adds VLAN information and a reboot action, which is only available when IPFire indicates that a reboot is required.

The update installation has been tested successfully on my IPFire system. See the README for details.

@radiocarbonat Please may I ask for some assistence. I have just uploaded your api.cgi to my IPFire, which is on the latest version and when I access it, I get this:

What on earth did I do wrong?

You didn’t do anything wrong. The API returns the retrieved values in JSON format (as stated in the README). Here in this thread, @siosios posted the source code for a PHP page that lets you view the API response formatted in your browser. If you just open the page in your browser, you’ll see a tree structure with the value pairs.
There’s also a way to control RED online or offline.
Did I express myself unclearly in the README? If so, let me know where, and I’ll revise it. Or were your expectations completely different?
Misunderstandings can only be cleared up by talking or writing about them.

@radiocarbonat I apologise if I offended in any way, it was not intentional.

Firstly, no you did not express yourself unclearly, I did not understand the part about the “JSON format”.

Secondly, I did see the PHP code posted by @siosios , however, again I did not understand what it was for, I thought it was just something he was using for himself.

As I obviously way over my head with this add-on, I will just remove it and call it a day and blame my lack of knowledge.

Thank you.

You didn’t offend me at all. I was just a little surprised, since I thought the README was explanation enough.
Maybe I should rework the introduction to make it clear that this API is intended as an interface for external programs or other applications.
I’ll give that some thought and see how I can implement it.
And yes, it’s a good idea to remove the API if you’re not using it. Any additional software that provides services or interfaces on a firewall is a potential security risk. It’s important to know what you’re doing when adding extensions.
Don’t worry—we all started out somewhere and learned step by step. And that never stops.

@radiocarbonat I totally agree that we all started out somewhere and we are constantly learning, so having said that, where would one place the PHP script uploaded by @siosios please? In the same cgi-bin folder?

@markadewet

The PHP script is hosted on a web server located on your local network. As far as I know, no PHP interpreter is installed on IPFire by default.

Update: I’ve revised the introduction to the README. I hope it’s now clearer what the api.cgi is used for.