Skip to content
Snippets Groups Projects

multi language support

Merged Hahn Axel (hahn) requested to merge restyle-adminlte into master
11 files
+ 377
358
Compare changes
  • Side-by-side
  • Inline

Files

+ 136
63
@@ -51,9 +51,10 @@ class cronlogrenderer extends cronlog{
return '';
}
$iAge=round((date('U')-$iLast)/60);
return ''
. 'Abruf: '.date("Y-m-d H:i:s").' min<br>'
. 'letzter Eintrag: vor '.$iAge.' min<br><br>'
return '<div class="accessandage">'
. sprintf($this->t("request-time"), date("Y-m-d H:i:s")).'<br>'
. sprintf($this->t("last-entry"), $iAge)
.'</div>'
;
}
@@ -65,14 +66,36 @@ class cronlogrenderer extends cronlog{
*
*/
protected function _filterDatatable($sDatatable, $sFiltertext){
/*
<a href="#" title="Filtere nach VHost «crawler.ascii.iml.unibe.ch:443»"
onclick="$('#tableRenderedallrequestsphp1_filter>INPUT').val('crawler.ascii.iml.unibe.ch:443');
$('#tableRenderedallrequestsphp1').dataTable().fnFilter('crawler.ascii.iml.unibe.ch:443'); return false;">crawler.ascii.iml.unibe.ch:443</a>
*/
return '$(\'#'.$sDatatable.'\').dataTable().fnFilter(\''.$sFiltertext.'\'); return false;';
}
/**
* helper function to be used in methods that render datatable tables
* get javascript code to be added in init options and set language specifi texts
* @return string
*/
protected function _getDatatableLanguage(){
return $this->t("dt-USE")
? ', "oLanguage":{
"sProcessing":"'.$this->t("dt-sProcessing").'",
"sLengthMenu":"'.$this->t("dt-sLengthMenu").'",
"sZeroRecords":"'.$this->t("dt-sZeroRecords").'",
"sInfo":"'.$this->t("dt-sInfo").'",
"sInfoEmpty":"'.$this->t("dt-sInfoEmpty").'",
"sInfoFiltered":"'.$this->t("dt-sInfoFiltered").'",
"sInfoPostFix":"'.$this->t("dt-sInfoPostFix").'",
"sSearch":"'.$this->t("dt-sSearch").'",
"sUrl":"'.$this->t("dt-sUrl").'",
"oPaginate":{
"sFirst":"'.$this->t("dt-sFirst").'",
"sPrevious":"'.$this->t("dt-sPrevious").'",
"sNext":"'.$this->t("dt-sNext").'",
"sLast":"'.$this->t("dt-sLast").'"
}
}'
: ''
;
}
/**
* get html code for a table with events of executed cronjobs
*
@@ -97,7 +120,16 @@ class cronlogrenderer extends cronlog{
// Array ( [SCRIPTNAME] => apt-get update [SCRIPTTTL] => 1440 [SCRIPTSTARTTIME] => 2016-06-21 06:00:02, 1466481602 [SCRIPTLABEL] => apt-get [SCRIPTENDTIME] => 2016-06-21 06:00:49, 1466481649 [SCRIPTEXECTIME] => 47 s [SCRIPTRC] => 0 )
foreach($aData as $sDtakey=>$aEntry){
if(!$sTblHead){
foreach(array('Startzeit', 'Label', 'Server', 'Dauer', 'TTL', '$?', 'Expired', 'Status' /*, 'Aktionen'*/) as $sKey){
foreach(array(
$this->t("col-starting-time"),
$this->t("col-label"),
$this->t("col-server"),
$this->t("col-duration"),
$this->t("col-ttl"),
$this->t("col-rc"),
$this->t("col-expired"),
$this->t("col-status"),
) as $sKey){
$sTblHead.='<th>'.$sKey.'</th>';
}
}
@@ -115,25 +147,29 @@ class cronlogrenderer extends cronlog{
$sServerFromLogfile=preg_replace('/_.*/', '', basename($aEntry['logfile']));
if($sServerFromLogfile!=$aEntry['server']){
$aErrors[]=[
'Hostname?',
'Der Hostname im Log ['.$sServerFromLogfile.'] stimmt nicht mit Servernamen ['.$aEntry['server'].'] &uuml;berein.',
$this->t('error-host-in-log-differs-servername-label'),
sprintf($this->t('error-host-in-log-differs-servername-description'),$sServerFromLogfile, $aEntry['server']),
];
}
if(!strstr($sServerFromLogfile, ".")){
$aErrors[]=[
'No FQDN',
'Der Hostname im Log ['.$sServerFromLogfile.'] ist kein KFQDN.',
$this->t('error-no-fqdn-label'),
sprintf($this->t('error-no-fqdn-description'),$sServerFromLogfile),
];
}
if($iNextRunErr < date("U")){
$aErrors[]=[
'Abgelaufen',
'Job wurde nicht mehr gestartet oder kein Sync zum Logserver',
$this->t('error-expired-label'),
$this->t('error-expired-description'),
];
}
if($aEntry['SCRIPTRC']>0){
$aErrors[]=[
sprintf($this->t('error-exitcode-label'), (int)$aEntry['SCRIPTRC']),
$this->t('error-exitcode-description'),
];
$aErrors[]=[
'Exitcode '.(int)$aEntry['SCRIPTRC'].' (<>0)',
'The command finished with a non error status'
@@ -141,8 +177,8 @@ class cronlogrenderer extends cronlog{
}
if(!$aEntry['SCRIPTLABEL']){
$aErrors[]=[
'Kein Label?',
'No label was detected for this job. Check the scheduled cronjob on server.'
$this->t('error-no-label-label'),
$this->t('error-no-label-description'),
];
}
@@ -165,14 +201,14 @@ class cronlogrenderer extends cronlog{
$sColStatus='';
if (count($aErrors)){
foreach($aErrors as $aErr){
$sColStatus.='<li><abbr title="'.$aErr[1].'">FEHLER: '.$aErr[0].'</abbr></li>';
$sColStatus.='<li><abbr title="'.$aErr[1].'">'.$this->t('status-error').': '.$aErr[0].'</abbr></li>';
}
$sColStatus='<ul>'.$sColStatus.'</ul>';
} else {
$sColStatus.='OK';
$sColStatus.=$this->t('status-ok');
}
// render table of last logfile per cron job
$sHtml.='<tr onclick="showFile(\''.$aEntry['logfile'].'\');" title="Klick=['.$aEntry['logfile'].'] anzeigen ">'
$sHtml.='<tr onclick="showFile(\''.$aEntry['logfile'].'\');" title="'.sprintf($this->t('row-click-show-logfile'), $aEntry['logfile']).'">'
. '<td>'.date("Y-m-d H:i:s", $aEntry['SCRIPTSTARTTIME']).'</td>'
// . '<td>'.$aEntry['SCRIPTNAME'].'</td>'
. '<td>'.$aEntry['SCRIPTLABEL'].'</td>'
@@ -208,17 +244,16 @@ class cronlogrenderer extends cronlog{
<!-- START '.__METHOD__.' -->
'
. '<h3>Letztes Logfile pro Job</h3>'
. '<p class="hint">'
. 'Von jedem Cronjob kann man das jeweils letzte Log im Detail ansehen. Mit Klick in der Tabelle wird die Logdatei ge&ouml;ffnet.'
. '</p>'
. '<div>'
. '<h3>'.$this->t('logs-head').'</h3>'
. '<p class="hint">'
. $this->t('logs-hint')
. '</p>'
. '<div>'
. $this->_renderAccessAndAge($iLast)
. ($iErrors ? '<a href="#" class="btn bg-danger" onclick="'.$this->_filterDatatable($sIdTable, "FEHLER").'">' . $iErrors.'</a> ' : '')
. ( $iOK ? '<a href="#" class="btn bg-success" onclick="'.$this->_filterDatatable($sIdTable, "OK").'">' . $iOK.'</a>' : '')
. ($iErrors && $iOK ? ' ... gesamt: <a href="#" class="btn bg-gray" onclick="'.$this->_filterDatatable($sIdTable, "").'">' . count($aData).'</a>' : '' )
. '<br>'
. '</div>'
. ($iErrors ? '<a href="#" class="btn bg-danger" onclick="'.$this->_filterDatatable($sIdTable, $this->t('status-error')).'"><i class="fas fa-exclamation-circle"></i> &nbsp; ' . $iErrors.'</a> ' : '')
. ( $iOK ? '<a href="#" class="btn bg-success" onclick="'.$this->_filterDatatable($sIdTable, $this->t('status-ok')).'"><i class="fas fa-check"></i> &nbsp; ' . $iOK.'</a>' : '')
. ($iErrors && $iOK ? ' ... '.$this->t('total').': <a href="#" class="btn bg-gray" onclick="'.$this->_filterDatatable($sIdTable, "").'"><i class="fas fa-th-large"></i> &nbsp; ' . count($aData).'</a>' : '' )
. '</div><br>'
. '<table id="'.$sIdTable.'" class="table-striped">'
. '<thead><tr>'.$sTblHead.'</tr></thead>'
. '<tbody>'
@@ -228,7 +263,13 @@ class cronlogrenderer extends cronlog{
// init datatable
. '<script>'
. '$(document).ready( function () { $(\'#'.$sIdTable.'\').DataTable({"retrieve": true, "bPaginate":false, "aaSorting":[[0,"desc"]]}); } );'
. '$(document).ready( function () { $(\'#'.$sIdTable.'\').DataTable({
"retrieve": true,
"bPaginate":false,
"aaSorting":[[0,"desc"]]
'.$this->_getDatatableLanguage().'
});
});'
. '</script>'
. '
@@ -262,7 +303,7 @@ class cronlogrenderer extends cronlog{
$sReturn='';
$sServer=isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : false;
$sReturn.='<li class="nav-item"><a class="nav-link nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a></li>'
. '<li class="nav-item d-none d-sm-inline-block"><a href="#" class="nav-link">Instances:</a></li>';
. '<li class="nav-item d-none d-sm-inline-block"><a href="#" class="nav-link">'.$this->t('instances').':</a></li>';
foreach($this->_aInstances as $sInstance => $sUrl){
$sHost=parse_url($sUrl, PHP_URL_HOST);
@@ -297,7 +338,15 @@ class cronlogrenderer extends cronlog{
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
foreach($aData as $aEntry){
if(!$sTblHead){
foreach(array('Startzeit', /*'Ende',*/ 'Label', 'Server', 'Dauer', 'TTL', '$?') as $sKey){
foreach(array(
$this->t("col-starting-time"),
$this->t("col-label"),
$this->t("col-server"),
$this->t("col-duration"),
$this->t("col-ttl"),
$this->t("col-rc"),
$this->t("col-status"),
) as $sKey){
$sTblHead.='<th>'.$sKey.'</th>';
}
}
@@ -324,7 +373,8 @@ class cronlogrenderer extends cronlog{
. '<td>'.$aEntry['ttl'].'</td>'
. '<td class="'
.($aEntry['rc']>0 ? 'message-error': 'message-ok')
. '">'.$aEntry['rc'].'</td>'
. '">'.$aEntry['rc'].'</td>'
. '<td>'.( $aEntry['rc'] ? $this->t('status-error') : $this->t('status-ok') ).'</td>'
. '</tr>'
;
}
@@ -332,17 +382,18 @@ class cronlogrenderer extends cronlog{
$sHtml='
<!-- START '.__METHOD__.' -->
'
. '<h3>History</h3>'
. '<p class="hint">'
. 'Von den gestarteten Cronjobs werden die Ausf&uuml;hrungszeiten und deren Exitcode f&uuml;r 6 Tage aufgehoben.'
. '</p>'
. '<div>'
. '<h3>'.$this->t('history-head').'</h3>'
. '<p class="hint">'
. $this->t('history-hint')
. '</p>'
. '<div>'
. $this->_renderAccessAndAge($iLast)
. 'gesamt: <strong>' . count($aData).'</strong>'
. ($iErrors ? ' (Fehler: <strong>' . $iErrors.'</strong>... OK: <strong>' . $iOK.'</strong>)' : '')
. '<br><br>'
. '</div>'
. ($iErrors ? '<a href="#" class="btn bg-danger" onclick="'.$this->_filterDatatable($sIdTable, $this->t('status-error')).'"><i class="fas fa-exclamation-circle"></i> &nbsp; ' . $iErrors.'</a> ' : '')
. ( $iOK ? '<a href="#" class="btn bg-success" onclick="'.$this->_filterDatatable($sIdTable, $this->t('status-ok')).'"><i class="fas fa-check"></i> &nbsp; ' . $iOK.'</a>' : '')
. ($iErrors && $iOK ? ' ... '.$this->t('total').': <a href="#" class="btn bg-gray" onclick="'.$this->_filterDatatable($sIdTable, "").'"><i class="fas fa-th-large"></i> &nbsp; ' . count($aData).'</a>' : '' )
. '</div>'
. '<br>'
. '<table id="'.$sIdTable.'">'
. '<thead><tr>'.$sTblHead.'</tr></thead>'
. '<tbody>'
@@ -352,7 +403,12 @@ class cronlogrenderer extends cronlog{
// init datatable
. '<script>'
. '$(document).ready( function () {$(\'#'.$sIdTable.'\').DataTable({"retrieve": true, "aaSorting":[[0,"desc"]],"aaSorting":[[0,"desc"]], "aLengthMenu":[[25,100,-1],[25,100,"---"]]});} );'
. '$(document).ready( function () {$(\'#'.$sIdTable.'\').DataTable({
"retrieve": true,
"aaSorting":[[0,"desc"]],
"aLengthMenu":[[25,100,-1],[25,100,"---"]]
'.$this->_getDatatableLanguage().'
});} );'
. '</script>'
. '
@@ -447,18 +503,16 @@ class cronlogrenderer extends cronlog{
<!-- START '.__METHOD__.' -->
<h3>Graph mit Timeline</h3>
<p class="hint">
Aus der History der letzten 6 Tage werden die Cronjobs mit mehr als '.$this->_iMinTime4Timeline.' Sekunden Laufzeit dargestellt.<br>
So kann man ggf. Konflikte und Ungereimtheiten finden.<br>
Innerhalb der Timeline kann man mit dem Mausrad den Zoom ver&auml;ndern.
</p>
<p>
Jobs mit mehr als '.$this->_iMinTime4Timeline.'s Laufzeit: <strong>'.count($aDataset).'</strong> (ges.: '.count($aData).')<br><br>
'. (count($aDataset) ? $this->_renderAccessAndAge($iLast) : '' ).'
</p>
'
. '<h3>'.$this->t('timeline-head').'</h3>'
. '<p class="hint">'
. sprintf($this->t('timeline-hint'), $this->_iMinTime4Timeline)
. '</p>
<p>'
.sprintf($this->t('graph-rendered-jobs'), $this->_iMinTime4Timeline).': <strong>'.count($aDataset).'</strong> '
.'('.$this->t('total').': '.count($aData).')<br><br>'
.(count($aDataset) ? $this->_renderAccessAndAge($iLast) : '' )
.'</p>'
.(count($aDataset) ?
'<div id="'.$sDivId.'"></div>
@@ -481,7 +535,9 @@ class cronlogrenderer extends cronlog{
// fix: some timelines do not properly work ... but I make them visible
$(\'#'.$sDivId.' .vis-timeline\').css(\'visibility\', \'visible\');
</script>
' : '(kein Graph)<br>')
'
: $this->t('graph-no-data').'<br>'
)
.'
<!-- ENDE '.__METHOD__.'-->
@@ -505,6 +561,23 @@ class cronlogrenderer extends cronlog{
return $this->renderJobGraph($aData);
}
/**
* used in config/page-replacements.php
* generate an array of javascript lang texts
*/
public function renderJSLang(){
$aReturn=[];
foreach($this->_aLang as $sKey=>$sText){
if(preg_match('/^JS_/', $sKey)){
$aReturn[preg_replace('/^JS_/', '', $sKey)]=$sText;
}
}
return "\n"
.'// generated by '.__METHOD__."\n"
.'var aLang='.json_encode($aReturn, JSON_PRETTY_PRINT).'; '."\n"
;
}
/**
* show a single log file
@@ -514,19 +587,19 @@ class cronlogrenderer extends cronlog{
*/
public function renderLogfile($sLogfile){
$sHtml=''
. '<button style="position: fixed;" onclick="closeOverlay();" class="btn btn-default"><i class="fas fa-chevron-left"></i> back</button><br><br>'
. '<h3>Logfile '.basename($sLogfile).'</h3>'
. '<button style="position: fixed;" onclick="closeOverlay();" class="btn btn-default"><i class="fas fa-chevron-left"></i> '.$this->t('back').'</button><br><br>'
. '<h3>'. $this->t('logfile').' '.basename($sLogfile).'</h3>'
;
if(!$sLogfile){
return $sHtml . 'ERROR: empty filename for log file was given.';
return $sHtml . $this->t('error-nologfile');
}
if(strstr($sLogfile, '..')){
return $sHtml . 'ERROR: wrong log file chars [..] are not allowed.';
return $sHtml . $this->t('error-dots-not-allowed');
}
// $sMyFile=$this->_getServerlogDir().'/'.$sLogfile;
$sMyFile=$this->_sDataDir.'/'.$sLogfile;
if(!file_exists($sMyFile)){
return $sHtml . 'ERROR: The requested logfile<br>['.$sMyFile.']<br>does not exist (anymore).';
return $sHtml . sprintf($this->t('error-logfile-not-found'), $sMyFile);
}
@@ -574,7 +647,7 @@ class cronlogrenderer extends cronlog{
$iMaxItemsToShow=30;
$sHtml.='<option value="ALL"'
.($sSelectedItem===false || $sSelectedItem==='ALL' ? ' selected="selected"' : '')
. '>[ALLE ('.count($this->getServers()).')]</option>';
. '>['.$this->t('ALL').' ('.count($this->getServers()).')]</option>';
foreach($this->getServers() as $sServer=>$aData){
$sHtml.='<option value="'.$sServer.'"'
.($sSelectedItem===$sServer ? ' selected="selected"' : '')
Loading