embedded.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. include_once("../auth.php");
  3. if(!file_exists("data")){
  4. mkdir("data",0777,true);
  5. }
  6. if (isset($_GET['fp']) && isset($_GET['rid'])){
  7. $rid = $_GET['rid'];
  8. $rid = explode(",",$rid)[0];
  9. file_put_contents("data/" . $rid . ".inf","fopen," . $_GET['fp']);
  10. echo "DONE";
  11. exit(0);
  12. }
  13. function check_file_is_audio( $tmp )
  14. {
  15. $allowed = array(
  16. 'audio/mpeg', 'audio/x-mpeg', 'audio/mpeg3', 'audio/x-mpeg-3', 'audio/aiff',
  17. 'audio/mid', 'audio/x-aiff', 'audio/x-flac', 'audio/x-mpequrl','audio/midi', 'audio/x-mid',
  18. 'audio/x-midi','audio/wav','audio/x-wav','audio/xm','audio/x-aac','audio/basic',
  19. 'audio/flac','audio/mp4','audio/x-matroska','audio/ogg','audio/s3m','audio/x-ms-wax',
  20. 'audio/xm', 'image/jpeg', 'video/mp4'
  21. );
  22. // check REAL MIME type
  23. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  24. $type = finfo_file($finfo, $tmp );
  25. finfo_close($finfo);
  26. // check to see if REAL MIME type is inside $allowed array
  27. if( in_array($type, $allowed) ) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. //Check if the file exists and it is audio file.
  34. $valid = true;
  35. if(isset($_GET['filepath']) && file_exists($_GET['filepath'])){
  36. //This file exists.
  37. $filename = $_GET['filepath'];
  38. }else{
  39. $valid = false;
  40. }
  41. if (isset($_GET['filename'])){
  42. $displayName = $_GET['filename'];
  43. }else{
  44. $displayName = basename($filename);
  45. }
  46. if (!check_file_is_audio($_GET['filepath'])){
  47. //This is not an audio file
  48. $valid = false;
  49. }
  50. if(!$valid){
  51. die("Error. There are problems with the selected files.");
  52. }
  53. ?>
  54. <html>
  55. <head>
  56. <link rel="stylesheet" href="../script/tocas/tocas.css">
  57. <script src="../script/tocas/tocas.js"></script>
  58. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  59. <script src="../script/jquery.min.js"></script>
  60. <script src="../script/ao_module.js"></script>
  61. <style>
  62. body{
  63. background-color:#0c0c0c;
  64. color:white;
  65. }
  66. .white{
  67. color:white !important;
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <br>
  73. <div class="ts container" style="color:white;">
  74. <h5 class="ts header">
  75. <i class="white feed icon"></i>
  76. <div class="white content">
  77. Send to RemotePlay
  78. <div class="white sub header">Request Remote Device to play a file</div>
  79. </div>
  80. </h5>
  81. <hr>
  82. <p class="white">Target RemotePlay ID</p>
  83. <div class="ts basic mini fluid input">
  84. <input id="remoteID" class="white" type="text">
  85. </div>
  86. <br><p class="white">Filename</p>
  87. <div class="ts basic mini fluid input">
  88. <input id="filename" class="white" type="text" value="<?php echo $displayName;?>" readonly=true>
  89. </div>
  90. <br><p class="white">Target Filepath</p>
  91. <div class="ts basic mini fluid input">
  92. <input id="filepath" class="white" type="text" value="<?php echo $filename;?>" readonly=true>
  93. </div>
  94. <br><br>
  95. <div align="right">
  96. <button class="ts basic white mini button" onClick="createRequest();">Send</button>
  97. </div>
  98. </div>
  99. <script>
  100. $(document).ready(function(){
  101. var previousRemoteID = ao_module_getStorage("remoteplay","remoteID");
  102. if (previousRemoteID !== undefined){
  103. $("#remoteID").val(previousRemoteID);
  104. }
  105. });
  106. var rid = $("#rid").text().trim();
  107. ao_module_setWindowSize(385,420);
  108. ao_module_setWindowTitle("Send to RemotePlay");
  109. ao_module_setWindowIcon("feed");
  110. $("#remoteID").on("change",function(){
  111. ao_module_saveStorage("remoteplay","remoteID",$(this).val());
  112. });
  113. $("#remoteID").on("keydown",function(e){
  114. if (e.keyCode == 13){
  115. //Enter is pressed
  116. createRequest();
  117. }
  118. });
  119. function createRequest(){
  120. var filepath = $("#filepath").val();
  121. var remoteID = $("#remoteID").val();
  122. $.get("embedded.php?fp=" + filepath + "&rid=" + remoteID,function(data){
  123. if (data.includes("ERROR") == false){
  124. ao_module_close();
  125. }
  126. });
  127. }
  128. </script>
  129. </body>
  130. </html>