Преглед на файлове

Added some basic input validation

carlos.diaz44 преди 4 години
родител
ревизия
bbf139c3c0

+ 84
- 54
platforms/android/app/src/main/assets/www/index.html Целия файл

@@ -259,7 +259,7 @@
259 259
                             //'title':'${Artesano.Nombre}','esp': '${info}'
260 260
                             //Tries to pass all the info of each artesano into a new page, the page that display this information is 'artesano.html', not to be confused with 'artesanias.html' or 'artesanos.html'(current page)
261 261
                             //And puts this into the 'item' variable
262
-                            var item = ons.createElement(`<ons-list-item onclick="myNavigator.pushPage('artesano.html', { data: { title: '${Artesano.Nombre.replace(/"/g, " ")}', mun: '${Artesano.Municipio}', tel: '${Artesano["Telefono 1"]}', email: '${Artesano["Email"]}', esp: '${Artesano.Especificacion}', redes: '${Artesano["E-Commerce 1"]}', tecnicas: '${Artesano["Tecnica"]}' } })" tappable>
262
+                            var item = ons.createElement(`<ons-list-item onclick="myNavigator.pushPage('artesano.html', { data: { title: '${Artesano.Nombre.replace(/"/g, " ")}', mun: '${Artesano.Municipio}', tel: '${Artesano["Telefono 1"]}', email: '${Artesano["Email"]}', esp: '${Artesano.Especificacion}', red1: '${Artesano["Red Social 1"]}', red2: '${Artesano["Red Social 2"]}', ecom: '${Artesano["E-Commerce 1"]}', tecnicas: '${Artesano["Tecnica"]}' } })" tappable>
263 263
                         <div class="title">${Artesano.Nombre}</div>
264 264
                     </ons-list-item>`);
265 265
 
@@ -364,14 +364,14 @@
364 364
                              });*/
365 365
 
366 366
                              for(var i=0; i<results.length; i++) {
367
-
367
+                                
368 368
                                  //if(Esp[num] in artesanos_json.) {}
369 369
                                  //results[i].Nombre = results[i].Nombre + " " + results[i]["Apellido Paterno"] + " " + results[i]["Apellido Materno"]
370 370
                                  ANombre = results[i].Nombre + " " + results[i]["Apellido Paterno"] + " " + results[i]["Apellido Materno"]
371 371
                                  Artesanos+=`${ANombre}|`
372
-                                 ArtesanosInfo+=`${results[i].Municipio}|${results[i]["Telefono 1"]}|${results[i]["Email"]}|${results[i].Especificacion}|${results[i]["Tecnica"]}&&`
372
+                                 ArtesanosInfo+=`${results[i].Municipio}|${results[i]["Telefono 1"]}|${results[i]["Email"]}|${results[i].Especificacion}|${results[i]["E-Commerce 1"]}|${results[i]["Red Social 1"]}|${results[i]["Red Social 2"]}|${results[i]["Tecnica"]}&&`
373 373
                                  //`<a id='home.html'>${Artesania.artesano} | ${Artesania.municipio}</a> `
374
-                             }
374
+                                }
375 375
 
376 376
                              return {
377 377
                                  name: Esp[num],
@@ -400,17 +400,20 @@
400 400
                                      tel = lot[1],
401 401
                                      email = lot[2],
402 402
                                      esp = lot[3],
403
-                                     redes = lot[4],
404
-                                     tecnicas = lot[5];
403
+                                     ecom = lot[4],
404
+                                     red1 = lot[5];
405
+                                     red2 = lot[6];
406
+                                     tecnicas = lot[7]
407
+                                     console.log(lot)
405 408
 
406
-                                 listaArt += `<ons-item tappable onclick="myNavigator.pushPage('artesano.html', {data: {title:'${arts[i].replace(/"/g, " ")}', mun: '${mun}', tel: '${tel}', email: '${email}', esp: '${esp}', redes: '${redes}', tecnicas: '${tecnicas}' }} )" ><div class="center">`+ arts[i] +`</div></ons-item><br>`;
409
+                                 listaArt += `<ons-item tappable onclick="myNavigator.pushPage('artesano.html', {data: {title:'${arts[i].replace(/"/g, " ")}', mun: '${mun}', tel: '${tel}', email: '${email}', esp: '${esp}', red1: '${red1}', red2: '${red2}', ecom: '${ecom}', tecnicas: '${tecnicas}' }} )" ><div class="center">`+ arts[i] +`</div></ons-item><br>`;
407 410
                              }
