Advertisement
Pampour

PUDS - login.php

Feb 3rd, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.97 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. session_start();
  4. /////////////////////////////////////////
  5. ////////PUDS Config Installer////////////
  6. //////Configuration//////////////////////
  7. //Steam API Key//////////////////////////
  8. $_STEAMAPI = "";
  9. /////////////////////////////////////////
  10. require("openid.php");
  11. require("admin.php");
  12. ?>
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  14. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
  15. <head>
  16. <link rel="stylesheet" type="text/css" href="style.css">
  17.     <title>PUDS Donation System</title>
  18. </head>
  19. <body>
  20.     <div id="header">
  21.         <h1>PayPay-ULX Donation System Config Installer</h1>
  22.     </div>
  23. <?php
  24. function curDomain() {
  25.     $pageURL = 'http';
  26.     if ($_SERVER["HTTPS"] == "on") {
  27.         $pageURL .= "s";
  28.     }
  29.         $pageURL .= "://";
  30.     if ($_SERVER["SERVER_PORT"] != "80") {
  31.         $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
  32.     } else {
  33.         $pageURL .= $_SERVER["SERVER_NAME"];
  34.     }
  35.     return $pageURL;
  36. }
  37. //Gets the current Directory
  38. function curDirectory() {
  39.     $current_dir_url = 'http';
  40.     if ($_SERVER["HTTPS"] == "on") {
  41.         $pageURL .= "s";
  42.     }
  43.         $current_dir_url .= "://";
  44.     if ($_SERVER["SERVER_PORT"] != "80") {
  45.         $current_dir_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
  46.     } else {
  47.         $current_dir_url .= $_SERVER["SERVER_NAME"];
  48.     }
  49.     $current_dir_url .= dirname($_SERVER['PHP_SELF']);
  50.     return $current_dir_url;
  51. }
  52. function GetSteamNorm($Steam64) {
  53.     $authserver = bcsub( $Steam64, '76561197960265728' ) & 1;
  54.     //Get the third number of the steamid
  55.     $authid = ( bcsub( $Steam64, '76561197960265728' ) - $authserver ) / 2;
  56.     //Concatenate the STEAM_ prefix and the first number, which is always 0, as well as colons with the other two numbers  
  57.     $steamid = "STEAM_0:$authserver:$authid";
  58.     return $steamid;
  59. }
  60. $curdirectory = curDirectory();
  61. $curdomain = curDomain();
  62.  
  63. if(empty($_STEAMAPI)) {
  64.     echo "<h1>You have not configured PUDS installer correctly! Please edit login.php and put your Steam API Key in the top of the file and try again!</h1>";
  65. } else {
  66.     if (!isset($_SESSION['id'])){
  67.         echo "
  68.             <p>Please login to configure Wullys PayPal-ULX Donation System</p>
  69.             <form action='?login' method='post'>
  70.             <input type='image' src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png'>
  71.             </form>
  72.             <h2>Instructions for use:</h2>
  73.             <p>Sign in through steam. If you are the first user it will make you admin.</p>
  74.             <p>You will be told your not admin, Log out then Log in again to be authenticated as admin.</p>";
  75.    
  76.         try {
  77.             $openid = new LightOpenID($curdomain);
  78.             if(!$openid->mode){
  79.                 if(isset($_GET['login'])) {
  80.                     $openid->identity = 'http://steamcommunity.com/openid/?l=english';
  81.                     // This is forcing english because it has a weird habit of selecting a random language otherwise
  82.                     header('Location: ' . $openid->authUrl());
  83.                 }
  84.             } elseif($openid->mode == 'cancel') {
  85.                 echo 'User has canceled authentication!';
  86.             } else {
  87.                 if($openid->validate()) {
  88.                     $id = $openid->identity;
  89.                     // identity is something like: http://steamcommunity.com/openid/id/76561197960435530
  90.                     // we only care about the unique account ID at the end of the URL.
  91.                     $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
  92.                     preg_match($ptn, $id, $matches);
  93.                     echo "User is logged in (steamID: $matches[1])\n";
  94.                     $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
  95.                     $json_object= file_get_contents($url);
  96.                     $json_decoded = json_decode($json_object);
  97.                     foreach ($json_decoded->response->players as $player){
  98.                         /*echo "                       
  99.                         <br/>Player ID: $player->steamid
  100.                         <br/>Player Name: $player->personaname
  101.                         <br/>Profile URL: $player->profileurl
  102.                         <br/>SmallAvatar: <img src='$player->avatar'/>
  103.                         <br/>MediumAvatar: <img src='$player->avatarmedium'/>
  104.                         <br/>LargeAvatar: <img src='$player->avatarfull'/>";
  105.                         echo "<br/>SmallAvatar: <img src='$player->avatar'/>";
  106.                         */                     
  107.                         $steam64 = $player->steamid;
  108.                         $steamID = GetSteamNorm($steam64);
  109.  
  110.                         //Get players ingame name
  111.                         $_SESSION['id'] = $steam64;
  112.                         $_SESSION['sid'] = $steamID;
  113.                         $_SESSION['name'] = $player->personaname;
  114.                         $_SESSION['mAvatar'] = $player->avatarmedium;
  115.                         $_SESSION['steamAPI'] = $_STEAMAPI;
  116.                         if(empty($admin)){         
  117.                             $str = "<?php \$admin = '$steam64';?>";
  118.                             $fp = FOPEN("admin.php", "w");
  119.                             FWRITE($fp, $str);
  120.                             FCLOSE($fp);           
  121.                             echo "<p> Successfully made $friendlyName an admin!</p>";
  122.                             header("Location: $curdirectory/logout.php");                          
  123.                         }                          
  124.                         if($steam64 == $admin){
  125.                             $_SESSION['admin'] = True;
  126.                         } else {
  127.                             $_SESSION['admin'] = False;
  128.                         }
  129.                     }
  130.                     header("Location: $curdirectory/install.php");
  131.                 }      
  132.             }
  133.         } catch(ErrorException $e) {
  134.             echo $e->getMessage();
  135.         }
  136.     } else {
  137.        
  138.     }
  139. }
  140. ?>
  141.     </body>
  142. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement