SyslogWatch server mode
=======================

Run SyslogWatch as a service and open its console from any browser on your network.

The desktop app needs a graphical session. Server mode does not: it receives,
stores and alerts exactly the same way, keeps running when nobody is signed in to
the server, and shows the same screen in your browser instead of a window —
over HTTPS, behind a username and password.

What a minimal server still needs
---------------------------------
Server mode opens no window and contacts no X server, but the program is one
binary and the system loads every library that binary is linked against before
it starts. So GTK, X11, NSS and ALSA have to be installed even though nothing
draws. The .deb package lists them as dependencies and your package manager
installs them for you — on Debian and Ubuntu that is the easier route. If you
unpacked the .tar.gz instead, install them yourself:

    # Debian / Ubuntu
    sudo apt-get install -y libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 \
        xdg-utils libatspi2.0-0 libuuid1 libsecret-1-0 libgbm1 libasound2
    # on Ubuntu 24.04 and Debian trixie or newer, libasound2 is libasound2t64

    # RHEL / Rocky / Alma / Fedora
    sudo dnf install -y gtk3 libnotify nss libXScrnSaver libXtst xdg-utils \
        at-spi2-atk libuuid libsecret mesa-libgbm alsa-lib

If any are missing, syslogwatch-headless says so and prints the list rather
than leaving you with a bare "error while loading shared libraries".

Licence agreement
-----------------
SyslogWatch does not receive anything until the licence agreement has been
accepted. The agreement is EULA.txt in this folder (also
https://meshwatch.app/terms). Read it, then either

  - start with --accept-eula, which records your acceptance in the data folder
    (eula.json) and prints one line saying so, or
  - start without it and sign in to the console as an administrator: it shows
    the agreement first, and syslog reception starts when you select "I agree".

The service unit (syslogwatch-headless.service) passes --accept-eula:
installing and enabling it means you accept the agreement. When a later
version changes the agreement, it asks again.

1. Run it as a service
----------------------
The commands are at the top of syslogwatch-headless.service in this folder:

    sudo useradd --system --home /var/lib/syslogwatch --create-home --shell /usr/sbin/nologin syslogwatch
    sudo cp /opt/SyslogWatch/syslogwatch-headless.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable --now syslogwatch-headless
    sudo journalctl -u syslogwatch-headless

The log shows the console address and the certificate fingerprint:

    console  https://syslog01:8514/
             https://192.168.1.20:8514/
    certificate  self-signed (/var/lib/syslogwatch/SyslogWatch/tls/cert.pem)
             SHA-256 3A:1F:...:C4
    accounts NONE YET — create the first administrator: ...

Open TCP 8514 in the server's firewall if it has one:

    sudo ufw allow 8514/tcp                                            # Ubuntu
    sudo firewall-cmd --add-port=8514/tcp --permanent && sudo firewall-cmd --reload   # RHEL

(To try it in the foreground first: /opt/SyslogWatch/syslogwatch-headless --accept-eula)

2. Create the first administrator
---------------------------------
Nobody can sign in until an administrator exists, and for safety the first one
can only be created from the server itself — otherwise anyone on the network
could claim it before you. Either run, on the server:

    sudo -u syslogwatch SYSLOGWATCH_DATA_DIR=/var/lib/syslogwatch/SyslogWatch \
        /opt/SyslogWatch/syslogwatch-headless --create-admin admin

(it asks for the password twice and does not show it; at least 12 characters),
or open https://localhost:8514/ in a browser on the server, or tunnel to it from
your PC and open the same address there:

    ssh -L 8514:127.0.0.1:8514 you@syslog01

3. Open the console from your PC
--------------------------------
Open https://<server>:8514/ in your browser. The certificate is self-signed, so
the browser warns that it does not know it. Open the certificate details, check
that its SHA-256 fingerprint is the one in the service log (the sign-in page
shows it too), then continue. Sign in with the administrator account.

A plain http:// address on the same port is redirected to https://.

Send a test message from the server to see it arrive:

    logger -n 127.0.0.1 -P 1514 -d "hello from $(hostname)"

Accounts and roles
------------------
  Administrator   everything: settings, alert rules, the licence, accounts
  Viewer          sees the logs, searches, exports reports — cannot change
                  anything (the server refuses it and the screen says so)

Add people in the console under Accounts (top right), or on the server:

    syslogwatch-headless --add-user alice --role viewer
    syslogwatch-headless --list-users
    syslogwatch-headless --reset-password alice     # forgotten password; signs her out everywhere

Run these as the service user with the same data folder (as in step 2). Sessions
end after 12 hours without activity, on Sign out, and when the service restarts.
Ten failed sign-ins a minute from one address, or five in a row for one account,
lock further attempts for a while.

HTTPS
-----
  - The self-signed certificate lives in <data folder>/tls (cert.pem, key.pem,
    mode 0600). It is valid for 825 days and is replaced automatically 30 days
    before it expires — the log then says the fingerprint is new.
  - Your own certificate: --cert /path/fullchain.pem --key /path/privkey.pem
    (the service user must be able to read both). The fingerprint shown is then
    that certificate's.
  - --insecure-http serves plain HTTP. Use it only behind an HTTPS reverse proxy
    (nginx, Caddy) on the same machine, together with --ui-host 127.0.0.1. Requests
    that arrive through a proxy (X-Forwarded-For) never count as "this machine",
    so create the first administrator with --create-admin.

Options: syslogwatch-headless --help
Lost the address or the fingerprint: syslogwatch-headless --show-url

Upgrading from 1.3.8 (token sign-in)
------------------------------------
1.3.8 opened the screen with a one-time token (ui-token in the data folder). That
token no longer opens anything; the console now uses accounts, and the log says
so on the first start. Create the first administrator as in step 2.

  - Your existing unit file in /etc/systemd/system still says --ui-host 127.0.0.1,
    so the console stays on this machine until you remove that option (the new
    unit file in this folder no longer has it).
  - If you put an HTTPS reverse proxy in front as 1.3.8 suggested, either point it
    at https://127.0.0.1:8514 (the console now speaks HTTPS itself), or add
    --insecure-http to keep plain HTTP behind the proxy.

Secrets on a server
-------------------
There is no keyring on a server, so the licence key, SMTP password and Central
token are stored as plain files readable only by the service user (mode 0600)
under the data folder. The screen says so in Settings. Account passwords are
stored only as scrypt hashes (users.json, mode 0600).

Same data as the desktop app
----------------------------
Server mode and desktop use the same folder (~/.config/SyslogWatch for the user
that runs it), so a licence activated in one is active in the other.


Behind a corporate proxy
------------------------
SyslogWatch makes two kinds of outbound request, both to meshwatch.app: the
once-a-day check for a newer version, and up to three one-time anonymous
start-up signals per installation (see https://meshwatch.app/privacy). Receiving
and the console are inbound and need no proxy. If the server reaches the
Internet only through a proxy, give it the usual variables — syslogwatch-headless
tells the runtime to honour them:

    Environment=HTTPS_PROXY=http://proxy.example.com:3128
    Environment=NO_PROXY=localhost,127.0.0.1

in the [Service] section of syslogwatch-headless.service (there are commented
lines ready for it), then systemctl daemon-reload and restart. Without the
variables nothing changes. To stop both requests altogether, set
MESHWATCH_DISABLE_UPDATE_CHECK=1 the same way, or create an empty file named
no-update-check in the data folder.
