]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/upnp.cgi
Add pound to make.sh.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / upnp.cgi
index 3970cc8d927075d4dd48e24be7e3f5f89ce642c0..8d2666ec75be4292aac4611dbf5efe8becf2438e 100644 (file)
@@ -1,33 +1,45 @@
 #!/usr/bin/perl
-#
-# IPFire CGIs
-#
-# This code is distributed under the terms of the GPL
-#
-# (c) The IPFire Team
-#
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 use strict;
 # enable only the following on debugging purpose
-use warnings;
-use CGI::Carp 'fatalsToBrowser';
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
 my %upnpsettings = ();
-my %checked = ();
 my %netsettings = ();
 my $message = "";
 my $errormessage = "";
 my %selected= () ;
-&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 
-my %servicenames =
-(
-        'UPnP Daemon' => 'upnpd',
-);
+my %servicenames =('UPnP Daemon' => 'upnpd',);
+
+my %color = ();
+my %mainsettings = ();
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
 
 &Header::showhttpheaders();
 ############################################################################################################################
@@ -35,25 +47,17 @@ my %servicenames =
 
 $upnpsettings{'DEBUGMODE'} = '3';
 $upnpsettings{'FORWARDRULES'} = 'yes';
-$upnpsettings{'FORWARDCHAIN'} = 'FORWARD';
-$upnpsettings{'PREROUTINGCHAIN'} = 'PORTFW';
-$upnpsettings{'DOWNSTREAM'} = '900000';
-$upnpsettings{'UPSTREAM'} = '16000000';
+$upnpsettings{'DOWNSTREAM'} = '1048576';
+$upnpsettings{'UPSTREAM'} = '131072';
 $upnpsettings{'DESCRIPTION'} = 'gatedesc.xml';
 $upnpsettings{'XML'} = '/etc/linuxigd';
 $upnpsettings{'ENABLED'} = 'off';
-$upnpsettings{'GREENi'} = 'on';
-$upnpsettings{'BLUEi'} = 'off';
-$upnpsettings{'REDi'} = 'off';
-$upnpsettings{'ORANGEi'} = 'off';
-$upnpsettings{'GREENe'} = 'off';
-$upnpsettings{'BLUEe'} = 'off';
-$upnpsettings{'REDe'} = 'on';
-$upnpsettings{'ORANGEe'} = 'off';
+$upnpsettings{'friendlyName'} = 'IPFire Gateway';
 ### Values that have to be initialized
 $upnpsettings{'ACTION'} = '';
 
 &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
+&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 &Header::getcgihash(\%upnpsettings);
 
 &Header::openpage('UPnP', 1, '');
@@ -63,20 +67,22 @@ $upnpsettings{'ACTION'} = '';
 ################################################### Speichern der Config ###################################################
 
 if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'})
-{
-&General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
+       {
+       $upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} * 1024;
+       $upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} * 1024;
+       &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
 
        open (FILE, ">${General::swroot}/upnp/upnpd.conf") or die "Can't save the upnp config: $!";
        flock (FILE, 2);
-       
-print FILE <<END
+
+       print FILE <<END
 
 # UPnP Config by Ipfire Project
 
 debug_mode = $upnpsettings{'DEBUGMODE'}
 insert_forward_rules = $upnpsettings{'FORWARDRULES'}
-forward_chain_name = $upnpsettings{'FORWARDCHAIN'}
-prerouting_chain_name = $upnpsettings{'PREROUTINGCHAIN'}
+forward_chain_name = FORWARD
+prerouting_chain_name = PORTFW
 upstream_bitrate = $upnpsettings{'DOWNSTREAM'}
 downstream_bitrate = $upnpsettings{'UPSTREAM'}
 description_document_name = $upnpsettings{'DESCRIPTION'}
@@ -84,165 +90,108 @@ xml_document_path = $upnpsettings{'XML'}
 
 END
 ;
