Skip to content

Commit

Permalink
Merge pull request #76 from HKFree/master
Browse files Browse the repository at this point in the history
update to PHP 8.2 + Nette 3.2
  • Loading branch information
vpithart authored Dec 5, 2024
2 parents 1b1bb9f + 11b0e91 commit 1ecbe24
Show file tree
Hide file tree
Showing 29 changed files with 2,516 additions and 1,793 deletions.
19 changes: 6 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
####################################################################################################
# 1st stage (composer deps only, in order to populate cache and speed up builds)
FROM php:7.2-apache-stretch AS userdb-runtime
FROM php:8.2-apache-bookworm AS userdb-runtime

RUN a2enmod rewrite
RUN a2enmod headers

# Debian 9 "stretch" je uz starej -> lze stahovat pouze z archivu
RUN echo '\n\
deb http://archive.debian.org/debian stretch main contrib non-free\n\
deb-src http://archive.debian.org/debian stretch main contrib non-free\n\
deb http://archive.debian.org/debian-security/ stretch/updates main contrib non-free\n\
deb-src http://archive.debian.org/debian-security/ stretch/updates main contrib non-free' > /etc/apt/sources.list

# Install extenstions: MySQL PDO, GD
RUN apt-get update && apt-get install -y \
git \
Expand All @@ -21,10 +14,12 @@ RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
python \
libzip-dev \
libicu-dev \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install pdo pdo_mysql gd zip
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-configure intl \
&& docker-php-ext-install pdo pdo_mysql gd zip intl

# Enable and configure xdebug
#RUN pecl install xdebug
Expand Down Expand Up @@ -76,5 +71,3 @@ COPY . /opt/userdb
RUN chmod 777 -R /opt/userdb/log
RUN chmod 777 -R /opt/userdb/temp
RUN chmod 777 -R /opt/userdb/vendor/mpdf/mpdf/tmp

ENTRYPOINT [ "/usr/local/bin/docker-php-entrypoint" ]
5 changes: 3 additions & 2 deletions app/ApiModule/presenters/ApiPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function injectApiKlicModel(\App\Model\ApiKlic $apiKlicModel)
/*
* Called by \Nette\Application\UI\Presenter!
*/
public function checkRequirements($element) {
public function checkRequirements($element): void
{
// due to CORS preflight test, we have to respond 200 OK (not 401) to OPTIONS request
if ($this->httpRequest->getMethod() == 'OPTIONS') {
$this->handleOptionsMethod();
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function forceMethod($method) {
}
}

protected function handleOptionsMethod() {
public function handleOptionsMethod() {
$this->sendResponse(new TextResponse(""));
}

Expand Down
3 changes: 2 additions & 1 deletion app/Console/UpdateLocationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function krowToWgs($X,$Y,$H)
return(array("lat" => $B,"lon" => $L,"h" => $H));
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->googleMapsApiKey = $this->getHelper('container')->getParameter('googleMapsApiKey');
$mode = $input->getArgument('mode');
Expand Down Expand Up @@ -172,5 +172,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
sleep(2);
}
echo "update_locations finished\n";
return 0;
}
}
3 changes: 2 additions & 1 deletion app/Console/Wewimo2InfluxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function configure()
->setDescription('Ziskat Wewimo data ze vsech sledovanych RB a zapsat do InfluxDB (Grafany)');
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$influxUrl = $this->getHelper('container')->getParameter('influxUrl');

$database = InfluxDB\Client::fromDSN($influxUrl); // 'influxdb://user:pass@host:port/db'
Expand Down Expand Up @@ -87,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
echo " ERROR: " .$ex->getMessage(). "\n";
}
}
return 0;
}

private function addFloatField(&$fields, $dstField, $station, $srcField)
Expand Down
10 changes: 10 additions & 0 deletions app/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

class Settings
{
public function __construct(
public bool|array $fakeUser,
) {}
}
92 changes: 46 additions & 46 deletions app/components/LogTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class LogTable extends UI\Control
private $subnet;
private $ipAdresa;
private $log;

const UZIVATEL = 1;
const IPADRESA = 2;
const PRAVO = 3;
const AP = 4;
const SUBNET = 5;

const INSERT = "I";
const UPDATE = "U";
const DELETE = "D";

