Merge pull request #27 from D-Modem/claude/project-thread-90lap6

Connect message: show the modulation, protocol and compression
This commit is contained in:
Neo authored and GitHub committed 2026-11-24 05:34:36 -08:00
commit f5380bc010
12 files changed
+201 -38

No files matched your search

+2 -2
View File
@@ -15,7 +15,7 @@ for each call or as one server for all calls.
```
Welcome to D-Modem.
Connected at 33600 bit/s.
Connected at 33600 bit/s (V.34, LAPM/V.42bis).
login: alice
Password: ******
@@ -41,7 +41,7 @@ Selection: ppp
- Menus with access by user and by group, guest access and self sign-up.
- A full-screen menu on ANSI and VT terminals, and a line menu on other terminals. The full-screen menu looks like a blue desktop from the 1990s. The cursor keys move the bar. For slow lines, dmodem-login sends only the changes to the screen.
- `dmodem-login -setup`: full screens with pull-down menus and the help text from the sample, to change the configuration. The sysop can use them at the console or on a call.
- Each item starts with the credentials of the caller and the details of the call: dialed number, caller ID, connect rate and time.
- Each item starts with the credentials of the caller and the details of the call: dialed number, caller ID, connect rate, modulation, error correction and time.
- Drop files for doors, a list of the last callers, and the transfer of a caller to a different menu.
- A FreePBX configuration that is ready to use ([freepbx/](freepbx/README.md)).
+6 -2
View File
@@ -198,6 +198,9 @@ func (s *session) String() string {
// run the login and the menu: the exit status
func run(t *term.Term, s *settings, sess *session) int {
logf("connect %v", sess)
if sess.Modulation != "" || sess.Protocol != "" {
logf("connection modulation=%s protocol=%s compression=%s %v", sess.Modulation, sess.Protocol, sess.Compression, sess)
}
if !s.callerAllowed(sess.CallerID) {
logf("refused by caller ID %v", sess)
t.Write(s.callerID.denyMessage)
@@ -214,8 +217,9 @@ func run(t *term.Term, s *settings, sess *session) int {
if t.Write(config.Expand(s.banner, sess.vars(false), nil)) != nil {
return 1
}
// the connect rate, as BBSs greeted their callers (not when it is
// not known: no "Connected at ." on a getty without -rate)
// the connect rate, the modulation and the link, as BBSs greeted
// their callers (not when the rate is not known: no "Connected at ."
// on a getty without -rate)
if s.connectMessage != "" && sess.Speed() != "" {
t.Write(config.Expand(s.connectMessage, sess.vars(false), nil))
}
+2 -1
View File
@@ -99,7 +99,8 @@ func headerEnv(h map[string]string, trust bool) []string {
"DMODEM_CHANNEL": "MODEM_CHANNEL", "DMODEM_PROFILE": "MODEM_PROFILE",
"DMODEM_RATE": "MODEM_RATE", "DMODEM_CALLERID": "MODEM_CALLERID",
"DMODEM_DIALED": "MODEM_DIALED", "DMODEM_CONNECTED": "MODEM_EPOCH",
"DMODEM_PEER": "MODEM_PEER",
"DMODEM_PEER": "MODEM_PEER", "DMODEM_MODULATION": "MODEM_MODULATION",
"DMODEM_PROTOCOL": "MODEM_PROTOCOL", "DMODEM_COMPRESSION": "MODEM_COMPRESSION",
}
var env []string
for d, m := range call {
+98 -8
View File
@@ -26,6 +26,12 @@ type session struct {
TxRate string `json:"tx_rate"`
RxRate string `json:"rx_rate"`
Channel string `json:"channel"`
// the modulation, error correction and compression of the
// connection, as app_dmodem's DMODEM_MODULATION, DMODEM_PROTOCOL and
// DMODEM_COMPRESSION give them (V90, LAPM, V42bis); "" if not told
Modulation string `json:"modulation"`
Protocol string `json:"protocol"`
Compression string `json:"compression"`
// the address the call came from by VoIP (the SIP peer's: app_dmodem's
// DMODEM_PEER), "" if not told
Peer string `json:"peer"`
@@ -55,16 +61,19 @@ type session struct {
// newSession from app_dmodem's environment (DMODEM_RATE "tx/rx",
// DMODEM_CALLERID, DMODEM_DIALED, DMODEM_CHANNEL, DMODEM_PROFILE,
// DMODEM_PEER), what the
// command line overrides of it
// DMODEM_PEER, DMODEM_MODULATION, DMODEM_PROTOCOL, DMODEM_COMPRESSION),
// what the command line overrides of it
func newSession(rate, dialed, callerID string, now time.Time) *session {
s := &session{
Dialed: dialed,
CallerID: callerID,
Channel: os.Getenv("DMODEM_CHANNEL"),
Peer: os.Getenv("DMODEM_PEER"),
Profile: os.Getenv("DMODEM_PROFILE"),
Connected: now,
Dialed: dialed,
CallerID: callerID,
Channel: os.Getenv("DMODEM_CHANNEL"),
Peer: os.Getenv("DMODEM_PEER"),
Profile: os.Getenv("DMODEM_PROFILE"),
Modulation: os.Getenv("DMODEM_MODULATION"),
Protocol: os.Getenv("DMODEM_PROTOCOL"),
Compression: os.Getenv("DMODEM_COMPRESSION"),
Connected: now,
}
// what an upstream menu found the terminal to be
s.Terminal = os.Getenv("DMODEM_LOGIN_UPSTREAM_TERMINAL")
@@ -103,6 +112,82 @@ func (s *session) Speed() string {
return fmt.Sprintf("%d bit/s down, %d bit/s up", tx, rx)
}
// modulationName: a modulation as app_dmodem names it (the pump names
// of AT+MS: V34, V90, V32bis, K56Flex, Bell103) in the form persons read
// (V.34, V.90, V.32bis, K56flex, Bell 103); a name already in that form,
// or one it does not know, as it is
func modulationName(m string) string {
switch m {
case "K56Flex":
return "K56flex"
case "VFC":
return "V.FC"
}
if rest, ok := strings.CutPrefix(m, "Bell"); ok && rest != "" && rest[0] >= '0' && rest[0] <= '9' {
return "Bell " + rest
}
if len(m) > 1 && m[0] == 'V' && m[1] >= '0' && m[1] <= '9' {
return "V." + m[1:]
}
return m
}
// protocolName: the error correction (LAPM, MNP, X.75...) for persons
// to read; "" for none (NONE) or not known
func protocolName(p string) string {
if strings.EqualFold(p, "NONE") {
return ""
}
return p
}
// compressionName: the compression (V42bis, V44, MNP5...) for persons
// to read (V.42bis, V.44, MNP5); "" for none (NONE) or not known
func compressionName(c string) string {
switch {
case strings.EqualFold(c, "NONE"):
return ""
case len(c) > 1 && c[0] == 'V' && c[1] >= '0' && c[1] <= '9':
return "V." + c[1:]
}
return c
}
// Link: the error correction and the compression as CONNECT shows them,
// "LAPM/V.42bis", "MNP/MNP5" or "LAPM"; "" without error correction or
// when it is not known
func (s *session) Link() string {
p := protocolName(s.Protocol)
if p == "" {
return ""
}
if c := compressionName(s.Compression); c != "" {
return p + "/" + c
}
return p
}
// Connection: the connect rate with the modulation and the link, for
// the caller to read: "33600 bit/s (V.34, LAPM/V.42bis)"; the rate alone
// ({speed}) when neither is known; "" when the rate is not known
func (s *session) Connection() string {
speed := s.Speed()
if speed == "" {
return ""
}
var parts []string
if m := modulationName(s.Modulation); m != "" {
parts = append(parts, m)
}
if l := s.Link(); l != "" {
parts = append(parts, l)
}
if len(parts) == 0 {
return speed
}
return speed + " (" + strings.Join(parts, ", ") + ")"
}
// vars: the placeholders of templates and the environment, by name
func (s *session) vars(withPassword bool) map[string]string {
v := map[string]string{
@@ -115,6 +200,11 @@ func (s *session) vars(withPassword bool) map[string]string {
"tx_rate": s.TxRate,
"rx_rate": s.RxRate,
"speed": s.Speed(),
"modulation": modulationName(s.Modulation),
"protocol": protocolName(s.Protocol),
"compression": compressionName(s.Compression),
"link": s.Link(),
"connection": s.Connection(),
"channel": s.Channel,
"peer": s.Peer,
"profile": s.Profile,
+1 -1
View File
@@ -128,7 +128,7 @@ func loadSettings(path string) (*settings, error) {
s.loginPrompt = config.Unescape(g.Get("login_prompt", `\r\nlogin: `))
s.passwordPrompt = config.Unescape(g.Get("password_prompt", "Password: "))
s.welcome = config.Unescape(g.Get("welcome", `\r\nWelcome, {user}.\r\n`))
s.connectMessage = config.Unescape(g.Get("connect_message", `\r\nConnected at {speed}.\r\n`))
s.connectMessage = config.Unescape(g.Get("connect_message", `\r\nConnected at {connection}.\r\n`))
s.motd = config.Unescape(g.Get("motd", ""))
s.motdFile = g.Get("motd_file", "")
s.goodbye = config.Unescape(g.Get("goodbye", `\r\nGoodbye.\r\n`))
+1 -1
View File
@@ -20,7 +20,7 @@ var setupDescs = map[string]string{
"general.banner_file": "A file shown instead of the banner (it may hold ANSI colors). Read at every call.",
"general.login_prompt": "The prompt that asks the caller for their user name.",
"general.password_prompt": "The prompt that asks the caller for their password.",
"general.connect_message": "Shown after the banner when the connect rate is known: {speed} is the rate. \"\" shows nothing.",
"general.connect_message": "Shown after the banner when the connect rate is known: {connection} is the rate, the modulation and the error correction; {speed} is the rate only. \"\" shows nothing.",
"general.welcome": "Shown once a caller has logged in, before the message of the day. {user}, {date} and the other placeholders work here.",
"general.motd": "The message of the day: shown after the welcome, before the menu.",
"general.motd_file": "A file shown after motd as part of the message of the day, read at every login.",
+41 -6
View File
@@ -36,6 +36,37 @@ func TestSpeed(t *testing.T) {
}
}
// TestConnection: {modulation}, {protocol}, {compression}, {link} and
// {connection} from app_dmodem's names
func TestConnection(t *testing.T) {
for _, c := range []struct {
rate, mod, proto, comp string
modulation, link, connection string
}{
{"33600/33600", "V34", "LAPM", "V42bis", "V.34", "LAPM/V.42bis", "33600 bit/s (V.34, LAPM/V.42bis)"},
{"50666/31200", "V90", "LAPM", "V44", "V.90", "LAPM/V.44", "50666 bit/s down, 31200 bit/s up (V.90, LAPM/V.44)"},
{"52000/31200", "K56Flex", "LAPM", "NONE", "K56flex", "LAPM", "52000 bit/s down, 31200 bit/s up (K56flex, LAPM)"},
{"14400/14400", "V32bis", "MNP", "MNP5", "V.32bis", "MNP/MNP5", "14400 bit/s (V.32bis, MNP/MNP5)"},
{"300/300", "Bell103", "NONE", "NONE", "Bell 103", "", "300 bit/s (Bell 103)"},
{"28800/28800", "", "LAPM", "V42bis", "", "LAPM/V.42bis", "28800 bit/s (LAPM/V.42bis)"},
// a menu's header: already the names for persons
{"33600/33600", "V.34", "LAPM", "V.42bis", "V.34", "LAPM/V.42bis", "33600 bit/s (V.34, LAPM/V.42bis)"},
// not told (a getty): the rate alone, as before
{"33600/33600", "", "", "", "", "", "33600 bit/s"},
{"", "V34", "LAPM", "V42bis", "V.34", "LAPM/V.42bis", ""},
} {
s := newSession(c.rate, "", "", time.Now())
s.Modulation, s.Protocol, s.Compression = c.mod, c.proto, c.comp
v := s.vars(false)
if v["modulation"] != c.modulation || v["link"] != c.link || v["connection"] != c.connection {
t.Errorf("%+v: modulation %q, link %q, connection %q", c, v["modulation"], v["link"], v["connection"])
}
if env := strings.Join(s.environ(false), "\n") + "\n"; !strings.Contains(env, "MODEM_CONNECTION="+c.connection+"\n") {
t.Errorf("%+v: no MODEM_CONNECTION in\n%s", c, env)
}
}
}
// the connect rate after the banner, before the login prompt
func TestConnectMessage(t *testing.T) {
dir := t.TempDir()
@@ -50,16 +81,20 @@ func TestConnectMessage(t *testing.T) {
os.WriteFile(p, []byte(fmt.Sprintf("[general]\nlog = none\nbanner = \"Test BBS\\r\\n\"\n%s\n[file]\npath = %s\n[item i]\ncommand = true\n", extra, users)), 0o600)
return p
}
link := []string{"DMODEM_MODULATION=V90", "DMODEM_PROTOCOL=LAPM", "DMODEM_COMPRESSION=V42bis"}
for _, c := range []struct {
conf, rate, want string
env []string
}{
{conf(""), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nConnected at 33600 bit/s.\r\n\r\nlogin: "},
{conf(""), "DMODEM_RATE=50666/31200", "Connected at 50666 bit/s down, 31200 bit/s up.\r\n"},
{conf(""), "DMODEM_RATE=", "Test BBS\r\n\r\nlogin: "},
{conf(`connect_message = "CONNECT {tx_rate}\r\n"`), "DMODEM_RATE=26400/24000", "Test BBS\r\nCONNECT 26400\r\n\r\nlogin: "},
{conf(`connect_message = ""`), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nlogin: "},
{conf(""), "DMODEM_RATE=50666/31200", "Test BBS\r\n\r\nConnected at 50666 bit/s down, 31200 bit/s up (V.90, LAPM/V.42bis).\r\n\r\nlogin: ", link},
{conf(`connect_message = "CONNECT {tx_rate}/{protocol}/{compression} {modulation}\r\n"`), "DMODEM_RATE=50666/31200", "Test BBS\r\nCONNECT 50666/LAPM/V.42bis V.90\r\n\r\nlogin: ", link},
{conf(""), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nConnected at 33600 bit/s.\r\n\r\nlogin: ", nil},
{conf(""), "DMODEM_RATE=50666/31200", "Connected at 50666 bit/s down, 31200 bit/s up.\r\n", nil},
{conf(""), "DMODEM_RATE=", "Test BBS\r\n\r\nlogin: ", nil},
{conf(`connect_message = "CONNECT {tx_rate}\r\n"`), "DMODEM_RATE=26400/24000", "Test BBS\r\nCONNECT 26400\r\n\r\nlogin: ", nil},
{conf(`connect_message = ""`), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nlogin: ", nil},
} {
cl, cmd := callAs(t, bin, c.conf, c.rate)
cl, cmd := callAs(t, bin, c.conf, append([]string{c.rate}, c.env...)...)
got := cl.expect("login: ")
if !strings.Contains(got, c.want) {
t.Errorf("%s: %q, want %q in it", c.rate, got, c.want)
+38 -11
View File
@@ -73,22 +73,45 @@ screen ([the sysop's setup](setup.md)).
Immediately after the banner, before the login prompt, dmodem-login tells
the caller the connect rate of the modems, as BBSs did:
the caller the connect rate, the modulation and the error correction of
the modems, as BBSs did:
```
Connected at 33600 bit/s.
Connected at 50666 bit/s down, 31200 bit/s up.
Connected at 33600 bit/s (V.34, LAPM/V.42bis).
Connected at 50666 bit/s down, 31200 bit/s up (V.90, LAPM/V.44).
Connected at 2400 bit/s (V.22bis).
```
The second line is for a V.90 call, with a different rate in each
direction ("down" is to the caller). `[general] connect_message`
(`"\r\nConnected at {speed}.\r\n"`) is the text. `{speed}` is the rate
in this format. It also operates in the other texts (the welcome, the
message of the day, the prompt). If the rate is not known (no
`DMODEM_RATE` and no `-rate`), dmodem-login does not show the message.
`connect_message = ""` disables the message. `{baud}`, `{tx_rate}` and
`{rx_rate}` are only the numbers. For example, use `connect_message =
"CONNECT {baud}\r\n"` to show the same words as a modem.
direction ("down" is to the caller). The third line is for a call
without error correction. `[general] connect_message`
(`"\r\nConnected at {connection}.\r\n"`) is the text. `{connection}`
is the rate, the modulation and the link in this format. These
placeholders also operate in the other texts (the welcome, the message
of the day, the prompt):
| placeholder | example | value |
|---|---|---|
| `{connection}` | `33600 bit/s (V.34, LAPM/V.42bis)` | the rate, then the modulation and the link in parentheses |
| `{speed}` | `33600 bit/s` | the rate only |
| `{modulation}` | `V.34` | the modulation: `V.92`, `V.90`, `K56flex`, `V.34`, `V.32bis`, `Bell 103` and so on |
| `{link}` | `LAPM/V.42bis` | the error correction and the compression, as `CONNECT` shows them |
| `{protocol}` | `LAPM` | the error correction: `LAPM`, `MNP` and so on |
| `{compression}` | `V.42bis` | the compression: `V.42bis`, `V.44`, `MNP5` and so on |
D-Modem gives the modulation, the error correction and the compression
in `DMODEM_MODULATION`, `DMODEM_PROTOCOL` and `DMODEM_COMPRESSION`
(D-Modem `V90`, `LAPM` and `V42bis`). dmodem-login changes these names
to the names in the table. If D-Modem does not give them (for example,
an older D-Modem or a getty), `{connection}` is the same as `{speed}`.
A call without error correction or without compression has an empty
`{protocol}` or `{compression}`.
If the rate is not known (no `DMODEM_RATE` and no `-rate`), dmodem-login
does not show the message. `connect_message = ""` disables the message.
`{baud}`, `{tx_rate}` and `{rx_rate}` are only the numbers. For example,
use `connect_message = "CONNECT {baud}/{link}\r\n"` to show the same
words as a modem.
## The caller's terminal
@@ -456,6 +479,10 @@ back to the menu.
| `{baud}` | `MODEM_BAUD` | the connect rate to the caller, bit/s |
| `{speed}` | `MODEM_SPEED` | the connect rate in a format for persons to read: `33600 bit/s`, or `50666 bit/s down, 31200 bit/s up`. Empty if not known |
| `{rate}`, `{tx_rate}`, `{rx_rate}` | `MODEM_RATE`, `MODEM_TX_RATE`, `MODEM_RX_RATE` | both rates |
| `{connection}` | `MODEM_CONNECTION` | the connect rate with the modulation and the link: `33600 bit/s (V.34, LAPM/V.42bis)`. Empty if the rate is not known |
| `{modulation}` | `MODEM_MODULATION` | the modulation (`DMODEM_MODULATION` of app_dmodem): `V.90`, `K56flex`, `V.34`. Empty if not known |
| `{protocol}`, `{compression}` | `MODEM_PROTOCOL`, `MODEM_COMPRESSION` | the error correction (`LAPM`, `MNP`) and the compression (`V.42bis`, `V.44`, `MNP5`). Empty for none or if not known |
| `{link}` | `MODEM_LINK` | the two as `CONNECT` shows them: `LAPM/V.42bis`. Empty without error correction |
| `{date}`, `{time}` | `MODEM_DATE`, `MODEM_TIME` | the date and time of the connection |
| `{datetime}`, `{epoch}` | `MODEM_DATETIME`, `MODEM_EPOCH` | the same, RFC 3339 and Unix time |
| `{channel}`, `{profile}` | `MODEM_CHANNEL`, `MODEM_PROFILE` | the channel and profile of app_dmodem |
+1 -1
View File
@@ -43,7 +43,7 @@ The login: the log, the backends, what the caller sees, the time limits.
| `banner_file` | `/etc/asterisk/dmodem-login.banner` | what the caller sees first (or a file of it, which may have ANSI's colors), then the prompts of the login. |
| `login_prompt` | `\r\nlogin: ` | what the caller sees first (or a file of it, which may have ANSI's colors), then the prompts of the login. |
| `password_prompt` | `Password: ` | what the caller sees first (or a file of it, which may have ANSI's colors), then the prompts of the login. |
| `connect_message` | `\r\nConnected at {speed}.\r\n` | after the banner, before the login prompt: the connect rate ({speed}: "33600 bit/s", or "50666 bit/s down, 31200 bit/s up"); left out when it is not known; "" for none. |
| `connect_message` | `\r\nConnected at {connection}.\r\n` | after the banner, before the login prompt: the connect rate, the modulation and the error correction ({connection}: "33600 bit/s (V.34, LAPM/V.42bis)"; {speed}: the rate only, "33600 bit/s", or "50666 bit/s down, 31200 bit/s up"); left out when the rate is not known; "" for none. |
| `welcome` | `\r\nHello {user}, on {date} at {time}.\r\n` | after a login, before the motd ({placeholders}; on the full-screen menu, at the top of its window) |
| `motd` | `\r\nThe line is down for maintenance on Sunday.\r\n` | the message of the day, after the welcome and before the menu: motd, then the file (read at each login), {placeholders} in both. |
| `motd_file` | `/etc/motd` | the message of the day, after the welcome and before the menu: motd, then the file (read at each login), {placeholders} in both. |
+5
View File
@@ -54,6 +54,11 @@
directions, different rates, and an unknown rate. It also tests the
connect rate on calls: after the banner, removed when there is no
rate, its own text, and disabled.
- It tests the modulation, the error correction and the compression as
`{modulation}`, `{link}` and `{connection}`: the names of D-Modem, the
names for persons, no error correction and no names. It also tests the
connect message on calls with `DMODEM_MODULATION`, `DMODEM_PROTOCOL`
and `DMODEM_COMPRESSION`.
- It tests the uid, root and group rules of the system backend, with a
replacement for PAM.
+1 -1
View File
@@ -27,7 +27,7 @@ auth = file
banner = "\r\nWelcome to D-Modem on FreePBX.\r\n"
login_prompt = "\r\nlogin: "
password_prompt = "Password: "
connect_message = "\r\nConnected at {speed}.\r\n"
connect_message = "\r\nConnected at {connection}.\r\n"
welcome = "\r\nHello {user}, on {date} at {time}.\r\n"
;motd = "\r\nThe line is down for maintenance on Sunday.\r\n"
;motd_file = /etc/dmodem-login/motd
+5 -4
View File
@@ -61,10 +61,11 @@ banner = "\r\nWelcome to D-Modem.\r\n"
;banner_file = /etc/asterisk/dmodem-login.banner
login_prompt = "\r\nlogin: "
password_prompt = "Password: "
; after the banner, before the login prompt: the connect rate ({speed}:
; "33600 bit/s", or "50666 bit/s down, 31200 bit/s up"); left out when it
; is not known; "" for none
connect_message = "\r\nConnected at {speed}.\r\n"
; after the banner, before the login prompt: the connect rate, the
; modulation and the error correction ({connection}: "33600 bit/s (V.34,
; LAPM/V.42bis)"; {speed}: the rate only, "33600 bit/s", or "50666 bit/s
; down, 31200 bit/s up"); left out when the rate is not known; "" for none
connect_message = "\r\nConnected at {connection}.\r\n"
; after a login, before the motd ({placeholders}; on the full-screen menu,
; at the top of its window)
welcome = "\r\nHello {user}, on {date} at {time}.\r\n"