diff --git a/lib/jabberbot.pm b/lib/jabberbot.pm index cc63ad6..550d9c0 100644 --- a/lib/jabberbot.pm +++ b/lib/jabberbot.pm @@ -136,7 +136,6 @@ sub run_jabberbot { while (sleep 3) { eval { $bot->Start(); - }; } } diff --git a/lib/metagen.pm b/lib/metagen.pm index 0ad652a..fdf2d56 100644 --- a/lib/metagen.pm +++ b/lib/metagen.pm @@ -38,7 +38,6 @@ sub __pdate; # generates current date in pretty format sub metagen($) { my $dir = shift; -# TODO: get dir from config! my $c = loadConf(); $dir = $c->{metagen}->{$dir}; @@ -268,4 +267,4 @@ sub __pdate { 1; -# vim: ft=perl noet ai ts=4 sw=4 sts=4: +# vim: set ft=perl noet ai ts=4 sw=4 sts=4 : diff --git a/lib/upload.pm b/lib/upload.pm index 566bdb5..82fe7a5 100644 --- a/lib/upload.pm +++ b/lib/upload.pm @@ -8,7 +8,6 @@ require Exporter; use strict; use warnings "all"; -use diagnostics; use Fcntl; use conf; @@ -82,3 +81,5 @@ sub upload { } 1; + +# vim: set ft=perl noet ai ts=4 sw=4 sts=4 : diff --git a/myapi-bots.psgi b/myapi-bots.psgi new file mode 100644 index 0000000..19ae4e6 --- /dev/null +++ b/myapi-bots.psgi @@ -0,0 +1,50 @@ +use strict; +use warnings "all"; + +# my plugins +use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5); +use conf; +use jabberbot; +use telegrambot; +use threads; + +my $CONF = loadConf(); + +if ($CONF->{api}->{prefix} eq '/') { $CONF->{api}->{prefix} = ''; } +my $prefix = $CONF->{api}->{prefix}; + +threads->create('run_jabberbot')->detach; +threads->create('run_telegrambot')->detach; + +my $app = sub { + my $env = shift; + + my $msg = "Your Opinion is very important for us, please stand by.\n"; + my $status = '404'; + my $content = 'text/plain'; + + if ($env->{PATH_INFO} eq "$prefix/help") { + $status = '200'; + $msg = << 'EOL'; +/ping - pong +/ip - your ip +/getaddrbyname - header hostname must be set +/getnameaaddr - header adderess must be set +/punycoder - header hostname must be set +/punydecoder - header hostname must be set +/time - current time +/quote - famous or not famous quotes +/fortune - synonym for quote +EOL + } + + + return [ + $status, + [ 'Content-Type' => $content, 'Content-Length' => length($msg) ], + [ $msg ], + ]; +}; + +__END__ +# vim: set ft=perl noet ai ts=4 sw=4 sts=4: diff --git a/myapi-repo.psgi b/myapi-repo.psgi new file mode 100644 index 0000000..6c64ce3 --- /dev/null +++ b/myapi-repo.psgi @@ -0,0 +1,54 @@ +use strict; +use warnings "all"; + +# my plugins +use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5); +use conf; +use upload; +use metagen; + +my $CONF = loadConf(); + +if ($CONF->{api}->{prefix} eq '/') { $CONF->{api}->{prefix} = ''; } +my $prefix = $CONF->{api}->{prefix}; + +my $app = sub { + my $env = shift; + + my $msg = "Your Opinion is very important for us, please stand by.\n"; + my $status = '404'; + my $content = 'text/plain'; + + if ($env->{PATH_INFO} =~ /$prefix\/upload\/(.+)/) { + my $upload = $1; + ($status, $content, $msg) = ('400', $content, "Bad Request?\n"); + + if (defined($env->{HTTP_AUTH}) && ($env->{HTTP_AUTH} eq $CONF->{upload}->{auth})) { + if (($upload !~ /\.\./) and ($upload =~ /^[A-Z|a-z|0-9|_|\-|\+|\/|\.]+$/)) { + if (defined($env->{CONTENT_LENGTH}) && ($env->{CONTENT_LENGTH} > 0)) { + ($status, $content, $msg) = upload($env->{'psgi.input'}, $env->{CONTENT_LENGTH}, $upload); + } + } else { + $msg = "Something wrong with upload path.\n"; + } + } else { + ($status, $content, $msg) = ('403', $content, "You're not allowed here. Fuck off.\n"); + } + } elsif ($env->{PATH_INFO} eq "$prefix/metagen") { + if (defined($env->{HTTP_REPO})) { + ($status, $content, $msg) = metagen($env->{HTTP_REPO}); + } + } + + + return [ + $status, + [ 'Content-Type' => $content, 'Content-Length' => length($msg) ], + [ $msg ], + ]; +}; + + +__END__ +# vim: set ft=perl noet ai ts=4 sw=4 sts=4: + diff --git a/myapi.psgi b/myapi.psgi index 34cbc66..888c100 100644 --- a/myapi.psgi +++ b/myapi.psgi @@ -1,18 +1,14 @@ -use Data::Dumper; use strict; use warnings "all"; use diagnostics; # my plugins -use lib qw(./lib ./vendor_perl); +use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5); use conf; use ping; use utils; use easter_egg; -use upload; use image_dl; -use metagen; -use jabberbot; use threads; my $CONF = loadConf(); @@ -21,9 +17,6 @@ if ($CONF->{api}->{prefix} eq '/') { $CONF->{api}->{prefix} = ''; } my $prefix = $CONF->{api}->{prefix}; threads->create('image_dl_thread')->detach; -#threads->create('run_ircbot')->detach; -#threads->create('run_jabberbot')->detach; -#threads->create('run_telegrambot')->detach; my $app = sub { my $env = shift; @@ -77,25 +70,8 @@ EOL ($status, $content, $msg) = nickserv(); } elsif ($env->{PATH_INFO} eq "$prefix/me") { ($status, $content, $msg) = me(); - } elsif ($env->{PATH_INFO} =~ /$prefix\/upload\/(.+)/) { - my $upload = $1; - ($status, $content, $msg) = ('400', $content, "Bad Request?\n"); - - if (defined($env->{HTTP_AUTH}) && ($env->{HTTP_AUTH} eq $CONF->{upload}->{auth})) { - if ((upload !~ /\.\./) and ($upload =~ /^[A-Z|a-z|0-9|_|\-|\+|\/]+$/)) { - if (defined($env->{CONTENT_LENGTH}) && ($env->{CONTENT_LENGTH} > 0)) { - ($status, $content, $msg) = upload($env->{'psgi.input'}, $env->{CONTENT_LENGTH}, $upload); - } - } - } else { - ($status, $content, $msg) = ('403', $content, "You're not allowed here. Fuck off.\n"); - } } elsif ($env->{PATH_INFO} eq "$prefix/image_dl") { ($status, $content, $msg) = image_dl_queue($env->{HTTP_URL}); - } elsif ($env->{PATH_INFO} eq "$prefix/metagen") { - if (defined($env->{HTTP_REPO})) { - ($status, $content, $msg) = metagen($env->{HTTP_REPO}); - } } @@ -107,9 +83,12 @@ EOL }; -# vim: ft=perl noet ai ts=4 sw=4 sts=4: __END__ https://toster.ru/q/75226 http://www.cbr.ru/scripts/XML_daily.asp + + + +# vim: ft=perl noet ai ts=4 sw=4 sts=4: