1: Okay yes, this is very ugly. I had it kind of nice and then 2: I decided to go all out and compact it a lot. So here is a 3: fully-functional CGI script that allows anyone to come in, 4: enter any name they want (yes, even multiple instances of 5: the same nick are allowed) and chat together. It does use 6: two small pieces of javascript: one to refresh the chat 7: messages (because inserting that meta tag in the HTML 8: headers would have taken more space) and one that sets focus 9: to the chat box when you put your mouse over it. 10: 11: It doesn't really fit in the category of obfu, but it will 12: look better here than anywhere else. Code is for reusable 13: stuff, same with Snippets. I don't think anyone'll want to 14: use this! 15: 16: Features of the program? Only one: URL's are turned into 17: links ONLY when used in the perlmonks way (using square 18: brackets). And even then, it must be a URL between the 19: brackets and nothing else. No vertical bar to name the 20: link! 21: 22: So here it is. All in 19 lines:<br> 23: 24: 25: 26: #!c:/perl/bin/perl 27: use strict;use CGI':Vars';use Data::Dumper;use Fcntl':flock'; 28: use IO::Scalar;my%i=CGI::Vars;my($a,$b,$d,$f,$r,$s,$g)=($ENV{ 29: 'SCRIPT_NAME'},$i{a},$i{u},$i{m});open L,">2.2"or die;flock L 30: ,LOCK_EX or die;our%c;do"1.1";$.=new IO::Scalar \$s;select$.;unless( 31: $b){print qq{<frameset rows="*,75"><frame src=$a?a=e><frame src= 32: $a?a=c&u=$d></frameset>};}if($b eq"e"){print qq{<script> 33: setTimeout('history.go(0)',8000);</script>};my$e;while(++$e){last if! 34: $c{$e};print qq{<strong>$c{$e}[0]</strong>: $c{$e}[1]<br>}if$c{$e};}} 35: if($b eq"c"){if(!$d){print qq{<form action=$a><input type=hidden name=a 36: value=c>Nickname:<input type=text name=u><input type=submit value=Start> 37: </form>};++$g;}if($f){$f=~s/</\</g;$f=~s/\[(.*?)\]/<a href='$1' 38: target=_blank>$1<\/a>/g;$c{++$c{n}}=[$d,$f];delete$c{$c{n}-15};}if(!$g){ 39: print qq{<form action=$a><input type=hidden name=u value="$d"><input 40: type=hidden name=a value=c>Message:<input type=text name=m size=50 41: onmouseover=focus()><input type=submit value=Chat></form>};}}open A,">1.1" 42: or die;flock A,LOCK_EX or die;print A Data::Dumper->Dump([\%c], ['*c']); 43: print$b?"</body></html>":"</html>";select STDOUT; 44: print"Content-type: text/html\n\n";print$b?"<html><body>":"<html>";print$s;
Back to
Craft