]> git.zerfleddert.de Git - rsbs2/blame - supermicro-kvm.pl
add $url to exceptions.sites if the file exists
[rsbs2] / supermicro-kvm.pl
CommitLineData
a154a83f
MG
1#!/usr/bin/perl -w
2
3use LWP::UserAgent;
4use LWP::ConnCache;
5use XML::Simple;
6use Data::Dumper;
7use File::Temp;
8
9my $ua = LWP::UserAgent->new(cookie_jar => {});
10$ua->default_header('Referer' => 'http://localhost');
11
12sub 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
22sub 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;
5e257ef3 30
a154a83f 31 next if (m/^#/);
5e257ef3 32
a154a83f
MG
33 if (m/^\s*\[(.*)\]\s*$/) {
34 push @sections, $1;
35 next;
36 }
5e257ef3 37
a154a83f
MG
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
27476265
TG
49sub 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
a154a83f
MG
65my %Config = read_inifile("$ENV{HOME}/.rsbs2rc");
66
583bcdfc 67my $hostalias = $ARGV[0];
a154a83f 68
583bcdfc 69if (!defined($hostalias) || !defined($Config{$hostalias})) {
a154a83f 70 print STDERR "Usage: $0 card-alias\n\n";
aee44959
TG
71 print STDERR "card-alias\tone of:\n";
72 foreach my $alias (sort keys(%Config)) {
73 print STDERR "\"${alias}\"\n";
a154a83f
MG
74 }
75 print STDERR "(see ~/.rsbs2rc)\n";
76 exit(1);
77}
78
79my $url = "http://" . ${$Config{$hostalias}}{"host"};
80login($url, ${$Config{$hostalias}}{"user"}, ${$Config{$hostalias}}{"pass"});
27476265 81add_url_to_java_exceptions($url);
a154a83f
MG
82
83my $response = $ua->get("${url}/cgi/url_redirect.cgi?url_name=ikvm&url_type=jwsk");
84die $response->status_line if (!($response->is_success));
85
86my $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
90my $fh = File::Temp->new(SUFFIX => '.jnlp');
91$fh->unlink_on_destroy(1);
92
93print $fh $jnlp;
94
2fd81eb0 95$ENV{'AWT_TOOLKIT'} = 'MToolkit';
a154a83f
MG
96system("javaws", $fh->filename);
97sleep(1);
Impressum, Datenschutz