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
|
#!/usr/bin/perl
# fillbugzilla
# copyright (c) 2002 Guillaume Rousse <guillomovitch@zarb.org>
# $Id$
use strict;
use warnings;
use Getopt::Long;
use Bugzilla;
use Mail::Sendmail;
# constants
my $name = "fillbugzilla";
my $version = "1.0";
# command-line parameters
my ($base, $user, $pass, $project, $mode, $help);
GetOptions(
"base=s" => \$base,
"user=s" => \$user,
"pass=s" => \$pass,
"mode=s" => \$mode,
"help" => \$help,
);
# mandatory argument
die usage() unless ($base && $user && $pass);
die usage() unless ($mode eq 'package' || $mode eq 'packager');
usage() && exit 0 if $help;
my $bugzilla = Bugzilla->new('localhost', $base, $user, $pass);
if ($mode eq 'packager') {
while (my $packager = <>) {
chomp $packager;
my ($name, $login) = split(/\t/, $packager);
# random passwd
my @chars = (0..9, 'A'..'Z', 'a'..'z', '-', '_', '!', '@', '#', '$', '%', '^', '&', '*');
my $password = join('', map { $chars[rand(scalar @chars)] } 1 .. 8);
# insert into database
$bugzilla->add_packager($name, $login, $password);
# mail user
my %mail = (
smtp => 'localhost',
To => $login,
From => 'bugmaster@zarb.org',
Subject => 'bugzilla password',
'X-Mailer' => "$name $version",
);
$mail{Message} .= "login: $login\n";
$mail{Message} .= "password: $password\n";
sendmail(%mail) or warn $Mail::Sendmail::error;
}
}
if ($mode eq 'package') {
while (my $line = <>) {
chomp $line;
my ($name, $summary, $version, $maintainer) = split(/\t/, $line);
$bugzilla->add_package($name, $summary, $version, $maintainer);
}
}
sub usage {
print <<EOF;
$name $version
Usage:
$name --base <base> --user <user> --pass <pass> --mode <mode> < $file
Options:
--base <base> bugzilla base name
--user <user> bugzilla base user
--pass <pass> bugzilla base password
--mode <mode> package or packager
EOF
}
|