guaclient/main.js

176 lines
5.0 KiB
JavaScript
Raw Permalink Normal View History

2024-11-05 18:46:34 +01:00
/*----------------------------------------------------------------------------*/
/* main.js */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* This file is part of GuaClient. */
/* */
/* GuaClient is free software: you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* GuaClient is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with GuaClient. If not, see <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
const electron = require('electron');
const { app, BrowserWindow } = electron;
const prompt = require('electron-prompt')
const process = require('process');
2024-11-05 18:46:34 +01:00
let mainWindow;
let target_url = "https://www.rx3.net/tdsots/admin/guacamole/";
let target_user = "";
2024-11-05 18:46:34 +01:00
app.on('login', (event, webContents, request, authInfo, callback) =>
{
event.preventDefault();
// popup a dialog to let the user enter a username/password
// ...
if( target_user != "")
2024-11-05 18:46:34 +01:00
{
prompt(
{
title: 'Authentication',
label: 'Enter Password:',
2024-11-05 18:46:34 +01:00
inputAttrs: { type: 'password'},
type: 'input'
}).then(( password) =>
{
callback( target_user, password);
}).catch( console.error);
}
else
{
prompt(
2024-11-05 18:46:34 +01:00
{
title: 'Authentication',
label: 'Enter Login:',
inputAttrs: { type: 'text'},
type: 'input'
}).then(( username) =>
{
prompt(
{
title: 'Authentication',
label: 'Enter Password:',
inputAttrs: { type: 'password'},
type: 'input'
}).then(( password) =>
{
callback( username, password);
}).catch( console.error);
}).catch( console.error);
}
2024-11-05 18:46:34 +01:00
});
app.on('ready', () => {
mainWindow = new BrowserWindow(
{
2024-11-05 18:46:34 +01:00
width: 1000,
height: 700
});
let exit = false;
for( let i = 2, next = ""; i < process.argv.length; i++)
{
if( next == "")
{
switch( process.argv[ i])
{
case "--url":
{
next = "URL";
break;
}
case "--user":
{
next = "USER";
break;
}
2024-11-05 18:46:34 +01:00
case "--user":
{
next = "USER";
break;
}
case "--help":
{
console.log( "usage: guaclient [--url <Target_URL>] [--user <USER_NAME>]");
console.log( "Defaults: URL: [" + target_url + "] ["+ target_user + "]");
exit = true;
break;
}
default:
{
console.log( "Unknown arg: [" + process.argv[i] + "]");
}
}
}
else
{
switch( next)
{
case "URL":
{
target_url = process.argv[ i];
break;
}
case "USER":
{
target_user = process.argv[ i];
break;
}
default:
{
console.log( "Erreur interne: [" + next + "]");
break;
}
}
next = "";
}
}
if( !exit)
{
console.log( "Connecting [" + target_url + "] with user: [" + target_user + "]");
mainWindow.setTitle('Rx3 Guacamole');
mainWindow.loadURL( target_url);
mainWindow.on('closed', () =>
{
mainWindow = null;
});
}
else
{
app.quit();
}
2024-11-05 18:46:34 +01:00
});