use pmt_ro;
use table_control;
+use report;
use misc_subs;
$self->{pmt_ro} = pmt_ro->new();
$self->{table_control} = table_control->new();
+ $self->{report} = report->new();
$self->load_settings();
$self->{table_control}->settings_form();
print "</div>";
+ print "<p id='show_report_settings' class='quasibutton' >report settings</p>";
+ print "<div align=right id='report_settings_container' class='stylishBox settings_form hidden_by_default'>";
+ $self->{report}->settings_form();
+ print "</div>";
+
print "</div>";
print end_html();
});
print ">>> scan completed!\n\n";
+ print ">>> sending report ...\n\n";
+ $self->compile_report();
+ print ">>> done!\n\n";
return "";
my $scan = $self->{scan_shm}->readShm();
my $tc = $self->{table_control};
+ my $tofile = $options{tofile};
+
my $sample_rect_x1 = $tc->{settings}->{sample_rect_x1};
my $sample_rect_x2 = $tc->{settings}->{sample_rect_x2};
my $sample_rect_y1 = $tc->{settings}->{sample_rect_y1};
}
push(@rows,join("\t",@cols));
}
- print join("\n",@rows);
+ if(defined($tofile)){
+ open(FILE,"> $tofile") or die "cannot open output file $tofile\n";
+ print FILE join("\n",@rows);
+ close(FILE);
+ } else {
+ print join("\n",@rows);
+ }
return " ";
}
}
+sub compile_report {
+
+ my $self = shift;
+ my %options = @_;
+
+ my $timestamp = strftime("%Y-%m-%d_%H:%M:%S", localtime());
+
+
+ my $storable = "./report/".$timestamp."_scan.storable";
+ system("cp /dev/shm/".$self->{scan_shm}->{shmName}." $storable");
+ my $dump = "./report/".$timestamp."_scan.dump";
+
+ my $csv = "./report/".$timestamp."_scan.csv";
+ my $svg = "./report/".$timestamp."_scan.svg";
+ my $xls = $csv.".xls";
+
+ open(DUMP,"> $dump") or die "cannot open $dump for writing \n";
+ print DUMP Dumper($self->last_scan());
+ close(DUMP);
+
+ $self->scan_to_ascii(tofile => $csv);
+ $self->scan_to_svg(svg_file => $svg);
+ system("./csv2xls.sh $csv");
+
+ $self->{report}->email(
+ text => "Scan has finished at $timestamp, all recorded data is attached",
+ attachments => join(",",($csv,$svg,$xls,$storable,$dump))
+ );
+
+ return " ";
+
+}
+
--- /dev/null
+package report;
+
+
+use strict;
+use warnings;
+use POSIX qw/strftime/;
+use POSIX;
+
+
+use Net::SMTP::SSL;
+use MIME::Base64 qw( encode_base64 );
+
+use File::Basename;
+
+use misc_subs;
+use has_settings;
+our @ISA = qw/has_settings/; # assimilate the methods of the has_settings class
+
+## methods
+
+sub new {
+ my $class = shift;
+ my %options = @_;
+
+ my $self = {}; # put tons of default values here (if you wish);
+
+ $self->{constants} = {
+ };
+
+ $self->{settings_file} = "./".__PACKAGE__.".settings";
+
+ $self->{default_settings} = { # hard default settings
+ recipients => "",
+ from => "",
+ sender_address => "",
+ sender_password => "",
+ subject => "Coral Scan finished",
+ smtp_server => "smtp.sth.sth",
+ smtp_port => "465",
+ };
+
+ $self->{settings_desc} = {
+ recipients => "A comma separated list of email addresses of people who are to receive a confirmation
+ and the data when a scan has finished.",
+ from => "The displayed address of the sender",
+ sender_address => "Email address of account which is used to send the confirmation email.",
+ sender_password => "Password of the account which is used to send the confirmation email.",
+ subject => "Confirmation email subject",
+ smtp_server => "Outgoing mail server (SMTP)",
+ smtp_port => "The port of the outgoing SMTP connection",
+ };
+
+ $self->{has_run} = {}; # remember which subs already have run
+
+ $self->{settings} = {%{$self->{default_settings}}};
+
+ $self = {
+ %$self,
+ %options
+ };
+ bless($self, $class);
+ $self->load_settings();
+
+ return $self;
+}
+
+
+sub email {
+
+ my $self = shift;
+ my %options = @_;
+
+ my $to = $self->{settings}->{recipients};
+ $to =~ s/\s//g;
+ my @recipients = split(',',$to);
+
+ my $attch_list = $options{attachments} || "";
+ $attch_list =~ s/\s//g;
+ my @attachments = split(',',$attch_list);
+
+ my $text = $options{text} || "";
+
+ my $account = $self->{settings}->{sender_address};
+ my $password = $self->{settings}->{sender_password};
+
+ my $boundary = 'frontier';
+
+ for my $recipient (@recipients) {
+
+ my $smtp = Net::SMTP::SSL->new(
+ Host => $self->{settings}->{smtp_server},
+ Port => $self->{settings}->{smtp_port},
+ Timeout => 120
+ ); # connect to an SMTP server
+ die "Couldn't open connection: $!" if (!defined $smtp );
+
+
+ $smtp->auth($account,$password);
+ $smtp->mail( $account ); # use the sender's address here
+ $smtp->to( $recipient ); # recipient's address
+ $smtp->data(); # Start the mail
+ # Send the header.
+ $smtp->datasend("To: $recipient\n");
+ $smtp->datasend("From: ".$self->{settings}->{from}."\n");
+ $smtp->datasend("Subject: ".$self->{settings}->{subject}."\n");
+
+ $smtp->datasend("MIME-Version: 1.0\n");
+ $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n");
+ $smtp->datasend("\n");
+ $smtp->datasend("--$boundary\n");
+ $smtp->datasend("Content-type: text/plain\n");
+ $smtp->datasend("Content-Disposition: quoted-printable\n");
+# $smtp->datasend("\nToday\'s files are attached:\n");
+# $smtp->datasend("\nHave a nice day! :)\n");
+ $smtp->datasend("\n".$text."\n");
+ $smtp->datasend("--$boundary\n");
+
+ for my $attachBinaryFile (@attachments) {
+ my $attachBinaryFileName = (fileparse($attachBinaryFile))[0] ;
+ $smtp->datasend("Content-Type: binary; name=\"$attachBinaryFileName\"\n");
+ $smtp->datasend("Content-Transfer-Encoding: base64\n");
+ $smtp->datasend("Content-Disposition: attachment; filename=\"$attachBinaryFileName\"\n");
+ $smtp->datasend("\n");
+ my $buf;
+ open(DAT, "$attachBinaryFile") || die("Could not open binary file!");
+ binmode(DAT);
+ # local $/=undef;
+ while (read(DAT, my $picture, 4096)) {
+ $buf = &encode_base64( $picture );
+ $smtp->datasend($buf);
+ }
+ close(DAT);
+ $smtp->datasend("\n");
+ $smtp->datasend("--$boundary\n");
+ }
+
+ $smtp->dataend(); # Finish sending the mail
+ $smtp->quit; # Close the SMTP connection
+ }
+
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+sub help {
+ my $self = shift;
+ my $verbose = shift;
+ print "This is the help message!\n";
+# pod2usage(verbose => $verbose);
+ exit;
+
+}
+
+
+
+1;