408 411
 
409 412
                              if (Artesania.name == "Figuras y simbolos indigenas") {
410 413
                                  Artesania.name = "Figuras y símbolos indígenas";
411 414
                              } 
412 415
 
413
-                             console.log(Artesania.name);
416
+        
414 417
 
415 418
                              return ons.createElement(`
416 419
               <ons-list-item expandable tappable>
@@ -469,6 +472,11 @@
469 472
                 var inputarte = document.getElementById('searchartesania').value;
470 473
                 var inputmuni = document.getElementById('searchbarmunicipio').value;
471 474
                 var x = document.getElementsByClassName('artists');
475
+
476
+                //validating input so that its not as easy to attack
477
+                input = input_validation(input);
478
+                inputarte = input_validation(inputarte);
479
+                inputmuni = input_validation(inputmuni);
472 480
                 //just making sure everything is at the same format by taking out special characters, trimming it and putting it in lowercase (same thing will be done to the arguments it's being compared to later on)
473 481
                 //acento_replace(): it's a function I made that takes out any special characters of a word and changes them back to the plain ones (quitar acentos o cosas asi)
474 482
                 input = input.trim().toLowerCase();
@@ -551,7 +559,7 @@
551 559
                     for (i = 0; i < all_artesanos.length;i++){
552 560
                         all_artesanos[i].Nombre = all_artesanos[i].Nombre +  " " + all_artesanos[i]["Apellido Paterno"] + " " + all_artesanos[i]["Apellido Materno"];
553 561
                         var artesano = ons.createElement(`<ons-list-item class = "artists"
554
-                        onclick="SNavigator.pushPage('artesano_s.html', { data: {title: '${all_artesanos[i].Nombre.replace(/"/g, " ")}', mun: '${all_artesanos[i].Municipio}', tel: '${all_artesanos[i]["Telefono 1"]}', email: '${all_artesanos[i]["Email"]}', esp: '${all_artesanos[i].Especificacion}', redes: '${all_artesanos[i]["E-Commerce 1"]}', tecnicas: '${all_artesanos[i]["Tecnica"]}' } })" tappable>
562
+                        onclick="SNavigator.pushPage('artesano_s.html', { data: {title: '${all_artesanos[i].Nombre.replace(/"/g, " ")}', mun: '${all_artesanos[i].Municipio}', tel: '${all_artesanos[i]["Telefono 1"]}', email: '${all_artesanos[i]["Email"]}', esp: '${all_artesanos[i].Especificacion}', red1: '${all_artesanos[i]["Red Social 1"]}', red2: '${all_artesanos[i]["Red Social 2"]}', ecom: '${all_artesanos[i]["E-Commerce 1"]}', tecnicas: '${all_artesanos[i]["Tecnica"]}' } })" tappable>
555 563
                         <div>${all_artesanos[i].Nombre}</div>
