Advertisement
aaaaaa123456789

Prize awarder for bls

Dec 25th, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.00 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'ptempl.php';
  4.  
  5. function ob_kill () {
  6.   $ob = ob_get_contents();
  7.   ob_end_clean();
  8.   return $ob;
  9. }
  10.  
  11. ob_start();
  12. // initial page follows
  13. ?>
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  15. <html>
  16.   <head>
  17.     <title>Prize awarder login</title>
  18.   </head>
  19.   <body>
  20.     <center>
  21.     <h4>Please enter the following cookie information:</h4>
  22.     <!-- ##form: location -->
  23.     <form action="$$location" method="post">
  24.       <input type="hidden" name="mode" value="awstart" />
  25.       bb_userid: <input type="text" name="cookie_bb_userid" value="" maxlength="5" size="6" /><br />
  26.       bb_password: <input type="text" name="cookie_bb_password" value="" maxlength="32" size="44" /><br />
  27.       <input type="submit" value="Log in" />
  28.       <input type="reset" value="Reset fields" />
  29.     </form>
  30.     <!-- ### -->
  31.   </body>
  32. </html>
  33. <?php
  34. $initial_page = ob_kill();
  35.  
  36. ob_start();
  37. // output page follows
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html>
  41.   <head>
  42.     <title>Prize awarder</title>
  43.   </head>
  44.   <body>
  45.     <center>
  46.       <!-- ##form: location -->
  47.       <form action="$$location" method="post">
  48.         <!-- ##parameter: name, value -->
  49.         <input type="hidden" name="$$name" value="$$value" />
  50.         <!-- #### -->
  51.         <input type="text" name="username" value="" /><br />
  52.         <input type="submit" value="Award!" />
  53.         <input type="reset" value="Reset" />
  54.       </form>
  55.       <!-- ### -->
  56.       <br /><hr /><br />
  57.       <!-- ##list -->
  58.       <h2>Awarded prizes:</h2>
  59.       <select multiple="multiple" style="width: 90%;">
  60.         <!-- ##awarded: info -->
  61.         <option>$$info</option>
  62.         <!-- #### -->
  63.       </select>
  64.       <!-- ### -->
  65.     </center>
  66.   </body>
  67. </html>
  68. <?php
  69. $output_page = ob_kill();
  70.  
  71. function show_initial_page () {
  72.   global $initial_page;
  73.   echo parse_template($initial_page, array('form' => function () {return array(1 => $_SERVER['PHP_SELF']);}));
  74. }
  75.  
  76. function award_prize ($username, $cookie_info) {
  77.   $curl_session = curl_init();
  78.   curl_setopt($curl_session, CURLOPT_URL, 'http://jiggmin.com/contests/award-prize.php?' . http_build_query(array(
  79.     'contest' => 'Epic Santa',
  80.     'action' => 'give',
  81.     'jvname' => '',
  82.     'pr2name' => $username)));
  83.   $cookiestring = '';
  84.   foreach ($cookie_info as $cookie => $value) {
  85.     if ($cookiestring != '') $cookiestring .= '; ';
  86.     $cookiestring .= "$cookie=$value";
  87.   }
  88.   curl_setopt($curl_session, CURLOPT_COOKIE, $cookiestring);
  89.   curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
  90.   $result = curl_exec($curl_session);
  91.   curl_close($curl_session);
  92.   $result = strpos($result, 'It seems there was an error:');
  93.   return $result === false;
  94. }
  95.  
  96. function show_awards_page ($award_info, $cookie_info) {
  97.   global $output_page;
  98.   echo parse_template($output_page, array(
  99.       'form' => function () {
  100.         return array(1 => $_SERVER['PHP_SELF']);
  101.       },
  102.       'parameter' => function ($awards, $cookies) {
  103.         $params = array();
  104.         $count = 0;
  105.         foreach ($cookies as $name => $value)
  106.           $params[++ $count] = array(1 => htmlspecialchars('cookie_' . $name), 2 => htmlspecialchars($value));
  107.         foreach ($awards as $id => $value)
  108.           $params[++ $count] = array(1 => 'award' . $id, 2 => htmlspecialchars($value));
  109.         $params[++ $count] = array(1 => 'total_awards', 2 => count($awards));
  110.         $params[++ $count] = array(1 => 'mode', 2 => 'award');
  111.         $params[0] = $count;
  112.         return $params;
  113.       },
  114.       'list' => function ($awards) {
  115.         return (bool) (count($awards));
  116.       },
  117.       'awarded' => function ($awards) {
  118.         $result = array();
  119.         $result[0] = count($awards);
  120.         for ($i = 0; $i < count($awards); $i ++)
  121.           $result[count($awards) - $i] = array(1 => $awards[$i]);
  122.         return $result;
  123.       }
  124.     ), $award_info, $cookie_info);
  125. }
  126.  
  127. function get_cookie_info () {
  128.   $cookieinfo = array();
  129.   foreach ($_POST as $name => $value)
  130.     if (substr($name, 0, 7) == 'cookie_')
  131.       $cookieinfo[substr($name, 7)] = $value;
  132.   return $cookieinfo;
  133. }
  134.  
  135. function get_award_info () {
  136.   if (@$_POST['mode'] != 'award') return array();
  137.   $count = (int) $_POST['total_awards'];
  138.   $result = array();
  139.   for ($i = 0; $i < $count; $i ++)
  140.     $result[$i] = $_POST['award' . $i];
  141.   return $result;
  142. }
  143.  
  144. if (!isset($_POST['mode']))
  145.   show_initial_page();
  146. else
  147.   switch ($_POST['mode']) {
  148.     case 'awstart':
  149.       $cookies = get_cookie_info();
  150.       show_awards_page(array(), $cookies);
  151.       break;
  152.     case 'award':
  153.       $cookies = get_cookie_info();
  154.       $user = $_POST['username'];
  155.       $awards = get_award_info();
  156.       $status = award_prize($user, $cookies);
  157.       $awards[] = $status ? $user : "$user [NOT AWARDED]";
  158.       show_awards_page($awards, $cookies);
  159.       break;
  160.     default:
  161.       show_initial_page();
  162.   }
  163. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement