-
Notifications
You must be signed in to change notification settings - Fork 96
/
stream.php
80 lines (62 loc) · 1.6 KB
/
stream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include ("config.php");
use Carbon\Carbon;
set_time_limit(0);
error_reporting(0);
$ip = $_SERVER['REMOTE_ADDR'];
$username=$_GET['username'];
$password=$_GET['password'];
$id=$_GET['stream'];
$setting = Setting::first();
if (empty($_GET['username']) || empty($_GET['password'])) {
$error = "Username or Password is invalid";
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
header('Status: 404 Not Found');
die();
}
$user = User::where('username', '=', $username)->where('password', '=', $password)->where('active', '=', 1)->first();
if (!isset($_SESSION['user_id'])){ // TODO: secret key
$token = (!$user) ? die() : uniqid();
}
if($user->exp_date != "0000-00-00") {
if($user->exp_date <= Carbon::today()) {
die();
}
}
$stream = Stream::find($id);
if (!isset($_SESSION['user_id'])) { // TODO: secret key
(!$stream ? die() : "");
}
($stream->status != 1 ? die() : "");
ob_end_clean();
ob_start();
ignore_user_abort(true);
$user->lastconnected_ip = $ip;
$user->last_stream = $stream->id;
$user->save();
$url = $stream->streamurl;
if($stream->checker == 2) {
$url = $stream->streamurl2;
}
if($stream->checker == 3) {
$url = $stream->streamurl3;
}
if($stream->restream == false) {
if($setting->less_secure) {
$file = "http://".$setting->webip.":".$setting->webport."/".$setting->hlsfolder."/".$id."_.m3u8";
header("location: $file");
die();
}
}
$fd = fopen($url, "r");
while(!feof($fd)) {
echo fread($fd, 1024 * 5);
ob_flush();
flush();
if (connection_aborted()){
break;
}
}
fclose ($fd);
exit();
die();