ns2 0.2.6__py3-none-any.whl

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 (98) hide show
  1. ns2/__init__.py +0 -0
  2. ns2/core.py +0 -0
  3. ns2/dbus/__init__.py +0 -0
  4. ns2/dbus/dbus.py +13 -0
  5. ns2/lib/__init__.py +0 -0
  6. ns2/lib/accounts.py +130 -0
  7. ns2/lib/commands.py +32 -0
  8. ns2/lib/firewalld.py +167 -0
  9. ns2/lib/introspection/org.fedoraproject.FirewallD1.config.xml +3 -0
  10. ns2/lib/introspection/org.fedoraproject.FirewallD1.xml +763 -0
  11. ns2/lib/introspection/org.freedesktop.NetworkManager.AccessPoint.xml +106 -0
  12. ns2/lib/introspection/org.freedesktop.NetworkManager.AgentManager.xml +43 -0
  13. ns2/lib/introspection/org.freedesktop.NetworkManager.Checkpoint.xml +36 -0
  14. ns2/lib/introspection/org.freedesktop.NetworkManager.Connection.Active.xml +185 -0
  15. ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml +21 -0
  16. ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml +20 -0
  17. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml +21 -0
  18. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml +36 -0
  19. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bond.xml +40 -0
  20. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml +41 -0
  21. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml +20 -0
  22. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Generic.xml +27 -0
  23. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Hsr.xml +51 -0
  24. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml +107 -0
  25. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml +31 -0
  26. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ipvlan.xml +38 -0
  27. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Loopback.xml +8 -0
  28. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Lowpan.xml +27 -0
  29. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml +109 -0
  30. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml +39 -0
  31. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Modem.xml +62 -0
  32. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml +34 -0
  33. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsBridge.xml +21 -0
  34. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsInterface.xml +11 -0
  35. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsPort.xml +21 -0
  36. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ppp.xml +11 -0
  37. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml +35 -0
  38. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Team.xml +48 -0
  39. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Tun.xml +65 -0
  40. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Veth.xml +18 -0
  41. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml +45 -0
  42. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vrf.xml +18 -0
  43. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml +139 -0
  44. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml +109 -0
  45. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WifiP2P.xml +76 -0
  46. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WireGuard.xml +38 -0
  47. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wired.xml +53 -0
  48. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml +131 -0
  49. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wpan.xml +20 -0
  50. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.xml +407 -0
  51. ns2/lib/introspection/org.freedesktop.NetworkManager.DnsManager.xml +40 -0
  52. ns2/lib/introspection/org.freedesktop.NetworkManager.IP4Config.xml +125 -0
  53. ns2/lib/introspection/org.freedesktop.NetworkManager.IP6Config.xml +95 -0
  54. ns2/lib/introspection/org.freedesktop.NetworkManager.PPP.xml +34 -0
  55. ns2/lib/introspection/org.freedesktop.NetworkManager.SecretAgent.xml +94 -0
  56. ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml +224 -0
  57. ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.xml +233 -0
  58. ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml +42 -0
  59. ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml +204 -0
  60. ns2/lib/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml +35 -0
  61. ns2/lib/introspection/org.freedesktop.NetworkManager.WifiP2PPeer.xml +91 -0
  62. ns2/lib/introspection/org.freedesktop.NetworkManager.xml +598 -0
  63. ns2/lib/lib.py +0 -0
  64. ns2/lib/network_delay.py +92 -0
  65. ns2/lib/networking.py +528 -0
  66. ns2/lib/ntl.py +188 -0
  67. ns2/lib/pam_client.py +37 -0
  68. ns2/lib/ping_data_collector.py +37 -0
  69. ns2/lib/snmp.py +511 -0
  70. ns2/lib/socket.py +132 -0
  71. ns2/lib/socket_client.py +62 -0
  72. ns2/lib/systemd.py +151 -0
  73. ns2/lib/test.py +374 -0
  74. ns2/lib/udp_client.py +227 -0
  75. ns2/lib/udp_server.py +167 -0
  76. ns2/snmp/__init__.py +0 -0
  77. ns2/snmp/ns_dbus_service.py +38 -0
  78. ns2/snmp/pam_interface.py +19 -0
  79. ns2/snmp/snmp_interface.py +66 -0
  80. ns2/ui/__init__.py +0 -0
  81. ns2/ui/assets/NOVUS_LOGO.svg +105 -0
  82. ns2/ui/assets/favicon.png +0 -0
  83. ns2/ui/firewalld_page.py +375 -0
  84. ns2/ui/fpga_page.py +24 -0
  85. ns2/ui/login.py +65 -0
  86. ns2/ui/main.py +200 -0
  87. ns2/ui/networking_page.py +406 -0
  88. ns2/ui/ntp.py +105 -0
  89. ns2/ui/root.py +31 -0
  90. ns2/ui/snmp_page.py +353 -0
  91. ns2/ui/terminal.py +65 -0
  92. ns2/ui/tests_page.py +116 -0
  93. ns2/ui/theme.py +25 -0
  94. ns2/utils.py +5 -0
  95. ns2-0.2.6.dist-info/METADATA +78 -0
  96. ns2-0.2.6.dist-info/RECORD +98 -0
  97. ns2-0.2.6.dist-info/WHEEL +4 -0
  98. ns2-0.2.6.dist-info/entry_points.txt +3 -0
