Project

General

Profile

Download (2.56 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / test / haketilo_test / __main__.py @ aec5c9ae

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 of 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
from .extension_crafting import get_extension_base_url
40

    
41
def fail(msg, error_code):
42
    print('Error:', msg)
43
    print('Usage:', sys.argv[0], '[--load-haketilo]', '[certificates_directory]')
44
    sys.exit(error_code)
45

    
46
load_haketilo = False
47
argv_idx = 1
48
if len(sys.argv) > argv_idx and sys.argv[argv_idx] == '--load-haketilo':
49
    load_haketilo = True
50
    argv_idx += 1
51

    
52
certdir = Path(sys.argv[argv_idx]).resolve() if len(sys.argv) > argv_idx \
53
    else default_cert_dir
54

    
55
if not certdir.is_dir():
56
    fail('selected certificate directory does not exist.', 2)
57

    
58
httpd = do_an_internet(certdir)
59
driver = firefox_safe_mode(proxy_port=httpd.server_port)
60

    
61
if load_haketilo:
62
    driver.install_addon(str(Path.cwd() / 'mozilla-build.zip'), temporary=True)
63
    driver.get(get_extension_base_url(driver) + 'html/settings.html')
64

    
65
print("You can now control the browser through 'driver' object")
66

    
67
# Here we enable readline-enhanced editing:
68
# https://stackoverflow.com/questions/35115208/is-there-any-way-to-combine-readline-rlcompleter-and-interactiveconsole-in-pytho#answer-35116399
69
readline.parse_and_bind('tab: complete');
70
console_locals = globals()
71
readline.set_completer(Completer(console_locals).complete)
72
code.InteractiveConsole(locals=globals()).interact()
73

    
74
driver.quit()
75
httpd.shutdown()
(2-2/11)