diff options
author | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-11-06 21:23:07 +0000 |
---|---|---|
committer | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-11-06 21:23:07 +0000 |
commit | 75e2d050496db86c6ed1e4c8ec8c9c9da6341f77 (patch) | |
tree | 52d05dda8965c0dbdc94f122c8da1330967ea177 /src/lib/Server/Hostbase | |
parent | 23c1f2cc6be9926fdfe85e37869ef88f84b9200e (diff) | |
download | bcfg2-75e2d050496db86c6ed1e4c8ec8c9c9da6341f77.tar.gz bcfg2-75e2d050496db86c6ed1e4c8ec8c9c9da6341f77.tar.bz2 bcfg2-75e2d050496db86c6ed1e4c8ec8c9c9da6341f77.zip |
dhcp option is now per interface
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2474 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Hostbase')
-rw-r--r-- | src/lib/Server/Hostbase/backends.py | 63 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/models.py | 4 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/views.py | 52 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/base.html | 4 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/edit.html | 21 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/host.html | 12 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/logout | 7 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/new.html | 9 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/search.html | 12 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/regex.py | 2 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/settings.py | 15 |
11 files changed, 102 insertions, 99 deletions
diff --git a/src/lib/Server/Hostbase/backends.py b/src/lib/Server/Hostbase/backends.py index c59ed5e93..e6c709f35 100644 --- a/src/lib/Server/Hostbase/backends.py +++ b/src/lib/Server/Hostbase/backends.py @@ -1,46 +1,47 @@ from django.contrib.auth.models import User -from ldapauth import * +#from ldapauth import * from nisauth import * -class LDAPBackend(object): +__revision__ = '$Revision$' - def authenticate(self,username=None,password=None): - try: +## class LDAPBackend(object): + +## def authenticate(self,username=None,password=None): +## try: - l = ldapauth(username,password) - temp_pass = User.objects.make_random_password(100) - ldap_user = dict(username=l.sAMAccountName, - ) - user_session_obj = dict( - email=l.email, - first_name=l.name_f, - last_name=l.name_l, - uid=l.badge_no - ) - #fixme: need to add this user session obj to session - #print str(ldap_user) - user,created = User.objects.get_or_create(username=username) - #print user - #print "created " + str(created) - return user +## l = ldapauth(username,password) +## temp_pass = User.objects.make_random_password(100) +## ldap_user = dict(username=l.sAMAccountName, +## ) +## user_session_obj = dict( +## email=l.email, +## first_name=l.name_f, +## last_name=l.name_l, +## uid=l.badge_no +## ) +## #fixme: need to add this user session obj to session +## #print str(ldap_user) +## user,created = User.objects.get_or_create(username=username) +## #print user +## #print "created " + str(created) +## return user - except LDAPAUTHError,e: - #print str(e) - return None +## except LDAPAUTHError,e: +## #print str(e) +## return None - def get_user(self,user_id): - try: - return User.objects.get(pk=user_id) - except User.DoesNotExist, e: - print str(e) - return None +## def get_user(self,user_id): +## try: +## return User.objects.get(pk=user_id) +## except User.DoesNotExist, e: +## print str(e) +## return None class NISBackend(object): def authenticate(self, username=None, password=None): try: - print "start nis authenticate" n = nisauth(username, password) temp_pass = User.objects.make_random_password(100) nis_user = dict(username=username, @@ -57,7 +58,6 @@ class NISBackend(object): return user except NISAUTHError, e: - print str(e) return None @@ -65,6 +65,5 @@ class NISBackend(object): try: return User.objects.get(pk=user_id) except User.DoesNotExist, e: - print str(e) return None diff --git a/src/lib/Server/Hostbase/hostbase/models.py b/src/lib/Server/Hostbase/hostbase/models.py index 613701685..fb979ff5a 100644 --- a/src/lib/Server/Hostbase/hostbase/models.py +++ b/src/lib/Server/Hostbase/hostbase/models.py @@ -45,7 +45,6 @@ class Host(models.Model): support = models.CharField(maxlength=8, choices=SUPPORT_CHOICES) csi = models.CharField(maxlength=32, blank=True) printq = models.CharField(maxlength=32) - dhcp = models.BooleanField() outbound_smtp = models.BooleanField() primary_user = models.EmailField() administrator = models.EmailField(blank=True) @@ -66,12 +65,13 @@ class Host(models.Model): class Interface(models.Model): TYPE_CHOICES = ( ('eth', 'ethernet'), ('wl', 'wireless'), ('virtual', 'virtual'), ('myr', 'myr'), - ('mgmt', 'mgmt'), ('tape', 'tape'), ('fe', 'fe'), ('ge', 'ge') + ('mgmt', 'mgmt'), ('tape', 'tape'), ('fe', 'fe'), ('ge', 'ge'), ('virtual', 'virtual') ) host = models.ForeignKey(Host, edit_inline=models.TABULAR, num_in_admin=2) mac_addr = models.CharField(maxlength=32, core=True) hdwr_type = models.CharField('type', maxlength=16, choices=TYPE_CHOICES, radio_admin=True, blank=True) + dhcp = models.BooleanField() def __str__(self): return self.mac_addr diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index 748a84471..c60e2c2ff 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -29,30 +29,8 @@ dispatch = {'mac_addr':'i.mac_addr LIKE \'%%%%%s%%%%\'', 'cname':'c.cname LIKE \'%%%%%s%%%%\'', 'mx':'m.mx LIKE \'%%%%%s%%%%\'', 'dns_view':'n.dns_view = \'%s\'', - 'hdwr_type':'i.hdwr_type = \'%s\''} - - -## def netreg(request): -## if request.GET.has_key('sub'): -## failures = [] -## validated = True -## # do validation right in here -## macaddr_regex = re.compile('^[0-9abcdef]{2}(:[0-9abcdef]{2}){5}$') -## if not (request.POST['mac_addr'] and macaddr_regex.match(request.POST['mac_addr'])): -## validated = False -## userregex = re.compile('^[a-z0-9-_\.@]+$') -## if not (request.POST['email_address'] and userregex.match(request.POST['email_address'])): -## validated = False -## if not validated: -## t = Template(open('./hostbase/webtemplates/errors.html').read()) -## t.failures = validate(request, True) -## return HttpResponse(str(t)) -## return HttpResponseRedirect('/hostbase/%s/' % host.id) -## else: -## t = Template(open('./hostbase/webtemplates/netreg.html').read()) -## t.TYPE_CHOICES = Interface.TYPE_CHOICES -## t.failures = False -## return HttpResponse(str(t)) + 'hdwr_type':'i.hdwr_type = \'%s\'', + 'dhcp':'i.dhcp = \'%s\''} def index(request): """rediredct to /hostbase/""" @@ -192,9 +170,6 @@ def edit(request, host_id): not request.POST.has_key('outbound_smtp') and host.outbound_smtp): host.outbound_smtp = not host.outbound_smtp - if (request.POST.has_key('dhcp') and not host.dhcp or - not request.POST.has_key('dhcp') and host.dhcp): - host.dhcp = not host.dhcp # add validation for attribs here # likely use a helper fucntion for attrib in attribs: @@ -214,6 +189,9 @@ def edit(request, host_id): oldtype = inter.hdwr_type inter.hdwr_type = request.POST['hdwr_type%d' % inter.id] changetype = True + if (request.POST.has_key('dhcp%d' % inter.id) and not inter.dhcp or + not request.POST.has_key('dhcp%d' % inter.id) and inter.dhcp): + inter.dhcp = not inter.dhcp for ip in ips: names = ip.name_set.all() if not ip.ip_addr == request.POST['ip_addr%d' % ip.id]: @@ -264,7 +242,8 @@ def edit(request, host_id): if request.POST['mac_addr_new']: new_inter = Interface(host=host, mac_addr=request.POST['mac_addr_new'], - hdwr_type=request.POST['hdwr_type_new']) + hdwr_type=request.POST['hdwr_type_new'], + dhcp=request.POST['dhcp_new']) new_inter.save() if request.POST['mac_addr_new'] and request.POST['ip_addr_new']: mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX) @@ -296,7 +275,8 @@ def edit(request, host_id): if created: mx.save() new_inter = Interface(host=host, mac_addr="", - hdwr_type=request.POST['hdwr_type_new']) + hdwr_type=request.POST['hdwr_type_new'], + dhcp=False) new_inter.save() new_ip = IP(interface=new_inter, num=0, ip_addr=request.POST['ip_addr_new']) @@ -517,7 +497,6 @@ def new(request): # this is the stuff that validate() should take care of # examine the check boxes for any changes host.outbound_smtp = request.POST.has_key('outbound_smtp') - host.dhcp = request.POST.has_key('dhcp') for attrib in attribs: if request.POST.has_key(attrib): host.__dict__[attrib] = request.POST[attrib].lower() @@ -535,7 +514,8 @@ def new(request): if request.POST['mac_addr_new']: new_inter = Interface(host=host, mac_addr=request.POST['mac_addr_new'], - hdwr_type=request.POST['hdwr_type_new']) + hdwr_type=request.POST['hdwr_type_new'], + dhcp=request.POST.has_key('dhcp_new')) new_inter.save() if request.POST['mac_addr_new'] and request.POST['ip_addr_new']: new_ip = IP(interface=new_inter, @@ -564,7 +544,8 @@ def new(request): if request.POST['ip_addr_new'] and not request.POST['mac_addr_new']: new_inter = Interface(host=host, mac_addr="", - hdwr_type=request.POST['hdwr_type_new1']) + hdwr_type=request.POST['hdwr_type_new1'], + dhcp=False) new_inter.save() new_ip = IP(interface=new_inter, num=0, ip_addr=request.POST['ip_addr_new1']) @@ -593,7 +574,8 @@ def new(request): if request.POST['mac_addr_new2']: new_inter = Interface(host=host, mac_addr=request.POST['mac_addr_new2'], - hdwr_type=request.POST['mac_addr_new2']) + hdwr_type=request.POST['mac_addr_new2'], + dhcp=request.POST.has_key('dhcp_new2')) new_inter.save() if request.POST['mac_addr_new2'] and request.POST['ip_addr_new2']: new_ip = IP(interface=new_inter, num=0, @@ -623,7 +605,8 @@ def new(request): if request.POST['ip_addr_new2'] and not request.POST['mac_addr_new2']: new_inter = Interface(host=host, mac_addr="", - hdwr_type=request.POST['hdwr_type_new2']) + hdwr_type=request.POST['hdwr_type_new2'], + dhcp=False) new_inter.save() new_ip = IP(interface=new_inter, num=0, ip_addr=request.POST['ip_addr_new2']) @@ -915,4 +898,3 @@ else: remove = login_required(remove) zoneedit = login_required(zoneedit) zonenew = login_required(zonenew) - diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/base.html b/src/lib/Server/Hostbase/hostbase/webtemplates/base.html index 0c556bd77..537535663 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/base.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/base.html @@ -5,9 +5,7 @@ <title>{% block title %}BCFG2 - Hostbase{% endblock %}</title> <link rel="stylesheet" type="text/css" href="/site_media/boxypastel.css" /> <link rel="stylesheet" type="text/css" href="/site_media/base.css" /> - <!--<script type="text/javascript" src="http://hostbase.mcs.anl.gov/site_media/main.js"> ---> - </script> + <!--<script type="text/javascript" src="http://hostbase.mcs.anl.gov/site_media/main.js"> --> {% block extra_header_info %}{% endblock %} </head> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html index 49e054e8a..d3bb848ca 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html @@ -102,13 +102,6 @@ div#interface{ <td> <input name="csi" type="text" value="{{ host.csi }}"></td></tr> <tr> <td> <b>printq</b></td> <td> <input name="printq" type="text" value="{{ host.printq }}"></td></tr> - <tr> <td> <b>dhcp</b></td> - <td> - {% if host.dhcp %} - <input type="checkbox" checked="checked" name="dhcp"></td></tr> - {% else %} - <input type="checkbox" name="dhcp"></td></tr> - {% endif %} <tr> <td> <b>outbound_smtp</b></td> <td> {% if host.outbound_smtp %} @@ -135,6 +128,13 @@ div#interface{ {% endifequal %} {% endfor %} </td></tr> + <tr> <td> <b>dhcp</b></td> + <td> + {% if interface.0.dhcp %} + <input type="checkbox" checked="checked" name="dhcp{{ interface.0.id }}"></td></tr> + {% else %} + <input type="checkbox" name="dhcp{{ interface.0.id }}"></td></tr> + {% endif %} <tr> <td> <b>mac_addr</b></td> <td> <input name="mac_addr{{ interface.0.id }}" type="text" value="{{ interface.0.mac_addr }}"> <a style="font-size:75%" href="/hostbase/{{ host.id }}/interface/{{ interface.0.id }}/confirm">remove</a> @@ -180,6 +180,13 @@ div#interface{ <input type="radio" name="hdwr_type_new" value="{{ choice.0 }}">{{ choice.1 }} {% endfor %} </td></tr> + <tr> <td> <b>dhcp</b></td> + <td> + {% if host.dhcp %} + <input type="checkbox" checked="checked" name="dhcp_new"></td></tr> + {% else %} + <input type="checkbox" name="dhcp_new"></td></tr> + {% endif %} <tr> <td> <b>mac_addr</b></td> <td> <input name="mac_addr_new" type="text"></td></tr> <tr> <td> <b>ip_addr</b></td> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/host.html b/src/lib/Server/Hostbase/hostbase/webtemplates/host.html index 2f557cf73..39cdc7ae4 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/host.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/host.html @@ -37,12 +37,6 @@ <td> {{ host.csi }}</td></tr> <tr> <td> <b>printq</b></td> <td> {{ host.printq }}</td></tr> - <tr> <td> <b>dhcp</b></td> - {% if host.dhcp %} - <td> y </td></tr> - {% else %} - <td> n </td></tr> - {% endif %} <tr> <td> <b>outbound_smtp</b></td> {% if host.outbound_smtp %} <td> y </td></tr> @@ -62,8 +56,14 @@ {% ifnotequal interface.0.hdwr_type 'no' %} <td><br>{{ interface.0.hdwr_type }}</td></tr> {% endifnotequal %} + <tr> <td> <b>dhcp</b></td> + {% if interface.0.dhcp %} + <td> y </td></tr> <tr> <td> <b>mac_addr</b></td> <td> {{ interface.0.mac_addr }}</b></td></tr> + {% else %} + <td> n </td></tr> + {% endif %} {% for ip in interface.1 %} <tr> <td> <b>ip_addr</b></td> <td> {{ ip.ip_addr }}</td></tr> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/logout b/src/lib/Server/Hostbase/hostbase/webtemplates/logout index 9fa46236f..e71e90e76 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/logout +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/logout @@ -1,5 +1,6 @@ +<p> {% if logged_in %} -<p> <a href="/logout/" class="sidebar">logout</a> +<a href="/logout/" class="sidebar">logout</a> {% else %} -<p> <a href="/login/" class="sidebar">login</a> -{% endif %}
\ No newline at end of file +<a href="/login/" class="sidebar">login</a> +{% endif %} diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html index c965d5af4..5c74197b4 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html @@ -56,9 +56,6 @@ <td> <input name="csi" type="text" ></td></tr> <tr> <td> <b>printq</b></td> <td> <input name="printq" type="text" ></td></tr> - <tr> <td> <b>dhcp</b></td> - <td> - <input type="checkbox" name="dhcp"></td></tr> <tr> <td> <b>outbound_smtp</b></td> <td> <input type="checkbox" name="outbound_smtp"></td></tr> @@ -75,6 +72,9 @@ <input type="radio" name="hdwr_type_new" value="{{ choice.0 }}" >{{ choice.1 }} {% endfor %} </td></tr> + <tr> <td> <b>dhcp</b></td> + <td> + <input type="checkbox" name="dhcp_new"></td></tr> <tr> <td> <b>mac_addr</b></td> <td> <input name="mac_addr_new" type="text"></td></tr> <tr> <td> <b>ip_addr</b></td> @@ -84,6 +84,9 @@ <input type="radio" name="hdwr_type_new2" value="{{ choice.0 }}" >{{ choice.1 }} {% endfor %} </td></tr> + <tr> <td> <b>dhcp</b></td> + <td> + <input type="checkbox" name="dhcp_new2"></td></tr> <tr> <td> <b>mac_addr</b></td> <td> <input name="mac_addr_new2" type="text"></td></tr> <tr> <td> <b>ip_addr</b></td> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/search.html b/src/lib/Server/Hostbase/hostbase/webtemplates/search.html index 1c869f0d7..03d65d058 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/search.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/search.html @@ -37,12 +37,6 @@ <td> <input name="csi" type="text" ></td></tr> <tr> <td> <b>printq</b></td> <td> <input name="printq" type="text" ></td></tr> - <tr> <td> <b>dhcp</b></td> - <td> - {% for choice in yesno %} - <input type="radio" name="dhcp" value="{{ choice.0 }}" >{{ choice.1 }} - {% endfor %} - </td></tr> <tr> <td> <b>outbound_smtp</b></td> <td> {% for choice in yesno %} @@ -62,6 +56,12 @@ <input type="radio" name="hdwr_type" value="{{ choice.0 }}" >{{ choice.1 }} {% endfor %} </td></tr> + <tr> <td> <b>dhcp</b></td> + <td> + {% for choice in yesno %} + <input type="radio" name="dhcp" value="{{ choice.0 }}" >{{ choice.1 }} + {% endfor %} + </td></tr> <tr> <td> <b>mac_addr</b></td> <td> <input name="mac_addr" type="text"></td></tr> <tr> <td> <b>ip_addr</b></td> diff --git a/src/lib/Server/Hostbase/regex.py b/src/lib/Server/Hostbase/regex.py index 4e86293fb..2d9614da9 100644 --- a/src/lib/Server/Hostbase/regex.py +++ b/src/lib/Server/Hostbase/regex.py @@ -5,5 +5,5 @@ host = re.compile('^[a-z0-9-_]+(\.[a-z0-9-_]+)+$') printq = re.compile('^[a-z0-9-]+$') user = re.compile('^[a-z0-9-_\.@]+$') location = re.compile('^[0-9]{3}-[a-zA-Z][0-9]{3}$|none|bmr|cave|dsl|evl|mobile|offsite|mural|activespaces') -macaddr = re.compile('^[0-9abcdef]{2}(:[0-9abcdef]{2}){5}$') +macaddr = re.compile('^[0-9abcdef]{2}(:[0-9abcdef]{2}){5}$|virtual') ipaddr = re.compile('^[0-9]{1,3}(\.[0-9]{1,3}){3}$') diff --git a/src/lib/Server/Hostbase/settings.py b/src/lib/Server/Hostbase/settings.py index 41c557f0d..45e54255b 100644 --- a/src/lib/Server/Hostbase/settings.py +++ b/src/lib/Server/Hostbase/settings.py @@ -5,7 +5,7 @@ ADMINS = ( # ('Your Name', 'your_email@domain.com'), ) MANAGERS = ADMINS -CFG_TYPE = 'environ' +CFG_TYPE = 'mcs' if CFG_TYPE == 'mcs': # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. @@ -23,6 +23,19 @@ if CFG_TYPE == 'mcs': # Local time zone for this installation. All choices can be found here: # http://www.postgresql.org/docs/current/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE TIME_ZONE = 'America/Chicago' + + DEFAULT_MX = 'mailgw.mcs.anl.gov' + PRIORITY = 30 + + SESSION_EXPIRE_AT_BROWSER_CLOSE = True + + AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', + 'Hostbase.backends.NISBackend') + AUTHORIZED_GROUP = 'support' + + #create login url area: + import django.contrib.auth + django.contrib.auth.LOGIN_URL = '/login' # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = '' |