File: p10cfgd

package info (click to toggle)
p10cfgd 1.0-14
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 80 kB
  • sloc: perl: 201; exp: 66; makefile: 39; sh: 2
file content (314 lines) | stat: -rw-r--r-- 10,297 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/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 = <NS>;
    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 ( <FILE> ) {
	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 <server_host> <filename> [options]
	The valid options are
		-t  <timeout in seconds>  default is 60 sec
		-p  <IP port #>           default is 1236
		-i	                  the file is for LocalInfo 
		-h  <secondary server>    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.