newentry.pl

#!/usr/local/bin/perl5
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                   #
# newentry.pl                                                       #
#                                                                   #
# Accepts a password, a title, some text, the year, the month, the  #
# date, and whether the entry is public.                            #
#                                                                   #
# Adds the entry to a database.                                     #
#                                                                   #
# Returns a brief HTML acknowledgement page.                        #
#                                                                   #
# (c) 2000, Benjamin Schak                                          #
# Feel free to use in any way, as long as you keep this notice.     #
#                                                                   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

use CGI_UltraLite;
use SCHAK;
use DBI;

package main;

print "Content-type: text/html; charset=utf-8\n\n";

CGI_UltraLite::postparse();
$password = $CGI_UltraLite::value[0];
$title    = $CGI_UltraLite::value[1];
$text     = $CGI_UltraLite::value[2];
$year     = $CGI_UltraLite::value[3];
$month    = $CGI_UltraLite::value[4];
$date     = $CGI_UltraLite::value[5];
$perm     = $CGI_UltraLite::value[6];
$date     = $year . "-" . $month . "-" . $date;
$perm     = $perm ? "PUBLIC" : "PRIVATE";

# This is the real encrypted password.
#$realpassword = '$1$YW$7Y6JQbpt1oYNGSom.ZIAN/';
$realpassword = 'YWCgXD8SA0Rug';

$cryptpassword = crypt("$password", "YW");
if ($realpassword eq $cryptpassword) {
	$right = 1;
}
else {
	$right = 0;
}

unless ($right == 1) {
	print "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">
<html lang=\"en-us\">
<head>
 <title>
  Error
 </title>
 <meta http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.classify.org/safesurf/\" l gen true for \"http://www.schak.com/\" r (SS~~000 4 SS~~001 6 SS~~008 2))'/>
 <meta http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.rsac.org/ratingsv01.html\" l gen true comment \"RSACi North America Server\" for \"http://www.schak.com/\" on \"1999.06.30T18:38-0800\" r (n 0 s 0 v 0 l 3))'/>
</head>
<body>
 <p>
  Bad password.
 </p>
</body>
</html>";
}

else {
# Don't indent this loop, since doing so would take too much effort.

SCHAK::connect;

SCHAK::doselect("SELECT MAX(ID) FROM ENTRIES\;");
($id) = SCHAK::fetchrow_array() + 1;

$text  = SCHAK::quote($text);
$title = SCHAK::quote($title);

SCHAK::do("INSERT INTO ENTRIES
VALUES ($id, '$date', $title, $text, '$perm', 0)\;");

SCHAK::disconnect;

print "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">
<html lang=\"en-us\">
<head>
 <title>
  Done
 </title>
 <meta http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.classify.org/safesurf/\" l gen true for \"http://www.schak.com/\" r (SS~~000 4 SS~~001 6 SS~~008 2))'/>
 <meta http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.rsac.org/ratingsv01.html\" l gen true comment \"RSACi North America Server\" for \"http://www.schak.com/\" on \"1999.06.30T18:38-0800\" r (n 0 s 0 v 0 l 3))'/>
</head>
<body>
 <p>
  The platform has been updated.
 </p>
</body>
</html>";

# This ends the if-then-else block dealing with user authentication.
}