mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
confui: refuse an edit that puts one port on every address and an IP
With the chat's HTTPS services each on an IP of their own, a port on every address for another can't be listened on beside them. The editor now refuses such an edit at once (the old value put back, the reason shown) instead of only at save. A file already mixed can still be put right an edit at a time. The DNS server joins Internet services. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTuaG98f8wiWHbNhPo
This commit is contained in:
6 files changed
+100
-4
No files matched your search
+4
-1
@@ -176,7 +176,10 @@ which is their PPP link's far end.
|
||||
|
||||
One port can't be both on every address and on an IP of its own: with
|
||||
`https_address = 192.168.77.11:443` for one front end, give the others an
|
||||
IP of their own too (not `:443`). `bbs check` refuses the mix.
|
||||
IP of their own too (not `:443`). `bbs check` refuses the mix, and the
|
||||
configuration editor (`bbs config`, and the sysop's menu) won't take an
|
||||
edit that makes it: the old value is put back and the reason shown. The
|
||||
editor has the DNS server under Internet services, "DNS for callers".
|
||||
|
||||
## Who may use it
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package confui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/confedit"
|
||||
"github.com/D-Modem/bbs/internal/forum"
|
||||
"github.com/D-Modem/bbs/internal/vhost"
|
||||
"github.com/D-Modem/bbs/internal/view"
|
||||
)
|
||||
|
||||
@@ -141,17 +143,42 @@ func (e *Editor) field(s confedit.Section, key string, label ...string) item {
|
||||
if it.Kind == view.EntryChoice && nv != "" && !contains(it.Choices, nv) {
|
||||
return fmt.Errorf("%s: one of %s", it.Label, strings.Join(it.Choices, ", "))
|
||||
}
|
||||
old, had := e.doc.Get(s, key)
|
||||
wasMixed := e.refuseMixed() != nil
|
||||
if nv == "" {
|
||||
e.doc.Unset(s, key)
|
||||
} else if err := e.doc.Set(s, key, nv); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := e.refuseMixed(); err != nil && !wasMixed {
|
||||
// put it back: the BBS could not listen on both
|
||||
if had {
|
||||
e.doc.Set(s, key, old)
|
||||
} else {
|
||||
e.doc.Unset(s, key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
e.checkDoc()
|
||||
return nil
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
||||
// refuseMixed is the error, if the file now has one port both on every
|
||||
// address and on an IP of its own (the chat's HTTPS services: an IP each,
|
||||
// or all on one), for the edit that made it to be refused. A file that
|
||||
// had it already is left to be put right an edit at a time.
|
||||
func (e *Editor) refuseMixed() error {
|
||||
if e.Tools.Check == nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := e.Tools.Check(e.doc.Bytes()); errors.Is(err, vhost.ErrMixedAddresses) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// isBool is whether a key is a yes or no: its default and examples are all
|
||||
// yes, no or nothing, and one is yes or no.
|
||||
func isBool(x *confedit.Key) bool {
|
||||
|
||||
@@ -319,6 +319,7 @@ func (e *Editor) servicesMenu() page {
|
||||
e.single("Gopher", "gopher"),
|
||||
e.single("Gemini", "gemini"),
|
||||
e.single("FTP", "ftp"),
|
||||
e.single("DNS for callers", "dns"),
|
||||
menu("News (NNTP)", e.onOff(sec("nntp")), func() error { return e.show(e.newsPage()) }),
|
||||
menu("Web: API, forum, image boards", e.onOff(sec("http")), func() error { return e.show(e.webPage()) }),
|
||||
menu("Certificates (ACME)", e.onOff(sec("acme")), func() error { return e.show(e.acmePage()) }),
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package confui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
bbssec "github.com/D-Modem/bbs"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/confedit"
|
||||
"github.com/D-Modem/bbs/internal/vhost"
|
||||
)
|
||||
|
||||
// mixedCheck is the BBS's check, as far as it goes here: [msn] on an IP of
|
||||
// its own and [ymsg] on every address of the same port can't both listen.
|
||||
func mixedCheck(data []byte) ([]string, error) {
|
||||
s := string(data)
|
||||
if strings.Contains(s, "https_address = 192.168.77.11:443") && strings.Contains(s, "https_address = :443") {
|
||||
return nil, fmt.Errorf("%w: port 443 is on every address for [ymsg] and on 192.168.77.11:443 for [msn]",
|
||||
vhost.ErrMixedAddresses)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TestRefuseMixedAddresses: with MSN's HTTPS server on an IP of its own,
|
||||
// putting Yahoo!'s on every address of the same port is refused and put
|
||||
// back; on an IP of its own it is taken.
|
||||
func TestRefuseMixedAddresses(t *testing.T) {
|
||||
doc, err := confedit.Parse([]byte("[msn]\nhttps_address = 192.168.77.11:443\n[ymsg]\nhttps_address = 192.168.77.12:443\n"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
orig, _ := confedit.Parse(doc.Bytes())
|
||||
e := &Editor{UI: &script{t: t}, Tools: bbs.ConfigTools{Check: mixedCheck}, doc: doc, orig: orig,
|
||||
cat: confedit.NewCatalog(bbssec.Sample)}
|
||||
it := e.field(sec("ymsg"), "https_address")
|
||||
err = it.set(":443")
|
||||
if err == nil || !strings.Contains(err.Error(), "on every address") {
|
||||
t.Fatalf("every address beside an IP of its own: %v", err)
|
||||
}
|
||||
if v, _ := e.doc.Get(sec("ymsg"), "https_address"); v != "192.168.77.12:443" {
|
||||
t.Errorf("not put back: %q", v)
|
||||
}
|
||||
if err := it.set("192.168.77.13:443"); err != nil {
|
||||
t.Fatalf("an IP of its own: %v", err)
|
||||
}
|
||||
if v, _ := e.doc.Get(sec("ymsg"), "https_address"); v != "192.168.77.13:443" {
|
||||
t.Errorf("kept %q", v)
|
||||
}
|
||||
// a file mixed already is put right an edit at a time
|
||||
e.doc.Set(sec("ymsg"), "https_address", ":443")
|
||||
if err := e.field(sec("ymsg"), "max_clients").set("100"); err != nil {
|
||||
t.Errorf("an edit beside a mix already there: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -320,9 +320,13 @@ func (c *Config) SharedPorts() ([]SharedPort, error) {
|
||||
for _, q := range out[i+1:] {
|
||||
qh, qp, _ := net.SplitHostPort(vhost.Normal(q.Address))
|
||||
if pp == qp && ph != qh && (ph == "" || qh == "") {
|
||||
return nil, fmt.Errorf("port %s is on every address for [%s] and on %s for [%s]: give each "+
|
||||
"front end an IP of its own (all of them), or the same address", pp, strings.Join(p.Members, "], ["),
|
||||
q.Address, strings.Join(q.Members, "], ["))
|
||||
all, own := p, q
|
||||
if qh == "" {
|
||||
all, own = q, p
|
||||
}
|
||||
return nil, fmt.Errorf("%w: port %s is on every address for [%s] and on %s for [%s]: give each "+
|
||||
"front end an IP of its own (all of them), or the same address", vhost.ErrMixedAddresses, pp,
|
||||
strings.Join(all.Members, "], ["), own.Address, strings.Join(own.Members, "], ["))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,6 +311,12 @@ func (l *connListener) Close() error {
|
||||
|
||||
func (l *connListener) Addr() net.Addr { return &net.TCPAddr{} }
|
||||
|
||||
// ErrMixedAddresses is a port on every address for one front end and on
|
||||
// an IP of its own for another, which can't both be listened on: each
|
||||
// HTTPS service on an IP of its own (a certificate of its own each) means
|
||||
// all of them on one.
|
||||
var ErrMixedAddresses = errors.New("a port on every address and on an IP of its own")
|
||||
|
||||
// claimed are the addresses a Port serves, which the front ends leave
|
||||
// alone.
|
||||
var (
|
||||
|
||||
Reference in new issue
Block a user