# SMArT

SMArT is the web-based configuration interface for **MARS_NWE**, a Novell NetWare 3.x emulator for Linux and FreeBSD.

In the current setup, this repository is no longer treated as a standalone component only. It is integrated into the main `mars_nwe` project as a **Git submodule** and is therefore included in the normal **mars_nwe release** process.

## Project status and integration

This repository is intended to be embedded into the main `mars_nwe` Git repository:

- Main project: `mars_nwe`
- Submodule role: provides the SMArT web UI and helper tools
- Release model: shipped as part of the integrated **MARS_NWE** release, not as a separate end-user release artifact

The build and install rules show that the web UI binaries, Perl helpers, configuration, static assets, and PAM file are installed as part of the overall build and installation flow.

## Architecture overview

SMArT consists of two main parts:

1. **Perl-based application logic** for configuration pages and helper scripts
2. **`nwwebui` service** as the web frontend that exposes the application over HTTP and HTTPS

The current implementation adds a dedicated `nwwebui` service that can serve the application directly over:

- **HTTP on port 9080**
- **HTTPS on port 9443**

The service supports TLS via OpenSSL and can run both listeners in parallel. HTTPS is the preferred mode because authentication happens more securely over an encrypted connection, while plain HTTP may still be useful for testing or trusted internal environments.

## Security model

SMArT uses PAM-based authentication through the `check_login` helper. The supplied PAM policy is a standard `pam_unix` stack for authentication, account, password, and session handling. During installation with **MARS_NWE**, this file is installed automatically as:

- `/etc/pam.d/smart`

That means no manual PAM file deployment is normally required when SMArT is installed through the integrated `mars_nwe` package or release.

## Installed components

The install rules include the following relevant components.

### Binaries

- `nwwebui` – dedicated web service frontend
- `check_login` – PAM authentication helper

### Perl helpers

- `smart`
- `apply.pl`
- `readconfig.pl`
- `settings.pl`
- `static.pl`

### Configuration and assets

- `smart.conf`
- static HTML and image assets for the web UI
- optional `mars-nwe-webui.service` systemd unit
- PAM file installed as `/etc/pam.d/smart`

These components are all installed by the build system as part of the same integrated installation target.

## Typical runtime paths

The original templates use CMake placeholders. For documentation, the following standard example paths can be used in a typical Linux installation:

- Main MARS_NWE config directory: `/etc/mars_nwe`
- SMArT config file: `/etc/mars_nwe/smart.conf`
- Main MARS_NWE server config: `/etc/mars_nwe/nwserv.conf`
- Helper binaries and scripts: `/usr/libexec/mars_nwe`
- Static SMArT assets: `/usr/libexec/mars_nwe/static`
- Log directory: `/var/log/mars_nwe`
- PID directory: `/run/mars_nwe`
- TLS certificate: `/etc/mars_nwe/server.crt`
- TLS private key: `/etc/mars_nwe/server.key`
- PAM file: `/etc/pam.d/smart`

These values are sensible standard defaults for documentation. Packaging may still adjust them depending on the target distribution.

## The `smart.conf` file

The `smart.conf` file controls both the SMArT frontend behavior and the `nwwebui` listener settings.

A documented example with standard installation paths is shown below:

```perl
# SMArT / nwwebui configuration file

# ------------------------------------------------------------
# UI colors
# ------------------------------------------------------------
$COLOR_BACK      = "#F0F0FF";
$COLOR_HEAD_BACK = "#C0C0FF";
$COLOR_HEAD_FORE = "#000000";
$COLOR_SUBH_BACK = "#D0D0FF";
$COLOR_SUBH_FORE = "#000000";
$COLOR_TEXT_BACK = "#E0E0FF";
$COLOR_TEXT_FORE = "#000000";

# ------------------------------------------------------------
# Main MARS_NWE configuration
# ------------------------------------------------------------
$mars_config = '/etc/mars_nwe/nwserv.conf';
$nonroot_user = 'nobody';
$smart_compact_nwservconf = 0;

# ------------------------------------------------------------
# SMArT internal file layout
# ------------------------------------------------------------
$smart_conf_path     = '/etc/mars_nwe/smart.conf';
$smart_nwclient_path = '/etc/mars_nwe/.nwclient';
$smart_static_dir    = '/usr/libexec/mars_nwe/static';
$smart_log_path      = '/var/log/mars_nwe/smart.log';
$smart_check_login   = '/usr/libexec/mars_nwe/check_login';

# Optional override, usually not needed
# $smart_perl_path   = '/usr/libexec/mars_nwe/smart';

# ------------------------------------------------------------
# nwwebui listener settings
# ------------------------------------------------------------
$nw_bind_ip    = '0.0.0.0';
$nw_log_level  = 1;
$nw_daemonize  = 0;
$nw_pid_file   = '/run/mars_nwe/nwwebui.pid';
$nw_log_file   = '/var/log/mars_nwe/nwwebui.log';

$nw_ssl_enable = 0;
$nw_http_port  = 9080;
$nw_https_port = 9443;

$nw_cert_file  = '/etc/mars_nwe/server.crt';
$nw_key_file   = '/etc/mars_nwe/server.key';
```

## `smart.conf` settings explained

### UI colors

These variables define the default SMArT page colors:

