Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('config.php');
- require_once('class.db.php');
- function file_force_download($file, $conn) {
- if (file_exists($file)) {
- if (ob_get_level()) {
- ob_end_clean();
- }
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=' . basename($file));
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- header('Content-Length: ' . filesize($file));
- if ($fd = fopen($file, 'rb')) {
- while (!feof($fd)) {
- print fread($fd, 1024);
- }
- fclose($fd);
- }
- // close session
- $hash = sha1($_SERVER["HTTP_USER_AGENT"]);
- $ip = $_SERVER["REMOTE_ADDR"];
- $database = new DB();
- $conn--;
- if($conn==0){
- $delete = [
- 'ip' => $ip,
- 'hash' => $hash
- ];
- $deleted = $database->delete('sessions', $delete, 1);
- }else{
- $record = [
- 'conn' => $conn
- ];
- $where_clause = [
- 'ip' => $ip,
- 'hash' => $hash
- ];
- $updated = $database->update('sessions', $record, $where_clause, 1);
- }
- exit;
- }
- }
- function check_access(&$connections){
- $database = new DB();
- $hash = sha1($_SERVER["HTTP_USER_AGENT"]);
- $ip = $_SERVER["REMOTE_ADDR"];
- $conn = 1;
- $query = "SELECT conn FROM sessions WHERE ip='$ip' AND hash='$hash'";
- if( $database->num_rows( $query ) > 0 )
- {
- list($curr_conn) = $database->get_row( $query );
- $conn = $curr_conn + 1;
- if($conn > 3) return false;
- $record = [
- 'conn' => $conn
- ];
- $where_clause = [
- 'ip' => $ip,
- 'hash' => $hash
- ];
- $updated = $database->update('sessions', $record, $where_clause, 1);
- }else{
- $record = [
- 'ip' => $ip,
- 'hash' => $hash,
- 'conn' => 1
- ];
- $add_query = $database->insert('sessions', $record);
- }
- $connections = $conn;
- return true;
- }
- $check = ['site1.su', 'site2.ru'];
- if(!in_array($_SERVER['SERVER_NAME'], $check)){
- if(empty($config['access_denied'])){
- header("HTTP/1.1 500 Internal Server Error");
- }else{
- // redirect
- header("Location: ".$config['access_denied'], true, 303);
- }
- }
- $conn=0;
- $access = check_access($conn);
- if(!$access){
- if(empty($config['limit_exceeded'])){
- header("HTTP/1.1 500 Internal Server Error");
- }else{
- // redirect
- header("Location: ".$config['limit_exceeded'], true, 303);
- }
- }
- $file = $_GET['f'];
- file_force_download($config['origin'].$file, $conn);
Advertisement
Add Comment
Please, Sign In to add comment