| 1 |
--- /dev/null |
| 2 |
+++ b/extra/cch/control/checkgroups.pl |
| 3 |
@@ -0,0 +1,82 @@ |
| 4 |
+## $Id: checkgroups.pl,v 1.2 2001/07/19 00:32:56 rra Exp $ |
| 5 |
+## |
| 6 |
+## checkgroups control message handler. |
| 7 |
+## |
| 8 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 9 |
+## |
| 10 |
+## Redistribution and use in source and binary forms, with or without |
| 11 |
+## modification, are permitted provided that the following conditions |
| 12 |
+## are met: |
| 13 |
+## |
| 14 |
+## 1. Redistributions of source code must retain the above copyright |
| 15 |
+## notice, this list of conditions and the following disclaimer. |
| 16 |
+## |
| 17 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 18 |
+## notice, this list of conditions and the following disclaimer in the |
| 19 |
+## documentation and/or other materials provided with the distribution. |
| 20 |
+ |
| 21 |
+use strict; |
| 22 |
+ |
| 23 |
+sub control_checkgroups { |
| 24 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 25 |
+ $headers, $body) = @_; |
| 26 |
+ my ($newsgrouppats) = @$par; |
| 27 |
+ |
| 28 |
+ if ($action eq 'mail') { |
| 29 |
+ my $mail = sendmail("checkgroups by $sender"); |
| 30 |
+ print $mail "$sender posted the following checkgroups message:\n"; |
| 31 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 32 |
+ print $mail <<END; |
| 33 |
+ |
| 34 |
+If you want to process it, feed the body |
| 35 |
+of the message to docheckgroups while logged |
| 36 |
+in as user ID "$inn::newsuser": |
| 37 |
+ |
| 38 |
+$inn::controlprogs/docheckgroups '$newsgrouppats' <<zRbJ |
| 39 |
+END |
| 40 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 41 |
+ print $mail "zRbJ\n"; |
| 42 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 43 |
+ } elsif ($action eq 'log') { |
| 44 |
+ if ($log) { |
| 45 |
+ logger($log, "checkgroups by $sender", $headers, $body); |
| 46 |
+ } else { |
| 47 |
+ logmsg("checkgroups by $sender"); |
| 48 |
+ } |
| 49 |
+ } elsif ($action eq 'doit') { |
| 50 |
+ if (defined &local_docheckgroups) { |
| 51 |
+ local_docheckgroups($body, $newsgrouppats, $log, $sender); |
| 52 |
+ } else { |
| 53 |
+ docheckgroups($body, $newsgrouppats, $log, $sender); |
| 54 |
+ } |
| 55 |
+ } |
| 56 |
+} |
| 57 |
+ |
| 58 |
+sub docheckgroups { |
| 59 |
+ my ($body, $newsgrouppats, $log, $sender) = @_; |
| 60 |
+ |
| 61 |
+ my $tempfile = "$inn::tmpdir/checkgroups.$$"; |
| 62 |
+ open(TEMPART, ">$tempfile.art") |
| 63 |
+ or logdie("Cannot open $tempfile.art: $!"); |
| 64 |
+ print TEMPART map { s/^~/~~/; "$_\n" } @$body; |
| 65 |
+ close TEMPART; |
| 66 |
+ |
| 67 |
+ open(OLDIN, '<&STDIN') or die $!; |
| 68 |
+ open(OLDOUT, '>&STDOUT') or die $!; |
| 69 |
+ open(STDIN, "$tempfile.art") or die $!; |
| 70 |
+ open(STDOUT, ">$tempfile") or die $!; |
| 71 |
+ my $st = system("$inn::controlprogs/docheckgroups", $newsgrouppats); |
| 72 |
+ logdie('Cannot run docheckgroups: ' . $!) if $st == -1; |
| 73 |
+ logdie('docheckgroups returned status ' . ($st & 255)) if $st > 0; |
| 74 |
+ open(STDIN, '<&OLDIN') or die $!; |
| 75 |
+ open(STDOUT, '>&OLDOUT') or die $!; |
| 76 |
+ |
| 77 |
+ open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!"); |
| 78 |
+ my @output = <TEMPFILE>; |
| 79 |
+ chop @output; |
| 80 |
+ logger($log || 'mail', "checkgroups by $sender", \@output); |
| 81 |
+ close TEMPFILE; |
| 82 |
+ unlink($tempfile, "$tempfile.art"); |
| 83 |
+} |
| 84 |
+ |
| 85 |
+1; |
| 86 |
--- /dev/null |
| 87 |
+++ b/extra/cch/control/ihave.pl |
| 88 |
@@ -0,0 +1,58 @@ |
| 89 |
+## $Id: ihave.pl,v 1.3 2001/07/19 00:32:56 rra Exp $ |
| 90 |
+## |
| 91 |
+## ihave control message handler. |
| 92 |
+## |
| 93 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 94 |
+## |
| 95 |
+## Redistribution and use in source and binary forms, with or without |
| 96 |
+## modification, are permitted provided that the following conditions |
| 97 |
+## are met: |
| 98 |
+## |
| 99 |
+## 1. Redistributions of source code must retain the above copyright |
| 100 |
+## notice, this list of conditions and the following disclaimer. |
| 101 |
+## |
| 102 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 103 |
+## notice, this list of conditions and the following disclaimer in the |
| 104 |
+## documentation and/or other materials provided with the distribution. |
| 105 |
+ |
| 106 |
+use strict; |
| 107 |
+ |
| 108 |
+sub control_ihave { |
| 109 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 110 |
+ $headers, $body) = @_; |
| 111 |
+ |
| 112 |
+ if ($action eq 'mail') { |
| 113 |
+ my $mail = sendmail("ihave by $sender"); |
| 114 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 115 |
+ close $mail or logdie('Cannot send mail: ' . $!); |
| 116 |
+ } elsif ($action eq 'log') { |
| 117 |
+ if ($log) { |
| 118 |
+ logger($log, "ihave $sender", $headers, $body); |
| 119 |
+ } else { |
| 120 |
+ logmsg("ihave $sender"); |
| 121 |
+ } |
| 122 |
+ } elsif ($action eq 'doit') { |
| 123 |
+ my $tempfile = "$inn::tmpdir/ihave.$$"; |
| 124 |
+ open(GREPHIST, "|grephistory -i > $tempfile") |
| 125 |
+ or logdie('Cannot run grephistory: ' . $!); |
| 126 |
+ foreach (@$body) { |
| 127 |
+ print GREPHIST "$_\n"; |
| 128 |
+ } |
| 129 |
+ close GREPHIST; |
| 130 |
+ |
| 131 |
+ if (-s $tempfile) { |
| 132 |
+ my $inews = open("$inn::inews -h") |
| 133 |
+ or logdie('Cannot run inews: ' . $!); |
| 134 |
+ print $inews "Newsgroups: to.$site\n" |
| 135 |
+ . "Subject: cmsg sendme $inn::pathhost\n" |
| 136 |
+ . "Control: sendme $inn::pathhost\n\n"; |
| 137 |
+ open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!"); |
| 138 |
+ print $inews $_ while <TEMPFILE>; |
| 139 |
+ close $inews or die $!; |
| 140 |
+ close TEMPFILE; |
| 141 |
+ } |
| 142 |
+ unlink $tempfile; |
| 143 |
+ } |
| 144 |
+} |
| 145 |
+ |
| 146 |
+1; |
| 147 |
--- /dev/null |
| 148 |
+++ b/extra/cch/control/newgroup.pl |
| 149 |
@@ -0,0 +1,186 @@ |
| 150 |
+## $Id: newgroup.pl,v 1.3 2001/07/19 00:32:56 rra Exp $ |
| 151 |
+## |
| 152 |
+## newgroup control message handler. |
| 153 |
+## |
| 154 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 155 |
+## |
| 156 |
+## Redistribution and use in source and binary forms, with or without |
| 157 |
+## modification, are permitted provided that the following conditions |
| 158 |
+## are met: |
| 159 |
+## |
| 160 |
+## 1. Redistributions of source code must retain the above copyright |
| 161 |
+## notice, this list of conditions and the following disclaimer. |
| 162 |
+## |
| 163 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 164 |
+## notice, this list of conditions and the following disclaimer in the |
| 165 |
+## documentation and/or other materials provided with the distribution. |
| 166 |
+ |
| 167 |
+use strict; |
| 168 |
+ |
| 169 |
+sub control_newgroup { |
| 170 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 171 |
+ $headers, $body) = @_; |
| 172 |
+ my ($groupname, $modflag) = @$par; |
| 173 |
+ |
| 174 |
+ $modflag ||= ''; |
| 175 |
+ my $modcmd = $modflag eq 'moderated' ? 'm' : 'y'; |
| 176 |
+ |
| 177 |
+ my $errmsg; |
| 178 |
+ $errmsg= local_checkgroupname($groupname) if defined &local_checkgroupname; |
| 179 |
+ if ($errmsg) { |
| 180 |
+ $errmsg = checkgroupname($groupname) if $errmsg eq 'DONE'; |
| 181 |
+ } |
| 182 |
+ |
| 183 |
+ if ($errmsg) { |
| 184 |
+ if ($log) { |
| 185 |
+ logger($log, "skipping newgroup ($errmsg)", $headers, $body); |
| 186 |
+ } else { |
| 187 |
+ logmsg("skipping newgroup ($errmsg)"); |
| 188 |
+ } |
| 189 |
+ return; |
| 190 |
+ } |
| 191 |
+ |
| 192 |
+ # Scan active to see what sort of change we are making. |
| 193 |
+ open(ACTIVE, $inn::active) or logdie("Cannot open $inn::active: $!"); |
| 194 |
+ my @oldgroup; |
| 195 |
+ while (<ACTIVE>) { |
| 196 |
+ next unless /^(\Q$groupname\E)\s\d+\s\d+\s(\w)/; |
| 197 |
+ @oldgroup = split /\s+/; |
| 198 |
+ last; |
| 199 |
+ } |
| 200 |
+ close ACTIVE; |
| 201 |
+ my $status; |
| 202 |
+ if (@oldgroup) { |
| 203 |
+ if ($oldgroup[3] eq 'm' and $modflag ne 'moderated') { |
| 204 |
+ $status = 'made unmoderated'; |
| 205 |
+ } elsif ($oldgroup[3] ne 'm' and $modflag eq 'moderated') { |
| 206 |
+ $status = 'made moderated'; |
| 207 |
+ } else { |
| 208 |
+ $status = 'no change'; |
| 209 |
+ } |
| 210 |
+ } elsif (not $approved) { |
| 211 |
+ $status = 'unapproved'; |
| 212 |
+ } else { |
| 213 |
+ $status = 'created'; |
| 214 |
+ } |
| 215 |
+ |
| 216 |
+ if ($action eq 'mail' and $status !~ /no change|unapproved/) { |
| 217 |
+ my $mail = sendmail("newgroup $groupname $modcmd $sender"); |
| 218 |
+ print $mail <<END; |
| 219 |
+$sender asks for $groupname |
| 220 |
+to be $status. |
| 221 |
+ |
| 222 |
+If this is acceptable, type: |
| 223 |
+ $inn::newsbin/ctlinnd newgroup $groupname $modcmd $sender |
| 224 |
+ |
| 225 |
+The control message follows: |
| 226 |
+ |
| 227 |
+END |
| 228 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 229 |
+ print $mail "\n"; |
| 230 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 231 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 232 |
+ } elsif ($action eq 'log') { |
| 233 |
+ if ($log) { |
| 234 |
+ logger($log, "skipping newgroup $groupname $modcmd" |
| 235 |
+ . " $sender (would be $status)", $headers, $body); |
| 236 |
+ } else { |
| 237 |
+ logmsg("skipping newgroup $groupname $modcmd $sender" |
| 238 |
+ . " (would be $status)"); |
| 239 |
+ } |
| 240 |
+ } elsif ($action eq 'doit' and $status ne 'unapproved') { |
| 241 |
+ ctlinnd('newgroup', $groupname, $modcmd, $sender) |
| 242 |
+ if $status ne 'no change'; |
| 243 |
+ |
| 244 |
+ # If there is a tag line, update newsgroups too, even if the group |
| 245 |
+ # did already exist. |
| 246 |
+ my $found = 0; |
| 247 |
+ my $ngline = ''; |
| 248 |
+ foreach (@$body) { |
| 249 |
+ if ($found) { |
| 250 |
+ $ngline = $_; |
| 251 |
+ last; |
| 252 |
+ } |
| 253 |
+ $found = 1 if $_ eq 'For your newsgroups file:'; |
| 254 |
+ } |
| 255 |
+ my ($ngname, $ngdesc) = split(/\s+/, $ngline, 2); |
| 256 |
+ if ($ngdesc) { |
| 257 |
+ $ngdesc =~ s/\s+$//; |
| 258 |
+ $ngdesc =~ s/\s+\(moderated\)\s*$//i; |
| 259 |
+ $ngdesc .= ' (Moderated)' if $modflag eq 'moderated'; |
| 260 |
+ } |
| 261 |
+ update_desc($ngname, $ngdesc) if $ngdesc and $ngname eq $groupname; |
| 262 |
+ |
| 263 |
+ logger($log, "newgroup $groupname $modcmd $status $sender", |
| 264 |
+ $headers, $body) if $log; |
| 265 |
+ } |
| 266 |
+ return; |
| 267 |
+} |
| 268 |
+ |
| 269 |
+sub update_desc { |
| 270 |
+ my ($name, $desc) = @_; |
| 271 |
+ shlock("$inn::locks/LOCK.newsgroups"); |
| 272 |
+ my $tempfile = "$inn::newsgroups.$$"; |
| 273 |
+ open(NEWSGROUPS, $inn::newsgroups) |
| 274 |
+ or logdie("Cannot open $inn::newsgroups: $!"); |
| 275 |
+ open(TEMPFILE, ">$tempfile") or logdie("Cannot open $tempfile: $!"); |
| 276 |
+ my $olddesc = ''; |
| 277 |
+ while (<NEWSGROUPS>) { |
| 278 |
+ if (/^\Q$name\E\s+(.*)/) { |
| 279 |
+ $olddesc = $1; |
| 280 |
+ next; |
| 281 |
+ } |
| 282 |
+ print TEMPFILE $_; |
| 283 |
+ } |
| 284 |
+ print TEMPFILE "$name\t$desc\n"; |
| 285 |
+ close TEMPFILE; |
| 286 |
+ close NEWSGROUPS; |
| 287 |
+ # install the modified file only if the description has changed |
| 288 |
+ if ($desc ne $olddesc) { |
| 289 |
+ rename($tempfile, $inn::newsgroups) |
| 290 |
+ or logdie("Cannot rename $tempfile: $!"); |
| 291 |
+ } else { |
| 292 |
+ unlink($tempfile); |
| 293 |
+ } |
| 294 |
+ unlink("$inn::locks/LOCK.newsgroups", $tempfile); |
| 295 |
+} |
| 296 |
+ |
| 297 |
+# Check the group name. This is partially derived from C News. |
| 298 |
+# Some checks are commented out if I think they're too strict or |
| 299 |
+# language-dependent. Your mileage may vary. |
| 300 |
+sub checkgroupname { |
| 301 |
+ local $_ = shift; |
| 302 |
+ |
| 303 |
+ # whole-name checking |
| 304 |
+ return 'Empty group name' if /^$/; |
| 305 |
+ return 'Whitespace in group name' if /\s/; |
| 306 |
+ return 'unsafe group name' if /[\`\/:;]/; |
| 307 |
+ return 'Bad dots in group name' if /^\./ or /\.$/ or /\.\./; |
| 308 |
+# return 'Group name does not begin/end with alphanumeric' |
| 309 |
+# if (/^[a-zA-Z0-9].+[a-zA-Z0-9]$/; |
| 310 |
+ return 'Group name begins in control. or junk.' if /^(?:junk|control)\./; |
| 311 |
+# return 'Group name too long' if length $_ > 128; |
| 312 |
+ |
| 313 |
+ my @components = split(/\./); |
| 314 |
+ # prevent alt.a.b.c.d.e.f.g.w.x.y.z... |
| 315 |
+ return 'Too many components' if $#components > 9; |
| 316 |
+ |
| 317 |
+ # per-component checking |
| 318 |
+ for (my $i = 0; $i <= $#components; $i++) { |
| 319 |
+ local $_ = $components[$i]; |
| 320 |
+ return 'all-numeric name component' if /^[0-9]+$/; |
| 321 |
+# return 'name component starts with non-alphanumeric' if /^[a-zA-Z0-9]/; |
| 322 |
+# return 'name component does not contain letter' if not /[a-zA-Z]/; |
| 323 |
+ return "`all' or `ctl' used as name component" if /^(?:all|ctl)$/; |
| 324 |
+# return 'name component longer than 30 characters' if length $_ > 30; |
| 325 |
+# return 'uppercase letter(s) in name' if /[A-Z]/; |
| 326 |
+ return 'illegal character(s) in name' if /[^a-z0-9+_\-.]/; |
| 327 |
+ # sigh, c++ etc must be allowed |
| 328 |
+ return 'repeated punctuation in name' if /--|__|\+\+./; |
| 329 |
+# return 'repeated component(s) in name' if ($i + 2 <= $#components |
| 330 |
+# and $_ eq $components[$i + 1] and $_ eq $components[$i + 2]); |
| 331 |
+ } |
| 332 |
+ return ''; |
| 333 |
+} |
| 334 |
+ |
| 335 |
+1; |
| 336 |
--- /dev/null |
| 337 |
+++ b/extra/cch/control/rmgroup.pl |
| 338 |
@@ -0,0 +1,89 @@ |
| 339 |
+## $Id: rmgroup.pl,v 1.3 2001/07/19 00:32:56 rra Exp $ |
| 340 |
+## |
| 341 |
+## rmgroup control message handler. |
| 342 |
+## |
| 343 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 344 |
+## |
| 345 |
+## Redistribution and use in source and binary forms, with or without |
| 346 |
+## modification, are permitted provided that the following conditions |
| 347 |
+## are met: |
| 348 |
+## |
| 349 |
+## 1. Redistributions of source code must retain the above copyright |
| 350 |
+## notice, this list of conditions and the following disclaimer. |
| 351 |
+## |
| 352 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 353 |
+## notice, this list of conditions and the following disclaimer in the |
| 354 |
+## documentation and/or other materials provided with the distribution. |
| 355 |
+ |
| 356 |
+use strict; |
| 357 |
+ |
| 358 |
+sub control_rmgroup { |
| 359 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 360 |
+ $headers, $body) = @_; |
| 361 |
+ my ($groupname) = @$par; |
| 362 |
+ |
| 363 |
+ # Scan active to see what sort of change we are making. |
| 364 |
+ open(ACTIVE, $inn::active) or logdie("Cannot open $inn::active: $!"); |
| 365 |
+ my @oldgroup; |
| 366 |
+ while (<ACTIVE>) { |
| 367 |
+ next unless /^(\Q$groupname\E)\s\d+\s\d+\s(\w)/; |
| 368 |
+ @oldgroup = split /\s+/; |
| 369 |
+ last; |
| 370 |
+ } |
| 371 |
+ close ACTIVE; |
| 372 |
+ my $status; |
| 373 |
+ if (not @oldgroup) { |
| 374 |
+ $status = 'no change'; |
| 375 |
+ } elsif (not $approved) { |
| 376 |
+ $status = 'unapproved'; |
| 377 |
+ } else { |
| 378 |
+ $status = 'removed'; |
| 379 |
+ } |
| 380 |
+ |
| 381 |
+ if ($action eq 'mail' and $status !~ /(no change|unapproved)/) { |
| 382 |
+ my $mail = sendmail("rmgroup $groupname $sender"); |
| 383 |
+ print $mail <<END; |
| 384 |
+$sender asks for $groupname |
| 385 |
+to be $status. |
| 386 |
+ |
| 387 |
+If this is acceptable, type: |
| 388 |
+ $inn::newsbin/ctlinnd rmgroup $groupname |
| 389 |
+ |
| 390 |
+The control message follows: |
| 391 |
+ |
| 392 |
+END |
| 393 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 394 |
+ print $mail "\n"; |
| 395 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 396 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 397 |
+ } elsif ($action eq 'log') { |
| 398 |
+ if ($log) { |
| 399 |
+ logger($log, "skipping rmgroup $groupname" |
| 400 |
+ . " $sender (would be $status)", $headers, $body); |
| 401 |
+ } else { |
| 402 |
+ logmsg("skipping rmgroup $groupname $sender (would be $status)"); |
| 403 |
+ } |
| 404 |
+ } elsif ($action eq 'doit' and $status !~ /(no change|unapproved)/) { |
| 405 |
+ ctlinnd('rmgroup', $groupname); |
| 406 |
+ # Update newsgroups too. |
| 407 |
+ shlock("$inn::locks/LOCK.newsgroups"); |
| 408 |
+ open(NEWSGROUPS, $inn::newsgroups) |
| 409 |
+ or logdie("Cannot open $inn::newsgroups: $!"); |
| 410 |
+ my $tempfile = "$inn::newsgroups.$$"; |
| 411 |
+ open(TEMPFILE, ">$tempfile") or logdie("Cannot open $tempfile: $!"); |
| 412 |
+ while (<NEWSGROUPS>) { |
| 413 |
+ print TEMPFILE $_ if not /^\Q$groupname\E\s/; |
| 414 |
+ } |
| 415 |
+ close TEMPFILE; |
| 416 |
+ close NEWSGROUPS; |
| 417 |
+ rename($tempfile, $inn::newsgroups) |
| 418 |
+ or logdie("Cannot rename $tempfile: $!"); |
| 419 |
+ unlink "$inn::locks/LOCK.newsgroups"; |
| 420 |
+ unlink $tempfile; |
| 421 |
+ |
| 422 |
+ logger($log, "rmgroup $groupname $status $sender", $headers, $body) |
| 423 |
+ if $log; |
| 424 |
+ } |
| 425 |
+} |
| 426 |
+ |
| 427 |
+1; |
| 428 |
--- /dev/null |
| 429 |
+++ b/extra/cch/control/sendme.pl |
| 430 |
@@ -0,0 +1,55 @@ |
| 431 |
+## $Id: sendme.pl,v 1.3 2001/07/19 00:32:56 rra Exp $ |
| 432 |
+## |
| 433 |
+## sendme control message handler. |
| 434 |
+## |
| 435 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 436 |
+## |
| 437 |
+## Redistribution and use in source and binary forms, with or without |
| 438 |
+## modification, are permitted provided that the following conditions |
| 439 |
+## are met: |
| 440 |
+## |
| 441 |
+## 1. Redistributions of source code must retain the above copyright |
| 442 |
+## notice, this list of conditions and the following disclaimer. |
| 443 |
+## |
| 444 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 445 |
+## notice, this list of conditions and the following disclaimer in the |
| 446 |
+## documentation and/or other materials provided with the distribution. |
| 447 |
+ |
| 448 |
+use strict; |
| 449 |
+ |
| 450 |
+sub control_sendme { |
| 451 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 452 |
+ $headers, $body) = @_; |
| 453 |
+ |
| 454 |
+ if ($action eq 'mail') { |
| 455 |
+ my $mail = sendmail("sendme by $sender"); |
| 456 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 457 |
+ close $mail or logdie('Cannot send mail: ' . $!); |
| 458 |
+ } elsif ($action eq 'log') { |
| 459 |
+ if ($log) { |
| 460 |
+ logger($log, "sendme $sender", $headers, $body); |
| 461 |
+ } else { |
| 462 |
+ logmsg("sendme from $sender"); |
| 463 |
+ } |
| 464 |
+ } elsif ($action eq 'doit') { |
| 465 |
+ my $tempfile = "$inn::tmpdir/sendme.$$"; |
| 466 |
+ open(GREPHIST, "|grephistory -s > $tempfile") |
| 467 |
+ or logdie("Cannot run grephistory: $!"); |
| 468 |
+ foreach (@$body) { |
| 469 |
+ print GREPHIST "$_\n"; |
| 470 |
+ } |
| 471 |
+ close GREPHIST or logdie("Cannot run grephistory: $!"); |
| 472 |
+ |
| 473 |
+ if (-s $tempfile and $site =~ /^[a-zA-Z0-9.-_]+$/) { |
| 474 |
+ open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!"); |
| 475 |
+ open(BATCH, ">>$inn::batch/$site.work") |
| 476 |
+ or logdie("Cannot open $inn::batch/$site.work: $!"); |
| 477 |
+ print BATCH $_ while <TEMPFILE>; |
| 478 |
+ close BATCH; |
| 479 |
+ close TEMPFILE; |
| 480 |
+ } |
| 481 |
+ unlink $tempfile; |
| 482 |
+ } |
| 483 |
+} |
| 484 |
+ |
| 485 |
+1; |
| 486 |
--- /dev/null |
| 487 |
+++ b/extra/cch/control/sendsys.pl |
| 488 |
@@ -0,0 +1,64 @@ |
| 489 |
+## $Id: sendsys.pl,v 1.2 2001/07/19 00:32:56 rra Exp $ |
| 490 |
+## |
| 491 |
+## sendsys control message handler. |
| 492 |
+## |
| 493 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 494 |
+## |
| 495 |
+## Redistribution and use in source and binary forms, with or without |
| 496 |
+## modification, are permitted provided that the following conditions |
| 497 |
+## are met: |
| 498 |
+## |
| 499 |
+## 1. Redistributions of source code must retain the above copyright |
| 500 |
+## notice, this list of conditions and the following disclaimer. |
| 501 |
+## |
| 502 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 503 |
+## notice, this list of conditions and the following disclaimer in the |
| 504 |
+## documentation and/or other materials provided with the distribution. |
| 505 |
+ |
| 506 |
+use strict; |
| 507 |
+ |
| 508 |
+sub control_sendsys { |
| 509 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 510 |
+ $headers, $body) = @_; |
| 511 |
+ my ($where) = @$par; |
| 512 |
+ |
| 513 |
+ if ($action eq 'mail') { |
| 514 |
+ my $mail = sendmail("sendsys $sender"); |
| 515 |
+ print $mail <<END; |
| 516 |
+$sender has requested that you send a copy |
| 517 |
+of your newsgroups file. |
| 518 |
+ |
| 519 |
+If this is acceptable, type: |
| 520 |
+ $inn::mailcmd -s "sendsys reply from $inn::pathhost" $replyto < $inn::newsfeeds |
| 521 |
+ |
| 522 |
+The control message follows: |
| 523 |
+ |
| 524 |
+END |
| 525 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 526 |
+ print $mail "\n"; |
| 527 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 528 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 529 |
+ } elsif ($action eq 'log') { |
| 530 |
+ if ($log) { |
| 531 |
+ logger($log, "sendsys $sender", $headers, $body); |
| 532 |
+ } else { |
| 533 |
+ logmsg("sendsys $sender"); |
| 534 |
+ } |
| 535 |
+ } elsif ($action =~ /^(doit|doifarg)$/) { |
| 536 |
+ if ($action eq 'doifarg' and $where ne $inn::pathhost) { |
| 537 |
+ logmsg("skipped sendsys $sender"); |
| 538 |
+ return; |
| 539 |
+ } |
| 540 |
+ my $mail = sendmail("sendsys reply from $inn::pathhost", $replyto); |
| 541 |
+ open(NEWSFEEDS, $inn::newsfeeds) |
| 542 |
+ or logdie("Cannot open $inn::newsfeeds: $!"); |
| 543 |
+ print $mail $_ while <NEWSFEEDS>; |
| 544 |
+ print $mail "\n"; |
| 545 |
+ close NEWSFEEDS; |
| 546 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 547 |
+ |
| 548 |
+ logger($log, "sendsys $sender to $replyto", $headers, $body) if $log; |
| 549 |
+ } |
| 550 |
+} |
| 551 |
+ |
| 552 |
+1; |
| 553 |
--- /dev/null |
| 554 |
+++ b/extra/cch/control/senduuname.pl |
| 555 |
@@ -0,0 +1,61 @@ |
| 556 |
+## $Id: senduuname.pl,v 1.2 2001/07/19 00:32:56 rra Exp $ |
| 557 |
+## |
| 558 |
+## senduuname control message handler. |
| 559 |
+## |
| 560 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 561 |
+## |
| 562 |
+## Redistribution and use in source and binary forms, with or without |
| 563 |
+## modification, are permitted provided that the following conditions |
| 564 |
+## are met: |
| 565 |
+## |
| 566 |
+## 1. Redistributions of source code must retain the above copyright |
| 567 |
+## notice, this list of conditions and the following disclaimer. |
| 568 |
+## |
| 569 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 570 |
+## notice, this list of conditions and the following disclaimer in the |
| 571 |
+## documentation and/or other materials provided with the distribution. |
| 572 |
+ |
| 573 |
+use strict; |
| 574 |
+ |
| 575 |
+sub control_senduuname { |
| 576 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 577 |
+ $headers, $body) = @_; |
| 578 |
+ my ($where) = @$par; |
| 579 |
+ |
| 580 |
+ if ($action eq 'mail') { |
| 581 |
+ my $mail = sendmail("senduuname $sender"); |
| 582 |
+ print $mail <<END; |
| 583 |
+$sender has requested information about your UUCP name. |
| 584 |
+ |
| 585 |
+If this is acceptable, type: |
| 586 |
+ uuname | $inn::mailcmd -s "senduuname reply from $inn::pathhost" $replyto |
| 587 |
+ |
| 588 |
+The control message follows: |
| 589 |
+ |
| 590 |
+END |
| 591 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 592 |
+ print $mail "\n"; |
| 593 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 594 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 595 |
+ } elsif ($action eq 'log') { |
| 596 |
+ if ($log) { |
| 597 |
+ logger($log, "senduuname $sender", $headers, $body); |
| 598 |
+ } else { |
| 599 |
+ logmsg("senduuname $sender"); |
| 600 |
+ } |
| 601 |
+ } elsif ($action =~ /^(doit|doifarg)$/) { |
| 602 |
+ if ($action eq 'doifarg' and $where ne $inn::pathhost) { |
| 603 |
+ logmsg("skipped senduuname $sender"); |
| 604 |
+ return; |
| 605 |
+ } |
| 606 |
+ my $mail = sendmail("senduuname reply from $inn::pathhost", $replyto); |
| 607 |
+ open(UUNAME, 'uuname|') or logdie("Cannot run uuname: $!"); |
| 608 |
+ print $mail $_ while <UUNAME>; |
| 609 |
+ close UUNAME or logdie("Cannot run uuname: $!"); |
| 610 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 611 |
+ |
| 612 |
+ logger($log, "senduuname $sender to $replyto", $headers, $body) if $log; |
| 613 |
+ } |
| 614 |
+} |
| 615 |
+ |
| 616 |
+1; |
| 617 |
--- /dev/null |
| 618 |
+++ b/extra/cch/control/version.pl |
| 619 |
@@ -0,0 +1,61 @@ |
| 620 |
+## $Id: version.pl,v 1.2 2001/07/19 00:32:56 rra Exp $ |
| 621 |
+## |
| 622 |
+## version control message handler. |
| 623 |
+## |
| 624 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 625 |
+## |
| 626 |
+## Redistribution and use in source and binary forms, with or without |
| 627 |
+## modification, are permitted provided that the following conditions |
| 628 |
+## are met: |
| 629 |
+## |
| 630 |
+## 1. Redistributions of source code must retain the above copyright |
| 631 |
+## notice, this list of conditions and the following disclaimer. |
| 632 |
+## |
| 633 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 634 |
+## notice, this list of conditions and the following disclaimer in the |
| 635 |
+## documentation and/or other materials provided with the distribution. |
| 636 |
+ |
| 637 |
+use strict; |
| 638 |
+ |
| 639 |
+sub control_version { |
| 640 |
+ my ($par, $sender, $replyto, $site, $action, $log, $approved, |
| 641 |
+ $headers, $body) = @_; |
| 642 |
+ my ($where) = @$par; |
| 643 |
+ |
| 644 |
+ my $version = $inn::version || '(unknown version)'; |
| 645 |
+ |
| 646 |
+ if ($action eq 'mail') { |
| 647 |
+ my $mail = sendmail("version $sender"); |
| 648 |
+ print $mail <<END; |
| 649 |
+$sender has requested information about your |
| 650 |
+news software version. |
| 651 |
+ |
| 652 |
+If this is acceptable, type: |
| 653 |
+ echo "InterNetNews $version" | $inn::mailcmd -s "version reply from $inn::pathhost" $replyto |
| 654 |
+ |
| 655 |
+The control message follows: |
| 656 |
+ |
| 657 |
+END |
| 658 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 659 |
+ print $mail "\n"; |
| 660 |
+ print $mail map { s/^~/~~/; "$_\n" } @$body; |
| 661 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 662 |
+ } elsif ($action eq 'log') { |
| 663 |
+ if ($log) { |
| 664 |
+ logger($log, "version $sender", $headers, $body); |
| 665 |
+ } else { |
| 666 |
+ logmsg("version $sender"); |
| 667 |
+ } |
| 668 |
+ } elsif ($action =~ /^(doit|doifarg)$/) { |
| 669 |
+ if ($action eq 'doifarg' and $where ne $inn::pathhost) { |
| 670 |
+ logmsg("skipped version $sender"); |
| 671 |
+ return; |
| 672 |
+ } |
| 673 |
+ sendmail("version reply from $inn::pathhost", $replyto, |
| 674 |
+ [ "InterNetNews $version\n" ]); |
| 675 |
+ |
| 676 |
+ logger($log, "version $sender to $replyto", $headers, $body) if $log; |
| 677 |
+ } |
| 678 |
+} |
| 679 |
+ |
| 680 |
+1; |
| 681 |
--- /dev/null |
| 682 |
+++ b/extra/cch/controlchan |
| 683 |
@@ -0,0 +1,463 @@ |
| 684 |
+#! /usr/bin/perl -w |
| 685 |
+require '/usr/lib/news/innshellvars.pl'; |
| 686 |
+ |
| 687 |
+# convert INN 1.x variables to 2.x style |
| 688 |
+$inn::syslog_facility = 'news'; |
| 689 |
+$inn::pgpverify = 'true'; |
| 690 |
+$inn::mta = $inn::sendmail; |
| 691 |
+$inn::pathbin = $inn::newsbin; |
| 692 |
+$inn::tmpdir = $inn::spooltemp; |
| 693 |
+$inn::pathhost = `$inn::innconfval pathhost`; |
| 694 |
+$inn::version = '1.7.2+insync-1.1d+debian'; |
| 695 |
+ |
| 696 |
+## $Id: controlchan.in,v 1.7 2002/11/21 00:03:15 vinocur Exp $ |
| 697 |
+## |
| 698 |
+## Channel feed program to route control messages to an appropriate handler. |
| 699 |
+## |
| 700 |
+## Copyright 2001 by Marco d'Itri <[email protected]> |
| 701 |
+## |
| 702 |
+## Redistribution and use in source and binary forms, with or without |
| 703 |
+## modification, are permitted provided that the following conditions |
| 704 |
+## are met: |
| 705 |
+## |
| 706 |
+## 1. Redistributions of source code must retain the above copyright |
| 707 |
+## notice, this list of conditions and the following disclaimer. |
| 708 |
+## |
| 709 |
+## 2. Redistributions in binary form must reproduce the above copyright |
| 710 |
+## notice, this list of conditions and the following disclaimer in the |
| 711 |
+## documentation and/or other materials provided with the distribution. |
| 712 |
+## |
| 713 |
+## Give this program its own newsfeed. Make sure that you've created |
| 714 |
+## the newsgroup control.cancel so that you don't have to scan through |
| 715 |
+## cancels, which this program won't process anyway. |
| 716 |
+## |
| 717 |
+## Make a newsfeeds entry like this: |
| 718 |
+## |
| 719 |
+## controlchan!\ |
| 720 |
+## :!*,control,control.*,!control.cancel\ |
| 721 |
+## :Tc,Wnsm\ |
| 722 |
+## :@prefix@/bin/controlchan |
| 723 |
+ |
| 724 |
+require 5.004_03; |
| 725 |
+use strict; |
| 726 |
+ |
| 727 |
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; |
| 728 |
+ |
| 729 |
+# globals |
| 730 |
+my ($cachedctl, $curmsgid); |
| 731 |
+my $lastctl = 0; |
| 732 |
+my $use_syslog = 0; |
| 733 |
+my $debug = 0; |
| 734 |
+ |
| 735 |
+# setup logging ########################################################### |
| 736 |
+# do not log to syslog if stderr is connected to a console |
| 737 |
+if (not -t 2) { |
| 738 |
+ eval { require INN::Syslog; import INN::Syslog; $use_syslog = 1; }; |
| 739 |
+ eval { require Sys::Syslog; import Sys::Syslog; $use_syslog = 1; } |
| 740 |
+ unless $use_syslog; |
| 741 |
+} |
| 742 |
+ |
| 743 |
+if ($use_syslog) { |
| 744 |
+ eval "sub Sys::Syslog::_PATH_LOG { '/dev/log' }" if $^O eq 'dec_osf'; |
| 745 |
+ Sys::Syslog::setlogsock('unix') if $^O =~ /linux|dec_osf/; |
| 746 |
+ openlog('controlchan', 'pid', $inn::syslog_facility); |
| 747 |
+} |
| 748 |
+logmsg('starting'); |
| 749 |
+ |
| 750 |
+# load modules from the control directory ################################# |
| 751 |
+opendir(CTL, $inn::controlprogs) |
| 752 |
+ or logdie("Cannot open $inn::controlprogs", 'crit'); |
| 753 |
+foreach (readdir CTL) { |
| 754 |
+ next if not /^([a-z\.]+\.pl)$/ or not -f "$inn::controlprogs/$_"; |
| 755 |
+ eval { require "$inn::controlprogs/$1" }; |
| 756 |
+ if ($@) { |
| 757 |
+ $@ =~ s/\n/ /g; |
| 758 |
+ logdie($@, 'crit'); |
| 759 |
+ } |
| 760 |
+ logmsg("loaded $inn::controlprogs/$1", 'debug'); |
| 761 |
+} |
| 762 |
+closedir CTL; |
| 763 |
+ |
| 764 |
+# main loop ############################################################### |
| 765 |
+while (<STDIN>) { |
| 766 |
+ chop; |
| 767 |
+ my ($token, $sitepath, $msgid) = split(/\s+/, $_); |
| 768 |
+ next if not defined $token; |
| 769 |
+ $sitepath ||= ''; |
| 770 |
+ $curmsgid = $msgid || ''; |
| 771 |
+ |
| 772 |
+ my $artfh = open_article($token); |
| 773 |
+ next if not defined $artfh; |
| 774 |
+ |
| 775 |
+ # suck in headers and body, normalize the strange ones |
| 776 |
+ my (@headers, @body, %hdr); |
| 777 |
+ if (not parse_article($artfh, \@headers, \@body, \%hdr)) { |
| 778 |
+ close $artfh; |
| 779 |
+ next; |
| 780 |
+ } |
| 781 |
+ close $artfh or logdie('sm died with status ' . ($? >> 8)); |
| 782 |
+ |
| 783 |
+ next if not exists $hdr{control}; |
| 784 |
+ |
| 785 |
+ $curmsgid = $hdr{'message-id'}; |
| 786 |
+ my $sender = cleanaddr($hdr{sender} || $hdr{from}); |
| 787 |
+ my $replyto = cleanaddr($hdr{'reply-to'} || $hdr{from}); |
| 788 |
+ |
| 789 |
+ my (@progparams, $progname); |
| 790 |
+ if ($hdr{control} =~ /\s/) { |
| 791 |
+ $hdr{control} =~ /^(\S+)\s+(.+)?/; |
| 792 |
+ $progname = lc $1; |
| 793 |
+ @progparams = split(/\s+/, lc $2) if $2; |
| 794 |
+ } else { |
| 795 |
+ $progname = lc $hdr{control}; |
| 796 |
+ } |
| 797 |
+ |
| 798 |
+ next if $progname eq 'cancel'; |
| 799 |
+ |
| 800 |
+ if ($progname !~ /^([a-z]+)$/) { |
| 801 |
+ logmsg("Naughty control in article $curmsgid ($progname)"); |
| 802 |
+ next; |
| 803 |
+ } |
| 804 |
+ $progname = $1; |
| 805 |
+ |
| 806 |
+ # Do we want to process the message? Let's check the permissions. |
| 807 |
+ my ($action, $logname, $newsgrouppats) = |
| 808 |
+ ctlperm($progname, $sender, $progparams[0], |
| 809 |
+ $token, \@headers, \@body); |
| 810 |
+ |
| 811 |
+ next if $action eq 'drop'; |
| 812 |
+ |
| 813 |
+ if ($action eq '_pgpfail') { |
| 814 |
+ my $type = ''; |
| 815 |
+ if ($progname and $progname eq 'newgroup') { |
| 816 |
+ if ($progparams[1] and $progparams[1] eq 'moderated') { |
| 817 |
+ $type = 'm '; |
| 818 |
+ } else { |
| 819 |
+ $type = 'y '; |
| 820 |
+ } |
| 821 |
+ } |
| 822 |
+ logmsg("skipping $progname $type$sender" |
| 823 |
+ . "(pgpverify failed) in $curmsgid"); |
| 824 |
+ next; |
| 825 |
+ } |
| 826 |
+ |
| 827 |
+ # used by checkgroups. Convert from perl regexp to grep regexp. |
| 828 |
+ if (local $_ = $newsgrouppats) { |
| 829 |
+ s/\$\|/|/g; |
| 830 |
+ s/[^\\]\.[^*]/?/g; |
| 831 |
+ s/\$//; |
| 832 |
+ s/\.\*/*/g; |
| 833 |
+ s/\\([\$\+\.])/$1/g; |
| 834 |
+ $progparams[0] = $_; |
| 835 |
+ } |
| 836 |
+ |
| 837 |
+ # find the appropriate module and call it |
| 838 |
+ my $subname = "control_$progname"; |
| 839 |
+ my $subfind = \&$subname; |
| 840 |
+ if (not defined &$subfind) { |
| 841 |
+ if ($logname) { |
| 842 |
+ logger($logname, "Unknown control message by $sender", |
| 843 |
+ \@headers, \@body); |
| 844 |
+ } else { |
| 845 |
+ logmsg("Unknown \"$progname\" control by $sender"); |
| 846 |
+ } |
| 847 |
+ next; |
| 848 |
+ } |
| 849 |
+ |
| 850 |
+ my $approved = $hdr{approved} ? 1 : 0; |
| 851 |
+ logmsg("$subname, " . join(' ', @progparams) |
| 852 |
+ . " $sender $replyto $token, $sitepath, $action" |
| 853 |
+ . ($logname ? "=$logname" : '') .", $approved"); |
| 854 |
+ |
| 855 |
+ &$subfind(\@progparams, $sender, $replyto, $sitepath, |
| 856 |
+ $action, $logname, $approved, \@headers, \@body); |
| 857 |
+} |
| 858 |
+ |
| 859 |
+closelog() if $use_syslog; |
| 860 |
+exit 0; |
| 861 |
+ |
| 862 |
+print $inn::most_logs.$inn::syslog_facility.$inn::mta. |
| 863 |
+ $inn::pathhost.$inn::tmpdir.$inn::sendmail.$inn::version. |
| 864 |
+ $inn::pathbin.$inn::innconfval.$inn::spooltemp.$ |
| 865 |
+ $inn::newsmaster.$inn::locks; # lint food |
| 866 |
+ |
| 867 |
+# misc functions ########################################################## |
| 868 |
+sub parse_article { |
| 869 |
+ my ($artfh, $headers, $body, $hdr) = @_; |
| 870 |
+ my $h; |
| 871 |
+ my %uniquehdr = map { $_ => 1 } qw(date followup-to from message-id |
| 872 |
+ newsgroups path reply-to subject sender); |
| 873 |
+ |
| 874 |
+ while (<$artfh>) { |
| 875 |
+ chop; |
| 876 |
+ last if /^$/; |
| 877 |
+ push @$headers, $_; |
| 878 |
+ if (/^(\S+):\s+(.+)/) { |
| 879 |
+ $h = lc $1; |
| 880 |
+ if (exists $hdr->{$h}) { |
| 881 |
+ if (exists $uniquehdr{$h}) { |
| 882 |
+ logmsg("Multiple $1 headers in article $curmsgid"); |
| 883 |
+ return 0; |
| 884 |
+ } |
| 885 |
+ $hdr->{$h} .= ' ' . $2; |
| 886 |
+ } else { |
| 887 |
+ $hdr->{$h} = $2; |
| 888 |
+ } |
| 889 |
+ next; |
| 890 |
+ } elsif (/^\s+(.+)/) { |
| 891 |
+ if (defined $h) { |
| 892 |
+ $hdr->{$h} .= ' ' . $1; |
| 893 |
+ next; |
| 894 |
+ } |
| 895 |
+ } |
| 896 |
+ logmsg("Broken headers in article $curmsgid"); |
| 897 |
+ return 0; |
| 898 |
+ } |
| 899 |
+ |
| 900 |
+ # article is empty or does not exist |
| 901 |
+ return 0 if not @$headers; |
| 902 |
+ |
| 903 |
+ chop (@$body = <$artfh>); |
| 904 |
+ return 1; |
| 905 |
+} |
| 906 |
+ |
| 907 |
+# Strip a mail address, innd-style. |
| 908 |
+sub cleanaddr { |
| 909 |
+ local $_ = shift; |
| 910 |
+ s/(\s+)?\(.*\)(\s+)?//g; |
| 911 |
+ s/.*<(.*)>.*/$1/; |
| 912 |
+ s/[^-a-zA-Z0-9+_.@%]/_/g; # protect MTA |
| 913 |
+ s/^-/_/; # protect MTA |
| 914 |
+ return $_; |
| 915 |
+} |
| 916 |
+ |
| 917 |
+# Read and cache control.ctl. |
| 918 |
+sub readctlfile { |
| 919 |
+ my $mtime = (stat($inn::ctlfile))[9]; |
| 920 |
+ return $cachedctl if $lastctl == $mtime; # mtime has not changed. |
| 921 |
+ $lastctl = $mtime; |
| 922 |
+ |
| 923 |
+ my @ctllist; |
| 924 |
+ open(CTLFILE, $inn::ctlfile) |
| 925 |
+ or logdie("Cannot open $inn::ctlfile", 'crit'); |
| 926 |
+ while (<CTLFILE>) { |
| 927 |
+ chop; |
| 928 |
+ # Not a comment or blank? Convert wildmat to regex |
| 929 |
+ next if not /^(\s+)?[^\#]/ or /^$/; |
| 930 |
+ if (not /:(?:doit|doifarg|drop|log|mail|verify-.*)(?:=.*)?$/) { |
| 931 |
+ s/.*://; |
| 932 |
+ logmsg("$_ is not a valid action for control.ctl", 'err'); |
| 933 |
+ next; |
| 934 |
+ } |
| 935 |
+ # Convert to a : separated list of regexps |
| 936 |
+ s/^all:/*:/i; |
| 937 |
+ s/([\$\+\.])/\\$1/g; |
| 938 |
+ s/\*/.*/g; |
| 939 |
+ s/\?/./g; |
| 940 |
+ s/(.*)/^$1\$/; |
| 941 |
+ s/:/\$:^/g; |
| 942 |
+ s/\|/\$|^/g; |
| 943 |
+ push @ctllist, $_; |
| 944 |
+ } |
| 945 |
+ close CTLFILE; |
| 946 |
+ |
| 947 |
+ logmsg('warning: control.ctl is empty!', 'err') if not @ctllist; |
| 948 |
+ return $cachedctl = [ reverse @ctllist ]; |
| 949 |
+} |
| 950 |
+ |
| 951 |
+# Parse a control message's permissions. |
| 952 |
+sub ctlperm { |
| 953 |
+ my ($type, $sender, $newsgroup, $token, $headers, $body) = @_; |
| 954 |
+ |
| 955 |
+ my $action = 'drop'; # default |
| 956 |
+ my ($logname, $hier); |
| 957 |
+ |
| 958 |
+ # newgroup and rmgroup require newsgroup names; check explicitly for that |
| 959 |
+ # here and return drop if the newsgroup is missing (to avoid a bunch of |
| 960 |
+ # warnings from undefined values later on in permission checking). |
| 961 |
+ if ($type eq 'newgroup' or $type eq 'rmgroup') { |
| 962 |
+ unless ($newsgroup) { |
| 963 |
+ return ('drop', undef, undef); |
| 964 |
+ } |
| 965 |
+ } |
| 966 |
+ |
| 967 |
+ my $ctllist = readctlfile(); |
| 968 |
+ foreach (@$ctllist) { |
| 969 |
+ my @ctlline = split /:/; |
| 970 |
+ # 0: type 1: from@addr 2: group.* 3: action |
| 971 |
+ if ($type =~ /$ctlline[0]/ and $sender =~ /$ctlline[1]/i and |
| 972 |
+ ($type !~ /(?:new|rm)group/ or $newsgroup =~ /$ctlline[2]/)) { |
| 973 |
+ $action = $ctlline[3]; |
| 974 |
+ $action =~ s/\^(.+)\$/$1/; |
| 975 |
+ $action =~ s/\\//g; |
| 976 |
+ $hier = $ctlline[2] if $type eq 'checkgroups'; |
| 977 |
+ last; |
| 978 |
+ } |
| 979 |
+ } |
| 980 |
+ |
| 981 |
+ ($action, $logname) = split(/=/, $action); |
| 982 |
+ |
| 983 |
+ if ($action =~ /^verify-(.+)/) { |
| 984 |
+ my $keyowner = $1; |
| 985 |
+ if ($inn::pgpverify and $inn::pgpverify =~ /^(?:true|on|yes)$/i) { |
| 986 |
+ my $pgpresult = defined &local_pgpverify ? |
| 987 |
+ local_pgpverify($token, $headers, $body) : pgpverify($token); |
| 988 |
+ if ($keyowner eq $pgpresult) { |
| 989 |
+ $action = 'doit'; |
| 990 |
+ } else { |
| 991 |
+ $action = '_pgpfail'; |
| 992 |
+ } |
| 993 |
+ } else { |
| 994 |
+ $action = 'mail'; |
| 995 |
+ } |
| 996 |
+ } |
| 997 |
+ |
| 998 |
+ return ($action, $logname, $hier); |
| 999 |
+} |
| 1000 |
+ |
| 1001 |
+# Write stuff to a log or send mail to the news admin. |
| 1002 |
+sub logger { |
| 1003 |
+ my ($logfile, $message, $headers, $body) = @_; |
| 1004 |
+ |
| 1005 |
+ if ($logfile eq 'mail') { |
| 1006 |
+ my $mail = sendmail($message); |
| 1007 |
+ print $mail map { s/^~/~~/; "$_\n" } @$headers; |
| 1008 |
+ print $mail "$_\n" . join ('', map { s/^~/~~/; "$_\n" } @$body) |
| 1009 |
+ if $body; |
| 1010 |
+ close $mail or logdie("Cannot send mail: $!"); |
| 1011 |
+ return; |
| 1012 |
+ } |
| 1013 |
+ |
| 1014 |
+ if ($logfile =~ /^([^.\/].*)/) { |
| 1015 |
+ $logfile = $1; |
| 1016 |
+ } else { |
| 1017 |
+ logmsg("Invalid log file: $logfile", 'err'); |
| 1018 |
+ $logfile = 'control'; |
| 1019 |
+ } |
| 1020 |
+ |
| 1021 |
+ $logfile = "$inn::most_logs/$logfile.log" unless $logfile =~ /^\//; |
| 1022 |
+ my $lockfile = $logfile; |
| 1023 |
+ $lockfile =~ s#.*/##; |
| 1024 |
+ $lockfile = "$inn::locks/LOCK.$lockfile"; |
| 1025 |
+ shlock($lockfile); |
| 1026 |
+ |
| 1027 |
+ open(LOGFILE, ">>$logfile") or logdie("Cannot open $logfile: $!"); |
| 1028 |
+ print LOGFILE "$message\n"; |
| 1029 |
+ foreach (@$headers, '', @$body, '') { |
| 1030 |
+ print LOGFILE " $_\n"; |
| 1031 |
+ } |
| 1032 |
+ close LOGFILE; |
| 1033 |
+ unlink $lockfile; |
| 1034 |
+} |
| 1035 |
+ |
| 1036 |
+# write to syslog or errlog |
| 1037 |
+sub logmsg { |
| 1038 |
+ my ($msg, $lvl) = @_; |
| 1039 |
+ |
| 1040 |
+ return if $lvl and $lvl eq 'debug' and not $debug; |
| 1041 |
+ if ($use_syslog) { |
| 1042 |
+ syslog($lvl || 'notice', '%s', $msg); |
| 1043 |
+ } else { |
| 1044 |
+ print STDERR (scalar localtime) . ": $msg\n"; |
| 1045 |
+ } |
| 1046 |
+} |
| 1047 |
+ |
| 1048 |
+# log a message and then die |
| 1049 |
+sub logdie { |
| 1050 |
+ my ($msg, $lvl) = @_; |
| 1051 |
+ |
| 1052 |
+ $msg .= " ($curmsgid)" if $curmsgid; |
| 1053 |
+ logmsg($msg, $lvl || 'err'); |
| 1054 |
+ exit 1; |
| 1055 |
+} |
| 1056 |
+ |
| 1057 |
+# wrappers executing external programs #################################### |
| 1058 |
+ |
| 1059 |
+# Open an article appropriately to our storage method (or lack thereof). |
| 1060 |
+sub open_article { |
| 1061 |
+ my $token = shift; |
| 1062 |
+ |
| 1063 |
+ return *ART if open(ART, $token); |
| 1064 |
+ logmsg("Cannot open article $token: $!"); |
| 1065 |
+ return undef; |
| 1066 |
+} |
| 1067 |
+ |
| 1068 |
+sub pgpverify { |
| 1069 |
+ my $token = shift; |
| 1070 |
+ |
| 1071 |
+ open(PGPCHECK, "$inn::newsbin/pgpverify < $token |") or goto ERROR; |
| 1072 |
+ my $pgpresult = <PGPCHECK>; |
| 1073 |
+ close PGPCHECK or goto ERROR; |
| 1074 |
+ $pgpresult ||= ''; |
| 1075 |
+ chop $pgpresult; |
| 1076 |
+ return $pgpresult; |
| 1077 |
+ERROR: |
| 1078 |
+ logmsg("pgpverify failed: $!", 'debug'); |
| 1079 |
+ return ''; |
| 1080 |
+} |
| 1081 |
+ |
| 1082 |
+sub ctlinnd { |
| 1083 |
+ my ($cmd, @args) = @_; |
| 1084 |
+ |
| 1085 |
+ my $st = system("$inn::newsbin/ctlinnd", '-s', $cmd, @args); |
| 1086 |
+ logdie('Cannot run ctlinnd: ' . $!) if $st == -1; |
| 1087 |
+ logdie('ctlinnd returned status ' . ($st & 255)) if $st > 0; |
| 1088 |
+} |
| 1089 |
+ |
| 1090 |
+sub shlock { |
| 1091 |
+ my $lockfile = shift; |
| 1092 |
+ |
| 1093 |
+ my $locktry = 0; |
| 1094 |
+ while ($locktry < 60) { |
| 1095 |
+ if (system("$inn::newsbin/shlock", '-p', $$, '-f', $lockfile) == 0) { |
| 1096 |
+ return 1; |
| 1097 |
+ } |
| 1098 |
+ $locktry++; |
| 1099 |
+ sleep 2; |
| 1100 |
+ } |
| 1101 |
+ |
| 1102 |
+ my $lockreason; |
| 1103 |
+ if (open(LOCKFILE, $lockfile)) { |
| 1104 |
+ $lockreason = 'held by ' . (<LOCKFILE> || '?'); |
| 1105 |
+ close LOCKFILE; |
| 1106 |
+ } else { |
| 1107 |
+ $lockreason = $!; |
| 1108 |
+ } |
| 1109 |
+ logdie("Cannot get lock $lockfile: $lockreason"); |
| 1110 |
+ return undef; |
| 1111 |
+} |
| 1112 |
+ |
| 1113 |
+# If $body is not defined, returns a file handle which must be closed. |
| 1114 |
+# Don't forget checking the return value of close(). |
| 1115 |
+# $addresses may be a scalar or a reference to a list of addresses. |
| 1116 |
+# If not defined, $inn::newsmaster is the default. |
| 1117 |
+# parts of this code stolen from innmail.pl |
| 1118 |
+sub sendmail { |
| 1119 |
+ my ($subject, $addresses, $body) = @_; |
| 1120 |
+ $addresses = [ $addresses || $inn::newsmaster ] if not ref $addresses; |
| 1121 |
+ $subject ||= '(no subject)'; |
| 1122 |
+ |
| 1123 |
+ # fix up all addresses |
| 1124 |
+ my @addrs = map { s#[^-a-zA-Z0-9+_.@%]##g; $_ } @$addresses; |
| 1125 |
+ |
| 1126 |
+ my $sm = $inn::mta; |
| 1127 |
+ if ($sm =~ /%s/) { |
| 1128 |
+ $sm = sprintf($sm, join(' ', @addrs)); |
| 1129 |
+ } else { |
| 1130 |
+ $sm .= ' ' . join(' ', @addrs); |
| 1131 |
+ } |
| 1132 |
+ |
| 1133 |
+ # fork and spawn the MTA whitout using the shell |
| 1134 |
+ my $pid = open(MTA, '|-'); |
| 1135 |
+ logdie('Cannot fork: ' . $!) if $pid < 0; |
| 1136 |
+ if ($pid == 0) { |
| 1137 |
+ exec(split(/\s+/, $sm)) or logdie("Cannot exec $sm: $!"); |
| 1138 |
+ } |
| 1139 |
+ |
| 1140 |
+ print MTA 'To: ' . join(",\n\t", @addrs) . "\nSubject: $subject\n\n"; |
| 1141 |
+ return *MTA if not defined $body; |
| 1142 |
+ $body = join("\n", @$body) if ref $body eq 'ARRAY'; |
| 1143 |
+ print MTA $body . "\n"; |
| 1144 |
+ close MTA or logdie("Execution of $sm failed: $!"); |
| 1145 |
+ return 1; |
| 1146 |
+} |