Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Muse - Personal Interlinked Encyclopedia Builder

by Pedro Picasso (Sexton)
on Apr 04, 2002 at 05:50 UTC ( [id://156579]=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info Adrian P. Dunston (pedro_picasso@x-omega.com)
Description: Do you like Everything2 and Perlmonks but can't seem to get the code to work on your machine because you're running Mandrake and not Debian or RedHat and while EveryDevel is a great company with a great content manager, their documentation leaves a lot to the imagination, and you honestly don't have time to sift through database application code when all you want is to have your own easily maintainable set of interlinked content? Well this is the script for you!

It's a simple CGI hack that imitates PerlMonks/Everything2's noding. You type a "musing" with links to other musings in brackets. It's great for keeping your own interlinked encyclopedia of personal notes.

#!/usr/bin/perl -wT

#########################################################
# Muse 
# A "Web of Content" Manager by Adrian P. Dunston
#
# This is a sort of dumbed down single user of the
# Everything Engine that Perlmonks runs on.
# (www.everydevel.com)
#
# Write different nodes or "musings" and link them
# together by surrounding certain words with [brackets].
# In the case of the last sentence, the word "brackets"
# links to the node of that title.
#########################################################

use strict;
use warnings;

use CGI qw(:standard);    
use CGI::Carp qw(fatalsToBrowser);



start();   


sub start {
    my $cgi = new CGI;
    my $output;
    my $node_text;
    my $node = param("node");
    my $text = param("text");

    print $cgi->header;

    # Untaint
    ($node) = $node =~ /([A-Za-z0-9 -_.,?]{1,30})/g;







    # If text has been passed, put it into its node.
    if ($text) {
        open(NODE, ">data/$node.musing") or die "Couldn't open data/$n
+ode.musing for writing because $!";
        print NODE $text;
        close NODE;
    }

    # If the user wants to see a node, show it to him with a form for 
+editing it.
    if ($node) {

        if (open(NODE, "data/$node.musing")) {
            $node_text .= $_ while <NODE>;
            $output = $node_text;
            $output =~ s|\[(.+?)\]|<a href="muse.cgi?node=$1">$1</a>|g
+;
            $output = "\n\n<table width=\"65\%\" style=\"margin-left: 
+50\"><tr><td>\n" . $output . "</td></tr></table>\n\n";
        } else {
            $output = "There is currently no musing \"$node\".  You ar
+e welcome to create your own.";
        }

        $output = "<html>\n<head><title>$node - Muse</title></head>\n<
+body>\n" .
            "<b style=\"font-size: 18pt\">$node</b><br><br>$output\n<b
+r><br><br>\n";

        $output .= '<form action="muse.cgi" method="post">';
        $output .= "\nEdit the node:<br>\n<textarea name=\"text\" rows
+=\"5\" cols=\"50\">$node_text</textarea><br>\n";
        $output .= "<input type=\"hidden\" name=\"node\" value=\"$node
+\">\n";
        $output .= "<input type=\"submit\" value=\"Edit Musing\">\n</f
+orm>\n";
        $output .= "<hr>\n";
        $output .= '<form action="muse.cgi" method="post"><input type=
+"text" name="node"><input type="submit" value="New Musing"></form>';
        $output .= '[ <a href="muse.cgi">Muse</a> ]  ';
        $output .= "</body>\n</html>";

    # Otherwise, show him the list of nodes in the system.
    } else {
        my @file = <data/*.musing>;

        foreach (@file) {
            s|data/||;        # Get rid of data/
            s/\.musing//;        # Get rid of .musing
            $output .= "<li><a href=\"muse.cgi?node=$_\">$_</a></li>\n
+";
        }

        $output = "<html>\n<head><title>Muse</title></head>\n<body>\n<
+u><b style=\"font-size: 24pt\">MUSE</b></u><br><br>\n" .
            "Musings: \n<ul>\n$output\n</ul>";

        $output .= '<form action="muse.cgi" method="post"><input type=
+"text" name="node"><input type="submit" value="New Musing"></form>';
        $output .= "</body>\n</html>";
    }


    ## OUTPUT
    print $output;


}
Replies are listed 'Best First'.
Re: Muse - Personal Interlinked Encyclopedia Builder
by MeowChow (Vicar) on Apr 04, 2002 at 06:11 UTC
    You really need to learn about and use Taint.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

      Thanks for the suggestion. I've untainted my input.

      I never use taint mode because I don't maintain a public http server (all my scripts are single-user only and behind a firewall), but I guess that doesn't really help other people who download my code and have it exploited. Please let me know if you think there's still a problem.



      -the Pedro Picasso
      (sourceCode == freeSpeech)
        I think you're permitting too much. I'd write:
        ($node) = $node =~ /\w{1,32}/g;
        Remember. Be paranoid. They are out to get you :)
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print
Re: Muse - Personal Interlinked Encyclopedia Builder
by thraxil (Prior) on Apr 04, 2002 at 16:04 UTC

    i'd really recommend using HTML::Template or some other templating mechanism. seeing all that html mixed in with the perl makes me cringe.

    anders pearson

      I agree that the mixing of code can get ugly, and this is an hour's hack and not the way I'd generally do it, but I prefer to avoid the templating way of doing it. Calling templates and passing them values can be just as ugly as bare HTML and it removes you one step from what you're actually trying to do (which is communicate through web pages).

      My preferred approach is object oriented. I create a "Display" object with subs for form generation, etc. that are specific to my current problem. If I can design the interfaces to these objects well enough, I can rewrite them later for Tk or whatever other kind of user display I'm using and not have to re-write the rest of the app. This provides cleanliness in the functional code and separation from the display code but still allows you to see the HTML directly when you want to.

      So far I don't know anyone else who does it this way, but I prefer it.

      -the Pedro Picasso
      (sourceCode == freeSpeech)
Re: Muse - Personal Interlinked Encyclopedia Builder
by premchai21 (Curate) on Apr 04, 2002 at 18:57 UTC

    Hmm. I wrote pocowiki a while back, which has the same sort of purpose (lightweight (Wiki/Every)-like engine), but is implemented very differently -- I use POE::Component::Server::HTTP (so it runs its own micro-HTTP server), and the database is stored in memory, using Data::Denter for (de)serialization to/from disk. I also wrote a little (MUCK-MPI)-like preprocessor for use on my website. Perhaps I should post (it/them) sometime...

    Update: Just noticed -- Personal Interlinked Encyclopedia? PIE? :-)

Re: Muse - Personal Interlinked Encyclopedia Builder
by cider (Acolyte) on Jun 15, 2002 at 03:06 UTC
    # no .. / ` \ die "no .. \/ \` \\ allowed in node name.\n" if ($node =~ /(\.\.|\/|\` +|\\)/);
    I strongly reccomend adding this snippet to this program if you are placing this on the public internet. Do not evaluate $node and run an open statement without doing more sanity checking on whats being sent your way. Making a node as ../data/test would work. With this, it would get shot down before the open call.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found