App-Phoebe
view release on metacpan or search on metacpan
script/phoebe view on Meta::CPAN
certificates for different hosts, you have to specify them all on the command
line. Generally speaking, use C<--host> to specifiy one or more hosts, followed
by both C<--cert_file> and C<--key_file> to specifiy the certificate and key to
use for the hosts.
For example:
phoebe --host=transjovian.org \
--cert_file=/home/alex/phoebe/transjovian-cert.pem \
--key_file=/home/alex/phoebe/transjovian-key.pem \
--host=alexschroeder.ch \
--cert_file=/home/alex/phoebe/alexschroeder-cert.pem \
--key_file=/home/alex/phoebe/alexschroeder-key.pem
=head1 SEE ALSO
The Transjovian Council has a wiki space dedicated to Phoebe, and it includes a
section with more configuration examples. See L<gemini://transjovian.org/phoebe>
or L<https://transjovian.org:1965/phoebe>.
=head1 LICENSE
GNU Affero General Public License
=cut
use FindBin;
use lib "$FindBin::Bin/../lib";
use App::Phoebe qw($log $server host_regex handle_request get_ip_numbers);
use Modern::Perl '2018';
use File::Slurper qw(read_dir);
use Encode qw(decode);
use Encode::Locale;
use IO::Socket::SSL;
use Mojo::IOLoop;
use Getopt::Long;
use Pod::Text;
use utf8;
use B;
# Some of these need to be decoded (hostnames, pagenames).
GetOptions(
$server,
'help' => \&help,
'log_level=s' => sub { $log->level($_[1]), },
'log_file=s' => sub { $log->path($_[1]) },
'no_cert' => \&host_setup,
'cert_file=s' => \&host_setup,
'key_file=s' => \&host_setup,
'host=s@' => \&host_setup,
'port=i@' => \&host_setup,
'wiki_dir=s',
'wiki_space=s@' => \&utf8_list_item,
'wiki_token=s@' => \&utf8_list_item,
'wiki_page=s@' => \&utf8_list_item,
'wiki_main_page=s' => \&utf8_item,
'wiki_mime_type=s@',
'wiki_page_size_limit=i')
or die("Error in command line arguments\n");
sub utf8_list_item { my ($key, $value) = @_; push(@{$server->{$key}}, decode(locale => $value)) };
sub utf8_item { my ($key, $value) = @_; $server->{$key} = decode(locale => $value) };
{
# use a block so that these variables stay local
my ($cert_file, $key_file, @host, @port);
sub host_setup {
my ($opt, $val) = @_;
if ($opt eq 'host') {
push @host, map { decode(locale => $_) } $val;
return;
} elsif ($opt eq 'port') {
push @port, $val;
return;
} elsif ($opt eq 'no_cert') {
push @port, 1965 unless @port;
if (not @host and not $server->{host}->{'localhost'}) {
$server->{host}->{'localhost'} = 1;
$server->{port}->{'localhost'} = [@port];
}
for my $host (@host) {
$server->{host}->{$host} = 1;
push(@{$server->{port}->{$host}}, @port);
# no $server->{cert_file} and $server->{key_file}
}
@host = @port = ();
return;
}
die "$val does not exist\n" unless -f $val;
if ($opt eq 'cert_file') { $cert_file = $val }
elsif ($opt eq 'key_file') { $key_file = $val }
if ($cert_file and $key_file) {
push @port, 1965 unless @port;
if (not @host) {
$server->{host}->{'localhost'} = 1;
push(@{$server->{port}->{'localhost'}}, @port);
for my $port (@port) {
$server->{cert_file}->{"localhost:$port"} = $cert_file;
$server->{key_file}->{"localhost:$port"} = $key_file;
}
}
for my $host (@host) {
$server->{host}->{$host} = 1;
push(@{$server->{port}->{$host}}, @port);
for my $port (@port) {
$server->{cert_file}->{"$host:$port"} = $cert_file;
$server->{key_file}->{"$host:$port"} = $key_file;
}
}
$cert_file = $key_file = undef;
@host = @port = ();
}
}
# if, at the end, there is a left-over
if ($cert_file or $key_file) {
die "I must have both --key_file and --cert_file\n";
}
push @port, 1965 unless @port;
# let's see if we need to generate certificates
my $default_certs = 0;
# if, at the end, we have some hosts but no certs and keys
for my $host (@host) {
$default_certs = 1;
$server->{host}->{$host} = 1;
push(@{$server->{port}->{$host}}, @port);
for my $port (@port) {
( run in 0.761 second using v1.01-cache-2.11-cpan-ceb78f64989 )