Project

General

Profile

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

haketilo / test / __main__.py @ 5a002642

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

    
34
from .server import do_an_internet
35
from .config import *
36
from .profiles import firefox_safe_mode
37

    
38
def fail(msg, error_code):
39
    print('Error:', msg)
40
    print('Usage:', sys.argv[0], '[certificates_directory] [proxy_port]')
41
    sys.exit(error_code)
42

    
43
certdir = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else default_cert_dir
44
if not certdir.is_dir():
45
    fail('selected certificate directory does not exist.', 2)
46

    
47
port = sys.argv[2] if len(sys.argv) > 2 else str(default_proxy_port)
48
if not port.isnumeric():
49
    fail('port must be an integer.', 3)
50

    
51
httpd = do_an_internet(certdir, int(port))
52
driver = firefox_safe_mode(proxy_port=int(port))
53

    
54
print("You can now control the browser through 'driver' object")
55

    
56
code.InteractiveConsole(locals=globals()).interact()
57

    
58
driver.quit()
59
httpd.shutdown()
(2-2/8)