Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14025 fix script name checking #14030

Merged
merged 7 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,10 @@ def get(self, request):
})


def get_report_module(module, request):
return get_object_or_404(ReportModule.objects.restrict(request.user), file_path__regex=f"^{module}\\.")


class ReportView(ContentTypePermissionRequiredMixin, View):
"""
Display a single Report and its associated Job (if any).
Expand All @@ -986,7 +990,7 @@ def get_required_permission(self):
return 'extras.view_report'

def get(self, request, module, name):
module = get_object_or_404(ReportModule.objects.restrict(request.user), file_path__startswith=module)
module = get_report_module(module, request)
report = module.reports[name]()

object_type = ContentType.objects.get(app_label='extras', model='reportmodule')
Expand All @@ -1007,7 +1011,7 @@ def post(self, request, module, name):
if not request.user.has_perm('extras.run_report'):
return HttpResponseForbidden()

module = get_object_or_404(ReportModule.objects.restrict(request.user), file_path__startswith=module)
module = get_report_module(module, request)
report = module.reports[name]()
form = ReportForm(request.POST, scheduling_enabled=report.scheduling_enabled)

Expand Down Expand Up @@ -1046,7 +1050,7 @@ def get_required_permission(self):
return 'extras.view_report'

def get(self, request, module, name):
module = get_object_or_404(ReportModule.objects.restrict(request.user), file_path__startswith=module)
module = get_report_module(module, request)
report = module.reports[name]()

return render(request, 'extras/report/source.html', {
Expand All @@ -1062,7 +1066,7 @@ def get_required_permission(self):
return 'extras.view_report'

def get(self, request, module, name):
module = get_object_or_404(ReportModule.objects.restrict(request.user), file_path__startswith=module)
module = get_report_module(module, request)
report = module.reports[name]()

object_type = ContentType.objects.get(app_label='extras', model='reportmodule')
Expand Down Expand Up @@ -1151,13 +1155,17 @@ def get(self, request):
})


def get_script_module(module, request):
arthanson marked this conversation as resolved.
Show resolved Hide resolved
return get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__regex=f"^{module}\\.")


class ScriptView(ContentTypePermissionRequiredMixin, View):

def get_required_permission(self):
return 'extras.view_script'

def get(self, request, module, name):
module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module)
module = get_script_module(module, request)
script = module.scripts[name]()
form = script.as_form(initial=normalize_querydict(request.GET))

Expand All @@ -1181,7 +1189,7 @@ def post(self, request, module, name):
if not request.user.has_perm('extras.run_script'):
return HttpResponseForbidden()

module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module)
module = get_script_module(module, request)
script = module.scripts[name]()
form = script.as_form(request.POST, request.FILES)

Expand Down Expand Up @@ -1218,7 +1226,7 @@ def get_required_permission(self):
return 'extras.view_script'

def get(self, request, module, name):
module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module)
module = get_script_module(module, request)
script = module.scripts[name]()

return render(request, 'extras/script/source.html', {
Expand All @@ -1234,7 +1242,7 @@ def get_required_permission(self):
return 'extras.view_script'

def get(self, request, module, name):
module = get_object_or_404(ScriptModule.objects.restrict(request.user), file_path__startswith=module)
module = get_script_module(module, request)
script = module.scripts[name]()

object_type = ContentType.objects.get(app_label='extras', model='scriptmodule')
Expand Down