From 1afeddc08f6c61cff204980cfae93d97320ae39f Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 14 Jan 2006 17:25:35 +0000 Subject: aggiornamento a nuovo Catalyst, e "permessi di scrittura" (orendo) --- lib/Bookmarks.pm | 4 +-- lib/Bookmarks/C/Main.pm | 21 +++++++++++++++ script/bookmarks_cgi.pl | 4 +-- script/bookmarks_create.pl | 23 +++++++++++------ script/bookmarks_fastcgi.pl | 30 ++++++++++++++++++--- script/bookmarks_server.pl | 63 +++++++++++++++++++++++++++++++++++++-------- script/bookmarks_test.pl | 6 ++--- 7 files changed, 121 insertions(+), 30 deletions(-) diff --git a/lib/Bookmarks.pm b/lib/Bookmarks.pm index 89aa0c9..bc4694b 100644 --- a/lib/Bookmarks.pm +++ b/lib/Bookmarks.pm @@ -1,14 +1,14 @@ package Bookmarks; use strict; -use Catalyst qw/Prototype DefaultEnd Static::Simple/; +use Catalyst qw/-Debug Prototype DefaultEnd Static::Simple/; use HTML::Element; our $VERSION = '0.01'; Bookmarks->config( name => 'Bookmarks', - 'Bookmarks::View::TT' => { + 'V::TT' => { TIMER => 0, }, ); diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm index d64f2fd..1039ade 100644 --- a/lib/Bookmarks/C/Main.pm +++ b/lib/Bookmarks/C/Main.pm @@ -87,6 +87,12 @@ sub jump : Global { sub add : Global { my ( $self, $c ) = @_; + unless ($self->_authorized($c)) { + $c->res->status(403); + $c->res->body('non puoi'); + return; + } + my %pre_link=(); for my $field (qw(pk url title descr)) { $pre_link{$field}=$c->req->param($field); @@ -167,6 +173,12 @@ sub add : Global { sub edit : Global { my ( $self, $c ) = @_; + unless ($self->_authorized($c)) { + $c->res->status(403); + $c->res->body('non puoi'); + return; + } + my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link')); $c->stash->{link}=$link; @@ -198,6 +210,15 @@ sub search : Global { $c->stash->{template}='results'; } +sub _authorized { + my ($self,$c)=@_; + + if ($ENV{BOOKMARKS_CAN_EDIT}) { + return 1; + } + return; +} + =head1 AUTHOR A clever guy diff --git a/script/bookmarks_cgi.pl b/script/bookmarks_cgi.pl index 473bb30..d4cf76e 100755 --- a/script/bookmarks_cgi.pl +++ b/script/bookmarks_cgi.pl @@ -31,7 +31,7 @@ Sebastian Riedel, C Copyright 2004 Sebastian Riedel. All rights reserved. -This library is free software. You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. =cut diff --git a/script/bookmarks_create.pl b/script/bookmarks_create.pl index 4dceeba..17cba1c 100755 --- a/script/bookmarks_create.pl +++ b/script/bookmarks_create.pl @@ -7,13 +7,19 @@ use Catalyst::Helper; my $help = 0; my $nonew = 0; +my $short = 0; -GetOptions( 'help|?' => \$help, - 'nonew' => \$nonew ); +GetOptions( + 'help|?' => \$help, + 'nonew' => \$nonew, + 'short' => \$short + ); pod2usage(1) if ( $help || !$ARGV[0] ); -my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew}); +my $helper = + Catalyst::Helper->new( { '.newfiles' => !$nonew, short => $short } ); + pod2usage(1) unless $helper->mk_component( 'Bookmarks', @ARGV ); 1; @@ -27,8 +33,9 @@ bookmarks_create.pl - Create a new Catalyst Component bookmarks_create.pl [options] model|view|controller name [helper] [options] Options: - -help display this help and exits - -nonew don't create a .new file where a file to be created exists + -help display this help and exits + -nonew don't create a .new file where a file to be created exists + -short use short types, like C instead of Controller... Examples: bookmarks_create.pl controller My::Controller @@ -49,7 +56,7 @@ Create a new Catalyst Component. Existing component files are not overwritten. If any of the component files to be created already exist the file will be written with a '.new' suffix. -This behaviour can be supressed with the C<-nonew> option. +This behavior can be suppressed with the C<-nonew> option. =head1 AUTHOR @@ -59,7 +66,7 @@ Sebastian Riedel, C Copyright 2004 Sebastian Riedel. All rights reserved. -This library is free software. You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. =cut diff --git a/script/bookmarks_fastcgi.pl b/script/bookmarks_fastcgi.pl index 7061403..546d552 100755 --- a/script/bookmarks_fastcgi.pl +++ b/script/bookmarks_fastcgi.pl @@ -3,11 +3,24 @@ BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' } use strict; +use Getopt::Long; +use Pod::Usage; use FindBin; use lib "$FindBin::Bin/../lib"; use Bookmarks; -Bookmarks->run; +my $help = 0; +my ( $listen, $nproc ); + +GetOptions( + 'help|?' => \$help, + 'listen|l=s' => \$listen, + 'nproc|n=i' => \$nproc, +); + +pod2usage(1) if $help; + +Bookmarks->run( $listen, { nproc => $nproc } ); 1; @@ -17,7 +30,16 @@ bookmarks_fastcgi.pl - Catalyst FastCGI =head1 SYNOPSIS -See L +bookmarks_fastcgi.pl [options] + + Options: + -? -help display this help and exits + -l -listen Socket path to listen on + (defaults to standard input) + can be HOST:PORT, :PORT or a + filesystem path + -n -nproc specify number of processes to keep + to serve requests (defaults to 1) =head1 DESCRIPTION @@ -31,7 +53,7 @@ Sebastian Riedel, C Copyright 2004 Sebastian Riedel. All rights reserved. -This library is free software. You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. =cut diff --git a/script/bookmarks_server.pl b/script/bookmarks_server.pl index ac117e0..1cc1e3c 100755 --- a/script/bookmarks_server.pl +++ b/script/bookmarks_server.pl @@ -2,7 +2,7 @@ BEGIN { $ENV{CATALYST_ENGINE} ||= 'HTTP'; - $ENV{CATALYST_SCRIPT_GEN} = 4; + $ENV{CATALYST_SCRIPT_GEN} = 11; } use strict; @@ -10,16 +10,47 @@ use Getopt::Long; use Pod::Usage; use FindBin; use lib "$FindBin::Bin/../lib"; -use Bookmarks; -my $help = 0; -my $port = 3000; - -GetOptions( 'help|?' => \$help, 'port=s' => \$port ); +my $debug = 0; +my $fork = 0; +my $help = 0; +my $host = undef; +my $port = 3000; +my $restart = 0; +my $restart_delay = 1; +my $restart_regex = '\.yml$|\.yaml$|\.pm$'; + +my @argv = @ARGV; + +GetOptions( + 'debug|d' => \$debug, + 'fork' => \$fork, + 'help|?' => \$help, + 'host=s' => \$host, + 'port=s' => \$port, + 'restart|r' => \$restart, + 'restartdelay|rd=s' => \$restart_delay, + 'restartregex|rr=s' => \$restart_regex +); pod2usage(1) if $help; -Bookmarks->run($port); +if ( $restart ) { + $ENV{CATALYST_ENGINE} = 'HTTP::Restarter'; +} +if ( $debug ) { + $ENV{CATALYST_DEBUG} = 1; +} + +require Bookmarks; + +Bookmarks->run( $port, $host, { + argv => \@argv, + 'fork' => $fork, + restart => $restart, + restart_delay => $restart_delay, + restart_regex => qr/$restart_regex/ +} ); 1; @@ -32,8 +63,18 @@ bookmarks_server.pl - Catalyst Testserver bookmarks_server.pl [options] Options: - -? -help display this help and exits - -p -port port (defaults to 3000) + -d -debug force debug mode + -f -fork handle each request in a new process + (defaults to false) + -? -help display this help and exits + -host host (defaults to all) + -p -port port (defaults to 3000) + -r -restart restart when files got modified + (defaults to false) + -rd -restartdelay delay between file checks + -rr -restartregex regex match files that trigger + a restart when modified + (defaults to '\.yml$|\.yaml$|\.pm$') See also: perldoc Catalyst::Manual @@ -51,7 +92,7 @@ Sebastian Riedel, C Copyright 2004 Sebastian Riedel. All rights reserved. -This library is free software. You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. =cut diff --git a/script/bookmarks_test.pl b/script/bookmarks_test.pl index 9476a7d..d692744 100755 --- a/script/bookmarks_test.pl +++ b/script/bookmarks_test.pl @@ -40,7 +40,7 @@ bookmarks_test.pl [options] uri =head1 DESCRIPTION -Run a Catalyst action from the comand line. +Run a Catalyst action from the command line. =head1 AUTHOR @@ -50,7 +50,7 @@ Sebastian Riedel, C Copyright 2004 Sebastian Riedel. All rights reserved. -This library is free software. You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. =cut -- cgit v1.2.3