]>
Commit | Line | Data |
---|---|---|
97de2cae | 1 | #!/usr/bin/perl |
70df8302 MT |
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 | ############################################################################### | |
97de2cae MT |
21 | |
22 | use strict; | |
23 | # enable only the following on debugging purpose | |
cb5e9c6c CS |
24 | #use warnings; |
25 | #use CGI::Carp 'fatalsToBrowser'; | |
97de2cae MT |
26 | |
27 | require '/var/ipfire/general-functions.pl'; | |
28 | require "${General::swroot}/lang.pl"; | |
29 | require "${General::swroot}/header.pl"; | |
30 | ||
31 | my %upnpsettings = (); | |
97de2cae MT |
32 | my %netsettings = (); |
33 | my $message = ""; | |
34 | my $errormessage = ""; | |
35 | my %selected= () ; | |
97de2cae | 36 | |
7654ad59 | 37 | my %servicenames =('UPnP Daemon' => 'upnpd',); |
97de2cae | 38 | |
f2fdd0c1 CS |
39 | my %color = (); |
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); | |
43 | ||
97de2cae | 44 | &Header::showhttpheaders(); |
2abc4aad MT |
45 | ############################################################################################################################ |
46 | ############################################### Setzen von Standartwerten ################################################## | |
47 | ||
48 | $upnpsettings{'DEBUGMODE'} = '3'; | |
49 | $upnpsettings{'FORWARDRULES'} = 'yes'; | |
5a3e0dca MT |
50 | $upnpsettings{'DOWNSTREAM'} = '1048576'; |
51 | $upnpsettings{'UPSTREAM'} = '131072'; | |
2abc4aad MT |
52 | $upnpsettings{'DESCRIPTION'} = 'gatedesc.xml'; |
53 | $upnpsettings{'XML'} = '/etc/linuxigd'; | |
97de2cae | 54 | $upnpsettings{'ENABLED'} = 'off'; |
5a3e0dca | 55 | $upnpsettings{'friendlyName'} = 'IPFire Gateway'; |
97de2cae MT |
56 | ### Values that have to be initialized |
57 | $upnpsettings{'ACTION'} = ''; | |
58 | ||
59 | &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings); | |
7654ad59 | 60 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
97de2cae MT |
61 | &Header::getcgihash(\%upnpsettings); |
62 | ||
63 | &Header::openpage('UPnP', 1, ''); | |
64 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
65 | ||
66 | ############################################################################################################################ | |
2abc4aad | 67 | ################################################### Speichern der Config ################################################### |
97de2cae MT |
68 | |
69 | if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'}) | |
7654ad59 | 70 | { |
5a3e0dca MT |
71 | $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024; |
72 | $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024; | |
7654ad59 | 73 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); |
2abc4aad | 74 | |
5fd30232 MT |
75 | open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!"; |
76 | flock (FILE, 2); | |
7654ad59 CS |
77 | |
78 | print FILE <<END | |
2abc4aad MT |
79 | |
80 | # UPnP Config by Ipfire Project | |
81 | ||
82 | debug_mode = $upnpsettings{'DEBUGMODE'} | |
83 | insert_forward_rules = $upnpsettings{'FORWARDRULES'} | |
7654ad59 | 84 | forward_chain_name = FORWARD |
0ac6c61d | 85 | prerouting_chain_name = UPNPFW |
2abc4aad MT |
86 | upstream_bitrate = $upnpsettings{'DOWNSTREAM'} |
87 | downstream_bitrate = $upnpsettings{'UPSTREAM'} | |
88 | description_document_name = $upnpsettings{'DESCRIPTION'} | |
89 | xml_document_path = $upnpsettings{'XML'} | |
90 | ||
91 | END | |
92 | ; | |
7654ad59 | 93 | close FILE; |
13211b21 | 94 | system("/usr/local/bin/upnpctrl","upnpxml","$upnpsettings{'friendlyName'}","$upnpsettings{'XML'}","$upnpsettings{'DESCRIPTION'}"); |
7654ad59 | 95 | } |
97de2cae | 96 | elsif ($upnpsettings{'ACTION'} eq 'Start') |
7654ad59 CS |
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 | } | |
97de2cae | 102 | elsif ($upnpsettings{'ACTION'} eq 'Stop') |
7654ad59 CS |
103 | { |
104 | $upnpsettings{'ENABLED'} = 'off'; | |
105 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); | |
106 | system("/usr/local/bin/upnpctrl stop"); | |
107 | } | |
97de2cae | 108 | elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'}) |
7654ad59 CS |
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 | } | |
97de2cae MT |
114 | |
115 | &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings); | |
5a3e0dca MT |
116 | $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024; |
117 | $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024; | |
97de2cae | 118 | |
7654ad59 CS |
119 | if ($errormessage) |
120 | { | |
121 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
122 | print "<class name='base'>$errormessage\n"; | |
123 | print " </class>\n"; | |
124 | &Header::closebox(); | |
125 | } | |
97de2cae MT |
126 | |
127 | ############################################################################################################################ | |
128 | ############################################################################################################################ | |
129 | ||
130 | &Header::openbox('100%', 'center', 'UPnP'); | |
131 | print <<END | |
7654ad59 CS |
132 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
133 | <table width='95%' cellspacing='0'> | |
97de2cae MT |
134 | END |
135 | ; | |
8b40eca5 | 136 | if ( $message ne "" ) {print "<tr><td colspan='3' style='text-align:center; color:red;'>$message</td></tr>";} |
7654ad59 CS |
137 | |
138 | my $lines = 0; | |
139 | my $key = ''; | |
140 | foreach $key (sort keys %servicenames) | |
141 | { | |
f2fdd0c1 | 142 | print "<tr><td align='left'>$key\n"; |
7654ad59 CS |
143 | my $shortname = $servicenames{$key}; |
144 | my $status = &isrunning($shortname); | |
145 | print "$status\n"; | |
146 | $lines++; | |
147 | } | |
5fd30232 | 148 | |
5fd30232 | 149 | print <<END |
7654ad59 CS |
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> | |
5fd30232 | 155 | </form> |
7654ad59 | 156 | <br /> |
5fd30232 | 157 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
2abc4aad | 158 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 159 | <tr><td colspan='2' align='left' bgcolor='$color{'color20'}'><b>$Lang::tr{'options'}</b></td></tr> |
7654ad59 | 160 | <tr><td align='left' colspan='2'><br /></td></tr> |
5a3e0dca | 161 | <tr><td align='left'>UPnP Device Name:</td><td><input type='text' name='friendlyName' value='$upnpsettings{'friendlyName'}' size="30" /></td></tr> |
7654ad59 | 162 | <tr><td align='left' colspan='2'><br /></td></tr> |
5a3e0dca MT |
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'} /> | |
f8aa0679 | 167 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/floppy.gif' /></td></tr> |
2abc4aad | 168 | </table></form> |
97de2cae MT |
169 | END |
170 | ; | |
171 | &Header::closebox(); | |
172 | ||
5a3e0dca MT |
173 | &Header::openbox('100%', 'center', 'Aktuell geoeffnete Ports'); |
174 | my @output = qx(iptables -t nat -n -L PORTFW); | |
175 | my ($outputline, $extip, $extport, $int); | |
176 | my @output2; | |
177 | print "<table>"; | |
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]"; | |
185 | $int =~ s/to://; | |
186 | print "<tr><td>$extip:$extport<td align='center'><img src='/images/forward.gif' alt='=>' /><td>$int"; | |
187 | ||
188 | } | |
189 | } | |
190 | ||
191 | print "</table>"; | |
192 | ||
193 | &Header::closebox(); | |
194 | ||
97de2cae MT |
195 | &Header::closebigbox(); |
196 | &Header::closepage(); | |
197 | ||
198 | ############################################################################################################################ | |
199 | ############################################################################################################################ | |
200 | ||
201 | sub isrunning | |
8b40eca5 | 202 | { |
7654ad59 | 203 | my $cmd = $_[0]; |
8b40eca5 | 204 | my $status = "<td bgcolor='${Header::colourred}' style='text-align:center; color:white;'><b>$Lang::tr{'stopped'}</b></td>"; |
7654ad59 CS |
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/) | |
8b40eca5 | 222 | {$status = "<td style='color:white; background-color:${Header::colourgreen};'><b>$Lang::tr{'running'}</b></td>";} |
7654ad59 CS |
223 | } |
224 | } | |
225 | ||
226 | return $status; | |
8b40eca5 AH |
227 | } |
228 |