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

Fix template; make pairing node specific; add debugging command #90

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions acl/management/commands/acl_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys

from django.core.management.base import BaseCommand

from acl.views import tags4machineBIN

from members.models import User
from acl.models import Machine, useNeedsToStateStr

class Command(BaseCommand):
help = "Export binary tag/member file for a given machine."

def add_arguments(self, parser):
parser.add_argument("machine", type=str, help="Machine this list is for")
parser.add_argument("user", type=str, help="User that list is for")

def handle(self, *args, **options):
rc = 0

terminal = None
machine = options["machine"]
user = options["user"]

machine = Machine.objects.get(node_machine_name=machine)
user = User.objects.get(last_name=user)

(needs, has) = machine.useState(user)
res = needs & has
print(f"has({has:X}) & needs({needs:X}) = {res:X}")
print(useNeedsToStateStr(needs,has))

sys.exit(rc)
9 changes: 5 additions & 4 deletions acl/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def api_gettags4machine(request, terminal=None, machine=None):
try:
machine = Machine.objects.get(name=machine)
except ObjectDoesNotExist:
logger.error(f"Machine {machine} not found, denied.")
logger.error(f"get4machine: Machine '{machine}' not found, denied.")
return HttpResponse("Machine not found", status=404, content_type="text/plain")

out = []
Expand Down Expand Up @@ -709,9 +709,10 @@ def byte_xor(ba1, ba2):
#
def tags4machineBIN(terminal=None, machine=None):
try:
machine = Machine.objects.get(name=machine)
machine = Machine.objects.get(node_machine_name=machine)
ctc = change_tracker_counter()
except ObjectDoesNotExist:
logger.error(f"BIN request for an unknown machine: {machine} (node-machine-name)")
raise ObjectDoesNotExist

tl = []
Expand Down Expand Up @@ -802,7 +803,7 @@ def api_gettags4machineBIN(request, terminal=None, machine=None):
try:
out = tags4machineBIN(terminal, machine)
except ObjectDoesNotExist:
logger.error(f"Machine {machine} not found, denied.")
logger.error(f"getBIN: Machine '{machine}' not found, denied.")
return HttpResponse("Machine not found", status=404, content_type="text/plain")
except Exception as e:
logger.error(f"Exception: {e}")
Expand All @@ -818,7 +819,7 @@ def api_getok(request, machine=None, tag=None):
try:
machine = Machine.objects.get(node_machine_name=machine)
except ObjectDoesNotExist:
logger.error("Machine '{}' not found, denied.".format(machine))
logger.error("getok: Machine '{}' not found, denied.".format(machine))
return HttpResponse("Machine not found", status=404, content_type="text/plain")
try:
r = RecentUse(user=tag.owner, machine=machine)
Expand Down
2 changes: 1 addition & 1 deletion pettycash/templates/pettycash/pair.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</form>
<hr>
<p>
<a href="{% url 'unpaired' user.id %}">Back to unpaired devices overview</a>
<a href="{% url 'unpaired' %}">Back to unpaired devices overview</a>
<p>
{% endblock %}
Loading