Removes not needed code from template
This commit is contained in:
		
							parent
							
								
									5abb066df5
								
							
						
					
					
						commit
						f738b95be0
					
				| 
						 | 
					@ -54,157 +54,4 @@ Connected Peers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</section>
 | 
					</section>
 | 
				
			||||||
 | 
					 | 
				
			||||||
<div class="modal fade" id="modal_endpoint_address_suggestion">
 | 
					 | 
				
			||||||
    <div class="modal-dialog">
 | 
					 | 
				
			||||||
        <div class="modal-content">
 | 
					 | 
				
			||||||
            <div class="modal-header">
 | 
					 | 
				
			||||||
                <h4 class="modal-title">Endpoint Address Suggestion</h4>
 | 
					 | 
				
			||||||
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
 | 
					 | 
				
			||||||
                    <span aria-hidden="true">×</span>
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="modal-body">
 | 
					 | 
				
			||||||
                <p>Following is the list of public and local IP addresses for your consideration.</p>
 | 
					 | 
				
			||||||
                <select id="ip_suggestion" class="select2"
 | 
					 | 
				
			||||||
                    data-placeholder="Select an IP address" style="width: 100%;">
 | 
					 | 
				
			||||||
                </select>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="modal-footer justify-content-between">
 | 
					 | 
				
			||||||
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 | 
					 | 
				
			||||||
                <button type="button" class="btn btn-success" id="btn_use_ip" disabled>Use selected IP address</button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- /.modal-content -->
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <!-- /.modal-dialog -->
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
<!-- /.modal -->
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "bottom_js"}}
 | 
					 | 
				
			||||||
    <script>
 | 
					 | 
				
			||||||
        function submitGlobalSettings() {
 | 
					 | 
				
			||||||
            const endpoint_address = $("#endpoint_address").val();
 | 
					 | 
				
			||||||
            const dns_servers = $("#dns_servers").val().split(",");
 | 
					 | 
				
			||||||
            const mtu = $("#mtu").val();
 | 
					 | 
				
			||||||
            const persistent_keepalive = $("#persistent_keepalive").val();
 | 
					 | 
				
			||||||
            const config_file_path = $("#config_file_path").val();
 | 
					 | 
				
			||||||
            const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "config_file_path": config_file_path};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            $.ajax({
 | 
					 | 
				
			||||||
                cache: false,
 | 
					 | 
				
			||||||
                method: 'POST',
 | 
					 | 
				
			||||||
                url: '/global-settings',
 | 
					 | 
				
			||||||
                dataType: 'json',
 | 
					 | 
				
			||||||
                contentType: "application/json",
 | 
					 | 
				
			||||||
                data: JSON.stringify(data),
 | 
					 | 
				
			||||||
                success: function(data) {
 | 
					 | 
				
			||||||
                    $("#modal_new_client").modal('hide');
 | 
					 | 
				
			||||||
                    toastr.success('Update global settings successfully');
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                error: function(jqXHR, exception) {
 | 
					 | 
				
			||||||
                    const responseJson = jQuery.parseJSON(jqXHR.responseText);
 | 
					 | 
				
			||||||
                    toastr.error(responseJson['message']);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        function updateEndpointSuggestionIP() {
 | 
					 | 
				
			||||||
            $.getJSON("/api/machine-ips", null, function(data) {
 | 
					 | 
				
			||||||
                $("#ip_suggestion option").remove();
 | 
					 | 
				
			||||||
                $.each(data, function(index, item) {
 | 
					 | 
				
			||||||
                    $("#ip_suggestion").append(
 | 
					 | 
				
			||||||
                        $("<option></option>")
 | 
					 | 
				
			||||||
                            .text(item.ip_address + ' - ' + item.name)
 | 
					 | 
				
			||||||
                            .val(item.ip_address)
 | 
					 | 
				
			||||||
                    );
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
                document.getElementById("btn_use_ip").disabled = false;
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    </script>
 | 
					 | 
				
			||||||
    <script>
 | 
					 | 
				
			||||||
        // Wireguard Interface DNS server tag input
 | 
					 | 
				
			||||||
        $("#dns_servers").tagsInput({
 | 
					 | 
				
			||||||
            'width': '100%',
 | 
					 | 
				
			||||||
            'height': '75%',
 | 
					 | 
				
			||||||
            'interactive': true,
 | 
					 | 
				
			||||||
            'defaultText': 'Add More',
 | 
					 | 
				
			||||||
            'removeWithBackspace': true,
 | 
					 | 
				
			||||||
            'minChars': 0,
 | 
					 | 
				
			||||||
            'placeholderColor': '#666666'
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Load DNS server to the form
 | 
					 | 
				
			||||||
        {{range .globalSettings.DNSServers}}
 | 
					 | 
				
			||||||
        $("#dns_servers").addTag('{{.}}');
 | 
					 | 
				
			||||||
        {{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Global setting form validation
 | 
					 | 
				
			||||||
        $(document).ready(function () {
 | 
					 | 
				
			||||||
            $.validator.setDefaults({
 | 
					 | 
				
			||||||
                submitHandler: function () {
 | 
					 | 
				
			||||||
                    submitGlobalSettings();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            $("#frm_global_settings").validate({
 | 
					 | 
				
			||||||
                rules: {
 | 
					 | 
				
			||||||
                    mtu: {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        digits: true,
 | 
					 | 
				
			||||||
                        range: [68, 65535]
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    persistent_keepalive: {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        digits: true
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    config_file_path: {
 | 
					 | 
				
			||||||
                        required: true
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                messages: {
 | 
					 | 
				
			||||||
                    mtu: {
 | 
					 | 
				
			||||||
                        required: "Please enter a MTU value",
 | 
					 | 
				
			||||||
                        digits: "MTU must be an integer",
 | 
					 | 
				
			||||||
                        range: "MTU must be in range 68..65535"
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    persistent_keepalive: {
 | 
					 | 
				
			||||||
                        required: "Please enter a Persistent Keepalive value",
 | 
					 | 
				
			||||||
                        digits: "Persistent keepalive must be an integer"
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    config_file_path: {
 | 
					 | 
				
			||||||
                        required: "Please enter WireGuard config file path"
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                errorElement: 'span',
 | 
					 | 
				
			||||||
                errorPlacement: function (error, element) {
 | 
					 | 
				
			||||||
                    error.addClass('invalid-feedback');
 | 
					 | 
				
			||||||
                    element.closest('.form-group').append(error);
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                highlight: function (element, errorClass, validClass) {
 | 
					 | 
				
			||||||
                    $(element).addClass('is-invalid');
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                unhighlight: function (element, errorClass, validClass) {
 | 
					 | 
				
			||||||
                    $(element).removeClass('is-invalid');
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Endpoint IP suggestion modal event
 | 
					 | 
				
			||||||
        $(document).ready(function () {
 | 
					 | 
				
			||||||
            $("#modal_endpoint_address_suggestion").on('shown.bs.modal', function (e) {
 | 
					 | 
				
			||||||
                updateEndpointSuggestionIP();
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Use selected IP address from suggestion form
 | 
					 | 
				
			||||||
        $(document).ready(function () {
 | 
					 | 
				
			||||||
            $("#btn_use_ip").click(function () {
 | 
					 | 
				
			||||||
                const ip = $("#ip_suggestion").select2('val');
 | 
					 | 
				
			||||||
                $("#endpoint_address").val(ip);
 | 
					 | 
				
			||||||
                $("#modal_endpoint_address_suggestion").modal('hide');
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    </script>
 | 
					 | 
				
			||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue