-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCodeForEmail.php
More file actions
40 lines (33 loc) · 1.61 KB
/
Copy pathgetCodeForEmail.php
File metadata and controls
40 lines (33 loc) · 1.61 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
<?php
// ============================================================================
// SiVote Home Sender — look up one voter's code
// ----------------------------------------------------------------------------
// Prints the code and link for a single voter from the SENSITIVE_MAPPED_CODES
// file, so you can give it to them another way (e.g. read it out) WITHOUT
// seeing everyone else's. Read-only — it does not send anything.
// This file is intentionally self-contained.
//
// Run from this folder:
// php getCodeForEmail.php --email=name@example.org \
// --cache_file=SENSITIVE_MAPPED_CODES_....csv
// ============================================================================
// --- 1. Read and check the command-line options ---
$options = getopt('', ['email:', 'cache_file:']);
if (empty($options['email']) || empty($options['cache_file'])) {
die('Usage: php getCodeForEmail.php --email=name@example.org --cache_file=SENSITIVE_MAPPED_CODES_....csv' . PHP_EOL);
}
if (!file_exists($options['cache_file'])) {
die("Cache file does not exist." . PHP_EOL);
}
// --- 2. Load the local record (each line is "email,code,url") ---
$cacheData = array_map(fn($line) => str_getcsv($line, ',', '"', ''), file($options['cache_file']));
// --- 3. Find the voter's row and print just their code + link ---
foreach ($cacheData as $row) {
if (($row[0] ?? null) === $options['email']) {
echo "Email: {$row[0]}" . PHP_EOL;
echo "Code: {$row[1]}" . PHP_EOL;
echo "Link: {$row[2]}" . PHP_EOL;
exit(0);
}
}
echo "No entry for {$options['email']} in the cache file." . PHP_EOL;