version 1.6, 2010/12/14 20:32:49
|
version 1.10, 2010/12/17 20:15:24
|
Line 13 BEGIN {
|
Line 13 BEGIN {
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; |
delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; |
$ENV{PATH} = "/bin:/usr/bin"; |
$ENV{PATH} = "/bin:/usr/bin"; |
$|++; |
$|++; |
$SIG{__DIE__} = sub { require Carp; Carp::confess(@_); } |
# $SIG{__DIE__} = sub { require Carp; Carp::confess(@_); } |
} |
} |
|
|
use strict; |
use strict; |
Line 36 my %cfg = &fetchConfig( );
|
Line 36 my %cfg = &fetchConfig( );
|
my $EOL = "\015\012"; |
my $EOL = "\015\012"; |
|
|
## |
## |
## These will be moved in to a config file |
## These are read in from the config file |
## |
## |
my $BBS_NODE = 0; |
my $BBS_NODE = 0; |
my $pidFile = $cfg{'pidfile'} || "/tmp/telnetbbs.pid"; |
my $pidFile = $cfg{'pidfile'} || "/tmp/telnetbbs.pid"; |
Line 44 my $port = $opts{'port'} || $c
|
Line 44 my $port = $opts{'port'} || $c
|
my $DISPLAY = $cfg{'display'} || ":0.0"; |
my $DISPLAY = $cfg{'display'} || ":0.0"; |
my $BBS_NAME = $cfg{'bbs_name'} || "Hell's Dominion BBS"; |
my $BBS_NAME = $cfg{'bbs_name'} || "Hell's Dominion BBS"; |
my $DBCONF = $cfg{'dosbox_cfg'} || "/tmp/dosbox-__NODE__.conf"; |
my $DBCONF = $cfg{'dosbox_cfg'} || "/tmp/dosbox-__NODE__.conf"; |
my $BBS_CMD = $cfg{'bbs_cmd'} || "DISPLAY=$DISPLAY /usr/bin/dosbox -conf "; |
my $BBS_CMD = $cfg{'bbs_cmd'} || "DISPLAY=__DISPLAY__ /usr/bin/dosbox -conf "; |
my $LOGGING = $cfg{'logging'} || 0; |
my $LOGGING = $cfg{'logging'} || 0; |
my $LOG = $cfg{'log_path'} || "/tmp/bbs.log"; |
my $LOG = $cfg{'log_path'} || "/tmp/bbs.log"; |
my $MAX_NODE = $cfg{'nodes'} || 1; |
my $MAX_NODE = $cfg{'nodes'} || 1; |
my $DOSBOXT = $cfg{'dosboxt'} || "dosbox.conf.template"; |
my $DOSBOXT = $cfg{'dosboxt'} || "dosbox.conf.template"; |
my $BASE_PORT = $cfg{'base_port'} || 7000; |
my $BASE_PORT = $cfg{'base_port'} || 7000; |
my $LOCK_PATH = $cfg{'lock_path'} || "/tmp"; |
my $LOCK_PATH = $cfg{'lock_path'} || "/tmp"; |
|
$BBS_CMD =~ s/__DISPLAY__/$DISPLAY/g; |
|
|
## |
## |
## Check that we are 'root' |
## Check that we are 'root' |
Line 105 while( 1 ) { sleep 1; }
|
Line 106 while( 1 ) { sleep 1; }
|
## Sub-routines begin here |
## Sub-routines begin here |
## |
## |
############################################################################### |
############################################################################### |
############################################################################### |
|
|
|
|
|
|
############################################################################### |
|
## |
|
## &logmsg( "string" ); |
|
## |
|
## This takes a string and prepends the process name, ID and timestamp |
|
## to the message. It then displays it to STDOUT and logs it if enabled. |
|
## |
|
############################################################################### |
sub logmsg |
sub logmsg |
{ |
{ |
my $message = "$0 $$ " . scalar( localtime( ) ) . ":@_\n"; |
my $message = "$0 $$ " . scalar( localtime( ) ) . ":@_\n"; |
Line 116 sub logmsg
|
Line 125 sub logmsg
|
|
|
|
|
############################################################################### |
############################################################################### |
|
## |
|
## &display_config_and_options( %hash ); |
|
## |
|
## This will display via Data::Dumper a hash that is passed to it. |
|
## If verbose is enabled it will got to STDOUT and if logging is enabled |
|
## it will be logged. |
|
## |
|
## This is called only once during startup. |
|
## |
############################################################################### |
############################################################################### |
sub display_config_and_options |
sub display_config_and_options |
{ |
{ |
Line 163 sub startNetServer
|
Line 181 sub startNetServer
|
## |
## |
my $node = 0; |
my $node = 0; |
my $lock_file = ""; |
my $lock_file = ""; |
foreach (1 .. $MAX_NODE) |
my $cnt = 0; |
|
while ( ! $node && $cnt < $MAX_NODE ) |
{ |
{ |
print "Searching for lock: " . $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock\n"; |
$cnt++; |
next if ( -f $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock" ); |
$lock_file = $LOCK_PATH . "/" . $BBS_NAME . |
|
"_node" . $cnt . ".lock"; |
|
print "Checking for node lock: $lock_file\n"; |
|
next if ( -f $lock_file ); |
|
|
## |
## |
## Create node lock file |
## Create node lock file |
## |
## |
$lock_file = $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock"; |
|
open LOCK, ">$lock_file"; |
open LOCK, ">$lock_file"; |
close( LOCK ); |
close( LOCK ); |
$node = $BBS_NODE = $_; |
$BBS_NODE = $node = $cnt; |
|
print "Using node: $node\n"; |
} |
} |
print "Using lock: " . $LOCK_PATH."/".$BBS_NAME."_node".$node.".lock\n"; |
|
|
|
## |
## |
## Create our dosbox config |
## Create our dosbox config |
Line 217 print "Using lock: " . $LOCK_PATH."/".$B
|
Line 238 print "Using lock: " . $LOCK_PATH."/".$B
|
print "Welcome to $BBS_NAME!" . $EOL; |
print "Welcome to $BBS_NAME!" . $EOL; |
|
|
## |
## |
if ( ! $lock_file ) |
if ( ! $node ) |
{ |
{ |
print "No available nodes. Try again later.".$EOL; |
print "No available nodes. Try again later.".$EOL; |
exit; |
exit; |
Line 235 print "Using lock: " . $LOCK_PATH."/".$B
|
Line 256 print "Using lock: " . $LOCK_PATH."/".$B
|
my $cmd = $BBS_CMD . $DBCONF; |
my $cmd = $BBS_CMD . $DBCONF; |
system( $cmd ); |
system( $cmd ); |
print "Shutting down node $BBS_NODE\n"; |
print "Shutting down node $BBS_NODE\n"; |
|
|
## |
## |
## Remove Lock |
## Remove Lock |
## |
## |
unlink( $lock_file ); |
unlink( $lock_file ); |
unlink( $DBCONF ); |
unlink( $DBCONF ); |
|
close( $hostConnection ); |
|
close( $server ); |
|
kill( "TERM" => $bbsPID ); |
exit; |
exit; |
} |
} |
|
|
Line 284 print "Using lock: " . $LOCK_PATH."/".$B
|
Line 309 print "Using lock: " . $LOCK_PATH."/".$B
|
unlink( $DBCONF ); |
unlink( $DBCONF ); |
} |
} |
close( $hostConnection ); |
close( $hostConnection ); |
exit; |
close( $server ); |
|
|
# close( $server ); |
exit; |
} |
} |
|
|
############################################################################### |
############################################################################### |
Line 318 sub shutdown
|
Line 343 sub shutdown
|
unlink( $pidFile ); |
unlink( $pidFile ); |
|
|
## |
## |
|
## Remove node lock files |
|
## |
|
foreach (1 .. $MAX_NODE) |
|
{ |
|
my $node_lock = $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock"; |
|
unlink( $node_lock ) if ( -f $node_lock ); |
|
} |
|
|
|
## |
## Wait for the thread to shutdown |
## Wait for the thread to shutdown |
## |
## |
# $netThread->detach( ); |
# $netThread->detach( ); |
Line 427 sub processExists
|
Line 461 sub processExists
|
} |
} |
|
|
############################################################################### |
############################################################################### |
|
## |
|
## %config_hash = &fetchConfig( ); |
|
## |
|
## This reads in a file in the format of "key = value" and stores them |
|
## in to a hash of $hash{$key} = $value. Lines starting with '#' are |
|
## considered comments and ignored. |
|
## |
############################################################################### |
############################################################################### |
sub fetchConfig |
sub fetchConfig |
{ |
{ |
Line 454 sub fetchConfig
|
Line 495 sub fetchConfig
|
} |
} |
|
|
############################################################################### |
############################################################################### |
|
## |
|
## my $file = &fetchConfig( ); |
|
## |
|
## This function will look for 'telnetbbs.conf' or whatever was specified |
|
## on the command line. It will search the @paths below for the default |
|
## filename if none is specifed. |
|
## |
############################################################################### |
############################################################################### |
sub findConfig |
sub findConfig |
{ |
{ |
my $cf = 0; |
my $cf = 0; |
my @paths = qw| ./ ./.telnetbbs /etc /usr/local/etc |; |
my @paths = qw| ./ ./.telnetbbs /etc /usr/local/etc |; |
|
|
|
return $opts{'config'} if defined $opts{'config'}; |
|
|
foreach ( @paths ) |
foreach ( @paths ) |
{ |
{ |
my $fn = $_ . "/telnetbbs.conf"; |
my $fn = $_ . "/telnetbbs.conf"; |
Line 480 sub fetchOptions {
|
Line 530 sub fetchOptions {
|
my %opts; |
my %opts; |
|
|
&GetOptions( |
&GetOptions( |
|
"config:s" => \$opts{'config'}, |
"help|?" => \$opts{'help'}, |
"help|?" => \$opts{'help'}, |
"man" => \$opts{'man'}, |
"man" => \$opts{'man'}, |
"port:i" => \$opts{'port'}, |
"port:i" => \$opts{'port'}, |
Line 502 telnetbbs.pl - A telnet server designed
|
Line 553 telnetbbs.pl - A telnet server designed
|
telnetbbs.pl [options] |
telnetbbs.pl [options] |
|
|
Options: |
Options: |
|
--config,c Specify the configuration file to use |
--help,? Display the basic help menu |
--help,? Display the basic help menu |
--man,m Display the detailed man page |
--man,m Display the detailed man page |
--port,p Port to listen on, default 23. |
--port,p Port to listen on, default 23. |
|
--verbose,v Enable verbose output |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|