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

  1. #! /bin/sh
  2. # injnews [-debug k] [-x site] [-ANV] - `sensible' news injection interface:
  3. #    censor locally-posted article on stdin; munge the article, enforce
  4. #    feeble attempts at Usenet security, generate lots of silly headers.
  5. #
  6. # Yes, it's slow.  The alternative is casting a lot of local policy in C.
  7.  
  8. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  9. . ${NEWSCONFIG-/var/lib/news/bin/config}
  10. export NEWSCTL NEWSBIN NEWSARTS NEWSPATH NEWSUMASK NEWSMASTER NEWSCONFIG
  11. PATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN:$NEWSPATH; export PATH
  12.  
  13. debug=''            # flags
  14. exclusion=''
  15. autopost=no; export autopost
  16. relayopts=-i; export relayopts    # redirect stdout to log
  17. badsites=; export badsites    # export to pnews
  18.  
  19. input=/tmp/in$$in        # uncensored input; save on error
  20. inhdrs=/tmp/in$$hdr        # generated by tear: headers
  21. inbody=/tmp/in$$body        # generated by tear: body
  22. censart=/tmp/in$$cens        # censored input
  23. outfile=/tmp/in$$out        # relaynews stdout
  24. rmlist="$input $inhdrs $inbody $censart $outfile"
  25.  
  26. umask $NEWSUMASK
  27.  
  28. # process arguments: for options, cat headers onto $input; cat files onto $input
  29. cleanup="test ! -f $HOME/dead.article -o -w $HOME/dead.article &&
  30.   cat $input >>$HOME/dead.article &&
  31.   { echo $0: article in $HOME/dead.article >&2; rm -f $rmlist; }; exit 1"
  32. trap "$cleanup" 0 1 2 3 15
  33.  
  34. ### option processing ###
  35.  
  36. while :
  37. do
  38.     case $# in
  39.     0)    break ;;        # arguments exhausted
  40.     esac
  41.  
  42.     case "$1" in
  43.     # peculiar to C news
  44.     -debug)    shift; debug="$1" ;;
  45.     -A)    autopost=yes ;;            # wait for free space
  46.     -N)    justfilter=yes ;;
  47.     -V)    relayopts= ;;    # verbose: don't redirect stdout (or stderr)
  48.     # useful standard option
  49.     -x)    shift; badsites="$badsites$1!" ;; # you're welcome, erik (B 2.11)
  50.     *)                    # bad option or a file name
  51.         echo "usage: $0 [-debug k] [-x site] [-ANV]" >&2
  52.         exit 1
  53.         ;;
  54.     esac
  55.     shift                    # pass option
  56. done
  57.  
  58. ### beat up article on stdin ###
  59. cat >$input                    # **
  60.  
  61. if
  62.     case "$justfilter" in    # ** pnews takes 3.2 seconds
  63.     yes) pnews /tmp/in$$ <$input ;;    # output in $inhdrs & $inbody
  64.     *)   pnews /tmp/in$$ <$input >$censart ;;    # output in $inhdrs & $inbody
  65.     esac
  66. then    :
  67. else    exit $?            # clean up; pnews will have complained
  68. fi
  69.  
  70. # to post or to mail? that is the question; whether 'tis nobler in the mind
  71. # to suffer the slings and arrows of outrageous mailers - Bill Shakespeare
  72.  
  73. ngs=` awk '
  74.     # a dreadful hack around all.all.ctl
  75.     /^Control:/    { print "control"; ngs=""; exit }
  76.     /^Newsgroups:/    { ngs=$2 }        # save for END
  77.     END        { if (ngs != "") print ngs }
  78.     ' $inhdrs `
  79. case "$ngs" in            # any Newsgroups:?
  80. '')    exit 1 ;;        # nope: pnews will have already complained
  81. esac
  82.  
  83. # look up groups in active, to determine disposition of this message.
  84. # n, x and (unapproved) m flags are dealt with on the spot; if none are
  85. # seen, the article is posted normally.
  86. # POLICY: what happens to = groups; how are m articles mailed?
  87. actflag="` actflag $ngs `"        # ** takes 0.4 seconds
  88. case "$actflag" in
  89. '')
  90.     echo "$0: $ngs: no groups in active file" >&2
  91.     exit 1
  92.     ;;
  93. [nx]*)
  94.     # TODO: deal better when only some groups are n or x.
  95.     set $actflag
  96.     ng="$2"
  97.     echo "$0: sorry, $ng may not be posted to locally." >&2
  98.     exit 1
  99.     ;;
  100. m*)
  101.     if grep -s '^Approved:[     ]' $inhdrs >/dev/null; then
  102.         :        # just post normally
  103.     else
  104.         case "$justfilter" in
  105.         yes)    ;;
  106.         *)
  107.             set $actflag
  108.             ng="$2"
  109.             # unApproved article: mail to a moderator.
  110.             moderator="` modroute $ng `"
  111.             echo "mailing your article to $moderator"
  112.             mail "$moderator" <$censart
  113.             ;;
  114.         esac
  115.         trap "rm -f $rmlist; exit 0" 0    # normal exit - no dead.article
  116.         exit 0
  117.     fi
  118.     ;;
  119.  
  120. y|*)                # * matches garbage flags, to be cautious.
  121.     # okay
  122.     ;;
  123. esac
  124.  
  125. ### if the article was mailed, that happened above; posting will follow ###
  126.  
  127. # to get here, we must have seen no n, x, nor (unapproved) m flags.
  128. # <$censart is used rather than a pipe to work around a bug in the 4.2 sh
  129. # which made it sometimes return the wrong exit status (that of anne.jones).
  130. # may not use "exec" or sh will leave /tmp/sh* files from here docs in /tmp.
  131.  
  132. if
  133.     case "$justfilter" in
  134.     yes)    : ;;
  135.     *)
  136.         # relayopts="$relayopts -s -d ''$debug" \
  137.         PATH=$NEWSCTL/bin:$NEWSBIN/input:$NEWSBIN:$NEWSPATH
  138.         newsspool -g 0 <$censart        # TODO: pass relayopts
  139.         ;;
  140.     esac
  141. then
  142.     # POLICY: warn the user about missing sys file?
  143.     if test ! -f $NEWSCTL/sys; then
  144.         echo "$0: $NEWSCTL/sys missing; your news can't leave this machine" >&2
  145.     fi
  146.     trap "rm -f $rmlist; exit 0" 0        # normal exit - no dead.article
  147.     exit 0
  148. else
  149.     exit $?                # trap 0 may cleanup, make dead.article
  150. fi
  151.