Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things


by strredwolf (Chaplain)
on Jan 11, 2001 at 11:10 UTC ( #51090=sourcecode: print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info strredwolf
Description: Anything, a mini-clone of Everything(which runs PerlMonks). This is what I get for trying to organize things with WolfSkunks. It is a CGI script, though, and works well with mhttpd. It will auto-setup itself. Just edit $root.

Update 1-11: Updated to secure it a bit and use CGI::Lite (which I think is a lot less complicated than all of CGI). The square brackets now work.

Update 1-29: Updated it again so that updates and node editing actually works.

# Anything, an Everything clone
# By strredwolf

# Config...

# Code
use CGI::Lite;
$cgi=new CGI::Lite;


chdir $root;

if(! -e 'ids/-1')
    mkdir 'names';
    mkdir 'ids';
    print OUT "Item not found\n-1\nNot found!  Try again.\n";
    print OUT "New node\n-2\n\n";

    $node_id=$form{"node_id"}; $node=$form{"node"};

    $node_id=0, $op='' unless($node_id ne ''||$node);
    chomp $node; chomp $node_id;
    if($node) {
    $node =~ y/A-Z/a-z/;
    $node =~ y/a-z0-9/_/cs;
    opendir(DIR,"names/.") || print "Error: $!\n";
    if(@z) { 
        <IN>; $node_id=<IN>; chomp $node_id; close(IN);
    foreach($node_id,-1) {
    $node_id=-1 unless(/^-?\d+$/);
    last if(-e $path);
    if(open(IN, "<$path")) {
    $name=<IN>; chomp $name;
    $nid=<IN>; chomp $nid;
    @mess=<IN>; @m2=@mess;
    foreach $_ (@m2)
        s#\[id://(\d+)\|([^\]]+)\]#<a href="/cgi-bin/
        s#\[(http[^|]+)\|([^\]]+)\]#<a href="$1">$2</a>#g;
        s#\[([^|]+)\|([^\]]+)\]#<a href="/cgi-bin/$1"
        s#\[([^\]]+)\]#<a href="/cgi-bin/$1">$1</a>#g
    print "Content-type: text/html\n\n";
    print "<html><head><title>$name -- Anything</title></head>\n";
    print '<body><TABLE WIDTH="99%" BORDER="0"><tr><td>';
    print "\n<b>$name</b><BR>$node_id\n</td>\n";
    print '<TD ALIGN="RIGHT"><B><I><FONT SIZE="+2">Anything</FONT></I>
+</B><BR><A HREF="/cgi-bin/">New node</a

    print "<P>";
    print @m2;
    print "</P>";
    if($op ne "edit")
        print "<P><a href=\"/cgi-bin/$nid&op=edit\
+">Edit this node</a></P>" if($nid>-1);
    } else {
            $nid = <IN>; chomp $node_id;
        } else { $nid=0 };
        print OUT "$nid\n";
        print '<hr><form method="post" action="/cgi-bin/"><
        print '<INPUT TYPE="text" NAME="name" SIZE="60" MAXLENGTH="256
+" VALUE="'.$name.'";><BR>';
        print '<TEXTAREA NAME="mess" COLS="60" WRAP="VIRTUAL" ROWS="20
        print "\n";
        print @mess;
        print "\n</textarea>";
        print '<INPUT TYPE="submit" NAME="op" VALUE="post">';
        print '<INPUT TYPE="hidden" NAME="node_id" VALUE="'.$nid.'">';
        print '</p></form>';
    print "\n<hr></body></html>\n";
    } else {
    print "Died because of this: $!<BR>\n";
} elsif($ENV{'REQUEST_METHOD'} eq "POST") {
    $node_id=$form{"node_id"}; $name=$form{"name"};
    $op=$form{"op"}; $mess=$form{"mess"};
    $node =~ y/A-Z/a-z/;
    $node =~ s/[^a-z0-9]/_/g;
    print OUT "$name\n$node_id\n$mess";


    print "\n\n";
    print "<html><head><META HTTP-EQUIV=\"Refresh\" content=\"2;URL=ht
    print "<a href=\"/cgi-bin/$node_id\">This is w
+here to go...</a>\n";
    print "</body></head>\n";

Replies are listed 'Best First'.
Re (tilly) 1: Anything
by tilly (Archbishop) on Jan 11, 2001 at 19:37 UTC
    I voted --, and wanted to explain why.

    Given all of the fuss over handrolled CGI parsers lately, I am amazed that you would post your own. chromatic right now has an excellent explanation of why you really didn't want to do that. (And yes, you did make most of the common mistakes.)

    Additionally you don't seem to be aware of a variety of race conditions, security holes, etc. For a random instance take a look at this and figure out how many of the attacks you could be taken down with. Oh, better than that, how many of the attacks are designed to get around checks that you don't even do?

    Hopefully you will take this as constructive criticism and learn how to avoid these problems in the future. But in the meantime -- for bad advice that will put at risk anyone who follows it.

      Thanks for the comments. I was looking for them, too!

      Yep, it's unfortunately handrolled, I'm a little bit spooked by's complexity. Sheesh, I just need to get varibles, not wrap the entire HTML generation process!!! (Update through the chatterbox: is split and autoloads what's needed. *sigh* Thanks, Fastolfe)

      It's also crude code, ment for an end-user; but securing it's probably worthy of some time.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://51090]
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-29 08:22 GMT
Find Nodes?
    Voting Booth?