Advertisement
Guest User

controller.vote_api.php

a guest
May 12th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.75 KB | None | 0 0
  1. <?php
  2.     in_file();
  3.  
  4.     class vote_api extends controller
  5.     {
  6.         protected $vars = [], $errors = [];
  7.  
  8.         public function __construct()
  9.         {
  10.             parent::__construct();
  11.             $this->load->helper('website');
  12.             $this->load->model('account');
  13.         }
  14.  
  15.         public function index()
  16.         {
  17.             throw new exception('Nothing to see here!');
  18.         }
  19.  
  20.         public function xtremetop($key = '')
  21.         {
  22.             if($this->checkApiKey($key, 'Xtremetop100')){
  23.                 if(isset($_GET['custom'], $_GET['votingip'])){
  24.                     if($_GET['custom'] != ''){
  25.                         if($this->Maccount->add_xtremetop_vote($_GET['custom'], $_GET['votingip'])){
  26.                             echo 'VOTE LOGGED';
  27.                         } else{
  28.                             writelog('Xtremetop100 error - unable to log vote custom: ' . $_GET['custom'] . ', ip: ' . $_GET['votingip'], 'vote_api');
  29.                         }
  30.                     } else{
  31.                         writelog('Xtremetop100 error - variable custom is empty, ip: ' . $_GET['votingip'], 'vote_api');
  32.                     }
  33.                 } else{
  34.                     writelog('Xtremetop100 error - missing some voting variable', 'vote_api');
  35.                 }
  36.             }
  37.         }
  38.  
  39.         public function ultratop($key = '')
  40.         {
  41.             if($this->checkApiKey($key, 'UltraTop100')){
  42.                 if(isset($_GET['custom'], $_GET['votingip'])){
  43.                     if($_GET['custom'] != ''){
  44.                         if($this->Maccount->add_ultratop_vote($_GET['custom'], $_GET['votingip'])){
  45.                             echo 'VOTE LOGGED';
  46.                         } else{
  47.                             writelog('UltraTop100 error - unable to log vote custom: ' . $_GET['custom'] . ', ip: ' . $_GET['votingip'], 'vote_api');
  48.                         }
  49.                     } else{
  50.                         writelog('UltraTop100 error - variable custom is empty, ip: ' . $_GET['votingip'], 'vote_api');
  51.                     }
  52.                 } else{
  53.                     writelog('UltraTop100 error - missing some voting variable', 'vote_api');
  54.                 }
  55.             }
  56.         }
  57.  
  58.         public function gametop100($key = '')
  59.         {
  60.             if($this->checkApiKey($key, 'GameTop100')){
  61.                 if(isset($_POST['custom'], $_POST['ip'])){
  62.                     if($_POST['custom'] != ''){
  63.                         if($this->Maccount->add_gametop100_vote($_POST['custom'], $_POST['ip'])){
  64.                             echo 'VOTE LOGGED';
  65.                         } else{
  66.                             writelog('GameTop100 error - unable to log vote custom: ' . $_POST['custom'] . ', ip: ' . $_POST['ip'], 'vote_api');
  67.                         }
  68.                     } else{
  69.                         writelog('GameTop100 error - variable custom is empty, ip: ' . $_POST['ip'], 'vote_api');
  70.                     }
  71.                 } else{
  72.                     writelog('GameTop100 error - missing some voting variable', 'vote_api');
  73.                 }
  74.             }
  75.         }
  76.  
  77.         public function gtop100($key = '')
  78.         {
  79.             if($this->checkApiKey($key, 'Gtop100')){
  80.                 if(isset($_POST['Successful']) && abs($_POST['Successful']) == 0){
  81.                     if(isset($_POST['pingUsername'], $_POST['VoterIP'])){
  82.                         if($this->Maccount->add_gtop100_vote($_POST['pingUsername'], $_POST['VoterIP'])){
  83.                             echo 'VOTE LOGGED';
  84.                         } else{
  85.                             writelog('Gtop100 error - unable to log vote', 'vote_api');
  86.                         }
  87.                     } else{
  88.                         writelog('Gtop100 error - missing some voting variable', 'vote_api');
  89.                     }
  90.                 } else{
  91.                     writelog('Gtop100 error - vote was not successfull reason: ' . $_POST['Reason'], 'vote_api');
  92.                 }
  93.             }
  94.         }
  95.  
  96.         public function topg($key = '')
  97.         {
  98.             if($this->checkApiKey($key, 'Topg')){
  99.                 if(isset($_GET['p_resp'], $_GET['ip'])){
  100.                     if($this->Maccount->add_topg_vote($_GET['p_resp'], $_GET['ip'])){
  101.                         echo 'VOTE LOGGED';
  102.                     } else{
  103.                         writelog('Topg error - unable to log vote', 'vote_api');
  104.                     }
  105.                 } else{
  106.                     writelog('Topg error - missing some voting variable', 'vote_api');
  107.                 }
  108.             }
  109.         }
  110.  
  111.         public function top100arena($key = '')
  112.         {
  113.             if($this->checkApiKey($key, 'Top100arena')){
  114.                 if(isset($_GET['postback'])){
  115.                     if($this->Maccount->add_top100arena_vote($_GET['postback'])){
  116.                         echo 'VOTE LOGGED';
  117.                     } else{
  118.                         writelog('Top100arena error - unable to log vote', 'vote_api');
  119.                     }
  120.                 } else{
  121.                     writelog('Top100arena error - missing some voting variable', 'vote_api');
  122.                 }
  123.             }
  124.         }
  125.  
  126.         public function mmoserver($key = '')
  127.         {
  128.             if($this->checkApiKey($key, 'Mmoserver')){
  129.                 if(isset($_POST['mod']) && $_POST['mod'] == 'reward'){
  130.                     if($this->Maccount->add_mmoserver_vote($_POST['user'])){
  131.                         echo 'OK';
  132.                     } else{
  133.                         writelog('Mmoserver error - unable to log vote', 'vote_api');
  134.                     }
  135.                 } else{
  136.                     writelog('Mmoserver error - missing some voting variable', 'vote_api');
  137.                 }
  138.             }
  139.         }
  140.  
  141.         /** SUPREMETOP100 **/
  142.         public function supremetop($key = '')
  143.         {
  144.             if($this->checkApiKey($key, 'SupremeTop100'))
  145.             {
  146.                 // Ensure that it is a POST request.
  147.                 if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0)
  148.                 {
  149.                     writelog('SupremeTop100 failed REQUEST_METHOD check', 'vote_api');
  150.                 }
  151.                 else
  152.                 {
  153.                     writelog('SupremeTop100 passed REQUEST_METHOD check', 'vote_api');
  154.                    
  155.                     // Ensure that this is SupremeTop100 sending the request
  156.                     if(strcasecmp($_SERVER['HTTP_USER_AGENT'], 'SupremeTop100/1.0 (Linux; x64) Postback Agent') != 0)
  157.                     {
  158.                         writelog('SupremeTop100 error - unable to log vote (invalid useragent): ' . $_SERVER['HTTP_USER_AGENT'], 'vote_api');
  159.                     }
  160.                     else
  161.                     {
  162.                         writelog('SupremeTop100 passed HTTP_USER_AGENT check', 'vote_api');
  163.                        
  164.                         // Ensure that the content type of the POST request has been set to application/json
  165.                         $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
  166.                        
  167.                         // For RESTful response
  168.                         // For "normal" response use 'application/x-www-form-urlencoded'
  169.                         if(strcasecmp($contentType, 'application/json') != 0)
  170.                         {
  171.                             writelog('SupremeTop100 error - unable to log vote (invalid content type): ' . $contentType, 'vote_api');
  172.                         }
  173.                         else
  174.                         {
  175.                             // Retrieve the RAW POST data.
  176.                             $content = trim(file_get_contents("php://input"));
  177.                            
  178.                             // Attempt to decode the incoming RAW POST data from JSON.
  179.                             $decoded = json_decode($content, true);
  180.                            
  181.                             // If json_decode failed, the JSON is invalid.
  182.                             if(!is_array($decoded))
  183.                             {
  184.                                 // Do not give too many details, because the attacker is smart.
  185.                                 writelog('SupremeTop100 error - unable to vote: ' . print_r($content), 'vote_api');
  186.                             }
  187.                             else
  188.                             {
  189.                                 // Process the JSON parsed as array.
  190.                                 if($decoded['supremetop100_vote_info']['status'] == 1)
  191.                                 {
  192.                                     // Rewards your user by username or character name
  193.                                     if($this->Maccount->add_supremetop_vote($decoded['supremetop100_user_info']['username'], $decoded['supremetop100_user_info']['ip_address']))
  194.                                     {
  195.                                         echo 'VOTE LOGGED';
  196.                                     }
  197.                                     else
  198.                                     {
  199.                                         writelog('SupremeTop100 error - unable to log vote: ' . print_r($decoded), 'vote_api');
  200.                                     }
  201.                                 }
  202.                                 else
  203.                                 {
  204.                                     writelog('SupremeTop100 error - unable to vote (bad status): ' . $decoded['supremetop100_vote_info']['status'], 'vote_api');
  205.                                 }
  206.                             }
  207.                         }
  208.                     }
  209.                 }
  210.             }
  211.         }
  212.        
  213.         private function checkApiKey($key = '', $site = '')
  214.         {
  215.             $vote_site = ($site != '') ? $site : 'Undefined';
  216.             if($key == ''){
  217.                 writelog($vote_site . ' error - empty api key', 'vote_api');
  218.             } else{
  219.                 $this->vars['config'] = $this->config->values('votereward_config');
  220.                 if($this->vars['config'] != false){
  221.                     if(isset($this->vars['config']['api_key'])){
  222.                         if($this->vars['config']['api_key'] == $key){
  223.                             return true;
  224.                         } else{
  225.                             writelog($vote_site . ' error - api keys does not match.', 'vote_api');
  226.                         }
  227.                     } else{
  228.                         writelog($vote_site . ' error - api key in votereward configuration not definded.', 'vote_api');
  229.                     }
  230.                 } else{
  231.                     writelog($vote_site . ' error - votereward configuration not found. ', 'vote_api');
  232.                 }
  233.             }
  234.             header("HTTP/1.1 403 Forbidden");
  235.             return false;
  236.         }
  237.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement