-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpsession.js
More file actions
72 lines (65 loc) · 2.67 KB
/
phpsession.js
File metadata and controls
72 lines (65 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var innovaphone = innovaphone || {};
innovaphone.PhpSession = innovaphone.PhpSession || function (url, app, appStart, params) {
var instance = this,
url = url,
challenge,
timer;
window.addEventListener('message', onpostmessage);
login();
function login() {
httpGet(url + "?mt=AppChallenge", onchallenge);
timer = setTimeout(login, 10000);
}
function onchallenge(text) {
var obj = JSON.parse(text);
if (obj && obj.mt) {
challenge = obj.challenge;
if (obj.mt == "AppChallengeResult") {
window.parent.postMessage(JSON.stringify({ mt: "getLogin", app: app, challenge: obj.challenge }), "*");
}
}
}
function onpostmessage(e) {
var obj = JSON.parse(e.data);
if (obj.mt && obj.mt == "Login") {
console.log(app + ": AppLogin(" + obj.sip + "@" + obj.domain + ")");
httpGet(url + "?mt=AppLogin&app=" + encodeURIComponent(obj.app) +
"&domain=" + encodeURIComponent(obj.domain) +
"&sip=" + encodeURIComponent(obj.sip) +
"&guid=" + encodeURIComponent(obj.guid) +
"&dn=" + encodeURIComponent(obj.dn) +
(obj.info ? "&info=" + encodeURIComponent(JSON.stringify(obj.info)) : "") +
"&digest=" + encodeURIComponent(obj.digest) +
"&challenge=" + encodeURIComponent(challenge), onlogin);
}
}
function onlogin(text) {
var obj = JSON.parse(text);
if (obj && obj.mt && obj.mt == "AppLoginResult" && obj.ok) {
var u = location.href.substring(0, location.href.lastIndexOf("/") + 1);
location.href = u + appStart + params;
clearTimeout(timer);
}
}
function httpGet(url, funcComplete, funcFailed) {
var xmlReq = new window.XMLHttpRequest();
if (xmlReq) {
xmlReq.open("GET", url, funcComplete ? true : false);
xmlReq.send(null);
if (funcComplete) {
xmlReq.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
funcComplete(this.responseText, this.responseXML);
}
else {
if (funcFailed) funcFailed(this);
else funcComplete("{}");
}
}
}
}
}
return xmlReq;
}
};