1
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2
|
|
3
|
"""
|
4
|
Run a Firefox-type browser with WebDriver attached and Python console open
|
5
|
"""
|
6
|
|
7
|
# This file is part of Haketilo.
|
8
|
#
|
9
|
# Copyright (C) 2021 jahoti <jahoti@tilde.team>
|
10
|
# Copyright (C) 2021 Wojtek Kosior <koszko@koszko.org>
|
11
|
#
|
12
|
# This program is free software: you can redistribute it and/or modify
|
13
|
# it under the terms of the GNU Affero General Public License as
|
14
|
# published by the Free Software Foundation, either version 3 of the
|
15
|
# License, or (at your option) any later version.
|
16
|
#
|
17
|
# This program is distributed in the hope that it will be useful,
|
18
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
# GNU Affero General Public License for more details.
|
21
|
#
|
22
|
# You should have received a copy of the GNU Affero General Public License
|
23
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
24
|
#
|
25
|
#
|
26
|
# I, Wojtek Kosior, thereby promise not to sue for violation of this
|
27
|
# file's license. Although I request that you do not make use this code
|
28
|
# in a proprietary program, I am not going to enforce this in court.
|
29
|
|
30
|
import sys
|
31
|
import time
|
32
|
import code
|
33
|
from rlcompleter import Completer
|
34
|
import readline
|
35
|
|
36
|
from .server import do_an_internet
|
37
|
from .misc_constants import *
|
38
|
from .profiles import firefox_safe_mode
|
39
|
|
40
|
def fail(msg, error_code):
|
41
|
print('Error:', msg)
|
42
|
print('Usage:', sys.argv[0], '[certificates_directory] [proxy_port]')
|
43
|
sys.exit(error_code)
|
44
|
|
45
|
certdir = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else default_cert_dir
|
46
|
if not certdir.is_dir():
|
47
|
fail('selected certificate directory does not exist.', 2)
|
48
|
|
49
|
port = sys.argv[2] if len(sys.argv) > 2 else str(default_proxy_port)
|
50
|
if not port.isnumeric():
|
51
|
fail('port must be an integer.', 3)
|
52
|
|
53
|
httpd = do_an_internet(certdir, int(port))
|
54
|
driver = firefox_safe_mode(proxy_port=int(port))
|
55
|
|
56
|
print("You can now control the browser through 'driver' object")
|
57
|
|
58
|
# Here we enable readline-enhanced editing:
|
59
|
# https://stackoverflow.com/questions/35115208/is-there-any-way-to-combine-readline-rlcompleter-and-interactiveconsole-in-pytho#answer-35116399
|
60
|
readline.parse_and_bind('tab: complete');
|
61
|
console_locals = globals()
|
62
|
readline.set_completer(Completer(console_locals).complete)
|
63
|
code.InteractiveConsole(locals=globals()).interact()
|
64
|
|
65
|
driver.quit()
|
66
|
httpd.shutdown()
|