PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/dialog/samples/copifuncs/copi.ifreq2

https://bitbucket.org/freebsd/freebsd-head/
Unknown | 68 lines | 59 code | 9 blank | 0 comment | 0 complexity | 2fb8730d820254b2ec0091cf9e765d26 MD5 | raw file
 1# this is the base directory, where the req-files are stored and the
 2# default outbound
 3$flo_path = "/var/spool/ifmail";
 4$outbound = "/outb"; # don't be confused, it means "/var/spool/ifmail/outb"
 5
 6# end of configuration #############################################
 7
 8# main()
 9#
10if ((@ARGV < 1) || @ARGV > 2 || $ARGV[0] eq "-?") {
11    &usage;
12} elsif ($ARGV[1] ne "") {
13    $node = $ARGV[1];
14}
15$file = $ARGV[0];
16
17if (! ($node =~ /\d+:\d+\/\d+/)) {
18    die "Wrong address: $node!!!";
19}
20
21($zone, $netnode) = split (/:/, $node);
22$reqfile = sprintf("%04x%04x", split(/\//, $netnode));
23
24if ($reqfile eq "00000000") {
25    print ("can't resolve the fido address \"$node\"\n");
26    &usage;
27} else {
28    if ( $zone == 2 ) {
29        $reqfile = $flo_path . $outbound . "/" . $reqfile . ".req";
30    } elsif ( $zone < 7 ) {
31        $reqfile = $flo_path . $outbound . ".00$zone/" . $reqfile . ".req";
32    } else {
33        $outbound = "";
34        open (CONFIG, "< $config") || die "can't open $config";
35        while ($_ = <CONFIG>) {
36            if ( /^address.*$zone:.*\@(\w*)/ ) { $outbound = $1; }
37        }
38        if ( $outbound eq "" ) {
39            die "No Zone $zone found in $config";
40        }
41        $reqfile = $flo_path . "/$outbound/" . $reqfile . ".req";
42    }
43
44    # seperate the file names of the first argument
45    @files = split (/\s+/, $ARGV[0]);
46
47    # open the flofile for appending
48    open(FLOFILE, ">>" . $reqfile) || die "can't open $reqfile";
49        while (@files) {
50            print (FLOFILE shift(@files), "\n");
51        }
52    close(FLOFILE);
53
54    print ("--- fido request $ver ---------------------------\n");
55    print ("requesting \"$file\" from fido-node $node\n");
56    print ("--- executing ifstat .. ------------------------\n");
57    system("ifstat");
58}
59
60#
61# subroutine "usage"
62#
63sub usage {
64    printf ("--- fido request %s -------------\n", $ver);
65    printf ("usage: ifreq <file> [<3-d address>]\n");
66    printf ("e.g. : ifreq FILES 2:2410/305\n");
67    exit 1;
68}