| 1 | #!/usr/bin/perl | ||||||||||||||||||
| 2 | # this defines all the valid commands for the frontend spooler. if you | ||||||||||||||||||
| 3 | # add more commands you have to define them in _is_valid_command | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | package Net::Server::Framework::Validate; | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | 1 | ▶ | use Data::FormValidator; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 1 | our ($VERSION) = '1.1'; | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 0 | ▶ | sub verify_command { | ||||||||||||||||
|
Subroutine
verify_command: not called CC=5 SCAR=34.0
| |||||||||||||||||||
| 16 | 0 | my $data = shift; | |||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | 0 | my $rules = { | |||||||||||||||||
| 19 | required => [qw/command user pass/], | ||||||||||||||||||
| 20 | optional => [qw/data format options/], | ||||||||||||||||||
| 21 | filters => ['trim'], | ||||||||||||||||||
| 22 | constraints => { | ||||||||||||||||||
| 23 | 'command' => \&_is_valid_command, | ||||||||||||||||||
| 24 | 'user' => qr/^[\w-]{3,100}/, | ||||||||||||||||||
| 25 | 'format' => qr/^[yaml|xml|json]/, | ||||||||||||||||||
| 26 | 'pass' => qr/^[\w]{10,100}$/, | ||||||||||||||||||
| 27 | }, | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | }; | ||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 0 | my $dfv = Data::FormValidator->check( $data, $rules ); | |||||||||||||||||
| 32 | #print STDERR Dumper($dfv); | ||||||||||||||||||
| 33 | 0 | ▶ | if ( $dfv->has_unknown ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 34 | 0 | return 2306; | |||||||||||||||||
| 35 | } | ||||||||||||||||||
| 36 | elsif ( $dfv->has_missing ) { | ||||||||||||||||||
| 37 | 0 | return 2003; | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | elsif ( $dfv->has_invalid ) { | ||||||||||||||||||
| 40 | 0 | ▶ | if ( defined $dfv->{invalid}->{command} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 41 | 0 | return 2000; | |||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | else { | ||||||||||||||||||
| 44 | 0 | return 2005; | |||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | 0 | return $dfv->valid; | |||||||||||||||||
| 48 | } | ||||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | 0 | ▶ | sub _is_valid_command { | ||||||||||||||||
|
Subroutine
_is_valid_command: not called CC=2 SCAR=17.9
| |||||||||||||||||||
| 51 | 0 | my $command = pop; | |||||||||||||||||
| 52 | 0 | $command = lc($command); | |||||||||||||||||
| 53 | # add your commands below to enable them in the frontend spooler | ||||||||||||||||||
| 54 | 0 | my @commands = qw{login}; | |||||||||||||||||
| 55 | 0 | ▶ | if ( my $hit = grep( /$command/, @commands ) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 56 | 0 | return 1; | |||||||||||||||||
| 57 | } | ||||||||||||||||||
| 58 | 0 | return 0; | |||||||||||||||||
| 59 | } | ||||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | 1 | 1; | |||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | =head1 NAME | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | Net::Server::Framework::Validate - validation library for Net::Server::Framework | ||||||||||||||||||
| 66 | based daemons | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | |||||||||||||||||||
| 69 | =head1 VERSION | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | This documentation refers to Net::Server::Framework::Validate version 1.1. | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | =head1 SYNOPSIS | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | A typical invocation looks like this: | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | $c = Net::Server::Framework::Validate::verify_command($c); | ||||||||||||||||||
| 79 | if ($c =~ /^\d+$/){ | ||||||||||||||||||
| 80 | print STDERR "Validation failed - dodgy command!"; | ||||||||||||||||||
| 81 | return $c; | ||||||||||||||||||
| 82 | } | ||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | =head1 DESCRIPTION | ||||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | This interface is used to validate commands sent to the daemon. You have | ||||||||||||||||||
| 87 | to provide valid commands in the array defined in _is_valid_command. | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | my @commands = qw{login MORE COMMANDS}; | ||||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | =head1 BASIC METHODS | ||||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | The commands accepted by the lib are: | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | =head2 verify_command | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | This tests for the validity of a command | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | There are no known bugs in this module. | ||||||||||||||||||
| 102 | Please report problems to | ||||||||||||||||||
| 103 | Lenz Gschwendtner ( <lenz@springtimesoft.com> ) | ||||||||||||||||||
| 104 | Patches are welcome. | ||||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | =head1 AUTHOR | ||||||||||||||||||
| 107 | |||||||||||||||||||
| 108 | Lenz Gschwendtner ( <lenz@springtimesoft.com> ) | ||||||||||||||||||
| 109 | |||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||
| 113 | |||||||||||||||||||
| 114 | Copyright (c) | ||||||||||||||||||
| 115 | 2007 Lenz Gschwerndtner ( <lenz@springtimesoft.comn> ) | ||||||||||||||||||
| 116 | All rights reserved. | ||||||||||||||||||
| 117 | |||||||||||||||||||
| 118 | This module is free software; you can redistribute it and/or | ||||||||||||||||||
| 119 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||
| 122 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||
| 123 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||