| 1 | #--------------------------------------------------------------- |
|---|
| 2 | # Project : pxemngr |
|---|
| 3 | # File : views.py |
|---|
| 4 | # Copyright : 2009-2010 Splitted-Desktop Systems |
|---|
| 5 | # Author : Frederic Lepied |
|---|
| 6 | # Created On : Sun Feb 1 13:54:41 2009 |
|---|
| 7 | # Purpose : http logic |
|---|
| 8 | #--------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | from django.http import HttpResponse, Http404 |
|---|
| 11 | from django.shortcuts import get_object_or_404 |
|---|
| 12 | from pxe.common import * |
|---|
| 13 | from pxe.models import * |
|---|
| 14 | |
|---|
| 15 | def get_system(request, mac): |
|---|
| 16 | try: |
|---|
| 17 | return System.objects.get(macaddress__mac=simplify_mac(mac)) |
|---|
| 18 | except System.DoesNotExist: |
|---|
| 19 | pass |
|---|
| 20 | |
|---|
| 21 | addr = request.META['REMOTE_ADDR'] |
|---|
| 22 | l = map(lambda x: '%02x' % int(x), addr.split('.')) |
|---|
| 23 | for i in range(len(l), 1, -1): |
|---|
| 24 | try: |
|---|
| 25 | return System.objects.get(macaddress__mac=''.join(l[0:i])) |
|---|
| 26 | except System.DoesNotExist: |
|---|
| 27 | pass |
|---|
| 28 | raise Http404 |
|---|
| 29 | |
|---|
| 30 | def localboot1(request): |
|---|
| 31 | return localboot(request, get_mac(request)) |
|---|
| 32 | |
|---|
| 33 | def localboot(request, mac): |
|---|
| 34 | try: |
|---|
| 35 | system = System.objects.get(macaddress__mac=simplify_mac(mac)) |
|---|
| 36 | set_next_boot(system, settings.PXE_LOCAL) |
|---|
| 37 | except System.DoesNotExist: |
|---|
| 38 | fn = '%s/%s' % (settings.PXE_ROOT, mac2filename(simplify_mac(mac))) |
|---|
| 39 | create_symlink('%s/%s%s' % (settings.PXE_PROFILES, settings.PXE_LOCAL, settings.PXE_SUFFIX), fn) |
|---|
| 40 | |
|---|
| 41 | return HttpResponse("Next boot set to local", mimetype="text/plain") |
|---|
| 42 | |
|---|
| 43 | def profile1(request): |
|---|
| 44 | return profile(request, get_mac(request)) |
|---|
| 45 | |
|---|
| 46 | def profile(request, mac): |
|---|
| 47 | system = get_system(request, mac) |
|---|
| 48 | log = Log.objects.filter(system=system).order_by('-date')[0] |
|---|
| 49 | return HttpResponse(log.boot_name.name, mimetype="text/plain") |
|---|