kreta99 / qs-custom-forms Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
/********* Custom login, logout and error forms + RESTORATION ************/ /* USAGE: node custom_forms [node_number] [restore] i.e. setting custom forms for 1st proxy: node custom_forms 0 i.e. restoring login forms for 1st proxy: node custom_forms 0 restore */ // Change following in multinode
// node to be changed
console.log("\x1b[0m")
var isRestore= process.argv[2]=="restore" ? true :false;
var fs = require('fs');
var request = require('request');
var dir_cert = "C:\ProgramData\Qlik\Sense\Repository\Exported Certificates\.Local Certificates\";
var hostname = 'localhost'; //Qlik Sense host name
var options = {
uri: 'https://' + hostname + ':4242/qrs/ProxyService?xrfkey=1234567891234567',
headers: {'content-type': 'application/json',
'X-Qlik-xrfkey': '1234567891234567',
'X-Qlik-user': 'UserDirectory = Internal; UserId= sa_repository'},
method: 'GET',
json: true,
ca: fs.readFileSync(dir_cert + "root.pem"),
key: fs.readFileSync(dir_cert +"client_key.pem"),
cert: fs.readFileSync(dir_cert +"client.pem"),
rejectUnauthorized: false
};
//Get Proxy
request(options, function (error, response, body) {
if(error){
console.log("Error: " + error);
}
else{
//console.log(response);
//getProxyProp(body);
printProxies(body);
}
});
function printProxies(b){
var px=[];
var pxCnt=b.length;
for (let r in b){
//console.log(r);
//console.log(b[r]);
var proxyid = b[r].id;
options.uri = 'https://' + hostname + ':4242/qrs/ProxyService/' + proxyid + '?xrfkey=1234567891234567';
request(options, function (error, response, body) {
if(error){
console.log("Error: " + error);
}
else{
px.push({"id":body.id,"name":body.serverNodeConfiguration.name});
// Once everything completed
if (pxCnt===px.length){
console.log("Select proxy:");
for (let r in px ){
console.log(" "+r+" - " + px[r].name + " ("+px[r].id+")");
}
var standard_input = process.stdin;
standard_input.setEncoding('utf-8');
standard_input.on('data', function (data) {
var selPrx=parseInt(data);
if(isNaN(selPrx) || selPrx>pxCnt)
{
console.log('Pick only one of the selected numbers and hit enter');
return
} else {
//Stop reading input
process.stdin.pause();
console.log("Processing proxy..."+px[selPrx].name);
getProxyProp(px[selPrx].id);
}
});
}
}
});
}
}
//Get Proxy properties
function getProxyProp(pid) {
options.uri = 'https://' + hostname + ':4242/qrs/ProxyService/' + pid + '?xrfkey=1234567891234567';
request(options, function (error, response, body) {
if(error){
console.log("Error: " + error);
}
else{
setCustomForms(body);
}
});
};
//Update forms
function setCustomForms(body){
//set new base64 encoded forms in Proxy properties structure
if(isRestore){
body.settings.formAuthenticationPageTemplate = "";
body.settings.loggedOutPageTemplate = "";
body.settings.errorPageTemplate = "";
} else {
var login_form_file = ".\\login_custom.html"; //file will be base64 encoded by this script!
var logout_form_file = ".\\logout_custom.html"; //file will be base64 encoded by this script!
var error_form_file = ".\\error_custom.html"; //file will be base64 encoded by this script!
var login_form = fs.readFileSync(login_form_file);
var logout_form = fs.readFileSync(logout_form_file);
var error_form = fs.readFileSync(error_form_file);
body.settings.formAuthenticationPageTemplate = Buffer.from(login_form).toString('base64');
body.settings.loggedOutPageTemplate = Buffer.from(logout_form).toString('base64');
body.settings.errorPageTemplate = Buffer.from(error_form).toString('base64');
}
options.method = 'PUT';
options.body = body;
request(options, function (error, response, body) {
if(error){
console.log("Error: " + error);
}
else{
for (prop in body.settings){
if (prop=="virtualProxies"){
console.log(prop);
console.log(body.settings[prop]);
}
if (prop=="formAuthenticationPageTemplate"){
console.log(prop);
console.log('\x1b[33m%s\x1b[0m', body.settings[prop].substr(0,100)); //yellow
}
}
if(isRestore){
console.log('\x1b[36m%s\x1b[0m',"*************** ORIGINAL login, logout and error forms restored ***************");
} else {
console.log('\x1b[36m%s\x1b[0m',"*************** CUSTOM login, logout and error forms SET ***************");
}
}
});
}
`
In some environments it takes the same proxy only everytime regardless of from which proxy it is actually installed. Applying loop works in some cases, it seems hardcoding of id of the proxy can be used in emeregencies. Also buffer seems to be obsolete...
//set new base64 encoded forms in Proxy properties structure
body.settings.formAuthenticationPageTemplate = Buffer.from(login_form).toString('base64');
body.settings.loggedOutPageTemplate = Buffer.from(logout_form).toString('base64');
body.settings.errorPageTemplate = Buffer.from(error_form).toString('base64');
Processing multiple proxies
for (pid in body){
var proxyid = body[pid].id;
options.uri = 'https://' + hostname + ':4242/qrs/ProxyService/' + proxyid + '?xrfkey=1234567891234567';
request(options, function (error, response, body) {
if(error){
console.log("Error: " + error);
}
else{
setCustomForms(body);
//console.log("Set for proxy:"+proxyid);
}
});
}
Hardcoded id for emergency cases when nothing else works
function getProxyProp(body) {
var proxyid = "27402a61-2364-4edc-a0b3-07477169d119";//proxy id for emergencies when nothing else works body[0].id;
Hi,
I have followed all the steps provided In the Page but the "node custom_forms" command Is unable to take the Var Request " Cannot find Module Request "
Module.js: 549 Throw Err;
We are stuck here after completing all the process can you please help us to resolve the Issue.
Thank you,
Neel
Hello kreta99,
I am facing trouble setting up your extension. I have downloaded node.js with all the modules,...
How do I tell Qlik that it should boot with the custom form? Do I have to run the script in order to use it or can I implement it in Qlik so it starts automatically?
Leave the domain fixed, so you do not have to enter every login, is it possible?
node : (node:7204) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please
use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.