Commit a79b9515 authored by Kai Kretschmann's avatar Kai Kretschmann 🐈

Major rework on formatting, sonar integration, cleanups

parent c1347980
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
</buildpath>
Options -indexes
Header always set Strict-Transport-Security "max-age=31536000"
#Header always set Strict-Transport-Security "max-age=31536000"
Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self'; report-uri https://report-uri.io/report/e7e84fa898ae6e0d0e8d70e25cd237c7;"
#Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self'; report-uri https://report-uri.io/report/e7e84fa898ae6e0d0e8d70e25cd237c7;"
<Files stats.php>
# Chart.js uses some dynamic functions.
......@@ -18,3 +18,5 @@ AuthType Basic
AuthName "Restricted Area"
AuthUserFile /var/www/webuser
Require valid-user
Require ip 127.0.0.1
Require ip ::1
......@@ -5,11 +5,6 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.php.composer.core.builder.buildPathManagementBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
......
DefaultProjectBasePath=/Lggr
eclipse.preferences.version=1
org.eclipse.php.debug.core.use-project-settings=true
org.eclipse.php.debug.coredefaultPHP=PHP 7.2.0 (CLI)
org.eclipse.php.debug.coredefaultPHP=PHP 5.6.32 (CLI)
org.eclipse.php.debug.coreoutput_encoding=UTF-8
org.eclipse.php.debug.corestop_at_first_line_string=true
org.eclipse.php.debug.coretransfer_encoding=UTF-8
This diff is collapsed.
cleanup.format.on.save=false
cleanup.organize.on.save=false
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=false
cleanup.remove_trailing_whitespaces_ignore_empty=true
eclipse.preferences.version=1
org.eclipse.php.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="php.core.component"/>
<fixed facet="php.component"/>
<installed facet="php.core.component" version="1"/>
<installed facet="php.component" version="7.1"/>
<installed facet="php.composer.component" version="1"/>
<fixed facet="php.core.component" />
<fixed facet="php.component" />
<installed facet="php.core.component" version="1" />
<installed facet="php.component" version="5.6" />
</faceted-project>
bootstrap=
debug_print_output=true
eclipse.preferences.version=1
no_namespace_check=true
pear_library=<Internal>
php_executable=PHP 5.6.32 (CLI)
source_file_pattern_folder=\\%p\\inc
test_file_pattern_file=%fTest.%e
test_file_pattern_folder=\\%p\\tests
test_file_super_class=PHPUnit_Framework_TestCase
<?php
spl_autoload_register(function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
spl_autoload_register(
function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
$iCount = 0;
$aPerf = array();
......@@ -16,7 +17,8 @@ try {
$iCount = $l->purgeOldMessages();
$aPerf = $l->getPerf();
} catch (LggrException $e) {
}
catch (LggrException $e) {
die($e->getMessage());
} // try
......
<?php
spl_autoload_register(function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
spl_autoload_register(
function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
$iCountServers = 0;
$aPerf = array();
......@@ -17,7 +18,8 @@ try {
$iCountServers = $l->updateServers();
$aPerf = $l->getPerf();
} catch (LggrException $e) {
}
catch (LggrException $e) {
die($e->getMessage());
} // try
......
<?php
spl_autoload_register(function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
spl_autoload_register(
function ($class) {
include __DIR__ . '/../inc/' . strtolower($class) . '_class.php';
});
$iCount = 0;
$a = array();
......@@ -17,6 +18,7 @@ try {
$l->normalizeHosts();
$a = $l->getPerf();
} catch (LggrException $e) {
}
catch (LggrException $e) {
die($e->getMessage());
} // try
<?php
spl_autoload_register(function ($class) {
include 'inc/' . strtolower($class) . '_class.php';
});
spl_autoload_register(
function ($class) {
include 'inc/' . strtolower($class) . '_class.php';
});
session_start();
......
......@@ -7,8 +7,10 @@ require 'tpl/head.inc.php';
$l = null;
try {
$l = new Lggr($state, $config);
} catch (LggrException $e) {
echo '<div class="container"><div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div></div>';
}
catch (LggrException $e) {
echo '<div class="container"><div class="alert alert-danger" role="alert">' .
$e->getMessage() . '</div></div>';
require 'tpl/foot.inc.php';
......@@ -22,8 +24,10 @@ try {
$searchvalue = '';
$searchvalueprog = '';
$isSearch = false;
} catch (LggrException $e) {
echo '<div class="container"><div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div></div>';
}
catch (LggrException $e) {
echo '<div class="container"><div class="alert alert-danger" role="alert">' .
$e->getMessage() . '</div></div>';
require 'tpl/foot.inc.php';
......@@ -31,7 +35,8 @@ try {
}
if (version_compare(phpversion(), '5.4', '<')) {
echo '<div class="container"><div class="alert alert-danger" role="alert">Your PHP version ' . phpversion() . ' might be too old, expecting at least 5.4</div></div>';
echo '<div class="container"><div class="alert alert-danger" role="alert">Your PHP version ' .
phpversion() . ' might be too old, expecting at least 5.4</div></div>';
} // if
require 'tpl/nav.inc.php';
......@@ -46,7 +51,8 @@ require 'tpl/nav.inc.php';
<?php
if (0 == count($aEvents)) {
echo '<div class="alert alert-danger" role="alert">' . _('empty result') . '</div>';
echo '<div class="alert alert-danger" role="alert">' . _('empty result') .
'</div>';
} // if
?>
......@@ -92,22 +98,26 @@ foreach ($aEvents as $event) {
$label = '<span class="label label-success">Info</span>';
break;
default:
$label = '<span class="label label-default">' . $event->level . '</span>';
$label = '<span class="label label-default">' . $event->level .
'</span>';
} // switch
switch ($event->archived) {
case 'Y':
$archived = '<span id="arch' . $event->id . '" class="lggr-archived glyphicon glyphicon-warning-sign" aria-hidden="true" title="archived"></span>';
$archived = '<span id="arch' . $event->id .
'" class="lggr-archived glyphicon glyphicon-warning-sign" aria-hidden="true" title="archived"></span>';
break;
case 'N':
$archived = '<span id="arch' . $event->id . '" class="lggr-notarchived glyphicon glyphicon-pushpin" aria-hidden="true" title=""></span>';
$archived = '<span id="arch' . $event->id .
'" class="lggr-notarchived glyphicon glyphicon-pushpin" aria-hidden="true" title=""></span>';
break;
default:
$archived = '?';
} // switch
$host = htmlentities($event->host, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES);
$program = htmlentities($event->program, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES);
$program = htmlentities($event->program,
ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES);
$msg = htmlentities($event->message, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES);
echo <<<EOL
......@@ -135,5 +145,4 @@ if (! $isSearch) {
<?php
$aPerf = $l->getPerf();
require 'tpl/foot.inc.php'
?>
require 'tpl/foot.inc.php'?>
......@@ -6,25 +6,25 @@ div.lggr-col-filter div.lggr-formelement {
margin-bottom: 1em;
}
@-moz-keyframes spin {
100% {
-moz-transform: rotate(360deg);
}
@
-moz-keyframes spin { 100% {
-moz-transform: rotate(360deg);
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@
-webkit-keyframes spin { 100% {
-webkit-transform: rotate(360deg);
}
@keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@
keyframes spin { 100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
div#liveheader h2 span.glyphicon-refresh {
-webkit-animation: spin 4s linear infinite;
-moz-animation: spin 4s linear infinite;
......@@ -99,4 +99,4 @@ p.debugfooter {
float: right;
color: #999999;
font-size: 75%;
}
}
\ No newline at end of file
......@@ -33,4 +33,4 @@ div.col-md-1, div.col-md-2 {
div.col-md-5 {
clear: left;
}
}
\ No newline at end of file
<?php
spl_autoload_register(function ($class) {
include 'inc/' . strtolower($class) . '_class.php';
});
spl_autoload_register(
function ($class) {
include 'inc/' . strtolower($class) . '_class.php';
});
session_start();
......
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square70x70logo src="/icos/mstile-70x70.png"/>
<square150x150logo src="/icos/mstile-150x150.png"/>
<square310x310logo src="/icos/mstile-310x310.png"/>
<wide310x150logo src="/icos/mstile-310x150.png"/>
<TileColor>#ffc40d</TileColor>
</tile>
</msapplication>
<msapplication>
<tile>
<square70x70logo src="/icos/mstile-70x70.png" />
<square150x150logo src="/icos/mstile-150x150.png" />
<square310x310logo src="/icos/mstile-310x310.png" />
<wide310x150logo src="/icos/mstile-310x150.png" />
<TileColor>#ffc40d</TileColor>
</tile>
</msapplication>
</browserconfig>
<?php
abstract class AbstractConfig
{
abstract class AbstractConfig {
protected $DBUSER;
......@@ -23,103 +22,83 @@ abstract class AbstractConfig
protected $LOCALE;
final public function getDbUser()
{
final public function getDbUser() {
return $this->DBUSER;
}
final public function getDbPwd()
{
final public function getDbPwd() {
return $this->DBPWD;
}
final public function getDbName()
{
final public function getDbName() {
return $this->DBNAME;
}
final public function getUrlBootstrap()
{
final public function getUrlBootstrap() {
return $this->URLBOOTSTRAP;
}
final public function getUrlJquery()
{
final public function getUrlJquery() {
return $this->URLJQUERY;
}
final public function getUrlJqueryui()
{
final public function getUrlJqueryui() {
return $this->URLJQUERYUI;
}
final public function getUrlJAtimepicker()
{
final public function getUrlJAtimepicker() {
return $this->URLJATIMEPICKER;
}
final public function getUrlChartjs()
{
final public function getUrlChartjs() {
return $this->URLCHARTJS;
}
final public function getUrlJQCloud()
{
final public function getUrlJQCloud() {
return $this->URLJQCLOUD;
}
final public function getLocale()
{
final public function getLocale() {
return $this->LOCALE;
}
protected function setDbUser($s)
{
protected function setDbUser($s) {
$this->DBUSER = $s;
}
protected function setDbPwd($s)
{
protected function setDbPwd($s) {
$this->DBPWD = $s;
}
protected function setDbname($s)
{
protected function setDbname($s) {
$this->DBNAME = $s;
}
protected function setUrlBootstrap($s)
{
protected function setUrlBootstrap($s) {
$this->URLBOOTSTRAP = $s;
}
protected function setUrlJquery($s)
{
protected function setUrlJquery($s) {
$this->URLJQUERY = $s;
}
protected function setUrlJqueryui($s)
{
protected function setUrlJqueryui($s) {
$this->URLJQUERYUI = $s;
}
protected function setUrlJAtimepicker($s)
{
protected function setUrlJAtimepicker($s) {
$this->URLJATIMEPICKER = $s;
}
protected function setUrlChartjs($s)
{
protected function setUrlChartjs($s) {
$this->URLCHARTJS = $s;
}
protected function setUrlJQCloud($s)
{
protected function setUrlJQCloud($s) {
$this->URLJQCLOUD = $s;
}
protected function setLocale($s)
{
protected function setLocale($s) {
$this->LOCALE = $s;
}
} // class
<?php
abstract class AbstractLggrCache
{
abstract class AbstractLggrCache {
abstract protected function store($key, $value);
......
<?php
class AdminConfig extends AbstractConfig
{
class AdminConfig extends AbstractConfig {
function __construct()
{
function __construct() {
$this->setDbUser('loggeradmin');
$this->setDbPwd('lggr');
$this->setDbName('lggrdev');
......
<?php
class Config extends AbstractConfig
{
class Config extends AbstractConfig {
function __construct()
{
function __construct() {
$this->setDbUser('lggr');
$this->setDbPwd('lggr');
$this->setDbName('lggr');
......@@ -16,7 +14,8 @@ class Config extends AbstractConfig
$this->setUrlBootstrap('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/');
$this->setUrlJquery('//code.jquery.com/');
$this->setUrlJqueryui('//code.jquery.com/ui/1.11.4/');
$this->setUrlJAtimepicker('//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/');
$this->setUrlJAtimepicker(
'//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/');
$this->setUrlChartjs('//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/');
$this->setUrlJQCloud('//cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/');
......
<?php
class Lggr
{
class Lggr {
const LASTSTAT = 5000;
......@@ -19,8 +18,7 @@ class Lggr
private $aPerf = null;
function __construct(LggrState $state, AbstractConfig $config)
{
function __construct(LggrState $state, AbstractConfig $config) {
$this->config = $config;
$this->state = $state;
$this->cache = new LggrCacheFile(); // or use LggrCacheRedis instead
......@@ -30,30 +28,34 @@ class Lggr
$this->checkSecurity();
}
$this->db = new mysqli('localhost', $this->config->getDbUSer(), $this->config->getDbPwd(), $this->config->getDbName());
$this->db = new mysqli('localhost', $this->config->getDbUSer(),
$this->config->getDbPwd(), $this->config->getDbName());
$this->db->set_charset('utf8');
}
// constructor
function __destruct()
{
// constructor
function __destruct() {
if (null != $this->db) {
$this->db->close();
} // if
}
// destructor
private function checkSecurity()
{
// destructor
private function checkSecurity() {
// local access allowed without login data
if ($_SERVER["REMOTE_ADDR"] === "::1") {
return;
}
if ($_SERVER["REMOTE_ADDR"] === "127.0.0.1") {
return;
}
if (! isset($_SERVER['REMOTE_USER'])) {
throw new LggrException('You must enable basic authentication');
} // if
}
// function
private function getViewName()
{
// function
private function getViewName() {
$rcView = '';
switch ($this->state->getRange()) {
case 1:
......@@ -75,14 +77,14 @@ class Lggr
return $rcView;
}
function getLevels()
{
function getLevels() {
$perf = new LggrPerf();
$v = $this->getViewName();
$sql = "
SELECT level, COUNT(*) AS c
FROM (SELECT level FROM $v ORDER BY `date` DESC LIMIT " . self::LASTSTAT . ") AS sub
FROM (SELECT level FROM $v ORDER BY `date` DESC LIMIT " .
self::LASTSTAT . ") AS sub
GROUP BY level
ORDER BY c DESC
";
......@@ -119,9 +121,9 @@ ORDER BY c DESC
$this->cache->store("levels$v", $a);
return $a;
}
// function
function getAllServers()
{
// function
function getAllServers() {
$perf = new LggrPerf();
$sql = "
......@@ -144,9 +146,9 @@ FROM servers";
return $a;
}
// function
function getServersName($id)
{
// function
function getServersName($id) {
$perf = new LggrPerf();
$sql = "
......@@ -171,16 +173,17 @@ WHERE id=$id";
return $a->name;
}
// function
function getServers()
{
// function
function getServers() {
$perf = new LggrPerf();
$v = $this->getViewName();
$sql = "
SELECT host, COUNT(*) AS c
FROM (SELECT host FROM $v ORDER BY `date` DESC LIMIT " . self::LASTSTAT . ") AS sub
SELECT host, COUNT(*) AS c
FROM (SELECT host FROM $v ORDER BY `date` DESC LIMIT " .
self::LASTSTAT . ") AS sub
GROUP BY host
ORDER BY c DESC";
......@@ -216,9 +219,9 @@ ORDER BY c DESC";
$this->cache->store("servers$v", $a);
return $a;
}
// function
function getArchived($from = 0, $count = LggrState::PAGELEN)
{
// function
function getArchived($from = 0, $count = LggrState::PAGELEN) {
$iArchivedSize = $this->cache->retrieve(ARCHIVEDSIZE);
$aArchivedData = $this->cache->retrieve(ARCHIVEDSIZE . intval($from));
......@@ -252,9 +255,9 @@ LIMIT $from,$count";
return $a;
}
// function
function getLatest($from = 0, $count = LggrState::PAGELEN)
{
// function
function getLatest($from = 0, $count = LggrState::PAGELEN) {