diff --git a/check.php b/check.php new file mode 100644 index 0000000..4553a06 --- /dev/null +++ b/check.php @@ -0,0 +1,12 @@ +getMessage()); + } + header('Location: index.php'); + ?> \ No newline at end of file diff --git a/index.php b/index.php index de155b0..c1df4f1 100644 --- a/index.php +++ b/index.php @@ -21,6 +21,12 @@ if (isset($_GET['ajax'])) $offset = $_GET['offset']; } +if (isset($_GET['subscriber_logout'])){ + setcookie('tg_user', ''); + setcookie('referer', '', time() - 3600); + header('Location: index.php'); +} + Template::render_header("Status"); ?>
diff --git a/telegram.php b/telegram.php index f1ac554..bf25641 100644 --- a/telegram.php +++ b/telegram.php @@ -18,4 +18,46 @@ function getTelegramUserData() { return $auth_data; } return false; -} \ No newline at end of file +} +/** + * Check if data is from telegram + * + * This checks if the data provides is from telegram. It includes a Fix for firefox + * + * @param mixed $auth_data The Authentication Data + * + * @return $auth_data + * +*/ +function checkTelegramAuthorization($auth_data) { + $check_hash = $auth_data['hash']; + unset($auth_data['hash']); + $data_check_arr = []; + foreach ($auth_data as $key => $value) { + // $data_check_arr[] = $key . '=' . $value; + $data_check_arr[] = $key . '=' . str_replace('https:/t', 'https://t', $value); + } + sort($data_check_arr); + $data_check_string = implode("\n", $data_check_arr); + $secret_key = hash('sha256', TG_BOT_API_TOKEN, true); + $hash = hash_hmac('sha256', $data_check_string, $secret_key); + if (strcmp($hash, $check_hash) !== 0) { + throw new Exception('Data is NOT from Telegram'); + } + if ((time() - $auth_data['auth_date']) > 86400) { + throw new Exception('Data is outdated'); + } + return $auth_data; + } + + +/** + * Save telegram userdata + * + * Save the telegram user data in a cookie + * @return void + */ +function saveTelegramUserData($auth_data) { + $auth_data_json = json_encode($auth_data); + setcookie('tg_user', $auth_data_json); + } \ No newline at end of file diff --git a/template.php b/template.php index 286ac36..57a2178 100644 --- a/template.php +++ b/template.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD