Commit f129a645 authored by Leigh Stoller's avatar Leigh Stoller

Reorg the perl side of the "branding" code, gathering it into Brand.pm.

parent ecbe9317
......@@ -35,6 +35,7 @@ use vars qw(@ISA @EXPORT $AUTOLOAD);
use EmulabConstants;
use emdb;
use libtestbed;
use Brand;
use APT_Profile;
use English;
use Data::Dumper;
......@@ -71,6 +72,7 @@ sub Lookup($$;$)
my $self = {};
$self->{'INSTANCE'} = $query_result->fetchrow_hashref();
$self->{'BRAND'} = Brand->Create($self->{'INSTANCE'}->{'servername'});
bless($self, $class);
......@@ -93,8 +95,9 @@ AUTOLOAD {
carp("No such slot '$name' field in class $type");
return undef;
}
sub isAPT($) { return $_[0]->servername() =~ /aptlab/ ? 1 : 0; }
sub isCloud($) { return $_[0]->servername() =~ /cloudlab/ ? 1 : 0; }
sub Brand($) { return $_[0]->{'BRAND'}; }
sub isAPT($) { return $_[0]->Brand()->isAPT() ? 1 : 0; }
sub isCloud($) { return $_[0]->Brand()->isCloud() ? 1 : 0; }
# Break circular reference someplace to avoid exit errors.
sub DESTROY {
......@@ -308,5 +311,47 @@ sub RecordHistory($)
return 0;
}
#
# Warn creator that the experiment is going to expire. This is hooked
# in from the sa_daemon, so we can send a message that is less geni like
# and more APT/Cloud.
#
sub WarnExpiring($$)
{
my ($self, $when) = @_;
require GeniDB;
require GeniSlice;
my $slice = GeniSlice->Lookup($self->slice_uuid());;
if (!defined($slice)) {
print STDERR "WarnExpiring: No slice for $self\n";
return -1;
}
my $slicename = $slice->slicename();
my $geniuser = GeniUser->Lookup($slice->creator_uuid(), 1);
if (!defined($geniuser)) {
print STDERR "WarnExpiring: No creator for $self\n";
return -1;
}
if (!defined($geniuser->email())) {
print STDERR "WarnExpiring: no email address for $geniuser\n";
return 0;
}
my $link = $self->Brand()->wwwBase();
$link = $link . "/status.php?uuid=" . $self->uuid();
$self->Brand()->SendEmail($geniuser->email(),
"Your experiment is expiring soon!",
"Your experiment $slicename is going to expire in ${when}.\n".
"If you want to extend this experiment, please go to:\n\n".
" $link\n\n".
"and click on the Extend button.\n".
"\n".
"Thanks!",
$self->Brand()->OpsEmailAddress());
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#!/usr/bin/perl -wT
#
# Copyright (c) 2005-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file 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 Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
package Brand;
use strict;
use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = "Exporter";
@EXPORT = qw ( );
use English;
use libtestbed;
# Configure variables
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBAPPROVAL = "@TBAPPROVALEMAIL@";
my $TBAUDIT = "@TBAUDITEMAIL@";
my $TBBASE = "@TBBASE@";
my $TBWWW = "@TBWWW@";
#
# Return an object representing a "brand" ... yes, its silly.
#
sub Create($$)
{
my ($class, $brand) = @_;
if ($brand =~ /aptlab/) {
$brand = "aptlab";
}
elsif ($brand =~ /cloudlab/) {
$brand = "cloudlab";
}
else {
$brand = "emulab";
}
my $self = {};
$self->{'BRAND'} = $brand;
bless($self, $class);
return $self;
}
sub brand($) { return $_[0]->{'BRAND'}; }
sub isAPT($) { return $_[0]->brand() eq "aptlab" ? 1 : 0; }
sub isCloud($) { return $_[0]->brand() eq "cloudlab" ? 1 : 0; }
sub isEmulab($) { return $_[0]->brand() eq "emulab" ? 1 : 0; }
sub wwwBase($)
{
my ($self) = @_;
return ($self->isAPT() ? "https://www.aptlab.net" :
$self->isCloud() ? "https://www.cloudlab.us" :
"@TBBASE@");
}
sub ApprovalEmailAddress($)
{
my ($self) = @_;
return ($self->isAPT() ? "aptlab-approval\@aptlab.net" :
$self->isCloud() ? "cloudlab-approval\@cloudlab.us" :
"@TBAPPROVALEMAIL@");
}
sub OpsEmailAddress($)
{
my ($self) = @_;
return ($self->isAPT() ? "aptlab-ops\@aptlab.net" :
$self->isCloud() ? "cloudlab-ops\@cloudlab.us" :
$TBOPS);
}
sub EmailTag($)
{
my ($self) = @_;
return ($self->isAPT() ? "aptlab.net" :
$self->isCloud() ? "cloudlab.us" : "@THISHOMEBASE@");
}
sub SignupURL($)
{
my ($self) = @_;
my $wwwbase = $self->wwwBase();
my $pid = $self->pid();
return ($self->isAPT() || $self->isCloud() ?
"${wwwbase}/signup.php?pid=$pid" :
"${wwwbase}/joinproject.php3?target_pid=$pid");
}
# So we can localize MAILTAG variable.
sub SendEmail($$$$;$$)
{
my ($self, $to, $subject, $body, $from, $headers) = @_;
# All this function does is this.
local $libtestbed::MAILTAG = $self->EmailTag();
SENDMAIL($to, $subject, $body, $from, $headers);
return 0;
}
# So we can localize MAILTAG variable.
sub AnonSendEmail($$$$;$$)
{
my ($self, $to, $subject, $body, $from, $headers) = @_;
# All this function does is this.
local $libtestbed::MAILTAG = $self->EmailTag();
AnonSENDMAIL($to, $subject, $body, $from, $headers);
return 0;
}
......@@ -50,7 +50,7 @@ LIB_SCRIPTS = libdb.pm Node.pm libdb.py libadminctrl.pm Experiment.pm \
libEmulab.pm EmulabConstants.pm TraceUse.pm \
EmulabFeatures.pm Port.pm BlockstoreType.pm Blockstore.pm \
IPBuddyAlloc.pm IPBuddyWrapper.pm Lease.pm Quota.pm \
libTaintStates.pm WebSession.pm WebTask.pm
libTaintStates.pm WebSession.pm WebTask.pm Brand.pm
# Stuff installed on plastic.
USERSBINS = genelists.proxy dumperrorlog.proxy backup
......
......@@ -32,6 +32,7 @@ use vars qw(@ISA @EXPORT);
use libdb;
use libtestbed;
use Brand;
use User;
use Group;
use English;
......@@ -105,6 +106,7 @@ sub Lookup($$)
if (!defined($self->{'GROUP'}));
bless($self, $class);
$self->{'BRAND'} = Brand->Create($self->genesis());
# Add to cache.
$projects{$self->{'PROJECT'}->{'pid_idx'}} = $self;
......@@ -145,68 +147,28 @@ sub nonlocal_id($) { return field($_[0], "nonlocal_id"); }
sub nonlocal_type($) { return field($_[0], "nonlocal_type"); }
sub manager_urn($) { return field($_[0], "manager_urn"); }
sub genesis($) { return field($_[0], "genesis"); }
sub isAPT($) { return $_[0]->genesis() eq "aptlab" ? 1 : 0; }
sub isCloud($) { return $_[0]->genesis() eq "cloudlab" ? 1 : 0; }
sub isEmulab($) { return $_[0]->genesis() eq "emulab" ? 1 : 0; }
sub Brand($) { return $_[0]->{'BRAND'}; }
sub isAPT($) { return $_[0]->Brand()->isAPT() ? 1 : 0; }
sub isCloud($) { return $_[0]->Brand()->isCloud() ? 1 : 0; }
sub isEmulab($) { return $_[0]->Brand()->isEmulab() ? 1 : 0; }
# These come from the group not the project.
sub unix_gid($) { return $_[0]->{'GROUP'}->unix_gid(); }
sub unix_name($) { return $_[0]->{'GROUP'}->unix_name(); }
# In general, not be used directly, use SendProjAdminMail
sub ApprovalEmailAddress($)
{
my ($self) = @_;
return ($self->isAPT() ? "aptlab-approval\@aptlab.net" :
$self->isCloud() ? "cloudlab-approval\@cloudlab.us" :
"@TBAPPROVALEMAIL@");
}
sub EmailTag($)
{
my ($self) = @_;
return ($self->isAPT() ? "aptlab.net" :
$self->isCloud() ? "cloudlab.us" : "@THISHOMEBASE@");
}
sub wwwBase($)
{
my ($self) = @_;
return ($self->isAPT() ? "https://www.aptlab.net" :
$self->isCloud() ? "https://www.cloudlab.us" : $TBBASE);
}
sub SignupURL($)
{
my ($self) = @_;
my $wwwbase = $self->wwwBase();
my $pid = $self->pid();
return ($self->isAPT() || $self->isCloud() ?
"${wwwbase}/signup.php?pid=$pid" :
"${wwwbase}/joinproject.php3?target_pid=$pid");
}
# Branding.
sub ApprovalEmailAddress($) { return $_[0]->Brand()->ApprovalEmailAddress(); }
sub OpsEmailAddress($) { return $_[0]->Brand()->OpsEmailAddress(); }
sub EmailTag($) { return $_[0]->Brand()->EmailTag(); }
sub wwwBase($) { return $_[0]->Brand()->wwwBase(); }
# So we can localize MAILTAG variable.
sub SendEmail($$$)
sub SendEmail($$$$$)
{
my ($self, $to, $subject, $body, $headers) = @_;
# All this function does is this.
local $libtestbed::MAILTAG = $self->EmailTag();
SENDMAIL($to, $subject, $body, $headers);
return 0;
return $_[0]->Brand()->SendEmail($_[1],$_[2],$_[3],$_[4]);
}
# So we can localize MAILTAG variable.
sub AnonSendEmail($$$)
sub AnonSendEmail($$$$$)
{
my ($self, $to, $subject, $body, $headers) = @_;
# All this function does is this.
local $libtestbed::MAILTAG = $self->EmailTag();
SENDMAIL($to, $subject, $body, $headers);
return 0;
return $_[0]->Brand()->AnonSendEmail($_[1],$_[2],$_[3],$_[4]);
}
#
......
......@@ -32,6 +32,7 @@ use emdb;
use emutil;
use EmulabConstants;
use libtestbed;
use Brand;
use English;
use Data::Dumper;
use File::Basename;
......@@ -144,6 +145,7 @@ sub Lookup($$)
$self->{'USER'} = $query_result->fetchrow_hashref();
bless($self, $class);
$self->{'BRAND'} = Brand->Create($self->genesis());
# Add to cache.
$users{$self->{'USER'}->{'uid_idx'}} = $self;
......@@ -214,9 +216,16 @@ sub nonlocal_type($) { return field($_[0], "nonlocal_type"); }
sub IsLocal($) { return (defined($_[0]->nonlocal_id()) ? 0 : 1); };
sub IsNonLocal($) { return (defined($_[0]->nonlocal_id()) ? 1 : 0); };
sub genesis($) { return field($_[0], "genesis"); }
sub isAPT($) { return $_[0]->genesis() eq "aptlab" ? 1 : 0; }
sub isCloud($) { return $_[0]->genesis() eq "cloudlab" ? 1 : 0; }
sub isEmulab($) { return $_[0]->genesis() eq "emulab" ? 1 : 0; }
sub Brand($) { return $_[0]->{'BRAND'}; }
sub isAPT($) { return $_[0]->Brand()->isAPT() ? 1 : 0; }
sub isCloud($) { return $_[0]->Brand()->isCloud() ? 1 : 0; }
sub isEmulab($) { return $_[0]->Brand()->isEmulab() ? 1 : 0; }
# Branding.
sub ApprovalEmailAddress($) { return $_[0]->Brand()->ApprovalEmailAddress(); }
sub OpsEmailAddress($) { return $_[0]->Brand()->OpsEmailAddress(); }
sub EmailTag($) { return $_[0]->Brand()->EmailTag(); }
sub wwwBase($) { return $_[0]->Brand()->wwwBase(); }
# Temporary data storage ... useful.
sub GetTempData($$) { return field($_[0], "tempdata"); }
......@@ -1505,9 +1514,11 @@ sub SendVerifiedEmail($)
return 0;
}
sub SendEmail($$$)
sub SendEmail($$$;$)
{
my ($self, $subject, $body) = @_;
my ($self, $subject, $body, $from) = @_;
$from = $self->Brand()->OpsEmailAddress()
if (!defined($from));
# Must be a real reference.
return -1
......@@ -1517,9 +1528,9 @@ sub SendEmail($$$)
my $user_email = $self->email();
my $user_name = $self->name();
# Audit email.
SENDMAIL("$user_name <$user_email>", $subject, $body,
$TBOPS, "Bcc: $TBAUDIT");
return $self->Brand()->SendEmail("$user_name <$user_email>",
$subject, $body, $from,
"Bcc: $TBAUDIT");
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment