/path/to/the/message
####
/path/to/the/message?mode=edit
####
use CGI qw(:all);
my $MESSAGE_LOCATION = "/path/to/file.txt";
my $CRYPTED_PASSWORD = "aaPwJ9XL9Y99E";
## this is from print crypt("hello", "aa"), so "hello" is the password
print header, start_html;
if (my $new_text = param('text') and my $password = param('password')) {
## update mode... is the password good?
if (crypt($password, $CRYPTED_PASSWORD) eq $CRYPTED_PASSWORD) {
open F, ">$MESSAGE_LOCATION" or die;
print F $new_text;
close F;
print h1('updated!'), p('The message was updated!');
}
} elsif (param('mode') eq 'edit') {
## secret mode
open F, $MESSAGE_LOCATION or die;
my $message = join '', ;
close F;
print h1('edit the message');
print start_form;
print textarea('text', $message);
print 'password: ', password_field('password');
print submit('update');
print end_form;
}
## always display the result:
open F, $MESSAGE_LOCATION or die;
my $message = join '', ;
close F;
print h1('Welcome to our info page');
print h2("Today's top tip:"), escapeHTML($message);
print end_html;