HEX
HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux 2amigos-php74 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
User: squarehillcompany.com (1002)
PHP: 7.4.25
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhosts/app.ett-dev.2amigos.us/cgi-bin/taillog.php
<?php
class TailLog {
    private $log = "";
    private $updateTime;
    private $maxSizeToLoad;

    public function __construct($log, $defaultUpdateTime = 2000, $maxSizeToLoad = 2097152) {
        $this->log = $log;
        $this->updateTime = $defaultUpdateTime;
        $this->maxSizeToLoad = $maxSizeToLoad;
    }

    public function getNewLines($lastFetchedSize, $grepKeyword, $invert) {
        clearstatcache();

        $fsize = filesize($this->log);
        $maxLength = ($fsize - $lastFetchedSize);

        if($maxLength > $this->maxSizeToLoad) {
            return json_encode(array("size" => $fsize, "data" => array("ERROR: TailLog attempted to load more (".round(($maxLength / 1048576), 2)."MB) then the maximum size (".round(($this->maxSizeToLoad / 1048576), 2)."MB) of bytes into memory. You should lower the defaultUpdateTime to prevent this from happening. ")));
        }

        $data = array();
        if($maxLength > 0) {
            $fp = fopen($this->log, 'r');
            fseek($fp, -$maxLength , SEEK_END);
            $data = explode("\n", fread($fp, $maxLength));
        }

        if($invert == 0) {
            $data = preg_grep("/$grepKeyword/",$data);
        }
        else {
            $data = preg_grep("/$grepKeyword/",$data, PREG_GREP_INVERT);
        }

        if(end($data) == "") {
            array_pop($data);
        }

        return json_encode(array("size" => $fsize, "data" => $data));
    }

    public function generateGUI() {
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
            <title><?php echo basename($this->log); ?></title>
            <meta http-equiv="content-type" content="text/html;charset=utf-8" />

            <link type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/flick/jquery-ui.css" rel="stylesheet"></link>
            <style type="text/css">
              #grepKeyword, #settings {
                font-size: 80%;
              }
              .float {
                background: white;
                border-bottom: 1px solid black;
                padding: 10px 0 10px 0;
                margin: 0px;
                height: 30px;
                width: 100%;
                font-size: large;
                text-align: left;
              }
              #results {
                background: black;
                padding-bottom: 10px;
                font-family: monospace;
                font-size: large;
                color: green;
                white-space: pre;
              }
            </style>

            <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
            <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

            <script type="text/javascript">
              /* <![CDATA[ */
              //Last know size of the file
//              lastSize = <?php echo filesize($this->log); ?>;
              lastSize = 0;
              //Grep keyword
              grep = "";
              //Should the Grep be inverted?
              invert = 0;
              //Last known document height
              documentHeight = 0;
              //Last known scroll position
              scrollPosition = 0;
              //Should we scroll to the bottom?
              scroll = true;

              $(document).ready(function(){
                // Setup the settings dialog
                $( "#settings" ).dialog({
                  modal: true,
                  resizable: false,
                  draggable: false,
                  autoOpen: false,
                  width: 590,
                  height: 270,
                  buttons: {
                    Close: function() {
                      $( this ).dialog( "close" );
                    }
                  },
                  close: function(event, ui) {
                    grep = $("#grep").val();
                    invert = $('#invert input:radio:checked').val();
                    $("#grepspan").html("Grep keyword: \"" + grep + "\"");
                    $("#invertspan").html("Inverted: " + (invert == 1 ? 'true' : 'false'));
                  }
                });
                //Close the settings dialog after a user hits enter in the textarea
                $('#grep').keyup(function(e) {
                  if(e.keyCode == 13) {
                    $( "#settings" ).dialog('close');
                  }
                });
                //Focus on the textarea
                $("#grep").focus();
                //Settings button into a nice looking button with a theme
                $("#grepKeyword").button();
                //Settings button opens the settings dialog
                $("#grepKeyword").click(function(){
                  $( "#settings" ).dialog('open');
                  $("#grepKeyword").removeClass('ui-state-focus');
                });
                //Set up an interval for updating the log. Change updateTime in the TailLog contstructor to change this
                setInterval ( "updateLog()", <?php echo $this->updateTime; ?> );
                //Some window scroll event to keep the menu at the top
                $(window).scroll(function(e) {
                  if ($(window).scrollTop() > 0) {
                    $('.float').css({
                      position: 'fixed',
                      top: '0',
                      left: 'auto'
                    });
                  } else {
                    $('.float').css({
                      position: 'static'
                    });
                  }
                });
                //If window is resized should we scroll to the bottom?
                $(window).resize(function(){
                  if(scroll) {
                    scrollToBottom();
                  }
                });
                //Handle if the window should be scrolled down or not
                $(window).scroll(function(){
                  documentHeight = $(document).height();
                  scrollPosition = $(window).height() + $(window).scrollTop();

                  if(documentHeight <= scrollPosition) {
                    scroll = true;
                  }
                  else {
                    scroll = false;
                  }
                });

                scrollToBottom();
              });
              //This function scrolls to the bottom
              function scrollToBottom() {
                $('.ui-widget-overlay').width($(document).width());
                $('.ui-widget-overlay').height($(document).height());
                $("html, body").scrollTop($(document).height());

                if($( "#settings" ).dialog("isOpen")) {
                  $('.ui-widget-overlay').width($(document).width());
                  $('.ui-widget-overlay').height($(document).height());
                  $( "#settings" ).dialog("option", "position", "center");
                }
              }
              //This function queries the server for updates.
              function updateLog() {
                $.getJSON('?viewlog=yes&ajax=1&lastsize='+lastSize + '&grep='+grep + '&invert='+invert, function(data) {
                  lastSize = data.size;
                  $.each(data.data, function(key, value) {
                    $("#results").append('' + value + '<br/>');
                  });
                  if(scroll) {
                    scrollToBottom();
                  }
                });
              }
              /* ]]> */
            </script>
          </head>
          <body>
            <div id="settings" title="TailLog settings">
              <p>Grep keyword (return results that contain this keyword)</p>
              <input id="grep" type="text" value=""/>
              <p>Should the grep keyword be inverted? (Return results that do NOT contain the keyword)</p>
              <div id="invert">
                <input type="radio" value="1" id="invert1" name="invert" /><label for="invert1">Yes</label>
                <input type="radio" value="0" id="invert2" name="invert" checked="checked" /><label for="invert2">No</label>
              </div>
            </div>
            <div class="float">
              <button id="grepKeyword">Settings</button>
              <span>Tailing file: <?php echo $this->log; ?></span> | <span id="grepspan">Grep keyword: ""</span> | <span id="invertspan">Inverted: false</span>
            </div>
            <div id="results">
            </div>
          </body>
        </html>
        <?php
    }
}