Skip to content

Commit 10f600f

Browse files
author
k9ert
authored
Merge branch 'master' into 20220528_build_docs
2 parents c38e156 + 4bcc25b commit 10f600f

File tree

5 files changed

+177
-4
lines changed

5 files changed

+177
-4
lines changed

pyinstaller/electron/assets/lock.svg

Lines changed: 49 additions & 0 deletions
Loading

pyinstaller/electron/basic_auth.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<html>
2+
<style>
3+
input[type="text"]:disabled {
4+
border: none;
5+
}
6+
</style>
7+
<link rel="stylesheet" type="text/css" href="./styles.css">
8+
<body style="overflow: auto; height: 100%;">
9+
<div style="margin: auto; text-align: left;">
10+
<h1 style="margin-top: 20px;">Authorization</h1>
11+
<form action="" class="card">
12+
<div>
13+
<h2>The server at '<span id="server">...</span>' is prompting for authorization</h2>
14+
<div style="margin: 10px;">
15+
<div id="basic-auth-settings">
16+
<input id="basic-auth-user" type="text" placeholder="Username" style="margin-bottom: 10px" />
17+
<input id="basic-auth-pass" type="password" placeholder="Password" style="margin-bottom: 10px" />
18+
<span style="vertical-align: bottom; margin-right: 10px;">Save username and password: </span><label class="switch">
19+
<input type="checkbox" id="save-auth-checkbox" onchange="toggleBasicAuth(this.checked)">
20+
<span class="slider"></span>
21+
</label>
22+
</div>
23+
</div>
24+
<br>
25+
</div><br>
26+
<div class="row flex-center">
27+
<button type="button" id="cancel-btn" class="btn" onclick="cancel()" style="margin: 5px;">Cancel</button>
28+
<button type="button" id="ok-btn" class="btn action" onclick="saveAuth()" style="margin: 5px;">Ok</button>
29+
</div>
30+
</form>
31+
</div>
32+
<script>
33+
const fs = require('fs')
34+
const { ipcRenderer } = require('electron')
35+
const helpers = require('./helpers')
36+
const getAppSettings = helpers.getAppSettings
37+
const appSettingsPath = helpers.appSettingsPath
38+
39+
function cancel() {
40+
window.close();
41+
}
42+
43+
function saveAuth() {
44+
let appSettings = getAppSettings()
45+
appSettings.basicAuth = true
46+
appSettings.basicAuthUser = document.getElementById('basic-auth-user').value
47+
appSettings.basicAuthPass = document.getElementById('basic-auth-pass').value
48+
if (document.getElementById('save-auth-checkbox').checked) {
49+
fs.writeFileSync(appSettingsPath, JSON.stringify(appSettings));
50+
}
51+
ipcRenderer.send('basic-auth', {
52+
username: appSettings.basicAuthUser,
53+
password: appSettings.basicAuthPass
54+
});
55+
}
56+
57+
document.addEventListener("DOMContentLoaded", function() {
58+
let appSettings = getAppSettings()
59+
document.getElementById('server').innerText = appSettings.specterURL
60+
document.getElementById('basic-auth-user').value = appSettings.basicAuthUser
61+
document.getElementById('basic-auth-pass').value = appSettings.basicAuthPass
62+
});
63+
</script>
64+
</body>
65+
</html>

