#!/usr/bin/perl -w

$VERSION = '1.54';

=head1 NAME

bbscomd - OurNet BBS remote access daemon

=head1 SYNOPSIS

    % bbscomd [-d] [-f] [-u key [-a]] [-p port] <backend> <args>...

=head1 DESCRIPTION

The bbscomd starts a L<OurNet::BBS::Server> daemon listening on 
the specified port (default 7978). Remote users could then start
using L<OurNet::BBS::Client> to connect, e.g.:

    use OurNet::BBS;

    my $Remote_BBS = OurNet::BBS->new('OurNet', 'remote.org');

If the C<-f> flag is specified, bbscomd will fork a new process
to run as daemon. The C<-d> flag turns on debugging.

The C<-u> specified the pgp key used in authorization. If C<-a>
is supplied, the server will serve in 'authentication' mode 
with additional permission controls.

Please refer to L<OurNet::BBS> modules for more information on
usages.

=cut

use strict;
use OurNet::BBS;
use Getopt::Std;
use Term::ReadKey;

my %opt;
getopts('p:u:dfa', \%opt);

die "Usage: $0 [-d] [-f] [-p port] [-u key [-a]] <backend> <args>...\n" 
    unless @ARGV;

my $BBS = OurNet::BBS->new(@ARGV) 
    or die "Cannot link to BBS: @ARGV\n";

$OurNet::BBS::DEBUG = $OurNet::BBS::DEBUG = 1 if $opt{d};

my @args = ($opt{p} || 7978);

if ($opt{u}) {
    ReadMode('noecho');
    print "enter passphrase for $opt{u}: ";
    push @args, ($opt{u}, scalar <STDIN>);
    ReadMode('restore');
    print "\n";
}

if (!$opt{f} or !fork()) {
    warn "warning: no key specified, using insecure connection.\n"
	unless $opt{u};

    print "BBSCOM Daemon starting at port $args[0]...\n";

    $BBS->daemonize(@args, $opt{a})
	or die "Failed to daemonize: $!\n";
}

__END__

=head1 AUTHORS

Autrijus Tang E<lt>autrijus@autrijus.org>

=head1 COPYRIGHT

Copyright 2001 by Autrijus Tang E<lt>autrijus@autrijus.org>.

All rights reserved.  You can redistribute and/or modify
this module under the same terms as Perl itself.

=cut

