1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
|
#!/usr/bin/perl -w
# $Id: perlbug,v 1.6 2013/07/17 19:34:06 tom Exp $
#
# Purpose:
# This 'rips' off Larry's perlbug from the utils directory.
use strict;
# Determine if the user has one of the mail modules.
BEGIN {
eval "use Mail::Send;";
$::HaveSend = ( $@ eq "" );
}
use Config;
use Sys::Hostname;
use Getopt::Std;
our ( $opt_a, $opt_c, $opt_f, $opt_h, $opt_r, $opt_s, $opt_v );
our $cc;
#
# Load in the Cdk Extension.
#
use Cdk;
Cdk::init();
# Create global variables.
my ($Version) = "1.00";
my $address = "perlbug\@perl.com";
# Check the command line arguments.
getopts("c:a:f:r:s:vh");
# Did they ask for help?
if ( defined $opt_h ) {
my @help = (
"<C></B/5>Perl Bug Reporting Facility Help Window.",
"</B/5>Usage:<!B!5> $0 [-c CC] [-a Admin Account]",
" [-r Reply Account] [-s subject]",
" [-f filename] [-v] [-h]",
"",
"<B=-c> The account to carbon copy to.",
"<B=-a> The perl admin account.",
"<B=-r> The account to reply to.",
"<B=-s> The subject of the bug report.",
"<B=-f> The file to read in as the bug report.",
"<B=-v> Turns on verbose output for the bug report.",
"<B=-h> Pops up this help window.",
"",
"<C></B/5>Press Any Key To Continue."
);
popupLabel( \@help );
}
# Create a program information message.
my @progInfo = (
"<C></5/B>Perl Bug Reporting Facility",
"<C></24/B>Version $Version",
"",
"This program allows you to create a bug report which will be",
"mailed to </B>$address<!B> once the report has been filled out.",
"",
"<C>Hit any key when you are ready to start."
);
popupLabel( \@progInfo );
# Create the generic label.
my @mesg = (
"******************************************************",
"******************************************************",
"******************************************************",
"******************************************************"
);
my $mainTitle = new Cdk::Label( 'Message' => \@mesg, 'Xpos' => "TOP" );
# Get the subject to the mail message.
my $subject = $opt_s || getSubject($mainTitle);
my $verbose = $opt_v;
# Get the reply address.
@mesg =
( "<C></B/24>Return Email Address", "<C>Enter your return e-mail address." );
my $defaultReplyAddress = getlogin() . "@" . hostname() . ".";
my $replyAddress = $opt_r
|| getEmailAddress( $mainTitle, $defaultReplyAddress, @mesg );
# Get the perl admin address.
@mesg = (
"<C></B/24>Perl Admin Email Address",
"<C>Enter the email address of the perl admin."
);
my $defaultAdminAddress = $::Config{perladmin};
my $adminAddress = $opt_a
|| getEmailAddress( $mainTitle, $defaultAdminAddress, @mesg );
# Create the bug report.
my @report = createBugReport( $mainTitle, $subject, $opt_f );
# View the bug report.
viewBugReport( $subject, $replyAddress, $adminAddress, $cc, @report );
exit;
############################################################################
#
# This gets the subject to the bug report.
#
sub getSubject {
my $mainTitle = shift;
# Create the subject entry field.
my $entry = new Cdk::Entry(
'Label' => "</B/5>Subject: ",
'Width' => 35,
'Min' => 3,
'Max' => 256
);
# Set the main title info.
@mesg = (
"<C></24/B>Enter Subject",
"<C>Please provide a subject for the message. It",
"<C>should be as a concise description of the bug",
"<C>as is possible."
);
$mainTitle->set( 'Message' => \@mesg );
$mainTitle->draw();
# Get the subject.
while (1) {
my $subject = $entry->activate();
last if defined $subject;
# No subject, prompt them for one...
popupLabel(
[
"<C></16/B>Error",
"<C>You must have a subject line for the mail message.",
"", "<C>Please try again."
]
);
}
return $subject;
}
############################################################################
#
# This gets an emial address.
#
sub getEmailAddress {
my ( $mainTitle, $entryValue, @mesg ) = @_;
my $info;
# Set the main title info.
$mainTitle->set( 'Message' => \@mesg );
# Create the entry field to get the email address.
my $entry = new Cdk::Entry(
'Label' => "</B/5>email Address: ",
'Min' => 3,
'Max' => 256,
'Width' => 35
);
# Put the user name in the entry field.
$entry->set( 'Value' => "$entryValue" );
# Get the emial address
while (1) {
$info = $entry->activate();
last if defined $info;
# No subject, prompt them for one...
popupLabel(
[
"<C></B/16>Error", "<C>You must provide an email address.",
"", "<C>Please Try again."
]
);
}
return $info;
}
############################################################################
#
# This gets the bug report from the user.
#
sub createBugReport {
my ( $mainTitle, $subject, $filename ) = @_;
my @bugReport = ();
my @info = ();
my $info;
# If a filename has been speicifed, then we will use the contents of the
# file for the bug report.
if ( defined $filename && -e $filename ) {
open( FILE, $filename );
my @tmp = <FILE>;
chomp(@tmp);
return @tmp;
}
# Create the title.
my @mesg = (
"<C></24/B>Bug Report",
"<C>Enter a description of the bug you are submitting."
);
# Set the main title info.
$mainTitle->set( 'Message' => \@mesg );
# Create the entry field to get the email address.
my $entry = new Cdk::Mentry(
'Label' => "</B/5>Description: ",
'Prows' => 8,
'Lrows' => 15,
'Width' => 50
);
# Get the bug report.
while (1) {
$info = $entry->activate();
last if defined $info;
# No subject, prompt them for one...
popupLabel(
[
"<C></B/16>Error",
"<C>You must provide a description of the bug.",
"", "<C>Please Try again."
]
);
}
# Split the string into a list.
@info = Cdk::scalar2List( $info, 40 );
# Create the bug report.
my $from = `whoami`;
push( @bugReport,
"This is a bug report for perl from $from generated with" );
push( @bugReport,
"the help of the Cdk version of perlbug running under perl $]." );
push( @bugReport, "" );
push( @bugReport, "Subject: $subject" );
push( @bugReport, "" );
for ( my $x = 0 ; $x <= $#info ; $x++ ) {
push( @bugReport, $info[$x] );
}
push( @bugReport, "" );
push( @bugReport, "Site configuration information for perl $]:" );
if ( $::Config{cf_by} and $::Config{cf_time} ) {
push( @bugReport,
"Configured by $::Config{cf_by} at $::Config{cf_time}." );
}
push( @bugReport, "" );
foreach ( split( /\n/, Config::myconfig ) ) {
push( @bugReport, $_ );
}
# Do they want a verbose bug report?
if ($::opt_v) {
push( @bugReport, "" );
push( @bugReport, "Complete configuration data for perl $]:" );
push( @bugReport, "" );
foreach ( sort keys %::Config ) {
my $value = $::Config{$_};
$value =~ s/'/\\'/g;
push( @bugReport, "$_='$value'" );
}
}
return @bugReport;
}
############################################################################
#
# This views the bug report.
#
sub viewBugReport {
my ( $subject, $replyAddress, $adminAddress, @bugReport ) = @_;
my @buttons = ("</B/24>OK");
# Get the height and width of the screen.
my ( $height, $width ) = Cdk::getCdkScreenDim();
$height -= 3;
$width -= 3;
# Create the file viewer.
my $viewer = new Cdk::Viewer(
'Buttons' => \@buttons,
'Height' => $height,
'Width' => $width
);
# Fill the viewer with the contents of the bug report.
$viewer->set(
'Title' => "<C></5>Bug Report",
'Highlight' => "</B/5>",
'Info' => \@bugReport
);
$viewer->activate();
# Ask them what they want to do with the bug report.
my @mesg = (
"<C>Now that the bug report has been created, you can",
"<C>send the bug report to </R>$replyAddress<!R> and </R>$adminAddress<!R>,",
"<C>or you can save the report to a file and send it later",
"<C>on your own, or you can quit without saving or sending",
"<C>the bug report."
);
@buttons = ( "</B/24>Send", "</B/8>Save", "</B/16>Cancel" );
my $choice = popupDialog( \@mesg, \@buttons );
# Redraw the viewer widget.
$viewer->draw();
# Check what they want to do.
if ( $choice == 0 ) {
# Mail to bug report.
sendBugReport( $subject, $replyAddress, $adminAddress, @bugReport );
}
elsif ( $choice == 1 ) {
# Save to a file.
saveBugReport(@bugReport);
}
else {
popupLabel( ["<C></B/24>Send Bug Report Canceled."] );
}
}
#
# This saves the bug report to a file.
#
sub saveBugReport {
my @bugReport = @_;
my $filename;
# Get the filename to save to.
my $entry = new Cdk::Entry(
'Label' => "</B/5>Filename: ",
'Width' => 30,
'Min' => 2,
'Max' => 256
);
# Make sure we can write to the file.
while (1) {
# Get the filename.
$filename = $entry->activate();
# Try to open the filename.
last if open( FILE, ">$filename" );
popupLabel(
[ "<C></B/16>Error", "<C>Can not save to the file $filename" ] );
}
# Save the bug report to the file.
foreach (@bugReport) {
print FILE "$_\n";
}
close(FILE);
# Tell the user the file has been saved.
popupLabel(
[
"The bug report has been saved to $filename",
"",
"<C>Press any key to continue."
]
);
}
#
# This sends the bug report to the given addresses.
#
sub sendBugReport {
my ( $subject, $replyAddress, $adminAddress, $cc, @bugReport ) = @_;
my $address = "perlbug\@perl.com";
# Do we have the sendmail module?
if ($::HaveSend) {
# Create a mail object.
my $mailMessage = new Mail::Send(
'Subject' => "$subject",
'To' => "$address"
);
# Add a carbon copy, if we have one.
$mailMessage->cc($cc) if $cc;
# Add a from line.
$mailMessage->add( "Reply-To" => $replyAddress ) if $replyAddress;
# Open the mail message and write the contents.
my $fh = $mailMessage->open;
foreach (@bugReport) {
print $fh "$_\n";
}
# Close the mail message (aka send it.)
$fh->close;
# Popup a little message.
popupLabel( ["<C>The bug report has been sent."] );
return;
}
else {
# No, Okay, let's try to use sendmail normally. (normally????)
my $sendmail = "";
# Where oh where are you you today...
foreach (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail))
{
$sendmail = $_, last if -e $_;
}
# Can we even send the bug report?
if ( $sendmail eq "" ) {
# We can't send the bug report, maybe we can save it to a file.
my @mesg = (
"</B/5>Hmmmm.",
"<C>I'm terribly sorry but I can't find sendmail and the package",
"<C>Mail::Send has not been installed, so I can't send your bug",
"<C>report. Since I can't send the bug report, would you like to",
"<C>save it to a file and send it yourself?"
);
if ( popupDialog( \@mesg, [ "Yep", "Nope" ] ) == 0 ) {
saveBugReport(@bugReport);
}
return;
}
# Send the message via sendmail.
open( SENDMAIL, "|$sendmail -t" );
print SENDMAIL "To: $address\n";
print SENDMAIL "Subject: $subject\n";
print SENDMAIL "Cc: $cc\n" if $cc;
print SENDMAIL "Reply-To: $replyAddress\n" if $replyAddress;
print SENDMAIL "\n\n";
foreach (@bugReport) {
print SENDMAIL "$_\n";
}
close(SENDMAIL);
# Popup a little message.
popupLabel( ["<C>The bug report has been sent."] );
}
}
|