embedded.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. <link rel="manifest" href="manifest.json">
  62. <style>
  63. body{
  64. background-color:#0c0c0c;
  65. color:white;
  66. }
  67. .white{
  68. color:white !important;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <br>
  74. <div class="ts container" style="color:white;">
  75. <h5 class="ts header">
  76. <i class="white feed icon"></i>
  77. <div class="white content">
  78. Send to RemotePlay
  79. <div class="white sub header">Request Remote Device to play a file</div>
  80. </div>
  81. </h5>
  82. <hr>
  83. <p class="white">Target RemotePlay ID</p>
  84. <div class="ts basic mini fluid input">
  85. <select class="ts basic dropdown" id="remoteID" style="background: black;color: white;width: 100%">
  86. <option>Scanning...</option>
  87. </select>
  88. </div>
  89. <br><p class="white">Filename</p>
  90. <div class="ts basic mini fluid input">
  91. <input id="filename" class="white" type="text" value="<?php echo $displayName;?>" readonly=true>
  92. </div>
  93. <br><p class="white">Target Filepath</p>
  94. <div class="ts basic mini fluid input">
  95. <input id="filepath" class="white" type="text" value="<?php echo $filename;?>" readonly=true>
  96. </div>
  97. <br><br>
  98. <div align="right">
  99. <button class="ts basic white mini button" onClick="createRequest();">Send</button>
  100. </div>
  101. </div>
  102. <script>
  103. $(document).ready(function(){
  104. $.get("opr.php?opr=scanalive",function(data){
  105. var obj = JSON.parse(data);
  106. $("#remoteID").html("");
  107. $("#remoteID").append($("<option></option>").attr("value", "").text("Not selected"));
  108. $.each( obj, function( key, value ) {
  109. $("#remoteID").append($("<option></option>").attr("value", value).text(value));
  110. });
  111. $("#remoteID").val("");
  112. var previousRemoteID = ao_module_getStorage("remoteplay","remoteID");
  113. if (previousRemoteID !== undefined && $("#remoteID option[value='" + previousRemoteID + "']").length > 0){
  114. $("#remoteID").val(previousRemoteID);
  115. }
  116. });
  117. });
  118. var rid = $("#rid").text().trim();
  119. ao_module_setWindowSize(385,420);
  120. ao_module_setWindowTitle("Send to RemotePlay");
  121. ao_module_setWindowIcon("feed");
  122. $("#remoteID").on("change",function(){
  123. ao_module_saveStorage("remoteplay","remoteID",$(this).val());
  124. });
  125. $("#remoteID").on("keydown",function(e){
  126. if (e.keyCode == 13){
  127. //Enter is pressed
  128. createRequest();
  129. }
  130. });
  131. function createRequest(){
  132. var filepath = $("#filepath").val();
  133. var remoteID = $("#remoteID").val();
  134. $.get("embedded.php?fp=" + filepath + "&rid=" + remoteID,function(data){
  135. if (data.includes("ERROR") == false){
  136. ao_module_close();
  137. }
  138. });
  139. }
  140. </script>
  141. </body>
  142. </html>