zscams 2.0.7__tar.gz → 2.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {zscams-2.0.7 → zscams-2.0.9}/PKG-INFO +1 -1
  2. {zscams-2.0.7 → zscams-2.0.9}/pyproject.toml +1 -1
  3. {zscams-2.0.7 → zscams-2.0.9}/zscams/__main__.py +12 -0
  4. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/__init__.py +6 -1
  5. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/backend/bootstrap.py +3 -1
  6. zscams-2.0.9/zscams/agent/src/core/backend/unbootstrap.py +49 -0
  7. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/services/reverse_ssh.py +1 -1
  8. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/services/ssh_forwarder.py +1 -1
  9. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/services/system_monitor.py +3 -4
  10. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/filesystem.py +2 -2
  11. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/os.py +51 -0
  12. {zscams-2.0.7 → zscams-2.0.9}/README.md +0 -0
  13. {zscams-2.0.7 → zscams-2.0.9}/zscams/__init__.py +0 -0
  14. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/certificates/.gitkeep +0 -0
  15. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/config.yaml +0 -0
  16. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/configuration/config.j2 +0 -0
  17. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/configuration/freebsd_service.j2 +0 -0
  18. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/configuration/linux_service.j2 +0 -0
  19. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/keys/autoport.key +0 -0
  20. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/__init__.py +0 -0
  21. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/__init__.py +0 -0
  22. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/backend/client.py +0 -0
  23. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/backend/exceptions.py +0 -0
  24. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/backend/update_machine_info.py +0 -0
  25. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/prerequisites.py +0 -0
  26. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/service_health_check.py +0 -0
  27. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/services.py +0 -0
  28. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/tunnel/__init__.py +0 -0
  29. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/tunnel/tls.py +0 -0
  30. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/core/tunnels.py +0 -0
  31. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/services/__init__.py +0 -0
  32. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/__init__.py +0 -0
  33. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/cli.py +0 -0
  34. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/configuration.py +0 -0
  35. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/logger.py +0 -0
  36. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/mac.py +0 -0
  37. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/network.py +0 -0
  38. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/openssl.py +0 -0
  39. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/ssh.py +0 -0
  40. {zscams-2.0.7 → zscams-2.0.9}/zscams/agent/src/support/yaml.py +0 -0
  41. {zscams-2.0.7 → zscams-2.0.9}/zscams/deps.py +0 -0
  42. {zscams-2.0.7 → zscams-2.0.9}/zscams/lib/.gitkeep +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zscams
3
- Version: 2.0.7
3
+ Version: 2.0.9
4
4
  Summary: Async TLS tunnel client with SNI routing, auto-reconnect, and health checks
5
5
  Author: OCD - Cairo Software Team
6
6
  Maintainer: OCD - Cairo Software Team
@@ -3,7 +3,7 @@ name = "zscams_agent"
3
3
 
4
4
  [tool.poetry]
5
5
  name = "zscams"
6
- version = "2.0.7"
6
+ version = "2.0.9"
7
7
  description = "Async TLS tunnel client with SNI routing, auto-reconnect, and health checks"
8
8
  authors = ["OCD - Cairo Software Team"]
9
9
  maintainers = ["OCD - Cairo Software Team"]
@@ -6,6 +6,7 @@ import asyncio
6
6
  import sys
7
7
  import os
8
8
  from zscams.agent.src.core.backend.bootstrap import bootstrap
9
+ from zscams.agent.src.core.backend.unbootstrap import unbootstrap
9
10
  from zscams.agent.src.core.backend.update_machine_info import update_machine_info
10
11
  from zscams.agent.src.support.logger import get_logger
11
12
  from zscams.agent import init_parser, ensure_bootstrapped, run
@@ -32,6 +33,17 @@ def main():
32
33
  update_machine_info()
33
34
  sys.exit(0)
34
35
 
36
+ if args.unbootstrap:
37
+ try:
38
+ if os.geteuid() != 0:
39
+ logger.error("You are NOT running as root.")
40
+ sys.exit(1)
41
+ unbootstrap()
42
+ sys.exit(0)
43
+ except Exception as exception:
44
+ logger.error(exception)
45
+ sys.exit(1)
46
+
35
47
  try:
36
48
  ensure_bootstrapped()
37
49
  asyncio.run(run())
@@ -22,10 +22,15 @@ def init_parser():
22
22
  action="store_true",
23
23
  help="Run bootstrap process and exit",
24
24
  )
25
+ parser.add_argument(
26
+ "--unbootstrap",
27
+ action="store_true",
28
+ help="Run unbootstrap process and exit",
29
+ )
25
30
  parser.add_argument(
26
31
  "--update-machine-info",
27
32
  action="store_true",
28
- help="Run bootstrap process and exit",
33
+ help="Reinitialize machine info",
29
34
  )
30
35
  return parser
31
36
 
@@ -4,7 +4,7 @@ import sysconfig
4
4
  import sys
5
5
  from typing import cast
6
6
  from zscams.agent.src.core.backend.client import backend_client
7
- from zscams.agent.src.support.configuration import reinitialize
7
+ from zscams.agent.src.support.configuration import reinitialize, CONFIG_PATH
8
8
  from zscams.agent.src.support.logger import get_logger
9
9
  from zscams.agent.src.support.os import create_system_user, install_service, is_freebsd
10
10
  from zscams.agent.src.support.ssh import add_to_authorized_keys
@@ -47,6 +47,8 @@ def bootstrap():
47
47
  f"{equipment_type.lower()}-{customer_name.lower()}-{connector_name.lower()}"
48
48
  )
49
49
  enforced_id = prompt("Enforced ID", "Enforced Agent ID")
50
+ if not os.path.exists(CONFIG_PATH):
51
+ os.remove(CONFIG_PATH)
50
52
  reinitialize(equipment_name=equipment_name, equipment_type=equipment_type)
51
53
  cm_info = backend_client.bootstrap(equipment_name, enforced_id or None)
52
54
 
@@ -0,0 +1,49 @@
1
+ import os
2
+ from zscams.agent.src.support.filesystem import resolve_path
3
+ from zscams.agent.src.support.configuration import get_config, CONFIG_PATH, ROOT_PATH
4
+ from zscams.agent.src.core.backend.client import BackendClient
5
+ from zscams.agent.src.support.logger import get_logger
6
+ from zscams.agent.src.support.os import remove_service, is_freebsd
7
+
8
+ logger = get_logger("Unbootstrap")
9
+
10
+
11
+ def unbootstrap():
12
+ remote_configs = get_config().get("remote", {})
13
+ backend_config = get_config().get("backend", {})
14
+ private_key_path = resolve_path(
15
+ remote_configs.get("client_key"), os.path.dirname(CONFIG_PATH)
16
+ )
17
+
18
+ cert_path = resolve_path(
19
+ remote_configs.get("client_key"), os.path.dirname(CONFIG_PATH)
20
+ )
21
+
22
+ ca_chain_path = resolve_path(
23
+ remote_configs.get("client_key"), os.path.dirname(CONFIG_PATH)
24
+ )
25
+
26
+ cache_path = os.path.join(
27
+ ROOT_PATH.parent,
28
+ backend_config.get("cache_dir"),
29
+ BackendClient.MACHINE_INFO_FILE_NAME,
30
+ )
31
+
32
+ if os.path.exists(private_key_path):
33
+ os.remove(private_key_path)
34
+ logger.debug("Removed private key")
35
+
36
+ if os.path.exists(cert_path):
37
+ os.remove(cert_path)
38
+ logger.debug("Removed certificate")
39
+
40
+ if os.path.exists(ca_chain_path):
41
+ os.remove(ca_chain_path)
42
+ logger.debug("Removed CA Chain")
43
+
44
+ if os.path.exists(cache_path):
45
+ os.remove(cache_path)
46
+ logger.debug("Removed Machine info")
47
+
48
+ remove_service("zscams" if is_freebsd() else "zscams.service")
49
+ logger.debug("Removed ZSCAMs service")
@@ -43,7 +43,7 @@ async def run():
43
43
 
44
44
  # Add additional SSH options
45
45
  ssh_cmd += SSH_OPTIONS
46
-
46
+ os.chmod(PRIVATE_KEY, 0o700)
47
47
  logger.info(f"Starting reverse SSH tunnel: {' '.join(ssh_cmd)}")
48
48
 
49
49
  while True:
@@ -45,7 +45,7 @@ async def run():
45
45
 
46
46
  # Add additional SSH options
47
47
  ssh_cmd += SSH_OPTIONS
48
-
48
+ os.chmod(PRIVATE_KEY, 0o700)
49
49
  logger.info(f"Starting reverse SSH tunnel: {' '.join(ssh_cmd)}")
50
50
 
51
51
  while True:
@@ -10,6 +10,7 @@ import socket
10
10
  import platform
11
11
  from zscams.agent.src.support.logger import get_logger
