Split applications into different .psgi files
* Развёл по разным файлам функции ботов, репозитория и остальное * Починил modeline там где он был * Небольшая чистка
This commit is contained in:
@@ -136,7 +136,6 @@ sub run_jabberbot {
|
|||||||
while (sleep 3) {
|
while (sleep 3) {
|
||||||
eval {
|
eval {
|
||||||
$bot->Start();
|
$bot->Start();
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ sub __pdate; # generates current date in pretty format
|
|||||||
|
|
||||||
sub metagen($) {
|
sub metagen($) {
|
||||||
my $dir = shift;
|
my $dir = shift;
|
||||||
# TODO: get dir from config!
|
|
||||||
my $c = loadConf();
|
my $c = loadConf();
|
||||||
$dir = $c->{metagen}->{$dir};
|
$dir = $c->{metagen}->{$dir};
|
||||||
|
|
||||||
@@ -268,4 +267,4 @@ sub __pdate {
|
|||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
# vim: ft=perl noet ai ts=4 sw=4 sts=4:
|
# vim: set ft=perl noet ai ts=4 sw=4 sts=4 :
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ require Exporter;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
use diagnostics;
|
|
||||||
use Fcntl;
|
use Fcntl;
|
||||||
use conf;
|
use conf;
|
||||||
|
|
||||||
@@ -82,3 +81,5 @@ sub upload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
# vim: set ft=perl noet ai ts=4 sw=4 sts=4 :
|
||||||
|
|||||||
50
myapi-bots.psgi
Normal file
50
myapi-bots.psgi
Normal file
@@ -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:
|
||||||
54
myapi-repo.psgi
Normal file
54
myapi-repo.psgi
Normal file
@@ -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:
|
||||||
|
|
||||||
31
myapi.psgi
31
myapi.psgi
@@ -1,18 +1,14 @@
|
|||||||
use Data::Dumper;
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
use diagnostics;
|
use diagnostics;
|
||||||
|
|
||||||
# my plugins
|
# my plugins
|
||||||
use lib qw(./lib ./vendor_perl);
|
use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5);
|
||||||
use conf;
|
use conf;
|
||||||
use ping;
|
use ping;
|
||||||
use utils;
|
use utils;
|
||||||
use easter_egg;
|
use easter_egg;
|
||||||
use upload;
|
|
||||||
use image_dl;
|
use image_dl;
|
||||||
use metagen;
|
|
||||||
use jabberbot;
|
|
||||||
use threads;
|
use threads;
|
||||||
|
|
||||||
my $CONF = loadConf();
|
my $CONF = loadConf();
|
||||||
@@ -21,9 +17,6 @@ if ($CONF->{api}->{prefix} eq '/') { $CONF->{api}->{prefix} = ''; }
|
|||||||
my $prefix = $CONF->{api}->{prefix};
|
my $prefix = $CONF->{api}->{prefix};
|
||||||
|
|
||||||
threads->create('image_dl_thread')->detach;
|
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 $app = sub {
|
||||||
my $env = shift;
|
my $env = shift;
|
||||||
@@ -77,25 +70,8 @@ EOL
|
|||||||
($status, $content, $msg) = nickserv();
|
($status, $content, $msg) = nickserv();
|
||||||
} elsif ($env->{PATH_INFO} eq "$prefix/me") {
|
} elsif ($env->{PATH_INFO} eq "$prefix/me") {
|
||||||
($status, $content, $msg) = 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") {
|
} elsif ($env->{PATH_INFO} eq "$prefix/image_dl") {
|
||||||
($status, $content, $msg) = image_dl_queue($env->{HTTP_URL});
|
($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__
|
__END__
|
||||||
|
|
||||||
https://toster.ru/q/75226
|
https://toster.ru/q/75226
|
||||||
|
|
||||||
http://www.cbr.ru/scripts/XML_daily.asp
|
http://www.cbr.ru/scripts/XML_daily.asp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# vim: ft=perl noet ai ts=4 sw=4 sts=4:
|
||||||
|
|||||||
Reference in New Issue
Block a user