diff --git a/Dockerfile b/Dockerfile index d6f1084c5b065e523550c5fb338eb006d3e4f4e7..af287d814eae8b400bb56ab8c3d837fbd5714ba6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,8 @@ RUN cpanm \ Mojo::Redis \ Mojo::JWT \ Mojolicious::Plugin::Authentication \ + Mojolicious::Plugin::BrowserDetect \ + Mojolicious::Plugin::ForwardedFor \ Mojolicious::Plugin::OpenAPI ADD . /opt/PZ diff --git a/TODO b/TODO index 5966e7f04f8b90fef08370c50196fc1bc19521e2..30ecaf983c4d566b2e27eb73e7f501bb9ca7acd8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ - statistika -- editace/smazani - loop detect - 302 nebo informacni stranka diff --git a/VERSION b/VERSION index 7dea76edb3dc51b6e5e8223e9f941a35c1e364d6..9084fa2f716a7117829f3f32a5f4cef400e02903 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.1 +1.1.0 diff --git a/lib/PZ.pm b/lib/PZ.pm index 81221fbd0b33d18ecb1f5f9e8db66d751799a32f..96d5e1376cd5c2c6786c619b6d39005e82ce3a6e 100644 --- a/lib/PZ.pm +++ b/lib/PZ.pm @@ -20,6 +20,7 @@ sub startup { # Delka session $self->sessions->default_expiration($cfg->{session}{lifetime}); + $self->plugin("ForwardedFor"); $self->plugin('PZ::Helpers::Core'); $self->plugin('PZ::Helpers::OIDC'); diff --git a/lib/PZ/Controller/Shortcut.pm b/lib/PZ/Controller/Shortcut.pm index e46d6c2b13318fec3c0fa7d3fa8523c1f70e7693..be4db4691ddec268ad1590e6c6d37edc0e3b36a5 100644 --- a/lib/PZ/Controller/Shortcut.pm +++ b/lib/PZ/Controller/Shortcut.pm @@ -16,6 +16,11 @@ sub redirect ($c) { return; } + $shortcut->add_to_log_items({ + ip => ($c->forwarded_for || $c->tx->remote_address), + ua => $c->req->headers->user_agent, + }); + $c->res->code($shortcut->code); $c->redirect_to($shortcut->url); } diff --git a/lib/PZ/Schema/Result/Shortcut.pm b/lib/PZ/Schema/Result/Shortcut.pm index d79d5fa5bb5ab45a30a4af0dcb5c51e653f6c8f8..11d302279d418a06ae37674fe7081bb48f1a8313 100644 --- a/lib/PZ/Schema/Result/Shortcut.pm +++ b/lib/PZ/Schema/Result/Shortcut.pm @@ -37,5 +37,9 @@ __PACKAGE__->add_unique_constraint( 'shortcut' => [qw(shortcut)] ); +__PACKAGE__->has_many( + log_items => 'PZ::Schema::Result::Log', + { 'foreign.shortcut_id' => 'self.id', }, +); 1; diff --git a/sql/migrations.sql b/sql/migrations.sql index eda2436e0198699aba867bcad447318eea4f1bcd..979778074f82663ddeff87efc565c46a4cedc740 100644 --- a/sql/migrations.sql +++ b/sql/migrations.sql @@ -44,3 +44,6 @@ create table "log" ( alter table "shortcuts" alter column "code" set default 302; alter table "shortcuts" drop constraint "shortcuts_shortcut_key"; create index "shortcuts_shortcut_idx" on "shortcuts" ("shortcut"); + +-- 3 up +alter table "log" add column "ua" text;