Add configurable host, port, ssl scheme to ussd browser emulator
This commit is contained in:
parent
1bfc1434b4
commit
2e09b69e36
@ -16,9 +16,16 @@ div#session {
|
||||
<textarea id="monitor" disabled="1"></textarea>
|
||||
<div id="login">
|
||||
<label for="user">API username</label>
|
||||
<input type="text" id="user" name="user" type="text" /><br/>
|
||||
<input type="text" id="user" name="user" />
|
||||
<label for="user">API password</label>
|
||||
<input type="text" id="pass" name="pass" type="text" /><br/>
|
||||
<input type="text" id="pass" name="pass" /> <br/>
|
||||
|
||||
<label for="host">API host</label>
|
||||
<input type="text" id="host" name="host" />
|
||||
<label for="host">API port</label>
|
||||
<input type="text" id="port" name="port" />
|
||||
<label for="host">SSL</label>
|
||||
<input type="checkbox" id="ssl" name="ssl" checked="1"/> <br/>
|
||||
<hr/>
|
||||
<input type="text" id="phone" /> <button onclick="setPhone(document.getElementById('phone').value);" id="send_phone">set phone number</button>
|
||||
</div>
|
||||
|
@ -1,10 +1,12 @@
|
||||
//var proto = 'http';
|
||||
//var host = 'localhost:9000';
|
||||
var ssl = false;
|
||||
var host = 'localhost';
|
||||
var port = 9000;
|
||||
var proto = 'https';
|
||||
var host = 'staging.sarafu.network';
|
||||
var user = 'admin_bert_token_inc.';
|
||||
var pass = '197781ed60bf16d5dc12d84e3df37e35';
|
||||
var serviceCode = '*483*061#';
|
||||
var user = 'foo';
|
||||
var pass = 'bar';
|
||||
var path = '/';
|
||||
var serviceCode = '*483*46#';
|
||||
|
||||
// cheekily stolen from https://www.tutorialspoint.com/how-to-create-guid-uuid-in-javascript
|
||||
function createUUID() {
|
||||
@ -23,9 +25,17 @@ function send(s) {
|
||||
document.getElementById('send_input').disabled = true;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.responseType = 'text';
|
||||
current_user = document.getElementById('user').value;
|
||||
current_pass = document.getElementById('pass').value;
|
||||
xhr.open('POST', proto + '://' + host + '/api/v1/ussd/kenya?username=' + current_user + '&password=' + current_pass, true);
|
||||
const current_user = document.getElementById('user').value;
|
||||
const current_pass = document.getElementById('pass').value;
|
||||
const current_host = document.getElementById('host').value;
|
||||
const current_port = document.getElementById('port').value;
|
||||
let current_scheme = 'http';
|
||||
if (document.getElementById('ssl').checked) {
|
||||
current_scheme += 's';
|
||||
}
|
||||
const url = current_scheme + '://' + current_host + ':' + current_port + '?username=' + current_user + '&password=' + current_pass
|
||||
console.debug('connecting to', url);
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
data = {
|
||||
sessionId: uuid,
|
||||
@ -106,6 +116,8 @@ function abort() {
|
||||
window.addEventListener('load', () => {
|
||||
document.getElementById('user').value = user;
|
||||
document.getElementById('pass').value = pass;
|
||||
document.getElementById('host').value = host;
|
||||
document.getElementById('port').value = port;
|
||||
document.getElementById('phone').addEventListener('keyup', (e) => {
|
||||
if (e.keyCode == '13') {
|
||||
document.getElementById('input').value = '';
|
||||
|
Loading…
Reference in New Issue
Block a user