3 # 21.8.2000r (C) Andrzej Radecki
5 # Skrypt objêty licencj± GPL (General Public License)
10 use CGI::Carp qw(fatalsToBrowser set_message);
16 if ($msg =~ /POSTs are limited to/) {
17 print "Zbyt du¿y killfile\n"
18 } else {print "Ooops.. czy¿by jaki¶ b³±d w skrypcie?\n$msg\n"}
20 set_message(\&handle_errors);
26 #$CGI::DISABLE_UPLOADS=1;
28 my $ident = "../ident"; #to musi byæ w bezpiecznym miejscu
29 my $log_file = "../log";
30 my $redirect = 'http://localhost';
31 my $zip = '/usr/bin/zip';
32 my $gzip = '/usr/bin/gzip';
33 my $bzip2 = '/usr/bin/bzip2';
34 my ($login_name, $pass, $compress, $uploaded_file, $debug);
35 my (%groups, %crossposts, @messages, %killfile);
40 if (autoryzuj()) {pobierz_newsy()}
46 # my ($blok, @tmp, $newsgroups, $old);
48 if ($q->param('compress')) {$compress = $q->param('compress'); $compress =~ s/\/$//;}
49 else {$compress = 'bzip2'}
50 if ($q->param('user')) {$login_name = $q->param('user'); $login_name =~ s/\/$//;}
51 if ($q->param('pass')) {$pass = $q->param('pass'); $pass =~ s/\/$//;}
52 if ($q->param('debug')) {$debug = $q->param('debug'); $debug =~ s/\/$//;}
55 my @groups = grep(/^count-.+/, $q->param());
56 # print @groups, "\n";
57 %groups = map { /^count-(.+)/; $1 => $q->param($_); } @groups;
58 # print keys(%groups),' ', values(%groups), "\n";
59 if ($q->param('killfile')) {$uploaded_file = $q->param('killfile'); $uploaded_file =~ s/\/$//;}
60 return if ($login_name eq 'test' || !defined($uploaded_file)); #ograniczenie dla anonimów
65 my $newsgroups = 'default';
66 while (<$uploaded_file>) {
67 m/\r?\n?$/ || next; #obciêta ostatnia linia?
68 s/\r?\n?$//; #usuwamy znaki koñca linii
71 s#/#\\/#g; #eskejpujemy '/'
72 s/([\$\@\%])(?=.+)/\\$1/g; #j.w. ale $zmienna, @zmienna, %zmienna
73 s/\(\?.+?\)/$1/g; #wycinamy wszelkie rozszerzenia regexpów
75 # push @messages, "$.: $_" if ($debug eq 'yes');
76 if (/^\[([a-z0-9\.+-]+)\]/) {$newsgroups = $1; next;}
77 if (/^(-?\d+):([\w_-]+?):(.+)/) {push @{$killfile{$newsgroups}}, [$1, $2, $3]; next;}
78 else {push @messages, "Syntax error in killfile (line $.)"; last;}
81 if ($debug eq 'yes') {
82 foreach my $grupa (keys (%killfile)) {
83 foreach my $regulka (@{$killfile{$grupa}}) {
84 my $tmp = join (':', @{$regulka});
85 push @messages, "$grupa\t$tmp";
93 my $c = new News::NNTPClient("localhost"); #, "", 2);
101 for (my $i=0; $i < scalar(@messages); $i++) {
102 print WYJSCIE "X-Notice-$i: $messages[$i]\r\n";
104 # print WYJSCIE "X-Notice-1: test\r\n";
105 if ($compress eq 'bzip2') {
106 print WYJSCIE $q->header(-type=>"application/octet-stream", "Content-Disposition"=>"filename=paczka.bz2");
107 open (WYJSCIE, "| $bzip2 -5");
108 } elsif ($compress eq 'gzip') {
109 print WYJSCIE $q->header(-type=>"application/octet-stream", "Content-Disposition"=>"filename=paczka.gz");
110 open (WYJSCIE, "| $gzip -9q");
111 } elsif ($compress eq 'zip') {
112 print WYJSCIE $q->header(-type=>"application/octet-stream", "Content-Disposition"=>"filename=paczka.zip");
113 open (WYJSCIE, "| $zip -9q");
114 } else { print WYJSCIE $q->header(-type=>"application/octet-stream", "Content-Disposition"=>"filename=paczka.txt")}
117 foreach my $grupa (keys (%groups)) {
118 $nr = $groups{$grupa};
119 ($first, $last) = ($c->group($grupa));
121 if ($nr =~ /^\-(\d+)/) { $nr = $last - $1 }
122 if ($nr < $first) { $nr = $first }
124 # print "$first $last $nr \n";
126 for (; $nr <= $last; $nr++) {
127 $c->{CMND} = "fetchbinary";
128 $headers = $c->command("HEAD $nr")."\015\012\015\012";
131 $tmp =~ s/\015?\012\s+/ /g; #scalamy wieloliniowe naglowki
132 %headers = map { /^(.+?): (.*)$/; $1 => $2; } split (/\015?\012/, $tmp);
133 if (!killarticle(%headers)) {
134 print (WYJSCIE $headers);
135 $c->{CMND} = "fetchbinary";
136 print (WYJSCIE $c->command("BODY $nr"), "\015\012.\015\012");
138 exit if (($login_name eq 'test') && ($count >= 50)); #ograniczenie dla anonimów
149 #eliminacja powielania crosspostow przy sciaganiu; %hdrs - hash naglowkow
150 if (scalar(my @tmp = split (/ /, $hdrs{'Xref'})) > 2) {
151 # print "Xref: ", $hdrs{'Xref'}, scalar(@tmp = split (/ /, $hdrs{'Xref'})),"\n";
152 if (defined($crossposts{$hdrs{'Message-ID'}})) {return 1} #mamy powtórzony crosspost
153 else {$crossposts{$hdrs{'Message-ID'}} = 1}
155 return if ($login_name eq 'test'); #ograniczenie dla anonimów
157 #sprawdzanie killfile'a:
161 foreach my $grupa (split (/,/, $hdrs{'Newsgroups'})) {
162 if (defined($killfile{$grupa})) {
163 foreach my $regulka (@{$killfile{$grupa}}) {
164 # print " ", join('::', @{$regulka}),"->@{$regulka}[2]\n";
165 if ($hdrs{@{$regulka}[1]} =~ /@{$regulka}[2]/i) {$count += @{$regulka}[0]};
169 if (defined($killfile{'default'})) {
170 foreach my $regulka (@{$killfile{'default'}}) {
171 # print " ", join('::', @{$regulka}),"\n";
172 if ($hdrs{@{$regulka}[1]} =~ /@{$regulka}[2]/i) {$count += @{$regulka}[0]};
175 return 1 if ($count < 0);
176 # print "$count\r\n";
185 flock IDENT, LOCK_EX;
186 my @jest = grep ((/^$login_name/o), <IDENT>);
187 flock IDENT, LOCK_UN;
191 if (($jest[0] =~ /^(.+) (\S+)$/) && ($2 eq crypt ($pass, $2))) {return 1};
193 print $q->redirect($redirect);
196 if (! ($login_name) || ($login_name ne 'test')) {
198 print $q->redirect($redirect);
207 open(LOG, ">> $log_file");
209 print LOG scalar(localtime(time)), "\t";#, join("\t",sort(grep(!/pass/, $q->param()))),"\n";
210 foreach my $k (grep(!/^pass$/, $q->param())) {
211 print LOG "$k=", $q->param($k), " ";