-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathstart.py
More file actions
98 lines (83 loc) · 2.7 KB
/
Copy pathstart.py
File metadata and controls
98 lines (83 loc) · 2.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
import warnings
warnings.filterwarnings('ignore', message='.*TripleDES.*')
import os
import sys
_MAINTENANCE_COMMANDS = frozenset({
'backup',
'create-admin',
'rotate-secret-key',
})
_FLASK_OPTIONS_WITH_VALUES = frozenset({
'--app',
'-A',
'--env-file',
'-e',
})
def _is_flask_cli_process(program_name=None, main_module_name=None):
if program_name is None:
program_name = sys.argv[0]
if main_module_name is None:
main_module = sys.modules.get('__main__')
main_module_spec = getattr(main_module, '__spec__', None)
main_module_name = getattr(main_module_spec, 'name', None)
executable_name = os.path.splitext(os.path.basename(program_name))[0].lower()
return executable_name == 'flask' or main_module_name == 'flask.__main__'
def _flask_top_level_command(arguments):
skip_next = False
for index, argument in enumerate(arguments):
if skip_next:
skip_next = False
continue
if argument == '--':
return arguments[index + 1] if index + 1 < len(arguments) else None
if argument in _FLASK_OPTIONS_WITH_VALUES:
skip_next = True
continue
if any(
argument.startswith(f'{option}=')
for option in _FLASK_OPTIONS_WITH_VALUES
if option.startswith('--')
):
continue
if argument.startswith('-A') and argument != '-A':
continue
if argument.startswith('-'):
continue
return argument
return None
def _is_maintenance_cli_invocation(
arguments=None,
program_name=None,
main_module_name=None,
):
arguments = sys.argv[1:] if arguments is None else arguments
if not _is_flask_cli_process(program_name, main_module_name):
return False
return _flask_top_level_command(arguments) in _MAINTENANCE_COMMANDS
from app import create_app, socketio
import config
if _is_maintenance_cli_invocation():
app = create_app(
initialize_storage=False,
start_runtime=False,
initialize_oidc=False,
)
else:
app = create_app()
app.extensions['runtime_lifecycle'].install_process_shutdown_signals(
config.RUNTIME_SHUTDOWN_GRACE_SECONDS
)
if __name__ == '__main__':
host = os.environ.get('HOST', '127.0.0.1')
port = int(os.environ.get('PORT', '5000'))
print("Starting Web SSH Terminal...")
print(f"Server running at http://{host}:{port}")
if host == '127.0.0.1':
print("Note: Listening on localhost only. Set HOST=0.0.0.0 to accept external connections.")
print("Press Ctrl+C to stop the server")
socketio.run(
app,
host=host,
port=port,
debug=config.DEBUG
)