Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found