Brand.pm.in 5.63 KB
Newer Older
1 2
#!/usr/bin/perl -wT
#
3
# Copyright (c) 2005-2018 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# 
# {{{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@";
39
my $TBLOGS      = "@TBLOGSEMAIL@";
40 41 42 43 44 45 46 47 48 49 50 51
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) = @_;

52 53 54 55 56
    # No brand means the classic interface.
    if (!defined($brand)) {
	$brand = "classic";
    }
    elsif ($brand =~ /aptlab/) {
57 58 59 60 61
	$brand = "aptlab";
    }
    elsif ($brand =~ /cloudlab/) {
	$brand = "cloudlab";
    }
62 63 64
    elsif ($brand =~ /phantomnet/) {
	$brand = "phantomnet";
    }
65 66 67
    elsif ($brand =~ /powder/) {
	$brand = "powder";
    }
68
    else {
69
	# This means the new Portal interface.
70 71 72 73 74 75 76 77 78 79 80
	$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; }
81
sub isPNet($)           { return $_[0]->brand() eq "phantomnet" ? 1 : 0; }
82
sub isPowder($)         { return $_[0]->brand() eq "powder" ? 1 : 0; }
83
sub isEmulab($)         { return $_[0]->brand() eq "emulab" ? 1 : 0; }
84
sub isClassic($)        { return $_[0]->brand() eq "classic" ? 1 : 0; }
85 86 87 88 89 90 91

sub wwwBase($)
{
    my ($self) = @_;

    return ($self->isAPT() ? "https://www.aptlab.net" :
	    $self->isCloud() ? "https://www.cloudlab.us" :
92
	    $self->isPNet() ? "https://www.phantomnet.org" :
93
	    $self->isPowder() ? "https://www.powderwireless.net" :
94
	    $self->isEmulab() ?	"@TBBASE@" . "/portal" :
95 96 97 98 99 100 101 102 103
	    "@TBBASE@");
}

sub ApprovalEmailAddress($)
{
    my ($self) = @_;

    return ($self->isAPT() ? "aptlab-approval\@aptlab.net" :
	    $self->isCloud() ? "cloudlab-approval\@cloudlab.us" :
104
	    $self->isPNet() ? "phantomnet-approval\@phantomnet.org" :
105
	    $self->isPowder() ? "powder-approval\@powderwireless.net" :
106 107 108 109 110 111 112
	    "@TBAPPROVALEMAIL@");
}

sub OpsEmailAddress($)
{
    my ($self) = @_;

113 114
    return ($self->isAPT() ? "portal-ops\@aptlab.net" :
	    $self->isCloud() ? "portal-ops\@cloudlab.us" :
115
	    $self->isPNet() ? "portal-ops\@phantomnet.org" :
116
	    $self->isPowder() ? "portal-ops\@powderwireless.net" :
117 118 119
	    $TBOPS);
}

120 121 122 123 124 125
sub LogsEmailAddress($)
{
    my ($self) = @_;

    return ($self->isAPT() ? "apt-logs\@aptlab.net" :
	    $self->isCloud() ? "cloudlab-logs\@cloudlab.us" :
126
	    $self->isPNet() ? "phantomnet-logs\@phantomnet.org" :
127
	    $self->isPowder() ? "powder-logs\@powderwireless.net" :
128 129 130
	    $TBLOGS);
}

131 132 133 134 135 136 137
sub ExtensionsEmailAddress($)
{
    my ($self) = @_;

    return ($self->isAPT() ? "portal-extensions\@aptlab.net" :
	    $self->isCloud() ? "portal-extensions\@cloudlab.us" :
	    $self->isPNet() ? "portal-extensions\@phantomnet.org" :
138
	    $self->isPowder() ? "portal-extensions\@powderwireless.net" :
139 140 141
	    $TBOPS);
}

142 143 144 145 146
sub EmailTag($)
{
    my ($self) = @_;

    return ($self->isAPT() ? "aptlab.net" :
147 148
	    $self->isCloud() ? "cloudlab.us" :
	    $self->isPNet() ? "phantomnet.org" :
149
	    $self->isPowder() ? "powderwireless.net" :
150
	    "@THISHOMEBASE@");
151 152
}

153
sub SignupURL($$)
154
{
155
    my ($self, $project)  = @_;
156
    my $wwwbase = $self->wwwBase();
157
    my $pid     = $project->pid();
158

159
    return ($self->isAPT() || $self->isCloud() ||
160
	    $self->isPNet() || $self->isPowder() || $self->isEmulab() ? 
161 162 163 164
	    "${wwwbase}/signup.php?pid=$pid" :
	    "${wwwbase}/joinproject.php3?target_pid=$pid");
}

165 166 167 168
sub UsersGroupName($)
{
    my ($self)  = @_;

169 170 171
    return ($self->isAPT() ? "apt-users\@googlegroups.com" :
	    $self->isCloud() ? "cloudlab-users\@googlegroups.com" :
	    $self->isPNet() ? "phantomnet-users\@googlegroups.com" :
172
	    $self->isPowder() ? "powder-users\@googlegroups.com" :
173
	    "emulab-users\@googlegroups.com");
174 175 176 177 178
}

sub UsersGroupURL($)
{
    my ($self)  = @_;
179
    my $url = 'https://groups.google.com/forum/#!forum';
180

181 182 183
    return ($self->isAPT() ? "$url/apt-users" : 
	    $self->isCloud() ? "$url/cloudlab-users" :
	    $self->isPNet() ? "$url/phantomnet-users" :
184
	    $self->isPowder() ? "$url/powder-users" :
185
	    "$url/emulab-users");
186 187
}

188
# So we can localize MAILTAG variable.
189
sub SendEmail($$$$;$$@)
190
{
191
    my ($self, $to, $subject, $body, $from, $headers, @files) = @_;
192 193 194 195

    # All this function does is this. 
    local $libtestbed::MAILTAG = $self->EmailTag();
    
196
    SENDMAIL($to, $subject, $body, $from, $headers, @files);
197 198 199
    return 0;
}
# So we can localize MAILTAG variable.
200
sub AnonSendEmail($$$$;$$@)
201
{
202
    my ($self, $to, $subject, $body, $from, $headers, @files) = @_;
203 204 205 206

    # All this function does is this. 
    local $libtestbed::MAILTAG = $self->EmailTag();
    
207
    AnonSENDMAIL($to, $subject, $body, $from, $headers, @files);
208 209 210
    return 0;
}