Changeset 8784edeece399f9d7eae5a786ea7a0f30a7732da
- Timestamp:
- 02/10/09 20:16:04 (3 years ago)
- Author:
- Frederic Lepied <frederic.lepied@…>
- Children:
- 7218e7ce77d425dcf3e8c6e1bea40242315868c4
- Parents:
- 0cdcde4b0b7371a511bb3681726d4102b8fac1af
- git-committer:
- Frederic Lepied <frederic.lepied@…> (02/10/09 20:16:04)
- Message:
-
transparently find the mac address
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1f8d77d
|
r8784ede
|
|
| 10 | 10 | import sys |
| 11 | 11 | import os |
| | 12 | import re |
| 12 | 13 | import settings |
| 13 | | from pxe.models import * |
| | 14 | from models import * |
| 14 | 15 | |
| | 16 | IP_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') |
| | 17 | |
| | 18 | def mac_to_ip(mac): |
| | 19 | for line in open('/proc/net/arp').readlines(): |
| | 20 | if line.find(mac) != -1: |
| | 21 | res = IP_REGEXP.search(line) |
| | 22 | if res: |
| | 23 | return res.group(1) |
| | 24 | return False |
| | 25 | |
| | 26 | def get_mac(request): |
| | 27 | mac = mac_to_ip(request.META['REMOTE_ADDR']) |
| | 28 | if not mac: |
| | 29 | raise Http404 |
| | 30 | print 'get_mac', mac |
| | 31 | return mac |
| | 32 | |
| 15 | 33 | def error(str): |
| 16 | 34 | sys.stderr.write(str + '\n') |
| … |
… |
|
| 19 | 37 | def simplify_mac(s): |
| 20 | 38 | '''Remove : or - between hexa numbers for a MAC address. Always return the address in lowercase''' |
| | 39 | print 'simplify_mac', s |
| 21 | 40 | ss = s.replace('-', '') |
| 22 | 41 | sss = ss.replace(':', '') |
| 23 | 42 | if len(sss) != 12: |
| | 43 | print 'invalid length (not 12)', sss, len(sss) |
| 24 | 44 | raise ValueError |
| 25 | 45 | return sss.lower() |
-
|
r1f8d77d
|
r8784ede
|
|
| 8 | 8 | #--------------------------------------------------------------- |
| 9 | 9 | |
| 10 | | from django.http import HttpResponse |
| | 10 | from django.http import HttpResponse, Http404 |
| 11 | 11 | from django.shortcuts import get_object_or_404 |
| 12 | 12 | from common import * |
| 13 | 13 | from models import * |
| 14 | 14 | |
| | 15 | def localboot1(request): |
| | 16 | return localboot(request, get_mac(request)) |
| | 17 | |
| 15 | 18 | def localboot(request, mac): |
| 16 | 19 | system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) |
| … |
… |
|
| 18 | 21 | return HttpResponse("Next boot set to local", mimetype="text/plain") |
| 19 | 22 | |
| | 23 | def profile1(request): |
| | 24 | return profile(request, get_mac(request)) |
| | 25 | |
| 20 | 26 | def profile(request, mac): |
| 21 | 27 | system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) |
-
|
r693511a
|
r8784ede
|
|
| 1 | 1 | # Django settings for pxemngr project. |
| 2 | 2 | |
| 3 | | DEBUG = False |
| | 3 | DEBUG = True |
| 4 | 4 | TEMPLATE_DEBUG = DEBUG |
| 5 | 5 | |
| … |
… |
|
| 11 | 11 | |
| 12 | 12 | DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. |
| 13 | | DATABASE_NAME = '/home/fred/work/pxemngr/pxe.db' # Or path to database file if using sqlite3. |
| | 13 | DATABASE_NAME = '/home/flepied/work/pxemngr/pxe.db' # Or path to database file if using sqlite3. |
| 14 | 14 | DATABASE_USER = '' # Not used with sqlite3. |
| 15 | 15 | DATABASE_PASSWORD = '' # Not used with sqlite3. |
| … |
… |
|
| 70 | 70 | # Always use forward slashes, even on Windows. |
| 71 | 71 | # Don't forget to use absolute paths, not relative paths. |
| 72 | | '/home/fred/work/pxemngr/pxe/templates', |
| | 72 | '/home/flepied/work/pxemngr/pxe/templates', |
| 73 | 73 | ) |
| 74 | 74 | |
| … |
… |
|
| 79 | 79 | 'django.contrib.sites', |
| 80 | 80 | 'pxe', |
| | 81 | # 'django.contrib.admin', |
| 81 | 82 | ) |
| 82 | 83 | |
-
|
r853b6ff
|
r8784ede
|
|
| 2 | 2 | |
| 3 | 3 | # Uncomment the next two lines to enable the admin: |
| 4 | | # from django.contrib import admin |
| 5 | | # admin.autodiscover() |
| | 4 | #from django.contrib import admin |
| | 5 | #admin.autodiscover() |
| 6 | 6 | |
| 7 | 7 | urlpatterns = patterns('', |
| … |
… |
|
| 13 | 13 | # (r'^admin/doc/', include('django.contrib.admindocs.urls')), |
| 14 | 14 | |
| | 15 | (r'^localboot/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.localboot'), |
| | 16 | (r'^localboot/$', 'pxe.views.localboot1'), |
| | 17 | (r'^profile/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.profile'), |
| | 18 | (r'^profile/$', 'pxe.views.profile1'), |
| | 19 | |
| 15 | 20 | # Uncomment the next line to enable the admin: |
| 16 | | # (r'^admin/(.*)', admin.site.root), |
| 17 | | (r'^localboot/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.localboot'), |
| 18 | | (r'^profile/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.profile'), |
| | 21 | #(r'^admin/(.*)', admin.site.root), |
| 19 | 22 | ) |