#! /usr/local/bin/perl -w

use strict;
use CGI ();
use Mail::Internet ();

# avoid mailx etc.
$ENV{'PERL_MAILERS'} = "mail:/donotuse:sendmail:/usr/sbin/sendmail";
$ENV{'MAILADDRESS'} = 'webmaster@mail.lns.cornell.edu';

my $to = "service\@lns.cornell.edu";

my $query = new CGI;

my @fields = (
	      'page', 'Who', 'Inst', 'Email', 'Phone', 'PhoneBldg', 'PhoneLNS',
	      'Visitor', 'Accnt', 'Auspices', 'HowLong', 'When', 'Bldg',
	      'Room', 'What', 'WhatOther', 'OS', 'Distr', 'OtherOS',
	      'Connection1', 'MACaddr1', 'Conn1Replace', 'Connection2', 'MACaddr2', 
              'Conn2Replace', 'Clark'
	     );

print $query->header();

print <<"header";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">        <meta http-equiv="Content-Language" content="en-us">
        <link rel="shortcut icon" href="https://wiki.lepp.cornell.edu/published/favicon.ico" type="image/x-icon">
        <link rel="stylesheet" type="text/css" href="/rsrc/WWW/FreeSkinStart/main.css" media="all">

<title>LEPP - Resources</title>
 </head><body>
<div id="cu-identity">
        <div id="cu-logo">
                <a href="http://www.cornell.edu/"><img src="/rsrc/WWW/FreeSkinBanner/cu_logo_small.gif" alt="Cornell University" width="166" height="45" border="0" /></a>
        </div>
        <div id="cu-search">
      <a href="http://www.cornell.edu/search/">Search Cornell</a>
        </div>
</div>
<div id="banner">
<div id="banner-content">
<a href="http://www.lepp.cornell.edu/Research/AP/SRF/"><img src="/rsrc/WWW/FreeSkinBanner/tesla_cavity_sm.jpg" alt="tesla_cavity_sm.jpg" width='70' height='70' /></a>
<a href="http://www.lepp.cornell.edu/public/CMS/"><img src="/rsrc/WWW/FreeSkinBanner/cms-yoke-rings.gif" alt="cms-yoke-rings.gif" width='70' height='70' /></a>
<a href="http://www.lepp.cornell.edu/Research/EPP/CLEO/"><img src="/rsrc/WWW/FreeSkinBanner/event_small.gif" alt="event_small.gif" width='70' height='70' /></a><a href="http://www.lepp.cornell.edu/Research/AP/CESR/"><img src="/rsrc/WWW/FreeSkinBanner/sep_small.gif" alt="sep_small.gif" width='70' height='70' /></a>
<a href="http://www.lepp.cornell.edu" class="twikiLink"><img class="logo" src="/rsrc/WWW/FreeSkinBanner/LEPP_non-logo1.gif" alt="LEPP" width="289" height="60" /></a>
</div>
</div>
<div id="main-nav">
<a class="menu" href="/">Home</a>
<a class="menu" href="/Research/">Research</a>
<a class="menu" href="/Education/">Education</a>
<a class="selectedmenu" href="/Resources/">Resources</a>
<div id="lepp-search">
<form action="http://web.search.cornell.edu/search" method="GET" name="gs">
<input type="text" name="q" value="" size="20" maxlength="256"id="search-form-query" /><input type="submit" name="btnG" value="Search LEPP" id="search-form-submit" />
<input type="hidden" name="output" value="xml_no_dtd" />
<input type="hidden" name="sort" value="date:D:L:d1" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="hidden" name="client" value="default_frontend" />
<input type="hidden" name="oe" value="UTF-8" />
<input type="hidden" name="site" value="default_collection" />
<input type="hidden" name="proxystylesheet" value="default_frontend" />
<input type="hidden" name="sitesearch" value="lepp.cornell.edu" id="search-filters1" />
</form>
</div>
</div>
<div id="section-navigation">
<a class="primary" href="/Resources/LeppDocs.html">Documents</a>
<a class="primary" href="/Resources/ComputingAtLEPP.html">Computing</a>
<a class="primary" href="http://www.lepp.cornell.edu/perl/scoreboard">CESR Scoreboard</a>
<a class="primary" href="http://www.lns.cornell.edu/~draft/">Design &amp; Publication Services</a>
<p />
<hr />
<p />
<h4><a name="Outside_Links"></a> Outside Links </h4> <ul>
<li> <a href="http://arxiv.org/"" target="_top">ArXiv</a>
</li> <li> <a href="http://www.slac.stanford.edu/spires/" target="_top">SLAC Spires</a>
</li> <li> <a href="http://publish.aps.org/" target="_top">Physical Review</a>
</li> <li> <a href="http://accelconf.web.cern.ch/accelconf/" target="_top">Joint Accelerator Conferences</a>
</li> <li> <a href="http://pdg.lbl.gov/" target="_top">Particle Data Group</a>
</li> <li> <a href="http://interactions.org" target="_top">Interactions.org</a>
</li></ul>
</div>
<div id="main">
<div id="content">
header

if (!$query->param('Email')) {
    print "<h1>Missing email address</h1>\nYou must supply an email address\n";
    print qq(Return to the previous page to resume filling in the form\n);
} elsif ($query->param('When') =~ /asap/i) {
    print qq(<h1>Invalid Date</h1>\nPlease provide a date--ASAP is not
	     sufficient for our scheduling purposes\n);
    print qq(Return to the previous page to resume filling in the form\n);
} else {
    my @body;

    for my $field (@fields) {
	push @body, sprintf("%-10s %s\n", $field, $query->param($field))
	    if $query->param($field);
    }

    push @body, sprintf("\nsubmitted from: %s (%s)\n", 
			$ENV{'REMOTE_ADDR'},
			$ENV{'REMOTE_HOST'} || "no reverse DNS"
		       );

    
    my $msg = Mail::Internet->new(Body => \@body);
    my $head = $msg->head;

    $head->replace('Subject', $query->param('Subject'));
    $head->replace('From', $query->param('Email'));
    $head->replace('To', $to);

    if ($msg->smtpsend(To => $to)) {
	# remove the remote host info
	pop @body;

	print qq(
		 <p>Your DHCP request has been sent to the LNS computer group
		 with this information:</p>
		 <pre>);

	print @body;
	print "</pre>\n";
    } else {
	print qq(<h1>Script Error</h1>
		 <p>Please send mail to
		 <a href="mailto:service\@lns.cornell.edu">
		 service\@mail.lns.cornell.edu</a></p>);
    }

    # Send confirmation email
    if($query->param('Clark')){
    	my @body2;

    	for my $field (@fields) {
	    push @body2, sprintf("%-10s %s\n", $field, $query->param($field))
	    	if $query->param($field);
    	}

	push @body2, sprintf("\nsubmitted from: %s (%s)\n", 
			$ENV{'REMOTE_ADDR'},
			$ENV{'REMOTE_HOST'} || "no reverse DNS"
		       );
	
	my $msg2 = Mail::Internet->new(Body => \@body2);	
	my $head2 = $msg2->head;	
        $head2->replace('Subject', $query->param('Subject'));
        $head2->replace('From', $query->param('Email'));
        $head2->replace('To', $query->param('Email'));	

	if ($msg2->smtpsend(To => $to)) {}
    }

}

print <<"trailer";
</div>
</div>
</body>
</html>
trailer