seriy-coder

Untitled

Nov 12th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2. require_once('config.php');
  3. require_once('class.db.php');
  4.  
  5. function file_force_download($file, $conn) {
  6.   if (file_exists($file)) {
  7.     if (ob_get_level()) {
  8.       ob_end_clean();
  9.     }
  10.     header('Content-Description: File Transfer');
  11.     header('Content-Type: application/octet-stream');
  12.     header('Content-Disposition: attachment; filename=' . basename($file));
  13.     header('Content-Transfer-Encoding: binary');
  14.     header('Expires: 0');
  15.     header('Cache-Control: must-revalidate');
  16.     header('Pragma: public');
  17.     header('Content-Length: ' . filesize($file));
  18.  
  19.     if ($fd = fopen($file, 'rb')) {
  20.       while (!feof($fd)) {
  21.         print fread($fd, 1024);
  22.       }
  23.       fclose($fd);
  24.     }
  25.  
  26.     // close session
  27.     $hash = sha1($_SERVER["HTTP_USER_AGENT"]);
  28.     $ip = $_SERVER["REMOTE_ADDR"];
  29.         $database = new DB();
  30.         $conn--;
  31.         if($conn==0){
  32.             $delete = [
  33.                 'ip' => $ip,
  34.                 'hash' => $hash
  35.             ];
  36.             $deleted = $database->delete('sessions', $delete, 1);
  37.         }else{
  38.             $record = [
  39.                 'conn' => $conn
  40.             ];
  41.             $where_clause = [
  42.                 'ip' => $ip,
  43.                 'hash' => $hash
  44.             ];
  45.             $updated = $database->update('sessions', $record, $where_clause, 1);
  46.         }
  47.  
  48.     exit;
  49.   }
  50. }
  51.  
  52. function check_access(&$connections){
  53.     $database = new DB();
  54.     $hash = sha1($_SERVER["HTTP_USER_AGENT"]);
  55.     $ip = $_SERVER["REMOTE_ADDR"];
  56.     $conn = 1;
  57.  
  58.     $query = "SELECT conn FROM sessions WHERE ip='$ip' AND hash='$hash'";
  59.     if( $database->num_rows( $query ) > 0 )
  60.     {
  61.         list($curr_conn) = $database->get_row( $query );
  62.         $conn = $curr_conn + 1;
  63.         if($conn > 3) return false;
  64.  
  65.         $record = [
  66.             'conn' => $conn
  67.         ];
  68.         $where_clause = [
  69.             'ip' => $ip,
  70.             'hash' => $hash
  71.         ];
  72.         $updated = $database->update('sessions', $record, $where_clause, 1);
  73.  
  74.     }else{
  75.         $record = [
  76.             'ip' => $ip,
  77.             'hash' => $hash,
  78.             'conn' => 1
  79.         ];
  80.         $add_query = $database->insert('sessions', $record);
  81.     }
  82.     $connections = $conn;
  83.     return true;
  84. }
  85.  
  86. $check = ['site1.su', 'site2.ru'];
  87.  
  88. if(!in_array($_SERVER['SERVER_NAME'], $check)){
  89.     if(empty($config['access_denied'])){
  90.         header("HTTP/1.1 500 Internal Server Error");
  91.     }else{
  92.         // redirect
  93.         header("Location: ".$config['access_denied'], true, 303);
  94.     }
  95. }
  96. $conn=0;
  97. $access = check_access($conn);
  98. if(!$access){
  99.     if(empty($config['limit_exceeded'])){
  100.         header("HTTP/1.1 500 Internal Server Error");
  101.     }else{
  102.         // redirect
  103.         header("Location: ".$config['limit_exceeded'], true, 303);
  104.     }
  105. }
  106. $file = $_GET['f'];
  107. file_force_download($config['origin'].$file, $conn);
Advertisement
Add Comment
Please, Sign In to add comment