#!/usr/bin/perl -T use strict; use lib qw(./ ./DADA ../ ../DADA ../DADA/perllib); use CGI::Carp "fatalsToBrowser"; #---------------------------------------------------------------------# # archive_editor.cgi # For instructions, see the pod of this file. try: # # http://mojo.skazat.com/support/documentation/archive_editor.cgi # #---------------------------------------------------------------------# # There are no serviceable parts # #---------------------------------------------------------------------# my $Program_Ver = '.01 - 11/15/05'; use CGI; my $q = new CGI; my $URL = $q->url; $ENV{PATH} = "/bin:/usr/bin"; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; use DADA::Config; use DADA::Template::HTML; use DADA::App::Guts; use DADA::MailingList::Settings; use DADA::MailingList::Archives; use DADA::Mail::Send; use MIME::Parser; $|++; my %Headers_To_Edit; my $parser = new MIME::Parser; $parser = optimize_mime_parser($parser); my $skel = []; my ($admin_list, $root_login) = check_list_security(-cgi_obj => $q, -Function => 'archive_editor'); my $list = $admin_list; my $ls = DADA::MailingList::Settings->new(-List => $list); my $li = $ls->get; my $mh = DADA::Mail::Send->new($li); my $ah = DADA::MailingList::Archives->new(-List => $li); main(); #---------------------------------------------------------------------# sub main { if($q->param('flavor') eq 'prefs'){ &prefs; }else{ if($q->param('process')){ &edit_archive; }else{ &view; } } } sub view { my $id = $q->param('id'); if(!$id){ print $q->redirect(-uri => $PROGRAM_URL . '?flavor=view_archive'); exit; } if($ah->check_if_entry_exists($id) <= 0){ print $q->redirect(-uri => $PROGRAM_URL . '?flavor=view_archive'); exit; } my ($subject, $message, $format, $raw_msg) = $ah->get_archive_info($id); # do I need this? $raw_msg ||= $ah->_bs_raw_msg($subject, $message, $format); print(admin_html_header(-Title => "Edit Archived Message (BETA) - $Program_Ver", -List => $li->{list}, -Form => 0, -Root_Login => $root_login)); if($q->param('done')){ print $GOOD_JOB_MESSAGE; } if($ah->can_display_message_source){ print qq{
Display Original Message Source
}; } print qq{'; print qq{}; print admin_html_footer(-List => $list, -Form => 0); } sub prefs { if($q->param('process')){ my $the_id = $q->param('id'); my $editable_headers = join(',', $q->param('editable_header')); $ls->save({editable_headers => $editable_headers}); print $q->redirect(-uri => $URL . '?flavor=prefs&done=1&id=' . $the_id); exit; }else{ my %editable_headers; $editable_headers{$_} = 1 foreach(split(',', $li->{editable_headers})); my $edit_headers_menu = []; foreach(@EMAIL_HEADERS_ORDER){ push(@$edit_headers_menu, {name => $_, editable => $editable_headers{$_}}); } print(admin_html_header(-Title => "Edit Archived Message (BETA) - $Program_Ver Preferences", -List => $li->{list}, -Form => 0, -Root_Login => $root_login)); #die $q->param('id'); my $the_id = $q->param('id'); my $done = $q->param('done'); require DADA::Template::Widgets; print DADA::Template::Widgets::screen(-data => prefs_template(), -vars => { edit_headers_menu => $edit_headers_menu, done => $done, URL => $URL, id => $the_id, }, ); print admin_html_footer(-List => $list, -Form => 0); } } sub prefs_template { my $template = <Editable Headers:
| " value="" checked="checked" /> |
<-- Back to the Archived Message
EOF ; return \$template; } sub edit_archive { my $id = $q->param('id'); my ($subject, $message, $format, $raw_msg) = $ah->get_archive_info($id); my $entity; eval { $entity = $parser->parse_data($raw_msg) }; my $throwaway = undef; ($entity, $throwaway) = edit($entity); $ah->set_archive_info($id, $q->param('Subject'), undef, undef, $entity->as_string); print $q->redirect(-uri => $URL . '?id=' . $id . '&done=1'); } sub make_skeleton { my ($entity, $name) = @_; defined($name) or $name = "0"; my $IO; # Output the body: my @parts = $entity->parts; if (@parts) { push(@$skel, {address => $name, entity => $entity}); # multipart... my $i; foreach $i (0 .. $#parts) { # dump each part... make_skeleton($parts[$i], ("$name\-".($i))); } }else { # single part... push(@$skel, {address => $name, entity => $entity, body => 1}); } } sub edit { my ($entity, $name) = @_; defined($name) or $name = "0"; my $IO; if($name eq '0'){ foreach my $h(@EMAIL_HEADERS_ORDER){ if($q->param($h)){ if($Headers_To_Edit{$h} == 1){ $entity->head->replace($h, $q->param($h)); } } } } my @parts = $entity->parts; if (@parts) { # multipart... my $i; foreach $i (0 .. $#parts) { my $name_is; ($parts[$i], $name_is) = edit($parts[$i], ("$name\-".($i))); if($q->param('delete_' . $name_is) == 1){ delete($parts[$i]); } } #love it. #love it love it. $entity->parts(\@parts); $entity->sync_headers('Length' => 'COMPUTE', 'Nonstandard' => 'ERASE'); }else { return (undef, $name) if($q->param('delete_' . $name) == 1); my $content = $q->param($name); if($content){ my $body = $entity->bodyhandle; my $io = $body->open('w'); $io->print( $content ); $io->close; } my $cid = $entity->head->get('content-id') || undef; if($q->param('upload_' . $name)){ $entity = get_from_upload($name, $cid); } $entity->sync_headers('Length' => 'COMPUTE', 'Nonstandard' => 'ERASE'); return ($entity, $name); } return ($entity, $name); } sub get_from_upload { my $name = shift; my $cid = shift; my $filename = file_upload('upload_' . $name); my $data; my $nice_filename = $q->param('upload_' . $name); require MIME::Entity; my $ent = MIME::Entity->build( Path => $filename, Filename => $nice_filename, Encoding => "base64", Disposition => "attachment", Type => find_attachment_type($filename), Id => $cid, ); return $ent; } sub file_upload { my $upload_file = shift; my $fu = CGI->new(); my $file = $fu->param($upload_file); if ($file ne "") { my $fileName = $file; $fileName =~ s!^.*(\\|\/)!!; eval {require URI::Escape}; if(!$@){ $fileName = URI::Escape::uri_escape($fileName, "\200-\377"); }else{ warn('no URI::Escape is installed!'); } $fileName =~ s/\s/%20/g; my $outfile = make_safer($TMP . '/' . time . '_' . $fileName); open (OUTFILE, '>' . $outfile) or warn("can't write to " . $outfile . ": $!"); while (my $bytesread = read($file, my $buffer, 1024)) { print OUTFILE $buffer; } close (OUTFILE); chmod($FILE_CHMOD, $outfile); return $outfile; } } sub find_attachment_type { my $filename = shift; my $a_type; my $attach_name = $filename; $attach_name =~ s!^.*(\\|\/)!!; $attach_name =~ s/\s/%20/g; my $file_ending = $attach_name; $file_ending =~ s/.*\.//; require MIME::Types; require MIME::Type; if(($MIME::Types::VERSION >= 1.005) && ($MIME::Type::VERSION >= 1.005)){ my ($mimetype, $encoding) = MIME::Types::by_suffix($filename); $a_type = $mimetype if ($mimetype && $mimetype =~ /^\S+\/\S+$/); ### sanity check }else{ if(exists($MIME_TYPES{'.'.lc($file_ending)})) { $a_type = $MIME_TYPES{'.'.lc($file_ending)}; }else{ $a_type = $DEFAULT_MIME_TYPE; } } #if(!$a_type){ #warn "attachment MIME Type never figured out, letting MIME::Lite handle this..."; #$a_type = 'AUTO'; #} return $a_type; } =cut =pod =head1 NAME archive_editor.cgi (BETA RELEASE) =head1 Obtaining The Program archive_editor.cgi is located in the, I