Commit 91e07880 authored by Luc Didry's avatar Luc Didry
Browse files

First commit. Working.

parents
local/*
files/*
lufi.conf
lufi.db
*.swp
script/hypnotoad.pid
EXTRACTFILES=utilities/locales_files.txt
EN=lib/Lufi/I18N/en.po
XGETTEXT=carton exec local/bin/xgettext.pl
CARTON=carton exec
REAL_LUFI=script/application
LUFI=script/lufi
locales:
$(XGETTEXT) -f $(EXTRACTFILES) -o $(EN)
test:
$(CARTON) $(REAL_LUFI) test
clean:
rm -rf lufi.db files/
dev: clean
$(CARTON) morbo $(LUFI) --listen http://0.0.0.0:3000
devlog:
multitail log/development.log
prod:
$(CARTON) hypnotoad $(LUFI)
requires "Mojolicious";
requires "ORLite";
requires "Mojolicious::Plugin::DebugDumperHelper";
requires 'Mojolicious::Plugin::I18N';
requires 'EV';
requires 'Filesys::DiskUsage';
requires 'Switch';
requires 'Locale::Maketext';
requires 'Locale::Maketext::Extract';
# carton snapshot format: version 1.0
DISTRIBUTIONS
CPAN-Meta-2.150005
pathname: D/DA/DAGOLDEN/CPAN-Meta-2.150005.tar.gz
provides:
CPAN::Meta 2.150005
CPAN::Meta::Converter 2.150005
CPAN::Meta::Feature 2.150005
CPAN::Meta::History 2.150005
CPAN::Meta::Merge 2.150005
CPAN::Meta::Prereqs 2.150005
CPAN::Meta::Spec 2.150005
CPAN::Meta::Validator 2.150005
requirements:
CPAN::Meta::Requirements 2.121
CPAN::Meta::YAML 0.008
Carp 0
ExtUtils::MakeMaker 6.17
JSON::PP 2.27200
Parse::CPAN::Meta 1.4414
Scalar::Util 0
perl 5.008
strict 0
version 0.88
warnings 0
Canary-Stability-2006
pathname: M/ML/MLEHMANN/Canary-Stability-2006.tar.gz
provides:
Canary::Stability 2006
requirements:
ExtUtils::MakeMaker 0
DBD-SQLite-1.48
pathname: I/IS/ISHIGAKI/DBD-SQLite-1.48.tar.gz
provides:
DBD::SQLite 1.48
DBD::SQLite::Constants undef
DBD::SQLite::VirtualTable 1.48
DBD::SQLite::VirtualTable::Cursor 1.48
DBD::SQLite::VirtualTable::FileContent undef
DBD::SQLite::VirtualTable::FileContent::Cursor undef
DBD::SQLite::VirtualTable::PerlData undef
DBD::SQLite::VirtualTable::PerlData::Cursor undef
requirements:
DBI 1.57
ExtUtils::MakeMaker 0
File::Spec 0.82
Test::Builder 0.86
Test::More 0.47
Tie::Hash 0
perl 5.006
DBI-1.634
pathname: T/TI/TIMB/DBI-1.634.tar.gz
provides:
Bundle::DBI 12.008696
DBD::DBM 0.08
DBD::DBM::Statement 0.08
DBD::DBM::Table 0.08
DBD::DBM::db 0.08
DBD::DBM::dr 0.08
DBD::DBM::st 0.08
DBD::ExampleP 12.014311
DBD::ExampleP::db 12.014311
DBD::ExampleP::dr 12.014311
DBD::ExampleP::st 12.014311
DBD::File 0.44
DBD::File::DataSource::File 0.44
DBD::File::DataSource::Stream 0.44
DBD::File::Statement 0.44
DBD::File::Table 0.44
DBD::File::TableSource::FileSystem 0.44
DBD::File::db 0.44
DBD::File::dr 0.44
DBD::File::st 0.44
DBD::Gofer 0.015327
DBD::Gofer::Policy::Base 0.010088
DBD::Gofer::Policy::classic 0.010088
DBD::Gofer::Policy::pedantic 0.010088
DBD::Gofer::Policy::rush 0.010088
DBD::Gofer::Transport::Base 0.014121
DBD::Gofer::Transport::corostream undef
DBD::Gofer::Transport::null 0.010088
DBD::Gofer::Transport::pipeone 0.010088
DBD::Gofer::Transport::stream 0.014599
DBD::Gofer::db 0.015327
DBD::Gofer::dr 0.015327
DBD::Gofer::st 0.015327
DBD::NullP 12.014715
DBD::NullP::db 12.014715
DBD::NullP::dr 12.014715
DBD::NullP::st 12.014715
DBD::Proxy 0.2004
DBD::Proxy::RPC::PlClient 0.2004
DBD::Proxy::db 0.2004
DBD::Proxy::dr 0.2004
DBD::Proxy::st 0.2004
DBD::Sponge 12.010003
DBD::Sponge::db 12.010003
DBD::Sponge::dr 12.010003
DBD::Sponge::st 12.010003
DBDI 12.015129
DBI 1.634
DBI::Const::GetInfo::ANSI 2.008697
DBI::Const::GetInfo::ODBC 2.011374
DBI::Const::GetInfoReturn 2.008697
DBI::Const::GetInfoType 2.008697
DBI::DBD 12.015129
DBI::DBD::Metadata 2.014214
DBI::DBD::SqlEngine 0.06
DBI::DBD::SqlEngine::DataSource 0.06
DBI::DBD::SqlEngine::Statement 0.06
DBI::DBD::SqlEngine::Table 0.06
DBI::DBD::SqlEngine::TableSource 0.06
DBI::DBD::SqlEngine::TieMeta 0.06
DBI::DBD::SqlEngine::TieTables 0.06
DBI::DBD::SqlEngine::db 0.06
DBI::DBD::SqlEngine::dr 0.06
DBI::DBD::SqlEngine::st 0.06
DBI::FAQ 1.014935
DBI::Gofer::Execute 0.014283
DBI::Gofer::Request 0.012537
DBI::Gofer::Response 0.011566
DBI::Gofer::Serializer::Base 0.009950
DBI::Gofer::Serializer::DataDumper 0.009950
DBI::Gofer::Serializer::Storable 0.015586
DBI::Gofer::Transport::Base 0.012537
DBI::Gofer::Transport::pipeone 0.012537
DBI::Gofer::Transport::stream 0.012537
DBI::Profile 2.015065
DBI::ProfileData 2.010008
DBI::ProfileDumper 2.015325
DBI::ProfileDumper::Apache 2.014121
DBI::ProfileSubs 0.009396
DBI::ProxyServer 0.3005
DBI::ProxyServer::db 0.3005
DBI::ProxyServer::dr 0.3005
DBI::ProxyServer::st 0.3005
DBI::SQL::Nano 1.015544
DBI::SQL::Nano::Statement_ 1.015544
DBI::SQL::Nano::Table_ 1.015544
DBI::Util::CacheMemory 0.010315
DBI::Util::_accessor 0.009479
DBI::common 1.634
requirements:
ExtUtils::MakeMaker 6.48
Test::Simple 0.90
perl 5.008
EV-4.21
pathname: M/ML/MLEHMANN/EV-4.21.tar.gz
provides:
EV 4.21
EV::MakeMaker undef
requirements:
Canary::Stability 0
ExtUtils::MakeMaker 6.52
common::sense 0
File-Remove-1.52
pathname: A/AD/ADAMK/File-Remove-1.52.tar.gz
provides:
File::Remove 1.52
requirements:
Cwd 3.29
ExtUtils::MakeMaker 6.36
File::Spec 3.29
Test::More 0.42
perl 5.00503
Filesys-DiskUsage-0.08
pathname: S/SZ/SZABGAB/Filesys-DiskUsage-0.08.tar.gz
provides:
Filesys::DiskUsage 0.08
requirements:
ExtUtils::MakeMaker 0
File::Basename 0
File::Find 0
File::Temp 0
Test::More 0
Test::Warn 0
IPC-Run3-0.048
pathname: R/RJ/RJBS/IPC-Run3-0.048.tar.gz
provides:
IPC::Run3 0.048
requirements:
ExtUtils::MakeMaker 0
Test::More 0.31
Time::HiRes 0
Locale-Maketext-Lexicon-1.00
pathname: D/DR/DRTECH/Locale-Maketext-Lexicon-1.00.tar.gz
provides:
Locale::Maketext::Extract 1.00
Locale::Maketext::Extract::Plugin::Base 1.00
Locale::Maketext::Extract::Plugin::FormFu 1.00
Locale::Maketext::Extract::Plugin::FormFu::Extractor 1.00
Locale::Maketext::Extract::Plugin::Generic 1.00
Locale::Maketext::Extract::Plugin::Haml 1.00
Locale::Maketext::Extract::Plugin::Mason 1.00
Locale::Maketext::Extract::Plugin::PPI 1.00
Locale::Maketext::Extract::Plugin::Perl 1.00
Locale::Maketext::Extract::Plugin::TT2 1.00
Locale::Maketext::Extract::Plugin::TT2::Directive 1.00
Locale::Maketext::Extract::Plugin::TT2::Parser 1.00
Locale::Maketext::Extract::Plugin::TextTemplate 1.00
Locale::Maketext::Extract::Plugin::TextTemplate::Parser 1.00
Locale::Maketext::Extract::Plugin::YAML 1.00
Locale::Maketext::Extract::Plugin::YAML::Extractor 1.00
Locale::Maketext::Extract::Run 1.00
Locale::Maketext::Lexicon 1.00
Locale::Maketext::Lexicon::Auto 1.00
Locale::Maketext::Lexicon::Gettext 1.00
Locale::Maketext::Lexicon::Msgcat 1.00
Locale::Maketext::Lexicon::Tie 1.00
requirements:
ExtUtils::MakeMaker 6.30
Locale::Maketext 1.17
Module-Build-0.4214
pathname: L/LE/LEONT/Module-Build-0.4214.tar.gz
provides:
Module::Build 0.4214
Module::Build::Base 0.4214
Module::Build::Compat 0.4214
Module::Build::Config 0.4214
Module::Build::Cookbook 0.4214
Module::Build::Dumper 0.4214
Module::Build::Notes 0.4214
Module::Build::PPMMaker 0.4214
Module::Build::Platform::Default 0.4214
Module::Build::Platform::MacOS 0.4214
Module::Build::Platform::Unix 0.4214
Module::Build::Platform::VMS 0.4214
Module::Build::Platform::VOS 0.4214
Module::Build::Platform::Windows 0.4214
Module::Build::Platform::aix 0.4214
Module::Build::Platform::cygwin 0.4214
Module::Build::Platform::darwin 0.4214
Module::Build::Platform::os2 0.4214
Module::Build::PodParser 0.4214
requirements:
CPAN::Meta 2.142060
CPAN::Meta::YAML 0.003
Cwd 0
Data::Dumper 0
ExtUtils::CBuilder 0.27
ExtUtils::Install 0
ExtUtils::Manifest 0
ExtUtils::Mkbootstrap 0
ExtUtils::ParseXS 2.21
File::Basename 0
File::Compare 0
File::Copy 0
File::Find 0
File::Path 0
File::Spec 0.82
File::Temp 0.15
Getopt::Long 0
Module::Metadata 1.000002
Parse::CPAN::Meta 1.4401
Perl::OSType 1
Pod::Man 2.17
Test::Harness 3.16
Test::More 0.49
Text::Abbrev 0
Text::ParseWords 0
perl 5.008000
version 0.87
Mojolicious-6.17
pathname: S/SR/SRI/Mojolicious-6.17.tar.gz
provides:
Mojo undef
Mojo::Asset undef
Mojo::Asset::File undef
Mojo::Asset::Memory undef
Mojo::Base undef
Mojo::ByteStream undef
Mojo::Cache undef
Mojo::Collection undef
Mojo::Content undef
Mojo::Content::MultiPart undef
Mojo::Content::Single undef
Mojo::Cookie undef
Mojo::Cookie::Request undef
Mojo::Cookie::Response undef
Mojo::DOM undef
Mojo::DOM::CSS undef
Mojo::DOM::HTML undef
Mojo::Date undef
Mojo::EventEmitter undef
Mojo::Exception undef
Mojo::Headers undef
Mojo::HelloWorld undef
Mojo::Home undef
Mojo::IOLoop undef
Mojo::IOLoop::Client undef
Mojo::IOLoop::Delay undef
Mojo::IOLoop::Server undef
Mojo::IOLoop::Stream undef
Mojo::JSON undef
Mojo::JSON::Pointer undef
Mojo::JSON::_Bool undef
Mojo::Loader undef
Mojo::Log undef
Mojo::Message undef
Mojo::Message::Request undef
Mojo::Message::Response undef
Mojo::Parameters undef
Mojo::Path undef
Mojo::Reactor undef
Mojo::Reactor::EV undef
Mojo::Reactor::Poll undef
Mojo::Server undef
Mojo::Server::CGI undef
Mojo::Server::Daemon undef
Mojo::Server::Hypnotoad undef
Mojo::Server::Morbo undef
Mojo::Server::PSGI undef
Mojo::Server::PSGI::_IO undef
Mojo::Server::Prefork undef
Mojo::Template undef
Mojo::Transaction undef
Mojo::Transaction::HTTP undef
Mojo::Transaction::WebSocket undef
Mojo::URL undef
Mojo::Upload undef
Mojo::UserAgent undef
Mojo::UserAgent::CookieJar undef
Mojo::UserAgent::Proxy undef
Mojo::UserAgent::Server undef
Mojo::UserAgent::Transactor undef
Mojo::Util undef
Mojolicious 6.17
Mojolicious::Command undef
Mojolicious::Command::cgi undef
Mojolicious::Command::cpanify undef
Mojolicious::Command::daemon undef
Mojolicious::Command::eval undef
Mojolicious::Command::generate undef
Mojolicious::Command::generate::app undef
Mojolicious::Command::generate::lite_app undef
Mojolicious::Command::generate::makefile undef
Mojolicious::Command::generate::plugin undef
Mojolicious::Command::get undef
Mojolicious::Command::inflate undef
Mojolicious::Command::prefork undef
Mojolicious::Command::psgi undef
Mojolicious::Command::routes undef
Mojolicious::Command::test undef
Mojolicious::Command::version undef
Mojolicious::Commands undef
Mojolicious::Controller undef
Mojolicious::Lite undef
Mojolicious::Plugin undef
Mojolicious::Plugin::Charset undef
Mojolicious::Plugin::Config undef
Mojolicious::Plugin::Config::Sandbox undef
Mojolicious::Plugin::DefaultHelpers undef
Mojolicious::Plugin::EPLRenderer undef
Mojolicious::Plugin::EPRenderer undef
Mojolicious::Plugin::HeaderCondition undef
Mojolicious::Plugin::JSONConfig undef
Mojolicious::Plugin::Mount undef
Mojolicious::Plugin::PODRenderer undef
Mojolicious::Plugin::TagHelpers undef
Mojolicious::Plugins undef
Mojolicious::Renderer undef
Mojolicious::Routes undef
Mojolicious::Routes::Match undef
Mojolicious::Routes::Pattern undef
Mojolicious::Routes::Route undef
Mojolicious::Sessions undef
Mojolicious::Static undef
Mojolicious::Types undef
Mojolicious::Validator undef
Mojolicious::Validator::Validation undef
Test::Mojo undef
ojo undef
requirements:
ExtUtils::MakeMaker 0
IO::Socket::IP 0.26
Pod::Simple 3.09
Time::Local 1.2
Mojolicious-Plugin-DebugDumperHelper-0.02
pathname: L/LD/LDIDRY/Mojolicious-Plugin-DebugDumperHelper-0.02.tar.gz
provides:
Mojolicious::Plugin::DebugDumperHelper 0.02
requirements:
ExtUtils::MakeMaker 0
Mojolicious 6.11
Mojolicious-Plugin-I18N-1.6
pathname: S/SH/SHARIFULN/Mojolicious-Plugin-I18N-1.6.tar.gz
provides:
Mojolicious::Plugin::I18N 1.6
requirements:
I18N::LangTags 0.35
Module::Build 0.42
Mojolicious 5
Test::More 0
perl 5.010001
ORLite-1.98
pathname: A/AD/ADAMK/ORLite-1.98.tar.gz
provides:
ORLite 1.98
requirements:
DBD::SQLite 1.27
DBI 1.607
ExtUtils::MakeMaker 6.59
File::Path 2.08
File::Remove 1.40
File::Spec 0.80
File::Temp 0.20
Params::Util 1.00
Test::More 0.47
Test::Script 1.06
perl 5.006
Params-Util-1.07
pathname: A/AD/ADAMK/Params-Util-1.07.tar.gz
provides:
Params::Util 1.07
requirements:
ExtUtils::CBuilder 0.27
ExtUtils::MakeMaker 6.52
File::Spec 0.80
Scalar::Util 1.18
Test::More 0.42
perl 5.00503
Probe-Perl-0.03
pathname: K/KW/KWILLIAMS/Probe-Perl-0.03.tar.gz
provides:
Probe::Perl 0.03
requirements:
Config 0
ExtUtils::MakeMaker 6.30
File::Spec 0
strict 0
Sub-Uplevel-0.25
pathname: D/DA/DAGOLDEN/Sub-Uplevel-0.25.tar.gz
provides:
Sub::Uplevel 0.25
requirements:
Carp 0
ExtUtils::MakeMaker 6.17
constant 0
perl 5.006
strict 0
warnings 0
Switch-2.17
pathname: C/CH/CHORNY/Switch-2.17.tar.gz
provides:
Switch 2.17
requirements:
ExtUtils::MakeMaker 0
Filter::Util::Call 0
Text::Balanced 2
if 0
perl 5.005
Test-Script-1.10
pathname: P/PL/PLICEASE/Test-Script-1.10.tar.gz
provides:
Test::Script 1.10
requirements:
ExtUtils::MakeMaker 0
File::Spec 0.80
IPC::Run3 0.034
Probe::Perl 0.01
Test::Builder 0.32
Test::More 0.96
perl 5.006
Test-Warn-0.30
pathname: C/CH/CHORNY/Test-Warn-0.30.tar.gz
provides:
Test::Warn 0.30
Test::Warn::Categorization 0.30
requirements:
Carp 1.22
ExtUtils::MakeMaker 0
File::Spec 0
Sub::Uplevel 0.12
Test::Builder 0.13
Test::Builder::Tester 1.02
Test::More 0
perl 5.006
common-sense-3.74
pathname: M/ML/MLEHMANN/common-sense-3.74.tar.gz
provides:
common::sense 3.74
requirements:
ExtUtils::MakeMaker 0
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
package Lufi;
use Mojo::Base 'Mojolicious';
use LufiDB;
$ENV{MOJO_MAX_WEBSOCKET_SIZE} = 100485760; # 10 * 1024 * 1024 = 10MiB
# This method will run once at server start
sub startup {
my $self = shift;
my $config = $self->plugin('Config' => {
default => {
provisioning => 100,
provis_step => 5,
length => 10,
token_length => 32,
secret => ['hfudsifdsih'],
default_delay => 0,
max_delay => 0
}
});
die "You need to provide a contact information in lufi.conf!" unless (defined($config->{contact}));
# Internationalization
$self->plugin('I18N');
# Debug
$self->plugin('DebugDumperHelper');
$self->secrets($config->{secrets});
# Helpers
$self->helper(
provisioning => sub {
my $c = shift;
# Create some short patterns for provisioning
if (LufiDB::Files->count('WHERE created_at IS NULL') < $c->config('provisioning')) {
for (my $i = 0; $i < $c->config('provis_step'); $i++) {
if (LufiDB->begin) {
my $short;
do {
$short= $c->shortener($c->config('length'));
} while (LufiDB::Files->count('WHERE short = ?', $short));
LufiDB::Files->create(
short => $short
);
LufiDB->commit;
}
}
}
}
);
$self->helper(
get_empty => sub {
my $c = shift;
my @records = LufiDB::Files->select('WHERE created_at IS NULL LIMIT 1');
return $records[0];
}
);
$self->helper(
shortener => sub {
my $c = shift;
my $length = shift;
my @chars = ('a'..'z','A'..'Z','0'..'9', '-', '_');
my $result = '';
foreach (1..$length) {
$result .= $chars[rand scalar(@chars)];
}
return $result;
}
);
$self->helper(
ip => sub {
my $c = shift;
my $proxy = $c->req->headers->header('X-Forwarded-For');
my $ip = ($proxy) ? $proxy : $c->tx->remote_address;
my $remote_port = (defined($c->req->headers->header('X-Remote-Port'))) ? $c->req->headers->header('X-Remote-Port') : $c->tx->remote_port;
return "$ip remote port:$remote_port";
}
);
$self->helper(
default_delay => sub {
my $c = shift;
return $c->config('default_delay') if ($c->config('default_delay') >= 0);
warn "default_delay set to a negative value. Default to 0.";
return 0;
}
);
$self->helper(
is_selected => sub {
my $c = shift;
my $num = shift;
return ($num == $c->default_delay) ? 'selected="selected"' : '';
}
);
# Hooks
$self->hook(
after_dispatch => sub {
shift->provisioning();
}
);
# For the first launch (after, this isn't really useful)
$self->provisioning();
# Create directory if needed
mkdir('files', 0700) unless (-d 'files');
# Default layout
$self->defaults(layout => 'default');