From ecaa48ed089ad9f8bb4a279e287e2136543f2d5e Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Tue, 3 Sep 2019 11:41:03 +0200
Subject: [PATCH] use config file to customize

---
 .gitignore                         |  3 ++-
 classes/cronlog-renderer.class.php | 11 ++++-------
 classes/cronlog.class.php          | 29 +++++++++++++++--------------
 classes/cronlog_cfg.php            |  6 ------
 config/inc_cronlog.php.dist        | 13 +++++++++++++
 5 files changed, 34 insertions(+), 28 deletions(-)
 delete mode 100644 classes/cronlog_cfg.php
 create mode 100644 config/inc_cronlog.php.dist

diff --git a/.gitignore b/.gitignore
index 5db9b71..42838eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 /data/
 /nbproject/
 /cronjobs.html
-/winscp.rnd
\ No newline at end of file
+/winscp.rnd
+config/inc_cronlog.php
diff --git a/classes/cronlog-renderer.class.php b/classes/cronlog-renderer.class.php
index 759acda..538ca07 100644
--- a/classes/cronlog-renderer.class.php
+++ b/classes/cronlog-renderer.class.php
@@ -1,15 +1,12 @@
 <?php
 
 require_once 'cronlog.class.php';
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
 
 /**
- * Description of cronlog-renderer
+ * central cronlog viewer
+ * 
+ * cronlog-renderer contains visual methods to render html
+ * @see cronlog.class.php
  *
  * @author hahn
  */
diff --git a/classes/cronlog.class.php b/classes/cronlog.class.php
index 571e627..ba6c4c0 100644
--- a/classes/cronlog.class.php
+++ b/classes/cronlog.class.php
@@ -1,7 +1,9 @@
 <?php
-
 /**
- * Description of cronlog
+ * central cronlog viewer
+ * 
+ * cronlog contains non visual methods
+ * @see cronlog-renderer.class.php
  *
  * @author hahn
  */
@@ -9,27 +11,26 @@
 class cronlog {
     
     
-    protected $_sDataDir = "__DIR__/data";
+    protected $_sDataDir = "__APPDIR__/data";
     protected $_iTtlCache = 60; // in sec
-    
+    protected $_aSkipJoblogs = array();
     
     protected $_aServers = false;
     protected $_sActiveServer = false;
     
     protected $_sFileFilter_serverjoblog = '*joblog*.done';
     protected $_sFileFilter_serverlog = '*.log';
-    
-    protected $_aSkipJoblogs = array(
-        // 'dok-kvm-instances',
-        'sync-log-2-lithium',
-    );
-    
+
     
     public function __construct() {
-        if (file_exists(__DIR__.'/cronlog_cfg.php')){
-            include(__DIR__.'/cronlog_cfg.php');
+
+        if (file_exists(__DIR__.'/../config/inc_cronlog.php')){
+            $aCfgTemp=include(__DIR__.'/../config/inc_cronlog.php');
+            $this->_sDataDir = isset($aCfgTemp['sDatadir']) ? $aCfgTemp['sDatadir'] : $this->_sDataDir;
+            $this->_iTtlCache = isset($aCfgTemp['iTtlCache']) ? (int)$aCfgTemp['iTtlCache'] : $this->_iTtlCache;
+            $this->_aSkipJoblogs = isset($aCfgTemp['aHidelogs']) && is_array($aCfgTemp['aHidelogs']) ? $aCfgTemp['aHidelogs'] : $this->_aSkipJoblogs;        
         }
-        $this->_sDataDir = str_replace("__DIR__", dirname(dirname(__FILE__)), $this->_sDataDir);
+        $this->_sDataDir = str_replace("__APPDIR__", dirname(dirname(__FILE__)), $this->_sDataDir);
         $this->_sDataDir = str_replace('\\', '/', $this->_sDataDir);
         
         $this->getServers();
@@ -112,7 +113,7 @@ class cronlog {
         $this->_aServers=array();
         // echo "DEBUG DATADIR: " . $this->_sDataDir."<br>";
         if (!is_dir($this->_sDataDir)){
-            echo "WARNING: no data. variable _sDataDir is wrong (or somehting is not mounted).<br>";
+            echo "WARNING: no data. Check sDatadir in the config and set it to an existing directory.<br>";
             die();
         }
 
diff --git a/classes/cronlog_cfg.php b/classes/cronlog_cfg.php
deleted file mode 100644
index 38713f1..0000000
--- a/classes/cronlog_cfg.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-$sLithiumDir='/var/www/cronlogs';
-
-if(is_dir($sLithiumDir)){
-    $this->_sDataDir = $sLithiumDir;
-}
\ No newline at end of file
diff --git a/config/inc_cronlog.php.dist b/config/inc_cronlog.php.dist
new file mode 100644
index 0000000..d995fee
--- /dev/null
+++ b/config/inc_cronlog.php.dist
@@ -0,0 +1,13 @@
+<?php
+/**
+ * CONFIG FILE
+ * 
+ * it is included by classes/cronlog.class.php
+ */
+return array(
+    // starting directory with all servers cronwrapper logs
+    'sDatadir'=>'__APPDIR__/data',
+
+    // caching time for infos in the browser
+    'iTtlCache'=>0,
+);
-- 
GitLab