Skip to content

Commit

Permalink
add uacreg and trusted tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mwolff44 committed Apr 13, 2018
1 parent 3262a66 commit 1cd89d9
Show file tree
Hide file tree
Showing 21 changed files with 640 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- In location DB, typo in cflags fields
- Specify order in DB migration
- Add uacreg and trusted tables for kamailio in PyFreeBilling base

### Security

Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
'pyfreebilling.kamailio.apps.KamailioConfig',
'pyfreebilling.sipdialog.apps.SipDialogConfig',
'pyfreebilling.accounting.apps.AccountingConfig',
'pyfreebilling.endpoint.apps.EndpointConfig',
)

EXTENSION_APPS = (
Expand Down
1 change: 1 addition & 0 deletions pyfreebilling/endpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
34 changes: 34 additions & 0 deletions pyfreebilling/endpoint/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.contrib import admin
from django import forms
from .models import UacReg, Trusted

class UacRegAdminForm(forms.ModelForm):

class Meta:
model = UacReg
fields = '__all__'


class UacRegAdmin(admin.ModelAdmin):
form = UacRegAdminForm
list_display = ['l_uuid', 'l_username', 'l_domain', 'r_username', 'r_domain', 'realm', 'auth_username', 'auth_password', 'auth_ha1', 'auth_proxy', 'expires', 'flags', 'reg_delay']
readonly_fields = ['l_uuid', 'l_username', 'l_domain', 'r_username', 'r_domain', 'realm', 'auth_username', 'auth_password', 'auth_ha1', 'auth_proxy', 'expires', 'flags', 'reg_delay']

admin.site.register(UacReg, UacRegAdmin)


class TrustedAdminForm(forms.ModelForm):

class Meta:
model = Trusted
fields = '__all__'


class TrustedAdmin(admin.ModelAdmin):
form = TrustedAdminForm
list_display = ['src_ip', 'proto', 'from_pattern', 'ruri_pattern', 'tag', 'priority']
readonly_fields = ['src_ip', 'proto', 'from_pattern', 'ruri_pattern', 'tag', 'priority']

admin.site.register(Trusted, TrustedAdmin)


21 changes: 21 additions & 0 deletions pyfreebilling/endpoint/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from . import models
from . import serializers
from rest_framework import viewsets, permissions


class UacRegViewSet(viewsets.ModelViewSet):
"""ViewSet for the UacReg class"""

queryset = models.UacReg.objects.all()
serializer_class = serializers.UacRegSerializer
permission_classes = [permissions.IsAuthenticated]


class TrustedViewSet(viewsets.ModelViewSet):
"""ViewSet for the Trusted class"""

queryset = models.Trusted.objects.all()
serializer_class = serializers.TrustedSerializer
permission_classes = [permissions.IsAuthenticated]


6 changes: 6 additions & 0 deletions pyfreebilling/endpoint/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EndpointConfig(AppConfig):
name = 'pyfreebilling.endpoint'
verbose_name = "endpoint"
16 changes: 16 additions & 0 deletions pyfreebilling/endpoint/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import forms
from .models import UacReg, Trusted


class UacRegForm(forms.ModelForm):
class Meta:
model = UacReg
fields = ['l_uuid', 'l_username', 'l_domain', 'r_username', 'r_domain', 'realm', 'auth_username', 'auth_password', 'auth_ha1', 'auth_proxy', 'expires', 'flags', 'reg_delay']


class TrustedForm(forms.ModelForm):
class Meta:
model = Trusted
fields = ['src_ip', 'proto', 'from_pattern', 'ruri_pattern', 'tag', 'priority']


55 changes: 55 additions & 0 deletions pyfreebilling/endpoint/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-13 16:59
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Trusted',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('src_ip', models.CharField(db_index=True, default=b'', help_text='Source address is equal to source address of request', max_length=50)),
('proto', models.CharField(choices=[(b'any', b'any'), (b'udp', b'udp'), (b'tcp', b'tcp'), (b'tls', b'tls'), (b'sctp', b'sctp')], default=b'any', help_text='Transport protocol is either any or equal to transport protocol of request', max_length=4)),
('from_pattern', models.CharField(blank=True, help_text='Regular expression matches From URI of request.', max_length=64, null=True)),
('ruri_pattern', models.CharField(blank=True, help_text='Regular expression matches Request URI of request.', max_length=64, null=True)),
('tag', models.CharField(default=b'', help_text='Tag', max_length=64)),
('priority', models.IntegerField(default=0, help_text='Priority of rule')),
],
options={
'ordering': ('-pk',),
'db_table': 'trusted',
},
),
migrations.CreateModel(
name='UacReg',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('l_uuid', models.CharField(db_index=True, default=b'', help_text='Local unique id used to build and match contact addresses.', max_length=64)),
('l_username', models.CharField(default=b'', help_text='Local username', max_length=64)),
('l_domain', models.CharField(default=b'', help_text='Local domain', max_length=64)),
('r_username', models.CharField(default=b'', help_text='Remote username', max_length=64)),
('r_domain', models.CharField(default=b'', help_text='Remote domain', max_length=64)),
('realm', models.CharField(default=b'', help_text='realm', max_length=64)),
('auth_username', models.CharField(default=b'', help_text='Auth username', max_length=64)),
('auth_password', models.CharField(default=b'', help_text='Auth password', max_length=64)),
('auth_ha1', models.CharField(default=b'', help_text='Hashed (HA1) auth password', max_length=128)),
('auth_proxy', models.CharField(default=b'', help_text='Outbound proxy SIP address', max_length=128)),
('expires', models.IntegerField(default=0, help_text='Expiration time in seconds, 0 means disabled')),
('flags', models.IntegerField(default=0, help_text='Flags to control the behaviour')),
('reg_delay', models.IntegerField(default=0, help_text='initial registration delay')),
],
options={
'ordering': ('-pk',),
'db_table': 'uacreg',
},
),
]
Empty file.
94 changes: 94 additions & 0 deletions pyfreebilling/endpoint/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2018 Mathias WOLFF
# This file is part of pyfreebilling.
#
# pyfreebilling is free software: you can redistribute it and/or modify
# it under the terms of the Affero GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyfreebilling is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/>

