#!/usr/bin/perl -w # Copyright (C) 2005 Christoph Berg # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; use CGI; my $cgi = new CGI; use CGI::Carp qw(fatalsToBrowser); use DB_File; my $planet_html = "data/planet.html"; my $user_db = "data/users.db"; my $url = "http://www.df7cb.de/debian/planet/"; my $path = "/debian/planet/"; my $count = 1; my $subscriptions = 0; my $post = 0; my (%p, %p_new); my (%s, %s_new); my $entry_href; my %db; # read old cookies my $oldcookie = $cgi->cookie(-name => 'people'); if ($oldcookie) { #print STDERR "cookie - reading data: $oldookie\n"; foreach (split /&/, $oldcookie) { $p{$1} = $2 if /(.*)=(.*)/; #print STDERR "cookie $1=$2
\n"; } } $oldcookie = $cgi->cookie(-name => 'seen'); if ($oldcookie) { foreach (split /&/, $oldcookie) { $s{$_} = 1; } } my $user = $cgi->param("user") || $cgi->cookie(-name => 'user') || ""; if ($user) { tie %db, "DB_File", $user_db, O_RDWR|O_CREAT, 0666 or die "Can't open database $user_db: $!"; if ($db{"p:$user"}) { foreach (split /&/, $db{"p:$user"}) { $p{$1} = $2 if /(.*)=(.*)/; } } if ($db{"s:$user"}) { foreach (split /&/, $db{"s:$user"}) { $s{$_} = 1; } } } # get POST data my @postdata = grep { /[A-Z]/; } $cgi->param(); if (@postdata) { %p = (); $post = 1; #print STDERR "post - resetting data\n"; foreach (@postdata) { $p{$_} = $cgi->param($_); #print STDERR "post $p{$_} = $cgi->param($_)
\n"; } } if ($cgi->param("showall")) { $post = 0; %p = (); } # refresh planet copy my $time = (stat $planet_html)[9]; if (!-f $planet_html or time()-$time > 900) { system "wget -q -O - http://planet.debian.org/ > $planet_html"; } my $output = ""; open F, $planet_html or die "$planet_html: $!"; while () { if (/^/) { s/boxless.css/http:\/\/planet.debian.org\/boxless.css/; $output .= $_; $output .= < EOF } elsif (/^
/) { my $div = $_; my ($head, $h2) = (scalar , ""); if ($head =~ /^; } else { ($head, $h2) = ("", $head); # no hackergotchi } $h2 =~ /]*>(.*)<\/a>/; my $name = $1 || "hmm?"; my $name_mangle = $name; $name_mangle =~ s/[^[:alpha:]]//g; $p{$name_mangle} ||= ($post ? "n" : "y"); my ($exp_style, $div_style) = ("", ""); if ($p{$name_mangle} eq "y") { # show $exp_style = " style='display:none'"; } else { # hide $div_style = " style='display:none'"; } $div =~ s/>/ id="text_$count"$div_style>/; $h2 =~ s/<\/h2>/ collapse<\/small>
<\/span><\/h2>/; $output .= "$name
\n"; $output .= $div; $output .= $head; $output .= $h2; $count++; } elsif (/^
/) { my $div = $_; my $h3 = ; $h3 =~ //; $entry_href = $1; $entry_href =~ s/^http:\/\///; $entry_href =~ s/[^[:alpha:]]//g; my $collapse_entry = $s{$entry_href} ? "expand" : "collapse"; $h3 =~ s/<\/h3>/ $collapse_entry<\/small><\/h3>/; $output .= $div; $output .= $h3; # increment $count in

$s_new{$entry_href} = 1; } elsif (/^

/) { my $display = $s{$entry_href} ? "none" : "block"; s/>/ id="content_$count" style="display:$display">/; $output .= $_; # increment $count in

} elsif (/^

/) { my $display = $s{$entry_href} ? "none" : "block"; s/>/ id="date_$count" style="display:$display">/; $output .= $_; $count++; } elsif (/^

Subscriptions<\/h2>/) { $subscriptions = 1; $output .= $_; $output .= "
\n"; } elsif ($subscriptions and /^
  • (]*>)([^<]*)(<.*)/) { my $print = $1.$2.$3; my $name = $2; $name =~ s/[^[:alpha:]]//g; $p{$name} ||= $post ? "n" : "y"; $p_new{$name} = $p{$name}; # copy people to get rid of cruft my $checked = $p{$name} eq "y" ? " checked" : ""; $output .= "
  • $print\n"; } elsif ($subscriptions and /^<\/ul>/) { $output .= $_; $output .= "\n"; $output .= "
    \n"; $output .= "User:
    \n"; $output .= "
    \n"; $output .= "<\/form>\n"; $output .= "
    planet.cgi\n"; } else { $output .= $_; } } close F; # set new cookies my $people = join '&', map { "$_=$p_new{$_}"; } sort keys %p_new; my $pcookie = $cgi->cookie(-name => 'people', -value => $people, -expires => '+3M', -path => $path); my $seen = join '&', sort keys %s_new; my $scookie = $cgi->cookie(-name => 'seen', -value => $seen, -expires => '+7d', -path => $path); my @cookies = ($pcookie, $scookie); if ($user) { $db{"p:$user"} = $people; $db{"s:$user"} = $seen; push @cookies, $cgi->cookie(-name => 'user', -value => $user, -expires => '+3M', -path => $path); } # print output print $cgi->header(-type => 'text/html; charset=utf-8', -cookie => \@cookies); print $output;