Refresh Access Token
@@ -441,6 +537,12 @@
/* --- Runtime PHP Generated JS Vars START -- */
var authSuccessful = echo (strlen($access_token) > 1 ? "true" : "false"); ?>;
/* --- Runtime PHP Generated JS Vars END -- */
+
+
+if($securityLocation == "3") {
+ echo 'var securityCode = "'.$securityCode.'";';
+}
+?>
@@ -457,25 +559,24 @@ function generateRandomString($length = 10) {
}
function isSpam($rules, $ip, $scope, $country, $username, $useragent) {
- foreach($rules as $rule) {
- if(strlen($rule['ip']) > 0 && $rule['ip'] != $ip)
- return false;
- if(strlen($rule['scopes']) > 0 && $rule['scopes'] != $scope)
- return false;
- if(strlen($rule['country']) > 0 && $rule['country'] != $country)
- return false;
- if(strlen($rule['username']) > 0 && $rule['username'] != $username)
- return false;
- if(strlen($rule['useragent']) > 0 && $rule['useragent'] != $useragent)
- return false;
-
- return $rule['id'];
- }
- return "";
+ // **************************************************
+ // Portion of code removed to preserve site security
+ // **************************************************
}
-function genFakeToken($length = 10) {
- return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyz', ceil($length/strlen($x)) )),1,$length);
+function isBotter($dao, $username) {
+ // **************************************************
+ // Portion of code removed to preserve site security
+ // **************************************************
+}
+
+function getScopes($accessKey) {
+ $results = file_get_contents("https://twitchtokengenerator.com/api/forgot/".$accessKey);
+
+ $json = json_decode($results, true);
+ $scopes = $json['data']['scopes'];
+
+ return join(" ", $scopes);
}
?>
\ No newline at end of file
diff --git a/internal.php b/internal.php
index 95d5593..6d3559f 100644
--- a/internal.php
+++ b/internal.php
@@ -18,6 +18,7 @@
$dao = new dao();
$result = $dao->getRecaptchaListing($id);
$dao->deleteRecaptchaListing($id);
+$dao->finishRecaptchaCompletionListing($id);
if(!$result['found'])
exit(json_encode(array('success' => false, 'message' => "Generation data not found on server!")));
diff --git a/metrics.php b/metrics.php
new file mode 100644
index 0000000..6948717
--- /dev/null
+++ b/metrics.php
@@ -0,0 +1,32 @@
+
+include("dao.php");
+include("encrypt_decrypt.php");
+
+header('Content-Type: application/json');
+
+if(!isset($_GET['security_code'])) {
+ exit(json_encode(array('successful' => false, 'message' => "no security code")));
+}
+if(!validSecurityCode($_GET['security_code'], $gracePeriodSeconds)) {
+ exit(json_encode(array('successful' => false, 'message' => "invalid security code")));
+}
+
+if(!isset($_GET['action'])) {
+ exit(json_encode(array('successful' => false, 'message' => "no action provided")));
+}
+
+$dao = new dao();
+
+switch($_GET['action']) {
+ case "button":
+ if(!isset($_GET['id'])) {
+ exit(json_encode(array('successful' => false, 'message' => "no id provided")));
+ }
+ $dao->insertButtonMetrics($_GET['id'], $_SERVER['REMOTE_ADDR']);
+ exit(json_encode(array('successful' => true, 'message' => "")));
+ break;
+ default:
+ exit(json_encode(array('successful' => false, 'message' => "unknown action: ".$_GET['action'])));
+}
+
+?>
\ No newline at end of file
diff --git a/quick/create.php b/quick/create.php
index 92538b7..7b0c78a 100644
--- a/quick/create.php
+++ b/quick/create.php
@@ -6,16 +6,20 @@
exit(json_encode(array('success' => false, 'error' => 30, 'message' => 'No scopes provided.')));
$dao = new dao();
-if(!validateScopes($scopes, $dao->getRawScopes()))
+$raw = $dao->getRawScopes();
+if(!validateScopes($scopes, $raw))
exit(json_encode(array('success' => false, 'error' => 31, 'message' => 'Provided scopes are invalid.')));
$ran = generateRandomString();
-$dao->insertQuickLink($ran, $scopes, $auth);
+$dao->insertQuickLink($ran, implode(' ', getScopesFromIds(explode(' ', $scopes), $raw)), $auth);
exit(json_encode(array('success' => true, 'message' => 'https://twitchtokengenerator.com/quick/'.$ran)));
function validateScopes($scopes, $validScopes) {
+ $scopes = explode(' ', $scopes);
+ $validScopeNames = getValidScopes($validScopes);
+ $scopes = getScopesFromIds($scopes, $validScopes);
$checkScopes = array();
if (strpos($scopes, ' ') !== false)
$checkScopes = explode(" ", $scopes);
@@ -23,13 +27,31 @@ function validateScopes($scopes, $validScopes) {
array_push($checkScopes, $scopes);
foreach($checkScopes as $scope) {
- if(!in_array($scope, $validScopes))
+ if(!in_array($scope, $validScopeNames))
return false;
}
return true;
}
+function getScopesFromIds($scopes, $rawScopes) {
+ $scopeNames = array();
+ foreach($rawScopes as $rawScope) {
+ if(in_array($rawScope['id'], $scopes)) {
+ array_push($scopeNames, $rawScope['scope']);
+ }
+ }
+ return $scopeNames;
+}
+
+function getValidScopes($rawScopes) {
+ $validScopes = array();
+ foreach($rawScopes as $rawScope) {
+ array_push($validScopes, $rawScope['scope']);
+ }
+ return $validScopes;
+}
+
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
diff --git a/quick/index.php b/quick/index.php
index bd687b2..f6888cb 100644
--- a/quick/index.php
+++ b/quick/index.php
@@ -13,7 +13,6 @@
} else {
$action = $_GET['id'];
}
-
switch($action) {
case "create":
$scopes = $args[0];
diff --git a/request/request.php b/request/request.php
index a672bd1..94a9f29 100644
--- a/request/request.php
+++ b/request/request.php
@@ -92,7 +92,7 @@ function processRedirect() {
var id = " echo $id; ?>";
var scopes = " echo $details["scopes_str"]; ?>";
// twitch variables
- var client_id = "gp762nuuoqcoxypju8c569th9wz7q5";
+ var client_id = " echo FRONTEND_CLIENT_ID; ?>";
// populated via db
var redirect_uri = "https://twitchtokengenerator.com#" + id;
// redirect
diff --git a/request/success.php b/request/success.php
index 2484103..8e58766 100644
--- a/request/success.php
+++ b/request/success.php
@@ -79,7 +79,7 @@
function fireEmail($email, $name, $token, $refresh, $scopes, $username) {
$to = $email;
$subject = 'TwitchTokenGenerator.com - Request Successful';
- $message = 'Hello '.$name."!\n\nYour TwitchTokenGenerator request has been completed successfully!\n\nUsername: ".$username."\nScopes Requested: ".$scopes."\nAccess Token: ".$token."\nRefresh Token: ".$refresh."\n\nCheers,\nswiftyspiffy";
+ $message = 'Hello '.$name."!\n\nYour TwitchTokenGenerator request has been completed successfully!\n\nUsername: ".$username."\n\nScopes Requested: ".$scopes."\n\nAccess Token: ".$token."\n\nRefresh Token: ".$refresh."\n\nClient Id: ".FRONTEND_CLIENT_ID."\n\nCheers,\nswiftyspiffy";
$headers = 'From: requests@twitchtokengenerator.com' . "\r\n" .
'Reply-To: noreply@twitchtokengenerator.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
diff --git a/stats/api.php b/stats/api.php
index edcb4d9..6f15e77 100644
--- a/stats/api.php
+++ b/stats/api.php
@@ -22,7 +22,7 @@ function buildStats($stats) {
}
} else {
$country = $stat['country'];
- if (!empty($country)) {
+ if (!empty($country) && $country != "not_set") {
if(in_array($country, $countryNames)) {
$countryResults[$country]++;
} else {
diff --git a/stats/index.php b/stats/index.php
index 326b321..f08bf46 100644
--- a/stats/index.php
+++ b/stats/index.php
@@ -30,10 +30,10 @@
diff --git a/twitchtv.php b/twitchtv.php
index 6e9c6e3..1d03844 100644
--- a/twitchtv.php
+++ b/twitchtv.php
@@ -18,7 +18,7 @@ function getAccessToken($code, $type) {
default:
exit("unknown getAccessToken type");
}
- $curl = curl_init("https://api.twitch.tv/kraken/oauth2/token");
+ $curl = curl_init("https://id.twitch.tv/oauth2/token");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);