sciveo 0.1.17__tar.gz → 0.1.18__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 (51) hide show
  1. {sciveo-0.1.17 → sciveo-0.1.18}/PKG-INFO +1 -1
  2. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/monitoring/monitor.py +1 -1
  3. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/network/camera.py +37 -18
  4. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/network/tools.py +0 -1
  5. sciveo-0.1.18/sciveo/network/tunnel.py +131 -0
  6. sciveo-0.1.18/sciveo/version.py +2 -0
  7. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/PKG-INFO +1 -1
  8. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/SOURCES.txt +1 -0
  9. sciveo-0.1.17/sciveo/version.py +0 -2
  10. {sciveo-0.1.17 → sciveo-0.1.18}/README.md +0 -0
  11. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/__init__.py +0 -0
  12. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/api/__init__.py +0 -0
  13. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/api/base.py +0 -0
  14. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/api/upload.py +0 -0
  15. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/cli.py +0 -0
  16. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/__init__.py +0 -0
  17. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/configuration.py +0 -0
  18. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/model.py +0 -0
  19. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/optimizers.py +0 -0
  20. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/sampling.py +0 -0
  21. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/__init__.py +0 -0
  22. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/compress.py +0 -0
  23. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/configuration.py +0 -0
  24. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/crypto.py +0 -0
  25. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/daemon.py +0 -0
  26. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/formating.py +0 -0
  27. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/hardware.py +0 -0
  28. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/logger.py +0 -0
  29. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/random.py +0 -0
  30. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/synchronized.py +0 -0
  31. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/common/tools/timers.py +0 -0
  32. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/content/__init__.py +0 -0
  33. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/content/dataset.py +0 -0
  34. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/content/experiment.py +0 -0
  35. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/content/project.py +0 -0
  36. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/content/runner.py +0 -0
  37. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/monitoring/__init__.py +0 -0
  38. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/monitoring/start.py +0 -0
  39. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo/network/__init__.py +0 -0
  40. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/dependency_links.txt +0 -0
  41. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/entry_points.txt +0 -0
  42. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/requires.txt +0 -0
  43. {sciveo-0.1.17 → sciveo-0.1.18}/sciveo.egg-info/top_level.txt +0 -0
  44. {sciveo-0.1.17 → sciveo-0.1.18}/setup.cfg +0 -0
  45. {sciveo-0.1.17 → sciveo-0.1.18}/setup.py +0 -0
  46. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_compress.py +0 -0
  47. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_configuration.py +0 -0
  48. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_crypto.py +0 -0
  49. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_monitoring.py +0 -0
  50. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_runner.py +0 -0
  51. {sciveo-0.1.17 → sciveo-0.1.18}/test/test_sampling.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -101,7 +101,7 @@ class BaseMonitor(DaemonBase):
101
101
  try:
102
102
  usage_per_core = psutil.cpu_percent(interval=None, percpu=True)
103
103
  self.data["CPU"]["usage per core"] = usage_per_core
104
- self.data["CPU"]["usage"] = np.array(usage_per_core).mean()
104
+ self.data["CPU"]["usage"] = float(np.array(usage_per_core).mean())
105
105
  except Exception:
106
106
  pass
107
107
 
@@ -1,6 +1,19 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import time
1
13
  import threading
2
14
  import cv2
3
15
  import numpy as np
16
+ from scapy.all import sniff, IP, TCP, UDP
4
17
 
5
18
  from sciveo.common.tools.logger import *
6
19
  from sciveo.common.tools.timers import FPSCounter
@@ -8,12 +21,17 @@ from sciveo.network.tools import StreamSniffer
8
21
 
9
22
 
10
23
  class RTSPStreamSniffer(StreamSniffer):
24
+ def __init__(self, iface=None, port=554):
25
+ super().__init__(iface)
26
+ self.port = port
27
+
11
28
  def on_packet(self, packet):
12
29
  if self.is_rtsp_packet(packet):
13
30
  self.append_ip_packet(packet)
14
31
 
15
32
  def is_rtsp_packet(self, packet):
16
- return IP in packet and TCP in packet and (packet[TCP].dport == 554 or packet[TCP].sport == 554)
33
+ return IP in packet and TCP in packet and (packet[TCP].dport == self.port or packet[TCP].sport == self.port)
34
+ # return IP in packet and ( (TCP in packet and (packet[TCP].dport == self.port or packet[TCP].sport == self.port)) or (UDP in packet and (packet[UDP].dport == self.port or packet[UDP].sport == self.port)) )
17
35
 
18
36
  def get_rtsp_frames(self, ip_src):
19
37
  frames = []
@@ -40,24 +58,25 @@ class RTSPStreamSniffer(StreamSniffer):
40
58
  if cv2.waitKey(1) & 0xFF == ord('q'):
41
59
  return
42
60
 
61
+ def play_cams(self, list_cams):
62
+ threads = []
63
+ for ip in list_cams:
64
+ t = threading.Thread(target=self.play, args=(ip,))
65
+ t.start()
66
+ threads.append(t)
43
67
 
44
- if __name__ == '__main__':
45
- sniffer = RTSPStreamSniffer(iface="eth0")
46
- sniffer.start()
68
+ self.start()
47
69
 
48
- camera_ips = []
70
+ try:
71
+ while True:
72
+ time.sleep(1)
73
+ except KeyboardInterrupt:
74
+ self.stop()
75
+ for t in threads:
76
+ t.join()
77
+ cv2.destroyAllWindows()
49
78
 
50
- threads = []
51
- for ip in camera_ips:
52
- t = threading.Thread(target=sniffer.play, args=(ip,))
53
- t.start()
54
- threads.append(t)
55
79
 
56
- try:
57
- while True:
58
- pass
59
- except KeyboardInterrupt:
60
- sniffer.stop_sniffing()
61
- for t in threads:
62
- t.join()
63
- cv2.destroyAllWindows()
80
+ if __name__ == '__main__':
81
+ sniffer = RTSPStreamSniffer(iface="en0", port=554)
82
+ sniffer.play_cams([])
@@ -93,7 +93,6 @@ class NetworkTools:
93
93
  pass
94
94
 
95
95
 
96
-
97
96
  class StreamSniffer:
98
97
  def __init__(self, iface=None):
99
98
  self.iface = iface
@@ -0,0 +1,131 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+
13
+ import os
14
+ import subprocess
15
+
16
+ from sciveo.common.tools.logger import *
17
+
18
+
19
+ class WireGuardBase:
20
+ def __init__(self, interface='wg0'):
21
+ self.interface = interface
22
+ self.config_path = f'/etc/wireguard/{self.interface}.conf'
23
+ self.private_key = None
24
+ self.public_key = None
25
+
26
+ def _run_command(self, command):
27
+ try:
28
+ result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
29
+ return result.stdout.decode().strip()
30
+ except subprocess.CalledProcessError as e:
31
+ debug(type(self).__name__, f"Error executing command: {e.stderr.decode().strip()}")
32
+ return None
33
+
34
+ def generate_keys(self, private_key_path=None, public_key_path=None):
35
+ # Generate the private key
36
+ self.private_key = self._run_command("wg genkey")
37
+ if not self.private_key:
38
+ raise Exception("Failed to generate private key.")
39
+
40
+ # Generate the public key from the private key
41
+ self.public_key = self._run_command(f"echo {self.private_key} | wg pubkey")
42
+ if not self.public_key:
43
+ raise Exception("Failed to generate public key.")
44
+
45
+ # Optionally save the keys to files
46
+ if private_key_path:
47
+ with open(private_key_path, 'w') as f:
48
+ f.write(self.private_key)
49
+ debug(type(self).__name__, f"Private key saved to {private_key_path}")
50
+
51
+ if public_key_path:
52
+ with open(public_key_path, 'w') as f:
53
+ f.write(self.public_key)
54
+ debug(type(self).__name__, f"Public key saved to {public_key_path}")
55
+
56
+ return self.private_key, self.public_key
57
+
58
+ def start(self):
59
+ debug(type(self).__name__, f"Starting WireGuard interface {self.interface}...")
60
+ return self._run_command(f'sudo systemctl start [email protected]{self.interface}')
61
+
62
+ def stop(self):
63
+ debug(type(self).__name__, f"Stopping WireGuard interface {self.interface}...")
64
+ return self._run_command(f'sudo systemctl stop [email protected]{self.interface}')
65
+
66
+ def restart(self):
67
+ debug(type(self).__name__, f"Restarting WireGuard interface {self.interface}...")
68
+ return self._run_command(f'sudo systemctl restart [email protected]{self.interface}')
69
+
70
+ def status(self):
71
+ debug(type(self).__name__, f"Checking status of WireGuard interface {self.interface}...")
72
+ return self._run_command(f'sudo systemctl status [email protected]{self.interface}')
73
+
74
+ class WGServer(WireGuardBase):
75
+ def init(self, private_key=None, listen_port=51820, address='192.168.21.1/24'):
76
+ if not private_key:
77
+ private_key = self.private_key
78
+ config = f"""
79
+ [Interface]
80
+ Address = {address}
81
+ ListenPort = {listen_port}
82
+ PrivateKey = {private_key}
83
+ SaveConfig = true
84
+ """
85
+ with open(self.config_path, 'w') as config_file:
86
+ config_file.write(config.strip())
87
+ debug(type(self).__name__, f"Server configuration written to {self.config_path}")
88
+
89
+ def add_peer(self, peer_public_key, allowed_ips):
90
+ peer_config = f"""
91
+ [Peer]
92
+ PublicKey = {peer_public_key}
93
+ AllowedIPs = {allowed_ips}
94
+ """
95
+ with open(self.config_path, 'a') as config_file:
96
+ config_file.write(peer_config.strip())
97
+ debug(type(self).__name__, f"Added peer with PublicKey: {peer_public_key}")
98
+
99
+ class WGClient(WireGuardBase):
100
+ def init(self, private_key=None, server_public_key=None, endpoint=None, address='192.168.21.2/24', allowed_ips='0.0.0.0/0', keepalive=25):
101
+ if not private_key:
102
+ private_key = self.private_key
103
+ config = f"""
104
+ [Interface]
105
+ Address = {address}
106
+ PrivateKey = {private_key}
107
+
108
+ [Peer]
109
+ PublicKey = {server_public_key}
110
+ Endpoint = {endpoint}
111
+ AllowedIPs = {allowed_ips}
112
+ PersistentKeepalive = {keepalive}
113
+ """
114
+ with open(self.config_path, 'w') as config_file:
115
+ config_file.write(config.strip())
116
+ debug(type(self).__name__, f"Client configuration written to {self.config_path}")
117
+
118
+
119
+ if __name__ == "__main__":
120
+ server = WGServer(interface='wg0')
121
+ server.generate_keys(private_key_path='/etc/wireguard/server_private.key', public_key_path='/etc/wireguard/server_public.key')
122
+ server.init(private_key=server.private_key, listen_port=51820, address='192.168.21.1/24')
123
+ server.add_peer(peer_public_key='<client_public_key>', allowed_ips='192.168.21.2/32')
124
+ server.start()
125
+ debug(type(self).__name__, server.status())
126
+
127
+ # client = WGClient(interface='wg0')
128
+ # client.generate_keys(private_key_path='/etc/wireguard/client_private.key', public_key_path='/etc/wireguard/client_public.key')
129
+ # client.init(private_key=client.private_key, server_public_key='<server_public_key>', endpoint='<server_ip>:51820')
130
+ # client.start()
131
+ # debug(type(self).__name__, client.status())
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.18'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -39,6 +39,7 @@ sciveo/monitoring/start.py
39
39
  sciveo/network/__init__.py
40
40
  sciveo/network/camera.py
41
41
  sciveo/network/tools.py
42
+ sciveo/network/tunnel.py
42
43
  test/test_compress.py
43
44
  test/test_configuration.py
44
45
  test/test_crypto.py
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.1.17'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes