]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame_incremental - html/cgi-bin/upnp.cgi
cgi-bin: Remove font tags with no effect, and style tags
[people/teissler/ipfire-2.x.git] / html / cgi-bin / upnp.cgi
... / ...
CommitLineData
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22use strict;
23# enable only the following on debugging purpose
24#use warnings;
25#use CGI::Carp 'fatalsToBrowser';
26
27require '/var/ipfire/general-functions.pl';
28require "${General::swroot}/lang.pl";
29require "${General::swroot}/header.pl";
30
31my %upnpsettings = ();
32my %netsettings = ();
33my $message = "";
34my $errormessage = "";
35my %selected= () ;
36
37my %servicenames =('UPnP Daemon' => 'upnpd',);
38
39my %color = ();
40my %mainsettings = ();
41&General::readhash("${General::swroot}/main/settings", \%mainsettings);
42&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
43
44&Header::showhttpheaders();
45############################################################################################################################
46############################################### Setzen von Standartwerten ##################################################
47
48$upnpsettings{'DEBUGMODE'} = '3';
49$upnpsettings{'FORWARDRULES'} = 'yes';
50$upnpsettings{'DOWNSTREAM'} = '1048576';
51$upnpsettings{'UPSTREAM'} = '131072';
52$upnpsettings{'DESCRIPTION'} = 'gatedesc.xml';
53$upnpsettings{'XML'} = '/etc/linuxigd';
54$upnpsettings{'ENABLED'} = 'off';
55$upnpsettings{'friendlyName'} = 'IPFire Gateway';
56### Values that have to be initialized
57$upnpsettings{'ACTION'} = '';
58
59&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
60&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
61&Header::getcgihash(\%upnpsettings);
62
63&Header::openpage('UPnP', 1, '');
64&Header::openbigbox('100%', 'left', '', $errormessage);
65
66############################################################################################################################
67################################################### Speichern der Config ###################################################
68
69if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'})
70 {
71 $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024;
72 $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024;
73 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
74
75 open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!";
76 flock (FILE, 2);
77
78 print FILE <<END
79
80# UPnP Config by Ipfire Project
81
82debug_mode = $upnpsettings{'DEBUGMODE'}
83insert_forward_rules = $upnpsettings{'FORWARDRULES'}
84forward_chain_name = FORWARD
85prerouting_chain_name = UPNPFW
86upstream_bitrate = $upnpsettings{'DOWNSTREAM'}
87downstream_bitrate = $upnpsettings{'UPSTREAM'}
88description_document_name = $upnpsettings{'DESCRIPTION'}
89xml_document_path = $upnpsettings{'XML'}
90
91END
92;
93 close FILE;
94 system("/usr/local/bin/upnpctrl","upnpxml","$upnpsettings{'friendlyName'}","$upnpsettings{'XML'}","$upnpsettings{'DESCRIPTION'}");
95 }
96elsif ($upnpsettings{'ACTION'} eq 'Start')
97 {
98 $upnpsettings{'ENABLED'} = 'on';
99 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
100 system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
101 }
102elsif ($upnpsettings{'ACTION'} eq 'Stop')
103 {
104 $upnpsettings{'ENABLED'} = 'off';
105 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
106 system("/usr/local/bin/upnpctrl stop");
107 }
108elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'})
109 {
110 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
111 system("/usr/local/bin/upnpctrl stop");
112 system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
113 }
114
115&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
116$upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024;
117$upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024;
118
119if ($errormessage)
120 {
121 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
122 print "<class name='base'>$errormessage\n";
123 print "&nbsp;</class>\n";
124 &Header::closebox();
125 }
126
127############################################################################################################################
128############################################################################################################################
129
130&Header::openbox('100%', 'center', 'UPnP');
131print <<END
132<form method='post' action='$ENV{'SCRIPT_NAME'}'>
133<table width='95%' cellspacing='0'>
134END
135;
136if ( $message ne "" ) {print "<tr><td colspan='3' style='text-align:center; color:red;'>$message</td></tr>";}
137
138my $lines = 0;
139my $key = '';
140foreach $key (sort keys %servicenames)
141{
142 print "<tr><td align='left'>$key\n";
143 my $shortname = $servicenames{$key};
144 my $status = &isrunning($shortname);
145 print "$status\n";
146 $lines++;
147}
148
149print <<END
150<tr><td align='left'>Alle Dienste:</td><td align='center' colspan='2'>
151<input type='submit' name='ACTION' value='Start' />
152<input type='submit' name='ACTION' value='Stop' />
153<input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
154</table>
155</form>
156<br />
157<form method='post' action='$ENV{'SCRIPT_NAME'}'>
158<table width='95%' cellspacing='0'>
159<tr><td colspan='2' align='left' bgcolor='$color{'color20'}'><b>$Lang::tr{'options'}</b></td></tr>
160<tr><td align='left' colspan='2'><br /></td></tr>
161<tr><td align='left'>UPnP Device Name:</td><td><input type='text' name='friendlyName' value='$upnpsettings{'friendlyName'}' size="30" /></td></tr>
162<tr><td align='left' colspan='2'><br /></td></tr>
163<tr><td align='left'>Downstream in KB:</td><td><input type='text' name='DOWNSTREAM' value='$upnpsettings{'DOWNSTREAM'}' size="30" /></td></tr>
164<tr><td align='left'>Upstream in KB:</td><td><input type='text' name='UPSTREAM' value='$upnpsettings{'UPSTREAM'}' size="30" /></td></tr>
165<tr><td align='left' colspan='2'><br /></td></tr>
166<tr><td colspan='2' align='center'> <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
167<input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/floppy.gif' /></td></tr>
168</table></form>
169END
170;
171&Header::closebox();
172
173&Header::openbox('100%', 'center', 'Aktuell geoeffnete Ports');
174my @output = qx(iptables -t nat -n -L PORTFW);
175my ($outputline, $extip, $extport, $int);
176my @output2;
177print "<table>";
178foreach $outputline (@output) {
179 if ( $outputline =~ /^DNAT/ ) {
180 @output2 = split(/ /, $outputline);
181 $extip = $output2[23];
182 $extport = $output2[29];
183 $extport =~ s/dpt://;
184 $int = "$output2[31]";
185 $int =~ s/to://;
186 print "<tr><td>$extip:$extport<td align='center'><img src='/images/forward.gif' alt='=&gt;' /><td>$int";
187
188 }
189}
190
191print "</table>";
192
193&Header::closebox();
194
195&Header::closebigbox();
196&Header::closepage();
197
198############################################################################################################################
199############################################################################################################################
200
201sub isrunning
202{
203 my $cmd = $_[0];
204 my $status = "<td bgcolor='${Header::colourred}' style='text-align:center; color:white;'><b>$Lang::tr{'stopped'}</b></td>";
205 my $pid = '';
206 my $testcmd = '';
207 my $exename;
208
209 $cmd =~ /(^[a-z]+)/;
210 $exename = $1;
211
212 if (open(FILE, "/var/run/${cmd}.pid"))
213 {
214 $pid = <FILE>; chomp $pid;
215 close FILE;
216 if (open(FILE, "/proc/${pid}/status"))
217 {
218 while (<FILE>)
219 {if (/^Name:\W+(.*)/) {$testcmd = $1; }}
220 close FILE;
221 if ($testcmd =~ /$exename/)
222 {$status = "<td style='color:white; background-color:${Header::colourgreen};'><b>$Lang::tr{'running'}</b></td>";}
223 }
224 }
225
226 return $status;
227}
228