NetBurner 3.5.7
PDF Version
Disable Config Server

Example Path: examples/Configuration/Application/SystemParams/DisableConfigServer

Disable Config Server

A NetBurner example application that demonstrates how to enable and disable the web configuration server at runtime using the NNDK_WEB_CONFIG_TOGGLE feature. The web config server (default port 20034) provides a browser-based interface for device configuration. This example shows how to control that server programmatically and persist the setting across reboots.

Overview

By default, the NNDK_WEB_CONFIG_TOGGLE feature is disabled in the NNDK. This example uses the overload directory mechanism to enable it, which exposes three API functions for runtime control of the web config server:

  • DisableWebConfig() - Disables the web config server
  • EnableWebConfig() - Enables the web config server
  • IsWebConfigEnabled() - Returns the current enabled/disabled state

These functions modify a config variable (Sys.DisableWebConfig) but do not automatically save to flash. Call SaveConfigToStorage() to persist the change across reboots.

Overload Directory

This example uses the overload directory to enable the NNDK_WEB_CONFIG_TOGGLE feature. The file overload/nbrtos/include/predef-overload.h contains:

#define NNDK_WEB_CONFIG_TOGGLE (1)

The NNDK build system automatically adds the project's overload/ directory to the include path before the system defaults. Since predef.h includes <predef-overload.h>, the project-local version takes precedence over the empty system default, enabling the toggle feature at compile time.

Commands

  • 1: Display the current web config server status (enabled or disabled)
  • 2: Disable the web config server
  • 3: Enable the web config server
  • S: Save the current configuration to flash memory
  • ?: Show the command menu

Usage

  1. Compile and load the application onto your NetBurner device
  2. Connect via serial console
  3. Use command 1 to check the current status
  4. Use commands 2 and 3 to disable or enable the web config server
  5. Use command S to save the setting to flash so it persists across reboots

Notes

  • The web config server listens on port 20034 by default
  • Changes take effect immediately but are not saved to flash until the S command is used
  • The setting is stored in the Sys.DisableWebConfig config variable
  • This feature is disabled by default; it must be enabled via the overload directory as shown in this example



Disable Firmware Uploads While Keeping the Config Server Active

Overview

The NetBurner config server web interface (default port 20034) provides both device configuration and firmware upload capabilities. In some deployments you may want to keep the configuration web page accessible while preventing firmware uploads via /APPUPDATE.HTM.

There is no dedicated toggle for this. Instead, use the NBApproveShutdown() callback to selectively refuse upload requests while leaving the rest of the config server fully functional.

How It Works

When a firmware upload is submitted through the config server, the system calls NBApproveShutdown(SHUTDOWN_CODEUPDATE) before processing the update. If the function returns false, the upload is refused. The relevant code path in config_server.cpp is:

pu->bUpdateRefused = (!NBApproveShutdown(SHUTDOWN_CODEUPDATE));
bool NBApproveShutdown(int reason)
Approve action that will result in a reboot.
Definition NBApproveShutdown/src/main.cpp:25
#define SHUTDOWN_CODEUPDATE
A code update is requested.
Definition ShutDownNotifications.h:52

The NNDK provides a default weak implementation of NBApproveShutdown() that returns true (allowing all shutdowns). By providing your own implementation, you override the default.

Implementation

Include the shutdown notifications header and define your callback:

#include <ShutDownNotifications.h>
bool NBApproveShutdown(int reason)
{
if (reason == SHUTDOWN_CODEUPDATE)
{
return false; // Refuse firmware uploads
}
return true; // Allow everything else (config saves, reboots, etc.)
}

This function is called for several shutdown reasons, defined in ShutDownNotifications.h:

Constant Value Meaning
SHUTDOWN_CODEUPDATE 1 Firmware upload via config server
SHUTDOWN_REBOOT 2 Device reboot request
SHUTDOWN_FACTORYREST 3 Factory reset request

By returning false only for SHUTDOWN_CODEUPDATE, you block firmware uploads while allowing all other operations.

What Remains Functional

With uploads blocked via this method, the config server web page still provides:

  • Viewing device configuration (network settings, system parameters)
  • Modifying configuration values
  • Saving configuration to flash
  • Device reboot (unless you also block SHUTDOWN_REBOOT)

Conditional Upload Control

You can also make the decision dynamic. For example, allow uploads only when a physical button is held, or only during a maintenance window:

#include <ShutDownNotifications.h>
#include <pins_io.h>
bool NBApproveShutdown(int reason)
{
if (reason == SHUTDOWN_CODEUPDATE)
{
// Only allow uploads when a button on pin 0 is pressed
return (Pins[0].read() == 0);
}
return true;
}
int read(int fd, char *buf, int nbytes)
Read data from a file descriptor (fd).

Comparison with DisableConfigServer

Approach Config Web Page Config Changes Firmware Uploads
DisableWebConfig() Disabled Disabled Disabled
NBApproveShutdown guard Active Active Blocked

References

  • nbrtos/include/ShutDownNotifications.h - Callback declaration and shutdown reason constants
  • nbrtos/source/config_server.cpp:1401 - Where NBApproveShutdown is called during uploads
  • nbrtos/source/config_server.cpp:1298-1300 - Upload refusal handling in AppUpdateDataSink()