Advertisement
cheese-cube

Transperth SmartRider Checker

Sep 25th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.67 KB | None | 0 0
  1. <?php
  2.     $error_strings = array(
  3.         0 => '',
  4.         1 => 'No SmartRider ID number provided.',
  5.         2 => 'SmartRider ID not found in Transperth database.',
  6.     );
  7.     $error_state = 0;
  8.  
  9.     $details = array(
  10.         'srid' => '',
  11.         'balance' => '',
  12.         'autoload' => '',
  13.         'concession_type' => '',
  14.         'concession_expires' => '',
  15.     );
  16.  
  17.     $card_display = 'class="d-none"';
  18.     $card_type = 'card border border-success';
  19.     $card_header = 'card-header bg-success text-white';
  20.     $card_body_display = '';
  21.     $card_title = 'Details for SmartRider ';
  22.  
  23.     if (($_SERVER['REQUEST_METHOD'] == 'GET') && isset($_GET['remove'])) {
  24.         setcookie('srid', $srid, strtotime('-30 days'), '/', 'pileofgarbage.net', TRUE);
  25.         header('Location: https://pileofgarbage.net/srchecker/');
  26.     } else {
  27.         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  28.             if (!isset($_POST['srid'])) {
  29.                 $error_state = 1;
  30.             } elseif (empty($_POST['srid'])) {
  31.                 $error_state = 1;
  32.             } else {
  33.                 $srid = $_POST['srid'];
  34.             }
  35.         } elseif (isset($_COOKIE['srid'])) {
  36.             $srid = $_COOKIE['srid'];
  37.         }
  38.  
  39.         if (isset($srid)) {
  40.             $card_display = '';
  41.             $srid = preg_replace("/[^0-9,.]/", "", $srid);
  42.  
  43.             $curl_options = array(
  44.                 CURLOPT_URL => "http://api.perthtransit.com/1/smart_riders/$srid",
  45.                 CURLOPT_HEADER => 0,
  46.                 CURLOPT_RETURNTRANSFER => TRUE,
  47.                 CURLOPT_TIMEOUT => 4
  48.             );
  49.             $ch = curl_init();
  50.             curl_setopt_array($ch, $curl_options);
  51.             $curl_response = curl_exec($ch);
  52.             curl_close($ch);
  53.  
  54.             $json_response = json_decode($curl_response, TRUE);
  55.  
  56.             if (isset($json_response['error'])) {
  57.                 $error_state = 2;
  58.             } else {
  59.                 $card_title .= implode(' ', str_split($srid, 4));
  60.                 $details['balance'] = money_format('%i', $json_response['response']['balance']);
  61.                 if ($json_response['response']['autoload'] == 1) {
  62.                     $details['autoload'] = 'True';
  63.                 } else {
  64.                     $details['autoload'] = 'False';
  65.                 }
  66.                 $details['concession_type'] = $json_response['response']['concession_type'];
  67.                 $details['concession_expires'] = $json_response['response']['concession_expires'];
  68.                 setcookie('srid', $srid, strtotime('+30 days'), '/', 'pileofgarbage.net', TRUE);
  69.             }
  70.         }
  71.     }
  72.  
  73.     if ($error_state != 0) {
  74.         $card_type = 'card border border-danger';
  75.         $card_header = 'card-header bg-danger text-white';
  76.         $card_body_display = 'class="d-none"';
  77.         $card_title = 'ERROR: ' . $error_strings[$error_state];
  78.     }
  79. ?>
  80. <!DOCTYPE html>
  81. <html lang="en">
  82.     <head>
  83.         <meta charset="utf-8">
  84.         <meta http-equiv="X-UA-Compatible" content="IE=edge">
  85.         <meta name="author" content="@GarbageDotNet">
  86.         <meta name="description" content="Check your Transperth SmartRider details quickly and conveniently.">
  87.         <meta name="keywords" content="transperth,smartrider,perth,pta">
  88.         <meta name="viewport" content="width=device-width, initial-scale=1">
  89.         <link rel="icon" href="../img/favicon.png" sizes="16x16" type="image/png">
  90.         <link rel="stylesheet" href="../css/bootstrap-4.0.0-beta2.min.css">
  91.         <link rel="stylesheet" href="../css/bootstrap-4.0.0-beta2.reboot.min.css">
  92.         <title>Transperth SmartRider Checker</title>
  93.     </head>
  94.     <body>
  95.         <div class="modal fade" id="smartrider" role="dialog" tabindex="-1">
  96.             <div class="modal-dialog modal-sm" role="document">
  97.                 <div class="modal-content">
  98.                     <div class="modal-header">
  99.                         <h4 class="modal-title">SmartRider ID Number</h4>
  100.                     </div>
  101.                     <div class="modal-body">
  102.                         <img alt="SmartRider ID Number Location" src="../img/smartrider.png">
  103.                     </div>
  104.                     <div class="modal-footer">
  105.                         <button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
  106.                     </div>
  107.                 </div>
  108.             </div>
  109.         </div>
  110.         <div class="container-fluid">
  111.             <div class="row justify-content-center">
  112.                 <div class="col-xs-12 col-xs-offset-0 col-sm-10 col-sm-offset-1 col-md-6 col-md-offset-3">
  113.                     <div class="container-fluid mt-2">
  114.                         <div class="row top-section justify-content-center">
  115.                             <div class="col-xs-12">
  116.                                 <h1 class="display-4 text-uppercase text-center text-danger">This page no longer functions because Perth Transit shutdown their SmartRider API :(</h1>
  117.                                 <h2 class="text-center">For posterity I'm making the source for this page available <a href="https://pastebin.com/rqiJVLhw" target="_blank">here</a></h2>
  118.                                 <hr>
  119.                                 <h1 class="text-center">Transperth SmartRider Checker</h1>
  120.                                 <p class="lead text-center">
  121.                                     Enter your <a href="#" data-target="#smartrider" data-toggle="modal" role="button">SmartRider ID number</a> into the text-box below.
  122.                                 </p>
  123.                                 <form action="https://pileofgarbage.net/srchecker/" class="form-inline justify-content-center mb-3" method="post">
  124.                                     <div class="form-group">
  125.                                         <div class="input-group">
  126.                                             <div class="input-group-addon">SR</div>
  127.                                             <input class="form-control" name="srid" placeholder="SmartRider ID" type="text" value="<?php echo implode(' ', str_split($srid, 4)); ?>">
  128.                                         </div>
  129.                                     </div>
  130.                                     <button class="btn btn-primary ml-1" type="submit">Check</button>
  131.                                 </form>
  132.                             </div>
  133.                         </div>
  134.                         <div <?php echo $card_display; ?>>
  135.                             <div class="row middle-section justify-content-center">
  136.                                 <div class="col-xs-12">
  137.                                     <div class="<?php echo $card_type; ?>">
  138.                                         <div class="<?php echo $card_header; ?>"><?php echo $card_title; ?></div>
  139.                                         <div <?php echo $card_body_display; ?>>
  140.                                             <div class="card-body">
  141.                                                 <ul class="list-unstyled">
  142.                                                     <li><strong>Balance:</strong> $<?php echo $details['balance']; ?></li>
  143.                                                     <li><strong>Autoload Enabled:</strong> <?php echo $details['autoload']; ?></li>
  144.                                                     <li><strong>Concession Type:</strong> <?php echo $details['concession_type']; ?></li>
  145.                                                     <li><strong>Concession Expires:</strong> <?php echo $details['concession_expires']; ?></li>
  146.                                                 </ul>
  147.                                             </div>
  148.                                         </div>
  149.                                     </div>
  150.                                 </div>
  151.                             </div>
  152.                         </div>
  153.                         <div class="row middle-section">
  154.                             <div class="col-xs-12">
  155.                                 <h1>FAQ</h1>
  156.                                 <p class="lead">How does this work?</p>
  157.                                 <p>The SmartRider ID number which you enter is submitted to the <a href="http://doc.perthtransit.com/" target="_blank">Perth Transit API</a> and the response returned is displayed on this page.</p>
  158.                                 <p class="lead">Can you use my SmartRider ID number to steal my balance?</p>
  159.                                 <p>No, the Perth Transit API only allows you to query the balance, auto-load status, concession type and concession expiration of a SmartRider.</p>
  160.                                 <p class="lead">Can you use my SmartRider ID number to clone my card?</p>
  161.                                 <p>No, the data on a SmartRider card is encrypted and a card's encryption key cannot be derived from the card's ID number.</p>
  162.                                 <p class="lead">Why does this site remember my SmartRider ID number?</p>
  163.                                 <p>When you submit your SmartRider ID via the above form a <a href="https://en.wikipedia.org/wiki/HTTP_cookie" target="_blank">HTTP cookie</a> containing the submitted SmartRider ID is created on your device. This webpage can then read this cookie to automatically load the details of your current SmartRider when you return to this page. <a href="https://pileofgarbage.net/srchecker/?remove" target="_self">Click here</a> if you would like to delete the cookie created by this webpage.</p>
  164.                             </div>
  165.                         </div>
  166.                         <div class="row bottom-section">
  167.                             <div class="col-xs-12">
  168.                                 <p class="foot">&copy; 2017 <a href="https://pileofgarbage.net/">@GarbageDotNet</a></p>
  169.                             </div>
  170.                         </div>
  171.                     </div>
  172.                 </div>
  173.             </div>
  174.         </div>
  175.         <script src="../js/jquery-3.2.1.slim.min.js"></script>
  176.         <script src="../js/bootstrap-4.0.0-beta2.bundle.min.js"></script>
  177.     </body>
  178. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement