sanitycheck.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env perl -w
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  4. # The contents of this file are subject to the Mozilla Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is the Bugzilla Bug Tracking System.
  15. #
  16. # The Initial Developer of the Original Code is Frédéric Buclin.
  17. # Portions created by Frédéric Buclin are Copyright (C) 2007
  18. # Frédéric Buclin. All Rights Reserved.
  19. #
  20. # Contributor(s): Frédéric Buclin <LpSolit@gmail.com>
  21. use strict;
  22. use lib qw(. lib);
  23. use Bugzilla;
  24. use Bugzilla::Constants;
  25. use Bugzilla::Error;
  26. use Bugzilla::User;
  27. use Bugzilla::Mailer;
  28. use Getopt::Long;
  29. use Pod::Usage;
  30. my $verbose = 0; # Return all comments if true, else errors only.
  31. my $login = ''; # Login name of the user which is used to call sanitycheck.cgi.
  32. my $help = 0; # Has user asked for help on this script?
  33. my $result = GetOptions('verbose' => \$verbose,
  34. 'login=s' => \$login,
  35. 'help|h|?' => \$help);
  36. pod2usage({-verbose => 1, -exitval => 1}) if $help;
  37. Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
  38. # Be sure a login name if given.
  39. $login || ThrowUserError('invalid_username');
  40. my $user = new Bugzilla::User({ name => $login })
  41. || ThrowUserError('invalid_username', { name => $login });
  42. my $cgi = Bugzilla->cgi;
  43. my $template = Bugzilla->template;
  44. # Authenticate using this user account.
  45. Bugzilla->set_user($user);
  46. # Pass this param to sanitycheck.cgi.
  47. $cgi->param('verbose', $verbose);
  48. require 'sanitycheck.cgi';
  49. # Now it's time to send an email to the user if there is something to notify.
  50. if ($cgi->param('output')) {
  51. my $message;
  52. my $vars = {};
  53. $vars->{'addressee'} = $user->email;
  54. $vars->{'output'} = $cgi->param('output');
  55. $vars->{'error_found'} = $cgi->param('error_found') ? 1 : 0;
  56. $template->process('email/sanitycheck.txt.tmpl', $vars, \$message)
  57. || ThrowTemplateError($template->error());
  58. MessageToMTA($message);
  59. }
  60. __END__
  61. =head1 NAME
  62. sanitycheck.pl - Perl script to perform a sanity check at the command line
  63. =head1 SYNOPSIS
  64. ./sanitycheck.pl [--help]
  65. ./sanitycheck.pl [--verbose] --login <user@domain.com>
  66. =head1 OPTIONS
  67. =over
  68. =item B<--help>
  69. Displays this help text
  70. =item B<--verbose>
  71. Causes this script to be more verbose in its output. Without this option,
  72. the script will return only errors. With the option, the script will append
  73. all output to the email.
  74. =item B<--login>
  75. This should be passed the email address of a user that is capable of
  76. running the Sanity Check process, a user with the editcomponents priv. This
  77. user will receive an email with the results of the script run.
  78. =back
  79. =head1 DESCRIPTION
  80. This script provides a way of running a 'Sanity Check' on the database
  81. via either a CLI or cron. It is equivalent to calling sanitycheck.cgi
  82. via a web broswer.