3 ms·
We’re in the nineties, okay? Whee! #!/usr/bin/perl $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV
by williamcotton 2y ago
We’re in the nineties, okay?
Whee!
#!/usr/bin/perl
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$buffer = $ENV{'QUERY_STRING'};
}
print "Content-type: text/html\n\n";
$post_id = $buffer;
$post_id =~ s/&.*//; # Get first parameter (before any &)
$post_id =~ s/[^a-zA-Z0-9\._-]//g; # Sanitize input
$truncate = ($buffer =~ /truncateContent=true/) ? 1 : 0;
$title = `mysql -u admin -p'password' -D blog --skip-column-names -e "SELECT title FROM posts WHERE url='$post_id'"`;
chomp($title);
$content = `mysql -u admin -p'password' -D blog --skip-column-names -e "SELECT content FROM posts WHERE url='$post_id'"`;
chomp($content);
if ($truncate) {
# Extract first paragraph (everything before the first blank line)
$first_paragraph = $content;
$first_paragraph =~ s/\n\n.*//s;
print "<h3><a href=\"/$post_id.html\">$title</a></h3>\n";
print "<p>$first_paragraph [...]</p>\n";
} else {
print "<h1>$title</h1>\n";
print "<p>\n";
print "$content\n";
print "</p>\n";
}