$( function() { $("select").selectmenu({ width: 180 }); $('#hap').click(function () { if ($('#hap').is(':checked')) { $('#haproxy_docker_td').show(); $('#haproxy_docker_td_header').show(); } else { $('#haproxy_docker_td').hide(); $('#haproxy_docker_td_header').hide(); } }); $('#nginx').click(function () { if ($('#nginx').is(':checked')) { $('#nginx_docker_td').show(); $('#nginx_docker_td_header').show(); } else { $('#nginx_docker_td').hide(); $('#nginx_docker_td_header').hide(); } }); $("#ha-cluster-master").on('selectmenuchange', function () { let server_ip = $('#ha-cluster-master option:selected').val(); let div_id = $('#cur_master_ver'); get_keepalived_ver(div_id, server_ip); }); $("#ha-cluster-master-interface").on('input', function () { let server_ip = $('#ha-cluster-master option:selected').val(); get_interface($(this), server_ip); }); $(".slave_int input").on('input', function () { let id = $(this).attr('id').split('-'); let server_ip = $('#slave_int_div-' + id[1]).attr('data-ip'); get_interface($(this), server_ip); }); }); function cleanProvisioningProccess(div_id, success_div, error_id, warning_id, progres_id) { $(div_id).empty(); $(success_div).empty(); $(success_div).hide(); $(error_id).empty(); $(error_id).hide(); $(warning_id).empty(); $(warning_id).hide(); $(progres_id).css('width', '5%'); $(div_id).each(function () { $(this).remove(''); }); $.getScript(awesome); } function confirmDeleteCluster(cluster_id) { $("#dialog-confirm").dialog({ resizable: false, height: "auto", width: 400, modal: true, title: delete_word + " " + $('#cluster-name-' + cluster_id).text() + "?", buttons: [{ text: delete_word, click: function () { $(this).dialog("close"); deleteCluster(cluster_id); } }, { text: cancel_word, click: function () { $(this).dialog("close"); } }] }); } function deleteCluster(cluster_id) { $.ajax({ url: api_prefix + "/ha/cluster/" + cluster_id, type: "DELETE", statusCode: { 204: function (xhr) { $("#cluster-" + cluster_id).remove(); }, 404: function (xhr) { $("#cluster-" + cluster_id).remove(); } }, success: function (data) { if (data) { if (data.status === "failed") { toastr.error(data); } } } }); } function createHaClusterStep1(edited=false, cluster_id=0, clean=true) { let next_word = translate_div.attr('data-next'); let tabel_title = $("#create-ha-cluster-step-1-overview").attr('title'); if (clean) { clearClusterDialog(edited); $.ajax({ url: "/ha/cluster/masters", async: false, type: "GET", contentType: "application/json; charset=utf-8", success: function (data) { if (data.status === 'failed') { toastr.error(data.error); } else { for (let i in data) { $('#ha-cluster-master').append(''); } $('#ha-cluster-master').selectmenu("refresh"); } } }); } if (edited) { tabel_title = $("#create-ha-cluster-step-1-overview").attr('data-edit'); } if (edited && clean) { let master_name = $('#master-server-'+cluster_id).text(); let master_ip = $('#master-ip-'+cluster_id).text(); let master_id = $('#master-id-'+cluster_id).text(); $("#ha-cluster-master option").not(master_name).each(function (index) { $(this).prop('disabled', true); }); $('#ha-cluster-master').append('').selectmenu("refresh"); get_keepalived_ver($('#cur_master_ver'), master_ip); $.ajax({ url: api_prefix + "/ha/cluster/" + cluster_id, type: "GET", async: false, success: function (data) { let clusterSettings = JSON.parse(JSON.stringify(data)); $('#ha-cluster-name').val(clusterSettings.name.replaceAll("'", "")); $('#ha-cluster-desc').val(clusterSettings.description.replaceAll("'", "")); $('#ha-cluster-master-interface').val(clusterSettings.eth); $('#vrrp-ip').val(clusterSettings.vip); if (clusterSettings.haproxy) { $('#hap').prop('checked', true); } else { $('#hap').prop('checked', false); } if (clusterSettings.nginx) { $('#nginx').prop('checked', true); } else { $('#nginx').prop('checked', false); } if (clusterSettings.return_master) { $('#return_master').prop('checked', true); } else { $('#return_master').prop('checked', false); } if (clusterSettings.syn_flood) { $('#syn_flood').prop('checked', true); } else { $('#syn_flood').prop('checked', false); } if (clusterSettings.virt_server) { $('#virt_server').prop('checked', true); } else { $('#virt_server').prop('checked', false); } if (clusterSettings.use_src) { $('#use_src').prop('checked', true); } else { $('#use_src').prop('checked', false); } $( "input[type=checkbox]" ).checkboxradio("refresh"); } }); } $.ajax({ url: "/ha/cluster/slaves/servers/" + cluster_id, async: false, type: "GET", success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { $(".checks").html(data); } } }); $.getScript(ha); let regx = /^[a-zA-Z0-9_-]+$/; let dialog_div = $("#create-ha-cluster-step-1").dialog({ autoOpen: false, resizable: false, height: "auto", width: 630, modal: true, title: tabel_title, show: { effect: "fade", duration: 200 }, hide: { effect: "fade", duration: 200 }, buttons: [{ text: next_word, click: function () { if ($('#ha-cluster-name').val() == '') { toastr.error('error: Fill in the Name field'); return false; } if ($('#ha-cluster-master option:selected').val().indexOf('--') != '-1') { toastr.error('error: Select a Master server'); return false; } if (!regx.test($('#ha-cluster-master-interface').val())) { toastr.error('error: Fill in the interface field'); return false; } if ($('#vrrp-ip').val() == '') { toastr.error('error: Fill in the VIP field'); return false; } if (!ValidateIPaddress($('#vrrp-ip').val())) { toastr.error('error: Wrong VIP'); return false; } let jsonData = createJsonCluster('#enabled-check div div span'); if (!validateSlaves(jsonData)) { return false; } createHaClusterStep2(edited, cluster_id, jsonData); $(this).dialog("close"); toastr.clear(); } }, { text: cancel_word, click: function () { $(this).dialog("close"); clearClusterDialog(edited); } }] }); dialog_div.dialog('open'); } function createHaClusterStep2(edited=false, cluster_id=0, jsonData='') { let apply_word = translate_div.attr('data-apply'); let tabel_title = $("#create-ha-cluster-step-2-overview").attr('title'); if (edited) { tabel_title = $("#create-ha-cluster-step-2-overview").attr('data-edit'); } let dialog_div = $("#create-ha-cluster-step-2").dialog({ autoOpen: false, resizable: false, height: "auto", width: 630, modal: true, title: tabel_title, show: { effect: "fade", duration: 200 }, hide: { effect: "fade", duration: 200 }, buttons: [{ text: save_word, click: function () { $(this).dialog("close"); saveCluster(jsonData, cluster_id, edited); } }, { text: apply_word, click: function () { $(this).dialog("close"); saveCluster(jsonData, cluster_id, edited, 1); } }, { text: back_word, click: function () { $(this).dialog("close"); createHaClusterStep1(edited, cluster_id, false); } }, { text: cancel_word, click: function () { $(this).dialog("close"); clearClusterDialog(edited); } }] }); dialog_div.dialog('open'); } function saveCluster(jsonData, cluster_id=0, edited=0, reconfigure=0) { let virt_server = 0; let return_master = 0; let syn_flood = 0; let use_src = 0; let hap = 0; let hap_docker = 0; let nginx = 0; let nginx_docker = 0; let apache = 0; let req_method = 'POST'; let url = api_prefix + '/ha/cluster'; if ($('#virt_server').is(':checked')) { virt_server = 1; } if ($('#return_master').is(':checked')) { return_master = '1'; } if ($('#syn_flood').is(':checked')) { syn_flood = '1'; } if ($('#use_src').is(':checked')) { use_src = '1'; } if ($('#hap').is(':checked')) { hap = '1'; } if ($('#hap_docker').is(':checked')) { hap_docker = '1'; } if ($('#nginx').is(':checked')) { nginx = '1'; } if ($('#nginx_docker').is(':checked')) { nginx_docker = '1'; } if ($('#apache').is(':checked')) { apache = '1'; } if (edited) { req_method = 'PUT'; url = api_prefix + '/ha/cluster/' + cluster_id; } jsonData['name'] = $('#ha-cluster-name').val(); jsonData['description'] = $('#ha-cluster-desc').val(); jsonData['vip'] = $('#vrrp-ip').val(); jsonData['virt_server'] = virt_server; jsonData['return_master'] = return_master; jsonData['syn_flood'] = syn_flood; jsonData['use_src'] = use_src; jsonData['services'] = {'haproxy': {'enabled': hap, 'docker': hap_docker}}; jsonData['services']['nginx'] = {'enabled': nginx, 'docker': nginx_docker}; jsonData['services']['apache'] = {'enabled': apache, 'docker': 0}; jsonData['router_id'] = $('#router_id-' + cluster_id).val(); $.ajax({ url: url, type: req_method, async: false, data: JSON.stringify(jsonData), contentType: "application/json; charset=utf-8", success: function (data) { if (data.status === 'failed') { toastr.error(data.error); } else { if (!edited) { cluster_id = data.id; getHaCluster(cluster_id, true); } else { getHaCluster(cluster_id); $("#cluster-" + cluster_id).addClass("update", 1000); setTimeout(function () { $("#cluster-" + cluster_id).removeClass("update"); }, 2500); } } } }); if (reconfigure) { Reconfigure(jsonData, cluster_id); } } function Reconfigure(jsonData, cluster_id) { let servers = JSON.parse(JSON.stringify(jsonData)); $("#wait-mess").html(wait_mess); $("#wait-mess").show(); let total_installation = 1; if (servers['services']['haproxy']['enabled']) { total_installation = total_installation + 1; } if (servers['services']['nginx']['enabled']) { total_installation = total_installation + 1; } if (servers['services']['apache']['enabled']) { total_installation = total_installation + 1; } let server_creating_title = $("#server_creating1").attr('title'); let server_creating = $("#server_creating1").dialog({ autoOpen: false, width: 574, modal: true, title: server_creating_title, close: function () { cleanProvisioningProccess('#server_creating1 ul li', '#created-mess', '#creating-error', '#creating-warning', '#creating-progress'); }, buttons: { Close: function () { $(this).dialog("close"); cleanProvisioningProccess('#server_creating1 ul li', '#created-mess', '#creating-error', '#creating-warning', '#creating-progress'); } } }); server_creating.dialog('open'); let progress_step = 100 / total_installation; $.when(installServiceCluster(jsonData, 'keepalived', progress_step, cluster_id)).done(function () { if (servers['services']['haproxy']['enabled']) { $.when(installServiceCluster(jsonData, 'haproxy', progress_step, cluster_id)).done(function () { if (servers['services']['nginx']['enabled']) { $.when(installServiceCluster(jsonData, 'nginx', progress_step, cluster_id)).done(function () { if (servers['services']['apache']['enabled']) { installServiceCluster(jsonData, 'apache', progress_step, cluster_id); } }); } else { if (servers['services']['apache']['enabled']) { installServiceCluster(jsonData, 'apache', progress_step, cluster_id); } } }); } else { if (servers['services']['nginx']['enabled']) { $.when(installServiceCluster(jsonData, 'nginx', progress_step, cluster_id)).done(function () { if (servers['services']['apache']['enabled']) { installServiceCluster(jsonData, 'apache', progress_step, cluster_id); } }); } else { if (servers['services']['apache']['enabled']) { installServiceCluster(jsonData, 'apache', progress_step, cluster_id); } } } }); } function installServiceCluster(jsonData, service, progress_step, cluster_id) { let servers = JSON.parse(JSON.stringify(jsonData)); servers['cluster_id'] = cluster_id; let li_id = 'creating-' + service + '-'; let install_mess = translate_div.attr('data-installing'); let timeout_mess = translate_div.attr('data-roxywi_timeout'); let something_wrong = translate_div.attr('data-something_wrong'); $('#server_creating_list').append('