-
Notifications
You must be signed in to change notification settings - Fork 1
/
requestuniqueidrange.php
204 lines (176 loc) · 8.66 KB
/
requestuniqueidrange.php
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once('access.php');
require_once('dal.php');
require_once('utils.php');
require_once('email.php');
$error = null;
$message = null;
$user = null;
$dal = new DAL($opts['hn'], $opts['db'], $opts['un'], $opts['pw']);
try {
$dal->beginTransaction();
$user = $dal->selectUser();
if (isset($_POST['send_request'])) {
if ($user === null) {
if (!isset($_POST['g-recaptcha-response']) || !$_POST['g-recaptcha-response']) throw new UserException('Robots not allowed.');
$recaptcha = new \ReCaptcha\ReCaptcha(RECAPTCHA_SECRET);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) throw new UserException('reCAPTCHA error');
if (!$_POST['email']) throw new UserException('Email address not entered.');
if ($_POST['email'] !== $_POST['repeat_email']) throw new UserException('The entered email addresses do not match.');
if ($dal->selectPersonByEmail($_POST['email']) !== null) throw new UserException('The entered email address is already in use. Please login before requesting an unique id range.');
$person = array(
'person_first_name' => $_POST['first_name'],
'person_last_name' => $_POST['last_name'],
'person_organization' => $_POST['organization'],
'person_email' => $_POST['email'],
'person_subscribe' => isset($_POST['subscribe']) ? 'y' : 'n',
'person_email_verified' => 'n',
'person_email_shared_secret' => null,
'person_password_hash' => null
);
$dal->insertPerson($person);
} else {
if ($user['person_unapproved_uniqueid_count'] > 0) throw new UserException('A previous unique id range request is still pending approval.');
$person = $user;
}
$unique_id = array(
'person_id' => $person['person_id'],
'uniqueid_url' => $_POST['url'],
'uniqueid_user_comment' => $_POST['comment']
);
$dal->insertUniqueId($unique_id);
$subject = "OpenLCB Unique ID Range Requested";
$body = "Hi " . formatPersonName($person) . ",
You were assigned an OpenLCB unique ID range of:
" . formatUniqueIdHex($unique_id) . "
Delegating organization or person: " . formatPersonName($person) . "
URL: " . $unique_id['uniqueid_url'] . "
Comment: " . $unique_id['uniqueid_user_comment'] . "
The OpenLCB Group";
if (!mail_abstraction(array( formatPersonEmail($person) ), $subject, $body)) throw new UserError('Failed to send email.');
$body = "A new OpenLCB unique ID range has been assigned.
You have been notified as you are a moderator.
" . formatUniqueIdHex($unique_id) . "
Delegating organization or person: " . formatPersonName($person) . "
URL: " . $unique_id['uniqueid_url'] . "
Comment: " . $unique_id['uniqueid_user_comment'] . "
UID: " . 'https://' . $_SERVER['HTTP_HOST'] . '/uniqueidrange?uniqueid_id=' . $unique_id['uniqueid_id'] . "
All pending UIDs: " . "https://" . $_SERVER['HTTP_HOST'] . '/uniqueidranges?pending';
if (!mail_abstraction(array_map('formatPersonEmail', $dal->selectModerators()), $subject, $body, array( EMAIL_FROM ))) throw new UserError('Failed to send email.');
$message = 'Your assigned range is: ' . formatUniqueIdHex($unique_id);
} else {
if ($user !== null && $user['person_unapproved_uniqueid_count'] > 0) $message = 'A previous unique id range request is still pending approval.';
}
$dal->commit();
} catch (UserException $e) {
$dal->rollback();
$error = $e->getMessage();
} catch (Exception $e) {
$dal->rollback();
throw $e;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="OpenLCB ID Registry"/>
<link rel="icon" href="../../favicon.ico"/>
<title>Request OpenLCB Unique ID Range</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
<!-- Custom styles for this template -->
<link href="theme.css" rel="stylesheet"/>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<?php
include('navbar.php');
?>
<div class="container-fluid form-request">
<h2 class="form-login-heading">Request OpenLCB Unique ID Range</h2>
<div class="alert alert-info" role="alert">
This page allows you to request a range of 256 OpenLCB Unique IDs for your own use.
<p>
For more information on OpenLCB, please see the <a href="https://openlcb.org/openlcb-and-lcc-documents/layout-command-control-lcc/">documentation page</a>.
For more information on OpenLCB unique ID assignment, please see the current
<a href="https://openlcb.org/wp-content/uploads/2021/08/S-9.7.0.3-UniqueIdentifiers-2021-04-25.pdf">specification</a> and
<a href="https://openlcb.org/wp-content/uploads/2021/08/TN-9.7.0.3-UniqueIdentifiers-2021-04-25.pdf">technical note</a>.
<p>
<ul>
<li>
You must provide a personal name. You may also provide a company name.
In our <a href="uniqueidranges">listing of assigned ranges</a>, we will publish the company name, if provided.
If there is no company name, we will publish the personal name.
</li>
<li>
We will not publish your email address.
</li>
<li>
You may provide a URL, which we will publish if provided.
</li>
<li>
You may provide a comment, which we will publish if provided.
You can use this for company contact information, for example, including an email address.
</li>
</ul>
Unique ID Range requests require moderator approval.
</div>
<?php
if ($error !== null) {
?>
<div class="alert alert-danger">
<a href="" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></a>
<?php echo htmlspecialchars($error); ?>
</div>
<?php
} else if ($message !== null) {
?>
<div class="alert alert-info">
<a href="" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></a>
<?php echo htmlspecialchars($message); ?>
</div>
<?php
} else {
?>
<form method="POST">
<div class="form-group">
<?php
if ($user === null) {
?>
<label for="inputFirstName" class="sr-only">First name</label>
<input type="text" name="first_name" id="inputFirstName" class="form-control input-sm" placeholder="First name" required autofocus/>
<label for="inputLastName" class="sr-only">Last name</label>
<input type="text" name="last_name" id="inputLastName" class="form-control input-sm" placeholder="Last name" required/>
<label for="inputOrganization" class="sr-only">Organization</label>
<input type="text" name="organization" id="inputOrganization" class="form-control input-sm" placeholder="Organization"/>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" id="inputEmail" class="form-control input-sm" placeholder="Email address" required/>
<label for="inputRepeatEmail" class="sr-only">Repeat email address</label>
<input type="email" name="repeat_email" id="inputRepeatEmail" class="form-control input-sm" placeholder="Repeat email address" required/>
<div class="g-recaptcha" data-sitekey="<?php echo htmlspecialchars(RECAPTCHA_SITE_KEY); ?>"></div>
<?php
}
?>
</div>
<div class="form-group">
<label for="inputUrl" class="sr-only">URL</label>
<input type="text" id="inputUrl" name="url" class="form-control input-sm" placeholder="URL"/>
</div>
<div class="form-group">
<label for="imputComment" class="sr-only">Comments</label>
<textarea name="comment" id="imputComment" class="form-control input-sm" placeholder="Comments" oninput="this.rows = 2; this.style.height = '0'; this.style.height = this.scrollHeight + 2 + 18 + 'px';"></textarea>
</div>
<button type="submit" name="send_request" class="btn btn-sm btn-primary btn-block"><span class="glyphicon glyphicon-send"></span> Send request</button>
</form>
<?php
}
?>
</div>
</body>
</html>