]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/zoneconf.cgi
Syntax fixes in several CGIs
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / zoneconf.cgi
index 3712b92cdeb080fafcb07441764c5c02613b6f20..0914ceb78ea5b23a51f359a843677630b4073ce6 100644 (file)
@@ -26,82 +26,83 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
-my $css = <<END
+my $extraHead = <<END
 <style>
-       table {
+       table#zoneconf {
                width: 100%;
+               border-collapse: collapse;
+               table-layout: fixed;
        }
 
-       tr {
+       #zoneconf tr {
                height: 4em;
        }
 
-       td:first-child {
-               width: 1px;
+       #zoneconf td {
+               padding: 5px 10px;
+               border: 0.5px solid black;
+               text-align: center;
        }
 
-       td {
-               padding: 5px;
-               padding-left: 10px;
-               padding-right: 10px;
-               border: 0.5px solid black;
+       /* dark grey header cells */
+       #zoneconf td.heading {
+               background-color: grey;
+               color: white;
+       }       
+       #zoneconf td.heading::first-line {
+               font-weight: bold;
+               line-height: 1.6;
        }
 
-       table {
-               border-collapse: collapse;
+       /* narrow left column */
+       #zoneconf tr > td:first-child {
+               width: 11em;
        }
 
-       td.h {
-               background-color: grey;
-               color: white;
-               font-weight: 800;
+       /* alternating row background color */
+       #zoneconf tr:nth-child(2n+3) {
+               background-color: #F0F0F0;
        }
 
-       td.green {
+       #zoneconf td.green {
                background-color: $Header::colourgreen;
        }
 
-       td.red {
+       #zoneconf td.red {
                background-color: $Header::colourred;
        }
 
-       td.blue {
+       #zoneconf td.blue {
                background-color: $Header::colourblue;
        }
 
-       td.orange {
+       #zoneconf td.orange {
                background-color: $Header::colourorange;
        }
 
-       td.topleft {
-               background-color: white;
+       #zoneconf td.topleft {
+               background-color: $Header::pagecolour;
                border-top-style: none;
                border-left-style: none;
        }
 
-       td.disabled {
-               background-color: #cccccc;
-       }
-
-       td.textcenter {
-               text-align: center;
+       input.vlanid {
+               width: 4em;
        }
 
        #submit-container {
                width: 100%;
                padding-top: 20px;
                text-align: right;
+               color: red;
        }
 
        #submit-container.input {
                margin-left: auto;
        }
-
-       button {
-               margin-top: 1em;
-       }
-
 </style>
+
+<script src="/include/zoneconf.js"></script>
 END
 ;
 
@@ -109,6 +110,8 @@ my %ethsettings = ();
 my %vlansettings = ();
 my %cgiparams = ();
 
+my $restart_notice = "";
+
 &General::readhash("${General::swroot}/ethernet/settings",\%ethsettings);
 &General::readhash("${General::swroot}/ethernet/vlans",\%vlansettings);
 
@@ -150,7 +153,7 @@ foreach (@nics) {
        }
 }
 
-&Header::openpage($Lang::tr{"zoneconf title"}, 1, $css);
+&Header::openpage($Lang::tr{"zoneconf title"}, 1, $extraHead);
 &Header::openbigbox('100%', 'center');
 
 ### Evaluate POST parameters ###
