]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/upnp.cgi
neues Theme hinzugefuegt, geloeschtes icons wieder hinzugefuegt
[people/teissler/ipfire-2.x.git] / html / cgi-bin / upnp.cgi
CommitLineData
97de2cae
MT
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8#
9
10use strict;
11# enable only the following on debugging purpose
12use warnings;
13use CGI::Carp 'fatalsToBrowser';
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %upnpsettings = ();
97de2cae
MT
20my %netsettings = ();
21my $message = "";
22my $errormessage = "";
23my %selected= () ;
97de2cae 24
7654ad59 25my %servicenames =('UPnP Daemon' => 'upnpd',);
97de2cae
MT
26
27&Header::showhttpheaders();
2abc4aad
MT
28############################################################################################################################
29############################################### Setzen von Standartwerten ##################################################
30
31$upnpsettings{'DEBUGMODE'} = '3';
32$upnpsettings{'FORWARDRULES'} = 'yes';
5a3e0dca
MT
33$upnpsettings{'DOWNSTREAM'} = '1048576';
34$upnpsettings{'UPSTREAM'} = '131072';
2abc4aad
MT
35$upnpsettings{'DESCRIPTION'} = 'gatedesc.xml';
36$upnpsettings{'XML'} = '/etc/linuxigd';
97de2cae 37$upnpsettings{'ENABLED'} = 'off';
5a3e0dca 38$upnpsettings{'friendlyName'} = 'IPFire Gateway';
97de2cae
MT
39### Values that have to be initialized
40$upnpsettings{'ACTION'} = '';
41
42&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
7654ad59 43&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
97de2cae
MT
44&Header::getcgihash(\%upnpsettings);
45
46&Header::openpage('UPnP', 1, '');
47&Header::openbigbox('100%', 'left', '', $errormessage);
48
49############################################################################################################################
2abc4aad 50################################################### Speichern der Config ###################################################
97de2cae
MT
51
52if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'})
7654ad59 53 {
5a3e0dca
MT
54 $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024;
55 $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024;
7654ad59 56 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
2abc4aad 57
5fd30232
MT
58 open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!";
59 flock (FILE, 2);
7654ad59
CS
60
61 print FILE <<END
2abc4aad
MT
62
63# UPnP Config by Ipfire Project
64
65debug_mode = $upnpsettings{'DEBUGMODE'}
66insert_forward_rules = $upnpsettings{'FORWARDRULES'}
7654ad59
CS
67forward_chain_name = FORWARD
68prerouting_chain_name = PORTFW
2abc4aad
MT
69upstream_bitrate = $upnpsettings{'DOWNSTREAM'}
70downstream_bitrate = $upnpsettings{'UPSTREAM'}
71description_document_name = $upnpsettings{'DESCRIPTION'}
72xml_document_path = $upnpsettings{'XML'}
73
74END
75;
7654ad59
CS
76 close FILE;
77 system("/usr/local/bin/upnpctrl upnpxml $upnpsettings{'XML'} $upnpsettings{'DESCRIPTION'} $upnpsettings{'manufacturer'}");
78 }
97de2cae 79elsif ($upnpsettings{'ACTION'} eq 'Start')
7654ad59
CS
80 {
81 $upnpsettings{'ENABLED'} = 'on';
82 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
83 system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
84 }
97de2cae 85elsif ($upnpsettings{'ACTION'} eq 'Stop')
7654ad59
CS
86 {
87 $upnpsettings{'ENABLED'} = 'off';
88 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
89 system("/usr/local/bin/upnpctrl stop");
90 }
97de2cae 91elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'})
7654ad59
CS
92 {
93 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
94 system("/usr/local/bin/upnpctrl stop");
95 system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
96 }
97de2cae
MT
97
98&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
5a3e0dca
MT
99$upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024;
100$upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024;
97de2cae 101
7654ad59
CS
102if ($errormessage)
103 {
104 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
105 print "<class name='base'>$errormessage\n";
106 print "&nbsp;</class>\n";
107 &Header::closebox();
108 }
97de2cae
MT
109
110############################################################################################################################
111############################################################################################################################
112
113&Header::openbox('100%', 'center', 'UPnP');
114print <<END
7654ad59
CS
115<form method='post' action='$ENV{'SCRIPT_NAME'}'>
116<table width='95%' cellspacing='0'>
97de2cae
MT
117END
118;
7654ad59
CS
119if ( $message ne "" ) {print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";}
120
121my $lines = 0;
122my $key = '';
123foreach $key (sort keys %servicenames)
124{
125 if ($lines % 2)
126 {print "<tr bgcolor='${Header::table1colour}'>\n";}
127 else
128 {print "<tr bgcolor='${Header::table2colour}'>\n"; }
129
130 print "<td align='left'>$key\n";
131 my $shortname = $servicenames{$key};
132 my $status = &isrunning($shortname);
133 print "$status\n";
134 $lines++;
135}
5fd30232 136
5fd30232 137print <<END
7654ad59
CS
138<tr><td align='left'>Alle Dienste:</td><td align='center' colspan='2'>
139<input type='submit' name='ACTION' value='Start' />
140<input type='submit' name='ACTION' value='Stop' />
141<input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
142</table>
5fd30232 143</form>
7654ad59 144<br />
5fd30232 145<form method='post' action='$ENV{'SCRIPT_NAME'}'>
2abc4aad 146<table width='95%' cellspacing='0'>
5fd30232 147<tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>$Lang::tr{'options'}</b></td></tr>
7654ad59 148<tr><td align='left' colspan='2'><br /></td></tr>
5a3e0dca 149<tr><td align='left'>UPnP Device Name:</td><td><input type='text' name='friendlyName' value='$upnpsettings{'friendlyName'}' size="30" /></td></tr>
7654ad59 150<tr><td align='left' colspan='2'><br /></td></tr>
5a3e0dca
MT
151<tr><td align='left'>Downstream in KB:</td><td><input type='text' name='DOWNSTREAM' value='$upnpsettings{'DOWNSTREAM'}' size="30" /></td></tr>
152<tr><td align='left'>Upstream in KB:</td><td><input type='text' name='UPSTREAM' value='$upnpsettings{'UPSTREAM'}' size="30" /></td></tr>
153<tr><td align='left' colspan='2'><br /></td></tr>
154<tr><td colspan='2' align='center'> <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
fa7be659 155 <input type='image' alt=$Lang::tr{'save'} src='/images/floppy.gif' /></td></tr>
2abc4aad 156</table></form>
97de2cae
MT
157END
158;
159&Header::closebox();
160
5a3e0dca
MT
161&Header::openbox('100%', 'center', 'Aktuell geoeffnete Ports');
162my @output = qx(iptables -t nat -n -L PORTFW);
163my ($outputline, $extip, $extport, $int);
164my @output2;
165print "<table>";
166foreach $outputline (@output) {
167 if ( $outputline =~ /^DNAT/ ) {
168 @output2 = split(/ /, $outputline);
169 $extip = $output2[23];
170 $extport = $output2[29];
171 $extport =~ s/dpt://;
172 $int = "$output2[31]";
173 $int =~ s/to://;
174 print "<tr><td>$extip:$extport<td align='center'><img src='/images/forward.gif' alt='=&gt;' /><td>$int";
175
176 }
177}
178
179print "</table>";
180
181&Header::closebox();
182
97de2cae
MT
183&Header::closebigbox();
184&Header::closepage();
185
186############################################################################################################################
187############################################################################################################################
188
189sub isrunning
7654ad59
CS
190 {
191 my $cmd = $_[0];
fa7be659 192 my $status = "<td bgcolor='${Header::colourred}' align='center'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
7654ad59
CS
193 my $pid = '';
194 my $testcmd = '';
195 my $exename;
196
197 $cmd =~ /(^[a-z]+)/;
198 $exename = $1;
199
200 if (open(FILE, "/var/run/${cmd}.pid"))
201 {
202 $pid = <FILE>; chomp $pid;
203 close FILE;
204 if (open(FILE, "/proc/${pid}/status"))
205 {
206 while (<FILE>)
207 {if (/^Name:\W+(.*)/) {$testcmd = $1; }}
208 close FILE;
209 if ($testcmd =~ /$exename/)
210 {$status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";}
211 }
212 }
213
214 return $status;
5a3e0dca 215 }