From 761c64b93f1030fe93319eab7d00bc83124ffd4e Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Fri, 6 Sep 2019 12:09:55 +0200
Subject: [PATCH] added comments, remove unnecessairy files

---
 classes/cronlog-renderer.class.php |  36 +++++++--
 classes/cronlog.class.php          |  33 +++++++-
 config/inc_cronlog.php.dist        |  14 +++-
 get.php                            |  32 +++++++-
 index.html                         |   5 +-
 js/functions.min.js                |   2 -
 main.css                           |   8 +-
 main.min.css                       |   2 -
 viewer.php                         | 119 -----------------------------
 9 files changed, 107 insertions(+), 144 deletions(-)
 delete mode 100644 js/functions.min.js
 delete mode 100644 main.min.css
 delete mode 100644 viewer.php

diff --git a/classes/cronlog-renderer.class.php b/classes/cronlog-renderer.class.php
index 7b3d175..5fab6ca 100644
--- a/classes/cronlog-renderer.class.php
+++ b/classes/cronlog-renderer.class.php
@@ -1,12 +1,37 @@
 <?php
 require_once 'cronlog.class.php';
 /**
- * central cronlog viewer
+ * ______________________________________________________________________
  * 
- * cronlog-renderer contains visual methods to render html
+ *  _____                 _       _             _                        
+ * /  __ \               (_)     | |           (_)                       
+ * | /  \/_ __ ___  _ __  _  ___ | |__   __   ___  _____      _____ _ __ 
+ * | |   | '__/ _ \| '_ \| |/ _ \| '_ \  \ \ / / |/ _ \ \ /\ / / _ \ '__|
+ * | \__/\ | | (_) | | | | | (_) | |_) |  \ V /| |  __/\ V  V /  __/ |   
+ *  \____/_|  \___/|_| |_| |\___/|_.__/    \_/ |_|\___| \_/\_/ \___|_|   
+ *                      _/ |                                             
+ *                     |__/                                              
+ * ______________________________________________________________________
+ * 
+ * The cronjob viewer for centralized monitoring of cronjobs using
+ * Axels cronrwapper (see <https://github.com/axelhahn/cronwrapper>).
+ * 
+ * You can browse all servers to see 
+ * - the last status of all cronjobs
+ * - results an execution times of running jonbs
+ * - a timeline for all jobs running > 60s
+ * 
+ * 
+ * Free software. Open Source. GNU GPL 3.
+ * SOURCE: <https://git-repo.iml.unibe.ch/iml-open-source/cronlog-viewer>
+ * 
+ * ______________________________________________________________________
+ * 
+ * The class cronlog-renderer contains visual methods to render html
  * @see cronlog.class.php
  *
- * @author hahn
+ * @license GNU GPL 3.0
+ * @author Axel Hahn <axel.hahn@iml.unibe.ch>
  */
 class cronlogrenderer extends cronlog{
 
@@ -49,7 +74,6 @@ class cronlogrenderer extends cronlog{
         if(!$aData){
             $aData=$this->getServersLastLog();
         }
-        // $sHtml='DEBUG: <pre>'.print_r($aData, 1).'</pre>';
 
         $sTblHead='';
         $iOK=0;
@@ -156,7 +180,6 @@ class cronlogrenderer extends cronlog{
             $aData=array_merge($aData, $this->getServersLastLog());
         }
         $this->setServer('ALL');
-        // echo '<pre>'.print_r($aData, 1).'</pre>';
         return $this->renderCronlogs($aData);
     }
     
@@ -190,7 +213,6 @@ class cronlogrenderer extends cronlog{
                 }
             }
             $iLast=max(array($iLast, date("U", $aEntry['start'])));
-            // $sViewerUrl='viewer.php?host='.$aEntry['host'].'&job='.$aEntry['job'];
             $sClass='message-'.($aEntry['rc']?'error':'ok');
             
             if($aEntry['rc']){
@@ -264,7 +286,6 @@ class cronlogrenderer extends cronlog{
             $aData=array_merge($aData, $this->getServerJobHistory());
         }
         $this->setServer('ALL');
-        // echo '<pre>'.print_r($aData, 1).'</pre>';
         return $this->renderJoblist($aData);
     }
     
