Project

General

Profile

Actions

Feature #13054

closed

Package plugin hook for web server configuration stanzas

Added by Jim Pingle over 2 years ago. Updated over 1 year ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Package System
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
Plus Target Version:
23.05
Release Notes:
Default

Description

Packages may potentially need to add server and location blocks to the web server configuration for various reasons. We should add plugin hooks that let packages define their own stanzas in at least two places:

  • location definitions inside the main server configuration stanza
  • server definitions later in the file, after the web server and redirect blocks.
Actions #1

Updated by Jim Pingle almost 2 years ago

  • Target version set to 2.7.0
  • Plus Target Version set to 23.05
Actions #2

Updated by Jim Pingle over 1 year ago

  • Status changed from New to In Progress
Actions #3

Updated by Jim Pingle over 1 year ago

Implementation is as described in the issue description. The plugin can be defined in a package as in the following example:

First, declare the plugin by name (plugin_nginx) in the package XML:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
<packagegui>
    <copyright>
    </copyright>
    <name>testnginx</name>
    <title>testnginx</title>
    <include_file>/usr/local/pkg/testnginx.inc</include_file>
    <plugins>
        <item>
            <type>plugin_nginx</type>
        </item>
    </plugins>
</packagegui>

And then in the package code, implement a function called <packagename>_plugin_nginx:

<?php

function testnginx_plugin_nginx($pluginparams) {
    global $config;
    /* Caller did not properly define data, exit early */
    if (!is_array($pluginparams) ||
        empty($pluginparams) ||
        empty($pluginparams['section'])) {
        return "";
    }
    $result = "";
    switch ($pluginparams['section']) {
        case 'location':
            $result = "        # This content is placed after the location stanzas of the main GUI server.";
            break;
        case 'server':
            $result = "    # This content is placed after the server stanza of the GUI server(s)";
            break;
        default:
            $result = "# Nothing to do here, no section given.";
    }
    return $result;
}

The 'section' parameter passed in from the caller will let the function know if it's being called for a location block in the main GUI server or for a server block that is separate. Be sure to indent the content appropriately (two tab levels for locations, one tab level for servers).

This function does not currently support captive portal but could be extended to do so in the future.

Actions #4

Updated by Jim Pingle over 1 year ago

  • Status changed from In Progress to Feedback
  • % Done changed from 0 to 100
Actions #5

Updated by Jim Pingle over 1 year ago

  • Status changed from Feedback to Resolved
Actions

Also available in: Atom PDF