forked from joshf/Indication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.php
More file actions
171 lines (149 loc) · 7.26 KB
/
get.php
File metadata and controls
171 lines (149 loc) · 7.26 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
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
<?php
//Indication, Copyright Josh Fradley (http://github.com/joshf/Indication)
ob_start();
if (!file_exists("config.php")) {
die("Error: Config file not found! Please contact the site administrator.");
}
require_once("config.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Indication</title>
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
if (THEME == "default") {
echo "<link href=\"resources/bootstrap/css/bootstrap.css\" type=\"text/css\" rel=\"stylesheet\">\n";
} else {
echo "<link href=\"//netdna.bootstrapcdn.com/bootswatch/2.3.2/" . THEME . "/bootstrap.min.css\" type=\"text/css\" rel=\"stylesheet\">\n";
}
?>
<style type="text/css">
body {
padding-top: 60px;
}
</style>
<link href="resources/bootstrap/css/bootstrap-responsive.css" type="text/css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- Nav start -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Indication</a>
</div>
</div>
</div>
<!-- Nav end -->
<!-- Content start -->
<div class="container">
<div class="page-header">
<h1><?php echo WEBSITE; ?></h1>
</div>
<?php
//Connect to database
@$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
die("<div class=\"alert alert-error\"><h4 class=\"alert-heading\">Error</h4><p>Could not connect to database (" . mysql_error() . "). Check your database settings are correct.</p><p><a class=\"btn btn-danger\" href=\"javascript:history.go(-1)\">Go Back</a></p></div></div></body></html>");
}
//Check database exists
$does_db_exist = mysql_select_db(DB_NAME, $con);
if (!$does_db_exist) {
die("<div class=\"alert alert-error\"><h4 class=\"alert-heading\">Error</h4><p>Database does not exist (" . mysql_error() . "). Check your database settings are correct.</p><p><a class=\"btn btn-danger\" href=\"javascript:history.go(-1)\">Go Back</a></p></div></div></body></html>");
}
//Get the ID from $_GET OR $_POST
if (isset($_GET["id"])) {
$id = mysql_real_escape_string($_GET["id"]);
} elseif (isset($_POST["id"])) {
$id = mysql_real_escape_string($_POST["id"]);
} else {
die("<div class=\"alert alert-error\"><h4 class=\"alert-heading\">Error</h4><p>ID cannot be blank.</p><p><a class=\"btn btn-danger\" href=\"javascript:history.go(-1)\">Go Back</a></p></div></div></body></html>");
}
//Check if ID exists
$getinfo = mysql_query("SELECT name, url, count FROM Data WHERE id = \"$id\"");
$getinforesult = mysql_fetch_assoc($getinfo);
if ($getinforesult == 0) {
die("<div class=\"alert alert-error\"><h4 class=\"alert-heading\">Error</h4><p>ID does not exist.</p><p><a class=\"btn btn-danger\" href=\"javascript:history.go(-1)\">Go Back</a></p></div></div></body></html>");
}
//Cookies don't like dots
$idclean = str_replace(".", "_", $id);
//Ignore admin counts if setting has been enabled
session_start();
if (IGNORE_ADMIN_STATE == "Enabled" && isset($_SESSION["is_logged_in_" . UNIQUE_KEY . ""])) {
echo "<div class=\"alert alert-info\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button><b>Info:</b> Currently logged in, downloads will not be counted.</div>";
} else {
if (COUNT_UNIQUE_ONLY_STATE == "Enabled") {
if (!isset($_COOKIE["indicationhasdownloaded_$idclean"])) {
mysql_query("UPDATE Data SET count = count+1 WHERE id = \"$id\"");
setcookie("indicationhasdownloaded_$idclean", "True", time()+3600*COUNT_UNIQUE_ONLY_TIME);
}
} else {
mysql_query("UPDATE Data SET count = count+1 WHERE id = \"$id\"");
}
}
//Check if download is password protected
$checkifprotected = mysql_query("SELECT protect, password FROM Data WHERE id = \"$id\"");
$checkifprotectedresult = mysql_fetch_assoc($checkifprotected);
//Check if we should show ads
$checkifadsshow = mysql_query("SELECT showads FROM Data WHERE id = \"$id\"");
$checkifadsshowresult = mysql_fetch_assoc($checkifadsshow);
if ($checkifprotectedresult["protect"] == "1") {
$case = "passwordprotected";
}
if ($checkifadsshowresult["showads"] == "1") {
$case = "showads";
}
if ($checkifprotectedresult["protect"] == "1" && $checkifadsshowresult["showads"] == "1") {
$case = "passwordprotectedandshowads";
}
if ($checkifprotectedresult["protect"] != "1" && $checkifadsshowresult["showads"] != "1") {
$case = "normal";
}
if (isset($_POST["password"])) {
if (sha1($_POST["password"]) == $checkifprotectedresult["password"]) {
$case = "passwordcorrect";
} else {
$case = "passwordincorrect";
}
}
switch ($case) {
case "showads":
$adcode = htmlspecialchars_decode(AD_CODE);
echo "<h3>" . $getinforesult["name"] . " (downloaded " . $getinforesult["count"] . " times)</h3><div class=\"well\">$adcode</div><fieldset><div class=\"form-actions\"><a class=\"btn btn-primary\" href=\"" . $getinforesult["url"] . "\">Get Download</a><a class=\"btn pull-right\" href=\"javascript:history.go(-1)\">Go Back</a></div></fieldset>";
break;
case "passwordprotected":
echo "<h3>" . $getinforesult["name"] . " (downloaded " . $getinforesult["count"] . " times)</h3><p>This download is password protected, please enter the password you were given</p><form method=\"post\"><fieldset><div class=\"control-group\"><label class=\"control-label\" for=\"password\">Password</label><div class=\"controls\"><input type=\"password\" id=\"password\" name=\"password\" placeholder=\"Password...\"></div></div><div class=\"form-actions\"><button type=\"submit\" class=\"btn btn-primary\">Get Download</button><a class=\"btn pull-right\" href=\"javascript:history.go(-1)\">Go Back</a></div></fieldset></form>";
break;
case "normal":
header("Location: " . $getinforesult["url"] . "");
exit;
break;
case "passwordprotectedandshowads":
$adcode = htmlspecialchars_decode(AD_CODE);
echo "<h3>" . $getinforesult["name"] . " (downloaded " . $getinforesult["count"] . " times)</h3><div class=\"well\">$adcode</div><p>This download is password protected, please enter the password you were given.</p><form method=\"post\"><fieldset><div class=\"control-group\"><label class=\"control-label\" for=\"password\">Password</label><div class=\"controls\"><input type=\"password\" id=\"password\" name=\"password\" placeholder=\"Password...\"></div></div><div class=\"form-actions\"><button type=\"submit\" class=\"btn btn-primary\">Get Download</button><a class=\"btn pull-right\" href=\"javascript:history.go(-1)\">Go Back</a></div></fieldset></form>";
break;
case "passwordcorrect":
header("Location: " . $getinforesult["url"] . "");
exit;
break;
case "passwordincorrect":
echo "<div class=\"alert alert-error\"><h4 class=\"alert-heading\">Error</h4><p>Incorrect password.</p><p><a class=\"btn btn-danger\" href=\"javascript:history.go(-1)\">Go Back</a></p></div>";
break;
}
ob_end_flush();
mysql_close($con);
?>
</div>
<!-- Content end -->
<!-- Javascript start -->
<script src="resources/jquery.js"></script>
<script src="resources/bootstrap/js/bootstrap.js"></script>
<!-- Javascript end -->
</body>
</html>