12
12
  from http.client import BadStatusLine, HTTPConnection, HTTPException
13
+
13
14
  logger = get_logger("system_monitor")
14
15
 
15
16
  # Load service-specific params from environment
@@ -30,8 +31,6 @@ SERVICE_NAME = params.get("service_name", "Zscaler-AppConnector")
30
31
  HOSTNAME = platform.node()
31
32
 
32
33
 
33
-
34
-
35
34
  def network():
36
35
  """
37
36
  Collect network interfaces and their statistics.
@@ -232,7 +231,6 @@ def log():
232
231
  }
233
232
 
234
233
 
235
-
236
234
  # -----------------------------
237
235
  # Helper function to log JSON
238
236
  # -----------------------------
@@ -249,13 +247,14 @@ async def send_json_log(payload: dict):
249
247
 
250
248
 
251
249
  async def schedule_task(interval):
252
- while (True):
250
+ while True:
253
251
  try:
254
252
  await send_json_log(log())
255
253
  except Exception as exception:
256
254
  print(exception)
257
255
  await asyncio.sleep(interval)
258
256
 
257
+
259
258
  if __name__ == "__main__":
260
259
  try:
261
260
  asyncio.run(schedule_task(30))
@@ -48,7 +48,7 @@ def is_file_exists(path, logger, base_dir=None):
48
48
  return False
49
49
 
50
50
 
51
- def append_to_file(path: str | Path, content: str):
51
+ def append_to_file(path, content: str):
52
52
  try:
53
53
  if isinstance(path, str):
54
54
  path = Path(path)
@@ -63,6 +63,6 @@ def append_to_file(path: str | Path, content: str):
63
63
  raise exception
64
64
 
65
65
 
66
- def write_to_file(path: str | Path, content: str):
66
+ def write_to_file(path: str, content: str):
67
67
  with open(path, "w", encoding="utf-8") as f:
68
68
  f.write(content)
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import sys
2
3
  import subprocess
3
4
  import platform
@@ -136,3 +137,53 @@ def install_systemd_service(service_name: str, content: str):
136
137
  service_name,
137
138
  service_name,
138
139
  )
140
+
141
+
142
+ def remove_service(service_name: str):
143
+ """
144
+ Stops, disables, and removes service configurations for Linux and FreeBSD.
145
+ """
146
+ # Standardize name (remove .service suffix if present for consistency)
147
+ clean_name = service_name.replace(".service", "")
148
+
149
+ if is_linux():
150
+ _remove_systemd_service(clean_name)
151
+ elif is_freebsd():
152
+ _remove_rc_service(clean_name)
153
+ else:
154
+ logger.error("Unsupported OS for service removal.")
155
+
156
+
157
+ def _remove_systemd_service(name: str):
158
+ service_file = f"/etc/systemd/system/{name}.service"
159
+ try:
160
+ logger.info("Stopping and disabling systemd service: %s", name)
161
+ subprocess.run(["sudo", "systemctl", "stop", name], check=False)
162
+ subprocess.run(["sudo", "systemctl", "disable", name], check=False)
163
+
164
+ if os.path.exists(service_file):
165
+ subprocess.run(["sudo", "rm", service_file], check=True)
166
+ subprocess.run(["sudo", "systemctl", "daemon-reload"], check=True)
167
+ logger.info("Systemd service %s removed.", name)
168
+ except subprocess.CalledProcessError as e:
169
+ logger.error("Failed to remove systemd service: %s", e)
170
+
171
+
172
+ def _remove_rc_service(name: str):
173
+ rc_file = f"/usr/local/etc/rc.d/{name}"
174
+ try:
175
+ logger.info("Stopping and disabling FreeBSD service: %s", name)
176
+ # 1. Stop the service
177
+ subprocess.run(["sudo", "service", name, "stop"], check=False)
178
+
179
+ # 2. Disable in /etc/rc.conf
180
+ # Using sysrc -x removes the variable entirely from rc.conf
181
+ subprocess.run(["sudo", "sysrc", "-x", f"{name}_enable"], check=False)
182
+
183
+ # 3. Remove the rc.d script
184
+ if os.path.exists(rc_file):
185
+ subprocess.run(["sudo", "rm", rc_file], check=True)
186
+ logger.info("FreeBSD rc script %s removed.", name)
187
+
188
+ except subprocess.CalledProcessError as e:
189
+ logger.error("Failed to remove FreeBSD service: %s", e)
File without changes
File without changes
File without changes
File without changes
File without changes