modemmenu -serve listens on [server] listen, a unix socket (or tcp:host:port), for app_dmodem's mode = unix profiles: each connection gets a session of its own, modemmenu on a new pty as mode = exec would give it, so pppd, shells and ^C work the same. A socket has no environment: the call's details come first as a header, NAME=value lines and an empty line (app_dmodem's header = yes). socket_mode and socket_group decide who may connect, max_sessions caps them, SIGTERM hangs them all up and removes the socket. Menu items reach other menu applications on unix sockets: mode = unix (raw), or a path on tcp, telnet and rlogin items, and header = yes sends the session ahead. A modemmenu -serve with trust_user takes the user of such a header as logged in, so a caller moves from one menu to another without a second login. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RvtV8Dg9kqRaakbTEfyH3f
modemmenu: a login and menu for dial-up callers
modemmenu is the first thing a caller sees once the modems are
connected. It asks for a user name and password, checks them against a
text file, LDAP, an SQL database (MySQL/MariaDB, PostgreSQL, SQLite) or
the system's own accounts through PAM, shows the message of the day and
offers a menu:
Welcome to D-Modem.
login: alice
Password: ******
Hello alice, connected at 33600 bit/s on 2026-10-10 21:05:09.
The line is down for maintenance on Sunday.
Main menu
[B] Bulletin board
[P] PPP (dial-up networking)
[S] Shell
[G] Goodbye (hang up)
Selection: ppp
The caller picks an item by its key, its name or an alias (p, ppp
or dialup here), and the item starts with the caller's credentials and
the details of the call: user name, password, the backend that accepted
them, the dialed number, the caller ID, the connect rate and the date
and time of the connection.
Running it from app_dmodem
app_dmodem, the Asterisk module of
D-Modem-RE (asterisk/),
hands it the caller's line in one of two ways: it starts modemmenu for
each call (mode = exec), or connects each call to one modemmenu -serve on a unix socket (mode = unix, below).
A program for each call
app_dmodem runs modemmenu as a mode = exec program on the caller's
line:
; dmodem.conf
[menu]
mode = exec
command = exec /usr/local/bin/modemmenu -config /etc/asterisk/modemmenu.conf
; extensions.conf
exten => 5551000,1,DModem(menu)
same => n,Hangup()
modemmenu reads the call's details from app_dmodem's environment:
DMODEM_RATE (tx/rx bit/s), DMODEM_CALLERID, DMODEM_DIALED,
DMODEM_CHANNEL and DMODEM_PROFILE. DMODEM_DIALED needs an
app_dmodem that sets it. The -rate, -callerid and -dialed options
set these instead, e.g. under a getty on another modem.
The line is raw (app_dmodem's pty): modemmenu echoes and edits what the caller types itself. Its exit, like the selection's, hangs up the call.
One server on a unix socket
modemmenu -serve listens on [server] listen (a unix socket, or
tcp:host:port) and app_dmodem connects each call to it:
; dmodem.conf
[menu]
mode = unix
path = /run/modemmenu/modemmenu.sock
header = yes
; modemmenu.conf
[server]
listen = /run/modemmenu/modemmenu.sock
socket_mode = 0660
socket_group = asterisk
A socket has no environment, so app_dmodem's header = yes sends the
call's details first: DMODEM_CHANNEL, DMODEM_PROFILE, DMODEM_RATE,
DMODEM_CALLERID, DMODEM_DIALED and DMODEM_CONNECTED (Unix time),
one NAME=value per line, then an empty line, then the caller's bytes.
[server] header = yes (the default) reads it; with header = no the
caller's bytes come from the start and the details are unknown.
Each connection gets a session of its own: a new pty with modemmenu on
it, as mode = exec would give it, so pppd, shells and ^C work the
same. The caller hanging up hangs up the pty; the session ending closes
the connection, which hangs up the call.
[server] option |
default | |
|---|---|---|
listen |
/run/modemmenu/modemmenu.sock |
a unix socket's path, or tcp:host:port |
socket_mode |
0660 |
the socket's permissions: who may connect |
socket_group |
the socket's group, e.g. Asterisk's | |
header |
yes |
read the session header first |
header_timeout |
10 |
seconds for the header to come |
trust_user |
no |
a header's MODEM_USER is logged in already (below) |
max_sessions |
32 |
sessions at once; more callers hear the lines are busy |
-listen PATH overrides listen. SIGTERM hangs up every session,
removes the socket and ends the server; a stale socket left by a server
that died is replaced at start, a live one is not.
modemmenu.service.sample runs it under
systemd, which also makes /run/modemmenu. Each connection is logged
with its peer's pid and uid.
Building
Go 1.22 or later:
make # or: go build (-tags pam for PAM)
make PAM=0 # without PAM, when libpam's headers are there
make test
make install # /usr/local/bin/modemmenu, and the samples into
# /etc/asterisk (and /etc/pam.d) if there are none
make builds with PAM when libpam's headers are installed
(libpam0g-dev on Debian and Ubuntu, pam-devel on Fedora). Without
them modemmenu builds with the other backends, and auth = system is a
configuration error.
Configuration
modemmenu.conf.sample has every option. In short:
[general]
; the backends, asked in this order
auth = file system
; the message of the day, before the menu
motd_file = /etc/motd
[file]
path = /etc/asterisk/modemmenu.users
[system]
pam_service = modemmenu
groups = dialup
[menu]
hangup = G goodbye bye logoff
[item bbs]
key = B
label = Bulletin board
mode = rlogin
host = 127.0.0.1
after = menu
[item ppp]
; p, ppp (its name) and dialup select it
key = P
aliases = dialup
label = PPP (dial-up networking)
mode = exec
command = exec /usr/sbin/pppd nodetach noauth local lock passive 192.168.77.1:192.168.77.2 ipparam {user}
[item shell]
key = S
label = Shell
mode = exec
run_as = {user}
tty = sane
pass_password = no
command = exec "$SHELL" -l
Comments (; or #) go on lines of their own. modemmenu -check -config FILE checks a configuration.
Authentication
[general] auth lists the backends, asked in that order. A backend
that does not know the user hands over to the next; one that knows the
user and finds the password wrong ends the attempt there. A backend
that is down (LDAP unreachable, SQL error) is logged and skipped.
- file:
user:passwordlines. The password is a bcrypt hash (modemmenu -hashprints one),{SHA256}/{SHA512}(hex or base64),{SSHA256}/{SSHA512}(salted, base64) or{PLAIN}text. The file is read at each login. - ldap: a bind as the user, either to
bind_dnwith{user}in it, or to the entrysearch_filterfinds undersearch_base. ldaps://, StartTLS and a private CA are supported; a group check goes in the filter (memberOf=...). Values are escaped for DNs and filters. - sql:
querywith the user (and optionally the password) as arguments returns the stored password, checked like the file's; or withhash = noneany row means the login is right, for a database that checks passwords itself (crypt()in PostgreSQL). - system (or pam): the machine's own accounts, through PAM. See below.
User names must match user_pattern (letters, digits, ._@- by default);
wrong logins wait fail_delay seconds, unknown users take as long as
known ones, and the call is hung up after attempts tries or
login_timeout.
System accounts (PAM)
auth = system runs the auth and account stacks of the PAM service
pam_service (modemmenu by default), so local accounts and anything
PAM is set up for (sssd, Kerberos, OTP modules) work, with PAM's own
checks for expired and locked accounts. It needs a build with PAM
(above). To set it up:
- Install the PAM service:
make installputs modemmenu.pam.sample in/etc/pam.d/modemmenu(the distribution'scommon-authandcommon-account). - Run Asterisk, and so modemmenu, as root for local accounts:
pam_unixchecks other users' passwords only for root. - Add
systemto[general] auth, and in[system]:option default pam_servicemodemmenuthe file in /etc/pam.dmin_uid1000accounts below it (system accounts) are not let in allow_rootnoyeslets root log ingroupsonly members of these groups (membership or primary group)
An account that these rules keep out is "unknown" to this backend: the
next one is asked, and the reason is logged. With run_as = {user}, a
selection such as the shell then runs as the caller's own account.
Message of the day
After the welcome and before the menu, modemmenu shows [general] motd
and then the file motd_file (e.g. /etc/motd), either or both. The
file is read at each login, so edits show at once; {placeholders} work
in both, e.g. motd = "Hello {user}, you called {dialed}.\r\n".
The menu
The caller types a choice and presses Enter. An item is selected by its
key, its name ([item ppp]) or one of its aliases, in any case; so
with key = P and aliases = dialup, p, P, ppp and dialup all
start PPP. A key may be longer than one character (key = SH); the
menu shows the key, its labels lined up.
?ormenushows the menu again; an unknown choice says so and asks again.[menu] hanguplists what hangs up,G goodbye bye logoffby default; the first one is shown in the menu.hotkeys = yesselects with one key, without Enter. Every key (and the first hangup word) must then be one character.- Two items, or an item and a hangup word, that answer to the same word are a configuration error.
[menu] title,promptanditems(the order) set the rest; see the sample.
What the selection gets
| placeholder | environment | |
|---|---|---|
{user} |
MODEM_USER |
the user name |
{password} |
MODEM_PASSWORD |
the password (not with pass_password = no) |
{auth} |
MODEM_AUTH |
file, ldap, sql or system |
{dialed} |
MODEM_DIALED |
the number dialed |
{callerid} |
MODEM_CALLERID |
the caller's number |
{baud} |
MODEM_BAUD |
the connect rate towards the caller, bit/s |
{rate}, {tx_rate}, {rx_rate} |
MODEM_RATE, MODEM_TX_RATE, MODEM_RX_RATE |
both rates |
{date}, {time} |
MODEM_DATE, MODEM_TIME |
the connection's date and time |
{datetime}, {epoch} |
MODEM_DATETIME, MODEM_EPOCH |
the same, RFC 3339 and Unix time |
{channel}, {profile} |
MODEM_CHANNEL, MODEM_PROFILE |
app_dmodem's channel and profile |
{selection} |
MODEM_SELECTION |
the item chosen |
How it reaches each kind of selection:
- exec (
command, by/bin/sh -c): the environment, the placeholders in the command (each one a shell-quoted word already, so{user}and not"{user}"), and withsession_file = yesall of it as JSON in a 0600 file named byMODEM_SESSION_FILE, removed when the program ends.run_asruns it as a system user (modemmenu must be root),tty = sanegives it a cooked terminal. - rlogin: the RFC 1282 handshake; by default the password as the
client user, the user name as the server user and
ansi/{baud}as the terminal, which is how Synchronet, Mystic and other BBSs log a caller in without asking again. - tcp and telnet:
send, e.g.send = "{user}\r{password}\r", is sent once connected; telnet negotiates binary, echo and the terminal type. - unix: like tcp, raw, to a server on the unix socket
path.tcp,telnetandrloginitems take apathtoo, for their protocol on a unix socket. - header (
header = yes, on any of the socket kinds): the session first,MODEM_*NAME=valuelines and an empty line (the password only withpass_password), beforesendor the protocol.
after = menu returns to the menu when the selection ends, after = hangup (the default) hangs up.
Handing a caller to another menu
An item can hand the caller to another menu application on a unix
socket. To another modemmenu -serve, with the session header and that
server's trust_user = yes, the caller stays logged in: it shows its own
banner, welcome and menu, with the user, the password (with
pass_password), MODEM_AUTH as upstream:<backend>, and the call's
rate, number and time from the header.
; the front menu
[item more]
key = M
label = More services
mode = unix
path = /run/modemmenu/more.sock
header = yes
after = menu
; the other menu's modemmenu.conf
[server]
listen = /run/modemmenu/more.sock
trust_user = yes
socket_mode = 0600
trust_user believes whoever can connect: keep that socket to the front
menu's user (socket_mode, socket_group). Without it, the other menu
asks the caller to log in again.
Security notes
- Asterisk usually runs as its own user: the users file (and modemmenu.conf, which may hold database and LDAP passwords) must be readable by it, and by no one else.
- Running as root (for
auth = systemwith local accounts, or forrun_as) means app_dmodem's Asterisk runs as root. - The password goes to the selection unless
pass_password = no. In the environment it is readable by the same user and root (/proc/PID/environ);session_filekeeps it out of the environment if the program reads the file instead. - Never put
{password}in a command line: other users see the arguments of every process. UseMODEM_PASSWORDor the session file. - A server's socket is only as safe as its permissions: anyone who can
connect gets a login prompt, and with
trust_usera login as whoever they name. Keepsocket_modeandsocket_groupto Asterisk or the front menu. - The log (syslog's auth facility by default) gets logins, failures and selections, never passwords. It is never the line: the caller would see it.
Tests
make test checks the password schemes, the file and SQLite backends,
the menu's choices and the telnet client, and runs modemmenu on a pty as
app_dmodem does: a wrong and a right login, the message of the day,
choices by key, name and alias, an unknown choice and ?, an rlogin BBS
and back to the menu, a cooked shell, and an exec selection's
environment and session file. It also runs modemmenu -serve on a unix
socket: a session from an app_dmodem header (on a pty of its own), a
caller hanging up, another modemmenu handing a logged-in caller over by
a mode = unix item, and SIGTERM. The system backend's uid, root and
group rules are tested with PAM replaced.
Two more tests run when their servers are given:
MODEMMENU_TEST_PAM=user:password make test, as root with/etc/pam.d/modemmenu: PAM against a real account.MODEMMENU_TEST_LDAP=ldap://host:port make test: the LDAP backend, against a server withuid=lduser,ou=people,dc=example,dc=com(passwordldpass).