#!/bin/perl #!/usr/bin/perl #!/usr/local/bin/perl ## ############################################ ## ## Modificar.cgi ## ## Copyright© 1998-2000 by Juliano Primavesi ## ## VERSAO 2.0 ## ############################################ ## # Bibliotecas # -------------------------------------------------------- eval { ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX / ($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \ require "../data/lib/busca.cfg"; require "$db_lib_path/tempo.pl"; require "$db_lib_path/anuncie.pl"; require "$db_lib_path/db_utils.pl"; require "$db_lib_path/links.def"; require "$db_lib_path/site_html_templates.pl"; use Socket; }; if ($@) { print "Content-type: text/plain\n\n"; print "Error including libraries: $@\n"; print "Make sure they exist, permissions are set properly, and paths are set correctly."; exit; } # ======================================================== eval { &main; }; # Trap any fatal errors so the program hopefully if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page. exit; # There are only two exit calls in the script, here and in in &cgierr. sub main { # -------------------------------------------------------- local (%in) = &parse_form; # We are processing the form. if ($in{'URL_Esqueci'}) { open (ARQUIVO,"<$db_links_name"); @dados = ; close (ARQUIVO); foreach $linha (@dados) { @tche = split(/\s*\|\s*/,$linha,40); if ($tche[2] eq $in{'URL'}) { my (%rec) = &get_record ($tche[0]); &manda_email ($tche[0]); &site_html_modify_senha ("Título: $rec{'Title'}
Endereço: $rec{'URL'}
Seu ID: $rec{'ID'}
Senha enviada para: $rec{'Contact Email'}"); exit; } } &site_html_modify_failure2 ("Endereço não encontrado.
Tente novamente"); exit; } elsif ($in{'SenhaAtual'}) { &process_form; } # Otherwise we are displaying the form (in site_html.pl), displaying # the entrance (Asks for Link ID and Password) else { if ($in{'ID'} =~ /^\d+$/) { my (%rec) = &get_record ($in{'ID'}); if ($rec{$db_key} eq $in{'ID'}) { if ($rec{'Senha'} eq $in{'Senha'}) { &site_html_modify_form (%rec); } else { # &manda_email (%rec); &site_html_modify_failure2 ("Senha Inválida: $in{'Senha'}"); } } else { &site_html_modify_failure2 ("ID: $in{'ID'}"); } } else { &site_html_modify; } } } sub process_form { # -------------------------------------------------------- my ($key, $status, @values, $found); local (%original); # Make sure we have a link to modify !$in{'SenhaAtual'} and &site_html_modify_failure ("Dados Incorretos!") and return; # Let's check to make sure the link we want to update is actually # in the database. open (DB, "<$db_file_name") or &cgierr("Erro validando registro. Impossível de abrir arquivo: $db_file_name. Reason: $!"); $found = 0; LINE: while () { (/^#/) and next LINE; (/^\s*$/) and next LINE; chomp; @data = &split_decode($_); if ($data[$db_url] eq $in{'Current URL'} and $data[$db_senha] eq $in{'SenhaAtual'}) { $in{$db_key} = $data[0]; $found = 1; %original = &array_to_hash (0, @data); last LINE; } } close DB; !$found and &site_html_modify_failure ("Link não encontrado no nosso Banco de Dados") and return; # Since we have a valid link, let's make sure the system fields are set to their # proper values. We will simply copy over the original field values. This is to stop # people from trying to modify system fields like number of hits, etc. foreach $key (keys %add_system_fields) { $in{$key} = $original{$key}; } # Set date variable to today's date. $in{$db_cols[$db_modified]} = &get_date; # Validate the form input.. $status = &validate_record(%in); if ($status eq "ok") { # First make sure the link isn't already in there. open (MOD, "<$db_modified_name") or &cgierr ("Erro abrindo banco de dados para modificação. Arquivo: $db_modified_name. Reason: $!"); while () { chomp; @values = split /\|/; if ($values[0] eq $in{$db_key}) { close MOD; &site_html_modify_failure("Já temos um pedido de modificação para este link. Favor, espere que este seja autorizado para que seja solicitado uma nova modificação."); return; } } close MOD; # Print out the modified record to a "modified database" where it is stored until # the admin decides to add it into the real database. open (MOD, ">>$db_modified_name") or &cgierr("Impossível abrir banco de dados: $db_modified_name. Reason: $!"); flock(MOD, $LOCK_EX) unless (!$db_use_flock); print MOD &join_encode(%in); close MOD; # automatically removes file lock # Send the admin an email message notifying of new addition. &send_email; # Send the visitor to the success page. &site_html_modify_success; } else { # Let's change that error message from a comma delimted list to an html # bulleted list. &site_html_modify_failure($status); } } sub send_email { # -------------------------------------------------------- my (%link) = @_; my $to = $in{$db_cols[$db_contact_email]}; my $from = $db_cadastros_email; my $subject = "Modificação de Cadastro: $in{'Title'}"; my $msg = &load_template ('email-mod-1.txt', { Date => $in{'Date'}, ID => $in{'ID'}, Title => $in{'Title'}, URL => $in{'URL'}, Category => $in{'Category'}, Description => $in{'Description'}, Keywords => $in{'Keywords'}, Senha => $in{'Senha'}, 'Contact Name' => $in{'Contact Name'}, 'Contact Email' => $in{'Contact Email'} } ); # Then mail it away! require "$db_lib_path/Mailer.pm"; my $mailer = new Mailer ( { smtp => $db_smtp_server, sendmail => $db_mail_path, from => $from, subject => $subject, to => $to, msg => $msg, log => $db_mailer_log } ) or return undef; $mailer->send or return undef; } sub manda_email { my $super = shift; my (%rec) = &get_record ($super); my $to = "$rec{'Contact Name'} <$rec{'Contact Email'}>"; my $from = $db_cadastros_email; my $subject = "Envio Automatico de Senha"; my $msg = &load_template ('email-mod-senha.txt', { Date => $rec{'Date'}, ID => $rec{'ID'}, Title => $rec{'Title'}, URL => $rec{'URL'}, Category => $rec{'Category'}, Description => $rec{'Description'}, Keywords => $rec{'Keywords'}, Senha => $rec{'Senha'}, 'Contact Name' => $rec{'Contact Name'}, 'Contact Email' => $rec{'Contact Email'} } ); # Then mail it away! require "$db_lib_path/Mailer.pm"; my $mailer = new Mailer ( { smtp => $db_smtp_server, sendmail => $db_mail_path, from => $from, subject => $subject, to => $to, msg => $msg, log => $db_mailer_log } ) or &cgierr("Unable to init mailer! Reason: $Mailer::error"); $mailer->send or &cgierr ("Unable to send message. Reason: $Mailer::error"); }