user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 5/6] daemon: allow listening on well-known ports based on protocol
  2022-08-01 21:24  6% [PATCH 0/6] flesh out more -netd funcionality Eric Wong
@ 2022-08-01 21:24  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-08-01 21:24 UTC (permalink / raw)
  To: meta

This allows admins to use "-l nntp://0.0.0.0/" to bind on port 119
without specifying ":119" on the CLI.
---
 lib/PublicInbox/Daemon.pm | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 3264bb6c..ead5afc0 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -35,6 +35,9 @@ my ($uid, $gid);
 my ($default_cert, $default_key);
 my %KNOWN_TLS = (443 => 'https', 563 => 'nntps', 993 => 'imaps', 995 =>'pop3s');
 my %KNOWN_STARTTLS = (110 => 'pop3', 119 => 'nntp', 143 => 'imap');
+my %SCHEME2PORT = map { $KNOWN_TLS{$_} => $_ + 0 } keys %KNOWN_TLS;
+for (keys %KNOWN_STARTTLS) { $SCHEME2PORT{$KNOWN_STARTTLS{$_}} = $_ + 0 }
+$SCHEME2PORT{http} = 80;
 
 sub listener_opt ($) {
 	my ($str) = @_; # opt1=val1,opt2=val2 (opt may repeat for multi-value)
@@ -103,9 +106,10 @@ sub open_log_path ($$) { # my ($fh, $path) = @_; # $_[0] is modified
 	do_chown($_[1]);
 }
 
-sub load_mod ($;$) {
-	my ($scheme, $opt) = @_;
+sub load_mod ($;$$) {
+	my ($scheme, $opt, $addr) = @_;
 	my $modc = "PublicInbox::\U$scheme";
+	$modc =~ s/S\z//;
 	my $mod = $modc.'D';
 	eval "require $mod"; # IMAPD|HTTPD|NNTPD|POP3D
 	die $@ if $@;
@@ -200,11 +204,17 @@ EOF
 	foreach my $l (@cfg_listen) {
 		my $orig = $l;
 		my $scheme = '';
-		if ($l =~ s!\A([^:]+)://!!) {
-			$scheme = $1;
-		} elsif ($l =~ /\A(?:\[[^\]]+\]|[^:]+):([0-9])+/) {
-			my $s = $KNOWN_TLS{$1} // $KNOWN_STARTTLS{$1};
-			$scheme = $s if defined $s;
+		my $port;
+		if ($l =~ s!\A([^:]+)://!!) { $scheme = $1 }
+		if ($l =~ /\A(?:\[[^\]]+\]|[^:]+):([0-9]+)/) {
+			$port = $1 + 0;
+			my $s = $KNOWN_TLS{$port} // $KNOWN_STARTTLS{$port};
+			$scheme //= $s if defined $s;
+		} elsif (index($l, '/') != 0) { # unix socket
+			$port //= $SCHEME2PORT{$scheme} if $scheme;
+			$port // die "no port in listen=$l\n";
+			$l =~ s!\A([^/]+)!$1:$port! or
+				die "unable to add port=$port to $l\n";
 		}
 		my $opt; # non-TLS options
 		if ($l =~ s!/?\?(.+)\z!!) {
@@ -215,8 +225,8 @@ EOF
 		} elsif ($scheme =~ /\A(?:https|imaps|nntps|pop3s)\z/) {
 			die "$orig specified w/o cert=\n";
 		}
-		$scheme =~ /\A(http|imap|nntp|pop3)/ and
-			$xnetd->{$l} = load_mod($1, $opt);
+		$scheme =~ /\A(?:http|imap|nntp|pop3)/ and
+			$xnetd->{$l} = load_mod($scheme, $opt, $l);
 
 		next if $listener_names->{$l}; # already inherited
 		my (%o, $sock_pkg);
@@ -263,7 +273,7 @@ EOF
 	for my $sockname (@inherited_names) {
 		$sockname =~ /:([0-9]+)\z/ or next;
 		if (my $scheme = $KNOWN_TLS{$1}) {
-			$xnetd->{$sockname} = load_mod(substr($scheme, 0, -1));
+			$xnetd->{$sockname} = load_mod($scheme);
 			$tls_opt{"$scheme://$sockname"} ||= accept_tls_opt('');
 		} elsif (($scheme = $KNOWN_STARTTLS{$1})) {
 			$xnetd->{$sockname} = load_mod($scheme);

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/6] flesh out more -netd funcionality
@ 2022-08-01 21:24  6% Eric Wong
  2022-08-01 21:24  7% ` [PATCH 5/6] daemon: allow listening on well-known ports based on protocol Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-08-01 21:24 UTC (permalink / raw)
  To: meta

These changes will allow public-inbox-netd to host multiple,
completely-unrelated .psgi apps within the same process via
psgi= as a per-listener option.  Having separate stdout/stderr
facsimiles is also supported via err= and out= keys (HTTP(S)
only has err= for $env->{'psgi.errors'}).

(public-inbox-{nntp,imap,pop3,http}d can actually do all that
-netd can do, too, the only difference is -netd has no default
port/protocol).

Further optimizations (PublicInbox::Config object sharing)
and reload improvements (TLS cert reload on SIGHUP) are on
the way...

Eric Wong (6):
  httpd: make internals slightly more generic
  daemon: support per-listener env, .psgi, out, err
  daemon: require absolute cert/key paths with --daemonize
  daemon: add diagnostics about inherited/bound listeners
  daemon: allow listening on well-known ports based on protocol
  daemon: share FDs for identical log paths

 Documentation/public-inbox-daemon.pod |  51 ++++++--
 Documentation/public-inbox-netd.pod   |  34 ++++--
 MANIFEST                              |   1 +
 lib/PublicInbox/Daemon.pm             | 168 +++++++++++++++++---------
 lib/PublicInbox/HTTP.pm               |  10 +-
 lib/PublicInbox/HTTPD.pm              |  60 +++++----
 lib/PublicInbox/IMAPD.pm              |   3 +-
 lib/PublicInbox/NNTPD.pm              |  25 ++--
 lib/PublicInbox/POP3D.pm              |  36 +++---
 t/alt.psgi                            |  17 +++
 t/httpd-corner.psgi                   |   8 +-
 t/httpd-corner.t                      |  39 +++++-
 12 files changed, 304 insertions(+), 148 deletions(-)
 create mode 100644 t/alt.psgi

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-08-01 21:24  6% [PATCH 0/6] flesh out more -netd funcionality Eric Wong
2022-08-01 21:24  7% ` [PATCH 5/6] daemon: allow listening on well-known ports based on protocol Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).