ewft.minidlna.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?PHP
  2. # Setup page variables
  3. $appname="ewft.minidlna";
  4. $displayname="MiniDLNA";
  5. $appexecutable="usr/sbin/minidlnad";
  6. $appconfigfile="settings.json";
  7. $plglogfile="/var/log/minidlnad/{$appname}.log";
  8. $arrayState=trim(shell_exec( "grep fsState /var/local/emhttp/var.ini | sed -n 's!fsState=\"\(.*\)\"!\\1!p'" ));
  9. $ver60check=trim(shell_exec( "grep version /etc/unraid-version | sed -n 's!version=\"\(.*\)\"!\\1!p'" ));
  10. # Sets the loader background to match the theme based on unRaid version sicne 6 has a dark theme
  11. $machine_type = trim(shell_exec( "uname -m" ));
  12. if ($machine_type == "x86_64") {
  13. $loaderbgcolor = "html";
  14. $prefix = "";
  15. if (substr($ver60check, 0, 3) === "6.0") {
  16. $prefix = "/usr/local/emhttp";
  17. }
  18. } else {
  19. $loaderbgcolor = ".Container";
  20. $prefix = "/usr/local/emhttp";
  21. }
  22. ?>
  23. <!-- ========================================================================= -->
  24. <!-- Page load animation and text -->
  25. <!-- ========================================================================= -->
  26. <!-- # Add jquery library, show loader, fade out when loaded -->
  27. <script type="text/javascript">
  28. if(typeof jQuery == 'undefined'){
  29. var oScriptElem = document.createElement("script");
  30. oScriptElem.type = "text/javascript";
  31. oScriptElem.src = "/plugins/<?=$appname;?>/scripts/jquery.min.js";
  32. document.head.insertBefore(oScriptElem, document.getElementsByTagName("script")[0])
  33. }
  34. </script>
  35. <div id="loading">
  36. <img id="loading-image" src='/plugins/<?=$appname;?>/icons/loader.gif' alt="Loading..." />
  37. <p id="loading-text">LOADING PLUGIN</p>
  38. </div>
  39. <script language="javascript" type="text/javascript">
  40. $("#loading").css("background-color",$("<?=$loaderbgcolor;?>").css("background-color"));
  41. $("#loading").show();
  42. </script>
  43. <script language="javascript" type="text/javascript">
  44. $(window).load(function() {$("#loading").fadeOut("slow");});
  45. </script>
  46. <!-- ========================================================================= -->
  47. <!-- Load current config file and check if program is installed already -->
  48. <!-- ========================================================================= -->
  49. <?PHP
  50. # This will clean any ^M characters caused by windows from the config file before use
  51. if (file_exists("/boot/config/plugins/{$appname}/{$appname}.cfg"))
  52. shell_exec("sed -i 's!\r!!g' \"/boot/config/plugins/{$appname}/{$appname}.cfg\"");
  53. if (file_exists("/usr/local/emhttp/plugins/{$appname}/scripts/rc.{$appname}"))
  54. shell_exec("sed -i 's!\r!!g' \"/usr/local/emhttp/plugins/{$appname}/scripts/rc.{$appname}\"");
  55. # Check existence of files and make startfile if missing
  56. $app_cfg = parse_ini_file( "/boot/config/plugins/{$appname}/{$appname}.cfg" );
  57. $app_installed = file_exists("/{$appexecutable}" ) ? "yes" : "no";
  58. # =========================================================================
  59. ## Collect local variables from config files and verify data as best as possible
  60. # =========================================================================
  61. # Set readonly status if array is offline
  62. if ($arrayState == "Started") {
  63. $app_readonly = "";
  64. $app_disabled = "";
  65. } else {
  66. $app_readonly = 'readonly="readonly"';
  67. $app_disabled = 'disabled="disabled"';
  68. }
  69. # Plugin Current Version Variable
  70. if (file_exists("/boot/config/plugins/{$appname}.plg")) {
  71. $app_plgver = trim(shell_exec ( "grep 'ENTITY version' /boot/config/plugins/{$appname}.plg | sed -n 's!.*\s\"\(.*\)\".*!\\1!p'" ));
  72. if ($app_plgver == "") {
  73. $app_plgver = "Unknown plugin version";
  74. }
  75. } else {
  76. $app_plgver = "(Plugin File Missing)";
  77. }
  78. # Service Status Variable
  79. if (isset($app_cfg['SERVICE']) && ($app_cfg['SERVICE'] == "enable" || $app_cfg['SERVICE'] == "disable"))
  80. $app_service = $app_cfg['SERVICE'];
  81. else
  82. $app_service = "disable";
  83. # =========================================================================
  84. ## Check is program is installed and running to get extra information
  85. # =========================================================================
  86. # Get current installed version of the program
  87. if ($arrayState=="Started") {
  88. $app_curversion = trim(shell_exec ( "/usr/local/emhttp/plugins/{$appname}/scripts/rc.{$appname} currentversion" ));
  89. if ($app_curversion == "")
  90. $app_curversion = "UNKNOWN";
  91. }
  92. if ($app_installed=="yes" && $arrayState=="Started") {
  93. $app_running = trim(shell_exec( "[ -f /proc/`cat /var/run/minidlna/minidlna.pid 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" ));
  94. if ($app_running == "yes")
  95. $app_updatestatus = "Running";
  96. else
  97. $app_updatestatus = "Stopped";
  98. }
  99. echo "<script>document.getElementById('loading-text').innerHTML = \"DONE\";</script>";
  100. ?>
  101. <!-- ========================================================================= -->
  102. <!-- Create the HTML code used to display the settings GUI -->
  103. <!-- ========================================================================= -->
  104. <div id="PANELALL"><div id="PANELLEFT">
  105. <div class="TITLEBARLEFT title" id="title">
  106. <span class="left"><img id="IMGICON" src="/plugins/<?=$appname;?>/icons/device_status.png">&#32;Status:
  107. <?if ($app_installed=="yes" && $arrayState=="Started"):?>
  108. <?if ($app_running=="yes"):?>
  109. <span class="green"><b>RUNNING</b></span>
  110. <?else:?>
  111. <span class="red"><b>STOPPED</b></span>
  112. <?endif;?>
  113. <?else:?>
  114. <span class="red"><b>NOT READY</b></span>
  115. <?endif;?>
  116. </span>
  117. </div>
  118. <div id="DIVLEFT">
  119. <div id="T50LM">
  120. <?if ($arrayState == "Started"):?>
  121. <p id="PLINE">Array State:<b><span class="green">ONLINE</span></b></p>
  122. <?if ($app_curversion == "NOT INSTALLED" || $app_curversion == "UNKNOWN"):?>
  123. <p id="PLINE">Installed Version:<b><span class="red"><?=$app_curversion;?></span></b></p>
  124. <?else:?>
  125. <p id="PLINE" class="longver">Installed Version:<b><span class="green" title="<?=$app_curversion;?>"><?=$app_curversion;?></span></b></p>
  126. <?endif;?>
  127. <?else:?>
  128. <p id="PLINE">Array State:<b><span class="red">OFFLINE</span></b></p>
  129. <?endif;?>
  130. </div>
  131. <?if ($app_installed=="yes"):?>
  132. <?if ($app_running=="yes"):?>
  133. <div id="T25RM">
  134. <form name="app_stop" method="POST" action="/update.htm" target="progressFrame">
  135. <input type="hidden" name="cmd" value="<?=$prefix;?>/plugins/ewft.minidlna/scripts/rc.ewft.minidlna"/>
  136. <input type="hidden" name="arg1" value="stop"/>
  137. <input <?=$app_disabled;?> type="submit" name="runCmd" id="STDSMBUTTONR" value="Stop"/>
  138. </form>
  139. </div>
  140. <div id="T25LM">
  141. <form name="app_restart" method="POST" action="/update.htm" target="progressFrame">
  142. <input type="hidden" name="cmd" value="<?=$prefix;?>/plugins/ewft.minidlna/scripts/rc.ewft.minidlna"/>
  143. <input type="hidden" name="arg1" value="restart"/>
  144. <input <?=$app_disabled;?> type="submit" name="runCmd" id="STDSMBUTTONL" value="Restart"/>
  145. </form>
  146. </div>
  147. <?else:?>
  148. <div id="T50CM">
  149. <form name="app_start" method="POST" action="/update.htm" target="progressFrame">
  150. <input type="hidden" name="cmd" value="<?=$prefix;?>/plugins/ewft.minidlna/scripts/rc.ewft.minidlna"/>
  151. <input type="hidden" name="arg1" value="start"/>
  152. <input <?=$app_disabled;?> type="submit" name="runCmd" id="STDSMBUTTON" value="Start"/>
  153. </form>
  154. </div>
  155. <?endif;?>
  156. <?else:?>
  157. <div id="T50CM">
  158. <form name="app_install" method="POST" action="/update.htm" target="progressFrame">
  159. <input type="hidden" name="cmd" value="<?=$prefix;?>/plugins/ewft.minidlna/scripts/rc.ewft.minidlna"/>
  160. <input type="hidden" name="arg1" value="install"/>
  161. <input <?=$app_disabled;?> type="submit" name="runCmd" id="STDSMBUTTON" value="Install"/>
  162. </form>
  163. </div>
  164. <?endif;?>
  165. </div>
  166. <? if ($app_installed=="yes" && $arrayState=="Started"): ?>
  167. <?if ($app_canupdate=="yes"):?>
  168. <div id="DIVLEFT">
  169. <div id="T50LM">
  170. <p id="PLINE"></p>
  171. </div>
  172. <div id="T50CM">
  173. <form name="app_updateapp" method="POST" action="/update.htm" target="progressFrame">
  174. <input type="hidden" name="cmd" value="<?=$prefix;?>/plugins/ewft.minidlna/scripts/rc.ewft.minidlna"/>
  175. <input type="hidden" name="arg1" value="update"/>
  176. <input type="hidden" name="arg3" value="<?=$app_updatestatus;?>"/>
  177. <input id="UPDATEBUTTON" type="submit" name="runCmd" value="Update <?=$displayname;?>"/>
  178. </form>
  179. <p id="VERSION" class="longver" title="<?=$app_newversion;?>"><b>New Version: <?=$app_newversion;?></b></p>
  180. </div>
  181. </div>
  182. <?endif;?>
  183. <? endif; ?>
  184. <div class="TITLEBARLEFT title" id="title">
  185. <span class="left"><img id="IMGICON" src="/plugins/<?=$appname;?>/icons/information.png">&#32;Information:</span>
  186. </div>
  187. <div id="DIVLEFT">
  188. <div id="T50LM">
  189. <p id="PLINE"><b>Plugin Version: <?=$app_plgver;?></b></p>
  190. </div>
  191. </div>
  192. <div id="DIVLEFT">
  193. <div id="T50LT">
  194. <p id="PLINE"><a title="<?=$appname;?> Activity Log - <?=$plglogfile;?>" href="#" target="_blank" id="ACTIVITYLINK" onclick="openLog();return false;">View Activity Log</a></p>
  195. </div>
  196. </div>
  197. </div>
  198. <script type="text/javascript">
  199. function openLog() {
  200. var machine_type = "<?=$machine_type;?>";
  201. var title="<?=$appname;?> Activity Log";
  202. if (machine_type == "x86_64") {
  203. <?if (substr($ver60check, 0, 3) === "6.0"):?>
  204. var url="/usr/bin/tail -n 42 -f <?=$plglogfile;?>";
  205. openWindow( url, title,600,900);
  206. <?else:?>
  207. var url="<?=$prefix;?>/plugins/<?=$appname;?>/scripts/tail_log&arg1=<?=$appname;?>.log";
  208. openWindow( url, title,600,900);
  209. <?endif;?>
  210. } else {
  211. var url="/logging.htm?title=" + title + "&cmd=/usr/bin/tail -n 42 -f <?=$plglogfile;?>&forkCmd=Start";
  212. openWindow( url, title.replace(/ /g, "_"),600,900);
  213. }
  214. }
  215. </script>