556 564
                     </ons-list-item>`);
557 565
                         document.getElementById('results').appendChild(artesano);
@@ -587,9 +595,13 @@
587 595
                             tel = this.data.tel,
588 596
                             em = this.data.email,
589 597
                             esp = this.data.esp,
590
-                            redes = this.data.redes,
598
+                            red1 = this.data.red1,
599
+                            red2 = this.data.red2,
600
+                            ecom = this.data.ecom,
591 601
                             tecnicas = this.data.tecnicas;
592 602
 
603
+                            
604
+
593 605
                         //here the email is the string made from the start to where the '#' is.
594 606
                         
595 607
 
@@ -638,37 +650,43 @@
638 650
                             data+='Tel\u00e9fono: <a style="color:blue" href="tel: '+ tel +'"><u>'+ tel +'</u></a><br>';
639 651
                         }
640 652
 
641
-                        console.log("Redes: "+redes);
653
+                        
642 654
 
643 655
                         //Here it has to decide what to do depending on the links they give to their social media pages
644 656
                         //if the link is to a facebook, instagram or myspace account then it will show the picture of the social media site, and when you click the picture then the app redirects you to their social media.
645
-                        //The alt attribute is required for images, it's in case theres no internet connection, then it will display that tet instead, I think screen readers can also read that text
646
-                        //If the link is to another website (but isn't a mailto link) then it will display a default picture we chose to display a default web browser, like the other ones clikcing on it will take you to the link.
657
+                        
658
+                        
647 659
                         //If it's none of them then it will not display anything
648
-                        if(redes.includes("facebook")){
649
-
650
-                            console.log(redes.substring(1,redes.length-2));
651
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;"><br>';
660
+                        //First Social Media
661
+                        if(red1.includes("facebook")){
662
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;">';
652 663
                         }
653
-                        else if(redes.includes("instagram")){
654
-                            console.log(redes.substring(1,redes.length-2));
655
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;"><br>';
664
+                        else if(red1.includes("instagram")){
665
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;">';
656 666
                         }
657
-                        else if(redes.includes("myspace")){
658
-                            console.log(redes.substring(1,redes.length-2));
659
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;"><br>';
667
+                        else if(red1.includes("myspace")){
668
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;">';
660 669
                         }
661
-                        else if((redes.includes(".org") || redes.includes(".com")) && !redes.includes("mailto")){
662
-                            redes = redes.substr(redes.indexOf("#")+1,redes.length);
663
-                            redes = redes.substr(0, redes.length-1);
664
-                            console.log(redes);
665
-                            data+='<br><a href="'+ redes + '"><img src="img/internet.jpg" style="width:35px;height:35px;border:0;"><br>';
670
+
671
+                        //Second Social Media
672
+                        if(red2.includes("facebook")){
673
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;">';
674
+                        }
675
+                        else if(red2.includes("instagram")){
676
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;">';
666 677
                         }
667
-                        else if(redes.includes("#") || redes.includes("mailto")){
668
-                            console.log("tiene un disparate");
669
-                        } else {
670
-                            console.log("no tiene nada");
678
+                        else if(red2.includes("myspace")){
679
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;">';
671 680
                         }
681
+                        
682
+                        //E-commerce 
683
+                        if ((ecom.includes(".org") || ecom.includes(".com")) && !ecom.includes("mailto")){
684
+                            ecom = ecom.substr(ecom.indexOf("#")+1,ecom.length);
685
+                            ecom = ecom.substr(0, ecom.length-1);
686
+                            
687
+                            data+='<a href="'+ ecom + '"><img src="img/internet.jpg" style="width:35px;height:35px;border:0;">';
688
+                        }
689
+                        
672 690
 
673 691
                         //This is the part that allows eveything (data) to be displayed
674 692
                         document.getElementById("all").innerHTML = `${data}`;
@@ -701,7 +719,9 @@
701 719
                             tel = this.data.tel,
702 720
                             em = this.data.email,
703 721
                             esp = this.data.esp,
704
-                            redes = this.data.redes,
722
+                            red1 = this.data.red1,
723
+                            red2 = this.data.red2,
724
+                            ecom = this.data.ecom,
705 725
                             tecnicas = this.data.tecnicas;
706 726
 
707 727
                         //here the email is the string made from the start to where the '#' is.
@@ -711,6 +731,11 @@
711 731
                         //if it has many especificaciones then it will replace all the ';' in it with ',' and writes it into the page
712 732
                         //but if theres only one then you just write it into the page
713 733
                         if(esp.trim() != ""){
734
+
735
+                            if(esp.includes("Figuras y simbolos indigenas")) {
736
+                                esp = esp.replace("Figuras y simbolos indigenas", "Figuras y símbolos indígenas")
737
+                            }
738
+
714 739
                             if(esp.includes(";", 0)){
715 740
                                 esp=esp.replace(/;/g,", ");
716 741
                                 data+='Tipos de artesanías: '+esp+'<br>';
@@ -746,37 +771,42 @@
746 771
                             data+='Tel\u00e9fono: <a style="color:blue" href="tel: '+ tel +'"><u>'+ tel +'</u></a><br>';
747 772
                         }
748 773
 
749
-                        console.log("Redes: "+redes);
774
+                        
750 775
 
751 776
                         //Here it has to decide what to do depending on the links they give to their social media pages
752 777
                         //if the link is to a facebook, instagram or myspace account then it will show the picture of the social media site, and when you click the picture then the app redirects you to their social media.
753 778
                         //The alt attribute is required for images, it's in case theres no internet connection, then it will display that tet instead, I think screen readers can also read that text
754 779
                         //If the link is to another website (but isn't a mailto link) then it will display a default picture we chose to display a default web browser, like the other ones clikcing on it will take you to the link.
755 780
                         //If it's none of them then it will not display anything
756
-                        if(redes.includes("facebook")){
757
-
758
-                            console.log(redes.substring(1,redes.length-2));
759
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;"><br>';
781
+                        if(red1.includes("facebook")){
782
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;">';
783
+                        }
784
+                        else if(red1.includes("instagram")){
785
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;">';
760 786
                         }
761
-                        else if(redes.includes("instagram")){
762
-                            console.log(redes.substring(1,redes.length-2));
763
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;"><br>';
787
+                        else if(red1.includes("myspace")){
788
+                            data+='<a style="margin-right:10px;" href="'+ red1 + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;">';
789
+                        }
790
+
791
+                        //Second Social Media
792
+                        if(red2.includes("facebook")){
793
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/facebook.png" alt="Facebook"style="width:35px;height:35px;border:0;">';
764 794
                         }
765
-                        else if(redes.includes("myspace")){
766
-                            console.log(redes.substring(1,redes.length-2));
767
-                            data+='<br><a href="'+ redes.substring(1,redes.length-2) + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;"><br>';
795
+                        else if(red2.includes("instagram")){
796
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/instagram.png" alt="Instagram"style="width:35px;height:35px;border:0;">';
768 797
                         }
769
-                        else if((redes.includes(".org") || redes.includes(".com")) && !redes.includes("mailto")){
770
-                            redes = redes.substr(redes.indexOf("#")+1,redes.length);
771
-                            redes = redes.substr(0, redes.length-1);
772
-                            console.log(redes);
773
-                            data+='<br><a href="'+ redes + '"><img src="img/internet.jpg" style="width:35px;height:35px;border:0;"><br>';
798
+                        else if(red2.includes("myspace")){
799
+                            data+='<a style="margin-right:10px;" href="'+ red2 + '"><img src="img/MySpace.png" alt="MySpace"style="width:35px;height:35px;border:0;">';
774 800
                         }
775
-                        else if(redes.includes("#") || redes.includes("mailto")){
776
-                            console.log("tiene un disparate");
777
-                        } else {
778
-                            console.log("no tiene nada");
801
+
802
+
803
+                        if((ecom.includes(".org") || ecom.includes(".com")) && !ecom.includes("mailto")){
804
+                            ecom = ecom.substr(ecom.indexOf("#")+1,ecom.length);
805
+                            ecom = ecom.substr(0, ecom.length-1);
806
+
807
+                            data+='<a href="'+ ecom + '"><img src="img/internet.jpg" style="width:35px;height:35px;border:0;">';
779 808
                         }
809
+                        
780 810
 
781 811
                         //This is the part that allows eveything (data) to be displayed
782 812
                         document.getElementById("all2").innerHTML = `${data}`;
@@ -840,7 +870,7 @@
840 870
                 </div>
841 871
                 <br><br>
842 872
                 <div id="button" style="text-align: center">
843
-                <button onclick="redirect()">Pasar a la página de eventos</button>
873
+                <ons-button onclick="redirect()" modifier="large" style="background-color: #00abc1;"> Pasar a la página de eventos </ons-button>
844 874
                 </div>
845 875
                 <br><br>
846 876
                 <div id="Mensaje">

+ 6
- 1
platforms/android/app/src/main/assets/www/js/index.js Целия файл

@@ -28,7 +28,12 @@ var app = {
28 28
     // 'pause', 'resume', etc.
29 29
     onDeviceReady: function() {
30 30
 
31
-        if (ons.platform.isIPhone()) { 
31
+        //A list of device models that have notches that interfere with page content.
32
+        //OnsenUi has the isIPhoneX boolean value, however, it does not detect IPhone 11 or 12 types. 
33
+        var notchDevices = ["iPhone12,1", "iPhone12,3", "iPhone12,5", "iPhone13,1", "iPhone13,2", "iPhone13,3", "iPhone13,4"]
34
+
35
+
36
+        if (ons.platform.isIPhoneX() || notchDevices.includes(device.model)) { 
32 37
             document.documentElement.setAttribute('onsflag-iphonex-portrait', '');
33 38
             document.documentElement.setAttribute('onsflag-iphonex-landscape', '');
34 39
         }

+ 9
- 3
platforms/android/app/src/main/assets/www/js/saveLocal.js Целия файл

@@ -1,5 +1,11 @@
1
-localStorage.setItem("RENGLONES", loadFile("https://artesaniaspr.website/renglones2.json"));
2
-localStorage.setItem("AZAR", loadFile("https://artesaniaspr.website/azar.json"));
1
+try {
2
+  localStorage.setItem("RENGLONES", loadFile("https://artesaniaspr.website/renglones2.json"));
3
+  localStorage.setItem("AZAR", loadFile("https://artesaniaspr.website/azar.json"));
4
+  
5
+} catch {
6
+  console.log("Files not found")
7
+}
8
+
3 9
 let renglones = JSON.parse(window.localStorage.getItem("RENGLONES"));
4 10
 
5 11
 //A synchronous request to the server 
@@ -18,7 +24,7 @@ function loadFile(filePath) {
18 24
 //Checks if date has changed in the server or if number or renglones has been shortened (since local storage can be erased when the device runs out of memory)
19 25
 function checkDate() {
20 26
   var date = loadFile("https://artesaniaspr.website/date.txt");
21
-  if (localStorage.getItem("DATE") == null || localStorage.getItem("DATE") != date || localStorage.length < 17) {
27
+  if (localStorage.getItem("DATE") == null || localStorage.getItem("DATE") != date || localStorage.length < 18) {
22 28
   localStorage.setItem("DATE", date);
23 29
     return false;
24 30
   }

+ 16
- 1
platforms/android/app/src/main/assets/www/js/searchfunctions.js Целия файл

@@ -280,5 +280,20 @@ function acento_replace(string){
280 280
             }
281 281
         }
282 282
     }
283
-    return string;
283
+    return string;   
284
+}
285
+function input_validation(input){
286
+    if (input.length > 40){
287
+        input = "";
288
+        return input;
289
+    }
290
+    else if (input.search('<') != -1){
291
+        input = "";
292
+        return input;
293
+    }
294
+    else if (input.search('>') != -1){
295
+    	input = "";
296
+    	return input;
297
+    }
298
+    return input;
284 299
 }

+ 6
- 0
www/index.html Целия файл

@@ -472,6 +472,12 @@
472 472
                 var inputarte = document.getElementById('searchartesania').value;
473 473
                 var inputmuni = document.getElementById('searchbarmunicipio').value;
474 474
                 var x = document.getElementsByClassName('artists');
475
+
476
+                //validating input so that its not as easy to attack
477
+                //no acepta strings mayores que 40 caracteres y no acepta '>' o '<' en el string
478
+                input = input_validation(input);
479
+                inputarte = input_validation(inputarte);
480
+                inputmuni = input_validation(inputmuni);
475 481
                 //just making sure everything is at the same format by taking out special characters, trimming it and putting it in lowercase (same thing will be done to the arguments it's being compared to later on)
476 482
                 //acento_replace(): it's a function I made that takes out any special characters of a word and changes them back to the plain ones (quitar acentos o cosas asi)
477 483
                 input = input.trim().toLowerCase();

+ 16
- 1
www/js/searchfunctions.js Целия файл

@@ -280,5 +280,20 @@ function acento_replace(string){
280 280
             }
281 281
         }
282 282
     }
283
-    return string;
283
+    return string;   
284
+}
285
+function input_validation(input){
286
+    if (input.length > 40){
287
+        input = "";
288
+        return input;
289
+    }
290
+    else if (input.search('<') != -1){
291
+        input = "";
292
+        return input;
293
+    }
294
+    else if (input.search('>') != -1){
295
+    	input = "";
296
+    	return input;
297
+    }
298
+    return input;
284 299
 }