PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/duplicator/views/tools/logging.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 211 lines | 173 code | 34 blank | 4 comment | 24 complexity | 7dcc8347d5ed1dbb877ac942319760da MD5 | raw file
  1. <?php
  2. require_once(DUPLICATOR_PLUGIN_PATH . '/assets/js/javascript.php');
  3. require_once(DUPLICATOR_PLUGIN_PATH . '/views/inc.header.php');
  4. $logs = glob(DUPLICATOR_SSDIR_PATH . '/*.log') ;
  5. if ($logs != false && count($logs)) {
  6. usort($logs, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
  7. @chmod(DUP_Util::SafePath($logs[0]), 0644);
  8. }
  9. $logname = (isset($_GET['logname'])) ? trim(sanitize_text_field($_GET['logname'])) : "";
  10. $refresh = (isset($_POST['refresh']) && $_POST['refresh'] == 1) ? 1 : 0;
  11. $auto = (isset($_POST['auto']) && $_POST['auto'] == 1) ? 1 : 0;
  12. //Check for invalid file
  13. if (!empty($logname)) {
  14. $validFiles = array_map('basename', $logs);
  15. if (validate_file($logname, $validFiles) > 0) {
  16. unset($logname);
  17. }
  18. unset($validFiles);
  19. }
  20. if (!isset($logname) || !$logname) {
  21. $logname = (count($logs) > 0) ? basename($logs[0]) : "";
  22. }
  23. $logurl = get_site_url(null, '', is_ssl() ? 'https' : 'http') . '/' . DUPLICATOR_SSDIR_NAME . '/' . $logname;
  24. $logfound = (strlen($logname) > 0) ? true :false;
  25. ?>
  26. <style>
  27. div#dup-refresh-count {display: inline-block}
  28. table#dup-log-panels {width:100%; }
  29. td#dup-log-panel-left {width:75%;}
  30. td#dup-log-panel-left div.name {float:left; margin: 0px 0px 5px 5px;}
  31. td#dup-log-panel-left div.opts {float:right;}
  32. td#dup-log-panel-right {vertical-align: top; padding-left:15px; max-width: 375px}
  33. div.dup-log-file-list a, span{display: inline-block; white-space: nowrap; text-overflow: ellipsis; max-width: 375px; line-height:20px; overflow:hidden}
  34. div.dup-log-file-list span {font-weight: bold}
  35. div.dup-opts-items {border:1px solid silver; background: #efefef; padding: 5px; border-radius: 4px; margin:2px 0px 10px -2px;}
  36. label#dup-auto-refresh-lbl {display: inline-block;}
  37. iframe#dup-log-content {padding:5px; background: #fff; min-height:500px; width:99%; border:1px solid silver}
  38. </style>
  39. <script type="text/javascript">
  40. jQuery(document).ready(function($) {
  41. Duplicator.Tools.FullLog = function() {
  42. var $panelL = $('#dup-log-panel-left');
  43. var $panelR = $('#dup-log-panel-right');
  44. if ($panelR.is(":visible") ) {
  45. $panelR.hide(400);
  46. $panelL.css({width: '100%'});
  47. } else {
  48. $panelR.show(200);
  49. $panelL.css({width: '75%'});
  50. }
  51. }
  52. Duplicator.Tools.Refresh = function() {
  53. $('#refresh').val(1);
  54. $('#dup-form-logs').submit();
  55. }
  56. Duplicator.Tools.RefreshAuto = function() {
  57. if ( $("#dup-auto-refresh").is(":checked")) {
  58. $('#auto').val(1);
  59. startTimer();
  60. } else {
  61. $('#auto').val(0);
  62. }
  63. }
  64. Duplicator.Tools.GetLog = function(log) {
  65. window.location = log;
  66. }
  67. Duplicator.Tools.WinResize = function() {
  68. var height = $(window).height() - 170;
  69. $("#dup-log-content").css({height: height + 'px'});
  70. }
  71. var duration = 10;
  72. var count = duration;
  73. var timerInterval;
  74. function timer() {
  75. count = count - 1;
  76. $("#dup-refresh-count").html(count.toString());
  77. if (! $("#dup-auto-refresh").is(":checked")) {
  78. clearInterval(timerInterval);
  79. $("#dup-refresh-count").text(count.toString().trim());
  80. return;
  81. }
  82. if (count <= 0) {
  83. count = duration + 1;
  84. Duplicator.Tools.Refresh();
  85. }
  86. }
  87. function startTimer() {
  88. timerInterval = setInterval(timer, 1000);
  89. }
  90. //INIT Events
  91. $(window).resize(Duplicator.Tools.WinResize);
  92. $('#dup-options').click(Duplicator.Tools.FullLog);
  93. $("#dup-refresh").click(Duplicator.Tools.Refresh);
  94. $("#dup-auto-refresh").click(Duplicator.Tools.RefreshAuto);
  95. $("#dup-refresh-count").html(duration.toString());
  96. //INIT
  97. Duplicator.Tools.WinResize();
  98. <?php if ($refresh) : ?>
  99. //Scroll to Bottom
  100. $("#dup-log-content").load(function () {
  101. var $contents = $('#dup-log-content').contents();
  102. $contents.scrollTop($contents.height());
  103. });
  104. <?php if ($auto) : ?>
  105. $("#dup-auto-refresh").prop('checked', true);
  106. Duplicator.Tools.RefreshAuto();
  107. <?php endif; ?>
  108. <?php endif; ?>
  109. });
  110. </script>
  111. <form id="dup-form-logs" method="post" action="">
  112. <input type="hidden" id="refresh" name="refresh" value="<?php echo ($refresh) ? 1 : 0 ?>" />
  113. <input type="hidden" id="auto" name="auto" value="<?php echo ($auto) ? 1 : 0 ?>" />
  114. <?php if (! $logfound) : ?>
  115. <div style="padding:20px">
  116. <h2><?php _e("Log file not found or unreadable", 'duplicator') ?>.</h2>
  117. <?php _e("Try to create a package, since no log files were found in the snapshots directory with the extension *.log", 'duplicator') ?>.<br/><br/>
  118. <?php _e("Reasons for log file not showing", 'duplicator') ?>: <br/>
  119. - <?php _e("The web server does not support returning .log file extentions", 'duplicator') ?>. <br/>
  120. - <?php _e("The snapshots directory does not have the correct permissions to write files. Try setting the permissions to 755", 'duplicator') ?>. <br/>
  121. - <?php _e("The process that PHP runs under does not have enough permissions to create files. Please contact your hosting provider for more details", 'duplicator') ?>. <br/>
  122. </div>
  123. <?php else: ?>
  124. <table id="dup-log-panels">
  125. <tr>
  126. <td id="dup-log-panel-left">
  127. <div class="name">
  128. <i class='fa fa-list-alt'></i> <b><?php echo basename($logurl); ?></b> &nbsp; | &nbsp;
  129. <i style="cursor: pointer"
  130. data-tooltip-title="<?php _e("Host Recommendation:", 'duplicator'); ?>"
  131. data-tooltip="<?php _e('Duplicator recommends going with the high performance pro plan or better from Bluehost.com', 'duplicator'); ?>">
  132. <i class="fa fa-lightbulb-o" aria-hidden="true"></i>
  133. <?php
  134. printf("%s <a target='_blank' href='//www.bluehost.com/track/snapcreek/?page=wordpress'>%s</a> %s",
  135. __("Duplicator recommends ", 'duplicator'),
  136. __("Bluehost", 'duplicator'),
  137. __("for more reliable conversions", 'duplicator'));
  138. ?>
  139. </i>
  140. </div>
  141. <div class="opts"><a href="javascript:void(0)" id="dup-options"><?php _e("Options", 'duplicator') ?> <i class="fa fa-angle-double-right"></i></a> &nbsp;</div>
  142. <br style="clear:both" />
  143. <iframe id="dup-log-content" src="<?php echo $logurl ?>" ></iframe>
  144. </td>
  145. <td id="dup-log-panel-right">
  146. <h2><?php _e("Options", 'duplicator') ?> </h2>
  147. <div class="dup-opts-items">
  148. <input type="button" class="button" id="dup-refresh" value="<?php _e("Refresh", 'duplicator') ?>" /> &nbsp;
  149. <div style="display:inline-block; margin-top:5px">
  150. <input type='checkbox' id="dup-auto-refresh" style="margin-top:1px" />
  151. <label id="dup-auto-refresh-lbl" for="dup-auto-refresh">
  152. <?php _e("Auto Refresh", 'duplicator') ?>
  153. [<div id="dup-refresh-count"></div>]
  154. </label>
  155. </div>
  156. </div>
  157. <b><?php _e("Last 20 Logs", 'duplicator') ?> </b><br/>
  158. <div class="dup-log-file-list">
  159. <?php
  160. $count=0;
  161. $active = basename($logurl);
  162. foreach ($logs as $log) {
  163. $time = date('h:i:s m/d/y', filemtime($log));
  164. $name = esc_html(basename($log));
  165. $url = '?page=duplicator-tools&logname=' . $name;
  166. echo ($active == $name)
  167. ? "<span title='{$name}'>{$time} - {$name}</span><br/>"
  168. : "<a href='javascript:void(0)' title='{$name}' onclick='Duplicator.Tools.GetLog(\"{$url}\")'>{$time} - {$name}</a><br/>";
  169. if ($count > 20) break;
  170. }
  171. ?>
  172. </div>
  173. </td>
  174. </tr>
  175. </table>
  176. <?php endif; ?>
  177. </form>