-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
154 lines (121 loc) · 5.09 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
include("header.php");
include("settings.php");
if (!file_exists($streams_path))
{
?>
<div class="info">
Streams folder missing: <?php echo $streams_path ?>
<BR>Solution requires a folder monitored by rtmp server / tools for streams to connect. Contact VideoWhisper for assistance.
</div>
<?php
exit;
}
$rtsp = $_POST['rtsp'];
if (!$_POST["username"]||$_POST["username"]=="Studio") $username="Studio".rand(100,999);
else $username=$_POST["username"];
if ($username)
{
include("incsan.php");
sanV($username);
}
function url(){
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$url = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strstr($url, '.php')) return dirname($url);
else return $url;
}
function streamList($name, $file)
{
global $httpstreamer, $httpdash, $maximumSessionTime;
$url = url() . '/';
$ms = 1000 *(time() - filemtime($file));
if ($maximumSessionTime && $ms > $maximumSessionTime)
{
echo 'Cleaning ' . $name . ' ... <BR>';
//terminate old stream
unlink($file);
}
else
{
$age = ceil($ms/60000);
echo '<br><i>'.$name.'</i> '; echo "($age min) ";
echo '<a target="_blank" href="'.$url.'channel.php?n='.urlencode($name).'"><b>Watch</b></a> | ';
echo '<a target="_blank" href="'.$url.'video_small.php?n='.urlencode($name).'">Video</a> | ';
echo '<a target="_blank" href="'. $httpstreamer . urlencode($name).'/playlist.m3u8">HLS</a> (Safari/VLC) | ';
echo '<a target="_blank" href="mpeg-dash.php?n=' . urlencode($name).'">MPEG DASH</a> (Chrome) | ';
echo '<a target="_blank" href="'.$url.'ls_transcoder.php?n='.urlencode($name).'">Transcode</a> (if needed) ';
}
}
if ($rtsp)
{
list($firstWord) = explode(':', $rtsp);
if (!in_array($firstWord, array('rtsp','udp','rtmp','rtmps','wowz','wowzs')))
{
echo "Address format not supported ($firstWord). Address should use one of these protocols: rtsp://, udp://, rtmp://, rtmps://, wowz://, wowzs://";
$rtsp = '';
}
if (strstr($rtsp,'[') || strstr($rtsp,'stream-path'))
{
echo 'Address should not contain special characters or sample path provided as demo. Insert address exactly as it works in <a target="_blank" href="http://www.videolan.org/vlc/index.html">VLC</a> or other player.';
$rtsp = '';
}
}
if ($username && $rtsp && $rtsp!='rtsp://[user:password]@IP:[port]/[stream-path]')
{
$file = $streams_path . '/' . $username . '.stream';
$myfile = fopen($file, "w") or die("Unable to write file!");
fwrite($myfile, $rtsp);
fclose($myfile);
?><div class="info">
Stream was setup. Streaming server should publish it shortly.
<?php
streamList($username.'.stream', $file);
?>
<?php
}
else
{
?>
<div style="padding:20px"><form id="adminForm" name="adminForm" method="post" action="index.php" onSubmit="return censorName()">
<b>IP Camera Setup: Provide a Label and your Stream Address</b><br>
<br>
<script language="JavaScript">
function censorName()
{
document.adminForm.username.value = document.adminForm.username.value.replace(/^[\s]+|[\s]+$/g, '');
document.adminForm.username.value = document.adminForm.username.value.replace(/[^0-9a-zA-Z_\-]+/g, '-');
document.adminForm.username.value = document.adminForm.username.value.replace(/\-+/g, '-');
document.adminForm.username.value = document.adminForm.username.value.replace(/^\-+|\-+$/g, '');
if (document.adminForm.username.value.length>2) return true;
else return false;
}
</script>
<BR>Stream Label <input name="username" type="text" id="username" value="Studio" size="12" maxlength="12" onChange="censorName()"/>
<BR>Stream Address <input name="rtsp" type="text" id="rtsp" value="rtsp://[user:password]@IP:[port]/[stream-path]" size="80" maxlength="250"/>
<BR>Insert address exactly as it works in <a target="_blank" href="http://www.videolan.org/vlc/index.html">VLC</a> or other player. For increased playback support, H264 video with AAC audio encoded streams should be used. Original address will remain secret (will not be shared with stream viewers). Address should use one of these protocols: rtsp://, udp://, rtmp://, rtmps://, wowz://, wowzs:// . If using a custom port, it needs to be enabled in server firewall (contact server administrator).
<BR><input type="submit" name="button" id="button" value="Add Stream" onClick="this.disabled=true; censorName(); this.value='Loading...'; adminForm.submit();" />
<?php
if (strstr($rtmp_server, "://localhost/")) echo "<P class='warning'>Warning: You are using a localhost based rtmp address ( $rtmp_server ). Unless you are just testing this with a rtmp server on your own computer, make sure you fill a <a href='http://www.videowhisper.com/?p=RTMP+Applications'>compatible rtmp address</a> in settings.php.</P>";
?>
</form></div>
<div class="info">
<b>Current Streams</b>
<?php
foreach (glob($streams_path . '/*.stream') as $file)
{
streamList(basename($file), $file);
}
if ($maximumSessionTime) echo '<br>Maximum stream age: ' . floor($maximumSessionTime/60000) . ' minutes. Older streams are terminated.';
?>
</div>
<div class="info">
Channel cleanup:<br />
<?php
include_once("clean_older.php");
?>
</div>
<?php
}
?>
</BODY>