from django.core.urlresolvers import reverse
from django.db import models as models
from django.db.models import *
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from django_extensions.db import fields as extension_fields
from django_extensions.db.fields import AutoSlugField


class UacReg(models.Model):

# Fields
l_uuid = models.CharField(max_length=64, default="", db_index=True, help_text=_(u"Local unique id used to build and match contact addresses."))
l_username = models.CharField(max_length=64, default="", help_text=_(u"Local username"))
l_domain = models.CharField(max_length=64, default="", help_text=_(u"Local domain"))
r_username = models.CharField(max_length=64, default="", help_text=_(u"Remote username"))
r_domain = models.CharField(max_length=64, default="", help_text=_(u"Remote domain"))
realm = models.CharField(max_length=64, default="", help_text=_(u"realm"))
auth_username = models.CharField(max_length=64, default="", help_text=_(u"Auth username"))
auth_password = models.CharField(max_length=64, default="", help_text=_(u"Auth password"))
auth_ha1 = models.CharField(max_length=128, default="", help_text=_(u"Hashed (HA1) auth password"))
auth_proxy = models.CharField(max_length=128, default="", help_text=_(u"Outbound proxy SIP address"))
expires = models.IntegerField(default=0, help_text=_(u"Expiration time in seconds, 0 means disabled"))
flags = models.IntegerField(default=0, help_text=_(u"Flags to control the behaviour"))
reg_delay = models.IntegerField(default=0, help_text=_(u"initial registration delay"))


class Meta:
db_table = 'uacreg'
app_label = 'endpoint'
ordering = ('-pk',)

def __unicode__(self):
return u'%s' % self.pk

def get_absolute_url(self):
return reverse('endpoint_uacreg_detail', args=(self.pk,))


def get_update_url(self):
return reverse('endpoint_uacreg_update', args=(self.pk,))


class Trusted(models.Model):

# Choices
PROTO_CHOICES = (
('any', 'any'),
('udp', 'udp'),
('tcp', 'tcp'),
('tls', 'tls'),
('sctp', 'sctp'),
)

# Fields
src_ip = models.CharField(max_length=50, db_index=True, default="", help_text=_(u"Source address is equal to source address of request"))
proto = models.CharField(max_length=4, choices=PROTO_CHOICES, default="any", help_text=_(u"Transport protocol is either any or equal to transport protocol of request"))
from_pattern = models.CharField(max_length=64, null=True, blank=True, help_text=_(u"Regular expression matches From URI of request."))
ruri_pattern = models.CharField(max_length=64, null=True, blank=True, help_text=_(u"Regular expression matches Request URI of request."))
tag = models.CharField(max_length=64, default="", help_text=_(u"Tag"))
priority = models.IntegerField(default=0, help_text=_(u"Priority of rule"))


class Meta:
db_table = 'trusted'
app_label = 'endpoint'
ordering = ('-pk',)

def __unicode__(self):
return u'%s' % self.pk

def get_absolute_url(self):
return reverse('endpoint_trusted_detail', args=(self.pk,))


def get_update_url(self):
return reverse('endpoint_trusted_update', args=(self.pk,))
42 changes: 42 additions & 0 deletions pyfreebilling/endpoint/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from . import models

from rest_framework import serializers


class UacRegSerializer(serializers.ModelSerializer):

class Meta:
model = models.UacReg
fields = (
'pk',
'l_uuid',
'l_username',
'l_domain',
'r_username',
'r_domain',
'realm',
'auth_username',
'auth_password',
'auth_ha1',
'auth_proxy',
'expires',
'flags',
'reg_delay',
)


class TrustedSerializer(serializers.ModelSerializer):

class Meta:
model = models.Trusted
fields = (
'pk',
'src_ip',
'proto',
'from_pattern',
'ruri_pattern',
'tag',
'priority',
)


1 change: 1 addition & 0 deletions pyfreebilling/endpoint/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head></head><body>{% block content %}Replace this.{% endblock %}</body>
15 changes: 15 additions & 0 deletions pyfreebilling/endpoint/templates/endpoint/trusted_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'endpoint_trusted_list' %}">Trusted Listing</a></p>
<table class="table">
<tr><td>src_ip</td><td>{{ object.src_ip }}</td></tr>
<tr><td>proto</td><td>{{ object.proto }}</td></tr>
<tr><td>from_pattern</td><td>{{ object.from_pattern }}</td></tr>
<tr><td>ruri_pattern</td><td>{{ object.ruri_pattern }}</td></tr>
<tr><td>tag</td><td>{{ object.tag }}</td></tr>
<tr><td>priority</td><td>{{ object.priority }}</td></tr>
</table>
<a class="btn btn-primary" href="{{object.get_update_url}}">Edit Trusted</a>

{% endblock %}
11 changes: 11 additions & 0 deletions pyfreebilling/endpoint/templates/endpoint/trusted_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'endpoint_trusted_list' %}">Trusted Listing</a></p>
<form method="post">
{% csrf_token %}
{{form|crispy}}
<button class="btn btn-primary" type="submit">Submit</button>
</form>
{% endblock %}
28 changes: 28 additions & 0 deletions pyfreebilling/endpoint/templates/endpoint/trusted_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'endpoint_trusted_list' %}">Trusted Listing</a></p>
<table class="table">
<tr>
<td>ID</td><td>Link</td>
<td>src_ip</td>
<td>proto</td>
<td>from_pattern</td>
<td>ruri_pattern</td>
<td>tag</td>
<td>priority</td>
</tr>
{% for object in object_list %}
<tr>
<td>{{object.pk}}</td>
<td><a href="{{object.get_absolute_url}}">{{object}}</a></td>
<td>{{ object.src_ip }}</td>
<td>{{ object.proto }}</td>
<td>{{ object.from_pattern }}</td>
<td>{{ object.ruri_pattern }}</td>
<td>{{ object.tag }}</td>
<td>{{ object.priority }}</td>
</tr>
{% endfor %}
</table><a class="btn btn-primary" href="{% url 'endpoint_trusted_create' %}">Create new Trusted</a>
{% endblock %}
22 changes: 22 additions & 0 deletions pyfreebilling/endpoint/templates/endpoint/uacreg_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'endpoint_uacreg_list' %}">UacReg Listing</a></p>
<table class="table">
<tr><td>l_uuid</td><td>{{ object.l_uuid }}</td></tr>
<tr><td>l_username</td><td>{{ object.l_username }}</td></tr>
<tr><td>l_domain</td><td>{{ object.l_domain }}</td></tr>
<tr><td>r_username</td><td>{{ object.r_username }}</td></tr>
<tr><td>r_domain</td><td>{{ object.r_domain }}</td></tr>
<tr><td>realm</td><td>{{ object.realm }}</td></tr>
<tr><td>auth_username</td><td>{{ object.auth_username }}</td></tr>
<tr><td>auth_password</td><td>{{ object.auth_password }}</td></tr>
<tr><td>auth_ha1</td><td>{{ object.auth_ha1 }}</td></tr>
<tr><td>auth_proxy</td><td>{{ object.auth_proxy }}</td></tr>
<tr><td>expires</td><td>{{ object.expires }}</td></tr>
<tr><td>flags</td><td>{{ object.flags }}</td></tr>
<tr><td>reg_delay</td><td>{{ object.reg_delay }}</td></tr>
</table>
<a class="btn btn-primary" href="{{object.get_update_url}}">Edit UacReg</a>

{% endblock %}
11 changes: 11 additions & 0 deletions pyfreebilling/endpoint/templates/endpoint/uacreg_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'endpoint_uacreg_list' %}">UacReg Listing</a></p>
<form method="post">
{% csrf_token %}
{{form|crispy}}
<button class="btn btn-primary" type="submit">Submit</button>
</form>
{% endblock %}
Loading

0 comments on commit 1cd89d9

Please sign in to comment.