home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / inject / inews < prev    next >
Encoding:
Text File  |  1994-09-02  |  3.2 KB  |  125 lines

  1. #! /bin/sh
  2. # inews [-p] [-debug k] [-x site] [-hMD] [-t subj] [-n ng] [-e exp] [-F ref] \
  3. #  [-d dist] [-a mod] [-f from] [-o org] [-C ng] [file...] - backward
  4. #    compatible news injection interface supporting all the old sludge:
  5. #    censor locally-posted article and field the "inews -C" kludge;
  6. #    munge the articles, enforce feeble attempts at Usenet security,
  7. #    generate lots of silly headers.
  8. #
  9. # Yes, it's slow and awkward.  The alternative is casting a lot of
  10. # local policy in C.
  11.  
  12. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  13. . ${NEWSCONFIG-/var/lib/news/bin/config}
  14. export NEWSCTL NEWSBIN NEWSARTS NEWSPATH NEWSUMASK NEWSMASTER NEWSCONFIG
  15. PATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN:$NEWSPATH
  16. export PATH
  17.  
  18. injnewsopts=
  19. hdrspresent=no
  20.  
  21. input=/tmp/in$$in        # uncensored input
  22. inhdrs=/tmp/in$$hdr        # generated by tear: headers
  23. inbody=/tmp/in$$body        # generated by tear: body
  24. rmlist="$inhdrs $inbody $input"
  25.  
  26. umask $NEWSUMASK
  27.  
  28. # "inews -p": invoke rnews
  29. case "$1" in
  30. -p)
  31.     shift
  32.     
  33.     PATH=$NEWSCTL/bin:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH
  34.     export PATH
  35.     exec relaynews -r $*    # feed directly to relaynews, seat belts off
  36.     ;;
  37. esac
  38.  
  39. # process arguments: for options, cat headers onto $input; cat files onto $input
  40. >$input
  41.  
  42. ### option processing ###
  43.  
  44. while :
  45. do
  46.     case $# in
  47.     0)    break ;;        # arguments exhausted
  48.     esac
  49.  
  50.     case "$1" in
  51.     # peculiar to C news
  52.     -debug|-x)    injnewsopts="$injnewsopts $1 ''$2"; shift ;;
  53.     -[ANV])        injnewsopts="$injnewsopts $1" ;;
  54.     -W)    ;;            # obsolete
  55.     # useful standard options
  56.     -h)    hdrspresent=yes ;;
  57.     # silly options supplied by newsreaders
  58.     -a)    shift; echo "Approved: $1"    >>$input ;;
  59.     -c)    shift; echo "Control: $1"    >>$input ;;
  60.     -d)    shift; echo "Distribution: $1"    >>$input ;;
  61.     -e)    shift; echo "Expires: $1"    >>$input ;;
  62.     -f)    shift; echo "From: $1"        >>$input ;;
  63.     -n)    shift; echo "Newsgroups: $1"    >>$input ;;
  64.     -o)    shift; echo "Organization: $1"    >>$input ;;
  65.     -r)    shift; echo "Reply-To: $1"    >>$input ;;
  66.     -t)    shift; echo "Subject: $1"    >>$input ;;    # aka Title:
  67.     -D)    # obsolete, undocumented: meant "don't check for recordings".
  68.         # last present in B 2.10.1, invoked by readnews for followups.
  69.         ;;
  70.     -F)    # undocumented in B 2.10.1, documented in B 2.11.
  71.         shift; echo "References: $1" >>$input ;;
  72.     -M)    # this apparently just sets From: to the author of the article
  73.         # instead of the poster (moderator), by leaving the From: line
  74.         # alone (under -h); easy to implement.
  75.         ;;
  76.  
  77.     -C)
  78.         cat <<eg >&2
  79. $0: you either want to use addgroup (see newsaux(8)) to make
  80. $0: $2 locally, or this to make it network-wide:
  81. injnews <<'!'
  82. Control: newgroup $2
  83. Subject: newgroup $2
  84. Newsgroups: $2
  85. Approved: you@hostname
  86.  
  87. Non-empty.
  88. !
  89. eg
  90.         exit 1
  91.         ;;
  92.     -*)
  93.         echo "$0: bad option $1; usage too large, see inews(1)" >&2
  94.         exit 1
  95.         ;;
  96.     *)    break ;;            # is a filename
  97.     esac
  98.     shift                    # pass option
  99. done
  100.  
  101. ### collect input ###
  102.  
  103. # B 2.11 kludge: assume -h if input starts with headers.
  104. # apparently the B 2.11 newsreaders assume this.
  105. tear /tmp/in$$ $*
  106. if test -s $inhdrs; then
  107.     hdrspresent=yes
  108. fi
  109. case "$hdrspresent" in
  110. no)    echo "" >>$input; hdrspresent=yes ;;
  111. esac
  112. # capture incoming news in case relaynews fails
  113. if cat $inhdrs $inbody >>$input; then
  114.     : far out
  115. else
  116.     echo "$0: lost news; cat status $?" >&2
  117.     exit 1
  118. fi
  119.  
  120. ### the input is now fully assembled in $input; beat it up ###
  121.  
  122. exec <$input
  123. rm -f $rmlist
  124. exec injnews $injnewsopts
  125.