Wed, 31 Jul 2013 19:48:00 +0200
Introduce port to the Tizen OS.
michael@14 | 1 | /* |
michael@14 | 2 | * OTPWCalc - One time password challenge response calculator client |
michael@14 | 3 | * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com> |
michael@14 | 4 | * |
michael@14 | 5 | * OTPWCalc is free software: you can redistribute it and/or modify |
michael@14 | 6 | * it under the terms of the European Union Public Licence, either |
michael@14 | 7 | * version 1.1 of the license, or (at your option) any later version. |
michael@14 | 8 | * |
michael@14 | 9 | * OTPWCalc is distributed in the hope that it will be useful, |
michael@14 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty |
michael@14 | 11 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
michael@14 | 12 | * the European Union Public License for more details. |
michael@14 | 13 | * |
michael@14 | 14 | * You should have received a copy of the European Union Public |
michael@14 | 15 | * Licence along with OTPWCalc. If not, please refer to |
michael@14 | 16 | * <http://joinup.ec.europa.eu/software/page/eupl/>. |
michael@14 | 17 | * |
michael@14 | 18 | * This file is part of project OTWPCalc, a one time password challenge |
michael@14 | 19 | * response calculator client and is found at http://otpwcalc.europalab.com/ |
michael@14 | 20 | * |
michael@14 | 21 | * main.js: ECMA JavaScript implementation |
michael@14 | 22 | */ |
michael@14 | 23 | |
michael@14 | 24 | // <![CDATA[ |
michael@14 | 25 | //// This doesn't work with AJAX (use pageinit instead) |
michael@14 | 26 | //// That means JavaScript in the head of any other HTML |
michael@14 | 27 | //// will be ignored, only the data-role="page" is parsed |
michael@14 | 28 | //$(document).ready(function() { |
michael@14 | 29 | //$.mobile.ajaxLinksEnabled = false; |
michael@14 | 30 | //}); |
michael@14 | 31 | $(document).on("mobileinit", function() { |
michael@14 | 32 | $.extend($.mobile, { |
michael@14 | 33 | pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.' |
michael@14 | 34 | }); |
michael@14 | 35 | }); |
michael@14 | 36 | //$(document).on("pageinit", function() { |
michael@14 | 37 | //}); |
michael@14 | 38 | $(document).on("pageinit", "[data-role='page'].oc-swipage", function() { |
michael@14 | 39 | var makepage = "#" + $(this).attr("id"), |
michael@14 | 40 | next = $(this).jqmData("next"), // Next page stored in data-next |
michael@14 | 41 | prev = $(this).jqmData("prev"); // Previous page stored in data-prev |
michael@14 | 42 | |
michael@14 | 43 | if (next) { // Check if data-next attribute is indeed set |
michael@14 | 44 | //// Prefetch next page |
michael@14 | 45 | //$.mobile.loadPage(next); |
michael@14 | 46 | // Navigate to next page on swipe left |
michael@14 | 47 | $(document).on("swipeleft", makepage, function(inev) { |
michael@14 | 48 | inev.stopImmediatePropagation(); |
michael@14 | 49 | $.mobile.changePage(next, {transition: "slide"}); |
michael@14 | 50 | }); |
michael@14 | 51 | } |
michael@14 | 52 | else { // If data-next not set then default to history |
michael@14 | 53 | $(document).on("swipeleft", makepage, function(inev) { |
michael@14 | 54 | inev.stopImmediatePropagation(); |
michael@14 | 55 | window.history.forward({transition: "slide"}); |
michael@14 | 56 | }); |
michael@14 | 57 | } |
michael@14 | 58 | if (prev) { // Check if data-prev attribute is set |
michael@14 | 59 | $(document).on("swiperight", makepage, function(inev) { |
michael@14 | 60 | inev.stopImmediatePropagation(); |
michael@14 | 61 | $.mobile.changePage(prev, {transition: "slide", reverse: true}); |
michael@14 | 62 | }); |
michael@14 | 63 | } |
michael@14 | 64 | else { // If data-prev not set then default to history |
michael@14 | 65 | $(document).on("swiperight", makepage, function(inev) { |
michael@14 | 66 | inev.stopImmediatePropagation(); |
michael@14 | 67 | //history.back(); // or window.history.back(); |
michael@14 | 68 | $.mobile.back({transition: "slide", reverse: true}); |
michael@14 | 69 | }); |
michael@14 | 70 | } |
michael@14 | 71 | }); |
michael@14 | 72 | |
michael@14 | 73 | // the main logical entry point |
michael@14 | 74 | function otpwcalc() { |
michael@14 | 75 | var secr = $('#paswrd').val(); |
michael@14 | 76 | var user = $('#seedid').val(); |
michael@14 | 77 | var iter = parseInt($('#crement').val(), 10); |
michael@14 | 78 | var hash = genotpmd5; |
michael@14 | 79 | if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1') |
michael@14 | 80 | hash = genotpsha1; |
michael@14 | 81 | else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160') |
michael@14 | 82 | hash = genotprmd160; |
michael@14 | 83 | var form = arrtosix; |
michael@14 | 84 | if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex') |
michael@14 | 85 | form = arrtohex; |
michael@14 | 86 | var resp = hash(secr, user, iter); |
michael@14 | 87 | //var resp = sjcl.random.randomWords(1,0); |
michael@14 | 88 | return form(resp); |
michael@14 | 89 | } |
michael@14 | 90 | |
michael@14 | 91 | // helper function |
michael@14 | 92 | function dosubmit() { |
michael@14 | 93 | if ($('#seedid').val().length == 0) { |
michael@14 | 94 | $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID'); |
michael@14 | 95 | return false; |
michael@14 | 96 | } |
michael@14 | 97 | else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) { |
michael@14 | 98 | $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #'); |
michael@14 | 99 | return false; |
michael@14 | 100 | } |
michael@14 | 101 | else { |
michael@14 | 102 | $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc()); |
michael@14 | 103 | $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val()); |
michael@14 | 104 | return false; |
michael@14 | 105 | } |
michael@14 | 106 | } |
michael@14 | 107 | |
michael@14 | 108 | // helper function |
michael@14 | 109 | function doreset() { |
michael@14 | 110 | $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP'); |
michael@14 | 111 | return true; |
michael@14 | 112 | } |
michael@14 | 113 | // ]]> |