Commit 9db05e62 authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Added MonLocalAuthnParam and InstRealmMon forms and views. Initial commit

parent 87f22055
......@@ -16,6 +16,16 @@ FQDN_RE = r'(^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z
DN_RE = r'(^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$)'
class MonLocalAuthnParamForm(forms.ModelForm):
class Meta:
model = MonLocalAuthnParam
class InstRealmMonForm(forms.ModelForm):
class Meta:
model = InstRealmMon
class UserProfileForm(forms.ModelForm):
class Meta:
......
......@@ -184,7 +184,7 @@ class InstRealm(models.Model):
proxyto = models.ManyToManyField("InstServer")
def __unicode__(self):
return 'Realm: %s' % self.realm
return '%s' % self.realm
def get_servers(self):
......@@ -282,7 +282,7 @@ class MonProxybackClient(models.Model):
class MonLocalAuthnParam(models.Model):
'''
EAPOL data for an old-style monitored realm
Parameters for an old-style monitored realm
'''
EAPTYPES = (
......@@ -312,9 +312,8 @@ class MonLocalAuthnParam(models.Model):
#exp_response = models.CharField(max_length=6, choices=MONRESPTYPES)
def __unicode__(self):
return _('Institution: %(inst)s, Monitored Realm: %(monrealm)s, EAP Method: %(eapmethod)s, Phase 2: %(phase2)s, Username: %(username)s') % {
return _('Monitored Realm: %(monrealm)s, EAP Method: %(eapmethod)s, Phase 2: %(phase2)s, Username: %(username)s') % {
# but name is many-to-many from institution
'inst': self.instid.name,
'monrealm': self.instrealmmonid.realm,
'eapmethod': self.eap_method,
'phase2': self.phase2,
......
......@@ -593,6 +593,121 @@ def del_contact(request):
return HttpResponse(json.dumps(resp), mimetype='application/json')
@login_required
@never_cache
def instrealmmon(request):
user = request.user
servers = False
instcontacts = []
try:
profile = user.get_profile()
inst = profile.institution
inst.__unicode__ = inst.get_name(request.LANGUAGE_CODE)
except UserProfile.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
try:
instdetails = inst.institutiondetails
except InstitutionDetails.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
if inst:
instrealmmons = InstRealmMon.objects.filter(realm__instid=inst)
return render_to_response('edumanage/instrealmmons.html', { 'realms': instrealmmons},
context_instance=RequestContext(request, base_response(request)))
@login_required
@never_cache
def add_instrealmmon(request, instrealmmon_pk):
user = request.user
instrealmmon = False
edit = False
try:
profile = user.get_profile()
inst = profile.institution
inst.__unicode__ = inst.get_name(request.LANGUAGE_CODE)
except UserProfile.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
try:
instdetails = inst.institutiondetails
except InstitutionDetails.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
if request.method == "GET":
# Determine add or edit
try:
instrealmmon = InstRealmMon.objects.get(pk=instrealmmon_pk, realm__instid=inst)
form = InstRealmMonForm(instance=instrealmmon)
except InstRealmMon.DoesNotExist:
form = InstRealmMonForm()
if instrealmmon:
edit = True
form.fields['realm'] = forms.ModelChoiceField(queryset=InstRealm.objects.filter(instid=inst.pk).exclude(realm__startswith="*"), empty_label=None)
return render_to_response('edumanage/instrealmmon_edit.html', { 'form': form, "edit" : edit},
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
try:
instrealmmon = InstRealmMon.objects.get(pk=instrealmmon_pk, realm__instid=inst)
form = InstRealmMonForm(request_data, instance=instrealmmon)
except InstRealmMon.DoesNotExist:
form = InstRealmMonForm(request_data)
if form.is_valid():
instrealmmonobj = form.save()
return HttpResponseRedirect(reverse("instrealmmon"))
if instrealmmon:
edit = True
return render_to_response('edumanage/instrealmmon_edit.html', { 'form': form, "edit": edit},
context_instance=RequestContext(request, base_response(request)))
@login_required
@never_cache
def add_monlocauthpar(request, instrealmmon_pk, monlocauthpar_pk):
user = request.user
monlocauthpar = False
edit = False
try:
profile = user.get_profile()
inst = profile.institution
inst.__unicode__ = inst.get_name(request.LANGUAGE_CODE)
except UserProfile.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
try:
instdetails = inst.institutiondetails
except InstitutionDetails.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
if request.method == "GET":
# Determine add or edit
try:
instrealmmon = InstRealmMon.objects.get(pk=instrealmmon_pk, realm__instid=inst)
monlocauthpar = MonLocalAuthnParam.objects.get(pk=monlocauthpar_pk, instrealmmonid__realm__instid=inst)
form = MonLocalAuthnParamForm(instance=monlocauthpar)
except MonLocalAuthnParam.DoesNotExist:
form = MonLocalAuthnParamForm()
except InstRealmMon.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
if monlocauthpar:
edit = True
form.fields['instrealmmonid'] = forms.ModelChoiceField(queryset=InstRealmMon.objects.filter(pk=instrealmmon.pk), empty_label=None)
return render_to_response('edumanage/monlocauthpar_edit.html', { 'form': form, "edit" : edit, "realm":instrealmmon },
context_instance=RequestContext(request, base_response(request)))
elif request.method == 'POST':
request_data = request.POST.copy()
try:
instrealmmon = InstRealmMon.objects.get(pk=instrealmmon_pk, realm__instid=inst)
monlocauthpar = MonLocalAuthnParam.objects.get(pk=monlocauthpar_pk, instrealmmonid__realm__instid=inst)
form = MonLocalAuthnParamForm(request_data, instance=monlocauthpar)
except MonLocalAuthnParam.DoesNotExist:
form = MonLocalAuthnParamForm(request_data)
except InstRealmMon.DoesNotExist:
return HttpResponseRedirect(reverse("manage"))
if form.is_valid():
monlocauthparobj = form.save()
return HttpResponseRedirect(reverse("instrealmmon"))
if monlocauthpar:
edit = True
form.fields['instrealmmonid'] = forms.ModelChoiceField(queryset=InstRealmMon.objects.filter(pk=instrealmmon.pk), empty_label=None)
return render_to_response('edumanage/monlocauthpar_edit.html', { 'form': form, "edit": edit, "realm":instrealmmon},
context_instance=RequestContext(request, base_response(request)))
@login_required
@never_cache
def adduser(request):
......@@ -648,6 +763,7 @@ def base_response(request):
instrealms = InstRealm.objects.filter(instid=institution)
instcontacts.extend([x.contact.pk for x in InstitutionContactPool.objects.filter(institution=institution)])
contacts = Contact.objects.filter(pk__in=instcontacts)
instrealmmons = InstRealmMon.objects.filter(realm__instid=institution)
except:
pass
try:
......@@ -660,6 +776,7 @@ def base_response(request):
'services_num': len(services),
'realms_num': len(instrealms),
'contacts_num': len(contacts),
'monrealms_num': len(instrealmmons),
'institution': institution,
'institutiondetails': instututiondetails,
'institution_exists': institution_exists,
......
......@@ -40,6 +40,8 @@ select, textarea, input[type="text"], input[type="password"], input[type="dateti
margin-bottom: 0;
margin-top: 5px;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Everything below this line is the same as demo_table.css. This file is
......
{% extends "edumanage/welcome.html"%}
{% load i18n %}
{% block crumbs %}
<li><a href="{% url manage %}">{% trans "Home" %}</a><span class="divider">/</span></li>
<li><a href="{% url instrealmmon %}">{% trans "Monitored Realms" %}</a><span class="divider">/</span></li>
<li class="active">{% if edit %}PLACEHOLDER({% trans "edit" %}){% else %}{% trans "Add Monitored Realm" %}{% endif %}</li>
{% endblock %}
{% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
{% endblock %}
{% block homeactive %}{% endblock %}
{% block instrealmmon %}class="active"{% endblock %}
{% block subcontent %} <h4>{% if edit %}{{form.instance.name}} ({% trans "edit" %}){% else %}{% trans "Add Monitored Realm" %}{% endif %}</h4>
<hr>
<form method="POST" class="form-horizontal">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="text-error" style="color: #B94A48">{{form.non_field_errors}}</div>
{% endif %}
<div style="display: none">
{{form.instid}}
</div>
<div class="control-group {% if form.realm.errors %} error {% endif %}">
<label class="control-label" for="id_realm"><b>{% trans "Realm" %}</b></label>
<div class="controls">
{{ form.realm }}
{% if form.realm.errors %} <span class="help-inline"> {{ form.realm.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.realm.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.mon_type.errors %} error {% endif %}">
<label class="control-label" for="id_mon_type"><b>{% trans "Monitoring Method" %}</b></label>
<div class="controls">
{{ form.mon_type }}
{% if form.mon_type.errors %} <span class="help-inline"> {{ form.mon_type.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.mon_type.help_text }}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" id="applybutton" value="Apply" class="btn btn-primary"/>
{% trans "Apply" %}</button>
</div>
</div>
</form>
{% endblock %}
{% extends "edumanage/welcome.html"%}
{% load i18n %}
{% block crumbs %}
<li><a href="{% url manage %}">{% trans "Home" %}</a><span class="divider">/</span></li>
<li class="active">{% trans "Monitored Realms" %}</li>
{% endblock %}
{% load i18n %}
{% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/js/datatables_bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
{% if contacts %}
var oTable = $('#table').dataTable({
"sPaginationType": "bootstrap",
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"aoColumns": [{
"bSearchable": true,
"bSortable": true
}, {
"bSearchable": true,
"bSortable": true
},
{
"bVisible": true,
"bSearchable": false,
"bSortable": false
},
{
"bSearchable": true,
"bSortable": true
}
],
"aaSorting": [[0, 'desc']],
"iDisplayLength": 25,
"oSearch": {"bSmart": false, "bRegex":true},
"oLanguage": {
"sLengthMenu": '{% trans "Display" %} <select><option value="25">25</option><option value="50">50</option><option value="-1">{% trans "All" %}</option></select> {% trans "contacts" %}',
"sProcessing": "Processing...",
"sZeroRecords": '{% trans "No records to display" %}',
"sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
"sInfoEmpty": "{% trans "Showing 0 to 0 of 0 entries" %}",
"sInfoFiltered": "(filtered from _MAX_ total entries)",
"sInfoPostFix": "",
"sSearch": '{% trans "Search:" %}',
"sUrl": "",
"oPaginate": {
"sFirst": '{% trans "First" %}',
"sPrevious": '{% trans "Previous" %}',
"sNext": '{% trans "Next" %}',
"sLast": '{% trans "Last" %}'
}
}
});
oTable.fnDraw();
$('[id^=del_contact_]').click(function(){
contact_id = (this.id).replace("del_contact_", '');
name = this.getAttribute("data-contactname");
$("#mymodalbody").html("{% trans 'You are about to delete realm' %}: <b>"+name+"</b><br>{% trans 'Press Delete to proceed or Cancel to cancel deletion' %}");
$("#myModalLabel").html("{% trans 'Delete realm' %} "+name);
$('#myModal').modal('show');
$(".modal-footer").show();
$("#contact_name_del").html(name)
return false;
});
$("#delcontactSubmit").click(function(){
$.ajax({
url:"{% url del-contact %}/?contact_pk="+contact_id,
type: "GET",
success: function(data){
if (data.error){
$(".modal-footer").hide();
$("#mymodalbody").html("<font style='color:#B94A48'>"+data.error+"</font>");
}
if (data.success){
$(".modal-footer").hide();
$("#mymodalbody").html("contact "+name+" successfully deleted");
window.setTimeout('location.reload()', 1000);
}
}
});
});
{% endif %}
});
</script>
{% endblock %}
{% block navbar %}
{% endblock %}
{% block homeactive %}{% endblock %}
{% block instrealmmon %}class="active"{% endblock %}
{% block subcontent %}
<h4>{% trans "Monitored Realms" %}</h4>
<hr>
<div><a href="{% url edit-instrealmmon %}" class="btn btn-primary">{% trans "Add monitored realm" %}</a></div>
<div class="span10"></div>
{% if realms %}
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" width="100%" id="table">
<thead>
<tr>
<th>{% trans "Realm" %}</th>
<th>{% trans "Type" %}</th>
<th style="text-align: center;">{% trans "Action" %}</th>
<th>
{% trans "Parameters" %}
</th>
</tr>
</thead>
<tbody>
{% for realm in realms %}
<tr class="GradeC">
<td>{{realm.realm}}</td>
<td style="width: 120px;">
{{realm.get_mon_type_display}}
</td>
<td style="text-align: center;">
<a href="{% url edit-instrealmmon realm.pk %}" class="btn btn-small">{% trans "edit" %}</a>
<a href="#" id="del_contact_{{contact.pk}}" data-contactname="{{contact.name}}" class="btn btn-small btn-warning">{% trans "delete" %}</a>
</td>
<td style="text-align: center;">
{% if realm.monlocalauthnparam %}
<a href="{% url edit-monlocauthpar realm.pk realm.monlocalauthnparam.pk %}" class="btn btn-small">{% trans "edit" %}</a>
<a href="{% url edit-monlocauthpar realm.pk realm.monlocalauthnparam.pk %}" class="btn btn-small btn-warning">{% trans "delete" %}</a>
<hr>
<dl class="dl-horizontal" style=" text-align: left;">
<dt>Method</dt>
<dd>{{realm.monlocalauthnparam.get_eap_method_display}}</dd>
<dt>Phase 2</dt>
<dd>{{realm.monlocalauthnparam.get_phase2_display}}</dd>
<dt>Username</dt>
<dd>{{realm.monlocalauthnparam.username}}</dd>
</dl>
{% else %}
{% if not realm.monlocalauthnparam %}<a href="{% url edit-monlocauthpar realm.pk %}" class="btn btn-small">{% trans "add" %}</a>{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">{% trans "Delete monitored realm" %}</h3>
</div>
<div class="modal-body" id="mymodalbody">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "Cancel" %}</button>
<a class="btn btn-warning" id="delcontactSubmit" href="#">{% trans "Delete" %}</a>
</div>
</div>
{% endblock %}
{% extends "edumanage/welcome.html"%}
{% load i18n %}
{% block crumbs %}
<li><a href="{% url manage %}">{% trans "Home" %}</a><span class="divider">/</span></li>
<li><a href="{% url instrealmmon %}">{% trans "Monitored Realms" %}</a><span class="divider">/</span></li>
<li class="active">{% if edit %}PLACEHOLDER({% trans "edit" %}){% else %}{% trans "Add Monitored Realm" %}{% endif %}</li>
{% endblock %}
{% block extrahead %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
{% endblock %}
{% block homeactive %}{% endblock %}
{% block instrealmmon %}class="active"{% endblock %}
{% block subcontent %} <h4>{% if edit %}{{form.instance.name}} ({% trans "edit" %}){% else %}{% trans "Add Monitored Realm" %}{% endif %}</h4>
<hr>
<form method="POST" class="form-horizontal">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="text-error" style="color: #B94A48">{{form.non_field_errors}}</div>
{% endif %}
<div style="display: none">
{{form.instrealmmonid}}
</div>
<div class="control-group {% if form.ertype.errors %} error {% endif %}">
<label class="control-label" for="id_realm"><b>{% trans "Realm" %}</b></label>
<div class="controls">
<input class="input" id="disabledInput" type="text" placeholder="{{realm.realm}}" disabled>
</div>
</div>
<div class="control-group {% if form.eap_method.errors %} error {% endif %}">
<label class="control-label" for="id_eap_method"><b>{% trans "EAP Method" %}</b></label>
<div class="controls">
{{ form.eap_method }}
{% if form.eap_method.errors %} <span class="help-inline"> {{ form.eap_method.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.eap_method.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.phase2.errors %} error {% endif %}">
<label class="control-label" for="id_phase2"><b>{% trans "EAP2 Method" %}</b></label>
<div class="controls">
{{ form.phase2 }}
{% if form.phase2.errors %} <span class="help-inline"> {{ form.phase2.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.phase2.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.username.errors %} error {% endif %}">
<label class="control-label" for="id_username"><b>{% trans "Username" %}</b></label>
<div class="controls">
{{ form.username }}
{% if form.username.errors %} <span class="help-inline"> {{ form.username.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.username.help_text }}</span>
</div>
</div>
<div class="control-group {% if form.passwp.errors %} error {% endif %}">
<label class="control-label" for="id_passwp"><b>{% trans "Password" %}</b></label>
<div class="controls">
{{ form.passwp }}
{% if form.passwp.errors %} <span class="help-inline"> {{ form.passwp.errors|join:", " }} </span>
{% endif %} <span class="help-block"> {{ form.passwp.help_text }}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" id="applybutton" value="Apply" class="btn btn-primary"/>
{% trans "Apply" %}</button>
</div>
</div>
</form>
{% endblock %}
......@@ -210,9 +210,13 @@ $.get("{% url get-service-points %}", function(data){
<li {% block realmsactive %}{% endblock %}>
<a href="{% url realms %}">{% trans "Realms" %} ({{realms_num}})</a>
</li>
<li {% block instrealmmon %}{% endblock %}>
<a href="{% url instrealmmon %}">{% trans "Monitored Realms" %} ({{monrealms_num}})</a>
</li>
<li {% block contactsactive %}{% endblock %}>
<a href="{% url contacts %}">{% trans "Contacts" %} ({{contacts_num}})</a>
</li>
{% endif %}
</ul>
</div><!--/.well -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment