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