diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index ebac2bc2f..5e86bade2 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -54,6 +54,7 @@ sign.in=Sign in register.new=or register yourself as a new user sign.up=Sign up register.title=Register +searchmenu=Search lesson not.empty=This field is required. diff --git a/src/main/resources/webgoat/static/js/search.js b/src/main/resources/webgoat/static/js/search.js new file mode 100644 index 000000000..1a56c2aec --- /dev/null +++ b/src/main/resources/webgoat/static/js/search.js @@ -0,0 +1,45 @@ +let input = document.getElementById('search'); +let timeout = null; + +input.addEventListener('keyup', function (e) { + clearTimeout(timeout); + timeout = setTimeout(function () { + //console.log('Value:', input.value); + search(input.value); + }, 1000); +}); + +function search(arg) { + var elementId = null; + lessons = document.querySelectorAll('[class="lesson"]'); + lessons.forEach(function(lesson) { + lessonLowerCase = lesson.textContent.toLowerCase(); + if (arg.length>2 && lessonLowerCase.includes(arg.toLowerCase())) { + if (arg.length<7 && arg.toLowerCase().includes('sql')) { + elementId = 'A3Injection-SQLInjectionintro'; + document.getElementById('search').value='sql injection'; + } else if (arg.length<9 && arg.toLowerCase().includes('pass')) { + elementId = 'A7IdentityAuthFailure-Passwordreset'; + document.getElementById('search').value='password'; + } else { + elementId = lesson.childNodes[0].id; + document.getElementById('search').value=lessonLowerCase; + } + } else { + return; + } + }); + + if (elementId != null) { + document.getElementById(elementId).click(); + categoryId = elementId.substring(0,elementId.indexOf("-")); + //extra click to make sure menu does not disappear on same category search + if (categoryId == 'Challenges') { + document.querySelectorAll('[category="Introduction"]')[0].click(); + } else { + document.querySelectorAll('[category="Challenges"]')[0].click(); + } + document.querySelectorAll('[category="'+categoryId+'"]')[0].click(); + } + +}; diff --git a/src/main/resources/webgoat/templates/main_new.html b/src/main/resources/webgoat/templates/main_new.html index 87efc9916..7a0f1d3b9 100644 --- a/src/main/resources/webgoat/templates/main_new.html +++ b/src/main/resources/webgoat/templates/main_new.html @@ -151,6 +151,8 @@ + +