Skip to content

Commit

Permalink
V2!!
Browse files Browse the repository at this point in the history
Migrate beta branch to master, master to master_v1...
  • Loading branch information
VaMaster committed May 3, 2018
1 parent 5632d91 commit 025d253
Show file tree
Hide file tree
Showing 362 changed files with 29,592 additions and 19,532 deletions.
40 changes: 18 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#################
## Ignore user-generated files
#################
/commands*
/config*
/composer.lock
/.idea/*
new_body.html
new_body.php
new_css/
new_img/
new_index.php
new_js/
/cacert.pem

/img/cache/
/manifest.json
/logs/*.log.php

rw/cacert.pem
rw/commands.php
rw/config.ini.php
#################
## Ignore user-generated files
#################
/commands*
/config*
/composer.lock
/.idea/*
/cacert.pem
/img/cache/
/manifest.json
/logs/*.log.php
/logs/*.log.old.php
/rw/config.ini.php
/rw/commands.php
/rw/cacert.pem
*.old
*.log.php
*.db.conf.php
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ If submitting a feature request, these are not required.

*BE SURE TO CHANGE ANY LINES CONTAINING API TOKENS OR OTHER PERSONAL IDENTIFYING INFORMATION*

#### 6. What are the last six digits of your server's API Token? (Settings -> Phlex)
#### 6. What are the last six digits of your server's API Token? (Settings -> Phlex)
129 changes: 63 additions & 66 deletions PHPTail.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ class PHPTail {
* @param integer $defaultUpdateTime The time between AJAX requests to the server.
* @param integer $maxSizeToLoad This variable holds the maximum amount of bytes this application can load into memory (in bytes). Default is 2 Megabyte = 2097152 byte
*/
public function __construct($log, $defaultUpdateTime = 1000, $maxSizeToLoad = 2097152,$token) {
public function __construct($log, $defaultUpdateTime = 1000, $maxSizeToLoad = 2097152,$token,$noHeader=false) {
$this->log = is_array($log) ? $log : array($log);
$this->updateTime = $defaultUpdateTime;
$this->maxSizeToLoad = $maxSizeToLoad;
$this->apiToken = $token;
$this->count = 0;
$this->noHeader = $noHeader;
}

function json_validate($string)
Expand All @@ -51,45 +52,17 @@ function json_validate($string)
// switch and check possible JSON errors
switch (json_last_error()) {
case JSON_ERROR_NONE:
$error = ''; // JSON is valid // No error has occurred
break;
case JSON_ERROR_DEPTH:
$error = 'ERROR11: The maximum stack depth has been exceeded.';
break;
case JSON_ERROR_STATE_MISMATCH:
$error = 'ERROR11: Invalid or malformed JSON.';
break;
case JSON_ERROR_CTRL_CHAR:
$error = 'ERROR11: Control character error, possibly incorrectly encoded.';
break;
case JSON_ERROR_SYNTAX:
$error = 'ERROR11: Syntax error, malformed JSON.';
break;
// PHP >= 5.3.3
case JSON_ERROR_UTF8:
$error = 'ERROR11: Malformed UTF-8 characters, possibly incorrectly encoded.';
break;
// PHP >= 5.5.0
case JSON_ERROR_RECURSION:
$error = 'ERROR11: One or more recursive references in the value to be encoded.';
break;
// PHP >= 5.5.0
case JSON_ERROR_INF_OR_NAN:
$error = 'ERROR11: One or more NAN or INF values in the value to be encoded.';
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$error = 'ERROR11: A value of a type that cannot be encoded was given.';
$error = false;
break;
default:
$error = 'ERROR11: Unknown JSON error occured.';
$error = true;
break;
}

if ($error !== '') {
return $error;
if ($error) {
return false;
}

// everything is OK
return $result;
}

Expand Down Expand Up @@ -142,11 +115,12 @@ public function getNewLines($file, $lastFetchedSize, $grepKeyword, $invert,$coun
else {
$data = preg_grep("/$grepKeyword/",$data, PREG_GREP_INVERT);
}
//if(preg_match("/Phlex.log/",$file)) {
$newData = [];

$i = 0;
if (!$count) $count = 0;
$l = 0;
$newData = [];
foreach($data as $line) {
if (!trim($line)) continue;
if ($i === 0) {
$i = 1;
$linecolor = "white";
Expand All @@ -157,28 +131,42 @@ public function getNewLines($file, $lastFetchedSize, $grepKeyword, $invert,$coun
$authString = "; <?php die('Access denied'); ?>".PHP_EOL;
$line = str_replace($authString,"",$line);
$og = $line;
$level = explode("] [",$line)[1] ?? "INFO";
$level = "DEBUG";
if (strpos($line,"[ERROR]") !== false || strpos($line,"[php7:error]") !== false) $level = "ERROR";
if (strpos($line,"[INFO]") !== false || strpos($line,"[php7:notice]") !== false) $level = "INFO";
if (strpos($line,"[WARN]") !== false || strpos($line,"[php7:warn]") !== false) $level = "WARN";
if (strpos($line,"[ALERT]") !== false || strpos($line,"[php7:alert]") !== false) $level = "ALERT";
$og = urlencode($og);
$substr = explode(": ",$line);
unset($substr[0]);
$substr = implode(": ",$substr);
try {
if (count($substr) >= 2) {
unset($substr[0]);
$substr = implode(": ", $substr);
$test = $this->json_validate($substr);
if ($test) {
$json = json_encode($test) ?? false;
if ($json !== "null" && (!preg_match("/ERROR11/", $json))) {
$jsonLink = '<a href="" class="jsonParse" title="' . htmlentities($json) . '" data-json="' . urlencode($json) . '">[JSON]</a>';
$line = str_replace($substr, $jsonLink, $line);
$og = htmlentities($json);
}
}
}

if (preg_match('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $line, $match)) {
$link = "<a href='$match[0]' target='_blank'>$match[0]</a>";
$line = str_replace($match[0],$link,$line);
}
$test = $this->json_validate($substr);
if ($test) {
$json = json_encode($test) ?? false;
}
preg_match('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $line, $match);
if (isset($match[0])) {
$parts = htmlentities(json_encode(parse_url($match[0])));
$link = "<a href='$match[0]' title='$parts' target='_blank'>$match[0]</a>";
$line = str_replace($match[0], $link, $line);
$og = $parts;
}
} catch (Exception $e) {

}
$line = "<span class='lineNo'>$l</span><span class='$level $linecolor logSpan' data-text='$og'>$line</span>";
array_push($newData, $line);
$l++;

if ($json !== "null" && (!preg_match("/ERROR11/",$json))) {
$jsonLink = '<a href="" class="jsonParse" title="'.urlencode($json).'" data-json="'.urlencode($json).'">[JSON]</a>';
$line = str_replace($substr, $jsonLink, $line);
}
$line = "<span class='lineNo'>$count</span><span class='$level $linecolor logSpan' data-text='".urlencode($og)."'>$line</span>";
array_push($newData,$line);
$count++;
}
$data = $newData;
//}
Expand Down Expand Up @@ -252,14 +240,20 @@ public function generateGUI() {
.DEBUG {
color: #007900;
}

.ALERT {
color: #ffffff;
background-color: black !important;
}

.ERROR {
color:red;
}
.INFO {
color:blue;
}
.grey {
background-color:#d3d3d37d;
background-color: rgb(223, 223, 223);
}
.white {
background-color:white;
Expand Down Expand Up @@ -315,14 +309,16 @@ public function generateGUI() {
gotoUrl("http://jsonselector.com/process",{'rawjson':data});
});

$(document).on('dblclick', '.logSpan',function(e) {
$(document).on('dblclick', '.logSpan',function() {
var data = $(this).data('text');
console.log("Data: ",data);
data = decodeURIComponent(data);
data = data.replace(/\+/g, ' ');
console.log("Span clicked! ",data);
data = data.split(" - ")[1];
clipboard.copy(data);
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute("id", "dummy_id");
document.getElementById("dummy_id").value=JSON.stringify(data);
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
});

// Setup the settings dialog
Expand Down Expand Up @@ -420,10 +416,11 @@ function updateLog() {
fileParts = fileParts.split("/");
fileParts = fileParts[fileParts.length - 1];
$(".navbar-brand").text(fileParts);
console.log("Navbar name should be " + fileParts);
$.each(data.data, function(key, value) {
$("#results").append('' + value + "\n");
});
if (data.data != null) {
$.each(data.data, function (key, value) {
$("#results").append('' + value + "\n");
});
}
if (scroll) {
scrollToBottom();
}
Expand Down Expand Up @@ -473,7 +470,7 @@ function gotoUrl(path, params, method) {
</script>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar navbar-default navbar-fixed-top" role="navigation" <?php if ($this->noHeader) echo 'style="display:none"'?>>
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Phlex.log</a>
Expand Down
Loading

0 comments on commit 025d253

Please sign in to comment.