summaryrefslogtreecommitdiffstats
path: root/etherpad/src/etherpad/store/eepnet_trial.js
blob: 570d35189dfe65cc7ba73960164921ca44e96f79 (plain)
1
2
3
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**
 * Copyright 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import("email.sendEmail");
import("sqlbase.sqlobj");
import("sqlbase.sqlcommon");
import("execution");

import("etherpad.sessions.getSession");
import("etherpad.log");
import("etherpad.licensing");
import("etherpad.utils.*");
import("etherpad.globals.*");

//----------------------------------------------------------------

function getTrialDays() {
  return 30;
}

function getTrialUserQuota() {
  return 100;
}

function mailLicense(data, licenseKey, expiresDate) {
  var toAddr = data.email;
  if (isTestEmail(toAddr)) {
    toAddr = "blackhole@appjet.com";
  }
  var subject = ('EtherPad: Trial License Information for '+
		 data.firstName+' '+data.lastName+' ('+data.orgName+')');

  var emailBody = renderTemplateAsString("email/eepnet_license_info.ejs", {
    userName: data.firstName+" "+data.lastName,
    licenseKey: licenseKey,
    expiresDate: expiresDate,
    isEvaluation: true
  });

  sendEmail(
    toAddr,
    'sales@pad.spline.inf.fu-berlin.de',
    subject,
    {},
    emailBody
  );
}

function mailLostLicense(email) {
  var data = sqlobj.selectSingle('eepnet_signups', {email: email});
  var keyInfo = licensing.decodeLicenseInfoFromKey(data.licenseKey);
  var expiresDate = keyInfo.expiresDate;

  mailLicense(data, data.licenseKey, expiresDate);
}

function hasEmailAlreadyDownloaded(email) {
  var existingRecord = sqlobj.selectSingle('eepnet_signups', {email: email});
  if (existingRecord) {
    return true;
  } else {
    return false
  }
}

function createAndMailNewLicense(data) {
  sqlcommon.inTransaction(function() {
    var expiresDate = new Date(+(new Date)+(1000*60*60*24*getTrialDays()));
    var licenseKey = licensing.generateNewKey(
      data.firstName + ' ' + data.lastName,
      data.orgName,
	+expiresDate,
      licensing.getEditionId('PRIVATE_NETWORK_EVALUATION'),
      getTrialUserQuota()
    );

    // confirm key
    if (!licensing.isValidKey(licenseKey)) {
      throw Error("License key I just created is not valid: "+l);
    }

    // Log all this precious info
    _logDownloadData(data, licenseKey);

    // Store in database
    sqlobj.insert("eepnet_signups", {
      firstName: data.firstName,
      lastName: data.lastName,
      email: data.email,
      orgName: data.orgName,
      jobTitle: data.jobTitle,
      date: new Date(),
      signupIp: String(request.clientAddr).substr(0,16),
      estUsers: data.estUsers,
      licenseKey: licenseKey,
      phone: data.phone,
      industry: data.industry
    });

    mailLicense(data, licenseKey, expiresDate);

    // Send sales notification
    var clientAddr = request.clientAddr;
    var initialReferer = getSession().initialReferer;
    execution.async(function() {
      _sendSalesNotification(data, clientAddr, initialReferer);
    });

  }); // end transaction
}

function _logDownloadData(data, licenseKey) {
  log.custom("eepnet_download_info", {
    email: data.email,
    firstName: data.firstName,
    lastName: data.lastName,
    org: data.orgName,
    jobTitle: data.jobTitle,
    phone: data.phone,
    estUsers: data.estUsers,
    licenseKey: licenseKey,
    ip: request.clientAddr,
    industry: data.industry,
    referer: getSession().initialReferer
  });
}

function getWeb2LeadData(data, ip, ref) {
  var googleQuery = extractGoogleQuery(ref);
  var w2ldata = {
    oid: "00D80000000b7ey",
    first_name: data.firstName,
    last_name: data.lastName,
    email: data.email,
    company: data.orgName,
    title: data.jobTitle,
    phone: data.phone,
    '00N80000003FYtG': data.estUsers,
    '00N80000003FYto': ref,
    '00N80000003FYuI': googleQuery,
    lead_source: 'EEPNET Download',
    industry: data.industry
  };

  if (!isProduction()) {
//    w2ldata.debug = "1";
//    w2ldata.debugEmail = "aaron@appjet.com";
  }

  return w2ldata;
}

function _sendSalesNotification(data, ip, ref) {
  var hostname = ipToHostname(ip) || "unknown";

  var subject = "EEPNET Trial Download: "+[data.orgName, data.firstName + ' ' + data.lastName, data.email].join(" / ");

  var body = [
    "",
    "This is an automated message.",
    "",
    "Somebody downloaded a "+getTrialDays()+"-day trial of EEPNET.",
    "",
    "This lead should be automatically added to the AppJet salesforce account.",
    "",
    "Organization: "+data.orgName,
    "Industry: "+data.industry,
    "Full Name: "+data.firstName + ' ' + data.lastName,
    "Job Title: "+data.jobTitle,
    "Email: "+data.email,
    'Phone: '+data.phone,
    "Est. Users: "+data.estUsers,
    "IP Address: "+ip+" ("+hostname+")",
    "Session Referer: "+ref,
    ""
  ].join("\n");

  var toAddr = 'sales@pad.spline.inf.fu-berlin.de';
  if (isTestEmail(data.email)) {
    toAddr = 'blackhole@appjet.com';
  }
  sendEmail(
    toAddr,
    'sales@pad.spline.inf.fu-berlin.de',
    subject,
    {'Reply-To': data.email},
    body
  );
}

function getSalesforceIndustryList() {
  return [
    '--None--',
    'Agriculture',
    'Apparel',
    'Banking',
    'Biotechnology',
    'Chemicals',
    'Communications',
    'Construction',
    'Consulting',
    'Education',
    'Electronics',
    'Energy',
    'Engineering',
    'Entertainment',
    'Environmental',
    'Finance',
    'Food & Beverage',
    'Government',
    'Healthcare',
    'Hospitality',
    'Insurance',
    'Machinery',
    'Manufacturing',
    'Media',
    'Not For Profit',
    'Other',
    'Recreation',
    'Retail',
    'Shipping',
    'Technology',
    'Telecommunications',
    'Transportation',
    'Utilities'
  ];
}