-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
75 lines (63 loc) · 2.57 KB
/
config.py
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
# Copyright (C) 2024 - 2025 HMS Industrial Network Solutions
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# config.py
import sys
import os
def get_base_dir():
"""Determines the base directory of the application."""
if getattr(sys, "frozen", False):
# Running as a bundled executable
BASE_DIR = os.path.dirname(os.path.abspath(sys.executable))
else:
# Running in a normal Python environment
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
return BASE_DIR
BASE_DIR = get_base_dir()
# Paths to external binaries
if getattr(sys, "frozen", False):
# Adjust paths when running as a bundled executable
OPENSSL_PATH = os.path.join(sys._MEIPASS, "needed_binaries", "openssl.exe")
OPENVPN_PATH = os.path.join(sys._MEIPASS, "needed_binaries", "openvpn.exe")
else:
OPENSSL_PATH = os.path.join(BASE_DIR, "needed_binaries", "openssl.exe")
OPENVPN_PATH = os.path.join(BASE_DIR, "needed_binaries", "openvpn.exe")
# Common certificate details (defaults)
COMMON_DETAILS = {
"C": "US",
"ST": "MO",
"L": "Mineral Point",
"O": "GregNet",
"OU": "IT",
"email_address": "gregory.allen.whitlock@gmail.com",
}
def get_user_input(prompt, default):
"""Helper function to get input from user, with a default option."""
user_input = input(f"{prompt} [{default}]: ")
return user_input if user_input else default
def get_certificate_details():
"""Prompt user for certificate details or use defaults."""
while True:
c_code = get_user_input("Country Name (2 letter code)", COMMON_DETAILS["C"])
if len(c_code) == 2 and c_code.isalpha():
break
else:
print("Error: Country code must be exactly 2 letters. Please try again.")
user_details = {
"C": c_code,
"ST": get_user_input(
"State or Province Name (full name)", COMMON_DETAILS["ST"]
),
"L": get_user_input("Locality Name (eg, city)", COMMON_DETAILS["L"]),
"O": get_user_input("Organization Name (eg, company)", COMMON_DETAILS["O"]),
"OU": get_user_input(
"Organizational Unit Name (eg, section)", COMMON_DETAILS["OU"]
),
"email_address": get_user_input(
"Email Address", COMMON_DETAILS["email_address"]
),
}
return user_details