'); return message; } function sanitize(input) { const tagsRegex = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi; const attributesRegex = /([a-z][a-z0-9]*)="[^"]*"/gi; const protocols = ["http", "https", "mailto", "tel"]; const hrefRegex = /href="(.*?)"/gi; const srcRegex = /src="(.*?)"/gi; const sanitizedInput = input.replace(tagsRegex, "").replace(attributesRegex, (match, attribute) => { if (attribute === "href" || attribute === "src") { return match.replace(/"/g, "'").replace(hrefRegex, (match, url) => { const protocol = url.split(":")[0]; if (protocols.includes(protocol)) { return `href="${url}"`; } else { return ""; } }).replace(srcRegex, (match, url) => { const protocol = url.split(":")[0]; if (protocols.includes(protocol)) { return `src="${url}"`; } else { return ""; } }); } else { return `${attribute}="${match.slice(attribute.length + 2, -1)}"`; }; }); return sanitizedInput; } function send_message(message, user, correspondent_id) { $("div.overlay_message_loader").fadeIn(200); const json_message = JSON.stringify(sanitize(message)); $.ajax({ type: "POST", dataType: 'json', contentType: 'application/json', url: "//www.womex.com/virtual/api/mail/person/"+user+"/other_person/"+correspondent_id, data: '{"text":'+json_message+'}', success: function(data){ $("textarea#chat_message").val(''); fill_message_thread_with_correspondent_id(user,correspondent_id,'new'); }, error: function(e){ } }); $("div.overlay_message_loader").fadeOut(200); } function mark_thread_as_read(user, correspondent_id) { $("a[correspondent_id="+correspondent_id+"]").find( "span.bg-danger" ).delay( 1300 ).fadeOut( 500 ); $.ajax({ type: "PUT", dataType: 'json', contentType: 'application/json', url: "//www.womex.com/virtual/api/mail/person/"+user+"/other_person/"+correspondent_id, success: function(data){ $("a[correspondent_id='"+correspondent_id+"']").children('span.danger').html(); }, error: function(e){ } }); } function send_company_email(message, subject,user, correspondent_id) { const json_message = JSON.stringify(sanitize(message)); const json_subject = JSON.stringify(sanitize(subject)); $.ajax({ type: "POST", dataType: 'json', contentType: 'application/json', url: "//www.womex.com/virtual/api/mail/person/"+user+"/other_company/"+correspondent_id, data: '{"text":'+json_message+', "subject":'+json_subject+'}', success: function(data){ $('div#emailModal').modal('hide'); $("div#send_message_okay").css('display', ''); $("div#send_message_okay").delay(1800).fadeOut(); clear_company_mail_form("#company_email"); }, error: function(e){ $("div#send_message_error").css('display', ''); $("div#send_message_error").delay(1800).fadeOut(); } }); } function send_admin_issue_email(message, subject,user,user_name, user_email, category, posting_id) { const json_message = JSON.stringify(sanitize(message)); const json_subject = JSON.stringify(sanitize(subject)); if (typeof user === 'undefined') { user = 0; } if (typeof user_name === 'undefined') { user_name = ""; } if (typeof user_email === 'undefined') { user_email = ""; } const json_user = JSON.stringify(user); const json_name = JSON.stringify(sanitize(user_name)); const json_email = JSON.stringify(sanitize(user_email)); const json_category = JSON.stringify(category); $.ajax({ type: "POST", dataType: 'json', contentType: 'application/json', url: "//www.womex.com/virtual/api/mail/admin/issue", data: '{"text":'+json_message+', "subject":'+json_subject+', "user_id":'+json_user+', "user_name":'+json_name+', "user_email":'+json_email+', "category":'+json_category+', "posting_id":'+posting_id+'}', success: function(data){ $('div#reportAnIssueModal').modal('hide'); $("div#send_message_okay").css('display', ''); $("div#send_message_okay").delay(1800).fadeOut(); }, error: function(e){ $("div#send_message_error").css('display', ''); $("div#send_message_error").delay(1800).fadeOut(); } }); } }); function company_recaptcha_check() { $("div#recaptcha_error").css('display', 'none'); localStorage.setItem("company_mail_captcha_valid", 1); company_mail_captcha_valid = 1; check_form("#company_email"); } function issue_mail_check() { $("div#recaptcha_error").css('display', 'none'); localStorage.setItem("issue_mail_captcha_valid", 1); issue_mail_captcha_valid = 1; check_form("#send_issue_form"); } function message_captcha_check() { $("div#recaptcha_error").css('display', 'none'); localStorage.setItem("message_captcha_valid", 1); message_captcha_valid = 1; let correspondent_id = $('button#send_message').attr('correspondent_id'); let message = $("textarea#chat_message").val(); send_message(message, l_person_id, correspondent_id); } function message_captcha_expired() { localStorage.setItem("message_captcha_valid", 0); message_captcha_valid = 0; } $('form#company_email input#subject').change(function() { check_form("#company_email"); }); $('form#company_email textarea#text').change(function() { check_form("#company_email"); }); $('form#send_issue_form input#issue_subject').change(function() { check_form("#send_issue_form"); }); $('form#send_issue_form textarea#issue_message').change(function() { check_form("#send_issue_form"); }); function check_form(form_id) { if (form_id == '#send_issue_form') { $(form_id).validate({ rules: { issue_subject: { required: true, minlength: 3 }, issue_text: { required: true, minlength: 3, }, }, messages: { subject: "Please enter a subject", text: "Please enter your message", } }); if ($("#send_issue_form").valid() && issue_mail_captcha_valid) { $("div#recaptcha_error").fadeOut(200); $('button#send_issue_mail').prop('disabled', false); return true; } else { $('button#send_issue_mail').prop('disabled', true); if (issue_mail_captcha_valid == 0) { $("div#recaptcha_error").fadeIn(200); } return false; } } else { $(form_id).validate({ rules: { subject: { required: true, minlength: 3 }, text: { required: true, minlength: 3, } }, messages: { subject: "Please enter a subject", text: "Please enter your message", } }); if ($("#company_email").valid() && company_mail_captcha_valid) { $("div#recaptcha_error").fadeOut(200); $('button#send_company_mail').prop('disabled', false); return true; } else { $('button#send_company_mail').prop('disabled', true); if (company_mail_captcha_valid == 0) { $("div#recaptcha_error").fadeIn(200); } return false; } } } function check_recaptcha(id, user) { let recaptcha_response = ''; let old_captcha = ''; let vw_category = $("input#issue_category").val(); if ((id == 'issue_mail_captcha') && (vw_category != 'companies')) { recaptcha_response = grecaptcha.getResponse(); old_captcha = localStorage.getItem("current_issue_mail_captcha"); } else if ((id == 'issue_mail_captcha') && (vw_category == 'companies') && user) { recaptcha_response = grecaptcha.getResponse(1); old_captcha = localStorage.getItem("current_company_mail_captcha"); } else if ((id == 'issue_mail_captcha') && (vw_category == 'companies') && (!user)) { recaptcha_response = grecaptcha.getResponse(); old_captcha = localStorage.getItem("current_company_mail_captcha"); } else if (id == 'company_mail_captcha') { recaptcha_response = grecaptcha.getResponse(); old_captcha = localStorage.getItem("current_company_mail_captcha"); } else if ((id == 'message_captcha') && user && (vw_category != 'companies') && (number_recaptchas == 2)) { recaptcha_response = grecaptcha.getResponse(1); old_captcha = localStorage.getItem("current_message_captcha"); } else if ((id == 'message_captcha') && (vw_category == 'companies') && user && (number_recaptchas == 3)) { recaptcha_response = grecaptcha.getResponse(2); old_captcha = localStorage.getItem("current_message_captcha"); } else if ((id == 'message_captcha') && (number_recaptchas == 1)) { recaptcha_response = grecaptcha.getResponse(); old_captcha = localStorage.getItem("current_message_captcha"); } if (recaptcha_response != '' && (old_captcha == recaptcha_response)) { return 1; } if (id == 'company_mail_captcha') { localStorage.setItem("current_company_mail_captcha", recaptcha_response); } else if (id == 'issue_mail_captcha') { localStorage.setItem("current_issue_mail_captcha", recaptcha_response); } else if (id == 'message_captcha') { localStorage.setItem("current_message_captcha", recaptcha_response); } if(recaptcha_response.length == 0) { $("div#recaptcha_error").fadeIn(200); if (id == 'company_mail_captcha') { company_mail_captcha_valid = 0; localStorage.setItem("company_mail_captcha_valid", 0); } else if (id == 'issue_mail_captcha') { issue_mail_captcha_valid = 0; localStorage.setItem("issue_mail_captcha_valid", 0); } else if (id == 'message_captcha') { message_captcha_valid = 0; localStorage.setItem("message_captcha_valid", 0); } } else { $("div#recaptcha_error").css('display', 'none'); if (id == 'company_mail_captcha') { company_mail_captcha_valid = 1; localStorage.setItem("company_mail_captcha_valid", 1); } else if (id == 'issue_mail_captcha') { issue_mail_captcha_valid = 1; localStorage.setItem("issue_mail_captcha_valid", 1); } else if (id == 'message_captcha') { message_captcha_valid = 1; localStorage.setItem("message_captcha_valid", 1); } } const json_recaptcha_response = JSON.stringify(recaptcha_response); let captcha_okay = 0; $.ajax({ type: "POST", dataType: 'json', contentType: 'application/json', async: false, url: "//www.womex.com/virtual/api/mail/check_captcha", data: '{"recaptcha_response":'+json_recaptcha_response+'}', success: function(data){ if (data.captcha_okay === 1) { captcha_okay = 1; } }, error: function(e){ } }); if (id == 'company_mail_captcha') { localStorage.setItem("company_mail_captcha_valid",captcha_okay); } else if (id == 'issue_mail_captcha') { localStorage.setItem("issue_mail_captcha_valid",captcha_okay); } else if (id == 'message_captcha') { localStorage.setItem("message_captcha_valid",captcha_okay); } return captcha_okay; } function clear_company_mail_form() { $('form#company_email input#subject').val(''); $('form#company_email textarea#text').val(''); }