« auto/share/dist/Nes/cgi-bin/obj/Nes/form/secure_login.pm
↑ Summary
auto/share/dist/Nes/cgi-bin/obj/Nes/form/multi_step.pm »
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # ----------------------------------------------------------------------------- | ||
| 4 | # | ||
| 5 | # NES by Skriptke | ||
| 6 | # Copyright 2009 - 2010 Enrique F. Castañón | ||
| 7 | # Licensed under the GNU GPL. | ||
| 8 | # | ||
| 9 | # Sample: | ||
| 10 | # http://nes.sourceforge.net/ | ||
| 11 | # | ||
| 12 | # Repository: | ||
| 13 | # http://github.com/Skriptke/nes | ||
| 14 | # | ||
| 15 | # Version 1.00_01 | ||
| 16 | # | ||
| 17 | # debug_info.pm | ||
| 18 | # | ||
| 19 | # ----------------------------------------------------------------------------- | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use Nes; | ||
| 23 | |||
| 24 | { | ||
| 25 | |||
| 26 | package debug_info; | ||
| 27 | use vars qw(@ISA); | ||
| 28 | @ISA = qw( Nes ); | ||
| 29 | |||
| 30 | my $instance; | ||
| 31 | |||
| 32 | sub new { | ||
| 33 | my $class = shift; | ||
| 34 | my $plugin = nes_plugin->get_obj('debug_info'); | ||
| 35 | my $self = $instance || $class->SUPER::new(); | ||
| 36 | my ($template) = @_; | ||
| 37 | |||
| 38 | $self->{'first_time'} = 1; | ||
| 39 | $self->init($template) if !$instance; | ||
| 40 | $self->{'first_time'} = 0 if $instance; | ||
| 41 | |||
| 42 | $instance = $self; | ||
| 43 | return $self; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub init { | ||
| 47 | my $self = shift; | ||
| 48 | my ($template) = @_; | ||
| 49 | |||
| 50 | $self->{'plugin'} = nes_plugin->new( 'debug_info', 'debug_info', $self ); | ||
| 51 | $self->{'objects'} = (); | ||
| 52 | $self->{'template'} = $template; | ||
| 53 | $self->{'remote_ip'} = $self->{'top_container'}->get_nes_env('nes_remote_ip'); | ||
| 54 | |||
| 55 | use POSIX qw(strftime); | ||
| 56 | my $gmt = POSIX::strftime( "%a %e %b %Y %H:%M:%S", gmtime ); | ||
| 57 | $self->{'starting'} = "*----------------------------------"; | ||
| 58 | $self->{'starting'} .= "* debug_info starting at $gmt GMT *"; | ||
| 59 | $self->{'starting'} .= "----------------------------------*\n\n"; | ||
| 60 | |||
| 61 | my $interpret = nes_interpret->new( $self->{'CFG'}->{'debug_info_template'} ); | ||
| 62 | $self->{'debug_info_template'} = $interpret->go(); | ||
| 63 | |||
| 64 | return; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub add { | ||
| 68 | my $self = shift; | ||
| 69 | |||
| 70 | $self->{'obj'} = debug_obj->new; | ||
| 71 | push( @{$self->{'objects'}}, $self->{'obj'} ); | ||
| 72 | |||
| 73 | $self->{'top'} = nes_top_container->new(); | ||
| 74 | |||
| 75 | $self->{'top'}->{'container'} = nes_container->new($self->{'debug_info_template'}); | ||
| 76 | $self->{'top'}->{'container'}->set_tags(%{$self->{'obj'}->{'tags'}}); | ||
| 77 | $self->{'top'}->{'container'}->interpret(); | ||
| 78 | $self->{'obj'}->{'out'} = $self->{'top'}->{'container'}->get_out; | ||
| 79 | $self->{'out'} .= $self->{'obj'}->{'out'}; | ||
| 80 | |||
| 81 | $self->save; | ||
| 82 | |||
| 83 | $self->{'top'}->{'container'}->forget(); | ||
| 84 | $self->{'top'}->forget(); | ||
| 85 | |||
| 86 | return; | ||
| 87 | } | ||
| 88 | |||
| 89 | sub save { | ||
| 90 | my $self = shift; | ||
| 91 | |||
| 92 | if ( $self->{'CFG'}->{'debug_info_save_to_log'} ) { | ||
| 93 | open(my $log, '>>', $self->{'CFG'}->{'debug_info_save_to_log'}) || warn "couldn't open $self->{'CFG'}->{'debug_info_save_to_log'}"; | ||
| 94 | print $log $self->{'starting'} if $self->{'first_time'}; | ||
| 95 | print $log $self->{'obj'}->{'out'}; | ||
| 96 | close $log; | ||
| 97 | } | ||
| 98 | |||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub del_instance { | ||
| 103 | my $self = shift; | ||
| 104 | |||
| 105 | utl::cleanup(\$instance) if $ENV{'MOD_PERL'}; | ||
| 106 | |||
| 107 | return; | ||
| 108 | } | ||
| 109 | |||
| 110 | { | ||
| 111 | |||
| 112 | package debug_obj; | ||
| 113 | use vars qw(@ISA); | ||
| 114 | @ISA = qw( Nes ); | ||
| 115 | |||
| 116 | sub new { | ||
| 117 | my $class = shift; | ||
| 118 | my $self = $class->SUPER::new(); | ||
| 119 | |||
| 120 | $self->{'tags'} = {}; | ||
| 121 | $self->{'tags'}->{'cfg'} = [ {} ]; | ||
| 122 | $self->{'tags'}->{'env_cgi'} = [ {} ]; | ||
| 123 | $self->{'tags'}->{'env_nes'} = [ {} ]; | ||
| 124 | $self->{'template'} = $self->{'container'}; | ||
| 125 | |||
| 126 | $self->add_top if $self->{'container'}->{'file_name'} eq $self->{'top_container'}->{'file'}; | ||
| 127 | $self->add; | ||
| 128 | |||
| 129 | return $self; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub add_top { | ||
| 133 | my $self = shift; | ||
| 134 | |||
| 135 | my $obj = $self->{'template'}; | ||
| 136 | my $object = $self->{'tags'}; | ||
| 137 | |||
| 138 | $object->{'top_template'} = 1; | ||
| 139 | $object->{'url'} = $ENV{'SERVER_NAME'}.$ENV{'REQUEST_URI'}; | ||
| 140 | |||
| 141 | $object->{'GET'} = $ENV{'QUERY_STRING'}; | ||
| 142 | # if ( $self->{'query'}->{'save_buffer'} ) { | ||
| 143 | # while ( my $buffer = $self->{'query'}->get_buffer ) { | ||
| 144 | # $object->{'POST'} .= $buffer; | ||
| 145 | # } | ||
| 146 | # } else { | ||
| 147 | $object->{'POST'} = $self->{'query'}->get_buffer_raw; | ||
| 148 | # } | ||
| 149 | |||
| 150 | $object->{'cookies'} = $obj->{'cookies'}->out; | ||
| 151 | $object->{'headers'} = $obj->{'content_obj'}->{'HTTP-headers'} || | ||
| 152 | $obj->{'content_obj'}->{'TAG_HTTP-headers'} || | ||
| 153 | $obj->{'content_obj'}->{'Content-type'}; | ||
| 154 | |||
| 155 | |||
| 156 | return; | ||
| 157 | } | ||
| 158 | |||
| 159 | sub add { | ||
| 160 | my $self = shift; | ||
| 161 | |||
| 162 | my $obj = $self->{'template'}; | ||
| 163 | my $object = $self->{'tags'}; | ||
| 164 | |||
| 165 | $object->{'object'} = $obj->{'file_name'}; | ||
| 166 | $object->{'object_no_path'} = $obj->{'file_name'}; | ||
| 167 | $object->{'object_no_path'} =~ s/.*\///; | ||
| 168 | $object->{'parent'} = $obj->{'previous'}->{'file_name'}; | ||
| 169 | $object->{'type'} = $obj->{'container'}->{'type'}; | ||
| 170 | $object->{'top_container_obj'} = $obj->{'top_container'}; | ||
| 171 | $object->{'container_obj'} = $obj; | ||
| 172 | $object->{'content_obj'} = $obj->{'container'}->{'content_obj'}; | ||
| 173 | $object->{'interactions'} = $obj->{'container'}->{'this_inter'}; | ||
| 174 | $object->{'scripts'} = "@{ $obj->{'file_script'} }"; | ||
| 175 | $object->{'source'} = $obj->{'container'}->{'file_nes_line'}."@{ $obj->{'container'}->{'file_souce'} }"; | ||
| 176 | $object->{'out'} = $obj->get_out_content(); | ||
| 177 | use Data::Dumper; | ||
| 178 | $Data::Dumper::Varname = 'Dumper_VARS'; | ||
| 179 | $Data::Dumper::Maxdepth = 2; | ||
| 180 | $object->{'dumper_top'} = Data::Dumper::Dumper($obj->{'top_container'}); | ||
| 181 | $object->{'dumper_container'} = Data::Dumper::Dumper($obj->{'container'}); | ||
| 182 | $object->{'dumper_template'} = Data::Dumper::Dumper($obj->{'container'}->{'content_obj'}); | ||
| 183 | $object->{'dumper_cookies'} = Data::Dumper::Dumper($obj->{'cookies'}); | ||
| 184 | $object->{'dumper_session'} = Data::Dumper::Dumper($obj->{'session'}); | ||
| 185 | $object->{'dumper_query'} = Data::Dumper::Dumper($obj->{'query'}); | ||
| 186 | $object->{'dumper_CFG'} = Data::Dumper::Dumper($obj->{'CFG'}); | ||
| 187 | $object->{'dumper_nes'} = Data::Dumper::Dumper($obj->{'nes'}); | ||
| 188 | $Data::Dumper::Maxdepth = 5; | ||
| 189 | $object->{'dumper_tags'} = Data::Dumper::Dumper($obj->{'container'}->{'content_obj'}->{'tags'}); | ||
| 190 | # $object->{'unknown_tags'} = $1 = $object->{'out'} =~ /({:[^}]*.?|[^{]*:})/g; | ||
| 191 | |||
| 192 | $self->env(); | ||
| 193 | |||
| 194 | return; | ||
| 195 | } | ||
| 196 | |||
| 197 | sub env { | ||
| 198 | my $self = shift; | ||
| 199 | |||
| 200 | my $obj = $self->{'template'}; | ||
| 201 | |||
| 202 | my $cfg = $self->{'tags'}->{'cfg'}; | ||
| 203 | my $env_cgi = $self->{'tags'}->{'env_cgi'}; | ||
| 204 | my $env_nes = $self->{'tags'}->{'env_nes'}; | ||
| 205 | |||
| 206 | my $c = 0; | ||
| 207 | foreach my $key ( sort keys %{ $self->{'CFG'} } ) { | ||
| 208 | my $value = $self->{'CFG'}->{$key}; | ||
| 209 | $value = "@{$self->{'CFG'}->{$key}}" if ref $self->{'CFG'}->{$key} eq 'ARRAY'; | ||
| 210 | $value = keys %{$self->{'CFG'}->{$key}} if ref $self->{'CFG'}->{$key} eq 'HASH'; | ||
| 211 | $cfg->[$c]->{'key'} = $key; | ||
| 212 | $cfg->[$c]->{'value'} = $value; | ||
| 213 | $cfg->[$c]->{'value'} = '***removed for safety***' if $key =~ /priv|pass/; | ||
| 214 | $c++; | ||
| 215 | } | ||
| 216 | |||
| 217 | $c = 0; | ||
| 218 | foreach my $key ( sort keys %ENV ) { | ||
| 219 | $env_cgi->[$c]->{'key'} = $key; | ||
| 220 | $env_cgi->[$c]->{'value'} = $ENV{$key}; | ||
| 221 | $env_cgi->[$c]->{'value'} = '***removed for safety***' if $key =~ /priv|pass/; | ||
| 222 | $c++; | ||
| 223 | } | ||
| 224 | |||
| 225 | $c = 0; | ||
| 226 | foreach my $key ( sort keys %{ $self->{'top_container'}->{'nes_env'} } ) { | ||
| 227 | $env_nes->[$c]->{'key'} = $key; | ||
| 228 | $env_nes->[$c]->{'value'} = $self->{'top_container'}->{'nes_env'}{$key}; | ||
| 229 | $env_nes->[$c]->{'value'} = '***removed for safety***' if $key =~ /priv|pass/; | ||
| 230 | $c++; | ||
| 231 | } | ||
| 232 | |||
| 233 | } | ||
| 234 | |||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | } | ||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | |||
| 243 | # don't forget to return a true value from the file | ||
| 244 | 1; | ||
| 245 |