-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbwautofillergui.py
More file actions
453 lines (380 loc) · 16.7 KB
/
bwautofillergui.py
File metadata and controls
453 lines (380 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#!/usr/bin/env python
import threading
import clipboard
import time
import sys
import os
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QCheckBox,
QPushButton,
QTabWidget,
QFileDialog,
QMessageBox,
QSpinBox
)
from PySide6.QtCore import (
Qt,
QSize,
QSettings,
QPoint,
)
from PySide6.QtGui import QIcon
import bitwardenautofiller
class BitwardenAutofillerGUI(QMainWindow):
def __init__(self):
self.pass_args(sys.argv[1:]) # bypass the gui on '-cli' argument request
super().__init__()
self.dthread = None
self.setWindowTitle("Bitwarden Autofiller")
icon = self.resource_path("fillericon.png")
if os.path.isfile(icon):
self.setWindowIcon(QIcon(icon))
# Initialize settings
self.settings = QSettings('BitwardenAutofiller', 'GUI')
# Restore window geometry
self.restore_window_geometry()
# Minimum size to ensure all elements are visible
self.setMinimumSize(400, 240)
# Central widget and main layout
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout()
central_widget.setLayout(main_layout)
# Create tabs
self.tab_widget = QTabWidget()
tab_widget = self.tab_widget
main_layout.addWidget(tab_widget)
# Daemon Tab
daemon_tab = QWidget()
daemon_layout = QVBoxLayout()
daemon_tab.setLayout(daemon_layout)
# Email and Password
email_layout = QHBoxLayout()
email_label = QLabel("Bitwarden Email:")
self.email_input = QLineEdit()
email_layout.addWidget(email_label)
email_layout.addWidget(self.email_input)
daemon_layout.addLayout(email_layout)
password_layout = QHBoxLayout()
password_label = QLabel("Vault Password:")
self.password_input = QLineEdit()
self.password_input.setEchoMode(QLineEdit.Password)
password_layout.addWidget(password_label)
password_layout.addWidget(self.password_input)
daemon_layout.addLayout(password_layout)
# Daemon Timeout Setting
daemon_settings_layout = QHBoxLayout()
timeout_label = QLabel("Daemon Timeout (seconds; -1 = infinite):")
self.timeout_spinbox = QSpinBox()
self.timeout_spinbox.setRange(-1, 86400) # infinite to 0 seconds to 1 day
self.timeout_spinbox.setValue(self.settings.value('daemon_timeout', 3600, type=int))
daemon_settings_layout.addWidget(timeout_label)
daemon_settings_layout.addWidget(self.timeout_spinbox)
daemon_layout.addLayout(daemon_settings_layout)
# Logout Checkbox
self.logout_check = QCheckBox("Relogin (helps with sync issues)")
daemon_layout.addWidget(self.logout_check)
# Close app but keep daemon
keep_daemon_layout = QHBoxLayout()
self.keep_daemon_check = QCheckBox("On GUI exit keep the daemon running in the backround")
self.keep_daemon_check.setChecked(self.settings.value('keep_daemon_check', False, type=bool))
keep_daemon_layout.addWidget(self.keep_daemon_check)
daemon_layout.addLayout(keep_daemon_layout)
# Run Daemon
self.daemon_mode = False
drunner_layout = QHBoxLayout()
drunner_button = QPushButton("Start Daemon")
drunner_button.clicked.connect(self.run_daemon)
drunner_layout.addWidget(drunner_button)
daemon_layout.addLayout(drunner_layout)
# Client Tab
client_tab = QWidget()
client_layout = QVBoxLayout()
client_tab.setLayout(client_layout)
# Sync vault Checkbox
sync_vault_layout = QHBoxLayout()
self.sync_vault_check = QCheckBox("Sync Vault")
sync_vault_layout.addWidget(self.sync_vault_check)
client_layout.addLayout(sync_vault_layout)
# Fill Actions
fill_actions_layout = QHBoxLayout()
fill_actions_label = QLabel("Fill Actions:")
self.fill_actions_input = QLineEdit()
self.fill_actions_input.setText(self.settings.value('fill_actions_input', 'C14724635'))
fill_actions_layout.addWidget(fill_actions_label)
fill_actions_layout.addWidget(self.fill_actions_input)
client_layout.addLayout(fill_actions_layout)
# IP Network Setting
ip_network_layout = QHBoxLayout()
ip_label = QLabel("Local IP:")
self.ip_input = QLineEdit()
self.ip_input.setText(self.settings.value('ip_input', '127.0.0.1'))
ip_network_layout.addWidget(ip_label)
ip_network_layout.addWidget(self.ip_input)
client_layout.addLayout(ip_network_layout)
# Port Network Setting
port_network_layout = QHBoxLayout()
port_label = QLabel("Local Port:")
self.port_input = QLineEdit()
self.port_input.setText(self.settings.value('port_input', '64756'))
port_network_layout.addWidget(port_label)
port_network_layout.addWidget(self.port_input)
client_layout.addLayout(port_network_layout)
# Run Client
self.client_mode = False
crunner_layout = QHBoxLayout()
crunner_button = QPushButton("Start Client (waits 3 seconds, focus the target app)")
crunner_button.clicked.connect(self.run_client)
crunner_layout.addWidget(crunner_button)
client_layout.addLayout(crunner_layout)
# Close Daemon
self.exit_daemon = False
close_daemon_button = QPushButton("Send Close Daemon Signal")
close_daemon_button.clicked.connect(self.close_daemon)
client_layout.addWidget(close_daemon_button)
# Other Settings Tab
connection_tab = QWidget()
connection_layout = QVBoxLayout()
connection_tab.setLayout(connection_layout)
# Salt folder Checkbox
remote_layout = QHBoxLayout()
self.salt_folder_check = QCheckBox("Salt folder (Useful for remote PC / daemon)")
self.salt_folder_check.setChecked(self.settings.value('salt_folder_check', False, type=bool))
remote_layout.addWidget(self.salt_folder_check)
connection_layout.addLayout(remote_layout)
# Server URL
server_url_layout = QHBoxLayout()
server_url_label = QLabel("Bitwarden Server URL:")
self.server_url_input = QLineEdit()
server_url_layout.addWidget(server_url_label)
server_url_layout.addWidget(self.server_url_input)
connection_layout.addLayout(server_url_layout)
# Certificate File
cert_file_layout = QHBoxLayout()
cert_file_label = QLabel("Certificate File:")
self.cert_file_input = QLineEdit()
self.cert_file_input.setText(self.settings.value('cert_file_input', ''))
cert_file_browse = QPushButton("Browse")
cert_file_browse.clicked.connect(self.browse_cert_file)
cert_file_layout.addWidget(cert_file_label)
cert_file_layout.addWidget(self.cert_file_input)
cert_file_layout.addWidget(cert_file_browse)
connection_layout.addLayout(cert_file_layout)
# Additional Encryption
encryption_layout = QHBoxLayout()
encryption_label = QLabel("Additional Encryption Password:")
self.encryption_input = QLineEdit()
self.encryption_input.setEchoMode(QLineEdit.Password)
encryption_layout.addWidget(encryption_label)
encryption_layout.addWidget(self.encryption_input)
connection_layout.addLayout(encryption_layout)
# Bitwarden CLI Path
cli_path_layout = QHBoxLayout()
cli_path_label = QLabel("Bitwarden CLI Path:")
self.cli_path_input = QLineEdit()
self.cli_path_input.setText(self.settings.value('cli_path_input', 'bw'))
cli_path_browse = QPushButton("Browse")
cli_path_browse.clicked.connect(self.browse_cli_path)
cli_path_layout.addWidget(cli_path_label)
cli_path_layout.addWidget(self.cli_path_input)
cli_path_layout.addWidget(cli_path_browse)
connection_layout.addLayout(cli_path_layout)
# Copy command clipboard button
cmd_clipboard_layout = QHBoxLayout()
cmd_clipboard_button = QPushButton("Copy client command to clipboard for system shortcuts")
cmd_clipboard_button.clicked.connect(self.copy_client_cmd)
cmd_clipboard_layout.addWidget(cmd_clipboard_button)
connection_layout.addLayout(cmd_clipboard_layout)
# Add tabs
tab_widget.addTab(daemon_tab, "Daemon")
tab_widget.addTab(client_tab, "Client")
tab_widget.addTab(connection_tab, "Other Settings")
# Action Button
# action_layout = QHBoxLayout()
# exit_button = QPushButton("Exit App")
# exit_button.clicked.connect(self.close_app)
# action_layout.addWidget(exit_button)
# main_layout.addLayout(action_layout)
def pass_args(self, args):
if '-cli' in args:
args.remove('-cli')
print("The argument '-cli' was passed redirecting to cli and closing after")
print()
bitwardenautofiller.main(args)
sys.exit()
print("The gui can be skipped and the command be bypassed to the Autofiller")
print("To do that add the argument '-cli' to the gui app start command")
print("any other arguments will then be passed to the autofiller and the gui will not run")
print()
def restore_window_geometry(self):
"""Restore the window's position and size from saved settings"""
# Restore window size
# size = self.settings.value('window_size', QSize(400, 240), type=QSize)
# self.resize(size)
# Restore window position
pos = self.settings.value('window_position', QPoint(), type=QPoint)
# If there is a previous position is saved, move to it
if not pos.isNull():
self.move(pos)
def closeEvent(self, event):
"""Save settings when the application is closed"""
if not self.keep_daemon_check.isChecked():
self.close_daemon(True)
# Save window geometry
# self.settings.setValue('window_size', self.size())
self.settings.setValue('window_position', self.pos())
# Text inputs
self.settings.setValue('cert_file_input', self.cert_file_input.text())
self.settings.setValue('ip_input', self.ip_input.text())
self.settings.setValue('port_input', self.port_input.text())
self.settings.setValue('cli_path_input', self.cli_path_input.text())
self.settings.setValue('fill_actions', self.fill_actions_input.text())
# Checkboxes
self.settings.setValue('salt_folder_check', self.salt_folder_check.isChecked())
self.settings.setValue('keep_daemon_check', self.keep_daemon_check.isChecked())
# Spinbox
self.settings.setValue('daemon_timeout', self.timeout_spinbox.value())
# Ensure settings are saved
self.settings.sync()
event.accept()
def sizeHint(self):
# Suggest a reasonable default size, but allow OS/window manager to adjust
return QSize(400, 240)
def browse_cert_file(self):
filename, _ = QFileDialog.getOpenFileName(self, "Select Certificate File", filter="Pem Certificate (*.pem)")
if filename:
self.cert_file_input.setText(filename)
def browse_cli_path(self):
filename, _ = QFileDialog.getOpenFileName(self, "Select Bitwarden CLI")
if filename:
self.cli_path_input.setText(filename)
def prepare_arguments(self):
args = []
dargs = []
cargs = []
# Enable non-blocking mode as the console is not used for the gui app
args.append('-n')
# Enable raise of errors
args.append('-r')
# Mode Selection
d = False
c = False
if self.daemon_mode:
d = True
self.daemon_mode = False
dargs.append('-d')
if self.client_mode:
c = True
self.client_mode = False
cargs.append('-c')
# Server URL
if self.server_url_input.text() and d:
dargs.extend(['-s', self.server_url_input.text()])
# Certificate File
if self.cert_file_input.text() and d:
dargs.extend(['-cf', self.cert_file_input.text()])
# Logout
if self.logout_check.isChecked() and d:
dargs.append('-l')
# Credentials
if self.email_input.text() and d:
dargs.extend(['-m', self.email_input.text()])
if self.password_input.text():
dargs.extend(['-p', self.password_input.text()])
# Additional Encryption
if self.encryption_input.text():
args.extend(['-e', self.encryption_input.text()])
# Bitwarden CLI Path
if self.cli_path_input.text() != 'bw' and d:
dargs.extend(['-bw', self.cli_path_input.text()])
# Daemon Timeout
if self.timeout_spinbox.value() != 3600 and d:
dargs.extend(['-t', str(self.timeout_spinbox.value())])
# Salt Folder
if self.salt_folder_check.isChecked():
args.append('-sf')
# Salt Folder
if self.sync_vault_check.isChecked():
args.append('-y')
# Local IP and Port
if self.ip_input.text() != '127.0.0.1' and c:
cargs.extend(['-ip', self.ip_input.text()])
if self.port_input.text() != '64756' and c:
cargs.extend(['-lp', self.port_input.text()])
# Fill Actions
if self.fill_actions_input.text() != 'C14724635' and c:
cargs.extend(['-f', self.fill_actions_input.text()])
if self.exit_daemon:
self.exit_daemon = False
if not self.client_mode:
cargs.append('-c')
cargs.append('-x')
if c and not d:
return args + cargs
elif d and not c:
return args + dargs
return args + dargs + cargs
def resource_path(self, relative_path):
"""Get absolute path to resource, works for dev and PyInstaller"""
if hasattr(sys, '_MEIPASS'): # Running as a PyInstaller bundle
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.dirname(os.path.abspath(__file__)), relative_path)
def run_bitwarden_autofiller(self,ierr=False):
daemon_mode = self.daemon_mode
try:
args = self.prepare_arguments()
ret = bitwardenautofiller.main(args)
del args # forget args for security
if daemon_mode and not ierr:
QMessageBox.information(self, "Success", "The BitwardenAutofiller daemon was successfully started in the backround!")
self.tab_widget.setCurrentIndex(1)
elif not ierr:
if not ret:
msg_box = QMessageBox(QMessageBox.Information, "Success", "The BitwardenAutofiller client successfully retrieved and filled the vault data!", parent=self)
msg_box.setWindowFlag(Qt.WindowDoesNotAcceptFocus)
msg_box.exec()
else:
msg_box = QMessageBox(QMessageBox.Information, "Success", f"The BitwardenAutofiller client successfully ran but returned:\n{ret}", parent=self)
msg_box.setWindowFlag(Qt.WindowDoesNotAcceptFocus)
msg_box.exec()
except Exception as e:
if not ierr:
QMessageBox.critical(self, "Error", f"An error occurred:\n{str(e)}")
if not daemon_mode:
if self.tab_widget.currentIndex() == 1:
self.tab_widget.setCurrentIndex(0)
def run_daemon(self):
self.daemon_mode = True
self.run_bitwarden_autofiller()
def close_daemon(self,ierr=False):
self.client_mode = True
self.exit_daemon = True
self.run_bitwarden_autofiller(ierr)
def run_client(self):
time.sleep(3)
self.client_mode = True
self.run_bitwarden_autofiller()
def copy_client_cmd(self):
self.client_mode = True
if getattr(sys, 'frozen', False): # Check if running as a compiled executable
script_path = os.path.abspath(sys.executable)
else: # Running as a regular Python script
script_path = os.path.abspath(__file__)
args = [script_path, '-cli'] + self.prepare_arguments()
copyargs = "'" + "' '".join(args) + "'"
clipboard.copy(copyargs)
QMessageBox.information(self, "Success", f"The BitwardenAutofiller client command was successfully copied into the clipboard\nYou can now add this command to a hotkey progam")
def main():
app = QApplication(sys.argv)
gui = BitwardenAutofillerGUI()
gui.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()