mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-08-27 05:41:15 +00:00
Improved clean at firewall rule form
Better integration with port forward rules.
This commit is contained in:
@@ -104,10 +104,11 @@
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a href="/firewall/port_forward/" class="nav-link {% if '/firewall/' in request.path %}active{% endif %}">
|
||||
<i class="fas fa-directions nav-icon"></i>
|
||||
<a href="/firewall/rule_list/" class="nav-link {% if '/firewall/' in request.path %}active{% endif %}">
|
||||
<i class="fas fa-shield-alt nav-icon"></i>
|
||||
<p>
|
||||
Port Forwarding
|
||||
Firewall
|
||||
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
|
@@ -2,11 +2,12 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if current_chain == "forward" %}active{% endif %}" href="/firewall/rule_list/?chain=forward" role="tab">Forward</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if current_chain == "portforward" %}active{% endif %}" href="/firewall/port_forward/" role="tab">Port Forward</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if current_chain == "postrouting" %}active{% endif %}" href="/firewall/rule_list/?chain=postrouting" role="tab">Post Routing</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if current_chain == "portforward" %}active{% endif %}" href="/firewall/port_forward/" role="tab">Port Forward</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
@@ -44,8 +44,6 @@
|
||||
<th>State</th>
|
||||
<th>Action</th>
|
||||
<th></th>
|
||||
|
||||
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rule in firewall_rule_list %}
|
||||
@@ -53,8 +51,8 @@
|
||||
<tr>
|
||||
<td style="width: 1%; white-space: nowrap;">{{ rule.sort_order }}</td>
|
||||
<td style="width: 1%; white-space: nowrap;">{% if rule.description %}<i class="fas fa-info-circle" title="{{ rule.description }}"></i>{% endif %}</td>
|
||||
<td>{{ rule.in_interface }}</td>
|
||||
<td>{{ rule.out_interface }}</td>
|
||||
<td>{{ rule.in_interface|default_if_none:'' }}</td>
|
||||
<td>{{ rule.out_interface|default_if_none:'' }}</td>
|
||||
<td>
|
||||
{% if rule.source_ip %}{% if rule.not_source %}<span title="Not source">!</span> {% endif %}{{ rule.source_ip }}/{{ rule.source_netmask }}<br>{% endif%}
|
||||
{% for peer in rule.source_peer.all %}{% if rule.not_source %}<span title="Not source">!</span> {% endif %}{{ peer }}{% if rule.source_peer_include_networks %} <span title="Include peer networks">+</span>{% endif %}<br>{% endfor %}
|
||||
@@ -65,8 +63,8 @@
|
||||
{% for peer in rule.destination_peer.all %}{% if rule.not_destination %}<span title="Not destination">!</span> {% endif %}{{ peer }}{% if rule.destination_peer_include_networks %} <span title="Include peer networks">+</span>{% endif %}<br>{% endfor %}
|
||||
</td>
|
||||
|
||||
<td>{{ rule.get_protocol_display }}</td>
|
||||
<td>{{ rule.destination_port }}</td>
|
||||
<td>{{ rule.get_protocol_display|default_if_none:'' }}</td>
|
||||
<td>{{ rule.destination_port|default_if_none:'' }}</td>
|
||||
<td>
|
||||
{% if rule.state_new %}{% if rule.not_state %}<span title="Not state">! </span>{% endif %}New<br>{% endif %}
|
||||
{% if rule.state_related %}{% if rule.not_state %}<span title="Not state">! </span>{% endif %}Related<br>{% endif %}
|
||||
|
@@ -370,37 +370,42 @@
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<a class="btn btn-outline-secondary" href="/firewall/rule_list/?chain={{ current_chain }}">Back</a>
|
||||
{% if instance %}
|
||||
<a href='javascript:void(0)' class='btn btn-outline-danger' data-command='delete' onclick='openCommandDialog(this)'>Delete Rule</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block custom_page_scripts %}
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Array de IDs dos campos a serem ignorados
|
||||
var ignoreFields = ['source_netmask', 'destination_netmask'];
|
||||
|
||||
// Itera por cada painel para verificar se contém dados nos campos
|
||||
$('.collapse').each(function() {
|
||||
var panel = $(this);
|
||||
var shouldOpen = false;
|
||||
|
||||
// Verifica inputs do tipo texto e número, excluindo os ignorados
|
||||
panel.find('input[type=text], input[type=number], textarea').each(function() {
|
||||
if (!ignoreFields.includes(this.id) && $(this).val()) {
|
||||
shouldOpen = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Verifica checkboxes e radios, excluindo os ignorados
|
||||
panel.find('input[type=checkbox], input[type=radio]').each(function() {
|
||||
if (!ignoreFields.includes(this.id) && $(this).is(':checked')) {
|
||||
shouldOpen = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Verifica selects, incluindo múltipla seleção, excluindo os ignorados
|
||||
panel.find('select').each(function() {
|
||||
if (!ignoreFields.includes(this.id) && $(this).find('option:selected').length > 0) {
|
||||
var allUnselected = true;
|
||||
@@ -413,15 +418,12 @@
|
||||
shouldOpen = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Se dados relevantes foram encontrados e não são para ser ignorados, abre o painel
|
||||
});
|
||||
if (shouldOpen) {
|
||||
panel.collapse('show');
|
||||
}
|
||||
});
|
||||
|
||||
// Controla o abrir/fechar dos painéis sem afetar os outros
|
||||
$('.card-header button').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var target = $(this).attr('data-target');
|
||||
@@ -429,7 +431,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -454,6 +455,20 @@
|
||||
updateSortOrder();
|
||||
{% endif %}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
function openCommandDialog(element) {
|
||||
var command = element.getAttribute('data-command');
|
||||
var confirmation = prompt("Please type 'delete' to remove this firewall rule.");
|
||||
if (confirmation) {
|
||||
var url = "?uuid={{ instance.uuid }}&action=delete&confirmation=" + encodeURIComponent(confirmation);
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
@@ -80,7 +80,7 @@
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<a href="/firewall/port_forward/" class="btn btn-secondary">Cancel</a>
|
||||
<a href="/firewall/port_forward/" class="btn btn-outline-secondary">Back</a>
|
||||
{% if instance %}<a href='javascript:void(0)' class='btn btn-outline-danger' data-command='delete' onclick='openCommandDialog(this)'>Delete Rule</a>{% endif %}
|
||||
|
||||
</form>
|
||||
|
@@ -66,6 +66,7 @@
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<a href="/firewall/manage_port_forward_rule/" class='btn btn-primary'>Create Port forwarding Rule</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,5 +76,5 @@
|
||||
|
||||
|
||||
|
||||
<a href="/firewall/manage_port_forward_rule/" class='btn btn-primary'>Create Port forwarding Rule</a>
|
||||
|
||||
{% endblock %}
|
Reference in New Issue
Block a user