first initial
This commit is contained in:
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# $Header: svn://svnsrv.mlands.com/systools/cpan2deb/trunk/Mojo-mysql/_do_it.sh 2139 2022-12-22 20:18:18Z js000387 $
|
||||||
|
|
||||||
|
export DEBFULLNAME="Jan Henning Thorsen"
|
||||||
|
export DEBEMAIL="jhthorsen@cpan.org"
|
||||||
|
#export DEB_BUILD_OPTIONS="nocheck"
|
||||||
|
|
||||||
|
cpan2deb Mojo::mysql
|
||||||
|
#--depends "libmojolicious-perl, libdbd-mysql-perl, libsql-abstract-perl" --version "1.07-2"
|
||||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Ca ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
VER=`grep Version DEBIAN/control | cut -d: -f2`
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Package: libsteffen-mojoplug-authorization-perl
|
||||||
|
Version: 1.0
|
||||||
|
Section: perl
|
||||||
|
Priority: optional
|
||||||
|
Architecture: all
|
||||||
|
Depends: libmojolicious-plugin-authorization-perl
|
||||||
|
Installed-Size: 94
|
||||||
|
Maintainer: Steffen Junge <Steffen.Junge@mlands.com>
|
||||||
|
Description: Steffens MOJO Plug Authorization
|
||||||
BIN
Binary file not shown.
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Cav ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
# Version in die startup app.pm eintragen
|
||||||
|
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
|
||||||
|
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/steffen/MojoPlug/Authorization.pm
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package steffen::MojoPlug::Authorization;
|
||||||
|
use parent 'Mojolicious::Plugin::Authorization';
|
||||||
|
|
||||||
|
our $VERSION = '__VERSION__';
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($self, $app, $args) = @_;
|
||||||
|
|
||||||
|
my $verbose = $args->{verbose} || 0;
|
||||||
|
|
||||||
|
$args->{has_priv} = sub {
|
||||||
|
my ($self, $priv, $xtra) = @_;
|
||||||
|
#$self->app->log->debug('has_priv') if $verbose;
|
||||||
|
return grep { /$priv/ } @{$self->session->{privs}};
|
||||||
|
};
|
||||||
|
|
||||||
|
$args->{is_role} = sub {
|
||||||
|
my ($self, $role, $xtra) = @_;
|
||||||
|
#$self->app->log->debug('is_role') if $verbose;
|
||||||
|
return $role eq $self->session->{role};
|
||||||
|
};
|
||||||
|
|
||||||
|
$args->{user_privs} = sub {
|
||||||
|
my ($self, $xtra) = @_;
|
||||||
|
#$self->app->log->debug('user_privs') if $verbose;
|
||||||
|
return $self->session->{privs};
|
||||||
|
};
|
||||||
|
|
||||||
|
$args->{user_role} = sub {
|
||||||
|
my ($self, $xtra) = @_;
|
||||||
|
#$self->app->log->debug('user_role') if $verbose;
|
||||||
|
return $self->session->{role};
|
||||||
|
};
|
||||||
|
|
||||||
|
$self->SUPER::register($app, $args);
|
||||||
|
$app->log->info(sprintf('REGISTERED: %s %s', __PACKAGE__, q$Revision: 86 $)) if $verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Package: libsteffen-mojoplug-navhelper-perl
|
||||||
|
Version: 1.0
|
||||||
|
Section: perl
|
||||||
|
Priority: optional
|
||||||
|
Architecture: all
|
||||||
|
Depends: libsteffen-mojoplug-authorization-perl
|
||||||
|
Installed-Size: 94
|
||||||
|
Maintainer: Steffen Junge <Steffen.Junge@mlands.com>
|
||||||
|
Description: Bootstrap 4/5 Menu
|
||||||
Binary file not shown.
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Cav ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
# Version in die startup app.pm eintragen
|
||||||
|
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
|
||||||
|
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/steffen/MojoPlug/NavHelper.pm
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package steffen::MojoPlug::NavHelper;
|
||||||
|
use Mojo::Base 'Mojolicious::Plugin';
|
||||||
|
|
||||||
|
our $VERSION = '__VERSION__';
|
||||||
|
|
||||||
|
# Navigation Helper für Bootstrap 4,5 navbar
|
||||||
|
#
|
||||||
|
# $self->plugin('steffen::MojoPlug::NavHelper' => { verbose => 0, bs => 5 });
|
||||||
|
#
|
||||||
|
# $menuitadmin = [
|
||||||
|
# {
|
||||||
|
# text => 'Admin Tools', icon => 'fas fa-tools', priv => 'itadmin',
|
||||||
|
# dropdown => [
|
||||||
|
# { icon => 'fas fa-file-code', text => 'Powershell Mitarbeiter in AD', href => '/rfs/get_psscript_noadlogin'},
|
||||||
|
# ]
|
||||||
|
# },
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# in html.ep
|
||||||
|
# <ul class="navbar-nav">
|
||||||
|
# <%== nav( $menuitadmin) %>
|
||||||
|
# </ul>
|
||||||
|
#
|
||||||
|
# priv = Privilegienabfrage benötigt das Plugin Authorization dort ist has_priv integriert
|
||||||
|
# icon = ein css Klassenicon fontawesome funktioniert ganz gut
|
||||||
|
# navlinkclass = zusätzliche navlinkclasse zum markieren
|
||||||
|
# iconstyle = htmlstyle
|
||||||
|
# text = text des links
|
||||||
|
# textstyle = htmlstyle
|
||||||
|
# dropdown = Anfang eines Dropdowmenu
|
||||||
|
# href = Link wird im selben Fenster geöffnet
|
||||||
|
# xhref = Link wird auf in neuem Fenster geöffnet
|
||||||
|
# img = Bildurl
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($self, $app, $args) = @_;
|
||||||
|
my $verbose = $args->{verbose} || 0;
|
||||||
|
my $bs = $args->{bs} || 4; # oder 5
|
||||||
|
|
||||||
|
$app->helper(nav => sub {
|
||||||
|
my ($c, $nav) = @_;
|
||||||
|
|
||||||
|
my $html = '';
|
||||||
|
foreach my $i (@{$nav}) {
|
||||||
|
next if ($i->{priv} && ! $c->has_priv($i->{priv}));
|
||||||
|
if ($i->{dropdown}) {
|
||||||
|
$html .= '<li class="nav-item dropdown">';
|
||||||
|
$html .= sprintf('<a href="#" class="nav-link dropdown-toggle %s"', $i->{navlinkclass} ? $i->{navlinkclass} :'').( $bs == 5 ? 'data-bs-toggle' : 'data-toggle' ) .'="dropdown" role="button" aria-haspopup="true" aria-expanded="false">';
|
||||||
|
$html .= $i->{icon} ? sprintf('<span class="%s p%s-2" style="%s"></span>', $i->{icon}, ( $bs == 5 ? 'e' : 'r' ), ($i->{iconstyle} ? $i->{iconstyle} :'')) : '';
|
||||||
|
$html .= sprintf('<span style="%s">%s</span>', ($i->{textstyle} ? $i->{textstyle} :''), $i->{text});
|
||||||
|
$html .= '<span class="caret"></span></a> <ul class="dropdown-menu">';
|
||||||
|
foreach my $d (@{$i->{dropdown}}) {
|
||||||
|
next if ($d->{priv} && ! $c->has_priv($d->{priv}));
|
||||||
|
if ($d->{xhref} ) {
|
||||||
|
$html .= sprintf('<li><a target="blank" class="dropdown-item form-control" href="%s">', ( $d->{xhref} =~ /http/ ? $d->{xhref} : $c->url_for($d->{xhref}) ) );
|
||||||
|
} elsif ($d->{href} ) {
|
||||||
|
$html .= sprintf('<li><a class="dropdown-item form-control" href="%s">', ( $d->{href} =~ /http/ ? $d->{href} : $c->url_for($d->{href}) ) | '' );
|
||||||
|
}
|
||||||
|
$html .= $d->{icon} ? sprintf('<span class="%s" style="%s"></span>', $d->{icon}, ($d->{iconstyle} ? $d->{iconstyle} :'') ) : '';
|
||||||
|
$html .= $d->{img} ? sprintf('<img height="18px" src="%s">', ( $d->{img} =~ /http/ ? $d->{img} : $c->url_for($d->{img}) ) ) : '';
|
||||||
|
$html .= ( $bs == 5 ? '<span class="ps-2">' : '<span class="pl-2">' );
|
||||||
|
$html .= sprintf('<span style="%s">%s</span>', ($d->{textstyle} ? $d->{textstyle} :''), $d->{text});
|
||||||
|
$html .= '</span></a></li>';
|
||||||
|
}
|
||||||
|
$html .= '</ul></li> ';
|
||||||
|
} else {
|
||||||
|
$html .= sprintf('<li><a class="nav-link %s" href="%s">', $i->{navlinkclass} ? $i->{navlinkclass} :'', ( $i->{href} =~ /http/ ? $i->{href} : $c->url_for($i->{href}) ) );
|
||||||
|
$html .= $i->{img} ? sprintf('<img height="18px" src="%s">', ( $i->{img} =~ /http/ ? $i->{img} : $c->url_for($i->{img}) ) ) : '';
|
||||||
|
$html .= $i->{icon} ? sprintf('<span class="%s" style="%s"></span>', $i->{icon}, ($i->{iconstyle} ? $i->{iconstyle} :'')) : '';
|
||||||
|
$html .= ( $bs == 5 ? '<span class="ps-2">' : '<span class="pl-2">' );
|
||||||
|
$html .= sprintf('<span style="%s">%s</span>', ($i->{textstyle} ? $i->{textstyle} :''), $i->{text});
|
||||||
|
$html .= '</span></a></li>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->log->info(sprintf('REGISTERED: %s %s', __PACKAGE__, q$Revision: 411 $)) if $verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Package: libsteffen-mojoplug-openapi-perl
|
||||||
|
Version: 0.0.1-1
|
||||||
|
Section: perl
|
||||||
|
Priority: optional
|
||||||
|
Architecture: all
|
||||||
|
Depends: libmojolicious-perl (>= 9.00), libmojolicious-plugin-openapi-perl
|
||||||
|
Installed-Size: 80
|
||||||
|
Maintainer:Tilo Brueckner <Tilo.Brueckner@mlands.com>
|
||||||
|
Description: Validierung der Übergabevariablen und Rückgabe im mlands Format
|
||||||
Binary file not shown.
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Cav ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
# Version in die startup app.pm eintragen
|
||||||
|
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
|
||||||
|
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/steffen/MojoPlug/OpenAPI.pm
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
# Plugin mit funktioneller Erweiterung von Mojolicious::Plugin::OpenAPI.
|
||||||
|
#
|
||||||
|
# SYNOPSIS
|
||||||
|
# ========
|
||||||
|
#
|
||||||
|
# Dies ist als Erweiterung bzw. Ersatz zu Mojolicious::Plugin::OpenAPI->valid_input gedacht.
|
||||||
|
# Wichtig ist hier, dass man den Rückgabetyp (return_type) definieren kann:
|
||||||
|
# - empty_array: JSON mit leerem Array
|
||||||
|
# - empty_hash: JSON mit leerem Hash
|
||||||
|
# - mlands_msg: JSON mit mlands-Struktur - in msg ist die Fehlermeldung
|
||||||
|
# - mlands: JSON mit mlands-Struktur - in msg steht 'Fehlerhafte Anfrage'
|
||||||
|
# - alternativ kommt es in der Struktur von JSON::Validator zurück
|
||||||
|
#
|
||||||
|
# mit dem Parameter 'validate_return' wird die Rückgabe vor dem Senden zum Nutzer validiert
|
||||||
|
#
|
||||||
|
# Die Fehlermeldung wird als Info-Meldung im Log des Programms abgelegt
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Beispiel
|
||||||
|
#
|
||||||
|
# sub rfc_function {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->openapi()->validate_params({'validate_return' => '1'}) || return;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# $self->plugin('steffen::MojoPlug::OpenAPI' => { verbose => 1 });
|
||||||
|
#
|
||||||
|
# Beispiel 1 - liefert JSON mit einem leeren Array zurück
|
||||||
|
#
|
||||||
|
# sub rfc_function {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->openapi()->validate_params({'return_type' => 'empty_array'}) || return;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# Beispiel 2 - liefert JSON mit einen leeren Hash zurück
|
||||||
|
#
|
||||||
|
# sub rfc_function {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->openapi()->validate_params({'return_type' => 'empty_hash'}) || return;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# Beispiel 3 - liefert JSON mit der mlands Struktur zurück
|
||||||
|
#
|
||||||
|
# sub rfc_function {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->openapi()->validate_params({'return_type' => 'mlands'}) || return;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# Beispiel 4 - liefert JSON mit der mlands Struktur in msg steht die Fehlermeldung zurück
|
||||||
|
#
|
||||||
|
# sub rfc_function {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->openapi()->validate_params({'return_type' => 'mlands_msg'}) || return;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# SEE ALSO
|
||||||
|
# ========
|
||||||
|
# L<https://metacpan.org/pod/Mojolicious::Plugin::OpenAPI>
|
||||||
|
# AUTHOR
|
||||||
|
# ======
|
||||||
|
# Tilo Brueckner tilo.brueckner@mlands.com
|
||||||
|
|
||||||
|
package steffen::MojoPlug::OpenAPI;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
use Mojo::Base 'Mojolicious::Plugin';
|
||||||
|
|
||||||
|
our $VERSION = '__VERSION__';
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($c, $app, $config) = @_;
|
||||||
|
|
||||||
|
$app->helper('openapi.validate_params' => \&_validate_params);
|
||||||
|
|
||||||
|
if ($config && %{$config} && $config->{'verbose'}) {
|
||||||
|
$app->log()->info(sprintf('REGISTERED: %s V%s', __PACKAGE__, $VERSION));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _validate_params {
|
||||||
|
my ($c, $params) = @_;
|
||||||
|
|
||||||
|
if (!$params || ref $params ne 'HASH') {
|
||||||
|
$c->app()->log()->warn('fehlerhafte oder leere Parameter bei Funktionsaufruf');
|
||||||
|
$params = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
$params->{'return_type'} //= q||;
|
||||||
|
|
||||||
|
my $type = $params->{'validate_return'} ? 'openapi' : 'json';
|
||||||
|
|
||||||
|
# es wird nur ausgewertet, wenn wir auchwirklich mit OpenAPI auf dem Pfad arbeiten
|
||||||
|
if ($c->stash()->{'openapi.path'}) {
|
||||||
|
my @errors = $c->openapi()->validate();
|
||||||
|
if (@errors) {
|
||||||
|
# Die übergebenen Parameter für die Fehleranzeige
|
||||||
|
my $params = $c->req()->json() || $c->req()->body_params()->to_hash();
|
||||||
|
my $msg = q||;
|
||||||
|
for my $error (@errors) {
|
||||||
|
if ($error->details()->[1] eq 'type') {
|
||||||
|
$msg .= 'Expected ' . $error->details()->[0] . ' - got ' . $error->details()->[2] . ' in path ' . $error->path() . "\n";
|
||||||
|
}
|
||||||
|
elsif ($error->details()->[1] eq 'required') {
|
||||||
|
$msg .= 'Missing property: ' . $error->path() . "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my @keys = split /\//, $error->path();
|
||||||
|
$msg .= 'Value "' . $params->{$keys[-1]} . '" does not match reqirement (' . $error->details()->[1] . '): ' . $error->path() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ausgabe im Log
|
||||||
|
$c->app()->log()->warn($msg);
|
||||||
|
|
||||||
|
# Rückgabe an den Aufrufer
|
||||||
|
if ($params->{'return_type'} eq 'empty_array') {
|
||||||
|
return !$c->render($type => [], 'status' => 400);
|
||||||
|
}
|
||||||
|
elsif ($params->{'return_type'} eq 'empty_hash') {
|
||||||
|
return !$c->render($type => {}, 'status' => 400);
|
||||||
|
}
|
||||||
|
elsif ($params->{'return_type'} eq 'mlands_msg') {
|
||||||
|
return !$c->render($type => {'rc' => 1, 'msg' => $msg}, 'status' => 400);
|
||||||
|
}
|
||||||
|
elsif ($params->{'return_type'} eq 'mlands') {
|
||||||
|
return !$c->render($type => {'rc' => 1, 'msg' => 'Fehlerhafte Anfrage'}, 'status' => 400);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return !$c->render($type => \@errors, 'status' => 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Package: libsteffen-mojoplug-swaggerui-perl
|
||||||
|
Version: 0.0.5-2
|
||||||
|
Section: perl
|
||||||
|
Priority: optional
|
||||||
|
Architecture: all
|
||||||
|
Depends: libmojolicious-perl (>= 9.00)
|
||||||
|
Installed-Size: 80
|
||||||
|
Maintainer: Steffen Junge <Steffen.Junge@mlands.com>
|
||||||
|
Description: Fork von Mojolicious::Plugin::SwaggerUI speziell für steffen
|
||||||
Binary file not shown.
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Cav ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
# Version in die startup app.pm eintragen
|
||||||
|
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
|
||||||
|
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/steffen/MojoPlug/SwaggerUI.pm
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+3
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+52
@@ -0,0 +1,52 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><%= $title %></title>
|
||||||
|
%= stylesheet "/swagger-ui/swagger-ui.css"
|
||||||
|
% if (defined $favicon) {
|
||||||
|
<link rel="icon" type="image/png" href=<%= url_for($favicon) %> />
|
||||||
|
% }
|
||||||
|
<style>
|
||||||
|
html
|
||||||
|
{
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: -moz-scrollbars-vertical;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after
|
||||||
|
{
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
margin:0;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
|
||||||
|
%= javascript "/swagger-ui/swagger-ui-bundle.js"
|
||||||
|
%= javascript "/swagger-ui/swagger-ui-standalone-preset.js"
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.onload = function () {
|
||||||
|
const ui = SwaggerUIBundle({
|
||||||
|
url: "<%= url_for($url) %>",
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
validatorUrl: <%= $validateUrl %>,
|
||||||
|
presets: [
|
||||||
|
SwaggerUIBundle.presets.apis,
|
||||||
|
SwaggerUIStandalonePreset
|
||||||
|
],
|
||||||
|
layout: "StandaloneLayout"
|
||||||
|
})
|
||||||
|
|
||||||
|
window.ui = ui
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package steffen::MojoPlug::SwaggerUI;
|
||||||
|
|
||||||
|
use Mojo::Base 'Mojolicious::Plugin';
|
||||||
|
use Mojo::File qw(path);
|
||||||
|
|
||||||
|
use File::ShareDir qw(dist_dir);
|
||||||
|
|
||||||
|
our $VERSION = '__VERSION__';
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($self, $app, $config) = @_;
|
||||||
|
|
||||||
|
my $prefix = $config->{route} // $app->routes()->any('/swagger-ui');
|
||||||
|
|
||||||
|
# --- Configuring the Mojolicious path resolvers
|
||||||
|
my $resources = path(dist_dir('steffen-MojoPlug-SwaggerUI'))
|
||||||
|
->child('resources');
|
||||||
|
|
||||||
|
push(@{$app->static()->paths()}, $resources->child('public')->to_string());
|
||||||
|
push(@{$app->renderer()->paths()}, $resources->child('templates')->to_string());
|
||||||
|
|
||||||
|
# --- Adding the route
|
||||||
|
my $url = $config->{url} // '/v1';
|
||||||
|
my $title = $config->{title} // 'Swagger UI';
|
||||||
|
my $validateUrl = $config->{validateUrl} // 'null';
|
||||||
|
my $favicon
|
||||||
|
= (defined $config->{favicon} and $app->static()->file($config->{favicon}))
|
||||||
|
? $config->{favicon}
|
||||||
|
: undef;
|
||||||
|
|
||||||
|
$prefix->get(q(/) => { url => $url, title => $title, favicon => $favicon, validateUrl => $validateUrl })
|
||||||
|
->name('swagger_ui');
|
||||||
|
|
||||||
|
$app->log->info(sprintf('REGISTERED: %s V%s', __PACKAGE__, $VERSION)) if $config->{verbose};
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
=encoding utf8
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Mojolicious::Plugin::SwaggerUI - Swagger UI plugin for Mojolicious
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
# Mojolicious Lite
|
||||||
|
plugin 'SwaggerUI' => {
|
||||||
|
route => app->routes()->any('/swagger'),
|
||||||
|
url => '/swagger.json',
|
||||||
|
};
|
||||||
|
|
||||||
|
# Mojolicious Full
|
||||||
|
$app->plugin(
|
||||||
|
SwaggerUI => {
|
||||||
|
route => $app->routes()->any('api'),
|
||||||
|
url => "/api/v1",
|
||||||
|
title => "Mojolicious App",
|
||||||
|
favicon => "/images/favicon.png"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
The plugin allows you to run the Swagger UI component inside your Mojolicious application.
|
||||||
|
|
||||||
|
=begin html
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<img alt="Screenshot"
|
||||||
|
src="https://gitlab.com/marghidanu/mojolicious-plugin-swaggerui/raw/master/share/images/Screenshot.png?inline=true">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
=end html
|
||||||
|
|
||||||
|
=head1 OPTIONS
|
||||||
|
|
||||||
|
=head2 route
|
||||||
|
|
||||||
|
plugin 'SwaggerUI' => {
|
||||||
|
route => app()->routes()->any('/swagger')
|
||||||
|
};
|
||||||
|
|
||||||
|
Route for the swagger-ui component. It defaults to a any route on C</swagger-ui>
|
||||||
|
|
||||||
|
=head2 url
|
||||||
|
|
||||||
|
plugin 'SwaggerUI' => {
|
||||||
|
url => '/swagger.json'
|
||||||
|
};
|
||||||
|
|
||||||
|
Url for the JSON Swagger specification. It defaults to C</v1>.
|
||||||
|
|
||||||
|
B<NOTE:>
|
||||||
|
L<Mojolicious::Plugin::OpenAPI> can expose the JSON Swagger spec under the base path route.
|
||||||
|
You can just point the path in her and it will automatically work.
|
||||||
|
|
||||||
|
=head2 title
|
||||||
|
|
||||||
|
plugin 'SwaggerUI' => {
|
||||||
|
title => 'Project Title'
|
||||||
|
};
|
||||||
|
|
||||||
|
The HTML title that you want to show on swagger-ui page. Deafult to 'Swagger UI'
|
||||||
|
|
||||||
|
=head2 favicon
|
||||||
|
|
||||||
|
plugin 'SwaggerUI' => {
|
||||||
|
favicon => '/images/favicon.png'
|
||||||
|
};
|
||||||
|
|
||||||
|
Favicon which you want to associate with swagger-ui page.
|
||||||
|
|
||||||
|
It will be served automatically from a 'public' directory if it exists.
|
||||||
|
In case of non existence mojolicious default favicon will be displayed.
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Tudor Marghidanu C<tudor@marghidanu.com>
|
||||||
|
|
||||||
|
=head1 CREDITS
|
||||||
|
|
||||||
|
Gaurav Rai C<gauravrai7860@gmail.com>
|
||||||
|
|
||||||
|
=head1 COPYRIGHT AND LICENSE
|
||||||
|
|
||||||
|
Copyright (C) 2019, Tudor Marghidanu.
|
||||||
|
|
||||||
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
__END__
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Package: libsteffen-mojoplug-syslog-perl
|
||||||
|
Version: 0.10-1
|
||||||
|
Section: perl
|
||||||
|
Priority: optional
|
||||||
|
Architecture: all
|
||||||
|
Depends: libsys-syslog-perl
|
||||||
|
Installed-Size: 94
|
||||||
|
Maintainer: Steffen Junge <Steffen.Junge@mlands.com>
|
||||||
|
Description: Pendant zum Mojolicious-Plugin-Syslog angepasst für mlands
|
||||||
Binary file not shown.
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script=`echo $0 | sed 's/^.*\///'`
|
||||||
|
echo "$script"
|
||||||
|
if [ -e ./$script ]; then
|
||||||
|
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
|
||||||
|
rm -Rf $workdir/*
|
||||||
|
mkdir -p $workdir
|
||||||
|
rsync -Cav ./DEBIAN $workdir/
|
||||||
|
|
||||||
|
rsync -Cav ./usr $workdir/
|
||||||
|
|
||||||
|
# Version in die startup app.pm eintragen
|
||||||
|
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
|
||||||
|
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/mlands/MojoPlug/Syslog.pm
|
||||||
|
echo "Version $VER"
|
||||||
|
|
||||||
|
chmod -R g-s $workdir
|
||||||
|
fakeroot dpkg-deb -b $workdir ./
|
||||||
|
|
||||||
|
echo "Installed-Size:"
|
||||||
|
du -h -k --max-depth=0 $workdir
|
||||||
|
|
||||||
|
else
|
||||||
|
echo Das Script $script muss im aktuellen Verzeichnis liegen!
|
||||||
|
echo Bitte dorthin wechseln und nochmal probieren.
|
||||||
|
fi
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
package steffen::MojoPlug::Syslog;
|
||||||
|
use Mojo::Base 'Mojolicious::Plugin';
|
||||||
|
use Sys::Syslog qw(:standard :macros);
|
||||||
|
|
||||||
|
our $VERSION = '__VERSION__';
|
||||||
|
|
||||||
|
my %PRIORITY = (
|
||||||
|
debug => LOG_DEBUG,
|
||||||
|
error => LOG_ERR,
|
||||||
|
fatal => LOG_CRIT,
|
||||||
|
info => LOG_INFO,
|
||||||
|
warn => LOG_WARNING,
|
||||||
|
);
|
||||||
|
|
||||||
|
sub register {
|
||||||
|
my ($self, $app, $config) = @_;
|
||||||
|
my $log_warn = $config->{log_warn} || '1';
|
||||||
|
my $log_level = $config->{level} || 'info';
|
||||||
|
my $log_color = $config->{color} && $config->{color} eq 1 ? 1 : 0;
|
||||||
|
my $only_syslog = $config->{only_syslog} && $config->{only_syslog} eq 1 ? 1 : 0;
|
||||||
|
|
||||||
|
if ( $Mojolicious::VERSION < 9.20 ) {
|
||||||
|
if ( $config->{access_log} && $config->{access_log} ne '' ) {
|
||||||
|
$config->{access_log} = undef;
|
||||||
|
$app->log->warn('Mojo access_log geht erst ab Version 9.20, wird deaktiviert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $log_level =~ /trace/ ) {
|
||||||
|
$log_level = 'debug';
|
||||||
|
$app->log->warn('Mojo Trace geht erst ab Version 9.20, setze auf debug');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $Mojolicious::VERSION > 9.00 ) {
|
||||||
|
$app->log->color( $log_color )
|
||||||
|
} elsif ( $log_color == 1 ) {
|
||||||
|
$app->log->warn('Mojo Log Color geht erst ab Version 9.01');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $log_level =~ /trace|debug|info|warn|error|fatal/ ) {
|
||||||
|
$app->log->level( lc $log_level);
|
||||||
|
} else {
|
||||||
|
return $app->log->error(sprintf('REGISTERED failed: %s V%s, loglevel: %s is unknown', __PACKAGE__, $VERSION, $log_level));
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->_add_syslog($app, %$config)
|
||||||
|
if $config->{enable} // $ENV{MOJO_SYSLOG_ENABLE}
|
||||||
|
// $app->mode ne 'development';
|
||||||
|
|
||||||
|
$self->_add_access_log($app, %$config)
|
||||||
|
if $config->{access_log} // $ENV{MOJO_SYSLOG_ACCESS_LOG};
|
||||||
|
|
||||||
|
if ($log_warn eq '1') {
|
||||||
|
$SIG{__WARN__} = sub {
|
||||||
|
|
||||||
|
my $msg = join ' ', @_;
|
||||||
|
chomp $msg;
|
||||||
|
|
||||||
|
$app->log->warn($msg)
|
||||||
|
if $app->mode eq 'development' && $only_syslog == 0; # wenn syslog aus ist dann auch im Developermode kein errorlog
|
||||||
|
syslog $PRIORITY{warn}, '%s [MOJO] %s', 'WARN', $msg;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
$app->log->info(sprintf('REGISTERED: %s V%s', __PACKAGE__, $VERSION)) if $config->{verbose};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _add_access_log {
|
||||||
|
my ($self, $app, %config) = @_;
|
||||||
|
|
||||||
|
my $log_format = $config{access_log} || $ENV{MOJO_SYSLOG_ACCESS_LOG} || 'v1';
|
||||||
|
$log_format = '%H "%P" (%I) %C %M (%Ts)' if $log_format =~ /^v?1$/;
|
||||||
|
$log_format = '%R %H %U %C "%F" "%A" (%Ts)' if $log_format =~ /^v?2$/;
|
||||||
|
|
||||||
|
$app->hook(
|
||||||
|
before_routes => sub {
|
||||||
|
shift->helpers->timing->begin(__PACKAGE__);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my %extractors = (
|
||||||
|
A => sub { $_[1]->headers->user_agent || '' },
|
||||||
|
C => sub { $_[2]->code },
|
||||||
|
F => sub { $_[1]->headers->referrer || '' },
|
||||||
|
H => sub { $_[1]->method },
|
||||||
|
I => sub { $_[1]->request_id },
|
||||||
|
M => sub { $_[2]->message || $_[2]->default_message($_[2]->code) },
|
||||||
|
P => sub { $_[1]->url->path->to_abs_string },
|
||||||
|
R => sub { $_[0]->tx->remote_address },
|
||||||
|
T => sub { $_[0]->helpers->timing->elapsed(__PACKAGE__) // 0 },
|
||||||
|
U => sub { $_[1]->url->to_abs->to_string },
|
||||||
|
);
|
||||||
|
|
||||||
|
my $app_log = $log_format =~ m!\%I\b! && $app->log;
|
||||||
|
|
||||||
|
my $re = join '|', sort keys %extractors;
|
||||||
|
$re = qr{\%($re)};
|
||||||
|
|
||||||
|
$app->hook(
|
||||||
|
after_dispatch => sub {
|
||||||
|
my $c = shift;
|
||||||
|
my $log = $app_log || $c->log;
|
||||||
|
my ($req, $res) = ($c->req, $c->res);
|
||||||
|
my $level = $res->is_server_error ? 'warn' : 'trace';
|
||||||
|
my $message = $log_format;
|
||||||
|
$message =~ s!$re!$extractors{$1}->($c, $req, $res)!ge;
|
||||||
|
$log->$level($message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _add_syslog {
|
||||||
|
my ($self, $app, %config) = @_;
|
||||||
|
|
||||||
|
$config{facility} ||= $ENV{MOJO_SYSLOG_FACILITY} || LOG_USER;
|
||||||
|
$config{ident} ||= $ENV{MOJO_SYSLOG_IDENT} || $app->moniker;
|
||||||
|
$config{logopt} ||= $ENV{MOJO_SYSLOG_LOGOPT} || 'ndelay';
|
||||||
|
|
||||||
|
openlog @config{qw(ident logopt facility)};
|
||||||
|
$app->log->unsubscribe('message') if $config{only_syslog};
|
||||||
|
$app->log->unsubscribe(message => \&_syslog);
|
||||||
|
$app->log->on(message => \&_syslog);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _syslog {
|
||||||
|
my ($log, $level, @msg) = @_;
|
||||||
|
my $loglevel = $level eq 'trace' ? 'debug': $level;
|
||||||
|
|
||||||
|
syslog $PRIORITY{$loglevel}, '%s [MOJO] %s', uc $level, join ' ', @msg if $PRIORITY{$loglevel};
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
=encoding utf8
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
steffen::MojoPlugin::Syslog - A plugin for enabling a Mojolicious app to log to syslog
|
||||||
|
original Mojolicious::Plugin::Syslog modified for mlands
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
use Mojolicious::Lite;
|
||||||
|
plugin syslog => {facility => 'local0'};
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
L<steffen::MojoPlug::Syslog> is a L<Mojolicious> plugin for making
|
||||||
|
L<Mojo::Log> use L<Sys::Syslog> in addition (or instead) of file logging.
|
||||||
|
|
||||||
|
This can be useful when starting Hypnotoad through Systemd, but want simple
|
||||||
|
logging of error messages to syslog.
|
||||||
|
|
||||||
|
This plugin can also be used for only access logging, as an alternative to
|
||||||
|
L<Mojolicious::Plugin::AccessLog>. This is done by forcing L</enable> to
|
||||||
|
"0" and enabling L</access_log>.
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
=head2 register
|
||||||
|
|
||||||
|
$app->plugin(steffen::MojoPlugin::Syslog => \%config);
|
||||||
|
$self->register($app, \%config);
|
||||||
|
|
||||||
|
Used to register the plugin in your L<Mojolicious> application. Available
|
||||||
|
config parameters are:
|
||||||
|
|
||||||
|
=over 2
|
||||||
|
|
||||||
|
=item * access_log
|
||||||
|
|
||||||
|
Used to enable logging of access to resources with a route enpoint. This means
|
||||||
|
that static files will not be logged, even if this option is enabled. It is
|
||||||
|
also possible to set the default value using the C<MOJO_SYSLOG_ACCESS_LOG>
|
||||||
|
environment variable.
|
||||||
|
|
||||||
|
This can be "v1", "v2" or a custom format. The default is currently "v1", but
|
||||||
|
that might change in the future.
|
||||||
|
|
||||||
|
.---------------------------------------.
|
||||||
|
| Version | Format |
|
||||||
|
|---------|-----------------------------|
|
||||||
|
| v1 | %H "%P" (%I) %C %M (%Ts) |
|
||||||
|
| v2 | %R %H %U %C "%F" "%A" (%Ts) |
|
||||||
|
'---------------------------------------'
|
||||||
|
|
||||||
|
Supported log variables:
|
||||||
|
|
||||||
|
.----------------------------------------------------.
|
||||||
|
| Variable | Value |
|
||||||
|
|----------|-----------------------------------------|
|
||||||
|
| %A | User-Agent request header |
|
||||||
|
| %C | Response status code, ex "200" |
|
||||||
|
| %F | Referer request header |
|
||||||
|
| %H | HTTP request method, ex "GET", "POST" |
|
||||||
|
| %I | Mojolicious request ID |
|
||||||
|
| %M | Response message, ex OK |
|
||||||
|
| %P | Request URL path |
|
||||||
|
| %R | Remote address |
|
||||||
|
| %T | Time in seconds for this request |
|
||||||
|
| %U | Absolute request URL, without user info |
|
||||||
|
'----------------------------------------------------'
|
||||||
|
|
||||||
|
=item * enable
|
||||||
|
|
||||||
|
Need to be true to activate this plugin. Will use the "MOJO_SYSLOG_ENABLE"
|
||||||
|
environment variable or default to true if L<Mojolicious/mode> is something
|
||||||
|
else than "development"
|
||||||
|
|
||||||
|
=item * facility
|
||||||
|
|
||||||
|
The syslog facility to use. Default to "MOJO_SYSLOG_FACILITY" environment
|
||||||
|
variable or default to "user".
|
||||||
|
|
||||||
|
The default is EXPERIMENTAL.
|
||||||
|
|
||||||
|
=item * ident
|
||||||
|
|
||||||
|
The syslog ident to use. Default to "MOJO_SYSLOG_IDENT" environment variable or
|
||||||
|
L<Mojolicious/moniker>.
|
||||||
|
|
||||||
|
=item * only_syslog
|
||||||
|
|
||||||
|
Set this to true to disabled the default L<Mojo::Log> logging to file/stderr.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Jan Henning Thorsen
|
||||||
|
|
||||||
|
=head1 COPYRIGHT AND LICENSE
|
||||||
|
|
||||||
|
Copyright (C) 2019, Jan Henning Thorsen.
|
||||||
|
|
||||||
|
This program is free software, you can redistribute it and/or modify it under
|
||||||
|
the terms of the Artistic License version 2.0.
|
||||||
|
|
||||||
|
=cut
|
||||||
Reference in New Issue
Block a user