#!/usr/bin/perl

my $MYFILENAME   = "fbs_001.txt";   # XXX: Absolute path?
my $SELF         = "http://www.cordula.ws/feedback.cgi";
my $BGCOLOR      = "#204060";
my $FGCOLOR      = "#FFFF00";
my $PICBEFORE    = "noaau037.jpg";
my $PICAFTER     = "noaau038.jpg";
my $PICBROKEN    = "mfcross.gif";
my $PICBEFOREALT = "Cordula's Web. NOAA. Long Bridge at Dawn.";
my $PICAFTERALT  = "Cordula's Web. NOAA. Long Bridge at Dawn, somewhat later.";
my $PICBROKENALT = "Cordula's Web. Broken Multifacetted Cross.";

$MYHEADER = <<'END_OF_HEADER';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta name="generator" content="HTML Tidy, see www.w3.org">
    <link rel="stylesheet" rev="stylesheet" href="cordula.css" type="text/css">
    <link rel="icon" rev="icon" href="favicon.ico">

    <title>Cordula's Web. Feedback Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="robots" content="follow,index,archive">
    <meta name="keywords" content="cordula, philipps, tribute">
    <meta name="description" content="A Tribute to Cordula Philipps.">
    <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline EN v2.0" l gen true for "http://www.cordula.ws/" r (nz 1 vz 1 lz 1 oz 1 cz 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.cordula.ws/" r (n 0 s 0 v 0 l 0))'>
  </head>

  <body bgcolor="#000000" text="#00D0FF" link="#00C000" vlink="#00C000" alink="#00C000" style="color: #00D0FF; background-color: #000000; font-family: Helvetica, Arial, Verdana, sans-serif;">
    <div>
      <center>
        <table cellspacing="0" width="800">
          <!-- 1. Header with banner -->

          <tr>
            <td>
              <img src="cpban.jpg" alt="Cordula's Web Banner"> 
            </td>
          </tr>
          <!-- 2. Middle Part with 3 columns -->

          <tr>
            <td>
              <table width="100%">
                <tr>
                  <!-- Left margin -->

                  <td style="background-color: #204060;" bgcolor="#204060" valign="top" width="20%">
                    <table style="background-color: #204060;" width="100%">
                      <tr>
                        <td><span style="color: #D0D000;"><b>Cordula's<br>
                         &nbsp; &nbsp; Web</b></span></td>
                      </tr>

                      <tr>
                        <td><span style="font-size: smaller; color: #D0D000;">A Tribute<br>
                         to Cordula<br>
                        </span> </td>
                      </tr>

                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><a href="http://www.cordula.ws/"><img src="btn_a_home.gif" alt="Home" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="about.html"><img src="btn_a_about.gif" alt="About" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="poetry.html"><img src="btn_a_poems.gif" alt="Poems" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="quotes.html"><img src="btn_a_quotes.gif" alt="Quotes" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="stories.html"><img src="btn_a_stories.gif" alt="Stories" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="authors.html"><img src="btn_a_authors.gif" alt="Authors" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="gallery.html"><img src="btn_a_gallery.gif" alt="Gallery" border="0"></a></td>
                      </tr>

                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><a href="thebridge.html"><img src="btn_a_thebridge.gif" alt="The Bridge" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="barrayar.html"><img src="btn_a_thorns.gif" alt="Thorns" border="0"></a></td>
                      </tr>

                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><a href="sitemap.html"><img src="btn_a_sitemap.gif" alt="Site Map" border="0"></a></td>
                      </tr>

                      <tr>
                        <td><a href="changelog.html"><img src="btn_a_changelog.gif" alt="Change Log" border="0"></a></td>
                      </tr>

		      <tr>
		        <td><img src="btn_i_contactus.gif" alt="Contact Us" border="0"></td>
		      </tr>

                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><a href="helpwanted.html"><img src="btn_helpwanted.gif" alt="Help Wanted" border="0"></a></td>
                      </tr>
                    </table>
                  </td>
                  <!-- Main body -->

                  <td width="78%">
                    <table width="100%">
                      <!-- Main content -->

                      <tr>
                        <td>
END_OF_HEADER

$MYFOOTER = <<'END_OF_FOOTER';
                        </td>
                      </tr>

                      <tr>
                        <td>
                          <hr>
                        </td>
                      </tr>
                      <!-- Dedication and Yellow Ribbon Campaign -->

                      <tr>
                        <td>
                          <table width="100%">
                            <tr>
                              <td width="50%">
                                <p style="text-align: center;"><span style="color: #FF0000;">A Tribute to Cordula.</span><br>
                                 <span style="color: #FF0000; font-size: smaller;">(Per Amica Silentia)</span><br>
                                 &nbsp;<br>
                                 <span style="font-size: smaller;">Quia natura mutari non potest,</span><br>
                                 <span style="font-size: smaller;">idcirco verae amicitiae sempiternae sunt.</span><br>
                                 <em><span style="font-size: smaller;">-- Cicero. (<a href="q-amicitia.html">Laelius de Amicitia, 32</a>).</span></em><br>
                                </p>
                              </td>

                              <td valign="middle;"><a href="yellowribbon.html"><img src="yellowribbon.gif" alt="Yellow Ribbon" border="0"></a> </td>

                              <td>
                                <p style="text-align: center; font-size: smaller;"><a style="color: #FFFF00;" href="yellowribbon.html">Yellow Ribbon Campaign</a><br>
                                 &nbsp;<br>
                                 <em>When someone has been taken away from their loved ones a yellow ribbon is used to show love in absentia and hope for their return.</em></p>
                              </td>
                            </tr>
                          </table>
                        </td>
                      </tr>
                    </table>
                  </td>

                  <td style="background-color: #204060;" bgcolor="#204060" width="2%">
                    <p>&nbsp;</p>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <!-- 3. Bottom with legaleze etc... -->

          <tr>
            <td>
              <hr>

              <table style="font-size: x-small;" width="100%">
                <tr>
                  <td valign="top" width="80%">Last modified: $Date: 2007/07/11 04:35:20 $<br>
                   <a href="feedback.cgi">Contact Us</a> :: <a href="faq.html">Questions?</a> :: <a class="LegalLink" href="disclaimer.html">Disclaimer</a> :: <a class="LegalLink" href="copyright.html">Copyright</a> :: <a class="LegalLink" href="privacy.html">Privacy</a> </td>

                  <td valign="top" width="20%"><a href="http://www.freebsd.org/"><img src="powered-by-freebsd.gif" alt="FreeBSD Logo"></a> </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </center>
    </div>
    <!-- $Id: feedback.cgi,v 1.44 2007/07/11 04:35:20 cordula Exp $ -->
  </body>
</html>
END_OF_FOOTER

