Example of SRS identity authentication configuration in Linux

Source: Internet
Author: User
Tags error code


Used a lot of free video tools, from Red5,crtmp to SRS, the SRS is relatively perfect, relatively stable. Until then, the SRS released the stable latest version of SRS 1.0R4 release, the following tests are rooted in this version.

1, Server description

SRS Server 192.168.1.108
Web Server 192.168.1.208

2,srs File configuration directory/usr/local/srs/conf/

[root@localhostconf]# LL
Total 136
-rw-r--r--1 root root 402 June 09:34 bandwidth.conf
-rw-r--r--1 root root 352 June 09:34 console.conf
-rw-r--r--1 root root 558 June 09:34 demo.19350.conf
-rw-r--r--1 root root 6045 June 09:34 demo.conf
-rw-r--r--1 root root 399 June 09:34 dvr.segment.conf
-rw-r--r--1 root root 335 June 09:34 dvr.session.conf
-rw-r--r--1 root root 359 June 09:34 edge.conf
-rw-r--r--1 root root 323 June 09:34 edge.token.traverse.conf
-rw-r--r--1 root root 995 June 09:34 ffmpeg.transcode.conf
-rw-r--r--1 root root 371 June 09:34 forward.master.conf
-rw-r--r--1 root root 333 June 09:34 forward.slave.conf
-rwxr-xr-x 1 root root 37388 June 09:34 full.conf
-rw-r--r--1 root root 366 June 09:34 hls.conf
-rw-r--r--1 root root 688 June 09:34 http.heartbeat.conf
-rw-r--r--1 root root 471 June 09:34 http.hls.conf
-rw-r--r--1 root root 874 June 09:34 http.hooks.callback.conf
-rw-r--r--1 root root 589 June 09:34 ingest.conf
-rw-r--r--1 root root 299 June 09:34 origin.conf
-rw-r--r--1 root root 294 June 09:34 realtime.conf
-rw-r--r--1 root root 09:34 June rtmp.conf
-rw-r--r--1 root root 1005 Aug 19:22 srs.conf//This is the configuration of the default call when the process starts
-rw-r--r--1 root root 819 June 09:34 transcode2hls.audio.only.conf
First of all, to praise the SRS configuration instructions, very comprehensive, all the configuration has an example, look at the official document, and then find the configuration file in the directory, very convenient.

Authentication configuration for 3,srs

Vhost __defaultvhost__ {
。。。。。。。。。。。。。。。。。。。。。
Http_hooks {
Enabled on;
# On_connect http://192.168.1.208/checkuser.php;
# On_close http://192.168.1.208/checkuser.php;
On_publish http://192.168.1.208/checkuser.php;
# On_unpublish http://192.168.1.208/checkuser.php;
On_play http://192.168.1.208/checkuser.php;
# On_stop http://192.168.1.208/checkuser.php;
}
。。。。。。。。。。。。。。。。。。。。。。。。。
}
Adding Http_hooks to the Vhost, the checkuser.php is checked before the rtmp stream is released, and the return of the root checkuser.php is determined to release the rtmp stream. Note Oh, you can verify multiple servers oh, that is, on_publish after the connection, can be multiple, separated by space, full.conf in a detailed description.

4,checkuser.php file is on Web server 208

Class CheckUser
{
Private $host = ' 192.168.1.208 ';
Private $user = "DBA";
Private $pass = "111111";
Private $database = ' SRS ';
Private $db;
Private $data;

Public Function __construct () {

$param = file_get_contents ("Php://input"); $info the contents of the next line of comments
' {action ': "On_publish", "client_id": "A", "IP": "192.168.1.108", "Vhost": "__defaultvhost__", "app": "Live", "stream ":" 23948523485?key=13799999999_vvvxaaanx "}";
$this->data=json_decode ($param);

$this->error_l ($param);
if (!emptyempty ($this->data->action)) {
$this->db = new ezSQL_mysql ($this->user, $this->pass, $this->database, $this->host);
$this->db->query ("Set names UTF8;");
$this->checkuser ();
}else{
echo "1";
}

}
Public Function CheckUser () {

if ($this->data->action = = "On_connect") {
echo "0";
}
else if ($this->data->action = = "On_close") {
echo "0";
}
else if ($this->data->action = = "On_publish") {

$arr _query = $this->converturlquery ($this->data->stream);
echo $arr _query;

}
else if ($this->data->action = = "On_unpublish") {
echo "0";
}
else if ($this->data->action = = "On_play") {
echo "0";
}
else if ($this->data->action = = "On_stop") {
echo "0";
}
else if ($this->data->action = = "On_dvr") {
echo "0";
}
else{
echo "1";
}
Die
}

Public Function Converturlquery ($query)
{
$m = '/key= (. *)/I ';
Preg_match ($m, $query, $match);
if (!emptyempty ($match [1])) {
$info = Explode (' _ ', $match [1]);
if (!emptyempty ($info [0]) &&!emptyempty ($info [1])) {
$result = $this->checksrslogin ($info [0], $info [1]);
if (!emptyempty ($result)) {
return 0;
}else{
return 1;
}
}else{
return 1;
}

}else{
return 1;
}
}

Public Function Checksrslogin ($account, $password)
{
if (Emptyempty ($account) | | emptyempty ($PASSWORD)) {
return false;
}

$sql = "Select user_id from User".
"Where password = '". $password. "' and mobile = '. $account;

$result = $this->db->get_row ($sql);
return $result;
}

Public Function error_l ($param) {

$message = "\ r \ n". ' Params: '. $param. "\ r \ n". ' Return time: '. Date (' y-m-d h:i:s '). "\ r \ n";
$message. = '-----------------------------------------------------------------------------------------------'. "\ r \ n";
$path = GETCWD (). /srs.log ";

Error_log ($message, 3, $path);
}

}

5, using FFmpeg to release rtmp video stream, in 108 server

Ffmpeg-re-i "/root/test.flv"-vcodec copy-acodec copy-f flv rtmp://192.168.1.108/live/23948523485?key=13799999999_ Vvvxaanx
rtmp flow, why is this situation. This is found from the full.conf document, and the following is a partial inner space in the full.conf file

# when client connect to Vhost/app, call the hook,
# The request in the POST data string was a object encode by JSON:
#       {
# "Action": "On_connect",
# "client_id": 1985,
# "IP": "192.168.1.10", "Vhost": "Video.test.com", "app": "Live",
# "Tcurl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a",//See?
# "Pageurl": "Http://www.test.com/live.html"
#       }
# if valid, the hook must return HTTP code (stauts OK) and response
# an int value specifies the error code (0 corresponding to success):
# 0
# support multiple API hooks, format:

So the content behind the key is the content to be passed to checkuser.php.

Here to pay attention to OH. Key=xxxxx, this situation is fixed oh, do not support KEY=XXXXXX&AAA=BBB. So after the key, what to preach, do not encrypt, the decision of their own.
6, look at the 208 server, Srs.log information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.