reduce cols in log stages section
[buildfarm-server.git] / cgi-bin / register.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7
8 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp);
9
10 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
11 #require "BuildFarmWeb.pl";
12
13 my $dsn="dbi:Pg:dbname=$dbname";
14 $dsn .= ";host=$dbhost" if $dbhost;
15 $dsn .= ";port=$dbport" if $dbport;
16
17 my $header = <<EOS;
18 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
19         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
20 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
21 <head>
22         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
23         <title>PostgreSQL BuildFarm Application</title>
24         <link rel="icon" type="image/png" href="/elephant-icon.png" />
25         <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
26         <style type="text/css"><!--
27         li#register a { color:rgb(17,45,137); background: url(/inc/b/r.png) no-repeat 100% -20px; } 
28         li#register { background: url(/inc/b/l.png) no-repeat 0% -20px; }
29         --></style>
30 </head>
31 <body class="application">
32 <div id="wrapper">
33 <div id="banner">
34 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
35 <div id="nav">
36 <ul>
37     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
38     <li id="status"><a href="/cgi-bin/show_status.pl" title="Current results">Status</a></li>
39     <li id="members"><a href="/cgi-bin/show_members.pl" title="Platforms tested">Members</a></li>
40     <li id="register"><a href="/register.html" title="Join PostgreSQL BuildFarm">Register</a></li>
41     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
42     <li id="postgresql.org"><a href="http://www.postgresql.org">PostgreSQL.org</a></li>
43 </ul>
44 </div><!-- nav -->
45 </div><!-- banner -->
46 <div id="main">
47 EOS
48
49 my $footer = <<EOS;
50 </div><!-- main -->
51 <hr />
52 <p style="text-align: center;">
53 Hosting for the PostgreSQL Buildfarm is generously 
54 provided by: 
55 <a href="http://www.commandprompt.com">CommandPrompt, 
56 The PostgreSQL Company</a>
57 </p>
58 </div><!-- wrapper -->
59 </body>
60 </html>
61 EOS
62
63 my $query = new CGI;
64
65 my $params = $query->Vars;
66
67 my ($os, $osv, $comp, $compv, $arch, $email, $owner) = @{$params}{
68         qw(os osv comp compv arch email owner)};
69
70 unless ($os && $osv && $comp && $compv && $arch && $email && $owner)
71 {
72         print "Content-Type: text/html\n\n",
73         $header,
74         "<p>You need to complete all the form items. <a href=\"/register.html\">Please try again.</a></p>\n",
75         $footer;
76         exit;
77 }
78
79 # some idiot has a script that tries to talk to me
80 # this should catch and dispose of him
81 if (grep {/rgergerger|\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/} $os,$osv,$comp,$compv,$arch,$email,$owner)
82 {
83     print 
84         "Status: 403 Forbidden - go away idiot\n",
85         "Content-Type: text/plain\n\n";
86     exit;    
87 }
88
89 # count transitions to and from upper case
90 my $trans = 1;
91 my $counttrans = 0;
92 foreach (split "" ,"$os$osv$comp$compv$arch$owner")
93 {
94         if (/[A-Z]/)
95         {
96                 next if $trans;
97                 $trans = 1;
98                 $counttrans++;
99         }
100         else
101         {
102                 next unless $trans;
103                 $trans = 0;
104                 $counttrans++;
105         }
106 }
107
108 # reject junk with too many transitions into/outof upper case
109 if ($counttrans > 20)
110 {
111     print 
112         "Status: 403 Forbidden - go away idiot\n",
113         "Content-Type: text/plain\n\n";
114     exit;   
115 }
116
117
118
119 my $secret = "";
120 my $dummyname=""; # we'll select an animal name when we approve it.
121 foreach (1..8)
122 {
123         # 8 random chars is enough for the dummy name
124         $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
125         $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
126 }
127 foreach (9..32)
128 {
129         $secret .= substr("0123456789abcdef",int(rand(16)),1);
130 }
131
132 my $db = DBI->connect($dsn,$dbuser,$dbpass);
133
134 my $statement = <<EOS;
135
136   insert into buildsystems 
137     (name, secret, operating_system, os_version, compiler, compiler_version,
138      architecture, status, sys_owner, owner_email)
139   values(?,?,?,?,?,?,?,'pending',?,?)
140
141 EOS
142 ;
143
144 my $sth=$db->prepare($statement);
145 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
146                           $arch,$owner,$email);
147 my $err=$db->errstr;
148 print "Content-type: text/html\n\n";
149 print $header
150     , "<h1>PostgreSQL BuildFarm Application received</h1>\n"
151     , "<p>Thank you. You should hear from us shortly.</p>"
152     , $footer;
153
154
155 $sth->finish;
156 $db->disconnect;
157
158
159 use Mail::Send;
160
161 my $msg = new Mail::Send;
162
163 my $me = `id -un`;
164
165 my $host = `hostname`;
166
167 $msg->set('From',"PG Build Farm <$me\@$host>");
168
169 $msg->to(@$notifyapp);
170 $msg->subject('New Buildfarm Application');
171 my $fh = $msg->open;
172 print $fh "\n\nName: $dummyname\n",
173     "OS: $os: $osv\n",
174     "Arch: $arch\n",
175     "Comp: $comp: $compv\n",
176     "Owner: $owner <$email>\n";
177 $fh->close;
178
179
180
181
182
183