};
my $kvmkeymaparray = [];
-foreach my $lc (keys %$keymaphash) {
+foreach my $lc (sort keys %$keymaphash) {
push @$kvmkeymaparray, $keymaphash->{$lc}->[1];
}
sub sendmail {
my ($mailto, $subject, $text, $html, $mailfrom, $author) = @_;
- $mailto = [ $mailto ] if ref($mailto) ne 'ARRAY';
+ $mailto = [ $mailto ] if !ref($mailto);
my $rcvrarg = '';
foreach my $r (@$mailto) {
my $rcvrtxt = join (', ', @$mailto);
$mailfrom = $mailfrom || "root";
- $author = $author || 'Proxmox VE mail notifier';
+ $author = $author || 'Proxmox VE';
open (MAIL,"|sendmail -B 8BITMIME -f $mailfrom $rcvrarg") ||
die "unable to open 'sendmail' - $!";
print MAIL "This is a multi-part message in MIME format.\n\n";
print MAIL "--$boundary\n";
- if ($text) {
+ if (defined($text)) {
print MAIL "Content-Type: text/plain;\n";
print MAIL "\tcharset=\"UTF8\"\n";
print MAIL "Content-Transfer-Encoding: 8bit\n";
print MAIL "\n--$boundary\n";
}
- if($html) {
+ if (defined($html)) {
print MAIL "Content-Type: text/html;\n";
print MAIL "\tcharset=\"UTF8\"\n";
print MAIL "Content-Transfer-Encoding: 8bit\n";
}
close(MAIL);
-
}
sub tempfile {
return ("/proc/$$/fd/".$fh->fileno, $fh);
}
+sub validate_ssh_public_keys {
+ my ($raw) = @_;
+ my @lines = split(/\n/, $raw);
+
+ foreach my $line (@lines) {
+ next if $line =~ m/^\s*$/;
+ eval {
+ my ($filename, $handle) = tempfile_contents($line);
+ run_command(["ssh-keygen", "-l", "-f", $filename],
+ outfunc => sub {}, errfunc => sub {});
+ };
+ die "SSH public key validation error\n" if $@;
+ }
+}
+
1;