Skip to content

Multinode support  #8

@analienx

Description

@analienx

/********* 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 ***************");			
		}
		
		
	
	}
});	

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions