Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

pmproxy2

by nashdj (Friar)
on Apr 02, 2001 at 15:58 UTC ( [id://68975]=CUFP: print w/replies, xml ) Need Help??

Update:

See Arguile's post below (pmproxy2.0.1?) for a much more up to date/feature packed version. Or see a screenshot (1/6/2001).


You may or may not have seen this before - pmproxy, but its back and I think it's really getting somewhere :) Before I get into the details, go take a look at what I was able to achieve - pmproxy2.png.

This new version basically adds cookie and post support. In my haste I wasnt able to find a way to correctly save the cookies to the file. If anyone can help me with that I would be most greatfull.

It does still lack any form of error control, I guess I'll add to that as I come across things. But so far I havent had too many problems.

I used this stylesheet to achieve whats displayed in the above screenshot.

As you can see at the bottom of the code I have added a simple sub in which to define some substitutions and other operations to be applied to the page. This is just to clean a few things up which I couldnt override in the css.

If you want to give it a go, grab the below code, save it to something like pmproxy2.pl. Get a stylesheet, try the one linked above (place that in the same directory). Then exec the script and connect to http://localhost:99/index.pl

Let me know what you think, or if I've done something strikingly bad with the code!

- nashdj

use strict; use LWP::Simple; use HTTP::Daemon; use HTTP::Status; use HTTP::Cookies; use LWP::UserAgent; open(CSS,"style.css") || die "CSS Error: $!"; my $css = join("",<CSS>); close(CSS); my $ua = new LWP::UserAgent; my $co = HTTP::Cookies->new(); $ua->cookie_jar($co); my $d=HTTP::Daemon->new(LocalAddr=>'localhost', LocalPort=>'99', Reuse => '1') || die "Cant Spawn: $!"; while(1) { my $c = $d->accept; my $r = $c->get_request(); my $url = $r->uri->as_string; my $content; if ($url !~ /style.css$/i) { $url = "http://www.perlmonks.org$url"; my $req; if ($r->method eq "GET") { $req = new HTTP::Request GET => $url; } else { $req = new HTTP::Request POST => $url; $req->content_type($r->content_type); $req->content($r->content); } my $res = $ua->request($req); $content = $res->content; $content = &dosubs($content); } else { $content = $css; } my $response = HTTP::Response->new(); $response->content($content); $c->send_response($response); $c->close; } sub dosubs { $_ = shift; s|<body|<link rel=stylesheet type="text/css" href="/style.css" />\ +n<body|i; ####DEFINE SUBSTITUTIONS HERE#### s/#FFFFFF/#EEEEEE/gi; s/border=1//gi; s/("checkbox")/$1 class="noborder"/gi; s/(INPUT type=radio)/$1 class="noborder"/gi; s/("radio")/$1 class="noborder"/gi; s/<font size=2/<font style="text"/gi; s/www\.perlmonks\.org/localhost:99/gi; ################################# $_; }

Replies are listed 'Best First'.
pmproxy2.0.1?
by Arguile (Hermit) on May 29, 2001 at 22:02 UTC

    Well, now I don't have to bug vroom about allowing custom themes. ;)

    I'm sort of new to this whole Perl game, so I love syntax highlighting. A CPAN search and came up w/ Syntax::Highlight::Perl so I tried it out and thought it would be very cool to view code on Perl Monk's w/ syntax highlighting in your own custom colours. So I wrote the following quick hack to nashdj's very cool proxy idea.

    Update:

    Quite a few changes to the overall code, broke some sections up and it's much nicer now. I slapped my head when I saw your regex solution nashdj, I didn't realise you could eval inside one. I caught the $formatter->reset() too but forgot to add it to the code on here initially. I also added perm cookie support so the proxy stores user info between sessions. I'd love to hear what you think of this updated hack of your code ;).

      That is truly amazing. It looks fantastic with highlighting applied. Coloured Obfuscation either looks beautiful or downright horrible :)

      I have an exam in about an hour, so rather than study I thought I'd play around with this for a bit. Just shortened your parsing code into a substitution, added support for the numbered pre sections (craft), and fixed up a slight problem with not resetting the formatter.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://68975]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found