1#!/usr/bin/perl
2# $File: //depot/libOurNet/BBS/script/bbscomd $ $Author: autrijus $
3# $Revision: #1 $ $Change: 3790 $ $DateTime: 2003/01/24 19:08:46 $
4
5$VERSION = '1.62_01';
6$REVISION = "rev$1\[\@$2\]"
7    if ('$Revision: #1 $ $Change: 3790 $' =~ /(\d+)[^\d]+(\d+)/);
8
9=head1 NAME
10
11bbscomd - OurNet BBS Remote Access Daemon
12
13=head1 SYNOPSIS
14
15B<bbscomd> S<[ B<-acdfgGhsx> ]> S<[ B<-b> I<addr> ]> S<[ B<-p>
16    I<port> ]> S<[ B<-u> I<key> ] >
17    S<[ B<-l> I<logfile> ]> S<[ B<-t> I<timeout> ]> S< I<backend>
18    [ I<argument>... ]>
19
20=head1 DESCRIPTION
21
22The bbscomd starts a I<OurNet::BBS::Server> daemon listening on
23the specified port (default 7979). Remote users could then start
24using the I<OurNet> backend or I<OurNet::BBS::Client> to connect
25like this:
26
27    use OurNet::BBS;
28    my $Remote_BBS = OurNet::BBS->new(OurNet => 'remote.org');
29
30If the C<-f> flag is specified, bbscomd will fork a new process
31to run as daemon. The C<-d> flag turns on debugging.
32
33The C<-u> specifies the pgp keyid or userid used in authorization.
34If C<-a> is supplied, the server will serve in the I<authenticated>
35mode with additional permission controls. Similarly, C<-c>
36disallows insecure cipher modes.
37
38The C<-g> flag allows server to assume C<guest> as the user ID on
39a failed Authentication (fallback to AUTH_NONE), with corresponding
40permissions.
41
42Similarly, the C<-G> flag allows the client to authenticate as
43B<ANY> user they wanted to; because of the security risk, this flag
44automatically specifies C<-b localhost> for you. Note that this does
45not assume the behaviour of C<-g>; you'll have to specify C<-gG>
46explicitly to turn on both settings.
47
48The C<-s> flag permits single-connection only. This is primary used
49for single-user situations.
50
51The C<-x> flag assumes default settings on Win32. It's not meant
52to be used on other platforms.
53
54If you don't want to bind all available IPs, specify one using
55the C<-b> flag.
56
57The C<-t> flag sets the C<connection-timeout> option to the Server
58object, which causes a child connection to terminate after an
59inactivity for I<timeout> seconds.
60
61If you want to keep a B<Net::Daemon> styled log file, specify
62the file name to C<-l>.
63
64Please refer to L<OurNet::BBS> modules for more information on
65usage.
66
67=head1 EXAMPLES
68
69Starting a typical MELIX daemon, require authentication, but allowing
70unprivileged guest access:
71
72    % bbscomd -acfg -u melix MELIX /home/melix 2997 350
73
74Starting a localhost-only bridge at port 8080 to another I<OurNet>
75node, with debugging output:
76
77    % bbscomd -d -b 127.0.0.1 -p 8080 OurNet localhost
78
79=cut
80
81use strict;
82use warnings;
83use Getopt::Std;
84use OurNet::BBS;
85use OurNet::BBS::Server;
86
87$|++;
88
89my %args;
90
91if (!@ARGV) {
92    die << ".";
93
94OurNet BBS Remote Access Daemon v$main::VERSION-$main::REVISION
95
96Usage: $0 [-acdfghx] [-b <addr>] [-p <port>] [-u <key>]
97       <backend> [ <argument>... ]
98
99Type '$0 -h' to see available argument and options.
100
101Copyright 2001-2002 by Autrijus Tang <autrijus\@autrijus.org>.
102
103This program is free software; you can redistribute it and/or
104modify it under the same terms as Perl itself.
105
106See <http://www.perl.com/perl/misc/Artistic.html>.
107
108.
109}
110
111getopts('acgGb:p:t:u:fdhsx', \%args);
112exec('perldoc', $0) if defined $args{h};
113
114my ($auth, $ciph, $port, $logfile, $timeout,
115    $key, $fork, $debug, $addr, $guest, $anyuser, $single)
116    = @{args}{qw/a c p l t u f d b g G s/};
117
118$guest = $guest ? 'guest' : undef;
119$guest = "*$guest" if $anyuser;
120$auth  = defined($auth) ? $guest ? 7 : 6 : 0;
121$ciph  = $key ? 6 : 2 if defined $ciph;
122$port  ||= 7979;
123
124if ($args{x}) {
125    @ARGV = (
126        'MELIX', -e 'c:/cygwin/home/melix'
127	    ? 'c:/cygwin/home/melix'
128	    : 'c:/program files/melix/home/melix'
129    );
130}
131
132no warnings 'once';
133
134$OurNet::BBS::DEBUG = $debug;
135$OurNet::BBS::Server::LocalAddr = $addr if defined $addr;
136%OurNet::BBS::Server::Options   = (
137    'logfile'		 => $logfile,
138    'connection-timeout' => $timeout,
139);
140
141if ($single) {
142    $OurNet::BBS::Server::Mode = 'single';
143}
144
145my $BBS = OurNet::BBS->new(@ARGV) or die "Cannot link to BBS: @ARGV\n";
146
147print "entering in debug mode, expect lots of outputs\n"
148    if $OurNet::BBS::DEBUG;
149
150my $pass = '';
151
152if ($key) {
153    require Term::ReadKey;
154    Term::ReadKey::ReadMode('noecho');
155    print "enter passphrase for <$key>: ";
156    $pass = scalar <STDIN>;
157    Term::ReadKey::ReadMode('restore');
158    print "\n";
159}
160
161if (!$fork or !fork()) {
162    print "BBSCOM Daemon starting at port $port...\n";
163
164    $BBS->daemonize($port, $key, $pass, $ciph, $auth, $guest)
165	or die "Failed to daemonize: $!\n";
166}
167
168__END__
169
170=head1 SEE ALSO
171
172L<OurNet::BBS>, L<RPC::PlServer>, L<Net::Daemon>
173
174=head1 AUTHORS
175
176Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
177
178=head1 COPYRIGHT
179
180Copyright 2001-2002 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
181
182This program is free software; you can redistribute it and/or
183modify it under the same terms as Perl itself.
184
185See L<http://www.perl.com/perl/misc/Artistic.html>
186
187=cut
188