/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. # end of configuration #############################################
  6. # main()
  7. #
  8. if ((@ARGV < 1) || @ARGV > 2 || $ARGV[0] eq "-?") {
  9. &usage;
  10. } elsif ($ARGV[1] ne "") {
  11. $node = $ARGV[1];
  12. }
  13. $file = $ARGV[0];
  14. if (! ($node =~ /\d+:\d+\/\d+/)) {
  15. die "Wrong address: $node!!!";
  16. }
  17. ($zone, $netnode) = split (/:/, $node);
  18. $reqfile = sprintf("%04x%04x", split(/\//, $netnode));
  19. if ($reqfile eq "00000000") {
  20. print ("can't resolve the fido address \"$node\"\n");
  21. &usage;
  22. } else {
  23. if ( $zone == 2 ) {
  24. $reqfile = $flo_path . $outbound . "/" . $reqfile . ".req";
  25. } elsif ( $zone < 7 ) {
  26. $reqfile = $flo_path . $outbound . ".00$zone/" . $reqfile . ".req";
  27. } else {
  28. $outbound = "";
  29. open (CONFIG, "< $config") || die "can't open $config";
  30. while ($_ = <CONFIG>) {
  31. if ( /^address.*$zone:.*\@(\w*)/ ) { $outbound = $1; }
  32. }
  33. if ( $outbound eq "" ) {
  34. die "No Zone $zone found in $config";
  35. }
  36. $reqfile = $flo_path . "/$outbound/" . $reqfile . ".req";
  37. }
  38. # seperate the file names of the first argument
  39. @files = split (/\s+/, $ARGV[0]);
  40. # open the flofile for appending
  41. open(FLOFILE, ">>" . $reqfile) || die "can't open $reqfile";
  42. while (@files) {
  43. print (FLOFILE shift(@files), "\n");
  44. }
  45. close(FLOFILE);
  46. print ("--- fido request $ver ---------------------------\n");
  47. print ("requesting \"$file\" from fido-node $node\n");
  48. print ("--- executing ifstat .. ------------------------\n");
  49. system("ifstat");
  50. }
  51. #
  52. # subroutine "usage"
  53. #
  54. sub usage {
  55. printf ("--- fido request %s -------------\n", $ver);
  56. printf ("usage: ifreq <file> [<3-d address>]\n");
  57. printf ("e.g. : ifreq FILES 2:2410/305\n");
  58. exit 1;
  59. }