Subversion Repositories oidplus

Rev

Rev 782 | Rev 1017 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
709 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
var OIDplusCaptchaPluginVtsClientChallenge = {
19
 
20
        oid: "1.3.6.1.4.1.37476.2.5.2.4.11.3",
21
 
22
        currentchallenge: [null,null,null,null,null,null],
23
        currentresponse: null,
24
 
25
        captchaResponse: function() {
26
                var data = OIDplusCaptchaPluginVtsClientChallenge.currentchallenge;
27
                var starttime = data[0];
28
                var ip_target = data[1];
29
                var challenge = data[2];
30
                var min = data[3];
31
                var max = data[4];
32
                var challenge_integrity = data[5];
33
 
34
                //$("#loading").show();
35
                // Without setTimeout, the load/hide of the spinner won't be visible?!
36
                setTimeout(function() {
37
                        // Note: #loading not defined in oobe.php
38
                        $("#loading").show();
39
                },1);
40
 
41
                var vts_validation_result = null;
42
                console.log("start VTS challenge");
43
                for (i=min; i<=max; i++) {
44
                        if (challenge == sha3_512(starttime+"/"+ip_target+"/"+i)) {
45
                                var answer = i;
46
                                vts_validation_result = JSON.stringify([starttime, ip_target, challenge, answer, challenge_integrity]);
47
                                break;
48
                        }
49
                }
50
                console.log("end VTS challenge");
51
 
52
                //$("#loading").hide();
53
                // Without setTimeout, the load/hide of the spinner won't be visible?!
54
                setTimeout(function() {
55
                        // Note: #loading not defined in oobe.php
56
                        $("#loading").hide();
57
                },100);
58
 
59
                return vts_validation_result;
60
        },
61
 
62
        captchaReset: function(autosolve) {
63
                $.ajax({
64
                        url:"../../../../ajax.php",
65
                        method:"POST",
66
                        //beforeSend: function(jqXHR, settings) {
67
                        //      $.xhrPool.abortAll();
68
                        //      $.xhrPool.add(jqXHR);
69
                        //},
70
                        //complete: function(jqXHR, text) {
71
                        //      $.xhrPool.remove(jqXHR);
72
                        //},
73
                        data: {
74
                        //      csrf_token:csrf_token,
75
                                plugin:OIDplusCaptchaPluginVtsClientChallenge.oid,
76
                                action:"get_challenge"
77
                        },
78
                        error:function(jqXHR, textStatus, errorThrown) {
79
                                if (errorThrown == "abort") return;
833 daniel-mar 80
                                alertError("Error: "+errorThrown); //alertError(_L("Error: %1",errorThrown));
709 daniel-mar 81
                        },
82
                        success:function(data) {
83
                                if ("error" in data) {
833 daniel-mar 84
                                        alertError("Error: "+data.error); //alertError(_L("Error: %1",data.error));
709 daniel-mar 85
                                } else if (data.status >= 0) {
86
                                        OIDplusCaptchaPluginVtsClientChallenge.currentchallenge = data.challenge;
87
                                        OIDplusCaptchaPluginVtsClientChallenge.currentresponse = null;
88
                                        if (autosolve) {
89
                                                // TODO: Solve using a JS Worker, so that the User UI is not slowed down... Then we also don't need the #loading spinner
90
                                                OIDplusCaptchaPluginVtsClientChallenge.currentresponse = OIDplusCaptchaPluginVtsClientChallenge.captchaResponse();
91
                                        }
92
                                } else {
833 daniel-mar 93
                                        alertError("Error: "+data); //alertError(_L("Error: %1",data));
709 daniel-mar 94
                                }
95
                        }
96
                });
97
 
98
        }
99
 
782 daniel-mar 100
};