- `$COLOR_BACK` – page background
- `$COLOR_HEAD_BACK` / `$COLOR_HEAD_FORE` – main section header colors
- `$COLOR_SUBH_BACK` / `$COLOR_SUBH_FORE` – subsection header colors
- `$COLOR_TEXT_BACK` / `$COLOR_TEXT_FORE` – regular content row colors

### Main MARS_NWE configuration

- `$mars_config` – path to the main `nwserv.conf` file that SMArT reads and updates
- `$nonroot_user` – unprivileged user account used when SMArT drops privileges
- `$smart_compact_nwservconf` – controls how `nwserv.conf` is written back:
  - `0` keeps comments, spacing, and the original structure as much as possible
  - `1` writes a more compact version without the original long comment layout

### SMArT internal file layout

- `$smart_conf_path` – absolute path to `smart.conf`
- `$smart_nwclient_path` – file used to store bindery login information for SMArT helper tools
- `$smart_static_dir` – directory containing HTML, icons, and other static assets
- `$smart_log_path` – log file used by the Perl-based SMArT frontend
- `$smart_check_login` – PAM-based authentication helper path
- `$smart_perl_path` – optional override for the main SMArT Perl executable; usually not needed

### `nwwebui` listener settings

- `$nw_bind_ip` – bind address for HTTP and HTTPS listeners, for example `0.0.0.0` for all IPv4 interfaces or `127.0.0.1` for localhost-only access
- `$nw_log_level` – service log verbosity:
  - `0` = errors only
  - `1` = informational messages
  - `2` = debug output
- `$nw_daemonize` – whether `nwwebui` detaches into the background
- `$nw_pid_file` – location of the PID file
- `$nw_log_file` – log file written by `nwwebui`
- `$nw_ssl_enable` – enables or disables HTTPS support
- `$nw_http_port` – HTTP listener port; set to `0` to disable plain HTTP
- `$nw_https_port` – HTTPS listener port; set to `0` to disable HTTPS
- `$nw_cert_file` – PEM certificate path for TLS
- `$nw_key_file` – PEM private key path for TLS

The current code and template show that:

- `nwwebui` listens on `9080` for HTTP by default
- `9443` is used for HTTPS
- the log file can be configured with `$nw_log_file`
- the log path can also be overridden at runtime with `-l`

Because passwords may be transmitted during login, HTTPS is the recommended way to access the interface.

## Starting the service

Depending on the installation method, `nwwebui` can be started either via **systemd** or directly from the **command line**. The build system installs a `mars-nwe-webui.service` unit when systemd support is enabled.

### Starting with systemd

A typical installed system uses the `mars-nwe-webui.service` unit. The unit starts `nwwebui`, prepares the needed runtime directories, and loads the standard `smart.conf` file.

Typical commands:

```bash
systemctl enable --now mars-nwe-webui.service
systemctl start mars-nwe-webui.service
systemctl stop mars-nwe-webui.service
systemctl restart mars-nwe-webui.service
systemctl status mars-nwe-webui.service
```

The service unit starts `nwwebui` with the equivalent of:

```bash
/usr/sbin/nwwebui -c /etc/mars_nwe/smart.conf
```

### Starting from the command line

`nwwebui` can also be launched manually. The built-in usage text documents the supported options:

```text
Usage: nwwebui [-h] [-d] [-s] [-c <smart.conf>] [-p <pidfile>] [-l <logfile>]

Options:
  -h, --help            Show this help text and exit
  -d, --daemon          Run in daemon mode
  -s, --stop            Stop the running nwwebui instance
  -c, --config <file>   Use an alternate smart.conf path
  -p, --pidfile <file>  Override PID file path
  -l, --logfile <file>  Override log file path
```

Typical examples:

```bash
# start in foreground with the standard configuration
/usr/sbin/nwwebui -c /etc/mars_nwe/smart.conf

# start in daemon mode
/usr/sbin/nwwebui -d -c /etc/mars_nwe/smart.conf

# stop a running instance
/usr/sbin/nwwebui -s -c /etc/mars_nwe/smart.conf

# use a custom PID file
/usr/sbin/nwwebui -d -c /etc/mars_nwe/smart.conf -p /run/mars_nwe/nwwebui.pid

# use a custom log file
/usr/sbin/nwwebui -c /etc/mars_nwe/smart.conf -l /var/log/mars_nwe/custom-nwwebui.log

# override both PID and log file
/usr/sbin/nwwebui -d -c /etc/mars_nwe/smart.conf -p /run/mars_nwe/nwwebui.pid -l /var/log/mars_nwe/nwwebui.log
```

The `-l` option overrides `$nw_log_file` from `smart.conf` at runtime.

Typical access URLs:

- `http://<host>:9080/`
- `https://<host>:9443/`

For production use, HTTPS should be preferred.

## Build and installation notes

This repository is built as part of the main `mars_nwe` build. The build system:

- generates `smart.conf` from the template
- generates the `smart` launcher script
- builds `nwwebui`
- builds `check_login`
- installs the PAM file and static UI assets

Because this repository is integrated as a Git submodule in `mars_nwe`, end users normally consume it through the main `mars_nwe` source tree and release packages rather than using it as a standalone project.

## Summary

SMArT is now an integrated part of the `mars_nwe` release and includes a dedicated `nwwebui` service that can expose the interface over both HTTP and HTTPS. The standard listener ports are **9080** for HTTP and **9443** for HTTPS. Authentication is handled through PAM, and the required `/etc/pam.d/smart` file is installed automatically together with the integrated MARS_NWE installation.