pyinstaller/electron/helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function getAppSettings() {
4040
let defaultSettings = {
4141
mode: 'specterd',
4242
specterURL: 'http://localhost:25441',
43+
basicAuth: false,
44+
basicAuthUser: '',
45+
basicAuthPass: '',
4346
tor: false,
4447
proxyURL: "socks5://127.0.0.1:9050",
4548
specterdVersion: versionData.version,

pyinstaller/electron/main.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,33 @@ switch (process.platform) {
118118
logger.info("Using version " + appSettings.specterdVersion);
119119
logger.info("Using platformName " + platformName);
120120

121+
let trySavedAuth = true
122+
app.on('login', function(event, webContents, request, authInfo, callback) {
123+
event.preventDefault();
124+
appSettings = getAppSettings(); // ensure latest settings are used
125+
if (appSettings.basicAuth && trySavedAuth) {
126+
callback(appSettings.basicAuthUser, appSettings.basicAuthPass);
127+
} else {
128+
let user = '';
129+
let pass = '';
130+
let win = createNewWindow('basic_auth.html', 800, 600, mainWindow, true);
131+
win.show();
132+
win.on('close', (event) => {
133+
win = null;
134+
callback(user, pass);
135+
});
136+
ipcMain.once('basic-auth', (event, creds) => {
137+
if (win != null) {
138+
user = creds.username;
139+
pass = creds.password;
140+
win.close();
141+
}
142+
});
143+
}
144+
// if we are prompted for auth again show the auth dialog
145+
trySavedAuth = false;
146+
})
147+
121148
function createWindow (specterURL) {
122149
if (!mainWindow) {
123150
initMainWindow()
@@ -481,12 +508,16 @@ function setMainMenu() {
481508
}
482509

483510

484-
function openNewWindow(htmlContentFile, width, height) {
511+
function createNewWindow(htmlContentFile, width, height, parent, modal) {
485512
if (! width) {width=700}
486513
if (! height) {height=750}
514+
if (! parent) {parent=null}
515+
if (! modal) {modal=false}
487516
prefWindow = new BrowserWindow({
488517
width: width,
489518
height: height,
519+
parent: parent,
520+
modal: modal,
490521
autoHideMenuBar: true,
491522
webPreferences: {
492523
nodeIntegration: true,
@@ -500,18 +531,18 @@ function openNewWindow(htmlContentFile, width, height) {
500531
shell.openExternal(url);
501532
});
502533
prefWindow.loadURL(`file://${__dirname}/${htmlContentFile}`)
503-
prefWindow.show()
534+
return prefWindow
504535
}
505536

506537

507538
function openPreferences() {
508-
openNewWindow("settings.html")
539+
createNewWindow("settings.html", 800, 750, mainWindow).show()
509540
}
510541

511542
function openErrorLog() {
512543
width = parseInt(dimensions.width * 0.7),
513544
height = parseInt(dimensions.height * 0.7)
514-
openNewWindow("error_logs.html", width, height)
545+
createNewWindow("error_logs.html", width, height).show()
515546
}
516547

517548
function showError(error) {

pyinstaller/electron/settings.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ <h2>Do you want to connect to a remote Specter?</h2>
1818
<span style="font-size: 0.95em;">Paste the URL you use to access your remote Specter:</span>
1919
<input id="specter-url" style="margin-top: 10px;" type="url" placeholder="http://" />
2020
<br>
21+
<p style="margin-top: 20px;">
22+
<img style="width: 25px; margin-right: 7px; vertical-align: bottom;" src="assets/lock.svg"/><span style="vertical-align: bottom; margin-right: 10px;">HTTP Basic authentication: </span><label class="switch">
23+
<input type="checkbox" id="basic-auth-checkbox" onchange="toggleBasicAuth(this.checked)">
24+
<span class="slider"></span>
25+
</label>
26+
</p>
27+
<input id="basic-auth-user" type="text" class="hidden" placeholder="Username" style="margin-bottom: 10px;" />
28+
<input id="basic-auth-pass" type="password" class="hidden" placeholder="Password" />
2129
<p style="margin-top: 20px;">
2230
<img style="width: 25px; margin-right: 7px; vertical-align: bottom;" src="assets/tor.svg"/><span style="vertical-align: bottom; margin-right: 10px;">Connect over Tor: </span><label class="switch">
2331
<input type="checkbox" id="tor-checkbox" onchange="toggleTorProxy(this.checked)">
@@ -129,6 +137,9 @@ <h2 style="float: left;">Specter daemon configurations</h2>
129137
let appSettings = getAppSettings()
130138
appSettings.mode = hwiBridgeMode ? 'hwibridge' : 'specterd'
131139
appSettings.specterURL = hwiBridgeMode ? remoteSpecterURL : 'http://localhost:25441'
140+
appSettings.basicAuth = document.getElementById('basic-auth-checkbox').checked
141+
appSettings.basicAuthUser = document.getElementById('basic-auth-user').value
142+
appSettings.basicAuthPass = document.getElementById('basic-auth-pass').value
132143
appSettings.tor = document.getElementById('tor-checkbox').checked
133144
appSettings.proxyURL = document.getElementById('proxy-url').value
134145
appSettings.specterdVersion = document.getElementById('specterd-version').value
@@ -141,6 +152,16 @@ <h2 style="float: left;">Specter daemon configurations</h2>
141152
});
142153
}
143154

155+
function toggleBasicAuth(basicAuthOn) {
156+
if (basicAuthOn) {
157+
document.getElementById('basic-auth-user').classList.remove('hidden')
158+
document.getElementById('basic-auth-pass').classList.remove('hidden')
159+
} else {
160+
document.getElementById('basic-auth-user').classList.add('hidden')
161+
document.getElementById('basic-auth-pass').classList.add('hidden')
162+
}
163+
}
164+
144165
function toggleTorProxy(torOn) {
145166
if (torOn) {
146167
document.getElementById('proxy-url').classList.remove('hidden')
@@ -155,6 +176,10 @@ <h2 style="float: left;">Specter daemon configurations</h2>
155176
if (hwiBridgeMode) {
156177
document.getElementById('specter-url').value = appSettings.specterURL
157178
}
179+
document.getElementById('basic-auth-user').value = appSettings.basicAuthUser
180+
document.getElementById('basic-auth-pass').value = appSettings.basicAuthPass
181+
document.getElementById('basic-auth-checkbox').checked = appSettings.basicAuth
182+
toggleBasicAuth(appSettings.basicAuth)
158183
document.getElementById('proxy-url').value = appSettings.proxyURL
159184
document.getElementById('tor-checkbox').checked = appSettings.tor
160185
toggleTorProxy(appSettings.tor)

0 commit comments

Comments
 (0)