ewft.getmail.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?PHP
  2. # Setup page variables
  3. $appname="ewft.getmail";
  4. $displayname="GetMail";
  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. <script type="text/javascript">
  105. function openLog() {
  106. var machine_type = "<?=$machine_type;?>";
  107. var title="<?=$appname;?> Activity Log";
  108. if (machine_type == "x86_64") {
  109. <?if (substr($ver60check, 0, 3) === "6.0"):?>
  110. var url="/usr/bin/tail -n 42 -f <?=$plglogfile;?>";
  111. openWindow( url, title,600,900);
  112. <?else:?>
  113. var url="<?=$prefix;?>/plugins/<?=$appname;?>/scripts/tail_log&arg1=<?=$appname;?>.log";
  114. openWindow( url, title,600,900);
  115. <?endif;?>
  116. } else {
  117. var url="/logging.htm?title=" + title + "&cmd=/usr/bin/tail -n 42 -f <?=$plglogfile;?>&forkCmd=Start";
  118. openWindow( url, title.replace(/ /g, "_"),600,900);
  119. }
  120. }
  121. </script>