my $MYTABLE = <<"END_OF_TABLE";
                          <center>
                            <img src="$PICBEFORE" alt="$PICBEFOREALT">
                          </center>

                          <h3>Cordula's Web Feedback Form</h3>

                          <h4>We'd love to hear from you!</h4>

                          <p class="feedback">
                            Did you like Cordula's Web? Would you like to submit a poem or short story? Do you have an idea how to improve this site? Do you operate a Cordula web site and would like to participate in a mutual link exchange? Please share your opinions with us. Besides English, we also speak French and German fluently. We also understand <em>a little bit</em> of Spanish and Italian (though not enough, so we'll reply in English). Praise and flames are welcome! :)
                          </p>

                          <p class="feedback" style="font-size: smaller;">Please fill in the form below and click on the <em>Send Message</em> button at the bottom of the form to send your message. You can remain anonymous by leaving the <em>E-Mail</em> field empty. For obvious technical reasons, only messages with valid E-Mail addresses can expect a reply. By using this form, you agree to the conditions stipulated in our <a class="LegalLink" href="privacy.html">privacy policy</a>.
                          </p>

                          <p class="wikinote" style=\"color: #FFFF00;\"><b>Very important!</b> We can't reply, if you don't submit a <b>valid</b> e-mail address! If you didn't get a reply within a week or two, the reason could be that the address you've submitted is incorrect, contains a typo or is otherwise unreachable. If this happens to you, please resubmit again and make sure you double-check your e-mail address. Thank you.</p>

                          <p class="wikinote" style=\"color: #FF0000;\"><b><blink>Latest News</blink></b> (2006-04-15) We've just discovered a bug in our feedback program that has been lingering for over two months! If you did send us a message in the last 8 weeks or so, and we didn't get back to you, we're terribly sorry! <b>Some</b> (but not all!) messages have been stored in a private file here on the server, but were not sent out to our internal mailing list, so we never saw them up until now. We're right now working through the backlog of two months worth of stored messages, and working as fast as we can to catch up. If the feedback program accepted your message, there's no need to resend it: it's here in the queue. Sorry, and thank you for your patience.</p> 

                          <p class="feedback" style="font-size: smaller; text-align: center;"><em>-- Cordula's Web feedback program.</em></p>

                          <form action="$SELF" method="POST">
                            <table border="0" cellpadding="0" cellspacing="5">
                              <tr>
                                <td class="feedback" valign="top" style="font-size: smaller;">E-Mail Address:</td>
                                <td valign="top"><input style="background-color: $BGCOLOR; color: $FGCOLOR;" size="50" name="mailfrom"></td>
                              </tr>
                              <tr>
                                <td class="feedback" valign="top" style="font-size: smaller;">Subject (<b>*</b>):</td>
                                <td valign="top"><input style="background-color: $BGCOLOR; color: $FGCOLOR;" size="50" name="mailsubject"></td>
                              </tr>
                              <tr>
                                <td class="feedback" valign="top" style="font-size: smaller;">Your Message:</td>
                                <td valign="top"><textarea style="background-color: $BGCOLOR; color: $FGCOLOR;" rows="20" cols="60" name="mailbody"></textarea></td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                                <td><input type="submit" value="Send Message"> <input type="reset" value="Reset values"> </td>
                              </tr>
                            </table>
                          </form>

<p class="feedback" style="font-size: smaller;">
<b>(*)</b> These fields <em>must not</em> be empty! Submissions would be rejected as virus, if these fields remain empty or contain only whitespaces.
</p>

END_OF_TABLE

#######################################################################

use CGI qw/:standard/;
use Fcntl ':flock'; # import LOCK_* constants

sub do_error($)
{
    my $msg = shift;
    print '<center>';
    print "  <img src=\"$PICBROKEN\" alt=\"$PICBROKENALT\">";
    print '</center>';
    print '<h3>An error occured in the feedback script</h3>';
    print '<p>' . $msg . '</p>';
    print $MYFOOTER;
    exit (0);
}

