« auto/share/dist/Nes/cgi-bin/plugin/captcha_plugin.pm
↑ Summary
auto/share/dist/Nes/cgi-bin/obj/Nes/form/secure_login.pm »
| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # Nes by Skriptke | ||||||||||||||||||||
| 6 | # Copyright 2009 - 2010 Enrique F. Castañón Barbero | ||||||||||||||||||||
| 7 | # Licensed under the GNU GPL. | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | # CPAN: | ||||||||||||||||||||
| 10 | # http://search.cpan.org/dist/Nes/ | ||||||||||||||||||||
| 11 | # | ||||||||||||||||||||
| 12 | # Sample: | ||||||||||||||||||||
| 13 | # http://nes.sourceforge.net/ | ||||||||||||||||||||
| 14 | # | ||||||||||||||||||||
| 15 | # Repository: | ||||||||||||||||||||
| 16 | # http://github.com/Skriptke/nes | ||||||||||||||||||||
| 17 | # | ||||||||||||||||||||
| 18 | # Version 1.03 | ||||||||||||||||||||
| 19 | # | ||||||||||||||||||||
| 20 | # Setting.pm | ||||||||||||||||||||
| 21 | # | ||||||||||||||||||||
| 22 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | { | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | package Nes::Setting; | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 5 | my $instance; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 4 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||
| 31 | 4 | my $class = shift; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 4 | ▶ | utl::cleanup(\$instance) if $ENV{'MOD_PERL'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 4 | ▶ | return $instance if $instance; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 4 | my $level = utl::get_file_dir(); | |||||||||||||||||||
| 37 | 4 | my $file_name = '.nes.cfg'; | |||||||||||||||||||
| 38 | 4 | ▶ | my $nes_dir = $ENV{'SCRIPT_NAME'} || '/cgi-bin/nes'; # default: /cgi-bin/nes | ||||||||||||||||||
|
Condition50%1/2
$ENV{'SCRIPT_NAME'} || '/cgi-bin/nes'
MC/DC0%0/1
$ENV{'SCRIPT_NAME'} || '/cgi-bin/nes'
$ENV{'SCRIPT_NAME'}
Truth table50%1/2
A
A= $ENV{'SCRIPT_NAME'}
| |||||||||||||||||||||
| 39 | 4 | ▶ | my $nes_top_dir = $ENV{'SCRIPT_FILENAME'} || ''; | ||||||||||||||||||
|
Condition50%1/2
$ENV{'SCRIPT_FILENAME'} || ''
MC/DC0%0/1
$ENV{'SCRIPT_FILENAME'} || ''
$ENV{'SCRIPT_FILENAME'}
Truth table50%1/2
A
A= $ENV{'SCRIPT_FILENAME'}
| |||||||||||||||||||||
| 40 | 4 | $nes_dir =~ s/\/[^\/]*\.cgi|pl$//; | |||||||||||||||||||
| 41 | 4 | $nes_top_dir =~ s/\/[^\/]*\.cgi|pl$//; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # en entornos no cgi da el directorio en el que se ejecuta el script | ||||||||||||||||||||
| 44 | 4 | my $top_dir = utl::get_root_dir(); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 4 | my $self = { | |||||||||||||||||||
| 47 | tmp_dir => '/tmp/nes', | ||||||||||||||||||||
| 48 | tmp_suffix => '.nes_file_temp', | ||||||||||||||||||||
| 49 | tmp_clear => 0, # borrar los archivos temporales de más del tiempo indicado, si es 0 no borra | ||||||||||||||||||||
| 50 | top_dir => $top_dir, # document root | ||||||||||||||||||||
| 51 | nes_top_dir => $nes_top_dir, # nes dir install | ||||||||||||||||||||
| 52 | nes_dir => $nes_dir, # default: /cgi-bin/nes | ||||||||||||||||||||
| 53 | plugin_dir => $nes_dir . '/plugin', | ||||||||||||||||||||
| 54 | obj_dir => $nes_dir . '/obj', | ||||||||||||||||||||
| 55 | plugin_top_dir => $nes_top_dir . '/plugin', | ||||||||||||||||||||
| 56 | obj_top_dir => $nes_top_dir . '/obj', | ||||||||||||||||||||
| 57 | obj_form => $nes_top_dir . '/obj/Nes/form', | ||||||||||||||||||||
| 58 | img_dir => $nes_dir . '/images', | ||||||||||||||||||||
| 59 | time_zone => 'Europe/Madrid', # * sin implementar * | ||||||||||||||||||||
| 60 | locale => '', # es_ES.utf8 | ||||||||||||||||||||
| 61 | session_prefix => 'NESSESSION', | ||||||||||||||||||||
| 62 | private_key => 'ChangeIt', # Change private key | ||||||||||||||||||||
| 63 | DB_base => '', # Change in you .nes.cfg | ||||||||||||||||||||
| 64 | DB_user => '', # Change in you .nes.cfg | ||||||||||||||||||||
| 65 | DB_pass => '', # Change in you .nes.cfg | ||||||||||||||||||||
| 66 | DB_driver => 'mysql', # Change in you .nes.cfg | ||||||||||||||||||||
| 67 | DB_host => 'localhost', # Change in you .nes.cfg | ||||||||||||||||||||
| 68 | DB_port => '3306', # Change in you .nes.cfg | ||||||||||||||||||||
| 69 | php_cline => '/usr/bin/php', | ||||||||||||||||||||
| 70 | php_cgi_cline => '/usr/bin/php-cgi', | ||||||||||||||||||||
| 71 | perl_cline => '/usr/bin/perl', | ||||||||||||||||||||
| 72 | python_cline => '/usr/bin/python', | ||||||||||||||||||||
| 73 | shell_cline => '/bin/bash', | ||||||||||||||||||||
| 74 | max_post => 512, # max kB. for POST | ||||||||||||||||||||
| 75 | max_upload => 2048, # max kB. for upload, 0 none | ||||||||||||||||||||
| 76 | tmp_upload => 512, # a partir de que kB. se usa un archivo temporal en los upload | ||||||||||||||||||||
| 77 | auto_load_plugin_top_first => [ ], # Cargar Plugins al inicio, sólo para la URL | ||||||||||||||||||||
| 78 | auto_load_plugin_all_first => [ ], # Cargar Plugins al inicio, para todos los archivos incluidos | ||||||||||||||||||||
| 79 | auto_load_plugin_top_last => [ ], # Cargar Plugins al final, sólo para la URL | ||||||||||||||||||||
| 80 | auto_load_plugin_all_last => [ ], # Cargar Plugins al final, para todos los archivos incluidos | ||||||||||||||||||||
| 81 | kletters => [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ], | ||||||||||||||||||||
| 82 | knumbers => [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ], | ||||||||||||||||||||
| 83 | kletnum => [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ], | ||||||||||||||||||||
| 84 | }; | ||||||||||||||||||||
| 85 | 4 | bless $self, $class; | |||||||||||||||||||
| 86 | 4 | $instance = $self; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 4 | while (1) { | |||||||||||||||||||
| 89 | 4 | my $file = $level . '/' . $file_name; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 4 | $self->load_cfg($file); | |||||||||||||||||||
| 92 | 4 | $level =~ s/[\/\\][^\/\\]*$//; | |||||||||||||||||||
| 93 | 4 | ▶ | last if $level !~ /$self->{'top_dir'}/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 4 | ▶ | warn "Change the private_key in $file_name" if $self->{'private_key'} =~ /ChangeIt/i; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 4 | return $self; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 4 | ▶ | sub load_cfg { | ||||||||||||||||||
|
Subroutine
load_cfg: called CC=17 SCAR=36.4
Pod
undocumented
| |||||||||||||||||||||
| 102 | 4 | my $class = shift; | |||||||||||||||||||
| 103 | 4 | my $self = Nes::Setting::get_obj(); | |||||||||||||||||||
| 104 | 4 | my ($file) = @_; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 4 | ▶ | if ( -e $file ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 4 | ▶ | open( my $fh, "$file" ) || warn "couldn't open $file"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 4 | ▶ | while (<$fh>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 12 | chomp; | |||||||||||||||||||
| 110 | 12 | my $line = $_; | |||||||||||||||||||
| 111 | 12 | ▶ | next if $line =~ /^#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | 8 | ▶ | next if $line =~ /^$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | 4 | my ( $key, $value ) = split( /=\s*/, $line, 2 ); | |||||||||||||||||||
| 114 | 4 | $key =~ s/\s*(\@|\%|\$)?$//; | |||||||||||||||||||
| 115 | 4 | ▶ | my $eval = $1 || 0; | ||||||||||||||||||
|
Condition50%1/2
$1 || 0
MC/DC0%0/1
$1 || 0
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||
| 116 | 4 | $value =~ s/\s*$//; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | # impide que se reescriba 'set'; | ||||||||||||||||||||
| 119 | 4 | ▶ | next if $key eq 'set'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | # sólo sobreescribe los valores que cambian, los valores de éste | ||||||||||||||||||||
| 122 | # directorio priman sobre el nivel superior, se empieza a leer en el | ||||||||||||||||||||
| 123 | # nivel del script ya que por ejemplo $self->{'top_dir'} tiene que | ||||||||||||||||||||
| 124 | # estar fijado para conocer cual es el nivel superior. | ||||||||||||||||||||
| 125 | 4 | ▶ | unless ( $self->{'set'}{$key} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 4 | ▶ | if ( $eval ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 127 | 0 | ▶ | $eval = '@' if ref( $self->{$key} ) eq 'ARRAY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 0 | ▶ | $eval = '%' if ref( $self->{$key} ) eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | 0 | ▶ | $eval = '$' if ref( $self->{$key} ) eq 'SCALAR'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | ▶ | @{ $self->{$key} } = eval { $value } if $eval eq '@'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | 0 | ▶ | %{ $self->{$key} } = eval { $value } if $eval eq '%'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 0 | ▶ | $self->{$key} = eval "$value" if $eval eq '$'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | } elsif ( ref( $self->{$key} ) eq 'ARRAY' ) { | ||||||||||||||||||||
| 134 | 0 | @{ $self->{$key} } = split( /,/, $value ); | |||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||
| 136 | 4 | $self->{$key} = $value; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | 4 | $self->{'set'}{$key} = 1; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | 4 | close $fh; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | # si por error se deja la ultima barra del directorio | ||||||||||||||||||||
| 145 | 4 | $self->{'top_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 146 | 4 | $self->{'tmp_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 147 | 4 | $self->{'nes_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 148 | 4 | $self->{'plugin_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 149 | 4 | $self->{'obj_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 150 | 4 | $self->{'plugin_top_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 151 | 4 | $self->{'obj_top_dir'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 152 | 4 | $self->{'obj_form'} =~ s/[\/\\]$//; | |||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 4 | push( @INC, ( $self->{'plugin_top_dir'}, $self->{'obj_top_dir'}, $self->{'obj_form'} ) ); | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 4 | return; | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 32 | ▶ | sub get_obj { | ||||||||||||||||||
|
Subroutine
get_obj: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 160 | 32 | ▶ | my $self = $instance || Nes::Setting->new(); | ||||||||||||||||||
|
Condition66%2/3
$instance || 'Nes::Setting'->new
MC/DC0%0/2
$instance || 'Nes::Setting'->new
$instance
'Nes::Setting'->new
Truth table66%2/3
A || B
A= $instanceB= 'Nes::Setting'->new
| |||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 32 | return $self; | |||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 5 | 1; | |||||||||||||||||||
| 168 | |||||||||||||||||||||