-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmextra_export.cgi
152 lines (123 loc) · 4.47 KB
/
vmextra_export.cgi
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/perl
require 'vboxctrl-lib.pl';
&ReadParse();
my $VM = $in{'vm'};
my $USER = $in{'user'};
init_config();
$DEBUGMODE = $config{'DEBUGMODE'};
if($DEBUGMODE)
{
DebugOut();
}
if ($in{'export'})
{
# figure out the natdata
my %INFO = GetVMInfo($USER,$VM);
my $XMLFILE = $INFO{'Config file'};
#print "Config File: $XMLFILE <br>";
my $VMNAT = Read_NatXML($XMLFILE, 'fh00');
# figure out the extradata
my %EXTRA = GetVMExtradata($USER,$VM);
# download File
if ($in{'source'})
{
my $FILENAME = "\"PORTFORWARDING_$VM\.txt\"";
print "Content-type: application/octet-stream\n";
print "Content-Disposition: attachment; filename=$FILENAME\n";
print "\n";
print "# Webminmodule '$module_info{'desc'} (V $module_info{'version'})'\n";
print "# portforwarding rules for VM '$VM'\n";
print "# created on ".cgsdatum()."\n\n";
for (my $NIC=1; $NIC <= 8; $NIC++)
{
foreach my $RULE (keys %{$VMNAT->{$NIC-1}->{'natrule'}})
{
my ($PROTOCOL) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'proto'};
my ($HOSTIP) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'hostip'};
my ($HOSTPORT) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'hostport'};
my ($GUESTIP) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'guestip'};
my ($GUESTPORT) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'guestport'};
print "natpf:$NIC,$RULE,$PROTOCOL,$HOSTIP,$HOSTPORT,$GUESTIP,$GUESTPORT\n";
}
}
foreach $KEY (keys %EXTRA)
{
if ( ($KEY =~ /port/gi) || ($KEY =~ /protocol/gi) )
{
print "Key: $KEY, Value: $EXTRA{$KEY}\n";
}
}
webmin_log("Export (Download)","NATRules","'$VM' ($USER)",\%in);
}
# local File
else
{
&ui_print_header(undef, $text{'EXPORT_VMEXTRATITLE'}." '$VM'", "");
my $TARGETDIR = $in{'file'};
# Expand with '/'
if (! ($TARGETDIR =~ /\/$/))
{
$TARGETDIR .= "/";
}
# targetdir exists ??
if (! (-e $TARGETDIR))
{
&ui_print_header(undef, $text{'EXPORT_VMEXTRATITLE'}." '$VM'", "");
print "<b>",text('EXPORT_VMEXTRAERRDIR'," <tt>'$TARGETDIR'</tt>"),"</b><p>\n";
&ui_print_footer("vmextra_export.cgi?vm=$VM", $text{'EXPORT_VMEXTRATITLE'});
$ERR = 1;
}
else
{
$TARGETDIR .= "PORTFORWARDING_$VM.txt";
open (EXTRA , "> $TARGETDIR");
print EXTRA "# Webminmodule '$module_info{'desc'} (V $module_info{'version'})'\n";
print EXTRA "# portforwarding rules for VM '$VM'\n";
print EXTRA "# created on ".cgsdatum()."\n\n";
#my %GETNATPF = GetNATPF($USER,$VM);
for (my $NIC=1; $NIC <= 8; $NIC++)
{
foreach my $RULE (keys %{$VMNAT->{$NIC-1}->{'natrule'}})
{
my ($PROTOCOL) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'proto'};
my ($HOSTIP) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'hostip'};
my ($HOSTPORT) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'hostport'};
my ($GUESTIP) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'guestip'};
my ($GUESTPORT) = $VMNAT->{$NIC-1}->{'natrule'}->{$RULE}->{'guestport'};
print EXTRA "natpf:$NIC,$RULE,$PROTOCOL,$HOSTIP,$HOSTPORT,$GUESTIP,$GUESTPORT\n";
}
}
foreach $KEY (keys %EXTRA)
{
#print "'$KEY' --> '$EXTRA{$KEY}<br>";
if ( ($KEY =~ /port/gi) || ($KEY =~ /protocol/gi) )
{
print EXTRA "Key: $KEY, Value: $EXTRA{$KEY}\n";
}
}
close(EXTRA);
&ui_print_header(undef, $text{'EXPORT_VMEXTRATITLE'}." '$VM'", "");
print "<b>",&text('EXPORT_VMEXTRADONE', "<tt>$TARGETDIR</tt>"),"</b><p>\n";
&ui_print_footer("forward_vm.cgi?vm=$VM&user=$USER", $text{'PORTFORWARD_VM'});
webmin_log("Export (local file)","NATRules","'$VM' ($USER)",\%in);
}
}
}
else
{
&ui_print_header(undef, $text{'EXPORT_VMEXTRATITLE'}." '$VM'", "");
print &ui_form_start("vmextra_export.cgi","post");
print &ui_table_start($text{'TABHEADER_EXTRAEXPORT'}, undef, 2);
print ui_hidden("export",1);
print ui_hidden("vm",$VM);
print ui_hidden("user",$USER);
my @ROW;
#push(@ROW, [ 0, $text{'EXPORT_VMEXTRALOCALFILE'},&ui_textbox("file", undef, 40) ]);
push(@ROW, [ 0, $text{'EXPORT_VMEXTRALOCALFILE'},&ui_filebox("file", "/", 40,0,50,"file",1) ]);
#print "<tr><td>".&ui_radio("to", 0,\@RADIO)."</td><td>".&ui_filebox("file_tgz", "/", 40,0,50,"file_tgz",1)."</td></tr>";
push(@ROW, [ 1, $text{'EXPORT_VMEXTRAFILE'}," "]);
print &ui_table_row($text{'EXPORT_VMEXTRASOURCE'},&ui_radio_table("source", 1,\@ROW));
print &ui_table_end();
print &ui_form_end([ [ "ok", $text{'EXPORT_VMEXTRAOK'} ] ]);
&ui_print_footer("forward_vm.cgi?vm=$VM&user=$USER", $text{'PORTFORWARD_VM'});
}