-close FILE;
-}
+       close FILE;
+       system("/usr/local/bin/upnpctrl","upnpxml","$upnpsettings{'friendlyName'}","$upnpsettings{'XML'}","$upnpsettings{'DESCRIPTION'}");
+       }
 elsif ($upnpsettings{'ACTION'} eq 'Start')
-{
-        $upnpsettings{'ENABLED'} = 'on';
-        &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
-        system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
-} 
+       {
+       $upnpsettings{'ENABLED'} = 'on';
+       &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
+       system("/usr/local/bin/upnpctrl upnpdstart $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
+       
 elsif ($upnpsettings{'ACTION'} eq 'Stop')
-{
-        $upnpsettings{'ENABLED'} = 'off';
-        &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
-        system("/usr/local/bin/upnpctrl stop");
-} 
+       {
+       $upnpsettings{'ENABLED'} = 'off';
+       &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
+       system("/usr/local/bin/upnpctrl stop");
+       
 elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'})
-{
-        &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
-        system("/usr/local/bin/upnpctrl stop");
-        system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
-}
+       {
+       &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
+       system("/usr/local/bin/upnpctrl stop");
+       system("/usr/local/bin/upnpctrl start $netsettings{'RED_DEV'} $netsettings{'GREEN_DEV'}");
+       }
 
 &General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
+$upnpsettings{'DOWNSTREAM'} = $upnpsettings{'DOWNSTREAM'} / 1024;
+$upnpsettings{'UPSTREAM'} = $upnpsettings{'UPSTREAM'} / 1024;
 
-if ($errormessage) {
-        &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
-        print "<class name='base'>$errormessage\n";
-        print "&nbsp;</class>\n";
-        &Header::closebox();
-}
-
-$checked{'GREENi'}{'on'} = '';
-$checked{'GREENi'}{'off'} = '';
-$checked{'GREENi'}{"$upnpsettings{'GREENi'}"} = 'checked';
-$checked{'BLUEi'}{'on'} = '';
-$checked{'BLUEi'}{'off'} = '';
-$checked{'BLUEi'}{"$upnpsettings{'BLUEi'}"} = 'checked';
-$checked{'REDi'}{'on'} = '';
-$checked{'REDi'}{'off'} = '';
-$checked{'REDi'}{"$upnpsettings{'REDi'}"} = 'checked';
-$checked{'ORANGEi'}{'on'} = '';
-$checked{'ORANGEi'}{'off'} = '';
-$checked{'ORANGEi'}{"$upnpsettings{'ORANGEi'}"} = 'checked';
-$checked{'GREENe'}{'on'} = '';
-$checked{'GREENe'}{'off'} = '';
-$checked{'GREENe'}{"$upnpsettings{'GREENe'}"} = 'checked';
-$checked{'BLUEe'}{'on'} = '';
-$checked{'BLUEe'}{'off'} = '';
-$checked{'BLUEe'}{"$upnpsettings{'BLUEe'}"} = 'checked';
-$checked{'REDe'}{'on'} = '';
-$checked{'REDe'}{'off'} = '';
-$checked{'REDe'}{"$upnpsettings{'REDe'}"} = 'checked';
-$checked{'ORANGEe'}{'on'} = '';
-$checked{'ORANGEe'}{'off'} = '';
-$checked{'ORANGEe'}{"$upnpsettings{'ORANGEe'}"} = 'checked';
+if ($errormessage)
+       {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<class name='base'>$errormessage\n";
+       print "&nbsp;</class>\n";
+       &Header::closebox();
+       }
 
 ############################################################################################################################
 ############################################################################################################################
 
 &Header::openbox('100%', 'center', 'UPnP');
 print <<END
-        <form method='post' action='$ENV{'SCRIPT_NAME'}'>
-        <table width='95%' cellspacing='0'>
-END
-;
-        if ( $message ne "" ) {
-                print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
-        }
-
-        my $lines = 0;
-        my $key = '';
-        foreach $key (sort keys %servicenames)
-        {
-                if ($lines % 2) {
-                        print "<tr bgcolor='${Header::table1colour}'>\n"; }
-                else {
-                        print "<tr bgcolor='${Header::table2colour}'>\n"; }
-                print "<td align='left'>$key\n";
-                my $shortname = $servicenames{$key};
-                my $status = &isrunning($shortname);
-                print "$status\n";
-                $lines++;
-        }
-        print <<END
-                <tr><td><b>Alle Dienste:</b></td><td colspan='2'>
-                <input type='submit' name='ACTION' value='Start' /> 
-                <input type='submit' name='ACTION' value='Stop' /> 
-                <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
-        </table>
+<form method='post' action='$ENV{'SCRIPT_NAME'}'>
+<table width='95%' cellspacing='0'>
 END
 ;
-#print <<END
-#        <br></br>
-#        <hr />
-#        <br></br>
-#        
-#        <table width='95%'>
-#        <tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>External Interface</b></td></tr>
-#        <tr><td align='left'>&nbsp;</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>
-#                                            <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>
-#END
-#;
-#         if (&Header::blue_used()){
-#         print <<END
-#                                             <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>
-#END
-#;
-#                                    }
-#         if (&Header::orange_used()){
-#         print <<END
-#                                             <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>
-#END
-#;
-#                                    }
-#        print <<END
-#        </td></tr>
-#        <tr><td colspan='2' align='left'><br></br></td></tr>
-#        <tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>Internal Interface</b></td></tr>
-#        <tr><td align='left'>&nbsp;</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>
-#                                            <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>
-#END
-#;
-#         if (&Header::blue_used()){
-#         print <<END
-#                                            <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>
-#END
-#;
-#                                    }
-#         if (&Header::orange_used()){
-#         print <<END
-#                                            <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>
-#END
-#;
-#                                    }
-#        print <<END
-#        </td></tr></table>
+if ( $message ne "" ) {print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";}
+
+my $lines = 0;
+my $key = '';
+foreach $key (sort keys %servicenames)
+{
+  print "<tr><td align='left'>$key\n";
+       my $shortname = $servicenames{$key};
+       my $status = &isrunning($shortname);
+       print "$status\n";
+       $lines++;
+}
+
 print <<END
+<tr><td align='left'>Alle Dienste:</td><td align='center' colspan='2'>
+<input type='submit' name='ACTION' value='Start' /> 
+<input type='submit' name='ACTION' value='Stop' /> 
+<input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
+</table>
 </form>
-<br></br>
+<br />
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <table width='95%' cellspacing='0'>
-<tr><td colspan='2' align='left' bgcolor='${Header::table1colour}'><b>$Lang::tr{'options'}</b></td></tr>
-<tr><td colspan='2' align='left'><br></br></td></tr>
-<tr><td align='left'>Debug Mode:</td><td><input type='text' name='DEBUGMODE' value='$upnpsettings{'DEBUGMODE'}' size="30"></input></td></tr>
-<tr><td align='left'>Forward Rules:</td><td><input type='text' name='FORWARDRULES' value='$upnpsettings{'FORWARDRULES'}' size="30"></input></td></tr>
-<tr><td align='left'>Forward Chain:</td><td><input type='text' name='FORWARDCHAIN' value='$upnpsettings{'FORWARDCHAIN'}' size="30"></input></td></tr>
-<tr><td align='left'>Prerouting Chain:</td><td><input type='text' name='PREROUTINGCHAIN' value='$upnpsettings{'PREROUTINGCHAIN'}' size="30"></input></td></tr>
-<tr><td align='left'>Down Stream:</td><td><input type='text' name='DOWNSTREAM' value='$upnpsettings{'DOWNSTREAM'}' size="30"></input></td></tr>
-<tr><td align='left'>Up Strean:</td><td><input type='text' name='UPSTREAM' value='$upnpsettings{'UPSTREAM'}' size="30"></input></td></tr>
-<tr><td align='left'>Description Document:</td><td><input type='text' name='DESCRIPTION' value='$upnpsettings{'DESCRIPTION'}' size="30"></input></td></tr>
-<tr><td align='left'>XML Document:</td><td><input type='text' name='XML' value='$upnpsettings{'XML'}' size="30"></input></td></tr>
-<tr><td colspan='2' align='left'><br></br></td></tr>
-<tr><td colspan='2' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
+<tr><td colspan='2' align='left' bgcolor='$color{'color20'}'><b>$Lang::tr{'options'}</b></td></tr>
+<tr><td align='left' colspan='2'><br /></td></tr>
+<tr><td align='left'>UPnP Device Name:</td><td><input type='text' name='friendlyName' value='$upnpsettings{'friendlyName'}' size="30" /></td></tr>
+<tr><td align='left' colspan='2'><br /></td></tr>
+<tr><td align='left'>Downstream in KB:</td><td><input type='text' name='DOWNSTREAM' value='$upnpsettings{'DOWNSTREAM'}' size="30" /></td></tr>
+<tr><td align='left'>Upstream in KB:</td><td><input type='text' name='UPSTREAM' value='$upnpsettings{'UPSTREAM'}' size="30" /></td></tr>
+<tr><td align='left' colspan='2'><br /></td></tr>
+<tr><td colspan='2' align='center'>    <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
+                                                                                                                                               <input type='image' alt=$Lang::tr{'save'} src='/images/floppy.gif' /></td></tr>
 </table></form>
-<br></br>
-<hr></hr>
 END
 ;
 &Header::closebox();
 
+&Header::openbox('100%', 'center', 'Aktuell geoeffnete Ports');
+my @output = qx(iptables -t nat -n -L PORTFW);
+my ($outputline, $extip, $extport, $int);
+my @output2;
+print "<table>";
+foreach $outputline (@output) {
+       if ( $outputline =~ /^DNAT/ ) { 
+               @output2 = split(/ /, $outputline);
+               $extip = $output2[23];
+               $extport = $output2[29];
+               $extport =~ s/dpt://;
+               $int = "$output2[31]";
+               $int =~ s/to://;
+               print "<tr><td>$extip:$extport<td align='center'><img src='/images/forward.gif' alt='=&gt;' /><td>$int";
+
+       }
+}
+
+print "</table>";
+
+&Header::closebox();
+
 &Header::closebigbox();
 &Header::closepage();
 
@@ -250,34 +199,29 @@ END
 ############################################################################################################################
 
 sub isrunning
-{
-        my $cmd = $_[0];
-        my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
-        my $pid = '';
-        my $testcmd = '';
-        my $exename;
-
-        $cmd =~ /(^[a-z]+)/;
-        $exename = $1;
-
-        if (open(FILE, "/var/run/${cmd}.pid"))
-        {
-                $pid = <FILE>; chomp $pid;
-                close FILE;
-                if (open(FILE, "/proc/${pid}/status"))
-                {
-                        while (<FILE>)
-                        {
-                                if (/^Name:\W+(.*)/) {
-                                        $testcmd = $1; }
-                        }
-                        close FILE;
-                        if ($testcmd =~ /$exename/)
-                        {
-                                $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
-                        }
-                }
-        }
-
-        return $status;
-}
+       {
+       my $cmd = $_[0];
+       my $status = "<td bgcolor='${Header::colourred}' align='center'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
+       my $pid = '';
+       my $testcmd = '';
+       my $exename;
+
+       $cmd =~ /(^[a-z]+)/;
+       $exename = $1;
+
+       if (open(FILE, "/var/run/${cmd}.pid"))
+               {
+               $pid = <FILE>; chomp $pid;
+               close FILE;
+               if (open(FILE, "/proc/${pid}/status"))
+                       {
+                       while (<FILE>)
+                               {if (/^Name:\W+(.*)/) {$testcmd = $1; }}
+                       close FILE;
+                       if ($testcmd =~ /$exename/)
+                               {$status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";}
+                       }
+               }
+
+               return $status;
+       }