]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - html/cgi-bin/upnp.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
23 # enable only the following on debugging purpose
25 #use CGI::Carp 'fatalsToBrowser';
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
31 my %upnpsettings = ();
34 my $errormessage = "";
37 my %servicenames =('UPnP Daemon' => 'upnpd',);
40 my %mainsettings = ();
41 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
42 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
44 &Header
::showhttpheaders
();
45 ############################################################################################################################
46 ############################################### Setzen von Standartwerten ##################################################
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'} = '';
59 &General
::readhash
("${General::swroot}/upnp/settings", \
%upnpsettings);
60 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
61 &Header
::getcgihash
(\
%upnpsettings);
63 &Header
::openpage
('UPnP', 1, '');
64 &Header
::openbigbox
('100%', 'left', '', $errormessage);
66 ############################################################################################################################
67 ################################################### Speichern der Config ###################################################
69 if ($upnpsettings{'ACTION'} eq $Lang::tr
{'save'})
71 $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024;
72 $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024;
73 &General
::writehash
("${General::swroot}/upnp/settings", \
%upnpsettings);
75 open (FILE
, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!";
80 # UPnP Config by Ipfire Project
82 debug_mode = $upnpsettings{'DEBUGMODE'}
83 insert_forward_rules = $upnpsettings{'FORWARDRULES'}
84 forward_chain_name = FORWARD
85 prerouting_chain_name = UPNPFW
86 upstream_bitrate = $upnpsettings{'DOWNSTREAM'}
87 downstream_bitrate = $upnpsettings{'UPSTREAM'}
88 description_document_name = $upnpsettings{'DESCRIPTION'}
89 xml_document_path = $upnpsettings{'XML'}
94 system("/usr/local/bin/upnpctrl","upnpxml","$upnpsettings{'friendlyName'}","$upnpsettings{'XML'}","$upnpsettings{'DESCRIPTION'}");
96 elsif ($upnpsettings{'ACTION'} eq 'Start')
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'}");
102 elsif ($upnpsettings{'ACTION'} eq 'Stop')
104 $upnpsettings{'ENABLED'} = 'off';
105 &General
::writehash
("${General::swroot}/upnp/settings", \
%upnpsettings);
106 system("/usr/local/bin/upnpctrl stop");
108 elsif ($upnpsettings{'ACTION'} eq $Lang::tr
{'restart'})
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'}");
115 &General
::readhash
("${General::swroot}/upnp/settings", \
%upnpsettings);
116 $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024;
117 $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024;
121 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
122 print "<class name='base'>$errormessage\n";
123 print " </class>\n";
127 ############################################################################################################################
128 ############################################################################################################################
130 &Header
::openbox
('100%', 'center', 'UPnP');
132 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
133 <table width='95%' cellspacing='0'>
136 if ( $message ne "" ) {print "<tr><td colspan='3' style='text-align:center; color:red;'>$message</td></tr>";}
140 foreach $key (sort keys %servicenames)
142 print "<tr><td align='left'>$key\n";
143 my $shortname = $servicenames{$key};
144 my $status = &isrunning
($shortname);
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'}' />
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>
173 &Header
::openbox
('100%', 'center', 'Aktuell geoeffnete Ports');
174 my @output = qx(iptables
-t nat
-n
-L PORTFW
);
175 my ($outputline, $extip, $extport, $int);
178 foreach $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]";
186 print "<tr><td>$extip:$extport<td align='center'><img src='/images/forward.gif' alt='=>' /><td>$int";
195 &Header
::closebigbox
();
196 &Header
::closepage
();
198 ############################################################################################################################
199 ############################################################################################################################
204 my $status = "<td bgcolor='${Header::colourred}' style='text-align:center; color:white;'><b>$Lang::tr{'stopped'}</b></td>";
212 if (open(FILE
, "/var/run/${cmd}.pid"))
214 $pid = <FILE
>; chomp $pid;
216 if (open(FILE
, "/proc/${pid}/status"))
219 {if (/^Name:\W+(.*)/) {$testcmd = $1; }}
221 if ($testcmd =~ /$exename/)
222 {$status = "<td style='color:white; background-color:${Header::colourgreen};'><b>$Lang::tr{'running'}</b></td>";}