public function __construct($parentPresenter, Model\IPAdresa $ipAdresa, Model\Subnet $subnet, Model\Log $log)
{
//parent::__construct();
Expand All @@ -31,19 +31,19 @@ public function __construct($parentPresenter, Model\IPAdresa $ipAdresa, Model\Su
$this->subnet = $subnet;
$this->log = $log;
}

/**
* Funkce parsující věci, co se vyskytují v poli "sloupec" v DB.
*
*
* V případě Uživatele vrací "typ"=>UZIVATEL a "sloupec"
* V případě IPAdresy vrací "typ"=>IPADRESA, "ipId" a "sloupec"
*
*
* @param string $sloupec IPAdresa.sloupec z DB
* @return array (typ, sloupec, ipId)
* @return array (typ, sloupec, ipId) or empty array (falsy value) when not matched
*/
private function parseSloupec($sloupec)
{
$out = false;
$out = [];
if (preg_match("/^uzivatel\.(.+)/i", $sloupec, $matches))
{
$out["typ"] = self::UZIVATEL;
Expand Down Expand Up @@ -74,10 +74,10 @@ private function parseSloupec($sloupec)
}
return($out);
}

/**
* Funkce která projde logy a pro všechny IPčka udělá seznam ipId - ipAdresa
*
*
* @param array $logy pole ipId
* @return array pole ipId=>ipAdresa
*/
Expand All @@ -91,16 +91,16 @@ private function getIPMapping($logy)
$ipsKProhlednuti[$sloupec["ipId"]] = "Nenalezeno";
}
}

$ipZDB = $this->ipAdresa->getIPzDB(array_keys($ipsKProhlednuti));
$ipZLogu = $this->log->getAdvancedzLogu(array_keys($ipsKProhlednuti));
// Bacha na poradi!
return($ipZDB + $ipZLogu + $ipsKProhlednuti);
}

/**
* Funkce která projde logy a pro všechny Subnety udělá seznam subnetId - subnet
*
*
* @param array $logy pole subnetId
* @return array pole subnetId=>subnet
*/
Expand All @@ -114,36 +114,36 @@ private function getSubnetMapping($logy)
$subnetsKProhlednuti[$sloupec["subnetId"]] = "Nenalezeno";
}
}

$subnetZDB = $this->subnet->getSubnetzDB(array_keys($subnetsKProhlednuti));
$subnetZLogu = $this->log->getAdvancedzLogu(array_keys($subnetsKProhlednuti), 'subnet');
// Bacha na poradi!
return($subnetZDB + $subnetZLogu + $subnetsKProhlednuti);
}

private function tableGetHeader()
{
$logyTab = Html::el('table')->setClass('table table-striped logstable');
$tr = $logyTab->create('tr');

$sloupce = array('Kdy', 'Kdo', 'Co', 'Z', 'Na');
foreach ($sloupce as $sloupec) {
$tr->create('th')->setText($sloupec);
}

return($logyTab);
}

private function tableGetFooter(&$table)
{
$table->create('script')->setHTML('$(\'a\').tooltip();');
return($table);
}

private function tableGetLineBegin(&$table, $line)
{
$tooltips = array('data-toggle' => 'tooltip', 'data-placement' => 'top');

$tr = $table->create('tr');
$tr->create('td')->setText($line->datum);

Expand All @@ -155,12 +155,12 @@ private function tableGetLineBegin(&$table, $line)
$tr->create('td')->setHtml($uzivatelA);
return($tr);
}

private function tableGetLineEndSimple(&$tr, $line, $rozparsovano)
{
$sloupec = $this->log->translateJmeno($rozparsovano["sloupec"]);
$tr->create('td')->setText($sloupec);

if($sloupec == 'heslo')
{
$tr->create('td')->setText('N/A');
Expand All @@ -178,25 +178,25 @@ private function tableGetLineEndSimple(&$tr, $line, $rozparsovano)
$tr->create('td')->setText($line->nova_hodnota);
}
}


private function tableProcessLines(&$table, $logy)
{
$ipVsechny = $this->getIPMapping($logy);
$subnetyVsechny = $this->getSubnetMapping($logy);

$last = false;
$toSkip = array("uzivatel_id", "ap_id");

$toSkip = array("uzivatel_id", "ap_id");
$toSkipString = implode("|", $toSkip);

foreach ($logy as $key => $line) {
if(($rozparsovano = $this->parseSloupec($line->sloupec)) === false)
if(!($rozparsovano = $this->parseSloupec($line->sloupec)))
continue;

if(preg_match("/^heslo/i", $rozparsovano["sloupec"]))
continue;

if($rozparsovano["typ"] == self::UZIVATEL) {
$tr = $this->tableGetLineBegin($table, $line);
$this->tableGetLineEndSimple($tr, $line, $rozparsovano);
Expand All @@ -214,11 +214,11 @@ private function tableProcessLines(&$table, $logy)

$datum = $line->datum;
$titulek = "IP ".$ipVsechny[$id];

if($last !== false && $last[0]->getText() == $datum && $last[2]->getText() == $titulek)
{
$text = "";
if($line->akce === self::INSERT)
if($line->akce === self::INSERT)
$text = $sloupec." = ".$line->nova_hodnota.", ";
elseif($line->akce === self::DELETE && $line->puvodni_hodnota!=null)
$text = $sloupec." = ".$line->puvodni_hodnota.", ";
Expand All @@ -231,15 +231,15 @@ private function tableProcessLines(&$table, $logy)
$last = $tr = $this->tableGetLineBegin($table, $line);

$tr->create('td')->setText($titulek);

$text = "";
if($line->akce === self::INSERT)
if($line->akce === self::INSERT)
$text = "Založení IP Adresy s parametry ".$sloupec." = ".$line->nova_hodnota.", ";
elseif($line->akce === self::DELETE)
$text = "IP Adresa byla smazána. Parametry byly ".$sloupec." = ".$line->puvodni_hodnota.", ";
elseif($line->akce === self::UPDATE)
$text = "Změna ".$sloupec." z ".$line->puvodni_hodnota." na ".$line->nova_hodnota.", ";

$tr->create('td')->setText($text)->setColspan(2);
}
}
Expand All @@ -252,11 +252,11 @@ private function tableProcessLines(&$table, $logy)

$datum = $line->datum;
$titulek = "Subnet ".$subnetyVsechny[$id];

if($last !== false && $last[0]->getText() == $datum && $last[2]->getText() == $titulek)
{
$text = "";
if($line->akce === self::INSERT)
if($line->akce === self::INSERT)
$text = $sloupec." = ".$line->nova_hodnota.", ";
elseif($line->akce === self::DELETE && $line->puvodni_hodnota!=null)
$text = $sloupec." = ".$line->puvodni_hodnota.", ";
Expand All @@ -269,41 +269,41 @@ private function tableProcessLines(&$table, $logy)
$last = $tr = $this->tableGetLineBegin($table, $line);

$tr->create('td')->setText($titulek);

$text = "";
if($line->akce === self::INSERT)
if($line->akce === self::INSERT)
$text = "Založení subnetu s parametry ".$sloupec." = ".$line->nova_hodnota.", ";
elseif($line->akce === self::DELETE)
$text = "Subnet byl smazán. Parametry byly ".$sloupec." = ".$line->puvodni_hodnota.", ";
elseif($line->akce === self::UPDATE)
$text = "Změna ".$sloupec." z ".$line->puvodni_hodnota." na ".$line->nova_hodnota.", ";

$tr->create('td')->setText($text)->setColspan(2);
}
}
}
}

public function render($id, $type = "user")
{
$template = $this->template;
$template->setFile(__DIR__ . '/LogTable.latte');

$tabulka = $this->tableGetHeader();
if($type == "user") {
$logy = $this->log->getLogyUzivatele($id);
$logy = $this->log->getLogyUzivatele($id);
} elseif($type == "ap") {
$logy = $this->log->getLogyAP($id);
$logy = $this->log->getLogyAP($id);
} else {
die('Spatne pouziti komponenty LogTable.');
}

$this->tableProcessLines($tabulka, $logy);
$this->tableGetFooter($tabulka);
// vložíme do šablony nějaké parametry

// vložíme do šablony nějaké parametry
$template->tabulka = $tabulka;

// a vykreslíme ji
$template->render();
}
Expand Down
Loading

0 comments on commit 1ecbe24

Please sign in to comment.