From: Bob M. <mce...@dr...> - 2002-01-16 17:31:52
|
Mario Lang [la...@zi...] wrote: > Hi. >=20 > As colour highlighted markup isnt the best method for me, I hacked the sh= owfiltering > part of Rewrite.pm a bit to optionally produce either diff -u or diff -c > output... Here is the patch against FilterProxy/Rewrite.pm. I wanted > to send it to you first, and leave the interface changes also up to you i= f you > want to include it... >=20 > Basicly, if you call showfiltering with an additional parameter &diff=3D-= u, > you get the difference between the original document and the rewritten on= e. Looks good to me. Go ahead and check this into CVS. You should change: if(defined $cgi->param('diff') && $cgi->param('diff')) { #... So that perl doesn't generate an "uninitialized value" warning at runtime. I used a CSS stylesheet for the colored marked-up pages. I used=20 <span class=3D"rulename">=20 tags to make the colored sections. Would there be a way of changing the stylesheet instead to make reading this easier for you? > Maybe we can even generalize this further to make it work with XSLT too? The diff would be easy for xslt, go ahead and write it if you want it. I've been slowly reading a few sites about XSLT. There's a pretty good rant abo= ut it on http://www.kuro5hin.org. The color highlighted markup would be very difficult for xslt. As it was, keeping track of which pieces of the document were modified in Rewrite was = much more difficult than I expected. With XSLT, all the work it does is hidden = in the libxslt library. So a 'diff' is about the only thing you can do. I don't like diff though because many web pages have very long lines (gener= ated by a script), so looking at a diff shows you the two 500 char long lines, a= nd it's a bit of work to scan through that line and figure out what was change= d. :( Probably better than nothing though! The diff stuff could be put in FilterProxy.html instead, that way you could= see all the changes at once. But then it would be difficult to tell what chang= ed what. The Rewrite markup gives you the rule name. How would you figure out which xslt stylesheet changed what? > Index: FilterProxy/Rewrite.pm > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/filterproxy/FilterProxy/FilterProxy/Rewrite.pm,v > retrieving revision 0.33 > diff -u -r0.33 Rewrite.pm > --- FilterProxy/Rewrite.pm 2002/01/12 22:43:54 0.33 > +++ FilterProxy/Rewrite.pm 2002/01/15 19:25:40 > @@ -24,6 +24,9 @@ > use vars qw($VERSION $CONFIG); > use Time::HiRes; > use URI::Escape; > +use Fcntl; > +use POSIX qw(tmpnam); > + > $VERSION =3D 0.30; > push @FilterProxy::MODULES, "Rewrite"; > $FilterProxy::Rewrite::CONFIG =3D {}; > @@ -1139,6 +1142,24 @@ > logger(ERROR, "View unfiltered source returned HTTP code: " = . $res->code); > return("HTTP code: " . $res->code); > } > + if ($cgi->param('diff')) { > + my $tmpnm1 =3D tmpnam(); > + my $tmpnm2 =3D tmpnam(); > + sysopen(ORIG, $tmpnm1, O_RDWR|O_CREAT|O_EXCL); > + sysopen(NEW, $tmpnm2, O_RDWR|O_CREAT|O_EXCL); > + print ORIG $origdoc; > + print NEW ${$res->content_ref}; > + close ORIG; close NEW; > + my $prm =3D $cgi->param('diff'); > + if ($prm!~/^-[cu]$/) { > + return "Cracker attack..."; > + } > + my $diff=3D`/usr/bin/diff $prm $tmpnm1 $tmpnm2`; > + unlink($tmpnm1);unlink($tmpnm2); > + $diff=3D~ s/</</g; > + $diff=3D~ s/>/>/g; > + return $diff; > + } else {=20 > $res->content($origdoc); # We don't care what the changed docum= ent looks like, we got > my($doc) =3D ""; # everything we need in @markup > my($markup); > @@ -1193,6 +1214,7 @@ > } > } > return $message; # message printed to user > +} > } > =20 > # Some code so this can be run at the command line -- for filtering algo= rithm tests. >=20 Cheers, -- Bob Bob McElrath (rsm...@st...)=20 Univ. of Wisconsin at Madison, Department of Physics |