diff --git a/cualsea-cli/Makefile.PL b/cualsea-cli/Makefile.PL index 78d8271..e8b0ff7 100644 --- a/cualsea-cli/Makefile.PL +++ b/cualsea-cli/Makefile.PL @@ -7,4 +7,7 @@ WriteMakefile( INST_BIN => './bin', test => { TESTS => 't/*.t' }, test => { TESTS => 't/*/*.t' }, + PREREQ_PM => { + 'Getopt::Long::Descriptive' => 0, + } ); diff --git a/cualsea-cli/bin/cualsea b/cualsea-cli/bin/cualsea index 8e40f4e..1c866e1 100755 --- a/cualsea-cli/bin/cualsea +++ b/cualsea-cli/bin/cualsea @@ -11,12 +11,31 @@ use IO::Socket::UNIX; use Cualsea::FileSocket; use Cualsea::MessageManager; +my $command = shift @ARGV or die 'No command passed'; +my @arguments = @ARGV; + my $socket = IO::Socket::UNIX->new( Type => SOCK_STREAM(), Peer => $Cualsea::FileSocket::SOCKET_PATH, ) or die "Daemon not started"; my $message_manager = Cualsea::MessageManager->new(socket => $socket); -$message_manager->write_message( message => {hola => 'mundo'} ); +$message_manager->write_message( message => {command => $command, arguments => \@arguments} ); -print Data::Dumper::Dumper $message_manager->read_message; +my $message = $message_manager->read_message; + +if ($message->{is_error}) { + for ($message->{status}) { + if (/^400$/) { + say STDERR 'The request was malformed.'; + exit; + } + if (/^403$/) { + say STDERR 'You are not in the cualsea group.'; + exit; + } + say 'Unknown Error'; + exit; + } +} +print Data::Dumper::Dumper $message; diff --git a/cualsea-server/Makefile.PL b/cualsea-server/Makefile.PL index c99098d..0964100 100644 --- a/cualsea-server/Makefile.PL +++ b/cualsea-server/Makefile.PL @@ -7,4 +7,7 @@ WriteMakefile( INST_BIN => './bin', test => { TESTS => 't/*.t' }, test => { TESTS => 't/*/*.t' }, + PREREQ_PM => { + 'DBD::SQLite' => 0, + } ); diff --git a/cualsea-server/lib/Cualsea/Server/MessageController.pm b/cualsea-server/lib/Cualsea/Server/MessageController.pm index dffe77a..ccb69eb 100644 --- a/cualsea-server/lib/Cualsea/Server/MessageController.pm +++ b/cualsea-server/lib/Cualsea/Server/MessageController.pm @@ -9,10 +9,74 @@ use Data::Dumper; use Socket qw/SOL_SOCKET SO_PEERCRED/; use Params::ValidationCompiler qw/validation_for/; -use Types::Standard qw/Object HashRef/; +use Types::Standard qw/Object HashRef Str/; use Cualsea::MessageManager; +my %commands = { + add => { + params => [ + 'name', + 'init', # Only sysvinit supported + 'pidfile', + 'binpath' + ], + validator => validation_for( + params => { + name => { type => Str }, + init => { type => Str }, + pidfile => { type => Str }, + binpath => { type => Str }, + } + ), + }, + del => { + params => [ + 'name' + ], + validator => validation_for( + params => { + name => { type => Str }, + } + ), + }, + report => { + params => [], + validator => validation_for( + params => {}, + ), + }, + start => { + params => [ + 'name', + ], + validator => validation_for( + params => { + name => { type => Str }, + } + ), + }, + stop => { + params => [ + 'name', + ], + validator => validation_for( + params => { + name => { type => Str }, + } + ), + }, + restart => { + params => [ + 'name', + ], + validator => validation_for( + params => { + name => { type => Str }, + } + ), + } +} sub new { my $class = shift; return bless {}, $class;