2005-10-11 22:44:16 +04:00
|
|
|
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
|
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License
|
|
|
|
# Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
# compliance with the License. You may obtain a copy of the License
|
|
|
|
# at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS"
|
|
|
|
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
# the License for the specific language governing rights and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is Litmus.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# the Mozilla Corporation.
|
2006-01-25 20:03:40 +03:00
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
2005-10-11 22:44:16 +04:00
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Chris Cooper <ccooper@deadsquid.com>
|
|
|
|
# Zach Lipton <zach@zachlipton.com>
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
|
|
|
=cut
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
package Litmus::SysConfig;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
require Exporter;
|
|
|
|
use Litmus;
|
2005-12-13 06:03:37 +03:00
|
|
|
use Litmus::DB::Locale;
|
2005-07-30 00:21:01 +04:00
|
|
|
use Litmus::DB::Product;
|
|
|
|
use Litmus::Error;
|
2005-08-04 04:59:29 +04:00
|
|
|
use Litmus::Utils;
|
2005-07-30 00:21:01 +04:00
|
|
|
use CGI;
|
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
|
|
|
my $configcookiename = $Litmus::Config::sysconfig_cookiename;
|
|
|
|
|
|
|
|
sub new {
|
2005-12-13 06:03:37 +03:00
|
|
|
my ($class, $product, $platform, $opsys, $branch, $buildid, $locale) = @_;
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
my $self = {};
|
|
|
|
bless($self);
|
|
|
|
|
|
|
|
$self->{"product"} = $product;
|
|
|
|
$self->{"platform"} = $platform;
|
|
|
|
$self->{"opsys"} = $opsys;
|
2005-12-13 06:03:37 +03:00
|
|
|
$self->{"branch"} = $branch;
|
2005-07-30 00:21:01 +04:00
|
|
|
$self->{"buildid"} = $buildid;
|
2005-12-13 06:03:37 +03:00
|
|
|
$self->{"locale"} = $locale;
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setCookie {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my %cookiedata;
|
|
|
|
|
2006-01-08 06:56:10 +03:00
|
|
|
my $c = Litmus->cgi();
|
2005-07-30 00:21:01 +04:00
|
|
|
my $cookie = $c->cookie(
|
|
|
|
-name => $configcookiename.'_'.$self->{"product"}->productid(),
|
|
|
|
-value => join('|', $self->{"product"}->productid(), $self->{"platform"}->platformid(),
|
2005-12-13 06:03:37 +03:00
|
|
|
$self->{"opsys"}->opsysid(), $self->{"branch"}->branchid(), $self->{"buildid"}, $self->{"locale"}->abbrev()),
|
2005-07-30 00:21:01 +04:00
|
|
|
-domain => $main::ENV{"HTTP_HOST"},
|
|
|
|
);
|
|
|
|
|
|
|
|
return $cookie;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getCookie() {
|
|
|
|
my $self = shift;
|
2006-01-08 06:56:10 +03:00
|
|
|
my $c = Litmus->cgi();
|
2005-07-30 00:21:01 +04:00
|
|
|
my $product = shift;
|
|
|
|
|
|
|
|
my $cookie = $c->cookie($configcookiename.'_'.$product->productid());
|
|
|
|
if (! $cookie) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @sysconfig = split(/\|/, $cookie);
|
|
|
|
|
|
|
|
return new(undef,
|
|
|
|
Litmus::DB::Product->retrieve($sysconfig[0]),
|
|
|
|
Litmus::DB::Platform->retrieve($sysconfig[1]),
|
|
|
|
Litmus::DB::Opsys->retrieve($sysconfig[2]),
|
|
|
|
Litmus::DB::Branch->retrieve($sysconfig[3]),
|
|
|
|
$sysconfig[4],
|
2005-12-13 06:03:37 +03:00
|
|
|
Litmus::DB::Locale->retrieve($sysconfig[5])
|
2005-07-30 00:21:01 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub product() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"product"};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub platform() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"platform"};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub opsys() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"opsys"};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub branch() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"branch"};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub buildid() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"buildid"};
|
|
|
|
}
|
|
|
|
|
2005-12-13 06:03:37 +03:00
|
|
|
sub locale() {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{"locale"};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-30 00:21:01 +04:00
|
|
|
# display the system configuration form
|
2005-08-04 04:59:29 +04:00
|
|
|
# optionally takes the product to configure for
|
|
|
|
# and requires a url to load when done. this
|
2005-07-30 00:21:01 +04:00
|
|
|
# url should call processForm() to
|
|
|
|
# set the sysconfig cookie and do
|
|
|
|
# error handling.
|
|
|
|
# optionaly, pass a CGI object and its
|
|
|
|
# data will be stored in the form so
|
|
|
|
# the receiving script can access it.
|
|
|
|
sub displayForm {
|
|
|
|
my $self = shift;
|
|
|
|
my $product = shift;
|
|
|
|
my $goto = shift;
|
|
|
|
my $c = shift;
|
|
|
|
|
2005-08-04 04:59:29 +04:00
|
|
|
my @products;
|
|
|
|
# if we already know the product, then just send it on:
|
|
|
|
if ($product) {
|
|
|
|
$products[0] = $product;
|
|
|
|
} else {
|
|
|
|
# we need to ask the user for the product then
|
|
|
|
@products = Litmus::DB::Product->retrieve_all();
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
2005-12-13 06:03:37 +03:00
|
|
|
|
|
|
|
my @locales = Litmus::DB::Locale->retrieve_all(
|
|
|
|
{ order_by => 'abbrev' }
|
|
|
|
);
|
2005-07-30 00:21:01 +04:00
|
|
|
my $vars = {
|
2005-12-13 06:03:37 +03:00
|
|
|
locales => \@locales,
|
2005-08-04 04:59:29 +04:00
|
|
|
products => \@products,
|
|
|
|
ua => Litmus::UserAgentDetect->new(),
|
2005-07-30 00:21:01 +04:00
|
|
|
"goto" => $goto,
|
|
|
|
cgidata => $c,
|
|
|
|
};
|
|
|
|
|
|
|
|
# if the user already has a cookie set for this product, then
|
|
|
|
# load those values as defaults:
|
2005-08-04 04:59:29 +04:00
|
|
|
if ($product && Litmus::SysConfig->getCookie($product)) {
|
|
|
|
my $sysconfig = Litmus::SysConfig->getCookie($product);
|
2005-07-30 00:21:01 +04:00
|
|
|
$vars->{"defaultplatform"} = $sysconfig->platform();
|
|
|
|
$vars->{"defaultopsys"} = $sysconfig->opsys();
|
|
|
|
$vars->{"defaultbranch"} = $sysconfig->branch();
|
2005-12-13 06:03:37 +03:00
|
|
|
$vars->{"defaultlocale"} = $sysconfig->locale();
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
|
|
|
|
2006-01-08 06:56:10 +03:00
|
|
|
my $cookie = Litmus::Auth::getCurrentUser();
|
2005-10-11 22:44:16 +04:00
|
|
|
$vars->{"defaultemail"} = $cookie;
|
|
|
|
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
|
|
|
|
|
|
|
|
$vars->{"title"} = "Run Tests";
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
Litmus->template()->process("runtests/sysconfig.html.tmpl", $vars) ||
|
|
|
|
internalError(Litmus->template()->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
# process a form containing sysconfig information.
|
2005-08-04 04:59:29 +04:00
|
|
|
# takes a CGI object containing param data
|
2005-07-30 00:21:01 +04:00
|
|
|
sub processForm {
|
|
|
|
my $self = shift;
|
|
|
|
my $c = shift;
|
|
|
|
|
2005-08-04 04:59:29 +04:00
|
|
|
my $product = Litmus::DB::Product->retrieve($c->param("product"));
|
|
|
|
my $platform = Litmus::DB::Platform->retrieve($c->param("platform"));
|
|
|
|
my $opsys = Litmus::DB::Opsys->retrieve($c->param("opsys"));
|
|
|
|
my $branch = Litmus::DB::Branch->retrieve($c->param("branch"));
|
|
|
|
my $buildid = $c->param("buildid");
|
2005-12-13 06:03:37 +03:00
|
|
|
my $locale = Litmus::DB::Locale->retrieve($c->param("locale"));
|
2005-08-04 04:59:29 +04:00
|
|
|
|
|
|
|
requireField("product", $product);
|
|
|
|
requireField("platform", $platform);
|
|
|
|
requireField("opsys", $opsys);
|
|
|
|
requireField("branch", $branch);
|
|
|
|
requireField("buildid", $buildid);
|
2005-12-13 06:03:37 +03:00
|
|
|
requireField("locale", $locale);
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
# set a cookie with the user's testing details:
|
|
|
|
my $prod = Litmus::DB::Product->retrieve($c->param("product"));
|
|
|
|
my $sysconfig = Litmus::SysConfig->new(
|
2005-08-04 04:59:29 +04:00
|
|
|
$product,
|
|
|
|
$platform,
|
|
|
|
$opsys,
|
|
|
|
$branch,
|
2005-12-13 06:03:37 +03:00
|
|
|
$buildid,
|
|
|
|
$locale
|
2005-07-30 00:21:01 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
return $sysconfig;
|
|
|
|
}
|
2005-10-11 22:44:16 +04:00
|
|
|
1;
|
2005-12-13 06:03:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
|