[LOSTWAGES] service.cgi update
Brian Vincent
vinn at theshell.com
Wed Mar 17 23:37:25 CST 2004
More or less a rewrite of service.cgi to incorporate some new ideas.
Changelog:
- redo publishing, download cookie from publisher
- new winrash command set
- ability to download multiple tests
Index: service.cgi
===================================================================
RCS file: /home/wine/tools/winetest/service.cgi,v
retrieving revision 1.1
diff -u -r1.1 service.cgi
--- service.cgi 9 Mar 2004 19:17:13 -0000 1.1
+++ service.cgi 18 Mar 2004 05:17:02 -0000
@@ -1,141 +1,227 @@
#!/usr/bin/perl
+#
+# This script acts as the middle man between people who build
+# tests to be distributed to Windows clients and the actual
+# Windows clients
+#
+# Copyright (C) 2004 Brian Vincent
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# We expect our input to be one of two things:
+# - publish a new file for clients to download
+# ?publish=winetest&url=http://myserver.com/path/to/current-winetest.exe
+# - a request to download that looks like:
+# ?winrash=1&cookie_name1=cookie_value1&cookie_name2=cookie_value2...
+#
+# We rely on the server to have directories available for every
+# program that can be published. For example, we need a winetest directory:
+# winetest/
+# url contains url to find latest winetests at, must be
+# writable
+# url.mask contains a reg ex to match against, only needs to
+# be read-only, in the above example it might be
+# something like: http://myserver/com/path/to
+# cookie contains a unique identifier of a program that winrash
+# clients can download, must be writable
use Date::Calc qw(Delta_DHMS);
-$hour_we_do_build = "2"; # hour, such as 2 or 17, in localtime
-$path_buildurl="./build.url";
-$path_winetestkey="./winetest.key";
-$path_servicekey="./service.key";
-
-%data_received = &User_Data();
-&read_keys();
-
-if ($data_received{"publish"} eq "winetest") {
- &save_new_key;
- exit;
-}
-
-if ($data_received{"servicekey"} ne $newservicekey) {
- &send_service_upgrade;
- exit;
-}
-
-if ($data_received{"winetestkey"} eq $newwinetestkey) {
- &send_wait;
- exit;
-}
-else {
- &send_winetest_upgrade;
- exit;
-}
-
-# We should never execute this.. but if some parameter was wrong it would
-# happen. This way we return some useful info for debugging.. assuming
-# there's a way to catch it.
+$hour_we_do_build = "2"; # hour, such as 2 or 17, in localtime, rounded up
+$path_to_test_directories="/point/me/somewhere/";
+$path_to_lynx="/usr/bin/lynx";
+&main;
+
+sub main {
+ %data_received = &User_Data;
+ &get_all_cookies;
+
+ if ($data_received{"publish"}) {
+ $cookie_current = read_cookie($data_received{"publish"});
+ $cookie_to_save = &get_new_cookie;
+
+ # Cookies should never be the same. Some day we could return an error
+ if ($cookie_to_save eq $cookie_current) {
+ print "Content-type: text/plain\n\n";
+ print "OK\n";
+ }
+ else {
+ save_new_cookie($cookie_to_save);
+ &save_new_url;
+ }
+ exit;
+ }
-print "Content-type: text/html\n\n";
-print "<h3>Fell through to here. That shouldn't have happened.. </h3>\n";
-print "<h3>So let's examine the keys:</h3>\n";
+ print "Content-type: text/plain\n\n";
+
+ if ($data_received{"winrash"} ne $cookie{"winrash"}) {
+ send_upgrade("winrash",$cookie{"winrash"});
+ exit;
+ }
+
+ # I expect the cookie hash won't have many values, but we could potentially
+ # run a lot of commands if we wanted.
+
+ foreach $key (keys %cookie) {
+ next if ($key eq "winrash");
+ if ($cookie{$key} ne $data_received{$key}) {
+ send_upgrade($key, $cookie{$key});
+ $upgrade_sent = 1;
+ }
+ }
-foreach $command (sort keys(%data_received)) {
- $command_string .= "<p>$command is ";
- foreach (split(" : ", $data_received{$command})) {
- $command_string .= "$_</p>";
+ if (!$upgrade_sent) {
+ &send_wait;
}
}
-print "$command_string\n";
##########################################################################
#
-# When Paul finishes compiling winetests he sends us some info we need
-# to remember. Clients use this info to find out if they have an up
-# to date copy of Wine tests.
+# When we publish, we:
+# 1) Look for <publish key value>/url.mask that had to have been
+# created by a web server admin thus ensuring this program is
+# approved for testing
+# 2) Download the cookie for the program from that web server
+# 3) Save that cookie to <publish key value>/cookie
#
##########################################################################
-sub save_new_key {
+sub get_new_cookie {
- # the md5sum Paul submits should never be the same as what we have
- if ($data_received{"cookie"} eq $newwinetestkey) {
- print "Content-type: text/plain\n\n";
- print "UHOH\n";
- return;
+ my $path_to_mask = $path_to_test_directories . $data_received{"publish"}
+ . "/url.mask";
+ my $cookie_url = $data_received{"url"} . ".cookie";
+ my $url_mask = "";
+ my $this_cookie = "";
+
+ open(URL_MASK_FH, "< $path_to_mask")
+ or die "Can't open $path_to_mask for reading.\n \
+ See comments at top of service.cgi for directory layout. \n";
+ do { $url_mask = <URL_MASK_FH> } until $. == 1;
+ close(URL_MASK_FH);
+
+ chomp $url_mask;
+ if (!($data_received{"url"} =~ $url_mask)) {
+ die "URL mask unmatched, dying.\n";
+ }
+
+ open(LYNX_OUTPUT, "$path_to_lynx -source $cookie_url |")
+ or die "Unable to run lynx to find cookie at $cookie_url.\n";
+ do { $this_cookie = <LYNX_OUTPUT> } until $. == 1;
+ close(LYNX_OUTPUT);
+
+ chomp $this_cookie;
+ return $this_cookie;
+}
+
+sub save_new_cookie {
+
+ my $cookie = $_[0];
+ my $path_to_cookie = $path_to_test_directories . $data_received{"publish"}
+ . "/cookie";
+
+ if(length($cookie) != 32) {
+ die "MD5sum is " . length($cookie) . ", not 32 characters long? \n";
}
- if(length($data_received{"cookie"}) != 32) {
- die "Why isn't our MD5sum 32 characters long?\n";
- }
-
- if($data_received{"cookie"} =~ /[^0-9^A-Z^a-z]/) {
+ if($cookie =~ /[^0-9^A-Z^a-z]/) {
die "Why do we have non-alpha characters in the MD5sum?\n";
}
- open(WINETESTKEY_FH, "> $path_winetestkey")
- or die "Can't open $path_winetestkey for writing.\n";
- print WINETESTKEY_FH "$data_received{\"cookie\"}";
- close(WINETESTKEY_FH);
-
- # do some kind of test here so we know it's Paul, for now
- # just comment out this part
-
- # open(BUILDURL_FH, "> $path_buildurl")
- # or die "Can't open $path_buildurl for writing.\n";
- # print BUILDURL_FH "$data_received{\"url\"}";
- # close(BUILDURL_FH);
+ open(COOKIE_FH, "> $path_to_cookie")
+ or die "Can't open $path_to_cookie for writing.\n";
+ print COOKIE_FH "$cookie";
+ close(COOKIE_FH);
print "Content-type: text/plain\n\n";
print "OK\n";
}
+sub save_new_url {
+
+ $path_to_url = $path_to_test_directories . $data_received{"publish"}
+ . "/url";
+
+ open(URL_FH, "> $path_to_url")
+ or die "Can't open $path_to_url for writing.\n";
+ print URL_FH "$data_received{\"url\"}";
+ close(URL_FH);
+}
##########################################################################
#
-# Process requests from winrash clients. We can do one of 3 things.
-# 1. send_service_upgrade
-# 2. send_wait
-# 3. send_winetest_upgrade
+# Issue commands understood by winrash. Try to be somewhat intelligent
+# in figuring out what needs to be sent.
#
##########################################################################
+sub send_upgrade {
-sub send_service_upgrade {
- print "Content-type: text/plain\n\n";
- print "download winetests20031127.exe http://www.theshell.com/~vinn/winetests20031127.exe";
- print "\n";
- print "fork winetests20031127.exe";
- print "\n";
-
- #unused commands that might apply here: exit and unzip
-}
+ my $path_to_url = $path_to_test_directories . $_[0] . "/url";
+ my $this_url;
+ my $local_filename;
+ my $this_cookie = $_[1];
+ my $sleeptime = &ret_random_wait;
+
+ open(URL_FH, "< $path_to_url")
+ or die "Can't open $path_to_url for reading.\n";
+ do { $this_url = <URL_FH> } until $. == 1;
+ close(URL_FH);
+ chomp $this_url;
-sub send_wait {
-
- $waittime = ret_random_wait();
+ if (substr($this_url, -4, 4) =~ ".zip") {
+ $local_filename = $_[0] . "-". $this_cookie . ".zip";
+ }
+ elsif (substr($this_url, -4, 4) =~ ".exe") {
+ $local_filename = $_[0] . "-". $this_cookie . ".exe";
+ }
+ else {
+ $local_filename = $_[0] . "-". $this_cookie;
+ }
- print "Content-type: text/plain\n\n";
- print "wait $waittime";
-}
+ print "download $local_filename $this_url\n";
-sub send_winetest_upgrade {
+ if ($_[0] eq "winrash") {
+ print "fork $local_filename\n";
+ return;
+ }
- $waittime = ret_random_wait();
+ # Set cookie now in case any commands following bomb.
+ print "cookie $_[0] $this_cookie\n";
- print "Content-type: text/plain\n\n";
- print "download winetest.zip $buildurl";
- print "\n";
- print "unzip winetest.zip";
- print "\n";
- print "run winetest.exe";
- print "\n";
- print "winetestkey $newwinetestkey";
- print "\n";
- print "wait $waittime";
+ if (substr($local_filename, -4, 4) =~ ".zip") {
+ print "unzip $local_filename\n";
+ print "run $_[0].exe\n"; # Just guessing on name?
+ }
+ else {
+ print "run $local_filename\n";
+ }
+
+ print "sleep $sleeptime\n";
+}
+
+sub send_wait {
+ $sleeptime = &ret_random_wait;
+ print "sleep $sleeptime\n";
}
##########################################################################
#
# Here we figure out when the next build will be ready and return a
-# wait time that is slightly randomized.
+# wait time that is slightly randomized. Relies on Date::Calc because
+# finding out the delta is too painful any other way.
#
##########################################################################
@@ -149,29 +235,27 @@
# point today we'll have a build coming up
# otherwise, we know the next build will happen tomorrow = $nowday + i1
if($nowhour < $hour_we_do_build) {
- ($diffdays, $diffhour, $diffmin, $diffsec) =
- Delta_DHMS( $nowyear, $nowmonth, $nowday, $nowhour, $nowmin, $nowsec,
- $nowyear, $nowmonth, $nowday, $hour_we_do_build, "0", "0");
+ ($diffdays, $diffhour, $diffmin, $diffsec) =
+ Delta_DHMS( $nowyear, $nowmonth, $nowday, $nowhour, $nowmin, $nowsec,
+ $nowyear, $nowmonth, $nowday, $hour_we_do_build, "0", "0");
}
else {
($diffdays, $diffhour, $diffmin, $diffsec) =
Delta_DHMS( $nowyear, $nowmonth, $nowday, $nowhour, $nowmin, $nowsec,
- $nowyear, $nowmonth, $nowday+1, $hour_we_do_build, "0", "0");
+ $nowyear, $nowmonth, $nowday+1, $hour_we_do_build,"0","0");
}
my $waittime = ($diffdays * 24 * 60) + ($diffhour * 60) + $diffmin;
my $randwait = int ( rand(60));
-
- return $randwait;
- return $waittime + $randwait;
+ return (($waittime + $randwait) * 60);
}
##########################################################################
#
-# We just split the name/value pairs into a hash here.
-# Works for GET or POST.
+# We just split the name/value pairs into a hash here. Works for GET or POST.
+# Makes testing from commandline easy if you set $QUERY_STRING
#
##########################################################################
@@ -207,27 +291,28 @@
##########################################################################
#
-# Read the key files to determine the versions of service and tests.
+# Read the cookie files to determine the versions of winrash and tests.
#
##########################################################################
-sub read_keys {
- open(SERVICEKEY_FH, "< $path_servicekey")
- or die "Can't open service key.\n";
- do { $newservicekey = <SERVICEKEY_FH> } until $. == 1;
- close(SERVICEKEY_FH);
- chomp $newservicekey;
-
- open(WINETESTKEY_FH, "< $path_winetestkey")
- or die "Can't open winetest key.\n";
- do { $newwinetestkey = <WINETESTKEY_FH> } until $. == 1;
- close(WINETESTKEY_FH);
- chomp $newwinetestkey;
-
- open(BUILDURL_FH, "< $path_buildurl")
- or die "Can't open file containing URL of build: $path_buildurl.\n";
- do { $buildurl = <BUILDURL_FH> } until $. == 1;
- close(BUILDURL_FH);
- chomp $buildurl;
+sub get_all_cookies {
+ foreach $key (keys %data_received) {
+ next if ($key eq "publish" or $key eq "url");
+ $cookie{$key} = read_cookie($key);
+ }
}
+
+sub read_cookie {
+
+ my $path_to_cookie = $path_to_test_directories . $_[0] . "/cookie";
+
+ open(COOKIE_FH, "$path_to_cookie")
+ or die "Can't open $path_to_cookie.\n";
+ do { $this_cookie = <COOKIE_FH> } until $. == 1;
+ close(COOKIE_FH);
+
+ chomp $this_cookie;
+ return $this_cookie;
+}
+
More information about the wine-patches
mailing list