diff --git a/assets/development/scripts/organization.js b/assets/development/scripts/organization.js index 14314bd..a40f525 100644 --- a/assets/development/scripts/organization.js +++ b/assets/development/scripts/organization.js @@ -123,3 +123,51 @@ let closeModal = () => { video.pause() } } + + +/** + * Decode things + */ + +let formatPhone = (phone) => { + if (phone.indexOf('+33') === 0) { + phone = '0' + phone.substr(3) + } + let phoneSplit = '' + let partEnd = false + for (var i = 0; i < phone.length; i++) { + phoneSplit += phone.charAt(i) + if (partEnd === true) { + phoneSplit += ' ' + } + partEnd = !partEnd + } + return ["+33" + phone.substr(1), phoneSplit] +} + +/** + * Decode email and phone data + */ +document.querySelectorAll('.offuscated').forEach(node => { + let data = node.getAttribute('data-source') + let type = node.getAttribute('data-source-type') + data = data.replace(/'/gm, '"').replace(/%_/gm, '') + data = data.replace(/\$/gm, 'A') + data = data.replace(/£/gm, 'c') + data = data.replace(/ù/gm, 'b') + data = data.replace(/#/gm, 'd') + data = data.replace(/µ/gm, 'e') + data = data.replace(/§/gm, 'z') + data = data.replace(/à/gm, 'i') + data = data.replace(/\|/gm, 'f') + data = JSON.parse(data).join('') + data = atob(data) + if (type === 'phone') { + data = formatPhone(data) + node.href = node.href.replace('data', data[0]) + data = data[1] + } else { + node.href = node.href.replace('data', data) + } + node.textContent = data +}) diff --git a/assets/production/scripts/organization.js b/assets/production/scripts/organization.js index d781d27..a3a1449 100644 --- a/assets/production/scripts/organization.js +++ b/assets/production/scripts/organization.js @@ -1 +1 @@ -document.querySelectorAll(".schedule-category").forEach(e=>{let t=!1,i=e.querySelector(".schedule-category-collapse-icon"),o=e.querySelector(".schedule-category-table");e.querySelector(".schedule-category-header").onclick=()=>{t?(i.style.transform="rotate(180deg)",o.style.maxHeight=null):(i.style.transform="rotate(0deg)",o.style.maxHeight=o.scrollHeight+"px"),t=!t}});let description=document.querySelector(".description-cutted"),descriptionActions=document.querySelector(".description-actions-container"),descriptionOpened=!1,defaultMaxHeight="";if(null!==description){let e=document.querySelector(".description-btn");e.onclick=()=>{descriptionOpened?(descriptionActions.className+=" closed",description.style.maxHeight=defaultMaxHeight,e.textContent="Ouvrir la description"):(descriptionActions.className=descriptionActions.className.replace(" closed",""),defaultMaxHeight=description.style.maxHeight,description.style.maxHeight=description.scrollHeight+"px",e.textContent="Fermer la description"),descriptionOpened=!descriptionOpened}}let mediaModal=document.querySelector("#media-modal"),mediaModalContent=document.querySelector("#media-modal-content"),openModal=(e,t)=>{mediaModal.style.visibility="visible",mediaModal.style.opacity=1,mediaModalContent.innerHTML="";let i=document.createAttribute("src");i.value=e;let o=null;if(t){o=document.createElement("video"),o.setAttribute("controls",""),o.setAttribute("autoplay",""),o.setAttribute("name","media");let t=document.createElement("source");t.setAttribute("src",e),t.setAttribute("type","video/mp4"),o.appendChild(t)}else o=document.createElement("img"),o.attributes.setNamedItem(i);mediaModalContent.appendChild(o),document.body.style.overflow="hidden",document.body.style.touchAction="none",setTimeout(()=>{const e=t=>{!mediaModalContent.contains(t.target)&&isVisible(mediaModalContent)&&(closeModal(),document.removeEventListener("click",e))};document.addEventListener("click",e)},100)};const isVisible=e=>!!e&&!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length);let closeModal=()=>{mediaModal.style.visibility="hidden",mediaModal.style.opacity=0,document.body.style.overflow="initial",document.body.style.height="initial";let e=document.querySelector("#media-modal video");null!==e&&e.pause()}; \ No newline at end of file +document.querySelectorAll(".schedule-category").forEach(e=>{let t=!1,o=e.querySelector(".schedule-category-collapse-icon"),i=e.querySelector(".schedule-category-table");e.querySelector(".schedule-category-header").onclick=()=>{t?(o.style.transform="rotate(180deg)",i.style.maxHeight=null):(o.style.transform="rotate(0deg)",i.style.maxHeight=i.scrollHeight+"px"),t=!t}});let description=document.querySelector(".description-cutted"),descriptionActions=document.querySelector(".description-actions-container"),descriptionOpened=!1,defaultMaxHeight="";if(null!==description){let e=document.querySelector(".description-btn");e.onclick=()=>{descriptionOpened?(descriptionActions.className+=" closed",description.style.maxHeight=defaultMaxHeight,e.textContent="Ouvrir la description"):(descriptionActions.className=descriptionActions.className.replace(" closed",""),defaultMaxHeight=description.style.maxHeight,description.style.maxHeight=description.scrollHeight+"px",e.textContent="Fermer la description"),descriptionOpened=!descriptionOpened}}let mediaModal=document.querySelector("#media-modal"),mediaModalContent=document.querySelector("#media-modal-content"),openModal=(e,t)=>{mediaModal.style.visibility="visible",mediaModal.style.opacity=1,mediaModalContent.innerHTML="";let o=document.createAttribute("src");o.value=e;let i=null;if(t){i=document.createElement("video"),i.setAttribute("controls",""),i.setAttribute("autoplay",""),i.setAttribute("name","media");let t=document.createElement("source");t.setAttribute("src",e),t.setAttribute("type","video/mp4"),i.appendChild(t)}else i=document.createElement("img"),i.attributes.setNamedItem(o);mediaModalContent.appendChild(i),document.body.style.overflow="hidden",document.body.style.touchAction="none",setTimeout(()=>{const e=t=>{!mediaModalContent.contains(t.target)&&isVisible(mediaModalContent)&&(closeModal(),document.removeEventListener("click",e))};document.addEventListener("click",e)},100)};const isVisible=e=>!!e&&!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length);let closeModal=()=>{mediaModal.style.visibility="hidden",mediaModal.style.opacity=0,document.body.style.overflow="initial",document.body.style.height="initial",document.body.style.touchAction="initial";let e=document.querySelector("#media-modal video");null!==e&&e.pause()},formatPhone=e=>{0===e.indexOf("+33")&&(e="0"+e.substr(3));let t="",o=!1;for(var i=0;i{let t=e.getAttribute("data-source"),o=e.getAttribute("data-source-type");t=t.replace(/'/gm,'"').replace(/%_/gm,""),t=t.replace(/\$/gm,"A"),t=t.replace(/£/gm,"c"),t=t.replace(/ù/gm,"b"),t=t.replace(/#/gm,"d"),t=t.replace(/µ/gm,"e"),t=t.replace(/§/gm,"z"),t=t.replace(/à/gm,"i"),t=t.replace(/\|/gm,"f"),t=JSON.parse(t).join(""),t=atob(t),"phone"===o?(t=formatPhone(t),e.href=e.href.replace("data",t[0]),t=t[1]):e.href=e.href.replace("data",t),e.textContent=t}); \ No newline at end of file diff --git a/src/controllers/PublicController.ts b/src/controllers/PublicController.ts index 9531756..fab8439 100644 --- a/src/controllers/PublicController.ts +++ b/src/controllers/PublicController.ts @@ -99,39 +99,73 @@ export default class PublicController { version.cover = { location: "https://fva-condorcet.s3.fr-par.scw.cloud/default-cover-plz-get-you-a-real-image.jpg" } } - let formatPhone = (phone: string) => { - if (phone.indexOf('+33') === 0) { - phone = '0' + phone.substr(3) - } - let phoneSplit = '' - let partEnd = false - for (var i = 0; i < phone.length; i++) { - phoneSplit += phone.charAt(i) - if (partEnd === true) { - phoneSplit += ' ' + let offuscate = (original: string) => { + if (original.length === 0) { return original } + let cipher: string[] = [] + let data: string = Buffer.from(original, 'utf-8').toString('base64') + data = data.replace(/A/gm, '$') + data = data.replace(/c/gm, '£') + data = data.replace(/b/gm, 'ù') + data = data.replace(/d/gm, '#') + data = data.replace(/e/gm, 'µ') + data = data.replace(/z/gm, '§') + data = data.replace(/i/gm, 'à') + data = data.replace(/f/gm, '|') + let remain = data + + let take: number = 0 + + while (remain.length != 0) { + take = remain.length + if (take > 5) { take = 5 } + take = Math.floor(Math.random() * (take + 1)) + if (take === 0) { take = 2 } + if (take > remain.length) { + take = remain.length } - partEnd = !partEnd + cipher.push('%_' + remain.substr(0, take) + '%_') + remain = remain.substr(take) } - return ["+33" + phone.substr(1), phoneSplit] + + return JSON.stringify(cipher).replace(/"/gm, "'") } + /** + * Parse contact + */ if (Utils.isUsable(version.contacts)) { + if (Utils.isStrUsable(version.contacts, 'email')) { + version.contacts.email = offuscate(version.contacts.email) + } if (Utils.isStrUsable(version.contacts, 'address')) { version.contacts.address = version.contacts.address.split('\n') } if (Utils.isStrUsable(version.contacts, 'phone')) { - let formated: any = formatPhone(version.contacts.phone) - version.contacts.phoneInt = formated[0] - version.contacts.phoneSplit = formated[1] + //let formated: any = formatPhone(version.contacts.phone) + version.contacts.phone = offuscate(version.contacts.phone) } if (Utils.isUsable(version.contacts, 'peoples') && Array.isArray(version.contacts.peoples)) { version.contacts.peoples = version.contacts.peoples.map((p: any) => { - let formated: any = formatPhone(p.phone) - p.phoneInt = formated[0] - p.phoneSplit = formated[1] + // let formated: any = formatPhone(p.phone) + // p.phoneInt = formated[0] + // p.phoneSplit = formated[1] + p.email = offuscate(p.email) + p.phone = offuscate(p.phone) return p }) } + if (Utils.isStrUsable(version.contacts, 'website')) { + if (version.contacts.website.indexOf('https://') === -1 || version.contacts.website.indexOf('https://') === -1) { + version.contacts.website = 'http://' + version.contacts.website + } + try { + let url = new URL(version.contacts.website) + version.contacts.websiteLabel = url.hostname + (url.pathname === '/' ? '' : url.pathname) + } catch (err) { + console.error(err) + version.contacts.website = version.contacts.websiteLabel = "OULA, c'est pas bon :(" + } + } if (Utils.isStrUsable(version.contacts, 'facebook')) { try { version.contacts.facebookLabel = new URL(version.contacts.facebook).pathname.replace('/', '') @@ -157,12 +191,20 @@ export default class PublicController { } } } + + /** + * Parse gallery + */ if (Array.isArray(version.gallery)) { version.gallery = version.gallery.slice(0, 5).map((media: any) => { media.isVideo = media.contentType.indexOf('video/') !== -1 return media }) } + + /** + * Parse schedule + */ if (Utils.isUsable(version, 'schedule')) { // TODO: Rassembler les horaires qui sont dans le même jour, uniquement pour le front version.schedule = version.schedule.map((s: any) => { @@ -193,6 +235,12 @@ export default class PublicController { // if (hour.charAt(1) === ':') { // hour = '0' + hour // } + + /** + * Obfuscate emails and phone + */ + + res.render('organization.twig', { layout: 'standalone', data: version, diff --git a/views/organization.twig b/views/organization.twig index 3cee8f5..83f9a61 100644 --- a/views/organization.twig +++ b/views/organization.twig @@ -202,17 +202,23 @@ - - {{ data.contacts.email|e }} + - {% if data.contacts.phoneInt is not empty %} + {% if data.contacts.phone is not empty %}
- - {{ data.contacts.phoneSplit|e }} +
{% endif %} @@ -233,18 +239,26 @@ - - {{ people.email|e }} + + {% if people.phone is not empty %}
- - {{ people.phoneSplit|e }} +
+ {% endif %} {% endfor %} @@ -310,7 +324,7 @@
- {{ data.contacts.website|e }} + {{ data.contacts.websiteLabel|e }}