sub do_feedback()
{
    if (param())
    {
	# There are parameters.
	# 1. Fetch them and save them in a file
	# 2. Generate a reply page.
	my $mailfrom = param('mailfrom') || "";
	my $mailsubject = param('mailsubject') || "";
	my $mailbody = param('mailbody') || "";
	my $now = gmtime(time());
	my $remotehost = remote_host();

	if (! check_for_viruses($mailfrom, $mailsubject, $mailbody)) {
	  # Not a virus, save everything and confirm
	  open FEEDBACKFILE, ">> $MYFILENAME" or do_error("Can't open feedback file!");

	  flock (FEEDBACKFILE, LOCK_EX);
	  seek (FEEDBACKFILE, 0, 2);

	  print FEEDBACKFILE "Remote  : ", $remotehost, "\n";
	  print FEEDBACKFILE "From    : ", substr($mailfrom, 0, 68), "\n";
	  print FEEDBACKFILE "Date    : ", $now, "\n";
	  print FEEDBACKFILE "Subject : ", substr($mailsubject, 0, 130), "\n";
	  print FEEDBACKFILE "\n";
	  print FEEDBACKFILE $mailbody, "\n\f\n";

	  flock (FEEDBACKFILE, LOCK_UN);

	  close (FEEDBACKFILE) or do_error("Can't close feedback file!");
       
	  print '<center>';
	  print "  <img src=\"$PICAFTER\" alt=\"$PICAFTERALT\">";
	  print '</center>';

	  print '<h3>Thank you!</h3>';
	  print '<div class="feedback" style="text-align: center;">';
	  print '<p>Thank you for your comments.</p>';
	  print '<p>If you submitted a valid E-Mail address,<br>';
	  print 'we will get back to you ASAP.</p>';
	  print '<p style="font-size: smaller;"><em>-- Cordula\'s Web feedback program.</em></p>';
	  print "<p class=\"wikinote\" style=\"color: #FFFF00;\"><b>Very important!</b> We can't reply, if the address you've submitted is not a <b>valid</b> e-mail address! If you didn't get a reply within a week or two, the reason could be that the address you've submitted is incorrect, contains a typo or is otherwise unreachable. If this happens to you, please resubmit again and make sure you double-check your e-mail address. If you can quote the gist of the message you've submitted, you don't need to repeat it entirely (it's already recorded). Just make sure we get your correct e-mail address, so we can reply. Thank you.</p>";
	  print '</div>';
      } else {
	  # Blaster virus etc..., save only date and hostname.
	  open FEEDBACKFILE, ">> $MYFILENAME" or do_error("Can't open feedback file!");

	  flock (FEEDBACKFILE, LOCK_EX);
	  seek (FEEDBACKFILE, 0, 2);

	  print FEEDBACKFILE "VIRUS. $now $remotehost\n";
	  #print FEEDBACKFILE "Remote  : ", $remotehost, "\n";
	  #print FEEDBACKFILE "Date    : ", $now, "\n";
	  #print FEEDBACKFILE "Subject : ", "VIRUS", "\n";
	  #print FEEDBACKFILE "\f\n";

	  flock (FEEDBACKFILE, LOCK_UN);

	  close (FEEDBACKFILE) or do_error("Can't close feedback file!");
       
	  print '<center>';
	  print "  <img src=\"$PICAFTER\" alt=\"$PICAFTERALT\">";
	  print '</center>';

	  print '<h3>Thank you!</h3>';
	  print '<div class="feedback" style="text-align: center;">';
	  print '<p>Thank you for your comments.</p>';
	  print '<p><b>Unfortunately, your message looked like a virus or worm,<br>';
	  print 'and has not been saved.</b></p>';
	  print '<p>Please resend with a different wording,<br>';
	  print 'OR send an an email to feedback (at) cordula (dot) ws</tt>.</p>';
	  print '<p>We apologize for the inconvenience.</p>';
	  print '<p style="font-size: smaller;"><em>-- Cordula\'s Web feedback program.</em></p>';
	  print '</div>';
      }
    }
    else
    {
	# There are not parameters: generate an HTML form
	print $MYTABLE;
    }
}

sub check_for_viruses {
    my $mailfrom = shift;
    my $mailsubject = shift;
    my $mailbody = shift;

    # Blaster worm
    return 1 if ($mailfrom    =~ /\@www\.cordula\.ws/);
    return 1 if ($mailfrom    =~ /\@cordula\.ws/);

    return 1 if ($mailsubject =~ /\@www\.cordula\.ws/);
    return 1 if ($mailsubject =~ /\@cordula\.ws/);

    return 1 if ($mailsubject =~ /Subject:\s(.*?)\((.*?),mailsubject\)/);

    # Empty subject is not allowed
    return 1 if ($mailsubject =~ /^ *$/);

    # Worm spamming with poker and casino stuff
    return 1 if ($mailbody =~ /poker|casino/);

    return 0;
}

######################################################################

#print "Content-type: text/html\n\n";
#print $MYHEADER;
#do_feedback();
#print $MYFOOTER;
#
#exit (0);

# print redirect(-uri => 'http://wiki.cordula.ws/', -status => 302);

# print "HTTP/1.1 302 Moved Temporarily\r\n";
# print "Location: http://wiki.cordula.ws/\r\n\r\n";

print "Content-type: text/plain\n\n";
print <<EOMMM;
                Cordula's Web Feedback Program.

We're sorry, but our feedback program is closed for maintenance. 
In the mean time, please send your feedback and submissions
to maintenance4712\@cordula.ws

We apologize for the inconvenience.

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

Es tut uns leid, aber unser Feedback-Programm ist wegen
Wartungsarbeiten z.Zt. ausser Betrieb. In der Zwischenzeit,
sendet doch bitte Eure Vorschlaege und Feedback an die Adresse
maintenance4712\@cordula.ws

Vielen Dank.

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

Cordula's Web. http://www.cordula.ws/
EOMMM
