-
Notifications
You must be signed in to change notification settings - Fork 0
/
genfake.php
72 lines (53 loc) · 1.95 KB
/
genfake.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
<?php
?>
<HTML><BODY>
<?php
function get_random_string($valid_chars, $length)
{
// start with an empty random string
$random_string = "";
$my_domain = "domain.com";
// count the number of chars in the valid chars string so we know how many choices we have
$num_valid_chars = strlen($valid_chars);
// repeat the steps until we've created a string of the right length
for ($i = 0; $i < $length; $i++)
{
// pick a random number from 1 up to the number of valid chars
$random_pick = mt_rand(1, $num_valid_chars);
// take the random character out of the string of valid chars
// subtract 1 from $random_pick because strings are indexed starting at 0, and we started picking at 1
$random_char = $valid_chars[$random_pick-1];
// add the randomly-chosen char onto the end of our string so far
$random_string .= $random_char;
}
// return our finished random string
return $random_string;
}
$dbh = new PDO("mysql:host=127.0.0.1;dbname=valias","valias", "dbpass");
//generate random string
$rand=get_random_string('abcdefghijklmnopqrstuvwxyz1234567890',6).$my_domain;
//echo "Random: $rand\n";
//insert string into database with given email address
$email = $_GET["email"];
$note = $_GET["note"];
$days = $_GET["days"];
$daysdb = $days." 0:0:0";
//echo "Dest: $email\n";
$stmt = $dbh->prepare("insert into mxaliases (alias,forw_addr,valid_thru) values (:rand,:email,".
"addtime(current_timestamp,:days))");
$stmt->bindParam(":rand",$rand);
$stmt->bindParam(":email",$email);
$stmt->bindParam(":days",$daysdb);
if (!$stmt->execute())
{
echo "PDO Error 1.1:\n";
print_r($stmt->errorInfo());
exit;
}
echo "<p>$rand now forwards to $email. This will be deleted in $days days.</p>\n";
mail($email, "Fake email address generated",
"$rand now forwards to this email address and will be ".
"deleted $days days from now. Note: $note",
"From: webmaster@$my_domain\n" );
?>
</body></html>