forked from joshpangell/single-use
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.php
65 lines (59 loc) · 1.32 KB
/
generate.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
<?php
/**
* This file creates the single use download link
* The query string should be the password (which is set in variables.php)
* If the password fails, then 404 is rendered
*
* Expects: generate.php?1234
*/
include("variables.php");
// Grab the query string as a password
$password = trim($_SERVER['QUERY_STRING']);
/*
* Verify the admin password (in variables.php)
*/
if($password == ADMIN_PASSWORD) {
// Create a new key
$new = uniqid('key',TRUE);
/*
* Create a protected directory to store keys in
*/
if(!is_dir('keys')) {
mkdir('keys');
$file = fopen('keys/.htaccess','w');
fwrite($file,"Order allow,deny\nDeny from all");
fclose($file);
}
/*
* Write the key key to the keys list
*/
$file = fopen('keys/keys','a');
fwrite($file,"{$new}\n");
fclose($file);
?>
<html>
<head>
<title>Download created</title>
<style>
nl {
font-family: monospace
}
</style>
</head>
<body>
<h1>Download key created</h1>
Your new single-use download link:<br>
<nl><?php
echo "http://" . $_SERVER['HTTP_HOST'] . DOWNLOAD_PATH . "?" . $new;
?></nl>
</body>
</html>
<?php
} else {
/*
* Someone stumbled upon this link with the wrong password
* Fake a 404 so it does not look like this is a correct path
*/
header("HTTP/1.0 404 Not Found");
}
?>