Skip to content
Snippets Groups Projects
Commit 4788caf6 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'freshup-php' into 'master'

OP#7365 PHP-8.1 - Upgrade - cronlog Viewer (monitors.ascii)https://projects.iml.unibe.ch/work_packages/7365

See merge request !18
parents c7bbc1f2 53cfa13f
No related branches found
No related tags found
1 merge request!18OP#7365 PHP-8.1 - Upgrade - cronlog Viewer (monitors.ascii)https://projects.iml.unibe.ch/work_packages/7365
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
/cronjobs.html /cronjobs.html
/winscp.rnd /winscp.rnd
config/inc_cronlog.php config/inc_cronlog.php
/data__/ /data__/
\ No newline at end of file allcronlogs/*
This diff is collapsed.
This diff is collapsed.
...@@ -15,27 +15,33 @@ ...@@ -15,27 +15,33 @@
* - icon - will be added as <i class="[icon value]"></i> to the label * - icon - will be added as <i class="[icon value]"></i> to the label
* *
* @author Axel * @author Axel
*
* 2024-07-04 <axel.hahn@unibe.ch> added type declarations; update php docs
* 2024-08-26 <axel.hahn@unibe.ch> remove unneeded methods; simplify icon methods; update phpdocs
*/ */
class htmlelements { class htmlelements
{
/** /**
* set of auto generated icon prefixes * Extracted label from array with attributes
* @var type * @var string
*/ */
var $_aIcons=array(
// 'fa-'=>'fa ',
);
var $_sLabel = ''; var $_sLabel = '';
var $_aAttributes = array();
/**
* Array of attributes for a html tag
* @var array
*/
var $_aAttributes = [];
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// CONSTRUCTOR // CONSTRUCTOR
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public function __construct() { public function __construct()
return true; {
// nothiung here
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
...@@ -43,27 +49,28 @@ class htmlelements { ...@@ -43,27 +49,28 @@ class htmlelements {
// PRIVATE FUNCTIONS // PRIVATE FUNCTIONS
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** /**
* generate html attibutes with all internal attributes key -> values * generate html attibutes with all internal attributes key -> values
* to be added in opening tag
* @return string * @return string
*/ */
protected function _addAttributes() { protected function _addAttributes(): string
{
$sReturn = ''; $sReturn = '';
foreach ($this->_aAttributes as $sAttr => $sValue) { foreach ($this->_aAttributes as $sAttr => $sValue) {
if(is_array($sValue)){ if (is_array($sValue)) {
echo "ERROR: an html tag was defined with array in attribute [$sAttr]:<br><pre>".print_r($this->_aAttributes, 1)."</pre>"; echo "ERROR: an html tag was defined with array in attribute [$sAttr]:<br><pre>" . print_r($this->_aAttributes, 1) . "</pre>";
} }
$sReturn .= ' '.$sAttr . '="' . $sValue . '"'; $sReturn .= " $sAttr=\"$sValue\"";
} }
return $sReturn; return $sReturn;
} }
/** /**
* internal helper: fetch all attributes from key-value hash; * Internal helper: fetch all attributes from key-value hash;
* Specialties here: * Specialties here:
* - label will be extracted from key 'label' * - label will be extracted from key 'label'
* - and optional existing key 'icon' will be added at beginning of a label * - and optional existing key 'icon' will be added at beginning of a label
...@@ -71,17 +78,18 @@ class htmlelements { ...@@ -71,17 +78,18 @@ class htmlelements {
* @param array $aAttributes * @param array $aAttributes
* @return boolean * @return boolean
*/ */
protected function _setAttributes($aAttributes){ protected function _setAttributes(array $aAttributes): bool
$this->_sLabel=''; {
if(isset($aAttributes['icon']) && $aAttributes['icon']){ $this->_sLabel = '';
$this->_sLabel.=$this->getIcon($aAttributes['icon']); if (isset($aAttributes['icon']) && $aAttributes['icon']) {
$this->_sLabel .= $this->getIcon($aAttributes['icon']);
unset($aAttributes['icon']); unset($aAttributes['icon']);
} }
if(isset($aAttributes['label']) && $aAttributes['label']){ if (isset($aAttributes['label']) && $aAttributes['label']) {
$this->_sLabel .= $aAttributes['label']; $this->_sLabel .= $aAttributes['label'];
unset($aAttributes['label']); unset($aAttributes['label']);
} }
$this->_aAttributes=$aAttributes; $this->_aAttributes = $aAttributes;
return true; return true;
} }
...@@ -91,21 +99,22 @@ class htmlelements { ...@@ -91,21 +99,22 @@ class htmlelements {
// HTML GENERIC // HTML GENERIC
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** /**
* generic function to get html code for a single tag * Generic function to get html code for a single tag
* *
* @param string $sTag tag name * @param string $sTag tag name
* @param array $aAttributes array with attributes (optional including 'icon' and 'label') * @param array $aAttributes array with attributes (optional including 'icon' and 'label')
* @param boolean $bCloseTag optional: set false if tag has no closing tag (= ending with "/>") * @param boolean $bCloseTag optional: set false if tag has no closing tag (= ending with "/>")
* @return type * @return string html code
*/ */
public function getTag($sTag, $aAttributes, $bCloseTag=true){ public function getTag(string $sTag, array $aAttributes, bool $bCloseTag = true): string
{
$sTpl = $bCloseTag ? "<$sTag%s>%s</$sTag>" : "<$sTag %s/>%s"; $sTpl = $bCloseTag ? "<$sTag%s>%s</$sTag>" : "<$sTag %s/>%s";
$this->_setAttributes($aAttributes); $this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes(), $this->_sLabel); return sprintf($sTpl, $this->_addAttributes(), $this->_sLabel);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// PUBLIC FUNCTIONS // PUBLIC FUNCTIONS
...@@ -114,109 +123,22 @@ class htmlelements { ...@@ -114,109 +123,22 @@ class htmlelements {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** /**
* helper detect prefix of a string add prefix of a framework * Helper detect prefix of a string add prefix of a framework
* i.e. value "fa-close" detects font awesome and adds "fa " as prefix * i.e. value "fa-close" detects font awesome and adds "fa " as prefix
* *
* @param string $sIconclass * @param string $sIconclass
* @return boolean * @return string HTML code
*/ */
public function getIcon($sIconclass=false){ public function getIcon(string $sIconclass = ''): string
if(!$sIconclass){ {
if (!$sIconclass) {
return ''; return '';
} }
$sPrefix='';
foreach ($this->_aIcons as $sPrefix =>$add) {
if (strpos($sIconclass, $sPrefix)===0){
$sPrefix=$add;
continue;
}
}
// do not use this .. it overrides internal attribute vars
// return $this->getTag('i', array('class'=>$sPrefix.$sIconclass));
return '<i class="'.$sPrefix.$sIconclass.'"></i> ';
}
// ----------------------------------------------------------------------
//
// PUBLIC FUNCTIONS
// HTML COMPONENTS
//
// ----------------------------------------------------------------------
/** // do not use this .. it overrides internal attribute vars
* get html code for an input field // return $this->getTag('i', ['class'=>$sIconclass]);
*
* @param array $aAttributes attributes of the select tag
* @return string
*/
public function getFormInput($aAttributes){
$sTpl = '<input %s/>';
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes());
}
/**
* get html code for an option field in a select drop down
*
* @param array $aAttributes attributes of the option tag
* @return string
*/
public function getFormOption($aAttributes){
$sTpl = '<option %s>%s</option>';
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes(), $this->_sLabel);
}
/**
* get html code for a select drop down
*
* @param array $aAttributes attributes of the select tag
* @param array $aOptions array for all option fields
* @return string
*/
public function getFormSelect($aAttributes, $aOptions=array()){
// $sTpl = '<select %s>%s</select>';
if(!count($aOptions)){ return "<i class=\"$sIconclass\"></i>&nbsp;&nbsp;";
return false;
}
$sOptions='';
foreach($aOptions as $aOptionAttributes){
// $sOptions.=$this->getFormOption($aOptionAttributes);
$sOptions.=$this->getTag('option', $aOptionAttributes);
}
$aAttributes['label']=$sOptions;
return $this->getTag('select', $aAttributes);
/*
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes(), $sOptions);
*
*/
} }
public function getTable($aHead, $aBody, $aTableAttributes=array()){
$sReturn='';
$sTdata='';
$sThead='';
$sTpl = '<table %s>'
. '<thead><tr>%s</tr></thead>'
. '<tbody>%s</tbody>'
. '</table>';
foreach($aHead as $sTh){
$sThead.='<th>'.$sTh.'</th>';
}
foreach($aBody as $aTr){
$sTdata.='<tr>';
foreach($aTr as $sTd){
$sTdata.='<td>'.$sTd.'</td>';
}
$sTdata.='</tr>';
}
$this->_setAttributes($aTableAttributes);
return sprintf($sTpl,
$this->_addAttributes(),
$sThead,
$sTdata
);
}
} }
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* it is included by classes/cronlog.class.php * it is included by classes/cronlog.class.php
*/ */
return array( return [
// starting directory with all servers cronwrapper logs // starting directory with all servers cronwrapper logs
'sDatadir'=>'__APPDIR__/data', 'sDatadir'=>'__APPDIR__/data',
...@@ -46,4 +46,4 @@ return array( ...@@ -46,4 +46,4 @@ return array(
'Extern'=>'https://cronlogs.extern.example.com/', 'Extern'=>'https://cronlogs.extern.example.com/',
], ],
*/ */
); ];
...@@ -26,7 +26,7 @@ return [ ...@@ -26,7 +26,7 @@ return [
"history" => "History", "history" => "History",
"history-head" => "History", "history-head" => "History",
"history-hint" => "Von den gestarteten Cronjobs werden die Ausf&uuml;hrungszeiten und deren Exitcode f&uuml;r 6 Tage aufgehoben.", "history-hint" => "Von den gestarteten Cronjobs werden die Ausf&uuml;hrungszeiten und deren Exitcode f&uuml;r mehrere Tage aufgehoben.",
"timeline" => "Timeline", "timeline" => "Timeline",
"timeline-head" => "Graph mit Timeline", "timeline-head" => "Graph mit Timeline",
......
...@@ -26,7 +26,7 @@ return [ ...@@ -26,7 +26,7 @@ return [
"history" => "History", "history" => "History",
"history-head" => "History", "history-head" => "History",
"history-hint" => "The cronwrapper keeps data for 6 days. For each executed cronjob you can see execution times and exitcode.", "history-hint" => "The cronwrapper keeps execution history data for multiples days. For each executed cronjob you can see execution times and exitcode.",
"timeline" => "Timeline", "timeline" => "Timeline",
"timeline-head" => "Graph with timeline", "timeline-head" => "Graph with timeline",
......
...@@ -26,72 +26,7 @@ ...@@ -26,72 +26,7 @@
<link rel="stylesheet" href="{{DIR_ADMINLTE}}/css/adminlte.min.css?v=3.2.0"> <link rel="stylesheet" href="{{DIR_ADMINLTE}}/css/adminlte.min.css?v=3.2.0">
<link rel="stylesheet" href="/main.css"> <link rel="stylesheet" href="/main.css">
<!--
<script nonce="b14481d0-1a31-4cec-b6e8-b5ad6020a5a9">
(function(w, d) {
! function(cM, cN, cO, cP) {
cM.zarazData = cM.zarazData || {};
cM.zarazData.executed = [];
cM.zaraz = {
deferred: [],
listeners: []
};
cM.zaraz.q = [];
cM.zaraz._f = function(cQ) {
return function() {
var cR = Array.prototype.slice.call(arguments);
cM.zaraz.q.push({
m: cQ,
a: cR
})
}
};
for (const cS of ["track", "set", "debug"]) cM.zaraz[cS] = cM.zaraz._f(cS);
cM.zaraz.init = () => {
var cT = cN.getElementsByTagName(cP)[0],
cU = cN.createElement(cP),
cV = cN.getElementsByTagName("title")[0];
cV && (cM.zarazData.t = cN.getElementsByTagName("title")[0].text);
cM.zarazData.x = Math.random();
cM.zarazData.w = cM.screen.width;
cM.zarazData.h = cM.screen.height;
cM.zarazData.j = cM.innerHeight;
cM.zarazData.e = cM.innerWidth;
cM.zarazData.l = cM.location.href;
cM.zarazData.r = cN.referrer;
cM.zarazData.k = cM.screen.colorDepth;
cM.zarazData.n = cN.characterSet;
cM.zarazData.o = (new Date).getTimezoneOffset();
if (cM.dataLayer)
for (const cZ of Object.entries(Object.entries(dataLayer).reduce(((c_, da) => ({
...c_[1],
...da[1]
}))))) zaraz.set(cZ[0], cZ[1], {
scope: "page"
});
cM.zarazData.q = [];
for (; cM.zaraz.q.length;) {
const db = cM.zaraz.q.shift();
cM.zarazData.q.push(db)
}
cU.defer = !0;
for (const dc of [localStorage, sessionStorage]) Object.keys(dc || {}).filter((de => de.startsWith("_zaraz_"))).forEach((dd => {
try {
cM.zarazData["z_" + dd.slice(7)] = JSON.parse(dc.getItem(dd))
} catch {
cM.zarazData["z_" + dd.slice(7)] = dc.getItem(dd)
}
}));
cU.referrerPolicy = "origin";
cU.src = "/cdn-cgi/zaraz/s.js?z=" + btoa(encodeURIComponent(JSON.stringify(cM.zarazData)));
cT.parentNode.insertBefore(cU, cT)
};
["complete", "interactive"].includes(cN.readyState) ? zaraz.init() : cM.addEventListener("DOMContentLoaded", zaraz.init)
}(w, d, 0, "script");
})(window, document);
</script>
-->
</head> </head>
<body class="hold-transition {{PAGE_SKIN}} {{PAGE_LAYOUT}}"> <body class="hold-transition {{PAGE_SKIN}} {{PAGE_LAYOUT}}">
......
...@@ -48,9 +48,9 @@ if($sServer){ ...@@ -48,9 +48,9 @@ if($sServer){
switch ($sItem){ switch ($sItem){
case 'cronhistory': case 'cronhistory':
if($sServer==='ALL'){ if($sServer==='ALL'){
$sHtml.=$oCL->renderJoblistOfAllServers(); $sHtml.=$oCL->renderHistoryOfAllServers();
} else { } else {
$sHtml.=$oCL->renderJoblist(); $sHtml.=$oCL->renderHistoryTable();
} }
break; break;
case 'cronlogs': case 'cronlogs':
...@@ -68,7 +68,7 @@ switch ($sItem){ ...@@ -68,7 +68,7 @@ switch ($sItem){
} }
break; break;
case 'instances': case 'instances':
$sHtml.=$oCL->renderInstances($sServer); $sHtml.=$oCL->renderInstances();
break; break;
case 'selectserver': case 'selectserver':
$sHtml.=$oCL->renderServerlist($sServer); $sHtml.=$oCL->renderServerlist($sServer);
......
<?php <?php
define("APP_VERSION", '2.1.4'); define("APP_VERSION", '2.2.0');
require_once('classes/render-adminlte.class.php'); require_once('classes/render-adminlte.class.php');
require_once('classes/cronlog-renderer.class.php'); require_once('classes/cronlog-renderer.class.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment