arthexis 0.1.20__py3-none-any.whl → 0.1.22__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.

Potentially problematic release.


This version of arthexis might be problematic. Click here for more details.

core/environment.py CHANGED
@@ -1,17 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
- import re
5
- import shlex
6
- import subprocess
7
- from pathlib import Path
8
-
9
- from django import forms
10
4
  from django.conf import settings
11
5
  from django.contrib import admin
12
- from django.core.exceptions import PermissionDenied
13
6
  from django.template.response import TemplateResponse
14
- from django.urls import path, reverse
7
+ from django.urls import path
15
8
  from django.utils.translation import gettext_lazy as _
16
9
 
17
10
 
@@ -21,224 +14,18 @@ def _get_django_settings():
21
14
  )
22
15
 
23
16
 
24
- class NetworkSetupForm(forms.Form):
25
- prompt_for_password = forms.BooleanField(
26
- label=_("Prompt for new WiFi password"),
27
- required=False,
28
- help_text=_("Add --password to request a password even when one is already configured."),
29
- )
30
- access_point_name = forms.CharField(
31
- label=_("Access point name"),
32
- required=False,
33
- max_length=32,
34
- help_text=_("Use --ap to set the wlan0 access point name."),
35
- )
36
- skip_firewall_validation = forms.BooleanField(
37
- label=_("Skip firewall validation"),
38
- required=False,
39
- help_text=_("Add --no-firewall to bypass firewall port checks."),
40
- )
41
- skip_access_point_configuration = forms.BooleanField(
42
- label=_("Skip access point configuration"),
43
- required=False,
44
- help_text=_("Add --no-ap to leave the access point configuration unchanged."),
45
- )
46
- allow_unsafe_changes = forms.BooleanField(
47
- label=_("Allow modifying the active internet connection"),
48
- required=False,
49
- help_text=_("Include --unsafe to allow changes that may interrupt connectivity."),
50
- )
51
- interactive = forms.BooleanField(
52
- label=_("Prompt before each step"),
53
- required=False,
54
- help_text=_("Run the script with --interactive to confirm each action."),
55
- )
56
- install_watchdog = forms.BooleanField(
57
- label=_("Install WiFi watchdog service"),
58
- required=False,
59
- initial=True,
60
- help_text=_("Keep selected to retain the watchdog or clear to add --no-watchdog."),
61
- )
62
- vnc_validation = forms.ChoiceField(
63
- label=_("VNC validation"),
64
- choices=(
65
- ("default", _("Use script default (skip validation)")),
66
- ("require", _("Require that a VNC service is enabled (--vnc)")),
67
- ),
68
- initial="default",
69
- required=True,
70
- )
71
- ethernet_subnet = forms.CharField(
72
- label=_("Ethernet subnet"),
73
- required=False,
74
- help_text=_("Provide N or N/P (prefix 16 or 24) to supply --subnet."),
75
- )
76
- update_ap_password_only = forms.BooleanField(
77
- label=_("Update access point password only"),
78
- required=False,
79
- help_text=_("Use --ap-set-password without running other setup steps."),
80
- )
81
-
82
- def clean_ethernet_subnet(self) -> str:
83
- value = self.cleaned_data.get("ethernet_subnet", "")
84
- if not value:
85
- return ""
86
- raw = value.strip()
87
- match = re.fullmatch(r"(?P<subnet>\d{1,3})(?:/(?P<prefix>\d{1,2}))?", raw)
88
- if not match:
89
- raise forms.ValidationError(
90
- _("Enter a subnet in the form N or N/P with prefix 16 or 24."),
91
- )
92
- subnet = int(match.group("subnet"))
93
- if subnet < 0 or subnet > 254:
94
- raise forms.ValidationError(
95
- _("Subnet value must be between 0 and 254."),
96
- )
97
- prefix_value = match.group("prefix")
98
- if prefix_value:
99
- prefix = int(prefix_value)
100
- if prefix not in {16, 24}:
101
- raise forms.ValidationError(
102
- _("Subnet prefix must be 16 or 24."),
103
- )
104
- return f"{subnet}/{prefix}"
105
- return str(subnet)
106
-
107
- def clean(self) -> dict:
108
- cleaned_data = super().clean()
109
- if cleaned_data.get("update_ap_password_only"):
110
- other_flags = [
111
- cleaned_data.get("prompt_for_password"),
112
- bool(cleaned_data.get("access_point_name")),
113
- cleaned_data.get("skip_firewall_validation"),
114
- cleaned_data.get("skip_access_point_configuration"),
115
- cleaned_data.get("allow_unsafe_changes"),
116
- cleaned_data.get("interactive"),
117
- bool(cleaned_data.get("ethernet_subnet")),
118
- cleaned_data.get("vnc_validation") == "require",
119
- not cleaned_data.get("install_watchdog", True),
120
- ]
121
- if any(other_flags):
122
- raise forms.ValidationError(
123
- _(
124
- "Update access point password only cannot be combined with other network-setup options."
125
- )
126
- )
127
- return cleaned_data
128
-
129
- def build_command(self, script_path: Path) -> list[str]:
130
- command = [str(script_path)]
131
- data = self.cleaned_data
132
- if data.get("update_ap_password_only"):
133
- command.append("--ap-set-password")
134
- return command
135
- if data.get("prompt_for_password"):
136
- command.append("--password")
137
- access_point_name = data.get("access_point_name")
138
- if access_point_name:
139
- command.extend(["--ap", access_point_name])
140
- if data.get("skip_firewall_validation"):
141
- command.append("--no-firewall")
142
- if data.get("skip_access_point_configuration"):
143
- command.append("--no-ap")
144
- if data.get("allow_unsafe_changes"):
145
- command.append("--unsafe")
146
- if data.get("interactive"):
147
- command.append("--interactive")
148
- if not data.get("install_watchdog"):
149
- command.append("--no-watchdog")
150
- if data.get("vnc_validation") == "require":
151
- command.append("--vnc")
152
- ethernet_subnet = data.get("ethernet_subnet")
153
- if ethernet_subnet:
154
- command.extend(["--subnet", ethernet_subnet])
155
- return command
156
-
157
-
158
17
  def _environment_view(request):
159
18
  env_vars = sorted(os.environ.items())
160
19
  context = admin.site.each_context(request)
161
- environment_tasks: list[dict[str, str]] = []
162
- if request.user.is_superuser:
163
- environment_tasks.append(
164
- {
165
- "name": _("Run network-setup"),
166
- "description": _(
167
- "Configure network services, stage managed NGINX sites, and review script output."
168
- ),
169
- "url": reverse("admin:environment-network-setup"),
170
- }
171
- )
172
20
  context.update(
173
21
  {
174
22
  "title": _("Environment"),
175
23
  "env_vars": env_vars,
176
- "environment_tasks": environment_tasks,
24
+ "environment_tasks": [],
177
25
  }
178
26
  )
179
27
  return TemplateResponse(request, "admin/environment.html", context)
180
28
 
181
-
182
- def _environment_network_setup_view(request):
183
- if not request.user.is_superuser:
184
- raise PermissionDenied
185
-
186
- script_path = Path(settings.BASE_DIR) / "network-setup.sh"
187
- command_result: dict[str, object] | None = None
188
-
189
- if request.method == "POST":
190
- form = NetworkSetupForm(request.POST)
191
- if form.is_valid():
192
- command = form.build_command(script_path)
193
- if not script_path.exists():
194
- form.add_error(None, _("The network-setup.sh script could not be found."))
195
- else:
196
- try:
197
- completed = subprocess.run(
198
- command,
199
- capture_output=True,
200
- text=True,
201
- cwd=settings.BASE_DIR,
202
- check=False,
203
- )
204
- except FileNotFoundError:
205
- form.add_error(None, _("The network-setup.sh script could not be executed."))
206
- except OSError as exc:
207
- form.add_error(
208
- None,
209
- _("Unable to execute network-setup.sh: %(error)s")
210
- % {"error": str(exc)},
211
- )
212
- else:
213
- if hasattr(shlex, "join"):
214
- command_display = shlex.join(command)
215
- else:
216
- command_display = " ".join(shlex.quote(part) for part in command)
217
- command_result = {
218
- "command": command_display,
219
- "stdout": completed.stdout,
220
- "stderr": completed.stderr,
221
- "returncode": completed.returncode,
222
- "succeeded": completed.returncode == 0,
223
- }
224
- else:
225
- form = NetworkSetupForm()
226
-
227
- context = admin.site.each_context(request)
228
- context.update(
229
- {
230
- "title": _("Run network-setup"),
231
- "form": form,
232
- "command_result": command_result,
233
- "task_description": _(
234
- "Configure script flags, execute network-setup, and review the captured output."
235
- ),
236
- "back_url": reverse("admin:environment"),
237
- }
238
- )
239
- return TemplateResponse(request, "admin/environment_network_setup.html", context)
240
-
241
-
242
29
  def _config_view(request):
243
30
  context = admin.site.each_context(request)
244
31
  context.update(
@@ -257,11 +44,6 @@ def patch_admin_environment_view() -> None:
257
44
  def get_urls():
258
45
  urls = original_get_urls()
259
46
  custom = [
260
- path(
261
- "environment/network-setup/",
262
- admin.site.admin_view(_environment_network_setup_view),
263
- name="environment-network-setup",
264
- ),
265
47
  path(
266
48
  "environment/",
267
49
  admin.site.admin_view(_environment_view),