audiopost.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* See license terms in /license.txt */
  3. //file_put_contents("result.txt", print_r($_POST, true));
  4. //file_put_contents("result3.txt", print_r($_FILES, true));
  5. //file_put_contents("result2.txt", print_r($_GET, true));
  6. require_once '../inc/global.inc.php';
  7. // check the request comes from our red5 server
  8. $ips = gethostbynamel(api_get_setting('service_visio', 'visio_host'));
  9. $is_our_server = false;
  10. // ignoring null file
  11. if ($_FILES["file"]["size"] == 0) {
  12. exit(0);
  13. }
  14. if (is_array($ips)) {
  15. foreach ($ips as $ip) {
  16. //get 255 range for known server address
  17. $split = split('.', $ip);
  18. $ip_range_server = $split[0].'.'.$split[1].'.'.$split[2];
  19. //get 255 range for request source address
  20. $split = split('.', $_SERVER['REMOTE_ADDR']);
  21. $ip_range_request = $split[0].'.'.$split[1].'.'.$split[2];
  22. if ($ip_range_server == $ip_range_request) {
  23. $is_our_server = true;
  24. }
  25. }
  26. }
  27. if ($is_our_server) {
  28. if (api_get_setting('service_visio', 'active') == 'true') {
  29. //check encryption key
  30. $string1 = $_GET['course_code'].$_GET['user_id'].gmdate('Ymd').$_configuration['security_key'];
  31. $string2 = $_GET['course_code'].$_GET['user_id'].(gmdate('Ymd') - 1).$_configuration['security_key'];
  32. if (md5($string1) == $_GET['checker'] or md5($string2) == $_GET['checker']) {
  33. $course_info = api_get_course_info($_GET['course_code']);
  34. $target = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/audio/';
  35. $basename = basename($_FILES['file']['name']);
  36. $target = $target.$basename;
  37. if (!move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
  38. error_log(__FILE__.':'.__LINE__.': File upload to '.$target.' failed', 0);
  39. } else {
  40. $id = FileManager::add_document(
  41. $course_info,
  42. '/audio/'.$basename,
  43. 'file',
  44. filesize($target),
  45. $basename
  46. );
  47. if ($id !== false) {
  48. $res = api_item_property_update(
  49. $course_info,
  50. TOOL_DOCUMENT,
  51. $id,
  52. 'DocumentAdded',
  53. $_GET['user_id']
  54. );
  55. if ($res === false) {
  56. error_log(
  57. __FILE__.':'.__LINE__.': Something went wrong with item properties update of '.$target,
  58. 0
  59. );
  60. } else { //make sound invisible?
  61. //$res = api_item_property_update($course_info,TOOL_DOCUMENT,$id,'invisible',$_GET['user_id']);
  62. }
  63. } else {
  64. error_log(__FILE__.':'.__LINE__.': Could not create document record for document '.$target, 0);
  65. }
  66. }
  67. } else {
  68. error_log(
  69. __FILE__.':'.__LINE__.': Attempting to save file but hash check did not suceed (hacking attempt?)',
  70. 0
  71. );
  72. }
  73. } else {
  74. error_log(__FILE__.':'.__LINE__.': Attempting to save file but videoconf is not enabled', 0);
  75. }
  76. } else {
  77. error_log(__FILE__.':'.__LINE__.': Attempting to save file but coming from unknown source', 0);
  78. }
  79. ?>