PHP TAIL LOG: Send text field to js then to PHP
Posted: Thu Oct 16, 2014 10:29 am
Hi.
I am working on modifying this AJAX Logfile Tailer & Viewerhttp://commavee.com/2007/04/13/ajax-log ... er-viewer/.
Working Example: https://freepository.com/ajax-logtail-v ... viewer.php
I want to add an input tex field where I can write the log file name that I want it to read.
In the html file there is a button that starts the viewer, the button calls a javascript function:
This is the button code:
This is the javascript file that has the function the button calls:
I modified the button that calls the function so it takes the text field value and passes it to the javascript getLog() function this way:
Then modified the function so it takes the second parameter:
Now, that function calls the ajax-logtail.php file that has this content:
Because I wanted this php file to get the text field value in the html I modified it this way:
Then, after all that modified fields Im unable to pass the field text value to the ajax-logtail.php.
When I execute it chrome says:
[text]Uncaught SyntaxError: Unexpected token } , line 16 of file logtail.php[/text]
This is the contend of that line and some others before it:
Can anyone help me identify the problem?
I am working on modifying this AJAX Logfile Tailer & Viewerhttp://commavee.com/2007/04/13/ajax-log ... er-viewer/.
Working Example: https://freepository.com/ajax-logtail-v ... viewer.php
I want to add an input tex field where I can write the log file name that I want it to read.
Code: Select all
<input type="text" id="filename"></input>This is the button code:
Code: Select all
<button onclick="getLog('start');">Start Viewer</button>Code: Select all
/* ajax utilit function from b. mclaughlin */
function createRequest() {
var request = null;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
if (request == null) {
alert("Error creating request object!");
} else {
return request;
}
}
var request = createRequest();
/* an ajax log file tailer / viewer
copyright 2007 john minnihan.
http://freepository.com
Released under these terms
1. This script, associated functions and HTML code ("the code") may be used by you ("the recipient") for any purpose.
2. This code may be modified in any way deemed useful by the recipient.
3. This code may be used in derivative works of any kind, anywhere, by the recipient.
4. Your use of the code indicates your acceptance of these terms.
5. This notice must be kept intact with any use of the code to provide attribution.
*/
function getLog(timer) {
var url = "ajax-logtail.php";
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
startTail(timer);
}
function startTail(timer) {
if (timer == "stop") {
stopTail();
} else {
t= setTimeout("getLog(10)",1000);
}
}
function stopTail() {
clearTimeout(t);
var pause = "The log viewer has been paused. To begin viewing again, click the Start Viewer button.\n";
logDiv = document.getElementById("log");
var newNode=document.createTextNode(pause);
logDiv.replaceChild(newNode,logDiv.childNodes[0]);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
var currentLogValue = request.responseText.split("\n");
eval(currentLogValue);
logDiv = document.getElementById("log");
var logLine = ' ';
for (i=0; i < currentLogValue.length - 1; i++) {
logLine += currentLogValue[i] + "<br/>\n";
}
logDiv.innerHTML=logLine;
} else {
alert("Error! Request status is " + request.status);
}
}
}
Code: Select all
<button onclick="getLog('start',document.getElementById("filename").value);">Start Viewer</button>Code: Select all
function getLog(timer,filename) {
var url = "ajax-logtail.php?"+"filename="+filename;
request.open("GET", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = updatePage;
request.send(null);
startTail(timer);
}Code: Select all
<? // logtail.php
$cmd = "tail -10 some.log";
exec("$cmd 2>&1", $output);
foreach($output as $outputline) {
echo ("$outputline\n");
}
?>
Code: Select all
<?
if(isset($_POST)){
$cmd = "tail -10 " . $_POST['filename'];
}
elseif (isset($_GET)){
$cmd = "tail -10 " . $_GET['filename'];
}
else {
$cmd = "tail -10 logfile.log";
}
exec("$cmd 2>&1", $output);
foreach($output as $outputline) {
echo ("$outputline\n");
}
?>
When I execute it chrome says:
[text]Uncaught SyntaxError: Unexpected token } , line 16 of file logtail.php[/text]
This is the contend of that line and some others before it:
Code: Select all
<div>
<button onclick="getLog('start',document.getElementById("filename").value);">Start Viewer</button>
<button onclick="stopTail();">Stop Viewer</button>
</div>