1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright 2013 Mathias WOLFF |
3
|
|
|
# This file is part of pyfreebilling. |
4
|
|
|
# |
5
|
|
|
# pyfreebilling is free software: you can redistribute it and/or modify |
6
|
|
|
# it under the terms of the GNU General Public License as published by |
7
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
# (at your option) any later version. |
9
|
|
|
# |
10
|
|
|
# pyfreebilling is distributed in the hope that it will be useful, |
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
# GNU General Public License for more details. |
14
|
|
|
# |
15
|
|
|
# You should have received a copy of the GNU General Public License |
16
|
|
|
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/> |
17
|
|
|
|
18
|
|
|
from django.contrib import admin, messages |
19
|
|
|
from django.template import Context, loader |
20
|
|
|
from django.utils.safestring import mark_safe |
21
|
|
|
from django.utils.translation import ugettext_lazy as _ |
22
|
|
|
|
23
|
|
|
# from pyfreebilling.switch import esl |
24
|
|
|
from pyfreebilling.pyfreebill.models import Company |
25
|
|
|
|
26
|
|
|
from .models import CustomerDirectory |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
# def directoryupdate(modeladmin, request, queryset): |
30
|
|
|
# """ generate new directory xml config file """ |
31
|
|
|
# try: |
32
|
|
|
# t = loader.get_template('xml/directory.conf.xml') |
33
|
|
|
# except IOError: |
34
|
|
|
# messages.error(request, _(u"""customer sip config xml file update failed. |
35
|
|
|
# Can not load template file !""")) |
36
|
|
|
# customerdirectorys = CustomerDirectory.objects.filter(company__customer_enabled__exact=True, enabled=True) |
37
|
|
|
# accounts = Company.objects.filter(customer_enabled=True) |
38
|
|
|
# c = Context({"customerdirectorys": customerdirectorys, |
39
|
|
|
# "accounts": accounts}) |
40
|
|
|
# try: |
41
|
|
|
# f = open('/usr/local/freeswitch/conf/directory/default.xml', 'w') |
42
|
|
|
# try: |
43
|
|
|
# f.write(t.render(c)) |
44
|
|
|
# f.close() |
45
|
|
|
# try: |
46
|
|
|
# fs = esl.getReloadACL() |
47
|
|
|
# messages.success(request, _(u"FS successfully reload")) |
48
|
|
|
# except IOError: |
49
|
|
|
# messages.error(request, _(u"""customer sip config xml file update |
50
|
|
|
# failed. FS ACL update failed ! Try manually - %s""" % fs)) |
51
|
|
|
# finally: |
52
|
|
|
# #f.close() |
53
|
|
|
# messages.success(request, _(u"""customer sip config xml file update |
54
|
|
|
# success""")) |
55
|
|
|
# except IOError: |
56
|
|
|
# messages.error(request, _(u"""customer sip config xml file update failed. |
57
|
|
|
# Can not create file !""")) |
58
|
|
|
# directoryupdate.short_description = _(u"update customer sip config xml file") |
59
|
|
|
# |
60
|
|
|
# |
61
|
|
|
# admin.site.add_action(directoryupdate, _(u"""generate customer sip |
62
|
|
|
# configuration file""")) |
63
|
|
|
|
64
|
|
|
# CustomerDirectory |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
class CustomerDirectoryAdmin(admin.ModelAdmin): |
68
|
|
|
list_display = ['name', |
69
|
|
|
'company', |
70
|
|
|
'domain', |
71
|
|
|
'get_registration_display', |
72
|
|
|
'sip_ip', |
73
|
|
|
'max_calls', |
74
|
|
|
'calls_per_second', |
75
|
|
|
'get_enabled_display', |
76
|
|
|
'get_fake_ring_display', |
77
|
|
|
'get_cli_debug_display'] |
78
|
|
|
ordering = ['company', 'enabled', 'name'] |
79
|
|
|
list_filter = ( |
80
|
|
|
'enabled', |
81
|
|
|
'domain__domain') |
82
|
|
|
# list_editable = ['max_calls', 'calls_per_second'] |
83
|
|
|
search_fields = ['^sip_ip', '^company__name', '^name'] |
84
|
|
|
exclude = ['vmd', ] |
85
|
|
|
# actions = [directoryupdate] |
86
|
|
|
save_on_top = True |
87
|
|
|
affix = True |
88
|
|
|
fieldsets = ( |
89
|
|
|
(_(u'General'), { |
90
|
|
|
'fields': (('company', |
91
|
|
|
'enabled'), |
92
|
|
|
'registration', |
93
|
|
|
('name', |
94
|
|
|
'domain'), |
95
|
|
|
'codecs'), |
96
|
|
|
'description': _(u'General sip account informations') |
97
|
|
|
}), |
98
|
|
|
(_(u'Registration settings'), { |
99
|
|
|
'fields': (('password', |
100
|
|
|
'multiple_registrations'), |
101
|
|
|
'log_auth_failures'), |
102
|
|
|
'classes': ('collapse',), |
103
|
|
|
'description': _(u'If registration, you must set a password') |
104
|
|
|
}), |
105
|
|
|
(_(u'IP Settings'), { |
106
|
|
|
'fields': (('sip_ip', |
107
|
|
|
'sip_port'), |
108
|
|
|
'rtp_ip'), |
109
|
|
|
'classes': ('collapse',), |
110
|
|
|
'description': _(u'If no registration, SIP IP CIDR is needed') |
111
|
|
|
}), |
112
|
|
|
(_(u'Caller/Callee settings'), { |
113
|
|
|
'fields': (('outbound_caller_id_name', |
114
|
|
|
'outbound_caller_id_number'), |
115
|
|
|
('force_caller_id','masq_caller_id'), |
116
|
|
|
('callerid_norm', 'callerid_norm_in'), |
117
|
|
|
('callee_norm', 'callee_norm_in'),), |
118
|
|
|
'classes': ('collapse',), |
119
|
|
|
'description': _(u'Caller/Callee parameters') |
120
|
|
|
}), |
121
|
|
|
(_(u'Limit settings'), { |
122
|
|
|
'fields': ('max_calls', |
123
|
|
|
'calls_per_second'), |
124
|
|
|
'classes': ('collapse',), |
125
|
|
|
'description': _(u'Limit settings') |
126
|
|
|
}), |
127
|
|
|
(_(u'Advanced settings'), { |
128
|
|
|
'fields': ('ignore_early_media', |
129
|
|
|
'fake_ring', |
130
|
|
|
'cli_debug'), |
131
|
|
|
'classes': ('collapse',), |
132
|
|
|
'description': _(u'Advanced parameters') |
133
|
|
|
}), |
134
|
|
|
(_(u'Urgency settings'), { |
135
|
|
|
'fields': ('urgency_numbr', |
136
|
|
|
'insee_code'), |
137
|
|
|
'classes': ('collapse',), |
138
|
|
|
'description': _(u'Urgency routing numbers parameters') |
139
|
|
|
}), |
140
|
|
|
(_(u'Description'), { |
141
|
|
|
'fields': ('description',), |
142
|
|
|
'classes': ('collapse',), |
143
|
|
|
'description': _(u'Description informations') |
144
|
|
|
}), |
145
|
|
|
) |
146
|
|
|
|
147
|
|
|
def get_registration_display(self, obj): |
148
|
|
|
if obj.registration: |
149
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-ok-sign"></i> Registration</span>') |
150
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-minus-sign"></i> IP Auth</span>') |
151
|
|
|
get_registration_display.short_description = _(u'Registration') |
152
|
|
|
get_registration_display.admin_order_field = _(u'registration') |
153
|
|
|
|
154
|
|
|
def get_enabled_display(self, obj): |
155
|
|
|
if obj.enabled: |
156
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
157
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
158
|
|
|
get_enabled_display.short_description = _(u'Enabled') |
159
|
|
|
get_enabled_display.admin_order_field = _(u'enabled') |
160
|
|
|
|
161
|
|
|
def get_fake_ring_display(self, obj): |
162
|
|
|
if obj.fake_ring: |
163
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-thumbs-up"></i> YES</span>') |
164
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
165
|
|
|
get_fake_ring_display.short_description = _(u'Fake ring') |
166
|
|
|
get_fake_ring_display.admin_order_field = _(u'fake_ring') |
167
|
|
|
|
168
|
|
|
def get_cli_debug_display(self, obj): |
169
|
|
|
if obj.cli_debug: |
170
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-up"></i> YES</span>') |
171
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
172
|
|
|
get_cli_debug_display.short_description = _(u'cli_debug') |
173
|
|
|
get_cli_debug_display.admin_order_field = _(u'cli_debug') |
174
|
|
|
|
175
|
|
|
def has_change_permission(self, request, obj=None): |
176
|
|
|
if request.user.is_superuser: |
177
|
|
|
return True |
178
|
|
|
else: |
179
|
|
|
return False |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
admin.site.register(CustomerDirectory, CustomerDirectoryAdmin) |
183
|
|
|
|