embedded.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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', 'image/png', 'image/svg'
  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. $external = false;
  36. if(isset($_GET['filepath']) && file_exists($_GET['filepath'])){
  37. //This file exists.
  38. $filename = $_GET['filepath'];
  39. $filepath = $filename;
  40. }else if (isset($_GET['filepath']) && strpos($_GET['filepath'],"extDiskAccess.php?file=") !== false){
  41. //This file is imported from external storage.
  42. $external = true;
  43. $filename = $_GET['filepath'];
  44. $filepath = array_pop(explode("=",$_GET['filepath']));
  45. }else{
  46. $valid = false;
  47. }
  48. if (isset($_GET['filename'])){
  49. $displayName = $_GET['filename'];
  50. }else{
  51. $displayName = basename($filename);
  52. }
  53. if (!check_file_is_audio($filepath)){
  54. //This is not an audio file
  55. $valid = false;
  56. }
  57. if(!$valid){
  58. die("Error. There are problems with the selected files.");
  59. }
  60. ?>
  61. <html>
  62. <head>
  63. <link rel="stylesheet" href="../script/tocas/tocas.css">
  64. <script src="../script/tocas/tocas.js"></script>
  65. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  66. <script src="../script/jquery.min.js"></script>
  67. <script src="../script/ao_module.js"></script>
  68. <link rel="manifest" href="manifest.json">
  69. <style>
  70. body{
  71. background-color:#0c0c0c;
  72. color:white;
  73. }
  74. .white{
  75. color:white !important;
  76. }
  77. </style>
  78. </head>
  79. <body>
  80. <br>
  81. <div class="ts container" style="color:white;">
  82. <h5 class="ts header">
  83. <i class="white feed icon"></i>
  84. <div class="white content">
  85. Send to RemotePlay
  86. <div class="white sub header">Request Remote Device to play a file</div>
  87. </div>
  88. </h5>
  89. <hr>
  90. <p class="white">Target RemotePlay ID</p>
  91. <div class="ts floating dropdown labeled icon button" style="padding: 0px;padding-right: calc(0.22em + 1em + .78571em * 2) !important;padding-left: 0em !important;background-color: black;color:white;height: 39.97px" width="100%">
  92. <div class="text">
  93. <div class="ts fluid input" style="right 1px;bottom:1px">
  94. <input type="text" style="border-top-right-radius: 0px;border-bottom-right-radius: 0px;background-color: black;color: white!important;border-color: white!important;border-right:0px" placeholder="RemotePlay ID" id="remoteID_tb">
  95. </div>
  96. </div>
  97. <i class="caret down icon" style="left: auto !important;right: 0em !important;background-color: black;"></i>
  98. <div class="menu" style="background-color: black !important;" id="n_remoteID">
  99. </div>
  100. </div>
  101. <br><p class="white">Filename</p>
  102. <div class="ts basic mini fluid input">
  103. <input id="filename" class="white" type="text" value="<?php echo $displayName;?>" readonly=true>
  104. </div>
  105. <br><p class="white">Target Filepath</p>
  106. <div class="ts basic mini fluid input">
  107. <input id="filepath" class="white" type="text" value="<?php echo $filename;?>" readonly=true>
  108. </div>
  109. <br><br>
  110. <div align="right">
  111. <button class="ts basic white mini button" onClick="createRequest();">Send</button>
  112. </div>
  113. </div>
  114. <script>
  115. var rid = $("#rid").text().trim();
  116. ao_module_setWindowSize(385,420);
  117. $(document).ready(function(){
  118. ts('.ts.dropdown:not(.basic)').dropdown();
  119. $(".ts.fluid.input").click(function(e) {
  120. e.stopPropagation();
  121. });
  122. var h = $(".ts.fluid.input").height();
  123. $(".ts.floating.dropdown.labeled.icon.button").attr("style",$(".ts.floating.dropdown.labeled.icon.button").attr("style").replace("39.97",h));
  124. //$(".caret.down.icon").attr("style",$(".caret.down.icon").attr("style").replace("39.97",h));
  125. update();
  126. });
  127. setInterval(update, 10000);
  128. function update(){
  129. var previousRemoteID = ao_module_getStorage("remoteplay","remoteID");
  130. $.get("opr.php?opr=scanalive",function(data){
  131. var obj = JSON.parse(data);
  132. $("#n_remoteID").html("");
  133. $("#n_remoteID").append($('<div class="item" style="color: white!important;"></div>').attr("value", "").text("Not selected"));
  134. $.each( obj, function( key, value ) {
  135. $("#n_remoteID").append($('<div class="item" style="color: white!important;"></div>').attr("value", value).text(value));
  136. });
  137. $("#n_remoteID").val("");
  138. /*
  139. if (previousRemoteID !== undefined && $(".item[value='" + previousRemoteID + "']").length > 0){
  140. $("#remoteID_tb").val(previousRemoteID);
  141. rid = previousRemoteID;
  142. }
  143. */
  144. $("#remoteID_tb").val(previousRemoteID);
  145. $("#n_remoteID .item").on("click",function(){
  146. //console.log($(this).attr("value"));
  147. $("#remoteID_tb").val($(this).attr("value"));
  148. ao_module_saveStorage("remoteplay","remoteID",$(this).attr("value"));
  149. rid = $(this).attr("value");
  150. });
  151. $("#remoteID_tb").on("change",function(){
  152. ao_module_saveStorage("remoteplay","remoteID",$(this).val());
  153. rid = $(this).val();
  154. });
  155. });
  156. }
  157. ao_module_setWindowTitle("Send to RemotePlay");
  158. ao_module_setWindowIcon("feed");
  159. $("#remoteID_tb").on("change",function(){
  160. ao_module_saveStorage("remoteplay","remoteID",$(this).val());
  161. });
  162. $("#remoteID_tb").on("keydown",function(e){
  163. if (e.keyCode == 13){
  164. //Enter is pressed
  165. createRequest();
  166. }
  167. });
  168. function createRequest(){
  169. var filepath = $("#filepath").val();
  170. var remoteID = $("#remoteID_tb").val();
  171. $.get("embedded.php?fp=" + filepath + "&rid=" + remoteID,function(data){
  172. if (data.includes("ERROR") == false){
  173. ao_module_close();
  174. }
  175. });
  176. }
  177. </script>
  178. </body>
  179. </html>