@@ -199,6 +202,8 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) {
                        my $mac = $_->[0];
                        my $nic_access = $cgiparams{"ACCESS $uc $mac"};
 
+                       next unless ($nic_access);
+
                        if ($nic_access ne "NONE") {
                                if ($VALIDATE_nic_check{"RESTRICT $mac"}) { # If this interface is already assigned to RED in PPP mode, throw an error
                                        $VALIDATE_error = $Lang::tr{"zoneconf val ppp assignment error"};
@@ -276,7 +281,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) {
        if ($VALIDATE_error) {
                &Header::openbox('100%', 'left', $Lang::tr{"error"});
 
-               print "$VALIDATE_error<br><a href='/cgi-bin/zoneconf.cgi'><button>$Lang::tr{'ok'}</button></a>";
+               print "$VALIDATE_error<br><br><a href='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'back'}</a>\n";
 
                &Header::closebox();
                &Header::closebigbox();
@@ -287,6 +292,8 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) {
 
        &General::writehash("${General::swroot}/ethernet/settings",\%ethsettings);
        &General::writehash("${General::swroot}/ethernet/vlans",\%vlansettings);
+
+       $restart_notice = $Lang::tr{'zoneconf notice reboot'};
 }
 
 &Header::openbox('100%', 'left', $Lang::tr{"zoneconf nic assignment"});
@@ -294,23 +301,14 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) {
 ### START OF TABLE ###
 
 print <<END
-       <form method='post' enctype='multipart/form-data'>
-               <table>
-                       <tr>
-                       <td class="h topleft" /td>
+<form method='post' enctype='multipart/form-data'>
+       <table id="zoneconf">
+       <tr>
+               <td class="topleft"></td>
 END
 ;
 
-# Fill the table header with all physical NICs
-foreach (@nics) {
-       my $mac = $_->[0];
-       my $nic = $_->[1];
-
-       print "<td class='h textcenter'>$nic<br>$mac</td>";
-}
-
-print "</tr>";
-
+# Fill the table header with all activated zones
 foreach (@zones) {
        my $uc = uc $_;
        my $dev_name = $ethsettings{"${uc}_DEV"};
@@ -319,28 +317,14 @@ foreach (@zones) {
                next;
        }
 
-       print "<tr>";
-
+       # If the zone is in PPP mode, don't show a mode dropdown
        if ($uc eq "RED") {
                my $red_type = $ethsettings{"RED_TYPE"};
                my $red_restricted = ($uc eq "RED" && ! ($red_type eq "STATIC" || $red_type eq "DHCP"));
 
-               # VLANs/Bridging is not possible if the RED interface is set to PPP, PPPoE, VDSL, ...
                if ($red_restricted) {
-                       print "<td class='h $_'>$uc<br>($red_type)</td>";
+                       print "\t\t<td class='heading $_'>$uc ($red_type)</td>\n";
 
-                       foreach (@nics) {
-                               my $mac = $_->[0];
-                               my $checked = "";
-
-                               if ($mac eq $ethsettings{"${uc}_MACADDR"}) {
-                                       $checked = "checked";
-                               }
-
-                               print "<td class='textcenter'><input type='radio' id='PPPACCESS $mac' name='PPPACCESS' value='$mac' $checked></td>";
-                       }
-
-                       print "</tr>";
                        next; # We're done here
                }
        }
@@ -357,7 +341,7 @@ foreach (@zones) {
        }
 
        print <<END
-               <td class='h $_'>$uc<br>
+               <td class='heading $_'>$uc<br>
                        <select name="MODE $uc">
                                <option value="DEFAULT" $mode_selected{"DEFAULT"}>$Lang::tr{"zoneconf nicmode default"}</option>
                                <option value="BRIDGE" $mode_selected{"BRIDGE"}>$Lang::tr{"zoneconf nicmode bridge"}</option>
@@ -366,29 +350,66 @@ foreach (@zones) {
                </td>
 END
 ;
+}
+
+print "\t</tr>\n";
+
+foreach (@nics) {
+       my $mac = $_->[0];
+       my $nic = $_->[1];
+       my $wlan = $_->[2];
+
+       print "\t<tr>\n";
+       print "\t\t<td class='heading'>$nic<br>$mac</td>\n";
+
+       # Iterate through all zones and check if the current NIC is assigned to it
+       foreach (@zones) {
+               my $uc = uc $_;
+               my $dev_name = $ethsettings{"${uc}_DEV"};
+               my $highlight = "";
 
-       # ZONE_PARENT_DEV is set if this zone accesses any interface via a VLAN
-       my $zone_parent_dev = $vlansettings{"${uc}_PARENT_DEV"};
+               if ($dev_name eq "") { # Again, skip the zone if it is not activated
+                       next;
+               }
 
-       # If ZONE_PARENT_DEV is set to a NICs name (e.g. green0 or eth0) instead of a MAC address, we have to find out this NICs MAC address
-       $zone_parent_dev = &Network::get_mac_by_name($zone_parent_dev);
+               if ($uc eq "RED") {
+                       my $red_type = $ethsettings{"RED_TYPE"};
+                       my $red_restricted = ($uc eq "RED" && ! ($red_type eq "STATIC" || $red_type eq "DHCP"));
+
+                       # VLANs/Bridging is not possible if the RED interface is set to PPP, PPPoE, VDSL, ...
+                       if ($red_restricted) {
+                               my $checked = "";
+
+                               if ($mac eq $ethsettings{"${uc}_MACADDR"}) {
+                                       $checked = "checked";
+                                       $highlight = $_;
+                               }
+
+                               print <<END
+               <td class="$highlight">
+                       <input type="radio" name="PPPACCESS" value="$mac" data-zone="RED" data-mac="$mac" onchange="highlightAccess(this)" $checked>
+               </td>
+END
+;
+                               next; # We're done here
+                       }
+               }
 
-       foreach (@nics) { # Check for all nics if they are assigned to the current zone
                my %access_selected = ();
-               my $mac = $_->[0];
-               my $wlan = $_->[2];
+               my $zone_mode = $ethsettings{"${uc}_MODE"};
+               my $zone_parent_dev = $vlansettings{"${uc}_PARENT_DEV"};  # ZONE_PARENT_DEV is set if this zone accesses any interface via a VLAN
                my $field_disabled = "disabled"; # Only enable the VLAN ID input field if the current access mode is VLAN
                my $zone_vlan_id = "";
 
+               # If ZONE_PARENT_DEV is set to a NICs name (e.g. green0 or eth0) instead of a MAC address, we have to find out this NICs MAC address
+               $zone_parent_dev = &Network::get_mac_by_name($zone_parent_dev);
+
                # If the current NIC is accessed by the current zone via a VLAN, the ZONE_PARENT_DEV option corresponds to the current NIC
                if ($mac eq $zone_parent_dev) {
                        $access_selected{"VLAN"} = "selected";
                        $field_disabled = "";
                        $zone_vlan_id = $vlansettings{"${uc}_VLAN_ID"};
-               }
-
-               # If the current zone is in bridge mode, all corresponding NICs (Native as well as VLAN) are set via the ZONE_SLAVES option
-               if ($zone_mode eq "bridge") {
+               } elsif ($zone_mode eq "bridge") { # If the current zone is in bridge mode, all corresponding NICs (Native as well as VLAN) are set via the ZONE_SLAVES option
                        my @slaves = split(/ /, $ethsettings{"${uc}_SLAVES"});
 
                        foreach (@slaves) {
@@ -400,35 +421,39 @@ END
                                        last;
                                }
                        }
-               } else { # Native access via ZONE_MACADDR is only set if the zone does not access a NIC via a VLAN and the zone is not in bridge mode
-                       if ($mac eq $ethsettings{"${uc}_MACADDR"}) {
-                               $access_selected{"NATIVE"} = "selected";
-                       }
+               } elsif ($mac eq $ethsettings{"${uc}_MACADDR"}) { # Native access via ZONE_MACADDR is only set if the zone does not access a NIC via a VLAN and the zone is not in bridge mode
+                       $access_selected{"NATIVE"} = "selected";
                }
 
                $access_selected{"NONE"} = ($access_selected{"NATIVE"} eq "") && ($access_selected{"VLAN"} eq "") ? "selected" : "";
                my $vlan_disabled = ($wlan) ? "disabled" : "";
 
+               # If the interface is assigned, hightlight table cell
+               if ($access_selected{"NONE"} eq "") {
+                       $highlight = $_;
+               }
+
                print <<END
-                       <td class="textcenter">
-                               <select name="ACCESS $uc $mac" onchange="document.getElementById('TAG $uc $mac').disabled = (this.value === 'VLAN' ? false : true)">
-                                       <option value="NONE" $access_selected{"NONE"}>- $Lang::tr{"zoneconf access none"} -</option>
-                                       <option value="NATIVE" $access_selected{"NATIVE"}>$Lang::tr{"zoneconf access native"}</option>
-                                       <option value="VLAN" $access_selected{"VLAN"} $vlan_disabled>$Lang::tr{"zoneconf access vlan"}</option>
-                               </select>
-                               <input type="number" id="TAG $uc $mac" name="TAG $uc $mac" min="1" max="4095" value="$zone_vlan_id" $field_disabled>
-                       </td>
+               <td class="$highlight">
+                       <select name="ACCESS $uc $mac" data-zone="$uc" data-mac="$mac" onchange="highlightAccess(this)">
+                               <option value="NONE" $access_selected{"NONE"}>- $Lang::tr{"zoneconf access none"} -</option>
+                               <option value="NATIVE" $access_selected{"NATIVE"}>$Lang::tr{"zoneconf access native"}</option>
+                               <option value="VLAN" $access_selected{"VLAN"} $vlan_disabled>$Lang::tr{"zoneconf access vlan"}</option>
+                       </select>
+                       <input type="number" class="vlanid" id="TAG-$uc-$mac" name="TAG $uc $mac" min="1" max="4095" value="$zone_vlan_id" $field_disabled>
+               </td>
 END
 ;
-
        }
-       print "</tr>";
+
+       print "\t</tr>\n";
 }
 
 print <<END
        </table>
 
        <div id="submit-container">
+               $restart_notice
                <input type="submit" name="ACTION" value="$Lang::tr{"save"}">
        </div>
 </form>