]>
Commit | Line | Data |
---|---|---|
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 | ||
10 | use strict; | |
11 | # enable only the following on debugging purpose | |
12 | use warnings; | |
13 | use CGI::Carp 'fatalsToBrowser'; | |
14 | ||
15 | require '/var/ipfire/general-functions.pl'; | |
16 | require "${General::swroot}/lang.pl"; | |
17 | require "${General::swroot}/header.pl"; | |
18 | ||
19 | my %upnpsettings = (); | |
20 | my %checked = (); | |
21 | my %netsettings = (); | |
22 | my $message = ""; | |
23 | my $errormessage = ""; | |
24 | my %selected= () ; | |
25 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
26 | ||
27 | my %servicenames = | |
28 | ( | |
5fd30232 | 29 | 'UPnP Daemon' => 'upnpd', |
97de2cae MT |
30 | ); |
31 | ||
32 | &Header::showhttpheaders(); | |
2abc4aad MT |
33 | ############################################################################################################################ |
34 | ############################################### Setzen von Standartwerten ################################################## | |
35 | ||
36 | $upnpsettings{'DEBUGMODE'} = '3'; | |
37 | $upnpsettings{'FORWARDRULES'} = 'yes'; | |
38 | $upnpsettings{'FORWARDCHAIN'} = 'FORWARD'; | |
39 | $upnpsettings{'PREROUTINGCHAIN'} = 'PORTFW'; | |
40 | $upnpsettings{'DOWNSTREAM'} = '900000'; | |
41 | $upnpsettings{'UPSTREAM'} = '16000000'; | |
42 | $upnpsettings{'DESCRIPTION'} = 'gatedesc.xml'; | |
43 | $upnpsettings{'XML'} = '/etc/linuxigd'; | |
97de2cae | 44 | $upnpsettings{'ENABLED'} = 'off'; |
5fd30232 MT |
45 | $upnpsettings{'GREENi'} = 'on'; |
46 | $upnpsettings{'BLUEi'} = 'off'; | |
47 | $upnpsettings{'REDi'} = 'off'; | |
48 | $upnpsettings{'ORANGEi'} = 'off'; | |
49 | $upnpsettings{'GREENe'} = 'off'; | |
50 | $upnpsettings{'BLUEe'} = 'off'; | |
51 | $upnpsettings{'REDe'} = 'on'; | |
52 | $upnpsettings{'ORANGEe'} = 'off'; | |
97de2cae MT |
53 | ### Values that have to be initialized |
54 | $upnpsettings{'ACTION'} = ''; | |
55 | ||
56 | &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings); | |
57 | &Header::getcgihash(\%upnpsettings); | |
58 | ||
59 | &Header::openpage('UPnP', 1, ''); | |
60 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
61 | ||
62 | ############################################################################################################################ | |
2abc4aad | 63 | ################################################### Speichern der Config ################################################### |
97de2cae MT |
64 | |
65 | if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'}) | |
66 | { | |
2abc4aad MT |
67 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); |
68 | ||
5fd30232 MT |
69 | open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!"; |
70 | flock (FILE, 2); | |
71 | ||
2abc4aad MT |
72 | print FILE <<END |
73 | ||
74 | # UPnP Config by Ipfire Project | |
75 | ||
76 | debug_mode = $upnpsettings{'DEBUGMODE'} | |
77 | insert_forward_rules = $upnpsettings{'FORWARDRULES'} | |
78 | forward_chain_name = $upnpsettings{'FORWARDCHAIN'} | |
79 | prerouting_chain_name = $upnpsettings{'PREROUTINGCHAIN'} | |
80 | upstream_bitrate = $upnpsettings{'DOWNSTREAM'} | |
81 | downstream_bitrate = $upnpsettings{'UPSTREAM'} | |
82 | description_document_name = $upnpsettings{'DESCRIPTION'} | |
83 | xml_document_path = $upnpsettings{'XML'} | |
84 | ||
85 | END | |
86 | ; | |
87 | close FILE; | |
88 | } | |
97de2cae MT |
89 | elsif ($upnpsettings{'ACTION'} eq 'Start') |
90 | { | |
5fd30232 MT |
91 | $upnpsettings{'ENABLED'} = 'on'; |
92 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); | |
406f019f | 93 | system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}"); |
5fd30232 | 94 | } |
97de2cae MT |
95 | elsif ($upnpsettings{'ACTION'} eq 'Stop') |
96 | { | |
5fd30232 MT |
97 | $upnpsettings{'ENABLED'} = 'off'; |
98 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); | |
406f019f | 99 | system("/usr/local/bin/upnpctrl stop"); |
5fd30232 | 100 | } |
97de2cae MT |
101 | elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'}) |
102 | { | |
5fd30232 | 103 | &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings); |
406f019f MT |
104 | system("/usr/local/bin/upnpctrl stop"); |
105 | system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}"); | |
97de2cae MT |
106 | } |
107 | ||
108 | &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings); | |
109 | ||
110 | if ($errormessage) { | |
5fd30232 MT |
111 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); |
112 | print "<class name='base'>$errormessage\n"; | |
113 | print " </class>\n"; | |
114 | &Header::closebox(); | |
97de2cae MT |
115 | } |
116 | ||
5fd30232 MT |
117 | $checked{'GREENi'}{'on'} = ''; |
118 | $checked{'GREENi'}{'off'} = ''; | |
119 | $checked{'GREENi'}{"$upnpsettings{'GREENi'}"} = 'checked'; | |
120 | $checked{'BLUEi'}{'on'} = ''; | |
121 | $checked{'BLUEi'}{'off'} = ''; | |
122 | $checked{'BLUEi'}{"$upnpsettings{'BLUEi'}"} = 'checked'; | |
123 | $checked{'REDi'}{'on'} = ''; | |
124 | $checked{'REDi'}{'off'} = ''; | |
125 | $checked{'REDi'}{"$upnpsettings{'REDi'}"} = 'checked'; | |
126 | $checked{'ORANGEi'}{'on'} = ''; | |
127 | $checked{'ORANGEi'}{'off'} = ''; | |
128 | $checked{'ORANGEi'}{"$upnpsettings{'ORANGEi'}"} = 'checked'; | |
129 | $checked{'GREENe'}{'on'} = ''; | |
130 | $checked{'GREENe'}{'off'} = ''; | |
131 | $checked{'GREENe'}{"$upnpsettings{'GREENe'}"} = 'checked'; | |
132 | $checked{'BLUEe'}{'on'} = ''; | |
133 | $checked{'BLUEe'}{'off'} = ''; | |
134 | $checked{'BLUEe'}{"$upnpsettings{'BLUEe'}"} = 'checked'; | |
135 | $checked{'REDe'}{'on'} = ''; | |
136 | $checked{'REDe'}{'off'} = ''; | |
137 | $checked{'REDe'}{"$upnpsettings{'REDe'}"} = 'checked'; | |
138 | $checked{'ORANGEe'}{'on'} = ''; | |
139 | $checked{'ORANGEe'}{'off'} = ''; | |
140 | $checked{'ORANGEe'}{"$upnpsettings{'ORANGEe'}"} = 'checked'; | |
97de2cae MT |
141 | |
142 | ############################################################################################################################ | |
143 | ############################################################################################################################ | |
144 | ||
145 | &Header::openbox('100%', 'center', 'UPnP'); | |
146 | print <<END | |
5fd30232 MT |
147 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
148 | <table width='95%' cellspacing='0'> | |
97de2cae MT |
149 | END |
150 | ; | |
5fd30232 MT |
151 | if ( $message ne "" ) { |
152 | print "<tr><td colspan='3' align='center'><font color='red'>$message</font>"; | |
153 | } | |
154 | ||
155 | my $lines = 0; | |
156 | my $key = ''; | |
157 | foreach $key (sort keys %servicenames) | |
158 | { | |
159 | if ($lines % 2) { | |
160 | print "<tr bgcolor='${Header::table1colour}'>\n"; } | |
161 | else { | |
162 | print "<tr bgcolor='${Header::table2colour}'>\n"; } | |
163 | print "<td align='left'>$key\n"; | |
164 | my $shortname = $servicenames{$key}; | |
165 | my $status = &isrunning($shortname); | |
166 | print "$status\n"; | |
167 | $lines++; | |
168 | } | |
2abc4aad | 169 | print <<END |
5fd30232 MT |
170 | <tr><td><b>Alle Dienste:</b></td><td colspan='2'> |
171 | <input type='submit' name='ACTION' value='Start' /> | |
172 | <input type='submit' name='ACTION' value='Stop' /> | |
173 | <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' /> | |
174 | </table> | |
97de2cae MT |
175 | END |
176 | ; | |
5fd30232 MT |
177 | #print <<END |
178 | # <br></br> | |
179 | # <hr /> | |
180 | # <br></br> | |
181 | # | |
182 | # <table width='95%'> | |
183 | # <tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>External Interface</b></td></tr> | |
184 | # <tr><td align='left'> </td><td><input type='radio' name='External' value='$netsettings{'RED_DEV'}' $checked{'REDe'}{'on'}><font size='2' color='$Header::colourred'><b>RED - $netsettings{'RED_DEV'}</b></font><br></br> | |
185 | # <input type='radio' name='External' value='$netsettings{'GREEN_DEV'}' $checked{'GREENe'}{'on'}><font size='2' color='$Header::colourgreen'><b>$Lang::tr{'green'} - $netsettings{'GREEN_DEV'}</b></font><br></br> | |
186 | #END | |
187 | #; | |
188 | # if (&Header::blue_used()){ | |
189 | # print <<END | |
190 | # <input type='radio' name='External' value='$netsettings{'BLUE_DEV'}' $checked{'BLUEe'}{'on'}><font size='2' color='$Header::colourblue'><b>$Lang::tr{'wireless'} - $netsettings{'BLUE_DEV'}</b></font><br></br> | |
191 | #END | |
192 | #; | |
193 | # } | |
194 | # if (&Header::orange_used()){ | |
195 | # print <<END | |
196 | # <input type='radio' name='External' value='$netsettings{'ORANGE_DEV'}' $checked{'ORANGEe'}{'on'}><font size='2' color='$Header::colourorange'><b>$Lang::tr{'dmz'} - $netsettings{'ORANGE_DEV'}</b></font><br></br> | |
197 | #END | |
198 | #; | |
199 | # } | |
200 | # print <<END | |
201 | # </td></tr> | |
202 | # <tr><td colspan='2' align='left'><br></br></td></tr> | |
203 | # <tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>Internal Interface</b></td></tr> | |
204 | # <tr><td align='left'> </td><td><input type='radio' name='Internal' value='$netsettings{'RED_DEV'}' $checked{'REDi'}{'on'}><font size='2' color='$Header::colourred'><b>RED - $netsettings{'RED_DEV'}</b></font><br></br> | |
205 | # <input type='radio' name='Internal' value='$netsettings{'GREEN_DEV'}' $checked{'GREENi'}{'on'}><font size='2' color='$Header::colourgreen'><b>$Lang::tr{'green'} - $netsettings{'GREEN_DEV'}</b></font><br></br> | |
206 | #END | |
207 | #; | |
208 | # if (&Header::blue_used()){ | |
209 | # print <<END | |
210 | # <input type='radio' name='Internal' value='$netsettings{'BLUE_DEV'}' $checked{'BLUEi'}{'on'}><font size='2' color='$Header::colourblue'><b>$Lang::tr{'wireless'} - $netsettings{'BLUE_DEV'}</b></font><br></br> | |
211 | #END | |
212 | #; | |
213 | # } | |
214 | # if (&Header::orange_used()){ | |
215 | # print <<END | |
216 | # <input type='radio' name='Internal' value='$netsettings{'ORANGE_DEV'}' $checked{'ORANGEi'}{'on'}><font size='2' color='$Header::colourorange'><b>$Lang::tr{'dmz'} - $netsettings{'ORANGE_DEV'}</b></font><br></br> | |
217 | #END | |
218 | #; | |
219 | # } | |
220 | # print <<END | |
221 | # </td></tr></table> | |
222 | print <<END | |
223 | </form> | |
224 | <br></br> | |
225 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
2abc4aad | 226 | <table width='95%' cellspacing='0'> |
5fd30232 MT |
227 | <tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>$Lang::tr{'options'}</b></td></tr> |
228 | <tr><td colspan='2' align='left'><br></br></td></tr> | |
2abc4aad MT |
229 | <tr><td align='left'>Debug Mode:</td><td><input type='text' name='DEBUGMODE' value='$upnpsettings{'DEBUGMODE'}' size="30"></input></td></tr> |
230 | <tr><td align='left'>Forward Rules:</td><td><input type='text' name='FORWARDRULES' value='$upnpsettings{'FORWARDRULES'}' size="30"></input></td></tr> | |
231 | <tr><td align='left'>Forward Chain:</td><td><input type='text' name='FORWARDCHAIN' value='$upnpsettings{'FORWARDCHAIN'}' size="30"></input></td></tr> | |
232 | <tr><td align='left'>Prerouting Chain:</td><td><input type='text' name='PREROUTINGCHAIN' value='$upnpsettings{'PREROUTINGCHAIN'}' size="30"></input></td></tr> | |
233 | <tr><td align='left'>Down Stream:</td><td><input type='text' name='DOWNSTREAM' value='$upnpsettings{'DOWNSTREAM'}' size="30"></input></td></tr> | |
234 | <tr><td align='left'>Up Strean:</td><td><input type='text' name='UPSTREAM' value='$upnpsettings{'UPSTREAM'}' size="30"></input></td></tr> | |
235 | <tr><td align='left'>Description Document:</td><td><input type='text' name='DESCRIPTION' value='$upnpsettings{'DESCRIPTION'}' size="30"></input></td></tr> | |
236 | <tr><td align='left'>XML Document:</td><td><input type='text' name='XML' value='$upnpsettings{'XML'}' size="30"></input></td></tr> | |
5fd30232 | 237 | <tr><td colspan='2' align='left'><br></br></td></tr> |
2abc4aad MT |
238 | <tr><td colspan='2' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} /> |
239 | </table></form> | |
240 | <br></br> | |
241 | <hr></hr> | |
97de2cae MT |
242 | END |
243 | ; | |
244 | &Header::closebox(); | |
245 | ||
246 | &Header::closebigbox(); | |
247 | &Header::closepage(); | |
248 | ||
249 | ############################################################################################################################ | |
250 | ############################################################################################################################ | |
251 | ||
252 | sub isrunning | |
253 | { | |
5fd30232 MT |
254 | my $cmd = $_[0]; |
255 | my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
256 | my $pid = ''; | |
257 | my $testcmd = ''; | |
258 | my $exename; | |
259 | ||
260 | $cmd =~ /(^[a-z]+)/; | |
261 | $exename = $1; | |
262 | ||
263 | if (open(FILE, "/var/run/${cmd}.pid")) | |
264 | { | |
265 | $pid = <FILE>; chomp $pid; | |
266 | close FILE; | |
267 | if (open(FILE, "/proc/${pid}/status")) | |
268 | { | |
269 | while (<FILE>) | |
270 | { | |
271 | if (/^Name:\W+(.*)/) { | |
272 | $testcmd = $1; } | |
273 | } | |
274 | close FILE; | |
275 | if ($testcmd =~ /$exename/) | |
276 | { | |
277 | $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
278 | } | |
279 | } | |
280 | } | |
281 | ||
282 | return $status; | |
406f019f | 283 | } |