Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

In my wanderings about the monastery I've discovered some cool goings-on on people's home nodes. The following is a collection of a few such things as well as some enhancements I've made. I've tried to give credit where credit is due, but as some of these things appear on many home nodes I've probably got it wrong. If you want to claim 'I was first' leave a note for others to read below.

1. Other stuff in your Bio
Beatnik's home node shows several extra pieces of info in his bio. Normally your bio just shows a few things that are standard on everyone's home node (Experience, Level, Location etc.) However, as the location is free-text it is possible to insert further fields into your bio.

Add this to your location, you can put more than one, just repeat the code:

</td></tr><tr><td>Field Name:</td><td>Field Content
2. The Button
I first ran into the button when someone clicked the button on Beatnik's home node. I don't want to spoil it for you other than to say once you've clicked it read the chatterbox.
<form method="POST"> <input type="hidden" name="op" value="message"> <input type="hidden" name="node_id" value="5993"> <input type="hidden" name="message" value="Your Message"> <input type="submit" value="Button Title"> </form>
Note: It is possible to add the button to your bio in the manner described above and as done on my home node.

3. The Javascript Warning
Petruchio has this piece of javascript on his home node as a warning. This javascript reads your perlmonks cookie and warns that is could be sent to another site for hacking your password.

<img src="http://www.brinzer.net/png/border.png" onload="if (document.cookie.length < 1) { return } alert( 'This is why you should not run around with JavaScript' + 'enabled. Your cookie says: ' + document.cookie + ' This information could have been quietly sent to a remote server, +' + ' and your account stolen.');">
3a. The Javascript Greeting
When you visit smitz' home node you'll get a lovely little greeting and a warning about javascript. He takes the cookie (as shown above) and extracts your username from it. He then says hello to you.
<script language="javascript"> <!-- var cookie = document.cookie; var userstart = cookie.indexOf('userpass', 0) + 9; var userend = cookie.indexOf('%257C', userstart); if( userend > userstart ) { var username = cookie.substring(userstart, userend); // For some reason, the RegExps don't work, // so we resort to the good old style. :) while( username.indexOf('%2520') > -1 ) { var index = username.indexOf('%2520'); username = username.substring(0, index) + ' ' + username.subst +r(index + 5, username.length); } document.write( '' + '<hr /><p align="center">' + '<table border="1" cellpadding="6">' + '<tr><td>' + 'Hello <i>' + '<a href="/?node=' + username + '">' + username + '</a></i>!<br />' + 'Javascript bad, you know? ' + 'Maybe you should turn it off,' + ' lest I dunk your cookies, bub.' + '</td></tr></table>' + '</p>' ); } //--> </script>
3b. The Home Node Logbook
After seeing the above greeting it occurred to me that I could use it to keep a log of the people who visit my home node. This uses two pieces of code: firstly the javascript to snarf the username and then a (remotely hosted) perl script to log the username with the time.

The javascript:

<script language="javascript"> <!-- var cookie = document.cookie; var userstart = cookie.indexOf('userpass', 0) + 9; var userend = cookie.indexOf('%257C', userstart); if( userend > userstart ) { var username = cookie.substring(userstart, userend); while( username.indexOf('%2520') > -1 ) { var index = username.indexOf('%2520'); username = username.substring(0, index) + ' ' + username.subst +r(index + 5, username.length); } document.write("<script src='http://www.isite.net.au/perlmonks/per +lmonkvisitor.pl?visitor="+username+"'></script>"); document.write("Hello "+username+", welcome to my homenode. Your visit + has been logged. If you'd like to see my log you can see it <a href= +'http://www.isite.net.au/perlmonks/perlmonkvisitor.pl'>here</a>.") } //--> </script>
The perl code. This code will not log you and will print your log if called without a visitor parameter:
#!/usr/bin/perl -w $visitorfile = "/path/to/visitors.txt"; use CGI; $query = new CGI; # If the visitor parameter exists then we assume its a visit from the +home node: if (my $visitor = $query->param('visitor')) { # Don't log ourselves: unless ($visitor =~ /your_username/i ) { open (VISITORS,">>$visitorfile") || die("Perlmonk Visitors cou +ldn't open $visitorfile: $!"); print VISITORS scalar(localtime) . "\t" . $visitor . "\t" . $E +NV{HTTP_REFERER} . "\n"; close VISITORS; } print "Content-Type: text/javascript\n\n"; # Output our javascript: print qq|document.write("Welcome and ")|; } else { open (VISITORS,"$visitorfile") || die("Perlmonk Visitors couldn't +open $visitorfile: $!"); @data = <VISITORS>; close VISITORS; print "Content-Type: text/html\n\n"; print "<h1>Visitors to my Homenode</h1>\n"; print "<table border=1 cellspacing=0><tr><th>Time/Date</th><th>Use +rname</th></tr>\n"; foreach $line(@data) { my ($date, $user) = split(/\t/,$line); print "<tr><td>$date</td><td>$user</td></tr>\n"; } print "</table>"; }
4. The Messager
Once again from Petruchio's home node comes this non-javascript code to allow visitors to send you a message when they visit your homenode. This harmless piece of code just submits a '/msg' to the chatterbox.
<form method="post"> <input type="hidden" name="op" value="message"> <input type="hidden" name="message" value="/msg Petruchio Hi, I just visited your page."> <center> <input type="submit" name="message_send" value="Hello"> </center> </FORM>
4a. The Custom Messager
This is an adaptation of the above. It uses javascript to allow the user to create their own custom message.
<form method="post" name='f' onSubmit="f.message.value = f.message.val +ue + prompt('Enter your message:'); return true;"> <input type="hidden" name="op" value="message"> <input type="hidden" name="message" value="/msg Username "> <center> <input type="submit" name="message_send" value="Hello"> </center> </form>

Edit kudra, 2002-09-26 Added readmore tag


In reply to Cool code for your home node by BigLug

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (14)
    As of 2014-04-16 20:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (433 votes), past polls