Thread Perlscript vom Browser aufrufen (7 answers)
Opened by Chris at 2013-04-04 00:19

guest Chris
 2013-04-04 00:19
#166871 #166871
Hallo zusammen,

ich bin neu am Thema Perl dran, habe aber schon eine (für mich) unlösbare Aufgabe an der Backe.

Ich benutze folgendes Script von der Konsole und da funktioniert es:
more (6.3kb):

Code: (dl )
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl -w
# Copyright (c) 2009-2010 William Lam All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author or contributors may not be used to endorse or
# promote products derived from this software without specific prior
# written permission.
# 4. Consent from original author prior to redistribution

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

# William Lam
# 09/22/2009
# http://communities.vmware.com/docs/DOC-10809
# http://engr.ucsb.edu/~duonglt/vmware/
# Original source: http://communities.vmware.com/thread/133551
#####################################################################

#use strict;
use warnings;
use VMware::VILib;
use VMware::VIRuntime;
use MIME::Base64;

my ($vc_name,$vmname,$vm_view,$obfuscate,$tail_string,$permission_string);

my %opts = (
vmname => {
type => "=s",
help => "Name of the Virutal Machine",
required => 1,
},
obfuscate => {
type => "=s",
help => "obfuscate URL [0|1]",
required => 0,
},
limit_single_vm_view => {
type => "=s",
help => "Limit veiw to a single virtual machine [0|1]",
required => 0,
default => 1,
},
limit_workspace_view => {
type => "=s",
help => "Limit workspace view to console [0|1]",
required => 0,
default => 1,
},
);

# validate options, and connect to the server
Opts::add_options(%opts);

# validate options, and connect to the server
Opts::parse();
Opts::validate();
Util::connect();

$vmname = Opts::get_option('vmname');
$obfuscate = Opts::get_option('obfuscate');
$vc_name = Opts::get_option('server');

my $remoteURL = "";
my $vcVersion = Vim::get_service_content()->about->version;

$vm_view = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {"name" => $vmname});

unless($vm_view) {
Util::disconnect();
die "Unable to locate VM: \"$vmname\"!\n";
}

if($vcVersion eq "5.0.0") {
my $vcInstanceUUID = Vim::get_service_content()->about->instanceUuid;
my $vmMoRef = $vm_view->{'mo_ref'}->{'value'};
$remoteURL = "https://$vc_name:9443/vsphere-client/vmrc/vmrc.jsp?vm=$vcInstanceUUID:VirtualMachine:$vmMoRef";
} else {
if($obfuscate eq "") {
Util::disconnect();
print "Please specify whether or not to obfuscate URL! with --obfuscate parameter!\n";
exit 1;
}

if(!Opts::get_option('limit_single_vm_view')) {
$permission_string = "&inventory=expanded";
} else {
$permission_string = "&inventory=none";
}

if(!Opts::get_option('limit_workspace_view')) {
$permission_string .= "&tabs=show_";
} else {
$permission_string .= "&tabs=hide_";
}

my $vm_mo_ref_id = $vm_view->{'mo_ref'}->value;
if($obfuscate eq "1") {
$tail_string = "http://localhost:80/sdk&mo=VirtualMachine|${vm_mo_ref_id}${permission_string}";
$tail_string = "?view=" . encode_base64($tail_string);
} else {
$tail_string = "?wsUrl=http://localhost:80/sdk&mo=VirtualMachine|${vm_mo_ref_id}${permission_string}";
}

$remoteURL = "https://$vc_name/ui/" . $tail_string;
}

print "Here is the Remote Console URL for " . $vm_view->name . "\n" . $remoteURL . "\n";

Util::disconnect();


Das Script stammt von hier: http://www.virtuallyghetto.com/2011/10/how-to-gene...

Nun möchte ich das gerne von einem Browser aufrufen und die geforderten Parameter per URL übergeben. Also z.B.:

http://localhost/script.pl?vmname=Testvm&vc-server...

IIS7 mit Perl ist eingerichtet und funktioniert. Das Script kann ich auch aufrufen, aber ich schaffe es nicht, die Parameter zu übergeben.

Ich bin für eure Hilfe echt dankbar!

Gruß aus Stuttgart

modedit Editiert von pq: script in more-tags gesetzt
Last edited: 2013-04-04 00:22:04 +0200 (CEST)

View full thread Perlscript vom Browser aufrufen