1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/tizen/main.js Wed Jul 31 19:48:00 2013 +0200 1.3 @@ -0,0 +1,113 @@ 1.4 +/* 1.5 + * OTPWCalc - One time password challenge response calculator client 1.6 + * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com> 1.7 + * 1.8 + * OTPWCalc is free software: you can redistribute it and/or modify 1.9 + * it under the terms of the European Union Public Licence, either 1.10 + * version 1.1 of the license, or (at your option) any later version. 1.11 + * 1.12 + * OTPWCalc is distributed in the hope that it will be useful, 1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty 1.14 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 1.15 + * the European Union Public License for more details. 1.16 + * 1.17 + * You should have received a copy of the European Union Public 1.18 + * Licence along with OTPWCalc. If not, please refer to 1.19 + * <http://joinup.ec.europa.eu/software/page/eupl/>. 1.20 + * 1.21 + * This file is part of project OTWPCalc, a one time password challenge 1.22 + * response calculator client and is found at http://otpwcalc.europalab.com/ 1.23 + * 1.24 + * main.js: ECMA JavaScript implementation 1.25 + */ 1.26 + 1.27 +// <![CDATA[ 1.28 +//// This doesn't work with AJAX (use pageinit instead) 1.29 +//// That means JavaScript in the head of any other HTML 1.30 +//// will be ignored, only the data-role="page" is parsed 1.31 +//$(document).ready(function() { 1.32 + //$.mobile.ajaxLinksEnabled = false; 1.33 +//}); 1.34 +$(document).on("mobileinit", function() { 1.35 + $.extend($.mobile, { 1.36 + pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.' 1.37 + }); 1.38 +}); 1.39 +//$(document).on("pageinit", function() { 1.40 +//}); 1.41 +$(document).on("pageinit", "[data-role='page'].oc-swipage", function() { 1.42 + var makepage = "#" + $(this).attr("id"), 1.43 + next = $(this).jqmData("next"), // Next page stored in data-next 1.44 + prev = $(this).jqmData("prev"); // Previous page stored in data-prev 1.45 + 1.46 + if (next) { // Check if data-next attribute is indeed set 1.47 + //// Prefetch next page 1.48 + //$.mobile.loadPage(next); 1.49 + // Navigate to next page on swipe left 1.50 + $(document).on("swipeleft", makepage, function(inev) { 1.51 + inev.stopImmediatePropagation(); 1.52 + $.mobile.changePage(next, {transition: "slide"}); 1.53 + }); 1.54 + } 1.55 + else { // If data-next not set then default to history 1.56 + $(document).on("swipeleft", makepage, function(inev) { 1.57 + inev.stopImmediatePropagation(); 1.58 + window.history.forward({transition: "slide"}); 1.59 + }); 1.60 + } 1.61 + if (prev) { // Check if data-prev attribute is set 1.62 + $(document).on("swiperight", makepage, function(inev) { 1.63 + inev.stopImmediatePropagation(); 1.64 + $.mobile.changePage(prev, {transition: "slide", reverse: true}); 1.65 + }); 1.66 + } 1.67 + else { // If data-prev not set then default to history 1.68 + $(document).on("swiperight", makepage, function(inev) { 1.69 + inev.stopImmediatePropagation(); 1.70 + //history.back(); // or window.history.back(); 1.71 + $.mobile.back({transition: "slide", reverse: true}); 1.72 + }); 1.73 + } 1.74 +}); 1.75 + 1.76 +// the main logical entry point 1.77 +function otpwcalc() { 1.78 + var secr = $('#paswrd').val(); 1.79 + var user = $('#seedid').val(); 1.80 + var iter = parseInt($('#crement').val(), 10); 1.81 + var hash = genotpmd5; 1.82 + if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1') 1.83 + hash = genotpsha1; 1.84 + else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160') 1.85 + hash = genotprmd160; 1.86 + var form = arrtosix; 1.87 + if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex') 1.88 + form = arrtohex; 1.89 + var resp = hash(secr, user, iter); 1.90 + //var resp = sjcl.random.randomWords(1,0); 1.91 + return form(resp); 1.92 +} 1.93 + 1.94 +// helper function 1.95 +function dosubmit() { 1.96 + if ($('#seedid').val().length == 0) { 1.97 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID'); 1.98 + return false; 1.99 + } 1.100 + else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) { 1.101 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #'); 1.102 + return false; 1.103 + } 1.104 + else { 1.105 + $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc()); 1.106 + $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val()); 1.107 + return false; 1.108 + } 1.109 +} 1.110 + 1.111 +// helper function 1.112 +function doreset() { 1.113 + $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP'); 1.114 + return true; 1.115 +} 1.116 +// ]]>