-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
454 lines (384 loc) · 16.1 KB
/
Copy pathsignup.php
File metadata and controls
454 lines (384 loc) · 16.1 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE.TXT.
*
* Further details on the project are available at http://postfixadmin.sf.net
*
* @version $Id$
* @license GNU GPL v2 or later.
*
* File: edit.php
* This file implements the handling of edit forms.
* The form layout is retrieved from the *Handler classes, which also do
* the actual work of verifying and storing the values.
*
* GET parameters:
* table what to edit (*Handler)
* edit item to edit (if net given: a new item will be created)
* additional parameters will be accepted if specified in *Handler->webformConfig()[prefill] when creating a new item
*/
define("RECAPTCHA_V3_SECRET_KEY", '6Lck3ykaAAAAAHjJR5Qbkea73XwyCa9c18DXX9Cu');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$token2 = $_POST['token2'];
$action2 = $_POST['action'];
// call curl to POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => RECAPTCHA_V3_SECRET_KEY, 'response' => $token2)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$arrResponse = json_decode($response, true);
// verify the response
if($arrResponse["success"] == '1' && $arrResponse["action"] == $action2 && $arrResponse["score"] >= 0.5) {
//valid submission
//go ahead and do necessary stuff
} else {
//spam submission
//show error message
header("Location: https://isellemails.com/postfixadmin/public/signup.php?table=mailbox&domain=isellemails.com");
exit;
}
}
$username='winicius@gmail.com';
$_SESSION['sessid']['username']=$username;
require_once('common.php');
//$username = authentication_get_username(); # enforce login
$table = safepost('table', safeget('table'));
$handlerclass = ucfirst($table) . 'Handler';
if (!preg_match('/^[a-z]+$/', $table) || !file_exists(dirname(__FILE__) . "/../model/$handlerclass.php")) { # validate $table
die("Invalid table name given!");
}
$error = 0;
$edit = safepost('edit', safeget('edit'));
$new = 0;
if ($edit == "") {
$new = 1;
}
//winicius
$new = 1;
//$is_admin = authentication_has_role('admin');
$is_admin = true;
$handler = new $handlerclass($new, $username, $is_admin);
$formconf = $handler->webformConfig();
$_SESSION['sessid']['roles'] = array('admin');
if ($is_admin) {
// error_log("echo 1: ". $formconf['required_role']);
authentication_require_role($formconf['required_role']);
} else {
// if (empty($formconf['user_hardcoded_field'])) {
// die($handlerclass . ' is not available for users');
// }
}
if ($new == 0 || $formconf['early_init']) {
if (!$handler->init($edit)) {
if (count($handler->errormsg) == 0) {
# should never happen and indicates a bug in $handler->init()
flash_error($handlerclass . "->init() failed, but didn't set any error message");
}
flash_error($handler->errormsg);
header("Location: " . $formconf['listview']);
exit;
}
}
$form_fields = $handler->getStruct();
$id_field = $handler->getId_field();
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($new) { # new - prefill fields from URL parameters if allowed in $formconf['prefill']
if (isset($formconf['prefill'])) {
foreach ($formconf['prefill'] as $field) {
$prefillvalue = safeget($field, safesession("prefill:$table:$field"));
if ($prefillvalue != '') {
$form_fields[$field]['default'] = $prefillvalue;
$handler->prefill($field, $prefillvalue);
}
}
}
$form_fields = $handler->getStruct(); # refresh $form_fields - a prefill field might have changed something
} else { # edit mode - read values from database
if (!$handler->view()) {
flash_error($handler->errormsg);
header("Location: " . $formconf['listview']);
exit;
} else {
$values = $handler->result;
$values[$id_field] = $edit;
}
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
//if (safepost('token') != $_SESSION['PFA_token']) {
// die('Invalid token!');
//}
$inp_values = safepost('value', array());
foreach ($form_fields as $key => $field) {
if ($field['editable'] && $field['display_in_form']) {
if (!isset($inp_values[$key])) {
$inp_values[$key] = ''; # newer PHP versions don't include empty fields in $_POST (noticed with PHP 5.6.6)
}
if ($field['type'] == 'bool' && $inp_values[$key] == '') {
$values[$key] = 0; # isset() for unchecked checkboxes is always false
} elseif ($field['type'] == 'txtl') {
$values[$key] = $inp_values[$key];
$values[$key] = preg_replace('/\\\r\\\n/', ',', $values[$key]);
$values[$key] = preg_replace('/\r\n/', ',', $values[$key]);
$values[$key] = preg_replace('/,[\s]+/i', ',', $values[$key]);
$values[$key] = preg_replace('/[\s]+,/i', ',', $values[$key]);
$values[$key] = preg_replace('/,,*/', ',', $values[$key]);
$values[$key] = preg_replace('/,*$|^,*/', '', $values[$key]);
if ($values[$key] == '') {
$values[$key] = array();
} else {
$values[$key] = explode(",", $values[$key]);
}
} else {
$values[$key] = $inp_values[$key];
}
}
}
if (isset($formconf['hardcoded_edit']) && $formconf['hardcoded_edit']) {
$values[$id_field] = $form_fields[$id_field]['default'];
} elseif ($new == 0) {
$values[$id_field] = $edit;
}
if ($new && ($form_fields[$id_field]['display_in_form'] == 0)) {
if ($form_fields[$id_field]['editable'] == 1) { # address split to localpart and domain?
$values[$id_field] = $handler->mergeId($values);
} else { # probably auto_increment
$values[$id_field] = '';
}
}
if (!$handler->init($values[$id_field])) {
$error = 1;
$errormsg = $handler->errormsg;
}
if (!$handler->set($values)) {
$error = 1;
$errormsg = $handler->errormsg;
}
$form_fields = $handler->getStruct(); # refresh $form_fields - set() might have changed something
//winicius
//winicius
// error_log("echo: " . $error);
if ($error != 1) {
// error_log("echo3: ");// . print_r($handler->values));
if (!$handler->store()) {
$errormsg = $handler->errormsg;
// error_log("echo2: ");
// error_log("echo2: " . $errormsg);
} else {
flash_info($handler->infomsg);
// error_log("echo2 info: ");
// error_log("echo2 info: " . $handler->infomsg);
if (count($handler->errormsg)) { # might happen if domain_postcreation fails
flash_error($handler->errormsg);
}
# remember prefill values for next usage of the form
if (isset($formconf['prefill'])) {
foreach ($formconf['prefill'] as $field) {
if (isset($values[$field])) {
$_SESSION["prefill:$table:$field"] = $values[$field];
}
}
}
if ($new == 0) {
header("Location: " . $formconf['listview']);
exit;
} else {
header("Location: signup.php?table=mailbox&domain=isellemails.com&success=true");
exit;
}
}
}
}
/*
if ($error != 1 && $new) { # no error and not in edit mode - reset fields to default for new item
$values = array();
foreach (array_keys($form_fields) as $key) {
$values[$key] = $form_fields[$key]['default'];
}
}
$errormsg = $handler->errormsg;
$fielderror = array();
foreach ($form_fields as $key => $field) {
if ($form_fields[$key]['display_in_form']) {
if (isset($errormsg[$key])) {
$fielderror[$key] = $errormsg[$key];
unset($errormsg[$key]);
} else {
$fielderror[$key] = '';
}
if (isset($values[$key])) {
$smarty->assign("value_$key", $values[$key]);
} else {
$smarty->assign("value_$key", $form_fields[$key]['default']);
}
}
}
if (count($errormsg)) {
flash_error($errormsg);
} # display the remaining error messages (not related to a field) with flash_error
if ($new) {
$smarty->assign('mode', 'create');
$smarty->assign('formtitle', Config::lang($formconf['formtitle_create']));
$smarty->assign('submitbutton', Config::lang($formconf['create_button']));
} else {
$smarty->assign('mode', 'edit');
$smarty->assign('formtitle', Config::lang($formconf['formtitle_edit']));
$smarty->assign('submitbutton', Config::lang('save'));
}
$smarty->assign('struct', $form_fields);
$smarty->assign('fielderror', $fielderror);
$smarty->assign('table', $table);
$smarty->assign('smarty_template', 'editform');
*/
//$smarty->display('index.tpl');
//
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
?>
<!-- index.tpl -->
<!-- header.tpl -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Postfix Signup - isellemails.com</title>
<link rel="shortcut icon" href="images/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.3/dist/jquery.validate.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js?render=6Lck3ykaAAAAABxqBmTWA1dwE_rP2XPVltJjjzeg"></script>
</head>
<body class="lang-en page-editform page-editform-mailbox">
<div id="container">
<div id="login_header">
<a href='https://mail.isellemails.com'><img id="login_header_logo" src="images/logo-default.png" alt="Logo" /></a>
</div>
<!-- menu.tpl -->
<?php
?>
<!-- flash_error.tpl -->
<div id="edit_form">
<form class="needs-validation" name="edit_mailbox" id="edit_mailbox" method="post" action="signup.php" novalidate oninput='password2.setCustomValidity(password2.value != password1.value ? "Passwords do not match." : "")'>
<input class="flat" type="hidden" name="table" value="mailbox" />
<input class="flat" type="hidden" name="token" value="" />
<?php
if (isset($_GET['success'])) {
echo ' <h1 class="col-md-6 mb-3"><a href="https://mail.isellemails.com">Login to your new email at mail.isellemails.com. Click here.</a></h1>
';
}else{
echo ' <h1 class="col-md-6 mb-3">Welcome to @isellemails.com</h1>
<h2 class="col-md-6 mb-3">Create a new email address! Forget about gmail, yahoo, and bing.</h2>
'; }
?>
<div class="col-md-6 mb-3">
<label for="username1">Username</label>
<input placeholder="Username" id="username1" class="form-control" type="text" name="value[local_part]" value="" pattern="[a-z0-9._%+-]+" required/>
<div class="invalid-feedback">
Valid alphanumeric username is required.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="domain">Domain</label>
<select class="form-control" name="value[domain]" required="">
<option value="isellemails.com" selected="selected">isellemails.com</option>
</select>
<div class="invalid-feedback">
Choose domain.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="password1">Password (length of 6 characters with 2 digits)</label>
<input type="password" class="form-control" id="password1" placeholder="Password" name="value[password]" pattern="(?=.*?\d.*?\d).{4,}" required="" />
<div class="invalid-feedback">
Valid password length of 6 characters with 2 digits is required.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="password2">Password</label>
<input id="password2" class="form-control" type="password" name="value[password2]" required=""placeholder="Password" />
<div class="invalid-feedback">
Passwords do not match.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="fullname">Full name</label>
<input class="form-control" type="text" name="value[name]" value="" required="" placeholder="Firstname Lastname" />
<div class="invalid-feedback">
Please enter full name.
</div>
</div>
<input class="flat" type="hidden" name="value[quota]" value="2000" />
<input class="flat" type="hidden" value='1' name="value[active]" checked="checked"/>
<input class="flat" type="hidden" value='1' name="value[welcome_mail]" checked="checked"/>
<div class="col-md-6 mb-3">
<label for="other_email">Other Email for Recovery (Optional)</label>
<input id="other_email" class="form-control" type="text" name="value[email_other]" value="" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" placeholder="email@domain.com"/>
<div class="invalid-feedback">
Enter valid email address.
</div>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="Add Mailbox (Press Once)" /></td>
</form>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('6Lck3ykaAAAAABxqBmTWA1dwE_rP2XPVltJjjzeg', {action: 'signup'}).then(function(token2) {
$('#edit_mailbox').prepend('<input type="hidden" name="token2" value="' + token2 + '">');
$('#edit_mailbox').prepend('<input type="hidden" name="action" value="signup">');
//$('#edit_mailbox').unbind('submit').submit();
//$('#edit_mailbox').submit();
});
});
</script>
<script>
/*
$('#edit_mailbox').submit(function(event) {
event.preventDefault();
grecaptcha.ready(function() {
grecaptcha.execute('6Lck3ykaAAAAABxqBmTWA1dwE_rP2XPVltJjjzeg', {action: 'signup'}).then(function(token2) {
$('#edit_mailbox').prepend('<input type="hidden" name="token2" value="' + token2 + '">');
$('#edit_mailbox').prepend('<input type="hidden" name="action" value="signup">');
$('#edit_mailbox').unbind('submit').submit();
});
});
});
*/
</script>
</div>
<!-- footer.tpl -->
<div id="footer">
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script>
//Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
//Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
//bootstrapValidate('#other_email', 'email:Enter a valid email address');
//Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
</body>
</html>