sciveo 0.1.18__tar.gz → 0.1.20__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 (54) hide show
  1. {sciveo-0.1.18 → sciveo-0.1.20}/PKG-INFO +1 -1
  2. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/cli.py +2 -1
  3. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/random.py +11 -0
  4. sciveo-0.1.20/sciveo/common/tools/remote.py +73 -0
  5. sciveo-0.1.20/sciveo/network/sniffer.py +75 -0
  6. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/network/tools.py +15 -64
  7. sciveo-0.1.20/sciveo/network/tunnel.py +17 -0
  8. sciveo-0.1.20/sciveo/version.py +2 -0
  9. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/PKG-INFO +1 -1
  10. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/SOURCES.txt +2 -0
  11. sciveo-0.1.18/sciveo/network/tunnel.py +0 -131
  12. sciveo-0.1.18/sciveo/version.py +0 -2
  13. {sciveo-0.1.18 → sciveo-0.1.20}/README.md +0 -0
  14. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/__init__.py +0 -0
  15. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/api/__init__.py +0 -0
  16. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/api/base.py +0 -0
  17. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/api/upload.py +0 -0
  18. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/__init__.py +0 -0
  19. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/configuration.py +0 -0
  20. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/model.py +0 -0
  21. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/optimizers.py +0 -0
  22. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/sampling.py +0 -0
  23. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/__init__.py +0 -0
  24. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/compress.py +0 -0
  25. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/configuration.py +0 -0
  26. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/crypto.py +0 -0
  27. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/daemon.py +0 -0
  28. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/formating.py +0 -0
  29. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/hardware.py +0 -0
  30. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/logger.py +0 -0
  31. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/synchronized.py +0 -0
  32. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/common/tools/timers.py +0 -0
  33. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/content/__init__.py +0 -0
  34. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/content/dataset.py +0 -0
  35. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/content/experiment.py +0 -0
  36. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/content/project.py +0 -0
  37. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/content/runner.py +0 -0
  38. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/monitoring/__init__.py +0 -0
  39. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/monitoring/monitor.py +0 -0
  40. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/monitoring/start.py +0 -0
  41. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/network/__init__.py +0 -0
  42. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo/network/camera.py +0 -0
  43. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/dependency_links.txt +0 -0
  44. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/entry_points.txt +0 -0
  45. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/requires.txt +0 -0
  46. {sciveo-0.1.18 → sciveo-0.1.20}/sciveo.egg-info/top_level.txt +0 -0
  47. {sciveo-0.1.18 → sciveo-0.1.20}/setup.cfg +0 -0
  48. {sciveo-0.1.18 → sciveo-0.1.20}/setup.py +0 -0
  49. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_compress.py +0 -0
  50. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_configuration.py +0 -0
  51. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_crypto.py +0 -0
  52. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_monitoring.py +0 -0
  53. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_runner.py +0 -0
  54. {sciveo-0.1.18 → sciveo-0.1.20}/test/test_sampling.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.18
3
+ Version: 0.1.20
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -29,6 +29,7 @@ def main():
29
29
  parser.add_argument('--block', type=bool, default=True, help='Block flag')
30
30
  parser.add_argument('--auth', type=str, default=config['secret_access_key'], help='Auth secret access key')
31
31
  parser.add_argument('--timeout', type=float, default=1.0, help='Timeout')
32
+ parser.add_argument('--net', type=str, default=None, help='Network like 192.168.10.0/24')
32
33
  parser.add_argument('--port', type=int, default=22, help='Host port number, used for network ops')
33
34
  parser.add_argument('--localhost', type=bool, default=False, help='Add localhost to list of hosts')
34
35
  args = parser.parse_args()
@@ -36,7 +37,7 @@ def main():
36
37
  if args.command == 'monitor':
37
38
  MonitorStart(period=args.period, block=args.block)()
38
39
  elif args.command == 'scan':
39
- NetworkTools(timeout=args.timeout, localhost=args.localhost).scan_port(port=args.port)
40
+ NetworkTools(timeout=args.timeout, localhost=args.localhost).scan_port(port=args.port, network=args.net)
40
41
  elif args.command == 'init':
41
42
  home = os.path.expanduser('~')
42
43
  base_path = os.path.join(home, '.sciveo')
@@ -1,3 +1,14 @@
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
+ # 2023
10
+ #
11
+
1
12
  import random
2
13
  import string
3
14
 
@@ -0,0 +1,73 @@
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 os
13
+ import time
14
+ import cv2
15
+ import base64
16
+ import requests
17
+
18
+ from sciveo.common.tools.logger import *
19
+ from sciveo.common.tools.configuration import GlobalConfiguration
20
+ from sciveo.common.tools.compress import CompressJsonData
21
+
22
+
23
+ class PredictorRemoteClient:
24
+ def __init__(self, url="http://localhost:8901", verify=True, auth_token=None, api_prefix=None):
25
+ debug(type(self).__name__, "init url", url, verify)
26
+ config = GlobalConfiguration.get()
27
+ if auth_token is None:
28
+ auth_token = config["api_auth_token"]
29
+ if api_prefix is None:
30
+ api_prefix = config["api_prefix"]
31
+ self.auth_token = auth_token
32
+ self.api_prefix = api_prefix
33
+ self.url = f"{url}/{self.api_prefix}/predict"
34
+ self.verify = verify
35
+ requests.packages.urllib3.disable_warnings()
36
+
37
+ def predict(self, params):
38
+ try:
39
+ debug(type(self).__name__, "predict", params)
40
+ headers = {"Authorization": f"Bearer {self.auth_token}"}
41
+ response = requests.post(self.url, json=params, headers=headers, verify=self.verify)
42
+
43
+ if response.status_code == 200:
44
+ data = response.json()
45
+
46
+ if params.get("compressed", 0) > 0 and params["predictor"] in data:
47
+ predicted = data[params["predictor"]]
48
+ predicted = CompressJsonData().decompress(predicted)
49
+ data[params["predictor"]] = predicted
50
+ else:
51
+ error(type(self).__name__, f"Request [{self.url}] failed with status code {response.status_code}")
52
+ data = {"error": response.status_code}
53
+ except Exception as e:
54
+ exception(type(self).__name__, "predict", e)
55
+ data = {"error": str(e)}
56
+ return data
57
+
58
+ def image_encoded(self, image=None, resize_to=(256, 256), local_path=None):
59
+ if local_path is not None:
60
+ image = cv2.imread(local_path)
61
+ if resize_to is not None:
62
+ image = cv2.resize(image, resize_to)
63
+ buffer = cv2.imencode('.jpg', image)[1].tobytes()
64
+ return base64.b64encode(buffer).decode('utf-8')
65
+
66
+ def predict_image_embedding(self, image=None, resize_to=(256, 256), local_path=None):
67
+ image_base64 = self.image_encoded(image=image, resize_to=resize_to, local_path=local_path)
68
+ params = {
69
+ 'predictor': 'ImageEmbedding', 'compressed': 1,
70
+ 'X': [image_base64]
71
+ }
72
+ r = self.predict(params=params)
73
+ return r[params["predictor"]][0]
@@ -0,0 +1,75 @@
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 socket
13
+ import threading
14
+ from scapy.all import sniff, IP, TCP
15
+
16
+ from sciveo.common.tools.logger import *
17
+ from sciveo.common.tools.timers import Timer
18
+
19
+
20
+ class StreamSniffer:
21
+ def __init__(self, iface=None):
22
+ self.iface = iface
23
+ self.running = False
24
+ self.lock = threading.Lock()
25
+ self.streams = {}
26
+
27
+ def start(self):
28
+ self.running = True
29
+ self.sniff_thread = threading.Thread(target=self.sniff_packets)
30
+ self.sniff_thread.start()
31
+
32
+ def stop(self):
33
+ debug(type(self).__name__, "stopping...")
34
+ self.running = False
35
+ self.sniff_thread.join()
36
+
37
+ def sniff_packets(self):
38
+ debug(type(self).__name__, "start sniffing on", self.iface)
39
+ sniff(iface=self.iface, prn=self.on_packet, stop_filter=self.should_stop)
40
+
41
+ def on_packet(self, packet):
42
+ if IP in packet:
43
+ self.append_ip_packet(packet)
44
+
45
+ def should_stop(self, packet):
46
+ return not self.running
47
+
48
+ def append_ip_packet(self, packet):
49
+ ip_src = packet[IP].src
50
+ with self.lock:
51
+ self.streams.setdefault(ip_src, [])
52
+ self.streams[ip_src].append(packet)
53
+
54
+ def get_ip_stream(self, ip):
55
+ current_packets = []
56
+ with self.lock:
57
+ if ip in self.streams:
58
+ current_packets = self.streams[ip][:]
59
+ self.streams[ip] = []
60
+ return current_packets
61
+
62
+ def keys(self):
63
+ with self.lock:
64
+ return list(self.streams.keys())
65
+
66
+
67
+ if __name__ == "__main__":
68
+ # debug(NetworkTools(timeout=1.0, localhost=False).scan_port(port=9901))
69
+
70
+ import time
71
+ sniffer = StreamSniffer(iface="en0")
72
+ sniffer.start()
73
+ time.sleep(5)
74
+ sniffer.stop()
75
+ debug(sniffer.keys())
@@ -10,8 +10,8 @@
10
10
  #
11
11
 
12
12
  import socket
13
+ import ipaddress
13
14
  import threading
14
- from scapy.all import sniff, IP, TCP
15
15
 
16
16
  from sciveo.common.tools.logger import *
17
17
  from sciveo.common.tools.timers import Timer
@@ -56,14 +56,23 @@ class NetworkTools:
56
56
  network_prefix = '.'.join(octets[:3])
57
57
  return [f'{network_prefix}.{i}' for i in range(1, 255)]
58
58
 
59
- def scan_port(self, port=22):
59
+ def scan_port(self, port=22, network=None):
60
60
  t = Timer()
61
- list_local_ips = self.get_local_nets()
62
- # debug(type(self).__name__, "scan_port", "list_local_ips", list_local_ips)
63
61
  self.data["scan"].setdefault(port, [])
64
- for local_ip in list_local_ips:
65
- list_ip = self.generate_ip_list(local_ip)
62
+
63
+ if network is None:
64
+ list_local_ips = self.get_local_nets()
65
+ # debug(type(self).__name__, "scan_port", "list_local_ips", list_local_ips)
66
+ for local_ip in list_local_ips:
67
+ list_ip = self.generate_ip_list(local_ip)
68
+ self.scan_port_hosts(list_ip, port)
69
+ else:
70
+ list_ip = []
71
+ net = ipaddress.ip_network(network, strict=False)
72
+ for ip in net.hosts():
73
+ list_ip.append(str(ip))
66
74
  self.scan_port_hosts(list_ip, port)
75
+
67
76
  if self.arguments["localhost"]:
68
77
  self.scan_port_hosts(["127.0.0.1"], port)
69
78
  self.data["scan"][port].sort(key=lambda ip: int(ip.split('.')[-1]))
@@ -91,61 +100,3 @@ class NetworkTools:
91
100
  # debug(type(self).__name__, "scan_ports", ip, port, result)
92
101
  except socket.error:
93
102
  pass
94
-
95
-
96
- class StreamSniffer:
97
- def __init__(self, iface=None):
98
- self.iface = iface
99
- self.running = False
100
- self.lock = threading.Lock()
101
- self.streams = {}
102
-
103
- def start(self):
104
- self.running = True
105
- self.sniff_thread = threading.Thread(target=self.sniff_packets)
106
- self.sniff_thread.start()
107
-
108
- def stop(self):
109
- debug(type(self).__name__, "stopping...")
110
- self.running = False
111
- self.sniff_thread.join()
112
-
113
- def sniff_packets(self):
114
- debug(type(self).__name__, "start sniffing on", self.iface)
115
- sniff(iface=self.iface, prn=self.on_packet, stop_filter=self.should_stop)
116
-
117
- def on_packet(self, packet):
118
- if IP in packet:
119
- self.append_ip_packet(packet)
120
-
121
- def should_stop(self, packet):
122
- return not self.running
123
-
124
- def append_ip_packet(self, packet):
125
- ip_src = packet[IP].src
126
- with self.lock:
127
- self.streams.setdefault(ip_src, [])
128
- self.streams[ip_src].append(packet)
129
-
130
- def get_ip_stream(self, ip):
131
- current_packets = []
132
- with self.lock:
133
- if ip in self.streams:
134
- current_packets = self.streams[ip][:]
135
- self.streams[ip] = []
136
- return current_packets
137
-
138
- def keys(self):
139
- with self.lock:
140
- return list(self.streams.keys())
141
-
142
-
143
- if __name__ == "__main__":
144
- # debug(NetworkTools(timeout=1.0, localhost=False).scan_port(port=9901))
145
-
146
- import time
147
- sniffer = StreamSniffer(iface="en0")
148
- sniffer.start()
149
- time.sleep(5)
150
- sniffer.stop()
151
- debug(sniffer.keys())
@@ -0,0 +1,17 @@
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
+
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.20'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.18
3
+ Version: 0.1.20
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -26,6 +26,7 @@ sciveo/common/tools/formating.py
26
26
  sciveo/common/tools/hardware.py
27
27
  sciveo/common/tools/logger.py
28
28
  sciveo/common/tools/random.py
29
+ sciveo/common/tools/remote.py
29
30
  sciveo/common/tools/synchronized.py
30
31
  sciveo/common/tools/timers.py
31
32
  sciveo/content/__init__.py
@@ -38,6 +39,7 @@ sciveo/monitoring/monitor.py
38
39
  sciveo/monitoring/start.py
39
40
  sciveo/network/__init__.py
40
41
  sciveo/network/camera.py
42
+ sciveo/network/sniffer.py
41
43
  sciveo/network/tools.py
42
44
  sciveo/network/tunnel.py
43
45
  test/test_compress.py
@@ -1,131 +0,0 @@
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())
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.1.18'
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