]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/upnp.cgi
makegraphs umgebaut, sodass nurnoch rrd daten geschrieben werden die graphen
[people/pmueller/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 26
f2fdd0c1
CS
27my %color = ();
28my %mainsettings = ();
29&General::readhash("${General::swroot}/main/settings", \%mainsettings);
30&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
31
97de2cae 32&Header::showhttpheaders();
2abc4aad
MT
33############################################################################################################################
34############################################### Setzen von Standartwerten ##################################################
35
36$upnpsettings{'DEBUGMODE'} = '3';
37$upnpsettings{'FORWARDRULES'} = 'yes';
5a3e0dca
MT
38$upnpsettings{'DOWNSTREAM'} = '1048576';
39$upnpsettings{'UPSTREAM'} = '131072';
2abc4aad
MT
40$upnpsettings{'DESCRIPTION'} = 'gatedesc.xml';
41$upnpsettings{'XML'} = '/etc/linuxigd';
97de2cae 42$upnpsettings{'ENABLED'} = 'off';
5a3e0dca 43$upnpsettings{'friendlyName'} = 'IPFire Gateway';
97de2cae
MT
44### Values that have to be initialized
45$upnpsettings{'ACTION'} = '';
46
47&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
7654ad59 48&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
97de2cae
MT
49&Header::getcgihash(\%upnpsettings);
50
51&Header::openpage('UPnP', 1, '');
52&Header::openbigbox('100%', 'left', '', $errormessage);
53
54############################################################################################################################
2abc4aad 55################################################### Speichern der Config ###################################################
97de2cae
MT
56
57if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'})
7654ad59 58 {
5a3e0dca
MT
59 $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024;
60 $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024;
7654ad59 61 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
2abc4aad 62
5fd30232
MT
63 open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!";
64 flock (FILE, 2);
7654ad59
CS
65
66 print FILE <<END
2abc4aad
MT
67
68# UPnP Config by Ipfire Project
69
70debug_mode = $upnpsettings{'DEBUGMODE'}
71insert_forward_rules = $upnpsettings{'FORWARDRULES'}
7654ad59
CS
72forward_chain_name = FORWARD
73prerouting_chain_name = PORTFW
2abc4aad
MT
74upstream_bitrate = $upnpsettings{'DOWNSTREAM'}
75downstream_bitrate = $upnpsettings{'UPSTREAM'}
76description_document_name = $upnpsettings{'DESCRIPTION'}
77xml_document_path = $upnpsettings{'XML'}
78
79END
80;
7654ad59
CS
81 close FILE;
82 system("/usr/local/bin/upnpctrl upnpxml $upnpsettings{'XML'} $upnpsettings{'DESCRIPTION'} $upnpsettings{'manufacturer'}");
83 }
97de2cae 84elsif ($upnpsettings{'ACTION'} eq 'Start')
7654ad59
CS
85 {
86 $upnpsettings{'ENABLED'} = 'on';
87 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
88 system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
89 }
97de2cae 90elsif ($upnpsettings{'ACTION'} eq 'Stop')
7654ad59
CS
91 {
92 $upnpsettings{'ENABLED'} = 'off';
93 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
94 system("/usr/local/bin/upnpctrl stop");
95 }
97de2cae 96elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'})
7654ad59
CS
97 {
98 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
99 system("/usr/local/bin/upnpctrl stop");
100 system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
101 }
97de2cae
MT
102
103&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
5a3e0dca
MT
104$upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024;
105$upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024;
97de2cae 106
7654ad59
CS
107if ($errormessage)
108 {
109 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
110 print "<class name='base'>$errormessage\n";
111 print "&nbsp;</class>\n";
112 &Header::closebox();
113 }
97de2cae
MT
114
115############################################################################################################################
116############################################################################################################################
117
118&Header::openbox('100%', 'center', 'UPnP');
119print <<END
7654ad59
CS
120<form method='post' action='$ENV{'SCRIPT_NAME'}'>
121<table width='95%' cellspacing='0'>
97de2cae
MT
122END
123;
7654ad59
CS
124if ( $message ne "" ) {print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";}
125
126my $lines = 0;
127my $key = '';
128foreach $key (sort keys %servicenames)
129{
f2fdd0c1 130 print "<tr><td align='left'>$key\n";
7654ad59
CS
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'>
f2fdd0c1 147<tr><td colspan='2' align='left' bgcolor='$color{'color20'}'><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 }