#!/usr/bin/perl 'di '; 'ig 00 '; # #* #* Copyright (c) 1993, 1995 by Colorado Digital Eclectics (CODE) #* All rights reserved. #* #* This code is derived from software contributed to CODE by #* John Conner, WD0FHG. #* #* Redistribution and use in source and binary forms, with or without #* modification, are permitted provided that the following conditions #* are met: #* 1. Redistributions of source code must retain the above copyright #* notice, this list of conditions and the following disclaimer. #* 2. Redistributions in binary form must reproduce the above copyright #* notice, this list of conditions and the following disclaimer in the #* documentation and/or other materials provided with the distribution. #* 3. All advertising materials mentioning features or use of this software #* must display the following acknowledgement: #* This product includes software developed by Colorado Digital Eclectics #* and its contributors. #* 4. Neither the CODE name nor the names of its contributors may be used #* to endorse or promote products derived from this software without #* specific prior written permission. #* #* THIS SOFTWARE IS PROVIDED BY CODE AND CONTRIBUTORS ``AS IS'' AND #* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #* ARE DISCLAIMED. IN NO EVENT SHALL CODE OR THE CONTRIBUTORS BE LIABLE #* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS #* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY #* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF #* SUCH DAMAGE. #* # $FILEDIR = "/etc/p10cfgd/"; $LOGFILE = "/var/log/p10cfgd.log"; $AF_INET = 2; $SOCK_STREAM = 1; $IPPORT_RMTCFG = 1236; $sockaddr = 'S n a4 x8'; $fileaddr = 'S n a4'; # just incase someone wants to set on a different port ($port) = @ARGV; $port = $IPPORT_RMTCFG unless $port; open(LOG,">>$LOGFILE") || die "Can't open log file: $!\n"; ($sec,$min,$hour,$mday,$mon,$year) = gmtime(time); ++$mon; print LOG "Starting p10cfgd: $mon/$mday/$year $hour:$min:$sec\n"; # if we were started by inetd then STDIN will be our # socket and getsockname will return $myport == $port $mysockaddr = getsockname(STDIN); ($family, $myport, $myaddr) = unpack($fileaddr,$mysockaddr); print LOG "Started by inetd port=$myport\n"; if ( $myport == $port ) { # we were started by inetd open(NS,"+<&STDIN"); $addr = getpeername(NS); $con = "inetd"; &ServiceConnection; exit; #should never get here } # we were started normally ($name, $aliases, $proto) = getprotobyname('tcp'); if ($port !~ /^\d+$/) { ($name, $aliases, $port) = getservbyport($port, 'tcp'); } $this = pack($sockaddr, $AF_INET, $port, "\0\0\0\0"); select(NS); $| = 1; select(stdout); socket(S, $AF_INET, $SOCK_STREAM, $proto) || die "socket: $!"; bind(S,$this) || die "bind: $!"; listen(S,5) || die "connect: $!"; select(S); $| = 1; select(stdout); $con = 0; print LOG "Listening for connection on Port = $port\n"; close(LOG); for(;;) { # wait here for connection ($addr = accept(NS,S)) || die $!; $con++; # now process the remote's file request if (($child[$con] = fork()) == 0) { unless (fork) { # child[$con]'s child &ServiceConnection; } #first child exits quickly exit; } wait; #parent reaps first child quickly close(NS); } sub ServiceConnection { open(LOG,">>$LOGFILE") || die "Can't open log file: $!\n"; ($sec,$min,$hour,$mday,$mon,$year) = gmtime(time); ++$mon; print LOG "$con: $mon/$mday/$year $hour:$min:$sec\n"; ($af,$port,$inetaddr) = unpack($sockaddr,$addr); @inetaddr = unpack('C4',$inetaddr); print LOG "$con: accept ok connection from @inetaddr\n"; # the only thing we are expecting from the remote is a file name $file = ; chop( $file ); # get rid of the newline $file =~ s/\r$//; # get rid of the return that may be at the end print LOG "$con: Requested file - $file\n"; print NS "# Config file: $file\n"; #Send a comment line $file = "$FILEDIR$file"; do { print NS "# Unable to open requested config file.\n"; close( NS ); print LOG "$con: Could not open file $file: $!\n"; exit; } unless open( FILE, $file ); # now copy the requested file to the socket while ( ) { chop; s/^$/ /; #make sure that all lines have at least one char s/^_$//; #except for lines starting with a underscore print NS "$_\n"; } # now send the time (MMDDYYHHMM) this should work for all files and # set the switch time when any command file is read. It should just # add a time stamp to the info files. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime( time ); $mon++; printf (NS "time %2.2d%2.2.2d%2.2d%2.2d%2.2d \n",$mon,$mday,$year,$hour,$min); close(FILE); close(NS); close(LOG); exit; } # end-ServiceConnection ############################################################### # These next few lines are legal in both Perl and nroff. .00 ; # finish .ig 'di \" finish diversion--previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 '; __END__ ##### From here on it's a standard manual page ##### .TH P10CFGD 1 "July 29, 1993" .AT 3 .SH NAME p10cfgd \- remote configuration daemom for Gracilis PackeTen .SH SYNOPSIS .B p10cfgd [IP_PORT] .SH COPYRIGHT Copyright (c) 1993 by Colorado Digital Eclectics (CODE) All rights reserved. .SH DESCRIPTION .I Rmtcfgd is a server program used to send configuration files to a Gracilis PackeTen. It can be run in background or it can be run by inetd. If .I p10cfgd is to be run by inetd, add the following line to .I /etc/services .nf rmtcfg 1236/tcp # Remote Configuration of PackeTen .fi and add the following to .I /etc/inetd.conf .nf # Remote configuration service for PackeTen rmtcfg stream tcp nowait root /usr/bin/p10cfgd p10cfgd .fi .I P10cfgd normally does not require the IP_PORT parameter. It listens for connections on IP Port 1236 as a default. The program will send on a line by line basis the file requested by the client that connects on the IP Port. The only expected input from the client is the file name. When the file has been sent, the connection is closed. The requested file must be in the directory /etc/p10cfgd. .I Rmtcfgd maintains a log of its activity in the file /var/log/p10cfgd.log. Program startup and all connections are logged in the file with GMT time stamps. The file is opened in append mode. The protocol used by the PackeTen is very simple. The PackeTen opens a tcp connection to port 1236 on a host system. Once the connection is made, the PackeTen sends the name of the file it wants to the host. The host then opens the file and sends it line by line to the PackeTen until all lines have been sent. The files to be transfered must be plain text files and each line must have at least one character in addition to the newline at the end. .I P10cfgd replaces all blank lines with lines that contain two spaces. If you wish to send a blank line, to stop loading of part of a LocalInfo file for example, place an underscore '_' at the begining of the line. The entire contents of the line will be deleted and a blank line will be sent to the client. At the end of the file, the server sends a time command ( time MMDDYYHHMM ) with the UTC time on the server. This will either set the time on the PackeTen or add a time stamp to the LocalInfo file. The server then closes the connection. The remote configuration command used on the PackeTen is .nf rmtcfg [options] The valid options are -t default is 60 sec -p default is 1236 -i the file is for LocalInfo -h if the primary does not answer .fi The rmtcfg commands would be placed in to the EEPROM on the PackeTen so that they would be executed during a reboot. The information stored in the EEPROM should include enough information to set the PackeTen up to allow communications with the primary and the secondary server. This would include commands to set MYCALL and the IP_ADDRESS, to attach an interface to the channel with the server, routing information and so forth. A sample EEPROM configuration for a PackeTen, empire.wd0fhg.ampr.org [44.32.0.32], that gets its configuration from a remote system winfree.n3eua.ampr.org [44.32.0.2], over a 9600 baud ax25 path would be: .nf # first the general setup of the PackeTen ee hostname gw.wd0fhg ee sitename empire ee ipaddr 44.32.0.32 ee mycall WD0FHG # Then we attach a 9600 ax25 interface as ax1 ee attach sync302 1 hdx ax25 ax1 8192 256 9600 ext ext nrzi # and set the default route to send every thing out ax1 ee route add default ax1 44.32.0.1 ee password sure-thing # # Now we will ask for the remainder of the setup # from the server winfree.n3eua.ampr.org [44.32.0.2] # Note that we have a secondary server available at # [44.20.0.195] that would be used if winfree is down. # first the Local Information file ee com 0 rmtcfg 44.32.0.2 empire.info -i -h 44.20.0.195 # and then the remaining configuration command file ee com 1 rmtcfg 44.32.0.2 empire.cfg -h 44.20.0.195 # ee save # end-of-eeprom setup .fi .I Rmtcfgd started life as the simple server program in PERL by Larry Wall and R.L. Schwartz published by ORA,Inc. .SH ENVIRONMENT No environment variables are used. .SH FILES .nf /etc/p10cfgd/* - files that can be accessed remotely /var/log/p10cfgd.log - p10cfgd log file .fi .SH AUTHOR .nf John Conner, WD0FHG, conner@empire.com hacked on by Bdale Garbee, N3EUA, bdale@gag.com. .fi .SH "SEE ALSO" Gracilis, Inc. PackeTen Manual and NOS User's Manual .SH DIAGNOSTICS Complains if it can't open a file to remote client and to log file.