3
# LSB Test Execution Framework
4
# Module for Integration with Certification System (cert_integration.pl)
6
# Copyright (C) 2007-2009 The Linux Foundation. All rights reserved.
8
# This program has been developed by ISP RAS for LF.
9
# The ptyshell tool is originally written by Jiri Dluhos <jdluhos@suse.cz>
10
# Copyright (C) 2005-2007 SuSE Linux Products GmbH
12
# This program is free software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# version 2 as published by the Free Software Foundation.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
32
my $boundary = '432432548930278320';
34
my $client_name = 'DTK Manager';
36
my %subst; # compiled patternes
40
return unless defined $text;
42
$text =~ s/([^A-Za-z0-9\-_.!~*\'()])/sprintf("%%%02X", $1)/ge;
48
my ($file_location, $filename, $field_name, $save_as) = @_;
50
my $content_type = 'application/octet-stream';
52
unless (open FILE, $file_location.$filename) {
53
print "Can't open ".$file_location.$filename."\n";
61
$body_text .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$save_as\"\r\n";
62
$body_text .= "Content-Type: $content_type\r\n";
63
#$body_text .= "Content-Transfer-Encoding: binary\r\n";
68
while ( read (FILE, $content_part, 1024*1024) ) {
69
$body_text .= $content_part;
74
$body_text .= "--$boundary";
81
my ($name, $value) = @_;
87
$body_text .= "Content-Disposition: form-data; name=\"$name\"\r\n";
89
$body_text .= "$value\r\n";
90
$body_text .= "--$boundary";
97
my ($filename, $directory, $save_as, $_POST) = @_;
102
$body_text .= "--$boundary";
104
$body_text .= multipart_file($directory, $filename, 'attachment', $save_as);
105
$body_text .= multipart_text('submit', 'Hidden');
106
foreach my $key ( keys %$_POST ) {
107
next if $key =~ /^secure_key/;
108
next if $key eq "filename";
109
next if $key eq "directory";
110
next if $key eq "save_as";
111
next if $key eq "pc_id";
112
next if $key eq "back_url";
113
next if $key eq "back_host";
114
$body_text .= multipart_text( $key, $_POST->{$key});
118
$body_text .= "--\r\n";
125
print "HTTP/1.0 200 OK" . CRLF;
126
print "Content-type: text/html" . CRLF . CRLF;
128
print_header("Test Results", "results");
130
if ( !exists($_POST{'filename'} )
131
|| !exists($_POST{'directory'})
132
|| !exists($_POST{'secure_key_name'})
133
|| !exists($_POST{'secure_key_val'})
135
print "Not enough parameters";
140
my $filename = $_POST{'filename'};
141
my $directory = $_POST{'directory'};
143
my $save_as = $filename;
144
if ( exists($_POST{'save_as'}) ) {
145
$save_as = $_POST{'save_as'};
149
my $cert_url = $cert_sys_base.'upload.php?inadvance';
150
$cert_url .= '&pcid='.$_POST{'pc_id'} if exists $_POST{'pc_id'};
153
$cert_url = $_POST{'back_url'} if exists $_POST{'back_url'};
155
$cert_sys_host = $_POST{'back_host'} if exists $_POST{'back_host'};
158
my $body_text = &multipart_body( $filename, $directory, $save_as, \%_POST );
160
my $content_length = length($body_text);
164
$_POST{'secure_key_name'} => $_POST{'secure_key_val'},
165
'integration' => $client_name,
167
my @cookie_pairs = ();
168
foreach my $key ( keys %cookies ) {
169
my $cookie_pair = $key.'='.uri_escape($cookies{$key});
170
push @cookie_pairs, $cookie_pair;
172
my $cookie_line = join('; ', @cookie_pairs);
175
my $host = $cert_sys_host;
177
my $pagename = $cert_url;
178
my $header_content_type = "multipart/form-data";
182
$header .= "POST $pagename HTTP/1.1" . CRLF;
183
$header .= "Host: $host" . CRLF;
184
$header .= "Content-Type: $header_content_type; boundary=$boundary" . CRLF;
185
$header .= "Content-Length: $content_length" . CRLF;
186
$header .= "Cookie: $cookie_line" . CRLF if ( $cookie_line );
187
$header .= "Connection: Close" . CRLF;
190
#print "<pre>$header</pre>";
193
my $message = $header.$body_text;
196
socket ( SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') );
198
my $iaddr = inet_aton($host);
199
my $paddr = sockaddr_in($port, $iaddr);
201
my $result = connect(SOCK, $paddr);
205
print '<p style="color:red">Error: Failed to connect to the Certification System'
206
.' at '.$cert_sys_host.':80.</p>';
210
<h1>Uploading test results</h1>
211
<p style="color:green;font-weight:bold">
212
Please, wait while uploading the data to the Certification System...
216
<span id="timer" style="font-family: monospace; color: blue;">00:00</span>
219
<table><tr><td><div style="width: 300px; height: 12px; border: 1px solid #004000;">
220
<img src="images/progress.png" alt="progress: 0/0"
221
width="0" height="12" id="progress_bar" style="display: none;" />
224
<span id="progress_text" style="padding-left:30pt"></span>
228
<p><span id="msg"><br/></span></p>
230
<script language="javascript" type="text/javascript">
232
var elapsed_time = 0;
234
function update_timer() {
235
if ( !timer ) return;
237
var elem = document.getElementById("timer");
239
var m = Math.floor(elapsed_time / 60);
240
var s = elapsed_time - m * 60;
242
tmp += (m < 10) ? "0" + m : m;
244
tmp += (s < 10) ? "0" + s : s;
245
elem.innerHTML = tmp;
246
timer = setTimeout("update_timer()", 1000);
250
function set_progress(done, total) {
251
var elem = document.getElementById("progress_bar");
253
elem.style.display = ((done == 0) ? 'none' : '');
256
elem.alt = "progress: " + done + "/" + total;
257
elem.width = Math.round(done * 300 / total);
259
var etxt = document.getElementById("progress_text");
263
etxt.innerHTML = "Uploaded: " + Math.floor(done/1024) + " of " + Math.floor(total/1024) +" Kbytes.";
267
function stopTimer() {
272
timer = setTimeout("update_timer()", 1000);
276
print_footer(1); # do not finish with </body></html> now!
281
select STDOUT; $| = 1;
283
# connected, let's post the data
285
my $total_bytes = length($message);
287
my $chunk_size = 1024*50;
290
$message =~ //; # reset search iterator
291
for ( my $sent_bytes = 0; $sent_bytes < $total_bytes; ) {
292
# reading chunks of $chunk_size bytes
293
my $chunk = substr($message, $sent_bytes, $chunk_size);
297
$sent_bytes += (length($chunk) or last);
299
# Progress bar increase
300
print_javascript_progress ( $sent_bytes, $total_bytes );
303
#select(undef, undef, undef, 0.2);
306
##### Data has been sent. Read the response. #####
310
# TODO: F: Check the response code
312
# Reading the response: looking for the "Location:" header field
313
my $resp_header = ''; # For debugging
317
$resp_header .= $_ if $mode==0;
318
$output .= $_ if $mode==1;
320
# TODO: /^HTTP1.\d\s+(\d+)/ - code should be 302
322
if ( /^Location:\s+(.*)$/ && $mode==0 ) {
324
$back_url =~ s/\s+$//; # Trim trailing \r\n; 'chomp' doesn't work here!
327
if ( /^\s*$/ && $mode==0 ) {
328
# End of header is marked by empty line.
329
#last; # Do not read the rest of the response.
333
# close the connection
336
if ( $output && $output !~ /^\s*0\s*$/ ) { print $output; }
338
if ( $back_url =~ m!^https?://! ) {
341
elsif ( $back_url =~ m!^/! ) {
342
$back_url = 'http://'.$cert_sys_host.$back_url;
344
elsif ( $back_url =~ /^\w/ ) {
345
$cert_url =~ s{/[^/]+$}{/$back_url};
346
$back_url = 'http://'.$cert_sys_host.$cert_url;
348
elsif ( $back_url =~ /^\?/ ) {
349
$cert_url =~ s{\?.+$}{$back_url};
350
$back_url = 'http://'.$cert_sys_host.$cert_url;
352
elsif ( exists($_POST{'back_url_error'}) ) {
353
$back_url = 'http://'.$cert_sys_host.$_POST{'back_url_error'};
359
# Stop the timer on the page, print message.
362
<script language="javascript" type="text/javascript">
365
var elem = document.getElementById("msg");
367
elem.innerHTML = "<span style='color:green;font-weight:bold'>... done!</span>";
368
elem.innerHTML += " ";
370
if ( $back_url ne '' ) {
372
elem.innerHTML += "Press [<a href='$back_url'>Continue</a>]";
381
# Footer has already been printed, but without "</body></html>".
382
print "</body>\n</html>\n";
386
sub print_javascript_redirect
388
my $back_url = shift;
392
<script language="javascript" type="text/javascript">
395
location.replace("$back_url");
401
sub print_javascript_progress
403
my $sent_bytes = shift;
404
my $total_bytes = shift;
407
<script language="javascript" type="text/javascript">
409
set_progress($sent_bytes, $total_bytes);
419
my $dir = $CONFIG{"RESULTS_DIR"}.'/'.$subdir;
423
if ( open(FILE, $dir."/host_info/host_platform")) {
424
$result->{'prod_arch'} = <FILE>;
425
chomp $result->{'prod_arch'};
426
$result->{'prod_arch'} =~ s/amd64/x86_64/;
429
if ( open(FILE, $dir."/host_info/host_os")) {
433
if ( $distr =~ s/\(([^\)]+)\)// ) {
434
if ( $1 ne $result->{'prod_arch'} ) {
435
$result->{'prod_comment'} = $1;
439
if ( $distr =~ s/\b(release)? *([0-9][0-9\.\-\w]*)\b// ) {
440
$result->{'prod_version'} = $2;
443
$distr =~ s/\s+$//; # Trim
444
$distr =~ s/^\s+//; # Trim
446
$result->{'prod_name'} = $distr;
449
if ( open(FILE, $dir."/host_info/lsb_release_all")) {
452
if ( /^Release:\s+(.*)$/ ) {
453
$result->{'prod_version'} = $1;
455
if ( /^Codename:\s+(.*)$/ ) {
456
next if ($1 eq 'n/a');
457
$result->{'prod_comment'} = $1;
462
if ( open(FILE, $dir."/host_info/lsb_version")) {
463
$result->{'lsb_version'} = <FILE>;
464
chomp $result->{'lsb_version'};
472
print "HTTP/1.0 200 OK" . CRLF;
473
print "Content-type: text/html" . CRLF . CRLF;
475
print_header("Test Results", "results");
477
my $file = $_GET{'file'};
478
$file = $_POST{'file'} if (!$file);
480
my $cert = $_GET{'cert'}; # Is this a good certification test result.
481
$cert = $_POST{'cert'} if (!$cert);
483
if ( index($file, $CONFIG{"RESULTS_DIR"}) != 0 ) {
484
print "Wrong parameter: file (access forbidden)";
489
print "Wrong parameter: file (access denied)";
494
my $get_credentials_page = "status.php";
495
my $action_url = 'http://'.$cert_sys_host.$cert_sys_base.$get_credentials_page;
497
my $base_url = 'http://'.$SERVER_PARAM{"HOST"};
498
my $this_url = $base_url.'/cert_integration.pl';
499
my $back_url = $this_url.'?upload'; # Callback for file uploading
500
my $client_url = $base_url.'/tests_results.pl'; # Return to it on success
503
my $file_location = '';
505
if ( $file =~ m/^(.*\/)([^\/]*)$/ ) {
507
$file_location = $1; # with trailing slash.
510
print "Wrong parameter: file (can't split)";
515
my $filesize = -s $file_location.$filename;
516
my $filelink = $base_url.'/get.pl'.$file_location.$filename;
519
if ( $file_location =~ m/\/([^\/]+)\/+$/ ) {
520
$result = get_test_info($1);
523
my $prod_kind = "distr";
525
my $prod_name = ($result->{'prod_name'} or '');
526
my $prod_version = ($result->{'prod_version'} or '');
527
my $prod_arch = ($result->{'prod_arch'} or '');
528
my $prod_comment = ($result->{'prod_comment'} or '');
529
my $prod_url = ($result->{'prod_url'} or '');
530
my $lsb_version = ($result->{'lsb_version'} or '');
533
<h1>Working with the Certification System</h1>
534
<p>To apply for certification you should pass the following steps
535
in the Certification System.
538
<li>If you are not logged in you will be suggested
539
to log in or create an account.</li>
540
<li>If you are not a company member you will be suggested to register
541
your company or join an existing one.</li>
542
<li>Then you should register the product or chose a registered one.</li>
543
<li>And after all you should start certification of the product
544
by signing the Trademark License Agreement.</li>
547
<p>All these steps are required to apply for certification.
548
Once you click on the 'continue' link the Certification System page
549
will be opened. Then follow the instructions.
551
<form method="post" name="dataform" action="$action_url">
553
<input type="hidden" name="prod_kind" value="$prod_kind" />
554
<input type="hidden" name="prod_name" value="$prod_name" />
555
<input type="hidden" name="prod_version" value="$prod_version" />
556
<input type="hidden" name="prod_comment" value="$prod_comment" />
557
<input type="hidden" name="prod_arch" value="$prod_arch" />
558
<input type="hidden" name="prod_url" value="$prod_url" />
559
<input type="hidden" name="lsb_version" value="$lsb_version" />
561
<input type="hidden" name="client" value="$client_name" />
562
<input type="hidden" name="client_url" value="$client_url" />
563
<input type="hidden" name="back_url" value="$back_url" />
565
<input type="hidden" name="filename" value="$filename" />
566
<input type="hidden" name="directory" value="$file_location" />
567
<input type="hidden" name="filesize" value="$filesize" />
568
<input type="hidden" name="filelink" value="$filelink" />
569
<input type="hidden" name="cert" value="$cert" />
571
<input type="hidden" name="integration" value="submit" />
573
<p>[<span class="active" onclick="document.dataform.submit();"
574
>Continue</span>]</p>
581
if ( exists($_GET{'start'}) && $_GET{'start'} ) {
586
if ( exists($_POST{'upload'}) && $_POST{'upload'} ) {
590
print "HTTP/1.0 200 OK" . CRLF;
591
print "Content-type: text/html" . CRLF . CRLF;
593
print_header("Test Results", "results");
596
<p>This address is used by the <a href="http://$cert_sys_host$cert_sys_base">Certification System</a> to interact with the DTK Manager.</p>