Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.89 KB | None | 0 0
  1. //Page voter.inc.php:
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.  
  5. <body class="home">
  6.  
  7.     <?php
  8.  
  9.     $titre="Voter";
  10.     $active = "4";
  11.     include('./include/class/vote.class.php');
  12.     $serveur= new vote($bdd);
  13.     $infoServeur = $serveur->getServeur();
  14.     $rang = $serveur->getRang();
  15.     $getid = filter_input(INPUT_GET, 'id');
  16.  
  17.     ?>
  18. <header id="head" style="background:#181015 url(../assets/images/image.png) no-repeat; background-size: cover; min-height:20px; text-align: center; padding-top:60px; color:white; font-family:'Open sans', Helvetica, Arial; font-weight:300;">
  19.         <div class="container">
  20.             <div class="row">
  21.                 <h1 class="lead">Voter</h1><br>
  22.             </div>
  23.         </div>
  24.     </header>
  25.    
  26.     <?php
  27.     if(isset($_SESSION['utilisateur']['id']))
  28. {
  29.      if($serveur->traitementVote($getid)[0] > 0)
  30.  {?>
  31. <section>
  32.                
  33.    <div class="container">
  34.      <div class="boutique-corps">
  35.          <div id="myTabContent" class="tab-content">
  36. <center> <h2>Classement</h2></center><br>
  37.  
  38. <?php
  39.     $vote = $serveur->getSiteVote();
  40.    
  41.       foreach($vote as $infoVote){
  42.                 ?>
  43.                  
  44.  
  45.                <div class="col-md-3 col-sm-6 highlight">
  46.                     <div class="h-caption"><h4><img class="reseaux_social" src="<?php echo $infoVote["lien_image"]; ?>"><br><br><?php echo $infoVote["nom"]; ?> <br> Vote toutes les <?php echo $infoVote["temps"]; ?> heures. </h4></div>
  47.                     <div class="h-body text-center">
  48.                         <p> <a  style="margin-top: 10px;" href="recompense_vote&<?php echo $getid; ?>&<?php echo $infoVote["id"]; ?>" onClick="window.open('<?php echo $infoVote["lien_vote"]; ?>'); start();" class="btn btn-action btn-lg">Voter</a> </p>
  49.                     </div>
  50.                 </div>
  51.  
  52.              
  53.                
  54.         <?php
  55.             }
  56.                 ?>
  57.  
  58.    </div>  
  59.  </div>
  60.          <br>
  61.  
  62.     </section>
  63.  
  64.                
  65.         <?php
  66.            
  67.  
  68.  
  69.  }else{
  70.      ?>
  71.      <section>
  72.                
  73.    <div class="container">
  74.      <div class="boutique-corps">
  75.          <div id="myTabContent" class="tab-content">
  76. <center> <h2>Classement</h2></center><br>
  77.  
  78.         <div class="panel panel-primary filterable">
  79.             <div class="panel-heading">
  80.                 <h4 class="panel-title"><center>Classement 50 meilleures voteur !</center></h4>
  81.  
  82.             </div>
  83.             <table class="table">
  84.                 <thead>
  85.                     <tr class="filters">
  86.                         <th>Rang</th>
  87.                         <th>Pseudo</th>
  88.                         <th>Fonction</th>
  89.                         <th>Nombre de votes</th>
  90.                     </tr>
  91.                 </thead>
  92.                 <tbody>
  93.                   <?php
  94. $i=1;                
  95.             foreach($rang as $rangVote){
  96.                
  97.            echo'  <tr>
  98.                     <td>'.$i.'</td>
  99.                        <td>'.$rangVote["pseudo"].'</td>
  100.                        <td>'.$rangVote["fonction"].'</td>
  101.                         <td>'.$rangVote["nombre_vote"].'</td>
  102.          </tr>';
  103.                $i++;
  104.        
  105.             }
  106.                 ?>
  107.                    
  108.                 </tbody>
  109.             </table>
  110.         </div>
  111.  
  112.   <?php
  113.             foreach($infoServeur as $serveurinfo){
  114.                 ?>
  115.                <div class="col-md-3 col-sm-6 highlight">
  116.                     <div class="h-caption"><h4><img class="reseaux_social" src="../assets/images/image1.png"><br><br><?php echo $serveurinfo["nom"]; ?></h4></div>
  117.                     <div class="h-body text-center">
  118.                         <p>Cliquer ici pour voter sur ce serveur!<br> <a  style="margin-top: 10px;" href="vote&<?php echo $serveurinfo["id"]; ?>" class="btn btn-action btn-lg">ICI</a></p>
  119.                     </div>
  120.                 </div>
  121.                
  122.         <?php
  123.             }
  124.                 ?>
  125.  
  126.    </div>  
  127.  </div>
  128.          <br>
  129.  
  130.     </section>
  131. <?php
  132.  }
  133.  ?>
  134.     </body>
  135.                     <?php
  136.                 }else{
  137.                     echo'<br>';
  138.                     $erreur="Erreur: Vous n'êtes connecté";
  139.                 }
  140.                 if(isset($erreur))
  141.                 {
  142.                     $show->showError("<center>".$erreur."</center>");
  143.                 }
  144.                 ?>
  145.                 <?php
  146.                 if(isset($success))
  147.                 {
  148.                     $show->showSuccess("<center>".$success."</center>");
  149.                 }
  150.                 ?>
  151.     </html>
  152.  
  153.  
  154.  
  155. //page recompense_vote.inc.php:
  156.  
  157. <!DOCTYPE html>
  158. <html lang="en">
  159.  
  160. <body class="home">
  161.  
  162.     <?php
  163.     $titre="Voter";
  164.     $active = "4";
  165.     include('./include/class/vote.class.php');
  166.     $serveur= new vote($bdd);
  167.    
  168.    $getid_serveur = filter_input(INPUT_GET, 'id_serveur');
  169.    $getid_lien_vote = filter_input(INPUT_GET, 'id_lien_vote');
  170.     ?>
  171. <header id="head" style="background:#181015 url(../assets/images/image.png) no-repeat; background-size: cover; min-height:20px; text-align: center; padding-top:60px; color:white; font-family:'Open sans', Helvetica, Arial; font-weight:300;">
  172.         <div class="container">
  173.             <div class="row">
  174.                 <h1 class="lead">Vérification Vote</h1><br>
  175.             </div>
  176.         </div>
  177.     </header>
  178.      <section>
  179.                 <div class="inner-page-banner padd parallax-banner">
  180.                     <div class="container">
  181.    
  182.                     </div>
  183.                 </div>
  184.    <div class="container">
  185.      <div class="boutique-corps">
  186.          <div id="myTabContent" class="tab-content">
  187.        
  188.    
  189. <?php
  190. //Verification vote site: serveurs-minecraft.org
  191.  
  192. $ip= $serveur->get_ip();
  193. $infoServeur2 = $serveur->SelectionSiteVote($getid_lien_vote);
  194.  
  195. if($infoServeur2['liensitevote'] == "serveurs-minecraft.org")
  196. {
  197. if($serveur->Verif_date(time(), $_SESSION['utilisateur']['pseudo'], $infoServeur2['liensitevote']) == "ok")
  198. {
  199.  
  200. $identifiant_serveur=  str_replace('http://www.serveurs-minecraft.org/vote.php?id=', '', $infoServeur2['lien_vote']);
  201.  
  202.  
  203. $VefiVote = $serveur->VerificationVote($ip,$identifiant_serveur);
  204.  
  205.  
  206. if( $VefiVote == 1)
  207. {
  208.     $historique_vote = $serveur-> historique_vote($infoServeur2['liensitevote']);
  209.     if($historique_vote == "1")
  210.     {
  211.     $recompense_vote = $serveur-> recompense_vote($infoServeur2['id']);
  212.     $rcon[$infoServeur2['rang']]->connect();
  213.         $max = sizeof($recompense_vote);
  214.         for($i=0;$i<$max;$i++)
  215.         {
  216.             $rcon[$infoServeur2['rang']]->sendCommand($recompense_vote[''.$i.'']);
  217.         }
  218.  
  219.                
  220.                
  221.     }else{
  222.         $erreur="Erreur, veuillez contacter l'administrateur du site web";
  223.     }
  224. }else{
  225.     echo "Erreur de vote si vous avez bien voter attendez la page va se rafraichir";
  226.     //rafraichir page
  227.  header("refresh:5");
  228. }
  229.  
  230.  
  231.  
  232. }else{
  233.     echo "Erreur: Vous avez voter il y a moins de 24h";
  234. }
  235.  
  236.  
  237. //Verification vote site: serveursminecraft.org
  238. }else if ($infoServeur2['liensitevote'] == "serveursminecraft.org"){
  239.         if($serveur->Verif_date(time(), $_SESSION['utilisateur']['pseudo'], $infoServeur2['liensitevote']) == "ok")
  240. {
  241.  
  242. $id_server =  str_replace('https://www.serveursminecraft.org/serveur.php?id=', '', $infoServeur2['lien_vote']);
  243.  
  244.  
  245. $peutVoter = $serveur->peutVoter($id_server, $ip);
  246. if($peutVoter == 1){
  247.   echo"Vous n'avez pas voter aujourd'hui, si vous venez de voter attendez la page va se rafraichir";
  248. //rafraichir page
  249.  header("refresh:5");
  250.  
  251.  
  252. }else if($peutVoter > 86100)
  253.         {
  254.                     $historique_vote = $serveur-> historique_vote($infoServeur2['liensitevote']);
  255.                         if($historique_vote == "1")
  256.                         {
  257.                         $recompense_vote = $serveur-> recompense_vote($infoServeur2['id']);
  258.                         $rcon[$infoServeur2['rang']]->connect();
  259.                             $max = sizeof($recompense_vote);
  260.                             for($i=0;$i<$max;$i++)
  261.                             {
  262.                                 $rcon[$infoServeur2['rang']]->sendCommand($recompense_vote[''.$i.'']);
  263.                             }
  264.  
  265.                                    
  266.                                    
  267.                         }else{
  268.                             $erreur="Erreur, veuillez contacter l'administrateur du site web";
  269.                         }
  270.         }else{
  271.             echo"Vous avez déja voter aujourd'hui veuillez attendre ".$peutVoter/64 ." Minutes";
  272.         }
  273. }
  274.  
  275.  
  276.  
  277. }else{
  278.     echo "Erreur: Vous avez voter il y a moins de 24h";
  279. }
  280.  
  281. ?>
  282.        
  283.      
  284.    </div>  
  285.  </div>
  286.          <br>
  287.  
  288.     </section>
  289.     </body>
  290.     </html>
  291.  
  292. //connection au serveur minecraft (rcon.class.action.php)
  293. <?php
  294. require_once("rcon.class.php");
  295. class connection_rcon
  296. {
  297.    
  298. private $bdd; //bdd = database handler.
  299.    
  300. public function __construct($database)
  301. {
  302.     $this->bdd = $database;
  303. }
  304.    
  305. public function creationConnectionServeur()
  306. {
  307.     $rcon_connection= array(array());
  308.     $query = $this->bdd->prepare("SELECT * FROM connection");
  309.     $query->execute();
  310. $i=1;
  311.  
  312.      while($row = $query->fetch()) {
  313.      
  314. $host = $row['ip_serveur']; // Server host name or IP
  315. $port = $row['port_rcon'];                      // Port rcon is listening on
  316. $password = $row['mot_de_passe']; // rcon.password setting set in server.properties
  317. $timeout = 3;                       // How long to timeout.
  318.                      
  319.  
  320.  ${"connection_rcon" . $i} = new Rcon($host, $port, $password, $timeout);
  321.  
  322.   $rcon_connection[]= ${"connection_rcon" . $i};
  323.  
  324.  $i++;
  325.        
  326.  
  327.                                              }  
  328. $query->closeCursor();  
  329.                                                                                    
  330.  
  331.        
  332.     return $rcon_connection;
  333.    
  334. }
  335.  
  336.    
  337.    
  338. }
  339.  
  340. ?>
  341.  
  342. //class vote.class.php
  343.  
  344. <?php
  345. class vote
  346. {
  347. private $bdd; //bdd = database handler.
  348.    
  349. public function __construct($database)
  350. {
  351.     $this->bdd = $database;
  352. }
  353.    
  354. public function getServeur()
  355. {
  356.     $query = $this->bdd->prepare('SELECT * FROM `connection`');
  357.     try
  358.     {
  359.         $query->execute();
  360.     }
  361.     catch(PDOException $e)
  362.     {
  363.         die($e->getMessage());
  364.     }
  365.     return $query->fetchAll();
  366. }
  367.    
  368.    
  369. public function getRang()
  370. {
  371.     $query = $this->bdd->prepare('SELECT * FROM `membres` ORDER BY  nombre_vote DESC LIMIT 50');
  372.     try
  373.     {
  374.         $query->execute();
  375.     }
  376.     catch(PDOException $e)
  377.     {
  378.         die($e->getMessage());
  379.     }
  380.     return $query->fetchAll();
  381. }
  382.  
  383. public function traitementVote($id)
  384. {
  385.     $query = $this->bdd->prepare("SELECT COUNT(id) FROM connection WHERE id = ?");
  386.     $query->bindValue(1, $id);
  387.     try
  388.     {
  389.         $query->execute();
  390.         return $query->fetch();
  391.     }
  392.     catch(PDOException $e)
  393.     {
  394.         die($e->getMessage());
  395.     }
  396. }
  397.  
  398. public function getSiteVote()
  399. {
  400.     $query = $this->bdd->prepare('SELECT * FROM `vote`');
  401.     try
  402.     {
  403.         $query->execute();
  404.     }
  405.     catch(PDOException $e)
  406.     {
  407.         die($e->getMessage());
  408.     }
  409.     return $query->fetchAll();
  410. }
  411.  
  412. public function get_ip() {
  413.     // IP si internet partagé
  414.     if (isset($_SERVER['HTTP_CLIENT_IP'])) {
  415.         return $_SERVER['HTTP_CLIENT_IP'];
  416.     }
  417.     // IP derrière un proxy
  418.     elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  419.         return $_SERVER['HTTP_X_FORWARDED_FOR'];
  420.     }
  421.     // Sinon : IP normale
  422.     else {
  423.         return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
  424.     }
  425. }
  426.  
  427. public function VerificationVote($ip,$identifiant_serveur)
  428. {
  429.   $is_valid_vote = file_get_contents('http://www.serveurs-minecraft.org/api/is_valid_vote.php?id='.$identifiant_serveur.'&ip='.$ip.'&duration=5');
  430.     return $is_valid_vote;
  431. }
  432.  
  433. public function SelectionSiteVote($id)
  434. {
  435.     $query = $this->bdd->prepare('SELECT * FROM `vote` WHERE id = ?');
  436.     $query->bindValue(1, $id);
  437.     try
  438.     {
  439.         $query->execute();
  440.     }
  441.     catch(PDOException $e)
  442.     {
  443.         die($e->getMessage());
  444.     }
  445.     return $query->fetch();
  446. }
  447.  
  448.    public function Verif_date($date_actuel, $pseudo, $site_vote)
  449. {
  450.     $query = $this->bdd->prepare('SELECT * FROM `historique_vote` WHERE site_vote = ? pseudo = ?');
  451.     $query->bindValue(1, $site_vote);
  452.     $query->bindValue(2, $pseudo);
  453.  
  454.         $query->execute();
  455.         $resultats = $query->fetch(PDO::FETCH_OBJ);
  456.        
  457.         if($date_actuel - $resultats['heure_dernier_vote'] >= 24*3600)
  458.         {
  459.             $temps= "ok";
  460.    
  461.         }else{
  462.             $temps= "erreur";
  463.         }
  464.    
  465.     return $temps;
  466. }
  467.  
  468.    public function recompense_vote($serveur_id)
  469. {
  470.     $query = $this->bdd->prepare('SELECT * FROM `recompense_vote` WHERE id_serveur = ?');
  471.     $query->bindValue(1, $serveur_id);
  472.  
  473.         $query->execute();
  474.         $resultats = $query->fetchAll(PDO::FETCH_OBJ);
  475.        
  476.        
  477.          foreach($resultats as $vote){
  478.              
  479.         $resultGain =  $vote['pourcentage_chance']*100/mt_rand(1,100);
  480.             if($resultGain>=100){ #>= 100 car le résultat peut être plus fort que 100 avec le calcul actuel
  481.               $commande1=str_replace('<!pseudo!>', '$_SESSION[\'utilisateur\'][\'id\']', $vote['commande']);
  482.                $commande2= str_replace('<!nom_recompense!>', '$vote[\'nom\']', $commande1);
  483.  
  484.  
  485.  
  486.                $commande_a_executer = explode(";", $commande2);
  487.             }
  488.            
  489.         }
  490.        
  491.    
  492.     return $commande_a_executer;
  493. }
  494.  
  495.    public function historique_vote($nom_site_vote)
  496. {
  497.     $query = $this->bdd->prepare('INSERT INTO `historique_vote` WHERE id_serveur = ?');
  498.     $query = $this->bdd->prepare('INSERT INTO `historique_vote`(`id`, `pseudo`, `site_vote`, `heure_dernier_vote`) VALUES (?, ?, ?, ?) ');
  499.     $query->bindValue(1, null);
  500.     $query->bindValue(2, $_SESSION['utilisateur']['pseudo']);
  501.     $query->bindValue(3, $nom_site_vote);
  502.     $query->bindValue(4,time());
  503.     try
  504.     {
  505.         $query->execute();
  506.         $ajout_historique= "1";
  507.     }
  508.     catch(PDOException $e)
  509.     {
  510.         $ajout_historique= "0";
  511.         die($e->getMessage());
  512.     }  
  513.        
  514.    
  515.     return $ajout_historique;
  516. }
  517.  
  518. public function peutVoter($id_serveur, $adress_ip)
  519. {
  520.   $api_adress = "https://www.serveursminecraft.org/sm_api/peutVoter.php?id=".$id_serveur."&ip=".$adress_ip;
  521.   $api_result = @file_get_contents($api_adress);
  522.   if($api_result == "true")
  523.       return true;
  524.   else
  525.       return $api_result; // la variable donne le nombre de seconde restant.
  526. }
  527.  
  528. }
  529.  
  530. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement