home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2864 < prev    next >
Encoding:
Text File  |  1992-12-23  |  26.2 KB  |  941 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!smurf.sub.org!mamunx!mam
  3. From: mam@mamunx.garmhausen.de (Michael A Meiszl)
  4. Subject: Newjunk, automatically create newsgroups from junk V2.0 (Part 1/1)
  5. Organization: Public Access Mailbox
  6. Date: Wed, 23 Dec 1992 10:11:41 GMT
  7. Message-ID: <BzpIzI.JuH@mamunx.garmhausen.de>
  8. Lines: 931
  9.  
  10.  
  11.  
  12.                 N e w j u n k
  13.                 -------------
  14.  
  15.         Install new newsgroups by scanning the junk directory.
  16.  
  17. Written        2/91 by Michael A. Meiszl (mam@mamunx.garmhausen.de)
  18. Last Update    12/92
  19.  
  20. If your systems receives news from more than one feed or from more than one
  21. net, you sometimes notice your junk directory growing pretty fast. This is
  22. mostly due missing control messages from the nets. You can configure your
  23. news software to install a new group automatically on reception of a newgroup
  24. control message, but you can't do anything against a feed that decides to
  25. send you more groups without notice.
  26.  
  27. So its up to the system operator to check junk concurrently and to decide 
  28. whether he needs to install that new group by hand or whether it was only
  29. a crossposting from another net.
  30.  
  31. Managing more than ones systems doubles the work of the operator and if this
  32. happens quite every day (we got big feeds here :-(), it was time for a cute
  33. little program that does the work for me...
  34.  
  35. Newjunk is a straightforward program which only reads through the junk direc-
  36. tory and scans for the "Newsgroups:" line in the message header. It exctracts
  37. the wanted newsgroup(s) and checks against the active file.
  38. Newjunk looks at the first (groupname) and fourth (statusflag) field of active.
  39. It should be fairly compatible with most news systems. B- and C- news are
  40. known to work, others may vary.
  41. If the group is already there, nothing is done with it.
  42. This keeps track of the chance when B-news will eject an valid article because
  43. it is "too old".
  44. If the group is not installed, newjunks checks if the group leader is already
  45. there. If not, the message is considered as a crossposting from another net
  46. and the message is thrown away. If the net is there and the group is new,
  47. newjunk creates an call to inews gererating an newgroup control message for
  48. a given distribution.
  49.  
  50. Normally you set this distribution to "local", so only
  51. your system will be affected, but for managing more systems it is well suited
  52. to create an own distribution, so newjunk must only be run on the main machine.
  53.  
  54. You may prevent creating groups in existing nets by inserting a line which
  55. excludes the top level group explictly:
  56.     alt            0    0    x    
  57.     alt.sex.pictures    0    0    m
  58. These lines will newjunk make new groups within the alt.sex.pictures hirarchie,
  59. but not create any new alt groups.
  60.  
  61. After newjunk is done it can start a normal script file which is executed by
  62. /bin/sh. Look at my sample newjunk.sh for some ideas what you can get from it.
  63. The tasks done by the script could easily be placed in the program itself,
  64. but a script is easier to adopt than fiddling with the code.
  65.  
  66. INSTALLATION:
  67. Edit the Makefile newjunk.h  and newjunks.sh for your needs then type "make".
  68. You can edit the message in newjunk.msg too, but please leave the copyright
  69. statement in it.
  70.  
  71. This should build the executable in the local directory. You can test your 
  72. nstallation by calling "newjunk -t" which will do all scanning but no executing.
  73. It will inform you about unreachable files or directorys and scan your junkdir.
  74. If everything looks good, type "make install". This will copy newjunk and 
  75. newjunk.sh into the news lib/bin directory and set permissions that it can
  76. be executed by the owner of the news system (normally "news").
  77.  
  78. Now su to the news user and edit its crontab entry. Add a line for newjunk.
  79. Running newjunk once a week or once a day depends on your traffic.
  80.  
  81. Make sure its run before your junk expires!
  82.  
  83. Your'e done and hopefully are rid of some work too...
  84.  
  85. COPYING:
  86. The program is put into the public domain, it may be copied and modificated
  87. without notice as long as the original author's name is included. The
  88. program may not be sold in any way. Especially semi-commercial "public-
  89. domain-resellers" are discouraged to keep and sell this program. Mailboxes
  90. can distribute it as long as they take no fee from there users.
  91. If major modifications are made, please send me the diffs.
  92.  
  93. BUGREPORTS:
  94.     Send diffs an bugreports to:    
  95.         mam@mamunx.hamm.sub.org or mam@mamunx.garmhausen.de
  96.         Michael A. Meiszl
  97.         Tomsonstrasse 25
  98.         D-W4700 Hamm 1
  99.         Germany     
  100.  
  101. #!/bin/sh
  102. # This is a shell archive (shar 3.24)
  103. # made 12/23/1992 10:10 UTC by root@mamunx
  104. # Source directory /u/mam/tools/newjunk
  105. #
  106. # existing files WILL be overwritten
  107. #
  108. # This shar contains:
  109. # length  mode       name
  110. # ------ ---------- ------------------------------------------
  111. #    970 -rw-r--r-- Makefile
  112. #   4102 -rw-r--r-- README
  113. #    680 -rwxr-xr-x newjunk.sh
  114. #  10878 -rw-r--r-- newjunk.c
  115. #   2224 -rw-r--r-- newjunk.h
  116. #    109 -rw-r--r-- newjunk.msg
  117. #
  118. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  119.  then TOUCH=touch
  120.  else TOUCH=true
  121. fi
  122. # ============= Makefile ==============
  123. echo "x - extracting Makefile (Text)"
  124. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  125. X#
  126. X# Makefile for NewJunk
  127. X# 
  128. X
  129. XCFLAGS=-O2 -s -DCNEWS -DCNEWSSPEEDUPVERSION
  130. XCC=gcc
  131. XSHELL=/bin/sh
  132. XBINDIR=/usr/lib/newsbin/contrib
  133. XOWNER= news
  134. XGROUP= news
  135. XLIBS=    -lc_s
  136. X
  137. X
  138. XTARGET=    newjunk
  139. XSCRIPT= $(TARGET).sh
  140. XMSG=    $(TARGET).msg
  141. X
  142. XOBJ=    $(TARGET).o
  143. XHDR=    $(TARGET).h
  144. XEXECUTABLE=    $(BINDIR)/$(TARGET)
  145. XEXESCRIPT=    $(BINDIR)/$(SCRIPT)
  146. XEXEMSG=        $(BINDIR)/$(MSG)
  147. X
  148. X$(TARGET):    $(OBJ) $(HDR)
  149. X    $(CC) $(CFLAGS) -o $(TARGET) $(OBJ) $(LIBS)
  150. X
  151. Xclean:
  152. X    -rm $(OBJ) $(TARGET) a.out core
  153. X
  154. Xinstall:    $(TARGET)
  155. X    -mkdir $(BINDIR)
  156. X    chown $(OWNER) $(BINDIR)
  157. X    chgrp $(GROUP) $(BINDIR)
  158. X    cp $(TARGET) $(EXECUTABLE)
  159. X    chown $(OWNER) $(EXECUTABLE)
  160. X    chgrp $(GROUP) $(EXECUTABLE)
  161. X    chmod 4700 $(EXECUTABLE)
  162. X    cp $(SCRIPT) $(EXESCRIPT)
  163. X    chgrp $(GROUP) $(EXESCRIPT)
  164. X    chown $(OWNER) $(EXESCRIPT)
  165. X    chmod 755 $(EXESCRIPT)
  166. X    cp $(MSG) $(EXEMSG)
  167. X    chgrp $(GROUP) $(EXEMSG)
  168. X    chown $(OWNER) $(EXEMSG)
  169. X    chmod 600 $(EXEMSG)
  170. X    
  171. Xshar:    $(TARGET)
  172. X    shar -onewjunk -l50 Makefile README *.sh *.c *.h *.msg
  173. X
  174. X.c.o:    
  175. X    $(CC) $(CFLAGS) -c $*.c
  176. SHAR_EOF
  177. $TOUCH -am 1223101692 Makefile &&
  178. chmod 0644 Makefile ||
  179. echo "restore of Makefile failed"
  180. set `wc -c Makefile`;Wc_c=$1
  181. if test "$Wc_c" != "970"; then
  182.     echo original size 970, current size $Wc_c
  183. fi
  184. # ============= README ==============
  185. echo "x - extracting README (Text)"
  186. sed 's/^X//' << 'SHAR_EOF' > README &&
  187. X
  188. X                N e w j u n k
  189. X                -------------
  190. X
  191. X        Install new newsgroups by scanning the junk directory.
  192. X
  193. XWritten        2/91 by Michael A. Meiszl (mam@mamunx.garmhausen.de)
  194. XLast Update    12/92
  195. X
  196. XIf your systems receives news from more than one feed or from more than one
  197. Xnet, you sometimes notice your junk directory growing pretty fast. This is
  198. Xmostly due missing control messages from the nets. You can configure your
  199. Xnews software to install a new group automatically on reception of a newgroup
  200. Xcontrol message, but you can't do anything against a feed that decides to
  201. Xsend you more groups without notice.
  202. X
  203. XSo its up to the system operator to check junk concurrently and to decide 
  204. Xwhether he needs to install that new group by hand or whether it was only
  205. Xa crossposting from another net.
  206. X
  207. XManaging more than ones systems doubles the work of the operator and if this
  208. Xhappens quite every day (we got big feeds here :-(), it was time for a cute
  209. Xlittle program that does the work for me...
  210. X
  211. XNewjunk is a straightforward program which only reads through the junk direc-
  212. Xtory and scans for the "Newsgroups:" line in the message header. It exctracts
  213. Xthe wanted newsgroup(s) and checks against the active file.
  214. XNewjunk looks at the first (groupname) and fourth (statusflag) field of active.
  215. XIt should be fairly compatible with most news systems. B- and C- news are
  216. Xknown to work, others may vary.
  217. XIf the group is already there, nothing is done with it.
  218. XThis keeps track of the chance when B-news will eject an valid article because
  219. Xit is "too old".
  220. XIf the group is not installed, newjunks checks if the group leader is already
  221. Xthere. If not, the message is considered as a crossposting from another net
  222. Xand the message is thrown away. If the net is there and the group is new,
  223. Xnewjunk creates an call to inews gererating an newgroup control message for
  224. Xa given distribution.
  225. X
  226. XNormally you set this distribution to "local", so only
  227. Xyour system will be affected, but for managing more systems it is well suited
  228. Xto create an own distribution, so newjunk must only be run on the main machine.
  229. X
  230. XYou may prevent creating groups in existing nets by inserting a line which
  231. Xexcludes the top level group explictly:
  232. X    alt            0    0    x    
  233. X    alt.sex.pictures    0    0    m
  234. XThese lines will newjunk make new groups within the alt.sex.pictures hirarchie,
  235. Xbut not create any new alt groups.
  236. X
  237. XAfter newjunk is done it can start a normal script file which is executed by
  238. X/bin/sh. Look at my sample newjunk.sh for some ideas what you can get from it.
  239. XThe tasks done by the script could easily be placed in the program itself,
  240. Xbut a script is easier to adopt than fiddling with the code.
  241. X
  242. XINSTALLATION:
  243. XEdit the Makefile newjunk.h  and newjunks.sh for your needs then type "make".
  244. XYou can edit the message in newjunk.msg too, but please leave the copyright
  245. Xstatement in it.
  246. X
  247. XThis should build the executable in the local directory. You can test your 
  248. Xnstallation by calling "newjunk -t" which will do all scanning but no executing.
  249. XIt will inform you about unreachable files or directorys and scan your junkdir.
  250. XIf everything looks good, type "make install". This will copy newjunk and 
  251. Xnewjunk.sh into the news lib/bin directory and set permissions that it can
  252. Xbe executed by the owner of the news system (normally "news").
  253. X
  254. XNow su to the news user and edit its crontab entry. Add a line for newjunk.
  255. XRunning newjunk once a week or once a day depends on your traffic.
  256. X
  257. XMake sure its run before your junk expires!
  258. X
  259. XYour'e done and hopefully are rid of some work too...
  260. X
  261. XCOPYING:
  262. XThe program is put into the public domain, it may be copied and modificated
  263. Xwithout notice as long as the original author's name is included. The
  264. Xprogram may not be sold in any way. Especially semi-commercial "public-
  265. Xdomain-resellers" are discouraged to keep and sell this program. Mailboxes
  266. Xcan distribute it as long as they take no fee from there users.
  267. XIf major modifications are made, please send me the diffs.
  268. X
  269. XBUGREPORTS:
  270. X    Send diffs an bugreports to:    
  271. X        mam@mamunx.hamm.sub.org or mam@mamunx.garmhausen.de
  272. X        Michael A. Meiszl
  273. X        Tomsonstrasse 25
  274. X        D-W4700 Hamm 1
  275. X        Germany     
  276. SHAR_EOF
  277. $TOUCH -am 1223110592 README &&
  278. chmod 0644 README ||
  279. echo "restore of README failed"
  280. set `wc -c README`;Wc_c=$1
  281. if test "$Wc_c" != "4102"; then
  282.     echo original size 4102, current size $Wc_c
  283. fi
  284. # ============= newjunk.sh ==============
  285. echo "x - extracting newjunk.sh (Text)"
  286. sed 's/^X//' << 'SHAR_EOF' > newjunk.sh &&
  287. X:
  288. X# This is a sample application started from newjunk
  289. X# This script is only executed if one or more groups were added by newjunk
  290. X# 
  291. XBINDIR=/usr/lib/newsbin/contrib
  292. XNEWSDIR=/usr/lib/news
  293. X#
  294. XPATH=/bin:/usr/bin:/usr/local/bin:${BINDIR}
  295. X#
  296. Xcd ${NEWSDIR}
  297. X#
  298. X# CNEWS only. lock the news system from touching active
  299. X#
  300. Xlock="$NEWSDIR/LOCK"
  301. Xltmp="$NEWSDIR/L.$$"
  302. Xecho $$ >$ltmp
  303. Xtrap "rm -f $ltmp ; exit 0" 0 1 2 15
  304. Xwhile true 
  305. Xdo
  306. X    if /usr/lib/newsbin/newslock $ltmp $lock
  307. X    then
  308. X        trap "rm -f $ltmp $lock ; exit 0" 0 1 2 15
  309. X        break;
  310. X    fi
  311. X    sleep 5
  312. Xdone
  313. X#
  314. X# First, let's sort our active file so that the new installed groups fit
  315. X# neatly into the whole stuff
  316. X#
  317. X            sort -i -o active active
  318. X
  319. Xexit 0
  320. SHAR_EOF
  321. $TOUCH -am 1223105492 newjunk.sh &&
  322. chmod 0755 newjunk.sh ||
  323. echo "restore of newjunk.sh failed"
  324. set `wc -c newjunk.sh`;Wc_c=$1
  325. if test "$Wc_c" != "680"; then
  326.     echo original size 680, current size $Wc_c
  327. fi
  328. # ============= newjunk.c ==============
  329. echo "x - extracting newjunk.c (Text)"
  330. sed 's/^X//' << 'SHAR_EOF' > newjunk.c &&
  331. X/*
  332. X * newjunk written by Michael A. Meiszl (mam@mamnix.hamm.sub.org)
  333. X */
  334. X
  335. X#include "newjunk.h"
  336. X            /* your standard mailer */
  337. X
  338. X#define MAILCMD  "/bin/rmail"
  339. X
  340. X#define POSTMASTER    "postmaster"    /* Person who cares about news */
  341. X
  342. X#define MAXITEMS 5000    /* if anybody cares for space lower it, but wouldn't
  343. X               it be better if you spend some bucks on rams ???
  344. X            */
  345. X
  346. Xchar *files[MAXITEMS];    /* Array for filenames,
  347. X               junk sometimes gets pretty big
  348. X            */
  349. X
  350. Xstruct GROUP {
  351. X    char *name;
  352. X    char    flag;
  353. X    };
  354. X
  355. Xstruct GROUP groups[MAXITEMS]; /* Array for groups out of active file
  356. X               Currently I have 3154 groups online :-(((
  357. X            */
  358. X
  359. X#define MAXARRAYBOUNDS 90 /* How many new groups can we stock ? */
  360. X
  361. X            /* Array will hold new groupnames that we don't
  362. X               create automatically (eg new top level groups)
  363. X            */
  364. Xstruct newnets {
  365. X    char *newnets;
  366. X    int    count;
  367. X    } newnets[MAXARRAYBOUNDS];
  368. X
  369. Xint maxfiles=0,maxgroups=0,maxnewnets=0; /* Upper bounds of arrays */
  370. X
  371. Xint debug=0;        /*  Debug level. Currently only 9 does something
  372. X                special. Everything above 0 shows program
  373. X                progress
  374. X            */
  375. X
  376. Xint scriptflag=0;    /*  Incremented by every group that is newly
  377. X                installed. If a file argv[0].sh exists in
  378. X                the BIN directory it is executed if any
  379. X                group is created.
  380. X            */
  381. X
  382. X#ifdef HAVE_GETOPT
  383. Xextern char *optarg;
  384. X#endif
  385. X/*
  386. X * PANIC
  387. X *        Aborts program because of too low array configuration
  388. X * Return:    Never (I hope)
  389. X */
  390. X
  391. Xvoid panic(what)
  392. Xchar *what;
  393. X{
  394. Xfprintf(stderr,"Sysop! You have more than %d %s in your JUNK directory!\n",
  395. XMAXITEMS,what);
  396. Xfprintf(stderr,"Either you cleanup by hand or recompile newjunk with a higher MAXITEMS value!\n");
  397. Xfprintf(stderr,"NEWJUNK: I give up!\n");
  398. Xexit(2);
  399. X}
  400. X
  401. X/*
  402. X * USAGE
  403. X *        a nice little routine which only tells the user about his
  404. X *        stupidity :-)
  405. X */
  406. Xvoid usage()
  407. X{
  408. X    printf("Usage: newjunk [-t] [-d NUM]\n");
  409. X    printf("        -t = testmode (show only, do nothing)\n");
  410. X    printf("        -d = debug level (9=testmode)\n");
  411. X    exit(0);
  412. X}
  413. X/*
  414. X * READIN
  415. X *        reads the junk directory and copies filenames into the
  416. X *        files[] array.
  417. X * Return:    0 if successful, -1 if open failiure
  418. X */
  419. Xint readin()
  420. X{
  421. X    char l[255];
  422. X    DIR *D;
  423. X    struct dirent *dir;
  424. X
  425. X    if (D=opendir(JUNKDIR)) {
  426. X        while (dir=readdir(D)) {
  427. X            if (*dir->d_name=='.') continue;
  428. X            files[maxfiles++]=strdup(dir->d_name);
  429. X            if (maxfiles>=MAXITEMS) panic("files");
  430. X        }
  431. X        closedir(D);
  432. X        return 0;
  433. X    }
  434. X    return -1;
  435. X}
  436. X
  437. X/*
  438. X * READACTIVE
  439. X *        reads the active file in and copies the groupnames to
  440. X *        the array groups[]
  441. X * Returns:    0 if successful, -1 can't read active file
  442. X */
  443. Xint readactive()
  444. X{
  445. X    FILE *F;
  446. X    char l[255];
  447. X    char gname[255],xflag[255];
  448. X
  449. X    if (!(F=fopen(ACTIVE,"r"))) return -1;
  450. X    while (fgets(l,255,F)) {
  451. X        sscanf(l,"%s %*s %*s %s",gname,xflag);
  452. X        groups[maxgroups].name=strdup(gname);
  453. X        groups[maxgroups++].flag=*xflag;
  454. X
  455. X        if (debug>7)
  456. X            fprintf(stderr,"Group\t%s\t\t Flag <%c>\n",
  457. X                groups[maxgroups-1].name,
  458. X                groups[maxgroups-1].flag);
  459. X
  460. X        if (maxgroups>=MAXITEMS) panic("groups");
  461. X        }
  462. X    fclose(F);
  463. X    return 0;
  464. X}
  465. X
  466. X/*
  467. X * ADDGROUP
  468. X *        adds a new group to the array groups[] and calls INEWS to
  469. X *        create this group.
  470. X * Returns:    NOTHING or panics if array overflow
  471. X */
  472. Xaddgroup(which)
  473. Xchar *which;
  474. X{
  475. X    char l[255];
  476. X    FILE *P,*F;
  477. X
  478. X    if (maxgroups>=MAXITEMS) panic ("groups");
  479. X
  480. X    groups[maxgroups  ].name=strdup(which);
  481. X    groups[maxgroups++].flag='y';
  482. X
  483. X/*
  484. X * build system() command line
  485. X */
  486. X#ifdef CNEWS
  487. X    sprintf (l,"%s -h ",INEWS);
  488. X    if (P=popen(l,"w")) {
  489. X        fprintf(P,"Control: newgroup %s\n",which);
  490. X        fprintf(P,"Subject: newgroup %s\n",which);
  491. X        fprintf(P,"Newsgroups: %s\n",which);
  492. X        fprintf(P,"Approved: %s\n",APPROVED);
  493. X#ifdef DISTRIBUTION
  494. X        fprintf(P,"Distribution: %s\n",DISTRIBUTION);
  495. X#endif
  496. X        fprintf(P,"\n");
  497. X        sprintf(l,"%s/newjunk.msg",BINDIR);
  498. X
  499. X        if (F=fopen(l,"r")) {
  500. X            while (fgets(l,255,F)) fputs(l,P);
  501. X            fclose(F);
  502. X            }
  503. X        pclose(P);
  504. X        scriptflag+=1;
  505. X#ifdef CNEWS
  506. X#ifndef CNEWSSPEEDUPVERSION
  507. X        /* Inews forks too much on CNEWS, have a nice time sleeping */
  508. X        sleep(30);
  509. X#else
  510. X        sleep(2);
  511. X#endif
  512. X#endif
  513. X        return 0;
  514. X    }
  515. X    perror("Can't pipe to INEWS");
  516. X    exit(-1);
  517. X
  518. X#else
  519. X    strcpy (l,INEWS);
  520. X#ifdef DISTRIBUTION
  521. X    strcat (l," -d ");
  522. X    strcat (l,DISTRIBUTION);
  523. X#endif
  524. X    strcat (l," -C ");
  525. X    strcat (l,which);
  526. X    strcat (l," < ");
  527. X    strcat (l,BINDIR);
  528. X    strcat (l,"/");
  529. X    strcat (l,"newjunk.msg");
  530. X
  531. X    if (debug) fprintf(stderr,"Executing:<%s>\n",l);
  532. X
  533. X/*
  534. X * Execute command line with a read pipe
  535. X * So we can get rid of inews output and keep pretty calm during crontab work
  536. X * Why bother the sysop? He will get mail from the news system soon...
  537. X */
  538. X    if (debug<9)
  539. X        if (P=popen(l,"r")) {
  540. X            while(fgets(l,255,P)) {
  541. X                if(debug) printf("INEWS:%s",l);
  542. X                }
  543. X            pclose(P);
  544. X/*
  545. X * Increment flag, so that MAIN can decide if it should start the script
  546. X */
  547. X            scriptflag+=1;
  548. X            return 0;
  549. X            }
  550. X        else 
  551. X            {
  552. X            perror("Can't Pipe to INEWS");
  553. X            exit(1);
  554. X            }
  555. X    else {
  556. X        fprintf(stderr,"no exec! just testing!\n");
  557. X        scriptflag+=1; /* fake it */
  558. X          }
  559. X#endif
  560. X    return 0;
  561. X}
  562. X
  563. X/*
  564. X * LOOKUP
  565. X *        searches the groups[] array for a given group
  566. X *        It is a poor linear scan, but who cares???
  567. X *        qsorting and bsearching maybe thousends of times faster,
  568. X *        but are not that portable as this routine
  569. X * Returns:    0 if group has been added, -1 if group already exists
  570. X */
  571. Xlookup(what)
  572. Xchar *what;
  573. X{
  574. X    register int i,len;
  575. X    register char *s;
  576. X
  577. X/*
  578. X * the stupid line parsing routine occasionally creates NULL strings, so
  579. X * we eliminate them here
  580. X */
  581. X    if (!strlen(what)) return -1;
  582. X
  583. X    if (debug) fprintf (stderr,"searching for %s:",what);
  584. X/*
  585. X * first we scan for the whole group name
  586. X */
  587. X    for (i=0;i<maxgroups;i++)
  588. X        if (!strcmp(groups[i].name,what)) {
  589. X            if (debug) fprintf (stderr," already there\n");
  590. X            return -1;
  591. X            }
  592. X/*
  593. X * Now, let's take a closer look to the net
  594. X * If the first part of the group does not exist, don't add this group, it
  595. X * may be a crossposting only.
  596. X * Added 12/23/92: if net is exluded in active, ("x") don't add that group!
  597. X *
  598. X * SYSOP NOTE: Since this program will never create a new net, you have to 
  599. X * take care about that by yourself. If you don't bother, define NETCREATION
  600. X * in the header file...
  601. X */
  602. X    if (debug) fprintf (stderr," not there! checking net ");
  603. X    s=strchr(what,'.');
  604. X    if (!s) {
  605. X        if (debug) fprintf (stderr,": No TOP level allowed!\n");
  606. X        return -1; /* This would be a top-top level.
  607. X                  I don't believe that...
  608. X               */
  609. X        }
  610. X
  611. X#ifndef NETCREATION
  612. X    *s=(char) 0;
  613. X    len=strlen(what);
  614. X    if (debug) fprintf(stderr,"%s:",what);
  615. X    *s=(char) '.'; /* in case we forget it later ... */
  616. X    for (i=0;i<maxgroups;i++)
  617. X        if (!strncmp(groups[i].name,what,len)) {
  618. X             if (debug) fprintf(stderr," ok, found %s\n",groups[i].name);
  619. X            if (groups[i].flag=='x') {
  620. X                if (debug) fprintf(stderr,"net excluded in active %s\n",what);
  621. X                addnew(what);
  622. X                return -1;
  623. X                }
  624. X            break;
  625. X            }
  626. X    if (i>=maxgroups) {
  627. X        if (debug) fprintf(stderr," new net, not allowed\n");
  628. X        addnew(what);
  629. X        return -1;
  630. X        }
  631. X#endif
  632. X/*
  633. X * otherwise do your job...
  634. X */
  635. X    if (debug) fprintf(stderr,"Installing new group %s\n",what);
  636. X    addgroup(what);
  637. X    return 0;
  638. X}
  639. X
  640. X/*
  641. X * SCAN_MESSAGE
  642. X *        reads the message specified as name and searches for the
  643. X *        "Newsgroups:" line. This line is broken up and fed into lookup.
  644. X * Returns:    0 if ok, -1 if message is unreadable
  645. X */
  646. Xscan_message(name)
  647. Xchar *name;
  648. X{
  649. X    char l[255],*s,*t;
  650. X    FILE *F;
  651. X
  652. X    sprintf(l,"%s/%s",JUNKDIR,name);
  653. X    if (!(F=fopen(l,"r"))) return -1;
  654. X    while (fgets(l,255,F)) {
  655. X        s=strrchr(l,'\n');
  656. X        if (s) *s=(char) 0;
  657. X        if (!strlen(l)) {
  658. X        if (debug) fprintf(stderr,"%s: no Newsgroups line!\n",name);
  659. X            break; /* End of Header */
  660. X            }
  661. X        if (!strncmp(l,"Newsgroups: ",12)) {
  662. X            s=l+12;
  663. X/*
  664. X * Pardon me this GOTO. It much more effective as strtok would be.
  665. X */
  666. Xredo:
  667. X            t=s;
  668. X            while (*t && *t!=' ' && *t!='\t' && *t!=',') t++;
  669. X            if (*t) {
  670. X                *t++=(char) 0;
  671. X                lookup(s);
  672. X            while (*t && (*t==' ' || *t=='\t' || *t==',')) t++;
  673. X                s=t;
  674. X                goto redo;
  675. X                }
  676. X            if (s) lookup(s);
  677. X            break;
  678. X            }
  679. X        }
  680. X    fclose(F);
  681. X    return 0;
  682. X}
  683. X
  684. X/*
  685. X * ADDNEW
  686. X *    mantains a list of new groups which are not automatically created
  687. X *    because of the missing top level group or exclusion in active.
  688. X *    These collected groupnames are mailed to the postmaster.
  689. X *    Quite an easy task, we only have to care about overrunning our array-
  690. X *    bounds and not to disturb POSTMASTER with thousends of messages in
  691. X *    one single group.
  692. X */
  693. X
  694. Xaddnew(groupname)
  695. Xchar *groupname;
  696. X{
  697. X    register int i;
  698. X
  699. X    if (maxnewnets>=MAXARRAYBOUNDS) {
  700. X        mail_to_postmaster();
  701. X        for (i=0;i<maxnewnets;i++) {
  702. X            free (newnets[i].newnets);
  703. X            newnets[i].count=0;
  704. X            }
  705. X        maxnewnets=0;
  706. X        }
  707. X
  708. X    if (maxnewnets) {
  709. X        for (i=0;i<maxnewnets;i++) {
  710. X            if (!strcmp(newnets[i].newnets,groupname)) {
  711. X                newnets[i].count+=1;
  712. X                return 0;
  713. X                }
  714. X            }
  715. X        }
  716. X    newnets[maxnewnets].newnets=strdup(groupname);
  717. X    newnets[maxnewnets].count=1;
  718. X    maxnewnets++;
  719. X    return 1;
  720. X}
  721. X
  722. X/*
  723. X * MAIL_TO_POSTMASTER
  724. X *    sends a nice letter which contains all uncreated new groups from
  725. X *    junk to the person defined in POSTMASTER
  726. X */
  727. Xmail_to_postmaster()
  728. X{
  729. X    char pname[80];
  730. X    int    i;
  731. X    FILE    *PIPE;
  732. X
  733. X    if (maxnewnets) {
  734. X        sprintf (pname,"%s %s",MAILCMD,POSTMASTER);
  735. X        if (debug) fprintf(stderr,"Executing %s\n",pname);
  736. X        if (PIPE=popen(pname,"w")) {
  737. X            fprintf(PIPE,"Subject: uncreated groups from newjunk\n\n");
  738. X            for (i=0;i<maxnewnets;i++)
  739. X                fprintf(PIPE,"\t%3d\t%s\n",
  740. X                    newnets[i].count,
  741. X                    newnets[i].newnets);
  742. X            fprintf(PIPE,"\nPlease take care of these groups.\n\tnewjunk\n");
  743. X            pclose(PIPE);
  744. X            }
  745. X        }        
  746. X}
  747. X    
  748. X/*
  749. X * MAIN
  750. X *    nothing to worry about, it just calles the reading routines and 
  751. X *    calls SCAN_MESSAGE for every entry of the files[] array
  752. X *
  753. X * Returns:    I hope so :-)
  754. X */
  755. Xmain(argc,argv)
  756. Xint argc;
  757. Xchar *argv[];
  758. X{
  759. X    int i;
  760. X    char script[255];
  761. X
  762. X    debug=0;
  763. X
  764. X
  765. X#ifdef HAVE_GETOPT
  766. X
  767. X    while ((i=getopt(argc,argv,"td:v:x:"))!=EOF) {
  768. X        switch (i) {
  769. X            case 'd':
  770. X            case 'v':
  771. X            case 'x':    debug=atoi(optarg); break;
  772. X            case 't':    debug=9; break;
  773. X            default :    usage();
  774. X            }
  775. X        }
  776. X#else
  777. X    if (argc>1) debug=atoi(argv[1]); /* stupid, but reliable :-) */
  778. X#endif
  779. X
  780. X    
  781. X/*
  782. X *     build filename for script
  783. X */
  784. X    sprintf(script,"%s/%s.sh",BINDIR,argv[0]);
  785. X
  786. X    if (debug) fprintf (stderr,"Reading JUNK directory: ");
  787. X    if (readin()) {
  788. X        perror("readin");
  789. X        exit(1);
  790. X        }
  791. X    if (debug) fprintf (stderr,"%d files found\n",maxfiles);
  792. X    if (debug) fprintf (stderr,"Reading ACTIVE file: ");
  793. X    if (readactive()) {
  794. X        perror("readactive");
  795. X        exit(1);
  796. X        }
  797. X    if (debug) fprintf (stderr,"%d groups found\n",maxgroups);
  798. X    for (i=0;i<maxfiles;i++) {
  799. X        if (debug) fprintf(stderr,"Scanning message %s\n",files[i]);
  800. X        scan_message(files[i]);
  801. X        }
  802. X    if (debug) fprintf(stderr,"%s: installed %d new group%s\n",
  803. X            argv[0],scriptflag,
  804. X            scriptflag>1?"s":"");
  805. X    if (scriptflag) {
  806. X        if (debug) fprintf(stderr,"%s: ready to start %s\n",
  807. X            argv[0],script);
  808. X        if (!access(script,1)) {
  809. X            if (debug!=9) i=system(script); else i=-1;
  810. X            if (debug) fprintf(stderr,"%s: exit status %d\n",
  811. X                argv[0],i);
  812. X            }
  813. X        }
  814. X    mail_to_postmaster();
  815. X    exit(0);
  816. X}
  817. X
  818. SHAR_EOF
  819. $TOUCH -am 1223103592 newjunk.c &&
  820. chmod 0644 newjunk.c ||
  821. echo "restore of newjunk.c failed"
  822. set `wc -c newjunk.c`;Wc_c=$1
  823. if test "$Wc_c" != "10878"; then
  824.     echo original size 10878, current size $Wc_c
  825. fi
  826. # ============= newjunk.h ==============
  827. echo "x - extracting newjunk.h (Text)"
  828. sed 's/^X//' << 'SHAR_EOF' > newjunk.h &&
  829. X/*
  830. X * NewJunk written 1991 by Michael A. Meiszl (mam@mamnix.hamm.sub.org)
  831. X *
  832. X * This version runs under SCO XENIX V2.3.3 but does nothing, any other
  833. X * unix brand could not do either.
  834. X *
  835. X * The only thing you must take care about is where your header file for
  836. X * the directory reading routines (opendir,readdir,closedir) is located.
  837. X * Look under sys/ndir.h or dir.h or dirent.h.
  838. X *
  839. X * If you make major changes in the code, please send me the diffs.
  840. X */
  841. X
  842. X/*
  843. X * some defines you like to change
  844. X */
  845. X
  846. X#define JUNKDIR "/usr/spool/news/junk"    /* where the junk is located */
  847. X#define INEWS "/bin/inews"    /* my favorite news software */
  848. X
  849. X/*
  850. X * BINDIR tells the program where to look for its shell script
  851. X * The script is named as the program but with a suffix ".sh"
  852. X * normally its called "newjunk.sh"
  853. X * If the script is ommited or not executable, no harm is done.
  854. X * The script is mainly for tidying up and other stupid things your
  855. X * system may require.
  856. X */
  857. X#define BINDIR "/usr/lib/newsbin/contrib"
  858. X
  859. X/*
  860. X * DISTRIBUTION tells the news software how far to spread the control
  861. X * message. Please don't make it "world" you will certainly annoy some-
  862. X * body. Keep it "local" as long as you don't manage more than one 
  863. X * system, otherwise make your own one (AND TELL IT TO YOUR NEWS-SOFT!)
  864. X */
  865. X/*#undef DISTRIBUTION            /* don't want any, use default */
  866. X#define DISTRIBUTION "local"        /* normal case */
  867. X/*#define DISTRIBUTION "mamnix"        /* I have my own */
  868. X
  869. X/*
  870. X * For CNEWS we need to generate the newgroup message by ourselves. So we
  871. X * need a person who is resposible for this.
  872. X */
  873. X#ifdef CNEWS
  874. X#define APPROVED "usenet@mamunx.hamm.sub.org"
  875. X#endif
  876. X/*
  877. X * this is where the news software keeps its groups
  878. X */
  879. X
  880. X#define ACTIVE "/usr/lib/news/active"
  881. X
  882. X/*
  883. X * if you have getopt(s) define this
  884. X */
  885. X#define HAVE_GETOPT
  886. X
  887. X/*
  888. X * if you like to create new nets automatically, define this
  889. X */
  890. X#undef NETCREATION
  891. X
  892. X#ifdef M_XENIX
  893. X#define SYSV
  894. X#endif
  895. X
  896. X#include <stdio.h>
  897. X#ifdef SYSV
  898. X/*
  899. X * we need FILE and string definitions
  900. X */
  901. X#include <fcntl.h>
  902. X#include <string.h>
  903. X#else
  904. X/*
  905. X * I suppose BSD needs this one
  906. X */
  907. X#include <strings.h>
  908. X#endif
  909. X
  910. X#include <sys/types.h>
  911. X
  912. X/*
  913. X * this one is subject to be different on your system. 
  914. X */
  915. X#include <dirent.h>
  916. SHAR_EOF
  917. $TOUCH -am 1231110691 newjunk.h &&
  918. chmod 0644 newjunk.h ||
  919. echo "restore of newjunk.h failed"
  920. set `wc -c newjunk.h`;Wc_c=$1
  921. if test "$Wc_c" != "2224"; then
  922.     echo original size 2224, current size $Wc_c
  923. fi
  924. # ============= newjunk.msg ==============
  925. echo "x - extracting newjunk.msg (Text)"
  926. sed 's/^X//' << 'SHAR_EOF' > newjunk.msg &&
  927. XThis group is automatically created by newjunk
  928. Xwritten 12/92 by Michael A. Meiszl (mam@mamunx.garmhausen.de)
  929. SHAR_EOF
  930. $TOUCH -am 1223110592 newjunk.msg &&
  931. chmod 0644 newjunk.msg ||
  932. echo "restore of newjunk.msg failed"
  933. set `wc -c newjunk.msg`;Wc_c=$1
  934. if test "$Wc_c" != "109"; then
  935.     echo original size 109, current size $Wc_c
  936. fi
  937. exit 0
  938. -- 
  939. ** Michael Andreas Meiszl | Tomsonstr 25 | 4700 Hamm 1 | Tel +49 2381 980131 **
  940.