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

  1. #! /bin/sh
  2. # newgroup group flag - create group (4-field version: B-2.10.3+ compatible)
  3. #    subject to our sys file group pattern
  4. # also subject to $NEWSCTL/newgroupperm:  four fields per line, first
  5. # a newsgroup pattern, second a sender name (or "any"), third a set of
  6. # flags ("y" do it, "n" don't, "q" don't report at all, "v" include
  7. # entire control message in report) (default "yv").  This is experimental
  8. # and likely to change.
  9.  
  10. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  11. . ${NEWSCONFIG-/var/lib/news/bin/config}
  12. export NEWSCTL NEWSBIN NEWSARTS
  13. PATH=$NEWSCTL/bin:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH; export PATH # finds mkpdir
  14. umask $NEWSUMASK
  15.  
  16. posting=/tmp/np$$
  17. hdr=/tmp/nc$$
  18.  
  19. # get the full article, and its header, into files for inspection
  20. trap "rm -f $posting $hdr; exit 0" 0
  21. cat >$posting
  22. canonhdr $posting >$hdr
  23.  
  24. # who sent it?
  25. SENDER="`egrep '^Sender:' $hdr | sed 's/^[^:]*: *//'`"
  26. case "$SENDER" in
  27. "")    SENDER="`egrep '^From:' $hdr | sed 's/^[^:]*: *//' `" ;;
  28. esac
  29. senderid="`echo \"$SENDER\" | sed '/.*<\(.*\)>.*/s//\1/
  30.                    /\([^ ][^ ]*\)  *(.*).*/s//\1/'`"
  31.  
  32. # was it approved?
  33. case "`egrep '^Approved:' $hdr`" in
  34. '')    reject=${reject-'no Approved header'}    ;;
  35. esac
  36.  
  37. # verify acceptable alphabet
  38. case "$1" in
  39. *[\    \ !:]*)    reject=${reject-'bad character(s) in name'}    ;;
  40. esac
  41.  
  42. # toss groups with too-long components.  usually due to alt.bozobozobozobozo
  43. for word in ` echo "$1" | tr . ' ' `
  44. do
  45.     case "$word" in
  46.     ???????????????*)
  47.         reject=${reject-'component exceeds 14 characters'}    ;;
  48.     esac
  49. done
  50.  
  51. # consult control file, if present
  52. perms=$NEWSCTL/newgroupperm
  53. action=yv
  54. if test -r $perms
  55. then
  56.     newaction=`gngp -a -r "$1" $perms |
  57.         awk '$2 == "any" || $2 == "'"$senderid"'" { print $3 }' |
  58.         sed -n 1p`
  59.     case "$newaction" in
  60.     ?*)    action=$newaction    ;;
  61.     esac
  62. fi
  63. case "$action" in
  64. *n*)    reject=${reject-'newgroupperm file denies permission'}    ;;
  65. esac
  66.  
  67. # check that my sys file allows this group
  68. me="`newshostname`"
  69. gngppat=`awk -f $NEWSBIN/relay/canonsys.awk $NEWSCTL/sys |
  70.     egrep "^($me|ME)[:/]" |
  71.     awk -F: '
  72. {
  73.     fields = split($2, field2, "/")    # split ngs/dists
  74.     print field2[1]            # print only ngs
  75.     exit
  76. }' `
  77. case "`echo \"$1\" | gngp -a \"$gngppat\"`" in
  78. '')    reject=${reject-'unsubscribed group'}    ;;
  79. esac
  80.  
  81. # is this just a change of moderation status?
  82. # escape egrep metacharacters.  In theory one could add " ' ` \ to the list.
  83. justmod=
  84. egreppat="^(` echo "$1" | sed -e 's/[.+*()|[]/\\\\&/g' -e 's/,/|/g' `) "
  85. case "`egrep \"$egreppat\" $NEWSCTL/active`" in
  86. ?*)    justmod=y    ;;
  87. esac
  88.  
  89. # the verdict
  90. case "$reject" in
  91. ?*)    case "$action" in
  92.     *q*)    ;;
  93.     *)    (
  94.             echo "$0: \`$SENDER' tried"
  95.             case "$justmod" in
  96.             y)    echo "to set newsgroup \`$1' to \`$2'."    ;;
  97.             *)    echo "to create newsgroup \`$1'."    ;;
  98.             esac
  99.             echo "Request was refused:  $reject."
  100.             case "$action" in
  101.             *v*)    echo '==='
  102.                 cat $posting
  103.                 echo '==='
  104.                 ;;
  105.             esac
  106.         ) | mail $NEWSMASTER
  107.         ;;
  108.     esac
  109.     exit
  110.     ;;
  111. esac
  112.  
  113. # handle changes of moderation status
  114. case "$justmod" in
  115. y)    export SENDER
  116.     chamod "$1" "$2"
  117.     exit
  118.     ;;
  119. esac
  120.  
  121. # finally, we are in the clear to make it
  122. case "$2" in
  123. moderated)    flag=m ;;
  124. *)        flag=y ;;
  125. esac
  126. echo "$1 0000000000 00001 $flag" >>$NEWSCTL/active
  127. echo "$1 `getdate now` $SENDER" >>$NEWSCTL/active.times
  128.  
  129. # make the directory since rn will bitch if it's missing
  130. mkpdir $NEWSARTS/`echo $1 | tr . / `
  131.  
  132. # and report it, if appropriate
  133. case "$action" in
  134. *q*)    ;;
  135. *)    (
  136.         echo "newsgroup $1 was created by $SENDER."
  137.         case "$action" in
  138.         *v*)    echo '==='
  139.             cat $posting
  140.             echo '==='
  141.             ;;
  142.         esac
  143.     ) | mail $NEWSMASTER
  144.     ;;
  145. esac
  146.