]> cvs.zerfleddert.de Git - rsbs2/blame - supermicro-kvm.pl
supermicro-kvm: handle redirects to https
[rsbs2] / supermicro-kvm.pl
CommitLineData
a154a83f
MG
1#!/usr/bin/perl -w
2
3use LWP::UserAgent;
4use LWP::ConnCache;
cf68e0ab 5use IO::Socket::SSL;
a154a83f
MG
6use XML::Simple;
7use Data::Dumper;
8use File::Temp;
9
cf68e0ab
MG
10my $ua = LWP::UserAgent->new(cookie_jar => {},
11 ssl_opts => {verify_hostname => 0,
12 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE});
a154a83f 13$ua->default_header('Referer' => 'http://localhost');
cf68e0ab 14push @{ $ua->requests_redirectable }, 'POST';
a154a83f
MG
15
16sub login {
17 my $url = shift;
18 my $user = shift;
19 my $pass = shift;
20
21 my $login = { 'name' => $user, 'pwd' => $pass };
22 my $response = $ua->post("${url}/cgi/login.cgi", $login);
23 die $response->status_line if (!($response->is_success));
24}
25
26sub read_inifile {
27 my $filename = shift;
28
29 open(INIFILE,"<${filename}") || die("can't open config: ${filename}: $!");
30 my %Ini = ();
31 my @sections = ();
32 while(<INIFILE>) {
33 chomp;
5e257ef3 34
a154a83f 35 next if (m/^#/);
5e257ef3 36
a154a83f
MG
37 if (m/^\s*\[(.*)\]\s*$/) {
38 push @sections, $1;
39 next;
40 }
5e257ef3 41
a154a83f
MG
42 if (@sections) {
43 if (m/^\s*([^=]+)\s*=\s*(.*)\s*$/) {
44 ${$Ini{$sections[$#sections]}}{$1} = $2;
45 }
46 }
47 }
48 close(INIFILE);
49
50 %Ini;
51}
52
27476265
TG
53sub add_url_to_java_exceptions {
54 my $url = shift || die;
55 my $file = "$ENV{HOME}/.java/deployment/security/exception.sites";
56 return unless -f ${file};
57 open my $fh, '+<', $file || die;
58 unless (grep{m#${url}#} <$fh>){
59 close $fh;
60 if (open my $fh, '>>', $file) {
61 print $fh "${url}\n";
62 close $fh;
63 }
64 } else {
65 close $fh;
66 }
67}
68
a154a83f
MG
69my %Config = read_inifile("$ENV{HOME}/.rsbs2rc");
70
583bcdfc 71my $hostalias = $ARGV[0];
a154a83f 72
583bcdfc 73if (!defined($hostalias) || !defined($Config{$hostalias})) {
a154a83f 74 print STDERR "Usage: $0 card-alias\n\n";
aee44959
TG
75 print STDERR "card-alias\tone of:\n";
76 foreach my $alias (sort keys(%Config)) {
77 print STDERR "\"${alias}\"\n";
a154a83f
MG
78 }
79 print STDERR "(see ~/.rsbs2rc)\n";
80 exit(1);
81}
82
83my $url = "http://" . ${$Config{$hostalias}}{"host"};
84login($url, ${$Config{$hostalias}}{"user"}, ${$Config{$hostalias}}{"pass"});
27476265 85add_url_to_java_exceptions($url);
a154a83f
MG
86
87my $response = $ua->get("${url}/cgi/url_redirect.cgi?url_name=ikvm&url_type=jwsk");
88die $response->status_line if (!($response->is_success));
89
90my $jnlp = $response->decoded_content;
91
92$jnlp =~ s/(<resources os=\"Linux\" arch=\"amd64\">)/$1<property name=\"jnlp.packEnabled\" value=\"true\"\/><property name=\"jnlp.versionEnabled\" value=\"true\"\/>/;
93
94my $fh = File::Temp->new(SUFFIX => '.jnlp');
95$fh->unlink_on_destroy(1);
96
97print $fh $jnlp;
98
2fd81eb0 99$ENV{'AWT_TOOLKIT'} = 'MToolkit';
a154a83f
MG
100system("javaws", $fh->filename);
101sleep(1);
Impressum, Datenschutz