Files
resatennis_tyroltenn/IDrive/.config/viewLog.php

275 lines
9.5 KiB
PHP
Executable File

<?php
include_once 'path.php';
session_write_close();
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST["FILE_NAME"]) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
if(!$_SESSION['validUser']){
echo "Session Expired";
exit;
}
$decodedPath = rawurldecode($_POST["FILE_NAME"]);
if(strpos($decodedPath,Scheduler::$user_dir)!==0 || !strpos($decodedPath,'/LOGS/')>0 ){
echo "invalid path";
exit;
}
$file_to_read = getUpdatedLogFileName($decodedPath);
if(isset($_POST["currentPage"])){
$currentPage = $_POST["currentPage"];
if($file_to_read)
{
$outputArray = array();
$outputArray = readFileChunkByChunk($file_to_read, $_POST['offset'], $_POST['readCount'],$currentPage);
echo nl2br($outputArray['data']);
?>
<script>
setLogVariables(<?php echo $outputArray['offset']?>,'','<?php echo $outputArray['stop'] ?>',<?php echo $outputArray['readCount'] ?>);
</script>
<?php
}
}
elseif(isset($_POST["updateDownloadLink"])){
$status = getLogStatus($file_to_read);
if($machine=='twotier')
$linkName = "/Downloads/".createOrVerifyOrDeleteLink($file_to_read);
else
$linkName = "../Downloads/".createOrVerifyOrDeleteLink($file_to_read);
$output = array("link"=>$linkName,"stop"=>$status['stop']);
header('Content-Type: application/json');
echo json_encode($output);
}
exit;
}
if(!$_SESSION['validUser'])
{
$destinationURL = "../index.php";
header("Location:$destinationURL");
exit;
}
if($_GET["FILE_NAME"])
{
$logFileNameGetString = $_GET["FILE_NAME"];
$decodedPath = rawurldecode($logFileNameGetString);
if(strpos($decodedPath,Scheduler::$user_dir)!==0 || !strpos($decodedPath,'/LOGS/')>0 ){
$destinationURL = "../index.php";
header("Location:$destinationURL");
exit;
}
machineBasedContent($machine);
$file_to_read = "";
$file_to_read = getUpdatedLogFileName($decodedPath);
} else {
exit;
}
$js_version = trim(preg_replace('/[a-zA-Z]+/', '', $appVersion));
?>
<html>
<head>
<meta charset="UTF-8">
<title><?php print $appMetaTitle;?></title>
<script src="include/scripts/1.7.2.jquery.min.js"></script>
<link href="include/css/qnap_layout.css?ver=<?php echo $js_version;?>" type="text/css" rel="stylesheet" />
<link href="include/css/<?php print $appThemeCSS;?>?ver=<?php echo $js_version;?>" type="text/css" rel="stylesheet" />
<link rel="icon" href="include/images/<?php print $appFavicon;?>" sizes="16x16" />
<link rel="shortcut icon" href="include/images/<?php print $appFavicon;?>" type="image/x-icon" />
<script>
var chunkSize = 0;
var OffsetLog = 0;
var logfileName = '<?php echo rawurlencode($file_to_read) ?>';
var stop = "";
var readCount = 0;
var currentPage = "first";
var ajaxRequest = "";
function setLogVariables(offset,logfile,stopFlag,readcount)
{
if(offset!=0)OffsetLog = offset;
if(logfile)logfileName = logfile;
if(stopFlag!="")stop = stopFlag;
if(readcount!="")readCount = readcount;
}
function loadLog(fromButton){
$("#loader-div").hide();
var loader = "<div id='loader_img' align=center><img src='include/images/qnap_loader_40.gif'/></div>";
$("#loader-div").show();
if(fromButton){
readCount = 0;
}
ajaxRequest = $.ajax({
type:"POST",
url:"viewLog.php",
data:{"offset":OffsetLog,"FILE_NAME":logfileName,"readCount":readCount,"currentPage":currentPage},
success: function(output){
$("#loader-div").hide();
if(output == "Session Expired" || output == "invalid path")
{
window.location="index.php";
}
else if(output)
{
if(fromButton) $(".report-wrapper").html("");
$(".report-wrapper").append(output);
}
updatePagination();
}
});
}
function updatePagination(){
$("#loader-div").hide();
if(stop == 0 ){
if((currentPage == "next"|| currentPage == "last"))
$("#previous,#first").removeClass('disableBtn');
loadLog();
}
else if(stop == 1 && currentPage == "first")
{
$("#next,#last").removeClass('disableBtn');
}
else if(stop == 2 && currentPage == "first")
{
$(".navsection").hide();
}
else if(stop== 1 && currentPage != "first")
{
$("#next,#last,#previous,#first").removeClass('disableBtn');
}
else if(stop== 2 && (currentPage == "next" || currentPage == "last"))
{
$("#previous,#first").removeClass('disableBtn');
}
}
$(function(){
if( 400 <= window.innerHeight ){ $('.report-wrapper').css('height',parseInt(window.innerHeight)- parseInt(285)); }
$(window).resize(function(){ if( 400 <= window.innerHeight ){ $('.report-wrapper').css('height',parseInt(window.innerHeight)- parseInt(285)); } });
$("#previous,#next,#first,#last").click(function(){
clickedButton = $(this).attr('id');
if(!$("#"+clickedButton).hasClass('disableBtn')){
if(ajaxRequest)
ajaxRequest.abort();
$("#next,#last,#previous,#first").addClass('disableBtn');
currentPage = clickedButton;
if(clickedButton == "first")
OffsetLog = 0;
else if(clickedButton == "previous"){
OffsetLog = OffsetLog - (readCount+chunkSize);
if(OffsetLog < 0){
OffsetLog = 0;
currentPage = "first";
}
}
else if(clickedButton == "next" || clickedButton == "last")
$("#previous,#first").removeClass('disableBtn');
loadLog(1);
}
});
});
updateDownloadLink();
var hasFile = true;
function updateDownloadLink()
{
$.ajax({
type:"POST",
url:"viewLog.php",
data:{"FILE_NAME":logfileName,"updateDownloadLink":1},
success: function(output){
if(output == "Session Expired" || output == "invalid path"){
window.location="index.php";
}
$("#downloadLink").removeAttr('href');
$("#downloadLink").attr('href',output.link);
if(output.stop != 2 && hasFile)
setTimeout(function(){updateDownloadLink();},5000);
}
});
}
</script>
</head>
<body>
<section class="body view_page">
<div class="wrapper">
<h1 style="height:90px;" >
<a class="<?php print $logoClassName; ?>" href="javascript:void(0)"><?php print $appMetaTitle;?></a>
<p class="version"><?php print $appVersion;?></p>
</h1>
<section class="view_content"><div class="download_log"><h2>View Log Report</h2><a class="downloadButton" id="downloadLink" oncontextmenu="return false" download href="javascript:;">Download Log report</a>
</div>
<div class="viewContent_wrap">
<div class="report-wrapper">
<div class="report-wrapper-inner">
<?php
if($file_to_read){
$outputArray = readFileChunkByChunk($file_to_read,0,0);
if($machine=='twotier')
$linkName = "/Downloads/".createOrVerifyOrDeleteLink($file_to_read);
else
$linkName = "../Downloads/".createOrVerifyOrDeleteLink($file_to_read);
echo nl2br(htmlentities($outputArray['data']));
?>
<script>
$("#downloadLink").attr('href','<?php echo $linkName ?>');
chunkSize = <?php echo CHUNK_SIZE ?>;
setLogVariables(<?php echo $outputArray['offset']?>,'<?php echo rawurlencode($file_to_read) ?>','<?php echo $outputArray['stop'] ?>',<?php echo $outputArray['readCount'] ?>);
setTimeout(function(){updatePagination();},1);
</script>
<?php
}
else{
echo "<br>Log file does not exist";
?>
<script>
hasFile = false;
$("#downloadLink").remove();
setLogVariables('','',2,'');
</script>
<?php
}
?>
</div>
</div>
</div>
<?php if($file_to_read){ ?>
<div class="navsection"><div>
<div class="loading-report" id="loader-div"> <span class="lr-img">
<img src="include/images/loading.gif" height="23" width="40" alt="loader"></span>
<span class="lr-text">Loading...</span>
</div>
<div class="pagination-wrapper">
<a class ="disableBtn" id="first">First</a>
<a class="previous disableBtn" id="previous">Previous</a>
<a class="next disableBtn" id="next">Next</a>
<a class="disableBtn" id="last" >Last</a></div></div></div>
<?php } ?>
</section>
<footer>&copy; IDrive Inc.</footer>
</div> <!-- End Wrapper -->
</section> <!-- End body -->
</body>
</html>