function ValidateIPaddress(ipaddress) { if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) { return (true) } return (false) } $( 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 () { var server_ip = $('#ha-cluster-master option:selected').val(); var div_id = $('#cur_master_ver'); get_keepalived_ver(div_id, server_ip); }); $("#ha-cluster-master-interface").on('input', function () { var server_ip = $('#ha-cluster-master option:selected').val(); get_interface($(this), server_ip); }); $(".slave_int input").on('input', function () { var id = $(this).attr('id').split('-'); var server_ip = $('#slave_int_div-' + id[1]).attr('data-ip'); get_interface($(this), server_ip); }); }); function showProvisioningError(data, step_id, wait_mess, error_id) { $(wait_mess).hide(); $(error_id).append(data); $(error_id).show(); $(step_id).removeClass('proccessing'); $(step_id).addClass('processing_error'); $.getScript("/inc/fontawesome.min.js"); } 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("/inc/fontawesome.min.js"); } function confirmDeleteCluster(cluster_id) { var delete_word = $('#translate').attr('data-delete'); var cancel_word = $('#translate').attr('data-cancel'); $("#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: "/app/ha/cluster", type: "DELETE", data: { cluster_id: cluster_id, }, success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { $("#cluster-" + cluster_id).remove(); } } }); } function createHaClusterStep1(edited=false, cluster_id=0, clean=true) { var cancel_word = $('#translate').attr('data-cancel'); var next_word = $('#translate').attr('data-next'); var tabel_title = $("#create-ha-cluster-step-1-overview").attr('title'); if (clean) { clearClusterDialog(edited); $.ajax({ url: "/app/ha/cluster/masters", async: false, type: "GET", success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { $("#ha-cluster-master").html(data); $('#ha-cluster-master').selectmenu("refresh"); } } }); } if (edited) { tabel_title = $("#create-ha-cluster-step-1-overview").attr('data-edit'); } if (edited && clean) { var master_name = $('#master-server-'+cluster_id).text(); var master_ip = $('#master-ip-'+cluster_id).text(); $("#ha-cluster-master option").not(master_name).each(function (index) { $(this).prop('disabled', true); }); $('#ha-cluster-master').append('').selectmenu("refresh"); $('#ha-cluster-master').selectmenu("refresh"); get_keepalived_ver($('#cur_master_ver'), master_ip); $.ajax({ url: "/app/ha/cluster/settings/" + cluster_id, type: "GET", async: false, success: function (data) { let clusterSettings = JSON.parse(JSON.stringify(data)); $('#ha-cluster-name').val(clusterSettings.name); $('#ha-cluster-desc').val(clusterSettings.desc); $('#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_to_master) { $('#return_to_master').prop('checked', true); } else { $('#return_to_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); } $( "input[type=checkbox]" ).checkboxradio("refresh"); } }); } $.ajax({ url: "/app/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('/inc/ha.js'); var regx = /^[a-z0-9_-]+$/; var 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; } 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='') { var add_word = $('#translate').attr('data-next'); var cancel_word = $('#translate').attr('data-cancel'); var next_word = $('#translate').attr('data-next'); var back_word = $('#translate').attr('data-back'); var save_word = $('#translate').attr('data-save'); var apply_word = $('#translate').attr('data-apply'); var tabel_title = $("#create-ha-cluster-step-2-overview").attr('title'); if (edited) { tabel_title = $("#create-ha-cluster-step-2-overview").attr('data-edit'); } var 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_to_master = 0; let syn_flood = 0; let hap = 0; let hap_docker = 0; let nginx = 0; let nginx_docker = 0; let apache = 0; let req_method = 'POST'; if (edited) { req_method = 'PUT'; } if ($('#virt_server').is(':checked')) { virt_server = '1'; } if ($('#return_to_master').is(':checked')) { return_to_master = '1'; } if ($('#syn_flood').is(':checked')) { syn_flood = '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'; } jsonData['cluster_id'] = cluster_id; jsonData['name'] = $('#ha-cluster-name').val(); jsonData['desc'] = $('#ha-cluster-desc').val(); jsonData['vip'] = $('#vrrp-ip').val(); jsonData['virt_server'] = virt_server; jsonData['return_to_master'] = return_to_master; jsonData['syn_flood'] = syn_flood; 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: "/app/ha/cluster", type: req_method, async: false, data: { jsonData: JSON.stringify(jsonData), }, success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { if (!edited) { cluster_id = data; 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) { 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; } var server_creating_title = $("#server_creating1").attr('title'); var 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 li_id = 'creating-' 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; var li_id = 'creating-' + service + '-'; var install_mess = $('#translate').attr('data-installing'); var timeout_mess = $('#translate').attr('data-roxywi_timeout'); var something_wrong = $('#translate').attr('data-something_wrong'); var nice_service_name = {'keepalived': 'HA Custer', 'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache'}; $('#server_creating_list').append('