ns2/__init__.py ADDED
File without changes
ns2/core.py ADDED
File without changes
ns2/dbus/__init__.py ADDED
File without changes
ns2/dbus/dbus.py ADDED
@@ -0,0 +1,13 @@
1
+ from dbus_next import BusType
2
+ from dbus_next.aio import MessageBus
3
+
4
+ global AppBus
5
+
6
+ async def setup():
7
+ global AppBus
8
+ AppBus = await MessageBus(bus_type=BusType.SYSTEM).connect()
9
+
10
+ async def cleanup():
11
+ global AppBus
12
+ AppBus.disconnect()
13
+
ns2/lib/__init__.py ADDED
File without changes
ns2/lib/accounts.py ADDED
@@ -0,0 +1,130 @@
1
+ from dataclasses import asdict, dataclass
2
+ from typing import Optional
3
+ from nicegui import ui, app
4
+
5
+ @dataclass
6
+ class SystemAccount:
7
+ Name: Optional[str] = None
8
+ PrimaryId: Optional[str] = None
9
+ SecondaryId: Optional[str] = None
10
+ Info: Optional[str] = None
11
+ Home: Optional[str] = None
12
+ Shell: Optional[str] = None
13
+
14
+ @dataclass
15
+ class SystemGroup:
16
+ Name: Optional[str] = None
17
+ Id: Optional[str] = None
18
+ NumLocalUsers : Optional[str] = None
19
+ LocalUsers : Optional[str] = None
20
+
21
+ def ReadPasswordsFile() -> list[SystemAccount]:
22
+ accounts = []
23
+ with open("/etc/passwd", "r") as f:
24
+ content = f.readlines()
25
+ for i, line in enumerate(content):
26
+ if ":" in line:
27
+ fields = line.split(":")
28
+ name = fields[0]
29
+ primaryId = fields[2]
30
+ secondaryId = fields[3]
31
+ info = fields[4]
32
+ home = fields[5]
33
+ shell = fields[6]
34
+ a = SystemAccount(name, primaryId, secondaryId, info, home, shell)
35
+ accounts.append(a)
36
+ pass #endfor
37
+
38
+ return accounts
39
+
40
+
41
+ def ReadGroupFile() -> list[SystemGroup]:
42
+ groups = []
43
+ with open("/etc/group") as f:
44
+ content = f.readlines()
45
+
46
+ for i, line in enumerate(content):
47
+ if ":" in line:
48
+ fields = line.split(":")
49
+ name = fields[0]
50
+ id = fields[2]
51
+ accounts = fields[3].strip("\n")
52
+ num = len(accounts.split(","))
53
+ g = SystemGroup(name, id, num, accounts)
54
+ groups.append(g)
55
+ pass #endfor
56
+
57
+ return groups
58
+
59
+
60
+ def CombineGroupsAndAccounts():
61
+ accounts = ReadPasswordsFile()
62
+ groups = ReadGroupFile()
63
+
64
+ newgroups = []
65
+ for g in groups:
66
+ for a in accounts:
67
+ if g.Id == a.SecondaryId:
68
+ g.NumLocalUsers += 1
69
+ g.LocalUsers += f",{a.Name}"
70
+
71
+ newgroups.append(g)
72
+
73
+ return newgroups
74
+
75
+ def GetCombinedDict():
76
+ return [asdict(i) for i in CombineGroupsAndAccounts()]
77
+
78
+
79
+
80
+ def GetGroupDict():
81
+ return [asdict(i) for i in ReadGroupFile()]
82
+
83
+ def GetAccountsDict():
84
+ return [asdict(i) for i in ReadPasswordsFile()]
85
+
86
+
87
+
88
+ async def accounts_user_page(user: str):
89
+ #ui.label("User Configuration").classes("text-h5")
90
+ ui.label(user).classes("text-h5")
91
+
92
+
93
+ async def accounts_page():
94
+ """user page content"""
95
+
96
+ ui.label("User Configuration").classes("text-h5")
97
+
98
+ #table("Groups", GetCombinedDict(), "Name", add_group_dialog(), "Name,Id,NumLocalUsers,LocalUsers") # Only show these
99
+ #ui.table("Groups", , "Name", add_group_dialog(), "Name,PrimaryId,SecondaryId,Info,Home,Shell") # Only show these
100
+
101
+
102
+ with ui.dialog() as asGroupDialog:
103
+ with ui.card():
104
+ ui.label("test")
105
+ ui.input("name")
106
+ ui.input("id")
107
+ ui.button("create")
108
+ ui.button("cancel")
109
+
110
+
111
+
112
+ table = ui.table(
113
+ title="Groups",
114
+ rows=GetAccountsDict(),
115
+ column_defaults={
116
+ "align": "left",
117
+ "headerClasses": "uppercase text-primary",
118
+ },
119
+ ).classes("w-full")
120
+
121
+ table.add_slot(f'body-cell-Name', f''' <q-td :props="props">
122
+ <a :href="'/accounts/'+ props.row.Name" class="text-accent cursor-pointer hover:underline"> {{{{ props.value }}}} </a>
123
+ </q-td> ''')
124
+
125
+ table.props(f'visible-columns={"Name,PrimaryId,SecondaryId,Info,Home,Shell"}') # Only show these
126
+
127
+ with table.add_slot('top-right'):
128
+ ui.button(icon="add", on_click = asGroupDialog.open).props(
129
+ "flat color=accent align=left").classes("w-full").props("dense")
130
+
ns2/lib/commands.py ADDED
@@ -0,0 +1,32 @@
1
+
2
+
3
+ import asyncio
4
+ import subprocess
5
+
6
+
7
+ #def runCmd(args: list[str]) -> tuple[str, str]:
8
+ # print(f"running: {args}")
9
+ # result = subprocess.run(args, capture_output=True, text=True)
10
+ # return result.stdout
11
+
12
+
13
+ async def runCmd(args: list[str]) -> str:
14
+ print(f"running: {args}")
15
+ process = await asyncio.create_subprocess_exec(
16
+ *args,
17
+ stdout=asyncio.subprocess.PIPE,
18
+ stderr=asyncio.subprocess.PIPE
19
+ )
20
+ stdout, stderr = await process.communicate()
21
+ return stdout.decode()
22
+
23
+
24
+ async def runAsyncCmd(args: list[str]) -> str:
25
+ print(f"running: {args}")
26
+ process = await asyncio.create_subprocess_exec(
27
+ *args,
28
+ stdout=asyncio.subprocess.PIPE,
29
+ stderr=asyncio.subprocess.PIPE
30
+ )
31
+ stdout, stderr = await process.communicate()
32
+ return stdout.decode()
ns2/lib/firewalld.py ADDED
@@ -0,0 +1,167 @@
1
+ import asyncio
2
+ from dataclasses import asdict, field
3
+ from pprint import pprint
4
+ from typing import List, Optional
5
+ from nicegui import ui, app, binding
6
+ from ns.lib.commands import runCmd
7
+ from ns.ui.theme import init_colors
8
+
9
+
10
+ from dbus_next.signature import Variant
11
+ from dbus_next.errors import DBusError
12
+ from dbus_next.aio.proxy_object import ProxyInterface
13
+ from dbus_next.aio import MessageBus
14
+ from ns.dbus import dbus
15
+ from ns.utils import INTROSPECTION_DIR
16
+
17
+
18
+ @binding.bindable_dataclass
19
+ class ServiceSetting:
20
+ Version: Optional[str] = ''
21
+ Name: Optional[str] = ''
22
+ Description: Optional[str] = ''
23
+ Ports: Optional[list[str]] = field(default_factory=list)
24
+ ModuleNames: Optional[list[str]] = field(default_factory=list)
25
+ Destinations: Optional[dict] = field(default_factory=dict)
26
+ Protocols: Optional[list[str]] = field(default_factory=list)
27
+ SourcePorts: Optional[list[str]] = field(default_factory=list)
28
+ Includes: Optional[list[str]] = field(default_factory=list)
29
+ Helpers: Optional[list[str]] = field(default_factory=list)
30
+
31
+
32
+ @binding.bindable_dataclass
33
+ class ZoneSetting:
34
+ Description: Optional[str] = ''
35
+ Interfaces: Optional[list[str]] = field(default_factory=list)
36
+ Services: Optional[list[str]] = field(default_factory=list)
37
+ Short: Optional[str] = ''
38
+ ServiceSettings: Optional[dict[ServiceSetting]] = field(default_factory=dict)
39
+ Sources: Optional[list[str]] = field(default_factory=list)
40
+
41
+
42
+ @binding.bindable_dataclass
43
+ class Firewall:
44
+ Enable: Optional[bool] = False
45
+ Status: Optional[str] = ''
46
+ ActiveZones: Optional[dict[dict]] = field(default_factory=dict)
47
+ AllowedAddresses: Optional[list[str]] = field(default_factory=list)
48
+ Services: Optional[dict[dict]] = field(default_factory=dict)
49
+ ZoneSettings: Optional[dict[ZoneSetting]] = field(default_factory=dict)
50
+
51
+
52
+ async def GetFirewalld(bus: MessageBus):
53
+ file_name = 'org.fedoraproject.FirewallD1.config.xml'
54
+ introspection = await bus.introspect('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1')
55
+ #pprint(introspection.tostring())
56
+ obj = bus.get_proxy_object('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1', introspection)
57
+ return obj.get_interface('org.fedoraproject.FirewallD1')
58
+
59
+ async def GetFirewalldConfig(bus: MessageBus):
60
+ file_name = 'org.fedoraproject.FirewallD1.config.xml'
61
+ introspection = await bus.introspect('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1/config')
62
+ #pprint(introspection.tostring())
63
+ obj = bus.get_proxy_object('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1/config', introspection)
64
+ return obj.get_interface('org.fedoraproject.FirewallD1.config')
65
+
66
+
67
+
68
+ async def GetFirewalldConfigZone(bus: MessageBus, path : str):
69
+ introspection = await bus.introspect('org.fedoraproject.FirewallD1', path)
70
+ obj = bus.get_proxy_object('org.fedoraproject.FirewallD1', path, introspection)
71
+ return obj.get_interface('org.fedoraproject.FirewallD1.config.zone')
72
+
73
+ #def GetDevice(bus: MessageBus, path : str):
74
+ # file_name = 'org.freedesktop.NetworkManager.Device.xml'
75
+ # with open(str(INTROSPECTION_DIR /file_name), "r") as f:
76
+ # introspection = f.read()
77
+ # obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
78
+ # return obj.get_interface('org.freedesktop.NetworkManager.Device')
79
+
80
+ async def GetFirewalldZone(bus: MessageBus):
81
+ file_name = 'org.fedoraproject.FirewallD1.zone.xml'
82
+ introspection = await bus.introspect('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1')
83
+ #pprint(introspection.tostring())
84
+ obj = bus.get_proxy_object('org.fedoraproject.FirewallD1', '/org/fedoraproject/FirewallD1', introspection)
85
+ return obj.get_interface('org.fedoraproject.FirewallD1.zone')
86
+
87
+
88
+
89
+
90
+ def formatListToString(elements: list[str]) -> str:
91
+ if len(elements) == 0:
92
+ return None
93
+ return ', '.join(elements) if elements else ''
94
+
95
+ def getZoneInfo(name :str, zone :dict) -> dict:
96
+
97
+ interfaces = formatListToString(zone.get('interfaces', []))
98
+ sources = formatListToString(zone.get('sources', []))
99
+
100
+ return {'name':name, 'interfaces':interfaces, 'sources':sources}
101
+
102
+
103
+ async def getServices(bus: MessageBus):
104
+ '''all not just runtime'''
105
+
106
+ fire = await GetFirewalld(bus)
107
+
108
+ conf = await GetFirewalldConfig(bus)
109
+ serviceNames = await conf.call_get_service_names()
110
+ services = {}
111
+ for name in serviceNames:
112
+ s = ServiceSetting()
113
+ s.Name = name
114
+ serviceSettings = await fire.call_get_service_settings2(s.Name)
115
+
116
+ includes = serviceSettings.get('includes', False)
117
+ if includes:
118
+ for i in includes.value:
119
+ ser_set = await fire.call_get_service_settings2(i)
120
+ s.Ports.extend(ser_set.get('ports', Variant('a(ss)', [['port not available', 'protocol not available']])).value)
121
+
122
+
123
+ s.Name = serviceSettings.get('short', Variant('s', 'name not available')).value
124
+ s.Ports.extend(serviceSettings.get('ports', Variant('a(ss)', [['port not available', 'protocol not available']])).value)
125
+ s.Description = serviceSettings.get('description', Variant('s', 'Description not available')).value
126
+
127
+ services[name] = s
128
+
129
+
130
+ return services
131
+
132
+
133
+
134
+ def getUdpPorts(ports) -> list:
135
+ out = []
136
+ for p in ports:
137
+ if p[1]=='udp':
138
+ out.append(p[0])
139
+
140
+ return formatListToString(out)
141
+
142
+ def getTcpPorts(ports) -> list:
143
+ out = []
144
+ for p in ports:
145
+ if p[1]=='tcp':
146
+ out.append(p[0])
147
+
148
+ return formatListToString(out)
149
+
150
+
151
+
152
+ def formatServicesInRows(serviceSettings :dict):
153
+
154
+
155
+ rows = []
156
+ for n, s in serviceSettings.items():
157
+ rows.append({
158
+ #"Select": False,
159
+ "Service": n
160
+ ,"UDP": getUdpPorts(s.Ports)
161
+ ,"TCP": getTcpPorts(s.Ports)
162
+ ,"Description": s.Description
163
+ #,"remove": ''
164
+ })
165
+
166
+ #pprint(rows)
167
+ return rows
@@ -0,0 +1,3 @@
1
+ <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
2
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
3
+ <node />