-
Notifications
You must be signed in to change notification settings - Fork 1
/
get.php
111 lines (101 loc) · 3.36 KB
/
get.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
<?php
include '/guitar3/home/www/imp/mysql_connect.php';
function get_hostname() {
return gethostbyaddr($_SERVER["REMOTE_ADDR"]);
}
function pkg_url($pkg) {
return "https://integrativemodeling.org/$pkg";
}
function redirect($pkg) {
header("HTTP/1.1 307 Temporary Redirect");
header("Location: " . pkg_url($pkg));
exit(0);
}
function get_db_details($db, $host) {
$query = "SELECT name,institution FROM addresses WHERE hostname = '"
. $db->real_escape_string($host) . "'";
$result = $db->query($query);
if (!$result) { return NULL; }
$line = $result->fetch_array(MYSQLI_ASSOC);
$result->close();
return $line;
}
function missing_details($details) {
if (!$details) {
return true;
} else {
return (!$details['name'] and !$details['institution']);
}
}
function add_db_details($db, $host, $details, $known) {
if (missing_details($details)) {
return false;
}
if ($known) {
$query = "UPDATE addresses SET name='"
. $db->real_escape_string($details['name']) . "', " .
"institution='"
. $db->real_escape_string($details['institution']) .
"' WHERE hostname='"
. $db->real_escape_string($host) . "'";
} else {
$query = "INSERT INTO addresses SET name='"
. $db->real_escape_string($details['name']) . "', " .
"institution='"
. $db->real_escape_string($details['institution']) .
"', hostname='"
. $db->real_escape_string($host) . "', " .
"first_download_utc=UTC_TIMESTAMP()";
}
$db->query($query);
return true;
}
function print_form($pkg) {
print "<h1>Download</h1>\n";
print <<<END
<div id="download">
<p>
Please provide us with your name and institution or company.
</p>
<p>
The development of IMP relies on funding agencies, and we need accurate
information on the usage of IMP in order to secure future funding. This
information will not be used for any other purpose, and we will try only to
ask you for this information once per unique IP address.
</p>
END;
print "<form method=\"get\" action=\"" . $_SERVER['REQUEST_URI'] .
"\" enctype=\"multipart/form-data\">\n";
print "<table>\n<tr>\n";
print "<td>Name:</td>\n";
print "<td><input type=\"text\" name=\"name\" size=\"50\" /></td></tr>\n";
print "<tr><td>Institution/company:</td>\n";
print "<td><input type=\"text\" name=\"institution\" size=\"50\" />";
print "</td></tr></table>\n";
print "<input type=\"hidden\" name=\"pkg\" value=\"$pkg\" />\n";
print "<p><input type=\"submit\" value=\"DOWNLOAD\" /></p>\n";
print "</form>\n\n";
print "<p><a class=\"directdownload\" href=\""
. pkg_url($pkg)
. "\">Download without providing this information</a></p>\n";
print "</div>\n";
}
if (!array_key_exists('pkg', $_GET) || !$_GET['pkg']) {
print_page_header();
print "<p>Missing 'pkg' parameter.</p>\n";
print_page_footer();
exit(0);
}
$db = connect_db();
$host = get_hostname();
$known = get_db_details($db, $host);
if (!add_db_details($db, $host, $_GET, $known) and missing_details($known)) {
print_page_header();
print_form($_GET['pkg']);
print_page_footer();
exit(0);
}
if ($_GET['pkg']) {
redirect($_GET['pkg']);
}
?>