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