@@ -392,7 +413,6 @@ class cronlogrenderer extends cronlog{
             $aData=array_merge($aData, $this->getServerJobHistory());
         }
         $this->setServer('ALL');
-        // echo '<pre>'.print_r($aData, 1).'</pre>';
         return $this->renderJobGraph($aData);
     }
     
diff --git a/classes/cronlog.class.php b/classes/cronlog.class.php
index 2d1ce52..d700bdf 100644
--- a/classes/cronlog.class.php
+++ b/classes/cronlog.class.php
@@ -1,11 +1,36 @@
 <?php
 /**
- * central cronlog viewer
+ * ______________________________________________________________________
  * 
- * cronlog contains non visual methods
+ *  _____                 _       _             _                        
+ * /  __ \               (_)     | |           (_)                       
+ * | /  \/_ __ ___  _ __  _  ___ | |__   __   ___  _____      _____ _ __ 
+ * | |   | '__/ _ \| '_ \| |/ _ \| '_ \  \ \ / / |/ _ \ \ /\ / / _ \ '__|
+ * | \__/\ | | (_) | | | | | (_) | |_) |  \ V /| |  __/\ V  V /  __/ |   
+ *  \____/_|  \___/|_| |_| |\___/|_.__/    \_/ |_|\___| \_/\_/ \___|_|   
+ *                      _/ |                                             
+ *                     |__/                                              
+ * ______________________________________________________________________
+ * 
+ * The cronjob viewer for centralized monitoring of cronjobs using
+ * Axels cronrwapper (see <https://github.com/axelhahn/cronwrapper>).
+ * 
+ * You can browse all servers to see 
+ * - the last status of all cronjobs
+ * - results an execution times of running jonbs
+ * - a timeline for all jobs running > 60s
+ * 
+ * 
+ * Free software. Open Source. GNU GPL 3.
+ * SOURCE: <https://git-repo.iml.unibe.ch/iml-open-source/cronlog-viewer>
+ * 
+ * ______________________________________________________________________
+ * 
+ * The cronlog class contains non visual methods
  * @see cronlog-renderer.class.php
  *
- * @author hahn
+ * @license GNU GPL 3.0
+ * @author Axel Hahn <axel.hahn@iml.unibe.ch>
  */
 
 class cronlog {
@@ -238,7 +263,7 @@ class cronlog {
             while (($line = fgets($fileHandle)) !== false) {
                 // send the current file part to the browser
                 $aData=$this->_parseJoblogLine($line);
-                if($bUseSkip && array_search($aData['job'], $this->_aSkipJoblogs)===false){
+                if(!$bUseSkip || array_search($aData['job'], $this->_aSkipJoblogs)===false){
                     $aReturn[$aData['start']]=$aData;
                 }
             }
diff --git a/config/inc_cronlog.php.dist b/config/inc_cronlog.php.dist
index a430a77..37c407c 100644
--- a/config/inc_cronlog.php.dist
+++ b/config/inc_cronlog.php.dist
@@ -1,5 +1,17 @@
 <?php
 /**
+ * ______________________________________________________________________
+ * 
+ *  _____                 _       _             _                        
+ * /  __ \               (_)     | |           (_)                       
+ * | /  \/_ __ ___  _ __  _  ___ | |__   __   ___  _____      _____ _ __ 
+ * | |   | '__/ _ \| '_ \| |/ _ \| '_ \  \ \ / / |/ _ \ \ /\ / / _ \ '__|
+ * | \__/\ | | (_) | | | | | (_) | |_) |  \ V /| |  __/\ V  V /  __/ |   
+ *  \____/_|  \___/|_| |_| |\___/|_.__/    \_/ |_|\___| \_/\_/ \___|_|   
+ *                      _/ |                                             
+ *                     |__/                                              
+ * ______________________________________________________________________
+ * 
  * CONFIG FILE
  * 
  * it is included by classes/cronlog.class.php
@@ -14,7 +26,7 @@ return array(
     // when show an error for expired jobs (latency to execute job and sync logs)
     'iExpiredJobsFailAfter'=>60*30,
 
-    // hide these cronjob labels in the web gui
+    // hide these cronjob labels in the web gui tab "history"
     'aHidelogs'=>array(
         'copycronlogs',
     )
diff --git a/get.php b/get.php
index 46babda..e786ffe 100644
--- a/get.php
+++ b/get.php
@@ -1,9 +1,35 @@
 <?php
-/* ======================================================================
+/**
+ * ______________________________________________________________________
  * 
- * CRONJOB VIEWER :: AJAX HELPER
+ *  _____                 _       _             _                        
+ * /  __ \               (_)     | |           (_)                       
+ * | /  \/_ __ ___  _ __  _  ___ | |__   __   ___  _____      _____ _ __ 
+ * | |   | '__/ _ \| '_ \| |/ _ \| '_ \  \ \ / / |/ _ \ \ /\ / / _ \ '__|
+ * | \__/\ | | (_) | | | | | (_) | |_) |  \ V /| |  __/\ V  V /  __/ |   
+ *  \____/_|  \___/|_| |_| |\___/|_.__/    \_/ |_|\___| \_/\_/ \___|_|   
+ *                      _/ |                                             
+ *                     |__/                                              
+ * ______________________________________________________________________
  * 
- * ======================================================================
+ * The cronjob viewer for centralized monitoring of cronjobs using
+ * Axels cronrwapper (see <https://github.com/axelhahn/cronwrapper>).
+ * 
+ * You can browse all servers to see 
+ * - the last status of all cronjobs
+ * - results an execution times of running jonbs
+ * - a timeline for all jobs running > 60s
+ * 
+ * 
+ * Free software. Open Source. GNU GPL 3.
+ * SOURCE: <https://git-repo.iml.unibe.ch/iml-open-source/cronlog-viewer>
+ * 
+ * ______________________________________________________________________
+ * 
+ * AJAX HELPER
+ *
+ * @license GNU GPL 3.0
+ * @author Axel Hahn <axel.hahn@iml.unibe.ch>
  */
 
 require_once 'classes/cronlog-renderer.class.php';
diff --git a/index.html b/index.html
index 30ecf2e..35905b6 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,10 @@
     <head>
         <meta charset="utf-8" />
         <meta http-equiv="Pragma" content="no-cache">
+        <meta name="robots" content="noindex,nofollow">
+
         <title>Cronjob-Viewer</title>
+        
         <script type="text/javascript" src="vendor/jquery/3.2.1/jquery.min.js"></script>
         <script type="text/javascript" src="js/asimax.class.js"></script>
         <script type="text/javascript" src="js/functions.js"></script>
@@ -19,7 +22,7 @@
     </head>
     <body>
         <div id="errorlog"></div>
-        <span style="float: right">Coded by Axel in 2018 :-)</span>
+        <span style="float: right">&copy; 2018 -2019</span>
         <h1><a href="?"><span class="imllogo"></span> CronjobViewer</a></h1>
         <nav class="servers">
             <div id="selectserver" class="active">...</div>
diff --git a/js/functions.min.js b/js/functions.min.js
deleted file mode 100644
index 12bcd19..0000000
--- a/js/functions.min.js
+++ /dev/null
@@ -1,2 +0,0 @@
-/* https://www.axel-hahn.de/ */
-var sMyServer=false;var oMapHtml2Api={crontable:"crontable",graph:"graph",selectServer:"selectserver"};function getPageItem(c){var b="get.php";$("#"+c).css("opacity","0.2");var a="item="+oMapHtml2Api[c]+"&server="+sMyServer;jQuery.ajax({url:b,data:a,type:"GET",success:function(d){$("#"+c).css("opacity","1");$("#"+c).html(d)},error:function(){$("#"+c).css("opacity",false);$("#"+c).html("Failed :-/");$("#errorlog").html($("#errorlog").html()+'AJAX error: <a href="'+b+"?"+a+'">'+b+"?"+a+"</a><br><br>")}})}function setServer(a){sMyServer=a;$("#lblServername").html(sMyServer);getPageItem("crontable")};
\ No newline at end of file
diff --git a/main.css b/main.css
index 9807c96..d9bf2bf 100644
--- a/main.css
+++ b/main.css
@@ -4,7 +4,7 @@
 
 a {color: #38a;text-decoration: none;}
 a:hover {text-decoration: underline;}
-body{background:#fff; color:#456; font-family: verdana,arial; font-size:1.0em;}
+body{background:#fff; color:#456; font-family: verdana,arial; font-size:1.0em; margin: 0;}
 button{background:#46a; border: none; color:#fff; padding: 0.5em 1em; border-radius: 0.3em; border: 2px solid rgba(0,0,0,0.1); box-shadow: 0.2em 0.2em 0.5em #aaa;}
 button.add{background:#8c8;}
 button.del{background:#c88;}
@@ -14,7 +14,7 @@ button:active{box-shadow: none; }
 footer{background: rgba(0,60,60,0.05); border-top: 1px solid #ccc; padding: 1em; margin-top: 5em;}
 footer a{color:#678;}
 
-h1{border-bottom: 1px solid #cde;}
+h1{border-bottom: 1px solid #cde; background:#eee; margin: 0 0 0.3em; padding: 1em 0.3em;}
 h1 a{color: #38a;}
 h1 a:hover{text-decoration: none;}
 h2{color:#379;}
@@ -25,14 +25,14 @@ i.fa{font-size: 150%; }
 i.fa.lookup{font-size: 100%; opacity: 0.4;}
 
 nav.servers{float: left; margin-right: 1em;}
-#selectserver{min-height: 20em; border-right: 1px dashed #cde;}
+#selectserver{min-height: 20em; border-right: 2px dashed #cde;}
 
 nav.tabs a{display: block; float: left; background: rgba(0,60,60,0.05); padding: 0.5em 1em; color:#345; text-decoration: none; margin-right: 2px; border-top: 4px solid rgba(0,0,0,0.01);}
 nav.tabs a.active{background: #d0e0e0; border-color: rgb(255,0,51); }
 nav.tabs a:hover{border-color: #abc;}
 
 input{border: 1px solid #ddd; padding: 0.3em;}
-option{font-family: verdana,arial; font-size:1.0em; }
+option{font-family: verdana,arial; font-size:1.2em; }
 option:hover{background: #eee;}
 select{border: 0;}
 
diff --git a/main.min.css b/main.min.css
deleted file mode 100644
index c5bbbd3..0000000
--- a/main.min.css
+++ /dev/null
@@ -1,2 +0,0 @@
-/* https://www.axel-hahn.de/ */
-a{color:#38a;text-decoration:none}a:hover{text-decoration:underline}body{background:#fff;color:#456;font-family:verdana,arial;font-size:1.0em}button{background:#468;border:0;color:#fff;padding:.5em 1em;border-radius:.3em;border:1px solid rgba(0,0,0,0.1)}button.add{background:#8c8}button.del{background:#c88}button:hover{background:#cde;color:#000}footer{background:rgba(0,60,60,0.05);border-top:1px solid #ccc;padding:1em;margin-top:5em}footer a{color:#678}i.fa{font-size:150%}i.fa.lookup{font-size:100%;opacity:.4}nav{margin-right:1em}option{font-family:verdana,arial;font-size:1.0em}table{border:1px solid #ccc}tr:hover{background:#eee}th{background:#abc;padding:.5em}td{padding:.3em}.imllogo:before{background:#f03;color:#fff;padding:.5em .3em;content:'IML';font-family:"arial";text-shadow:none}.message{border:1px solid rgba(0,0,0,0.1);padding:1em;float:right}.message-ok{background:#cfc;color:#080}.message-error{background:#fee;color:#800}.vis-item.timeline-result-error{background:#fcc;border-color:#800}.vis-item.timeline-result-ok{background:#cfc;border-color:#080}
\ No newline at end of file
diff --git a/viewer.php b/viewer.php
deleted file mode 100644
index 3228296..0000000
--- a/viewer.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/*
-    Axels simpler Fileviewer fuer Cronwrapper-Logs
-*/
-?>
-<?php
-$mybasedir=$_SERVER["DOCUMENT_ROOT"]."/cronlogs";
-
-/**
-  * im Cronwrapper Output den Wert eines Schlüsselwortes holen
-  * @return string
-  */
-function parse($sData, $sKeyword){
-    $sReturn='';
-    $sPattern='/\n'.$sKeyword.'=(.*)/';
-    preg_match_all($sPattern, $sData, $aMatches);
-    if (array_key_exists("1", $aMatches)) {
-        foreach ($aMatches[1] as $key=>$value) $sReturn.=$value . "\n";
-    }
-    return trim($sReturn);
-}
-
-// ------------------------------------------------------------
-// Dateiname holen
-// ------------------------------------------------------------
-
-if (!array_key_exists("file", $_GET)){
-    die("no file was detected in the url.");
-}
-$myfile=$_GET["file"];
-
-if (strpos(" ".$myfile, "..")){
-    echo "Sorry, the .. is not allowed.<br>";
-    die();
-}
-if (!file_exists($mybasedir."/".$myfile) || !is_file($mybasedir."/".$myfile)) {
-    echo "Sorry. File not found: $myfile<br>";
-    die();
-}
-
-// ------------------------------------------------------------
-// Ausgabe zusammenbauen
-// ------------------------------------------------------------
-$sHtml='';
-
-$sType="text";
-$sData=file_get_contents($mybasedir."/".$myfile);
-
-$sScript=parse($sData, "SCRIPTNAME");
-if ($sScript) $sType="cronlog";
-
-switch ($sType) {
-    case "cronlog":
-        $rc=parse($sData, "SCRIPTRC");        
-        $iExpire=parse($sData, "JOBEXPIRE");
-
-
-        $sClassRc='error'; if ($rc==0) $sClassRc='ok';
-        $sClassExp='error'; if ($iExpire>date("U")) $sClassExp='ok';
-
-        if ($rc==0 && $iExpire>date("U")) {
-            $sHtml.='<div class="ok">Cronjob ist OK.';
-        } else {
-            $sHtml.='<div class="error">Fehler gefunden.';
-            $sHtml.='&nbsp;&nbsp;&nbsp;<span class="'.$sClassRc.'">returncode: '.$rc.'</span>';
-        }
-        $sHtml.='&nbsp;&nbsp;&nbsp;<span class="'.$sClassExp.'">expire: '.date("Y-m-d H:i:s", $iExpire).'</span>';
-        $sHtml.='</div>';
-        $sData=preg_replace('/([A-Z]*=)(.*)/', '<span class="key">$1</span><span class="value">$2</span>', $sData);
-        $sData=preg_replace('/(JOBEXPIRE=.*)/', '<span class="'.$sClassExp.'">$1</span>', $sData);
-        $sData=preg_replace('/(SCRIPTRC=.*)/', '<span class="'.$sClassRc.'">$1</span>', $sData);
-
-        // moegliche returncodes im scriptout Block einfaerben
-        $sData=preg_replace('/(rc=[1-9][0-9]*)/', '<span class="error">$1</span>', $sData);
-        $sData=preg_replace('/(rc=[1-9])/', '<span class="error">$1</span>', $sData);
-        // $sData=preg_replace('/(rc=0)/', '<span class="ok">$1</span>', $sData);
-
-        // remove terminal color
-        $sData=preg_replace('/(\[[0-9]{1,3}m)/', '', $sData);
-
-        $sData='<div class="cronlog">'.$sData.'</div>';
-        break;
-    default:
-       echo ""; 
-}
-// ------------------------------------------------------------
-// Ausgabe
-// ------------------------------------------------------------
-
-echo "<!doctype html>
-<html><head>
-    <title>$myfile</title>
-    <style>
-        .ok{background: #afa;}
-        .error{background: #faa;}
-        .cronlog{color:#aaa; font-style: italic;}
-        .key{color:#11a; font-style: normal;}
-        .value{color:#000; font-style: normal;}
-        a.button{
-            padding: 3px; border: 3px solid #fff; box-shadow: 0 0 7px #ccc;
-            background: #eee; background: linear-gradient(#ddd, #fff, #ccc);
-            border-radius: 5px; text-decoration: none; color: #555; 
-        }
-        a.button:hover{background: #ddf; box-shadow: 0 0 2px #ddd; }
-        body{font-family: arial; background:#fff; color:#333;}
-        pre{background: #eee; color:#666; margin: 0;}
-    </style>
-</head>
-<body>
-    <a href='#' onclick='javascript:history.back();' class='button'>zur&uuml;ck</a>
-    <a href='cronjobs.html' class='button'>&uuml;bersicht der Cronjobs</a>
-    File: $myfile<br>
-    <br>
-    $sHtml
-    <pre>$sData</pre>
-
-</body></html>
-";
-
-- 
GitLab