Advertisement
lachiu

rtmp

Jan 13th, 2020
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. streamauth.php
  2. <?php
  3. /*
  4. * ---------------------------------------------------------------
  5. * Stream authentication
  6. * ---------------------------------------------------------------
  7. *
  8. * This file must be specified in the nginx RTMP block using the
  9. * on_publish directive. Example:
  10. *
  11. * # Live Stream Application
  12. * application live {
  13. * live on;
  14. * on_publish http://path/to/streamauth.php;
  15. * }
  16. *
  17. * Publish URL should be rtmp://yourserver/live/$displayname?key=$streamkey
  18. *
  19. * In OBS:
  20. * - URL: rtmp://yourserver/live
  21. * - Stream key: $DisplayName?key=$StreamKey
  22. * (Where $DisplayName and $StreamKey are the appropriate values for your account)
  23. *
  24. */
  25. require_once '../inc/config.php';
  26. /**
  27. * @param $class
  28. */
  29. function __autoload($class) {
  30. include '../lib/' . $class . '.class.php';
  31. }
  32. $rtmp = new rtmp();
  33. $user = new user();
  34. $key = filter_input(INPUT_GET, 'key', FILTER_SANITIZE_STRING);
  35. $name = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
  36. $accountinfo = $user->info($name, 'display_name');
  37. $stream_title = $accountinfo['channel_title'];
  38. $timestamp = new DateTime();
  39. $timestamp = $timestamp->format('Y-m-d H:i:s');
  40. $timestamp = "Connection Attempt: $timestamp\r\n";
  41. $getstring = $timestamp;
  42. $getstring .= print_r($_GET, true);
  43. // write connection attempt to log, regardless of success
  44. file_put_contents($logfile . "streamauth.log", $getstring, FILE_APPEND | LOCK_EX);
  45. //check if querystrings exist or not
  46. if (empty($key)) {
  47. //no querystrings or wrong syntax
  48. $current = "ERROR: Invalid query input.\n";
  49. file_put_contents($logfile . "streamauth.log", $current, FILE_APPEND | LOCK_EX);
  50. echo "wrong query input";
  51. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
  52. exit(1);
  53. } else {
  54. //check and verify key against the DB, then run email notices for on-live
  55. $check = $rtmp->stream_check($key, $name, $logfile . "streamauth.log");
  56. if ($check === false) {
  57. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
  58. }
  59. else {
  60. // kinda messy to pass needed vars from config.php, but cleaner than $GLOBALS
  61. $notify = $rtmp->onLive($key, $name, $stream_title, $furl, $logfile, $from_email, $reply_email);
  62. }
  63. }
  64.  
  65. en
  66.  
  67. rtmp.conf
  68.  
  69. tmp {
  70. server {
  71. listen 1935;
  72. chunk_size 8192;
  73.  
  74. ping 10s;
  75. ping_timeout 5s;
  76. notify_method get;
  77. idle_streams off;
  78.  
  79. # Live Stream Application
  80. application live {
  81. live on;
  82. wait_video on;
  83. meta copy;
  84. # NOTE: This line should point to your streamauth.php.
  85. # However, if you intend to run the site on SSL, the on_publish directive will NOT work with SSL,
  86. # so you will need to use a proxy. See lines 1-12 of /sites-available/main.conf.
  87. on_publish http://proxy.url:8080/on_publish;
  88. notify_method get;
  89.  
  90. # executes the rolling screenshots script. There are probably better ways of accomplishing this
  91. # (using recorder blocks) but I haven't been able to get them to work reliably.
  92. exec_push /path/to/rtmp_sslive.sh $name &>/var/log/rachni/exec-$name.log;
  93.  
  94. recorder rec {
  95. record all manual;
  96. record_suffix .flv;
  97. record_unique on;
  98. record_path /var/rachni/rec;
  99. record_notify on;
  100. record_lock on;
  101. exec_record_done /path/to/rtmp_convert.sh $dirname $basename;
  102. }
  103. exec_kill_signal TERM;
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement