mirror of https://gitlab.federez.net/re2o/re2o
190 changed files with 9726 additions and 2637 deletions
@ -0,0 +1,360 @@ |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2018 Mael Kervella |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
""" |
|||
Serializers for the API app |
|||
""" |
|||
|
|||
from rest_framework import serializers |
|||
from users.models import Club, Adherent |
|||
from machines.models import ( |
|||
Interface, |
|||
IpType, |
|||
Extension, |
|||
IpList, |
|||
MachineType, |
|||
Domain, |
|||
Txt, |
|||
Mx, |
|||
Srv, |
|||
Service_link, |
|||
Ns, |
|||
OuverturePortList, |
|||
OuverturePort, |
|||
Ipv6List |
|||
) |
|||
|
|||
|
|||
class ServiceLinkSerializer(serializers.ModelSerializer): |
|||
name = serializers.CharField(source='service.service_type') |
|||
|
|||
class Meta: |
|||
model = Service_link |
|||
fields = ('name',) |
|||
|
|||
|
|||
class MailingSerializer(serializers.ModelSerializer): |
|||
name = serializers.CharField(source='pseudo') |
|||
|
|||
class Meta: |
|||
model = Club |
|||
fields = ('name',) |
|||
|
|||
|
|||
class MailingMemberSerializer(serializers.ModelSerializer): |
|||
class Meta: |
|||
model = Adherent |
|||
fields = ('email', 'name', 'surname', 'pseudo',) |
|||
|
|||
|
|||
class IpTypeField(serializers.RelatedField): |
|||
"""Serialisation d'une iptype, renvoie son evaluation str""" |
|||
def to_representation(self, value): |
|||
return value.type |
|||
|
|||
|
|||
class IpListSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'une iplist, ip_type etant une foreign_key, |
|||
on evalue sa methode str""" |
|||
ip_type = IpTypeField(read_only=True) |
|||
|
|||
class Meta: |
|||
model = IpList |
|||
fields = ('ipv4', 'ip_type') |
|||
|
|||
|
|||
class Ipv6ListSerializer(serializers.ModelSerializer): |
|||
class Meta: |
|||
model = Ipv6List |
|||
fields = ('ipv6', 'slaac_ip') |
|||
|
|||
|
|||
class InterfaceSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'une interface, ipv4, domain et extension sont |
|||
des foreign_key, on les override et on les evalue avec des fonctions |
|||
get_...""" |
|||
ipv4 = IpListSerializer(read_only=True) |
|||
mac_address = serializers.SerializerMethodField('get_macaddress') |
|||
domain = serializers.SerializerMethodField('get_dns') |
|||
extension = serializers.SerializerMethodField('get_interface_extension') |
|||
|
|||
class Meta: |
|||
model = Interface |
|||
fields = ('ipv4', 'mac_address', 'domain', 'extension') |
|||
|
|||
def get_dns(self, obj): |
|||
return obj.domain.name |
|||
|
|||
def get_interface_extension(self, obj): |
|||
return obj.domain.extension.name |
|||
|
|||
def get_macaddress(self, obj): |
|||
return str(obj.mac_address) |
|||
|
|||
|
|||
class FullInterfaceSerializer(serializers.ModelSerializer): |
|||
"""Serialisation complete d'une interface avec les ipv6 en plus""" |
|||
ipv4 = IpListSerializer(read_only=True) |
|||
ipv6 = Ipv6ListSerializer(read_only=True, many=True) |
|||
mac_address = serializers.SerializerMethodField('get_macaddress') |
|||
domain = serializers.SerializerMethodField('get_dns') |
|||
extension = serializers.SerializerMethodField('get_interface_extension') |
|||
|
|||
class Meta: |
|||
model = Interface |
|||
fields = ('ipv4', 'ipv6', 'mac_address', 'domain', 'extension') |
|||
|
|||
def get_dns(self, obj): |
|||
return obj.domain.name |
|||
|
|||
def get_interface_extension(self, obj): |
|||
return obj.domain.extension.name |
|||
|
|||
def get_macaddress(self, obj): |
|||
return str(obj.mac_address) |
|||
|
|||
|
|||
class ExtensionNameField(serializers.RelatedField): |
|||
"""Evaluation str d'un objet extension (.example.org)""" |
|||
def to_representation(self, value): |
|||
return value.name |
|||
|
|||
|
|||
class TypeSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un iptype : extension et la liste des |
|||
ouvertures de port son evalués en get_... etant des |
|||
foreign_key ou des relations manytomany""" |
|||
extension = ExtensionNameField(read_only=True) |
|||
ouverture_ports_tcp_in = serializers\ |
|||
.SerializerMethodField('get_port_policy_input_tcp') |
|||
ouverture_ports_tcp_out = serializers\ |
|||
.SerializerMethodField('get_port_policy_output_tcp') |
|||
ouverture_ports_udp_in = serializers\ |
|||
.SerializerMethodField('get_port_policy_input_udp') |
|||
ouverture_ports_udp_out = serializers\ |
|||
.SerializerMethodField('get_port_policy_output_udp') |
|||
|
|||
class Meta: |
|||
model = IpType |
|||
fields = ('type', 'extension', 'domaine_ip_start', 'domaine_ip_stop', |
|||
'prefix_v6', |
|||
'ouverture_ports_tcp_in', 'ouverture_ports_tcp_out', |
|||
'ouverture_ports_udp_in', 'ouverture_ports_udp_out',) |
|||
|
|||
def get_port_policy(self, obj, protocole, io): |
|||
if obj.ouverture_ports is None: |
|||
return [] |
|||
return map( |
|||
str, |
|||
obj.ouverture_ports.ouvertureport_set.filter( |
|||
protocole=protocole |
|||
).filter(io=io) |
|||
) |
|||
|
|||
def get_port_policy_input_tcp(self, obj): |
|||
"""Renvoie la liste des ports ouverts en entrée tcp""" |
|||
return self.get_port_policy(obj, OuverturePort.TCP, OuverturePort.IN) |
|||
|
|||
def get_port_policy_output_tcp(self, obj): |
|||
"""Renvoie la liste des ports ouverts en sortie tcp""" |
|||
return self.get_port_policy(obj, OuverturePort.TCP, OuverturePort.OUT) |
|||
|
|||
def get_port_policy_input_udp(self, obj): |
|||
"""Renvoie la liste des ports ouverts en entrée udp""" |
|||
return self.get_port_policy(obj, OuverturePort.UDP, OuverturePort.IN) |
|||
|
|||
def get_port_policy_output_udp(self, obj): |
|||
"""Renvoie la liste des ports ouverts en sortie udp""" |
|||
return self.get_port_policy(obj, OuverturePort.UDP, OuverturePort.OUT) |
|||
|
|||
|
|||
class ExtensionSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'une extension : origin_ip et la zone sont |
|||
des foreign_key donc evalués en get_...""" |
|||
origin = serializers.SerializerMethodField('get_origin_ip') |
|||
zone_entry = serializers.SerializerMethodField('get_zone_name') |
|||
soa = serializers.SerializerMethodField('get_soa_data') |
|||
|
|||
class Meta: |
|||
model = Extension |
|||
fields = ('name', 'origin', 'origin_v6', 'zone_entry', 'soa') |
|||
|
|||
def get_origin_ip(self, obj): |
|||
return obj.origin.ipv4 |
|||
|
|||
def get_zone_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
def get_soa_data(self, obj): |
|||
return { 'mail': obj.soa.dns_soa_mail, 'param': obj.soa.dns_soa_param } |
|||
|
|||
|
|||
class MxSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un MX, evaluation du nom, de la zone |
|||
et du serveur cible, etant des foreign_key""" |
|||
name = serializers.SerializerMethodField('get_entry_name') |
|||
zone = serializers.SerializerMethodField('get_zone_name') |
|||
mx_entry = serializers.SerializerMethodField('get_mx_name') |
|||
|
|||
class Meta: |
|||
model = Mx |
|||
fields = ('zone', 'priority', 'name', 'mx_entry') |
|||
|
|||
def get_entry_name(self, obj): |
|||
return str(obj.name) |
|||
|
|||
def get_zone_name(self, obj): |
|||
return obj.zone.name |
|||
|
|||
def get_mx_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
|
|||
class TxtSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un txt : zone cible et l'entrée txt |
|||
sont evaluées à part""" |
|||
zone = serializers.SerializerMethodField('get_zone_name') |
|||
txt_entry = serializers.SerializerMethodField('get_txt_name') |
|||
|
|||
class Meta: |
|||
model = Txt |
|||
fields = ('zone', 'txt_entry', 'field1', 'field2') |
|||
|
|||
def get_zone_name(self, obj): |
|||
return str(obj.zone.name) |
|||
|
|||
def get_txt_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
|
|||
class SrvSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un srv : zone cible et l'entrée txt""" |
|||
extension = serializers.SerializerMethodField('get_extension_name') |
|||
srv_entry = serializers.SerializerMethodField('get_srv_name') |
|||
|
|||
class Meta: |
|||
model = Srv |
|||
fields = ( |
|||
'service', |
|||
'protocole', |
|||
'extension', |
|||
'ttl', |
|||
'priority', |
|||
'weight', |
|||
'port', |
|||
'target', |
|||
'srv_entry' |
|||
) |
|||
|
|||
def get_extension_name(self, obj): |
|||
return str(obj.extension.name) |
|||
|
|||
def get_srv_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
|
|||
class NsSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un NS : la zone, l'entrée ns complète et le serveur |
|||
ns sont évalués à part""" |
|||
zone = serializers.SerializerMethodField('get_zone_name') |
|||
ns = serializers.SerializerMethodField('get_domain_name') |
|||
ns_entry = serializers.SerializerMethodField('get_text_name') |
|||
|
|||
class Meta: |
|||
model = Ns |
|||
fields = ('zone', 'ns', 'ns_entry') |
|||
|
|||
def get_zone_name(self, obj): |
|||
return obj.zone.name |
|||
|
|||
def get_domain_name(self, obj): |
|||
return str(obj.ns) |
|||
|
|||
def get_text_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
|
|||
class DomainSerializer(serializers.ModelSerializer): |
|||
"""Serialisation d'un domain, extension, cname sont des foreign_key, |
|||
et l'entrée complète, sont évalués à part""" |
|||
extension = serializers.SerializerMethodField('get_zone_name') |
|||
cname = serializers.SerializerMethodField('get_alias_name') |
|||
cname_entry = serializers.SerializerMethodField('get_cname_name') |
|||
|
|||
class Meta: |
|||
model = Domain |
|||
fields = ('name', 'extension', 'cname', 'cname_entry') |
|||
|
|||
def get_zone_name(self, obj): |
|||
return obj.extension.name |
|||
|
|||
def get_alias_name(self, obj): |
|||
return str(obj.cname) |
|||
|
|||
def get_cname_name(self, obj): |
|||
return str(obj.dns_entry) |
|||
|
|||
|
|||
class ServicesSerializer(serializers.ModelSerializer): |
|||
"""Evaluation d'un Service, et serialisation""" |
|||
server = serializers.SerializerMethodField('get_server_name') |
|||
service = serializers.SerializerMethodField('get_service_name') |
|||
need_regen = serializers.SerializerMethodField('get_regen_status') |
|||
|
|||
class Meta: |
|||
model = Service_link |
|||
fields = ('server', 'service', 'need_regen') |
|||
|
|||
def get_server_name(self, obj): |
|||
return str(obj.server.domain.name) |
|||
|
|||
def get_service_name(self, obj): |
|||
return str(obj.service) |
|||
|
|||
def get_regen_status(self, obj): |
|||
return obj.need_regen() |
|||
|
|||
|
|||
class OuverturePortsSerializer(serializers.Serializer): |
|||
"""Serialisation de l'ouverture des ports""" |
|||
ipv4 = serializers.SerializerMethodField() |
|||
ipv6 = serializers.SerializerMethodField() |
|||
|
|||
def get_ipv4(): |
|||
return {i.ipv4.ipv4: |
|||
{ |
|||
"tcp_in":[j.tcp_ports_in() for j in i.port_lists.all()], |
|||
"tcp_out":[j.tcp_ports_out()for j in i.port_lists.all()], |
|||
"udp_in":[j.udp_ports_in() for j in i.port_lists.all()], |
|||
"udp_out":[j.udp_ports_out() for j in i.port_lists.all()], |
|||
} |
|||
for i in Interface.objects.all() if i.ipv4 |
|||
} |
|||
|
|||
def get_ipv6(): |
|||
return {i.ipv6: |
|||
{ |
|||
"tcp_in":[j.tcp_ports_in() for j in i.port_lists.all()], |
|||
"tcp_out":[j.tcp_ports_out()for j in i.port_lists.all()], |
|||
"udp_in":[j.udp_ports_in() for j in i.port_lists.all()], |
|||
"udp_out":[j.udp_ports_out() for j in i.port_lists.all()], |
|||
} |
|||
for i in Interface.objects.all() if i.ipv6 |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2017 Gabriel Détraz |
|||
# Copyright © 2017 Goulven Kermarec |
|||
# Copyright © 2017 Augustin Lemesle |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
from django.test import TestCase |
|||
|
|||
# Create your tests here. |
|||
@ -0,0 +1,59 @@ |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2018 Mael Kervella |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
"""api.urls |
|||
|
|||
Urls de l'api, pointant vers les fonctions de views |
|||
""" |
|||
|
|||
from __future__ import unicode_literals |
|||
|
|||
from django.conf.urls import url |
|||
|
|||
from . import views |
|||
|
|||
|
|||
urlpatterns = [ |
|||
# Services |
|||
url(r'^services/$', views.services), |
|||
url(r'^services/(?P<server_name>\w+)/(?P<service_name>\w+)/regen/$', views.services_server_service_regen), |
|||
url(r'^services/(?P<server_name>\w+)/$', views.services_server), |
|||
|
|||
# DNS |
|||
url(r'^dns/mac-ip-dns/$', views.dns_mac_ip_dns), |
|||
url(r'^dns/alias/$', views.dns_alias), |
|||
url(r'^dns/corresp/$', views.dns_corresp), |
|||
url(r'^dns/mx/$', views.dns_mx), |
|||
url(r'^dns/ns/$', views.dns_ns), |
|||
url(r'^dns/txt/$', views.dns_txt), |
|||
url(r'^dns/srv/$', views.dns_srv), |
|||
url(r'^dns/zones/$', views.dns_zones), |
|||
|
|||
# Firewall |
|||
url(r'^firewall/ouverture_ports/$', views.firewall_ouverture_ports), |
|||
|
|||
# DHCP |
|||
url(r'^dhcp/mac-ip/$', views.dhcp_mac_ip), |
|||
|
|||
# Mailings |
|||
url(r'^mailing/standard/$', views.mailing_standard), |
|||
url(r'^mailing/standard/(?P<ml_name>\w+)/members/$', views.mailing_standard_ml_members), |
|||
url(r'^mailing/club/$', views.mailing_club), |
|||
url(r'^mailing/club/(?P<ml_name>\w+)/members/$', views.mailing_club_ml_members), |
|||
] |
|||
@ -0,0 +1,114 @@ |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2018 Maël Kervella |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""api.utils. |
|||
|
|||
Set of various and usefull functions for the API app |
|||
""" |
|||
|
|||
from rest_framework.renderers import JSONRenderer |
|||
from django.http import HttpResponse |
|||
|
|||
class JSONResponse(HttpResponse): |
|||
"""A JSON response that can be send as an HTTP response. |
|||
Usefull in case of REST API. |
|||
""" |
|||
|
|||
def __init__(self, data, **kwargs): |
|||
"""Initialisz a JSONResponse object. |
|||
|
|||
Args: |
|||
data: the data to render as JSON (often made of lists, dicts, |
|||
strings, boolean and numbers). See `JSONRenderer.render(data)` for |
|||
further details. |
|||
|
|||
Creates: |
|||
An HTTPResponse containing the data in JSON format. |
|||
""" |
|||
|
|||
content = JSONRenderer().render(data) |
|||
kwargs['content_type'] = 'application/json' |
|||
super(JSONResponse, self).__init__(content, **kwargs) |
|||
|
|||
|
|||
class JSONError(JSONResponse): |
|||
"""A JSON response when the request failed. |
|||
""" |
|||
|
|||
def __init__(self, error_msg, data=None, **kwargs): |
|||
"""Initialise a JSONError object. |
|||
|
|||
Args: |
|||
error_msg: A message explaining where the error is. |
|||
data: An optional field for further data to send along. |
|||
|
|||
Creates: |
|||
A JSONResponse containing a field `status` set to `error` and a field |
|||
`reason` containing `error_msg`. If `data` argument has been given, |
|||
a field `data` containing it is added to the JSON response. |
|||
""" |
|||
|
|||
response = { |
|||
'status' : 'error', |
|||
'reason' : error_msg |
|||
} |
|||
if data is not None: |
|||
response['data'] = data |
|||
super(JSONError, self).__init__(response, **kwargs) |
|||
|
|||
|
|||
class JSONSuccess(JSONResponse): |
|||
"""A JSON response when the request suceeded. |
|||
""" |
|||
|
|||
def __init__(self, data=None, **kwargs): |
|||
"""Initialise a JSONSucess object. |
|||
|
|||
Args: |
|||
error_msg: A message explaining where the error is. |
|||
data: An optional field for further data to send along. |
|||
|
|||
Creates: |
|||
A JSONResponse containing a field `status` set to `sucess`. If `data` |
|||
argument has been given, a field `data` containing it is added to the |
|||
JSON response. |
|||
""" |
|||
|
|||
response = { |
|||
'status' : 'success', |
|||
} |
|||
if data is not None: |
|||
response['data'] = data |
|||
super(JSONSuccess, self).__init__(response, **kwargs) |
|||
|
|||
|
|||
def accept_method(methods): |
|||
"""Decorator to set a list of accepted request method. |
|||
Check if the method used is accepted. If not, send a NotAllowed response. |
|||
""" |
|||
def decorator(view): |
|||
def wrapper(request, *args, **kwargs): |
|||
if request.method in methods: |
|||
return view(request, *args, **kwargs) |
|||
else: |
|||
return JSONError('Invalid request method. Request methods authorize are '+str(methods)) |
|||
return view(request, *args, **kwargs) |
|||
return wrapper |
|||
return decorator |
|||
@ -0,0 +1,464 @@ |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2018 Maël Kervella |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""api.views |
|||
|
|||
The views for the API app. They should all return JSON data and not fallback on |
|||
HTML pages such as the login and index pages for a better integration. |
|||
""" |
|||
|
|||
from django.contrib.auth.decorators import login_required, permission_required |
|||
from django.views.decorators.csrf import csrf_exempt |
|||
|
|||
from re2o.utils import all_has_access, all_active_assigned_interfaces |
|||
|
|||
from users.models import Club |
|||
from machines.models import (Service_link, Service, Interface, Domain, |
|||
OuverturePortList) |
|||
|
|||
from .serializers import * |
|||
from .utils import JSONError, JSONSuccess, accept_method |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def services(request): |
|||
"""The list of the different services and servers couples |
|||
|
|||
Return: |
|||
GET: |
|||
A JSONSuccess response with a field `data` containing: |
|||
* a list of dictionnaries (one for each service-server couple) containing: |
|||
* a field `server`: the server name |
|||
* a field `service`: the service name |
|||
* a field `need_regen`: does the service need a regeneration ? |
|||
""" |
|||
service_link = Service_link.objects.all().select_related('server__domain').select_related('service') |
|||
seria = ServicesSerializer(service_link, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET', 'POST']) |
|||
def services_server_service_regen(request, server_name, service_name): |
|||
"""The status of a particular service linked to a particular server. |
|||
Mark the service as regenerated if POST used. |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSucess response with a field `data` containing: |
|||
* a field `need_regen`: does the service need a regeneration ? |
|||
|
|||
POST: |
|||
An empty JSONSuccess response. |
|||
""" |
|||
query = Service_link.objects.filter( |
|||
service__in=Service.objects.filter(service_type=service_name), |
|||
server__in=Interface.objects.filter( |
|||
domain__in=Domain.objects.filter(name=server_name) |
|||
) |
|||
) |
|||
if not query: |
|||
return JSONError("This service is not active for this server") |
|||
|
|||
service = query.first() |
|||
if request.method == 'GET': |
|||
return JSONSuccess({'need_regen': service.need_regen()}) |
|||
else: |
|||
service.done_regen() |
|||
return JSONSuccess() |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def services_server(request, server_name): |
|||
"""The list of services attached to a specific server |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSuccess response with a field `data` containing: |
|||
* a list of dictionnaries (one for each service) containing: |
|||
* a field `name`: the name of a service |
|||
""" |
|||
query = Service_link.objects.filter( |
|||
server__in=Interface.objects.filter( |
|||
domain__in=Domain.objects.filter(name=server_name) |
|||
) |
|||
) |
|||
if not query: |
|||
return JSONError("This service is not active for this server") |
|||
|
|||
services = query.all() |
|||
seria = ServiceLinkSerializer(services, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_mac_ip_dns(request): |
|||
"""The list of all active interfaces with all the associated infos |
|||
(MAC, IP, IpType, DNS name and associated zone extension) |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each interface) containing: |
|||
* a field `ipv4` containing: |
|||
* a field `ipv4`: the ip for this interface |
|||
* a field `ip_type`: the name of the IpType of this interface |
|||
* a field `ipv6` containing `null` if ipv6 is deactivated else: |
|||
* a field `ipv6`: the ip for this interface |
|||
* a field `ip_type`: the name of the IpType of this interface |
|||
* a field `mac_address`: the MAC of this interface |
|||
* a field `domain`: the DNS name for this interface |
|||
* a field `extension`: the extension for the DNS zone of this interface |
|||
""" |
|||
interfaces = all_active_assigned_interfaces(full=True) |
|||
seria = FullInterfaceSerializer(interfaces, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_alias(request): |
|||
"""The list of all the alias used and the DNS info associated |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each alias) containing: |
|||
* a field `name`: the alias used |
|||
* a field `cname`: the target of the alias (real name of the interface) |
|||
* a field `cname_entry`: the entry to write in the DNS to have the alias |
|||
* a field `extension`: the extension for the DNS zone of this interface |
|||
""" |
|||
alias = Domain.objects.filter(interface_parent=None).filter(cname__in=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None))).select_related('extension').select_related('cname__extension') |
|||
seria = DomainSerializer(alias, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_corresp(request): |
|||
"""The list of the IpTypes possible with the infos about each |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each IpType) containing: |
|||
* a field `type`: the name of the type |
|||
* a field `extension`: the DNS extension associated |
|||
* a field `domain_ip_start`: the first ip to use for this type |
|||
* a field `domain_ip_stop`: the last ip to use for this type |
|||
* a field `prefix_v6`: `null` if IPv6 is deactivated else the prefix to use |
|||
* a field `ouverture_ports_tcp_in`: the policy for TCP IN ports |
|||
* a field `ouverture_ports_tcp_out`: the policy for TCP OUT ports |
|||
* a field `ouverture_ports_udp_in`: the policy for UDP IN ports |
|||
* a field `ouverture_ports_udp_out`: the policy for UDP OUT ports |
|||
""" |
|||
ip_type = IpType.objects.all().select_related('extension') |
|||
seria = TypeSerializer(ip_type, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_mx(request): |
|||
"""The list of MX record to add to the DNS |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each MX record) containing: |
|||
* a field `zone`: the extension for the concerned zone |
|||
* a field `priority`: the priority to use |
|||
* a field `name`: the name of the target |
|||
* a field `mx_entry`: the full entry to add in the DNS for this MX record |
|||
""" |
|||
mx = Mx.objects.all().select_related('zone').select_related('name__extension') |
|||
seria = MxSerializer(mx, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_ns(request): |
|||
"""The list of NS record to add to the DNS |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each NS record) containing: |
|||
* a field `zone`: the extension for the concerned zone |
|||
* a field `ns`: the DNS name for the NS server targeted |
|||
* a field `ns_entry`: the full entry to add in the DNS for this NS record |
|||
""" |
|||
ns = Ns.objects.exclude(ns__in=Domain.objects.filter(interface_parent__in=Interface.objects.filter(ipv4=None))).select_related('zone').select_related('ns__extension') |
|||
seria = NsSerializer(ns, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_txt(request): |
|||
"""The list of TXT record to add to the DNS |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each TXT record) containing: |
|||
* a field `zone`: the extension for the concerned zone |
|||
* a field `field1`: the first field in the record (target) |
|||
* a field `field2`: the second field in the record (value) |
|||
* a field `txt_entry`: the full entry to add in the DNS for this TXT record |
|||
""" |
|||
txt = Txt.objects.all().select_related('zone') |
|||
seria = TxtSerializer(txt, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_srv(request): |
|||
"""The list of SRV record to add to the DNS |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each SRV record) containing: |
|||
* a field `extension`: the extension for the concerned zone |
|||
* a field `service`: the name of the service concerned |
|||
* a field `protocole`: the name of the protocol to use |
|||
* a field `ttl`: the Time To Live to use |
|||
* a field `priority`: the priority for this service |
|||
* a field `weight`: the weight for same priority entries |
|||
* a field `port`: the port targeted |
|||
* a field `target`: the interface targeted by this service |
|||
* a field `srv_entry`: the full entry to add in the DNS for this SRV record |
|||
""" |
|||
srv = Srv.objects.all().select_related('extension').select_related('target__extension') |
|||
seria = SrvSerializer(srv, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dns_zones(request): |
|||
"""The list of the zones managed |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each zone) containing: |
|||
* a field `name`: the extension for the zone |
|||
* a field `origin`: the server IPv4 for the orgin of the zone |
|||
* a field `origin_v6`: `null` if ipv6 is deactivated else the server IPv6 for the origin of the zone |
|||
* a field `soa` containing: |
|||
* a field `mail` containing the mail to contact in case of problem with the zone |
|||
* a field `param` containing the full soa paramters to use in the DNS for this zone |
|||
* a field `zone_entry`: the full entry to add in the DNS for the origin of the zone |
|||
""" |
|||
zones = Extension.objects.all().select_related('origin') |
|||
seria = ExtensionSerializer(zones, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def firewall_ouverture_ports(request): |
|||
"""The list of the ports authorized to be openned by the firewall |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSuccess response with a `data` field containing: |
|||
* a field `ipv4` containing: |
|||
* a field `tcp_in` containing: |
|||
* a list of port number where ipv4 tcp in should be ok |
|||
* a field `tcp_out` containing: |
|||
* a list of port number where ipv4 tcp ou should be ok |
|||
* a field `udp_in` containing: |
|||
* a list of port number where ipv4 udp in should be ok |
|||
* a field `udp_out` containing: |
|||
* a list of port number where ipv4 udp out should be ok |
|||
* a field `ipv6` containing: |
|||
* a field `tcp_in` containing: |
|||
* a list of port number where ipv6 tcp in should be ok |
|||
* a field `tcp_out` containing: |
|||
* a list of port number where ipv6 tcp ou should be ok |
|||
* a field `udp_in` containing: |
|||
* a list of port number where ipv6 udp in should be ok |
|||
* a field `udp_out` containing: |
|||
* a list of port number where ipv6 udp out should be ok |
|||
""" |
|||
r = {'ipv4':{}, 'ipv6':{}} |
|||
for o in OuverturePortList.objects.all().prefetch_related('ouvertureport_set').prefetch_related('interface_set', 'interface_set__ipv4'): |
|||
pl = { |
|||
"tcp_in":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.TCP, io=OuverturePort.IN))), |
|||
"tcp_out":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.TCP, io=OuverturePort.OUT))), |
|||
"udp_in":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.UDP, io=OuverturePort.IN))), |
|||
"udp_out":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.UDP, io=OuverturePort.OUT))), |
|||
} |
|||
for i in filter_active_interfaces(o.interface_set): |
|||
if i.may_have_port_open(): |
|||
d = r['ipv4'].get(i.ipv4.ipv4, {}) |
|||
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"]) |
|||
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"]) |
|||
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"]) |
|||
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"]) |
|||
r['ipv4'][i.ipv4.ipv4] = d |
|||
if i.ipv6(): |
|||
for ipv6 in i.ipv6(): |
|||
d = r['ipv6'].get(ipv6.ipv6, {}) |
|||
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"]) |
|||
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"]) |
|||
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"]) |
|||
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"]) |
|||
r['ipv6'][ipv6.ipv6] = d |
|||
return JSONSuccess(r) |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def dhcp_mac_ip(request): |
|||
"""The list of all active interfaces with all the associated infos |
|||
(MAC, IP, IpType, DNS name and associated zone extension) |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSON Success response with a field `data` containing: |
|||
* a list of dictionnaries (one for each interface) containing: |
|||
* a field `ipv4` containing: |
|||
* a field `ipv4`: the ip for this interface |
|||
* a field `ip_type`: the name of the IpType of this interface |
|||
* a field `mac_address`: the MAC of this interface |
|||
* a field `domain`: the DNS name for this interface |
|||
* a field `extension`: the extension for the DNS zone of this interface |
|||
""" |
|||
interfaces = all_active_assigned_interfaces() |
|||
seria = InterfaceSerializer(interfaces, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def mailing_standard(request): |
|||
"""All the available standard mailings. |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSucess response with a field `data` containing: |
|||
* a list of dictionnaries (one for each mailing) containing: |
|||
* a field `name`: the name of a mailing |
|||
""" |
|||
return JSONSuccess([ |
|||
{'name': 'adherents'} |
|||
]) |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def mailing_standard_ml_members(request): |
|||
"""All the members of a specific standard mailing |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSucess response with a field `data` containing: |
|||
* a list if dictionnaries (one for each member) containing: |
|||
* a field `email`: the email of the member |
|||
* a field `name`: the name of the member |
|||
* a field `surname`: the surname of the member |
|||
* a field `pseudo`: the pseudo of the member |
|||
""" |
|||
# All with active connextion |
|||
if ml_name == 'adherents': |
|||
members = all_has_access().values('email').distinct() |
|||
# Unknown mailing |
|||
else: |
|||
return JSONError("This mailing does not exist") |
|||
seria = MailingMemberSerializer(members, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def mailing_club(request): |
|||
"""All the available club mailings. |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSucess response with a field `data` containing: |
|||
* a list of dictionnaries (one for each mailing) containing: |
|||
* a field `name` indicating the name of a mailing |
|||
""" |
|||
clubs = Club.objects.filter(mailing=True).values('pseudo') |
|||
seria = MailingSerializer(clubs, many=True) |
|||
return JSONSuccess(seria.data) |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
@permission_required('machines.serveur') |
|||
@accept_method(['GET']) |
|||
def mailing_club_ml_members(request): |
|||
"""All the members of a specific club mailing |
|||
|
|||
Returns: |
|||
GET: |
|||
A JSONSucess response with a field `data` containing: |
|||
* a list if dictionnaries (one for each member) containing: |
|||
* a field `email`: the email of the member |
|||
* a field `name`: the name of the member |
|||
* a field `surname`: the surname of the member |
|||
* a field `pseudo`: the pseudo of the member |
|||
""" |
|||
try: |
|||
club = Club.objects.get(mailing=True, pseudo=ml_name) |
|||
except Club.DoesNotExist: |
|||
return JSONError("This mailing does not exist") |
|||
members = club.administrators.all().values('email').distinct() |
|||
seria = MailingMemberSerializer(members, many=True) |
|||
return JSONSuccess(seria.data) |
|||
@ -0,0 +1,3 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
contributeurs = ['Gabriel Detraz', 'chirac', 'Maël Kervella', 'LEVY-FALK Hugo', 'Dalahro', 'lhark', 'root', 'Hugo LEVY-FALK', 'Chirac', 'guimoz', 'Mael Kervella', 'klafyvel', 'matthieu', 'Yoann Pietri', 'Simon Brélivet', 'chibrac', 'David Sinquin', 'Pierre Cadart', 'moamoak', 'Éloi Alain', 'FERNET Laouen', 'Hugo Levy-Falk', 'Joanne Steiner', 'Matthieu Michelet', 'Yoann PIETRI', 'B', 'Daniel STAN', 'Eloi Alain', 'Guimoz', 'Hugo Hervieux', 'Laouen Fernet', 'Lemesle', 'MICHELET matthieu', 'Nymous', 'Thibault de BOUTRAY', 'Tipunchetrhum', 'Éloi ALAIN'] |
|||
@ -0,0 +1,40 @@ |
|||
# -*- mode: python; coding: utf-8 -*- |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2017 Gabriel Détraz |
|||
# Copyright © 2017 Goulven Kermarec |
|||
# Copyright © 2017 Augustin Lemesle |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""cotisations.acl |
|||
|
|||
Here are defined some functions to check acl on the application. |
|||
""" |
|||
|
|||
def can_view(user): |
|||
"""Check if an user can view the application. |
|||
|
|||
Args: |
|||
user: The user who wants to view the application. |
|||
|
|||
Returns: |
|||
A couple (allowed, msg) where allowed is a boolean which is True if |
|||
viewing is granted and msg is a message (can be None). |
|||
""" |
|||
can = user.has_module_perms('cotisations') |
|||
return can, None if can else "Vous ne pouvez pas voir cette application." |
|||
@ -0,0 +1,39 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-12-30 23:07 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('cotisations', '0027_auto_20171029_1156'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='article', |
|||
options={'permissions': (('view_article', 'Peut voir un objet article'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='banque', |
|||
options={'permissions': (('view_banque', 'Peut voir un objet banque'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='cotisation', |
|||
options={'permissions': (('view_cotisation', 'Peut voir un objet cotisation'), ('change_all_cotisation', 'Superdroit, peut modifier toutes les cotisations'))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='facture', |
|||
options={'permissions': (('change_facture_control', "Peut changer l'etat de controle"), ('change_facture_pdf', 'Peut éditer une facture pdf'), ('view_facture', 'Peut voir un objet facture'), ('change_all_facture', 'Superdroit, peut modifier toutes les factures'))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='paiement', |
|||
options={'permissions': (('view_paiement', 'Peut voir un objet paiement'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='vente', |
|||
options={'permissions': (('view_vente', 'Peut voir un objet vente'), ('change_all_vente', 'Superdroit, peut modifier toutes les ventes'))}, |
|||
), |
|||
] |
|||
@ -0,0 +1,111 @@ |
|||
"""Payment |
|||
|
|||
Here are defined some views dedicated to online payement. |
|||
""" |
|||
from django.urls import reverse |
|||
from django.shortcuts import redirect, get_object_or_404 |
|||
from django.contrib.auth.decorators import login_required |
|||
from django.contrib import messages |
|||
from django.views.decorators.csrf import csrf_exempt |
|||
from django.utils.datastructures import MultiValueDictKeyError |
|||
from django.http import HttpResponse, HttpResponseBadRequest |
|||
|
|||
from collections import OrderedDict |
|||
|
|||
from preferences.models import AssoOption |
|||
from .models import Facture |
|||
from .payment_utils.comnpay import Payment as ComnpayPayment |
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
def accept_payment(request, factureid): |
|||
facture = get_object_or_404(Facture, id=factureid) |
|||
messages.success( |
|||
request, |
|||
"Le paiement de {} € a été accepté.".format(facture.prix()) |
|||
) |
|||
return redirect(reverse('users:profil', kwargs={'userid':request.user.id})) |
|||
|
|||
|
|||
@csrf_exempt |
|||
@login_required |
|||
def refuse_payment(request): |
|||
messages.error( |
|||
request, |
|||
"Le paiement a été refusé." |
|||
) |
|||
return redirect(reverse('users:profil', kwargs={'userid':request.user.id})) |
|||
|
|||
@csrf_exempt |
|||
def ipn(request): |
|||
p = ComnpayPayment() |
|||
order = ('idTpe', 'idTransaction', 'montant', 'result', 'sec', ) |
|||
try: |
|||
data = OrderedDict([(f, request.POST[f]) for f in order]) |
|||
except MultiValueDictKeyError: |
|||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request") |
|||
|
|||
if not p.validSec(data, AssoOption.get_cached_value('payment_pass')): |
|||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request") |
|||
|
|||
result = True if (request.POST['result'] == 'OK') else False |
|||
idTpe = request.POST['idTpe'] |
|||
idTransaction = request.POST['idTransaction'] |
|||
|
|||
# On vérifie que le paiement nous est destiné |
|||
if not idTpe == AssoOption.get_cached_value('payment_id'): |
|||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request") |
|||
|
|||
try: |
|||
factureid = int(idTransaction) |
|||
except ValueError: |
|||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request") |
|||
|
|||
facture = get_object_or_404(Facture, id=factureid) |
|||
|
|||
# On vérifie que le paiement est valide |
|||
if not result: |
|||
# Le paiement a échoué : on effectue les actions nécessaires (On indique qu'elle a échoué) |
|||
facture.delete() |
|||
|
|||
# On notifie au serveur ComNPay qu'on a reçu les données pour traitement |
|||
return HttpResponse("HTTP/1.1 200 OK") |
|||
|
|||
facture.valid = True |
|||
facture.save() |
|||
|
|||
# A nouveau, on notifie au serveur qu'on a bien traité les données |
|||
return HttpResponse("HTTP/1.0 200 OK") |
|||
|
|||
|
|||
def comnpay(facture, request): |
|||
host = request.get_host() |
|||
p = ComnpayPayment( |
|||
str(AssoOption.get_cached_value('payment_id')), |
|||
str(AssoOption.get_cached_value('payment_pass')), |
|||
'https://' + host + reverse( |
|||
'cotisations:accept_payment', |
|||
kwargs={'factureid':facture.id} |
|||
), |
|||
'https://' + host + reverse('cotisations:refuse_payment'), |
|||
'https://' + host + reverse('cotisations:ipn'), |
|||
"", |
|||
"D" |
|||
) |
|||
r = { |
|||
'action' : 'https://secure.homologation.comnpay.com', |
|||
'method' : 'POST', |
|||
'content' : p.buildSecretHTML( |
|||
"Rechargement du solde", |
|||
facture.prix(), |
|||
idTransaction=str(facture.id) |
|||
), |
|||
'amount' : facture.prix, |
|||
} |
|||
return r |
|||
|
|||
|
|||
PAYMENT_SYSTEM = { |
|||
'COMNPAY' : comnpay, |
|||
'NONE' : None |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
import time |
|||
from random import randrange |
|||
import base64 |
|||
import hashlib |
|||
from collections import OrderedDict |
|||
from itertools import chain |
|||
|
|||
class Payment(): |
|||
|
|||
vad_number = "" |
|||
secret_key = "" |
|||
urlRetourOK = "" |
|||
urlRetourNOK = "" |
|||
urlIPN = "" |
|||
source = "" |
|||
typeTr = "D" |
|||
|
|||
def __init__(self, vad_number = "", secret_key = "", urlRetourOK = "", urlRetourNOK = "", urlIPN = "", source="", typeTr="D"): |
|||
self.vad_number = vad_number |
|||
self.secret_key = secret_key |
|||
self.urlRetourOK = urlRetourOK |
|||
self.urlRetourNOK = urlRetourNOK |
|||
self.urlIPN = urlIPN |
|||
self.source = source |
|||
self.typeTr = typeTr |
|||
|
|||
def buildSecretHTML(self, produit="Produit", montant="0.00", idTransaction=""): |
|||
if idTransaction == "": |
|||
self.idTransaction = str(time.time())+self.vad_number+str(randrange(999)) |
|||
else: |
|||
self.idTransaction = idTransaction |
|||
|
|||
array_tpe = OrderedDict( |
|||
montant= str(montant), |
|||
idTPE= self.vad_number, |
|||
idTransaction= self.idTransaction, |
|||
devise= "EUR", |
|||
lang= 'fr', |
|||
nom_produit= produit, |
|||
source= self.source, |
|||
urlRetourOK= self.urlRetourOK, |
|||
urlRetourNOK= self.urlRetourNOK, |
|||
typeTr= str(self.typeTr) |
|||
) |
|||
|
|||
if self.urlIPN!="": |
|||
array_tpe['urlIPN'] = self.urlIPN |
|||
|
|||
array_tpe['key'] = self.secret_key; |
|||
strWithKey = base64.b64encode(bytes('|'.join(array_tpe.values()), 'utf-8')) |
|||
del array_tpe["key"] |
|||
array_tpe['sec'] = hashlib.sha512(strWithKey).hexdigest() |
|||
|
|||
ret = "" |
|||
for key in array_tpe: |
|||
ret += '<input type="hidden" name="'+key+'" value="'+array_tpe[key]+'"/>' |
|||
|
|||
return ret |
|||
|
|||
def validSec(self, values, secret_key): |
|||
if "sec" in values: |
|||
sec = values['sec'] |
|||
del values["sec"] |
|||
strWithKey = hashlib.sha512(base64.b64encode(bytes('|'.join(values.values()) +"|"+secret_key, 'utf-8'))).hexdigest() |
|||
return strWithKey.upper() == sec.upper() |
|||
else: |
|||
return False |
|||
|
|||
@ -0,0 +1,157 @@ |
|||
|
|||
{% extends "cotisations/sidebar.html" %} |
|||
{% comment %} |
|||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
se veut agnostique au réseau considéré, de manière à être installable en |
|||
quelques clics. |
|||
|
|||
Copyright © 2017 Gabriel Détraz |
|||
Copyright © 2017 Goulven Kermarec |
|||
Copyright © 2017 Augustin Lemesle |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program 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 General Public License along |
|||
with this program; if not, write to the Free Software Foundation, Inc., |
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
{% endcomment %} |
|||
|
|||
{% load bootstrap3 %} |
|||
{% load staticfiles%} |
|||
|
|||
{% block title %}Création et modification de factures{% endblock %} |
|||
|
|||
{% block content %} |
|||
{% bootstrap_form_errors venteform.management_form %} |
|||
|
|||
<form class="form" method="post"> |
|||
{% csrf_token %} |
|||
<h3>Nouvelle facture</h3> |
|||
{{ venteform.management_form }} |
|||
<!-- TODO: FIXME to include data-type="check" for right option in id_cheque select --> |
|||
<h3>Articles de la facture</h3> |
|||
<div id="form_set" class="form-group"> |
|||
{% for form in venteform.forms %} |
|||
<div class='product_to_sell form-inline'> |
|||
Article : |
|||
{% bootstrap_form form label_class='sr-only' %} |
|||
|
|||
<button class="btn btn-danger btn-sm" |
|||
id="id_form-0-article-remove" type="button"> |
|||
<span class="fa fa-times"></span> |
|||
</button> |
|||
</div> |
|||
{% endfor %} |
|||
</div> |
|||
<input class="btn btn-primary btn-sm" role="button" value="Ajouter un article" id="add_one"> |
|||
<p> |
|||
Prix total : <span id="total_price">0,00</span> € |
|||
</p> |
|||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} |
|||
</form> |
|||
|
|||
<script type="text/javascript"> |
|||
|
|||
var prices = {}; |
|||
{% for article in articlelist %} |
|||
prices[{{ article.id|escapejs }}] = {{ article.prix }}; |
|||
{% endfor %} |
|||
|
|||
var template = `Article : |
|||
{% bootstrap_form venteform.empty_form label_class='sr-only' %} |
|||
|
|||
<button class="btn btn-danger btn-sm" |
|||
id="id_form-__prefix__-article-remove" type="button"> |
|||
<span class="fa fa-times"></span> |
|||
</button>` |
|||
|
|||
function add_article(){ |
|||
// Index start at 0 => new_index = number of items |
|||
var new_index = |
|||
document.getElementsByClassName('product_to_sell').length; |
|||
document.getElementById('id_form-TOTAL_FORMS').value ++; |
|||
var new_article = document.createElement('div'); |
|||
new_article.className = 'product_to_sell form-inline'; |
|||
new_article.innerHTML = template.replace(/__prefix__/g, new_index); |
|||
document.getElementById('form_set').appendChild(new_article); |
|||
add_listenner_for_id(new_index); |
|||
} |
|||
|
|||
function update_price(){ |
|||
var price = 0; |
|||
var product_count = |
|||
document.getElementsByClassName('product_to_sell').length; |
|||
var article, article_price, quantity; |
|||
for (i = 0; i < product_count; ++i){ |
|||
article = document.getElementById( |
|||
'id_form-' + i.toString() + '-article').value; |
|||
if (article == '') { |
|||
continue; |
|||
} |
|||
article_price = prices[article]; |
|||
quantity = document.getElementById( |
|||
'id_form-' + i.toString() + '-quantity').value; |
|||
price += article_price * quantity; |
|||
} |
|||
document.getElementById('total_price').innerHTML = |
|||
price.toFixed(2).toString().replace('.', ','); |
|||
} |
|||
|
|||
function add_listenner_for_id(i){ |
|||
document.getElementById('id_form-' + i.toString() + '-article') |
|||
.addEventListener("change", update_price, true); |
|||
document.getElementById('id_form-' + i.toString() + '-article') |
|||
.addEventListener("onkeypress", update_price, true); |
|||
document.getElementById('id_form-' + i.toString() + '-quantity') |
|||
.addEventListener("change", update_price, true); |
|||
document.getElementById('id_form-' + i.toString() + '-article-remove') |
|||
.addEventListener("click", function(event) { |
|||
var article = event.target.parentNode; |
|||
article.parentNode.removeChild(article); |
|||
document.getElementById('id_form-TOTAL_FORMS').value --; |
|||
update_price(); |
|||
} |
|||
) |
|||
} |
|||
|
|||
function set_cheque_info_visibility() { |
|||
var paiement = document.getElementById("id_Facture-paiement"); |
|||
var visible = paiement.value == paiement.getAttribute('data-cheque'); |
|||
p = document.getElementById("id_Facture-paiement"); |
|||
var display = 'none'; |
|||
if (visible) { |
|||
display = 'block'; |
|||
} |
|||
document.getElementById("id_Facture-cheque") |
|||
.parentNode.style.display = display; |
|||
document.getElementById("id_Facture-banque") |
|||
.parentNode.style.display = display; |
|||
} |
|||
|
|||
// Add events manager when DOM is fully loaded |
|||
document.addEventListener("DOMContentLoaded", function() { |
|||
document.getElementById("add_one") |
|||
.addEventListener("click", add_article, true); |
|||
var product_count = |
|||
document.getElementsByClassName('product_to_sell').length; |
|||
for (i = 0; i < product_count; ++i){ |
|||
add_listenner_for_id(i); |
|||
} |
|||
document.getElementById("id_Facture-paiement") |
|||
.addEventListener("change", set_cheque_info_visibility, true); |
|||
set_cheque_info_visibility(); |
|||
update_price(); |
|||
}); |
|||
|
|||
</script> |
|||
|
|||
{% endblock %} |
|||
|
|||
@ -0,0 +1,37 @@ |
|||
{% extends "cotisations/sidebar.html" %} |
|||
{% comment %} |
|||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
se veut agnostique au réseau considéré, de manière à être installable en |
|||
quelques clics. |
|||
|
|||
Copyright © 2017 Gabriel Détraz |
|||
Copyright © 2017 Goulven Kermarec |
|||
Copyright © 2017 Augustin Lemesle |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program 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 General Public License along |
|||
with this program; if not, write to the Free Software Foundation, Inc., |
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
{% endcomment %} |
|||
|
|||
{% load bootstrap3 %} |
|||
{% load staticfiles%} |
|||
|
|||
{% block title %}Rechargement du solde{% endblock %} |
|||
|
|||
{% block content %} |
|||
<h3>Recharger de {{ amount }} €</h3> |
|||
<form class="form" method="{{ method }}" action="{{action}}"> |
|||
{{ content | safe }} |
|||
{% bootstrap_button "Payer" button_type="submit" icon="piggy-bank" %} |
|||
</form> |
|||
{% endblock %} |
|||
@ -0,0 +1,39 @@ |
|||
{% extends "cotisations/sidebar.html" %} |
|||
{% comment %} |
|||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
se veut agnostique au réseau considéré, de manière à être installable en |
|||
quelques clics. |
|||
|
|||
Copyright © 2017 Gabriel Détraz |
|||
Copyright © 2017 Goulven Kermarec |
|||
Copyright © 2017 Augustin Lemesle |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program 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 General Public License along |
|||
with this program; if not, write to the Free Software Foundation, Inc., |
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
{% endcomment %} |
|||
|
|||
{% load bootstrap3 %} |
|||
{% load staticfiles%} |
|||
|
|||
{% block title %}Rechargement du solde{% endblock %} |
|||
|
|||
{% block content %} |
|||
<h2>Rechargement du solde</h2> |
|||
<h3>Solde : <span class="label label-default">{{ request.user.solde }} €</span></h3> |
|||
<form class="form" method="post"> |
|||
{% csrf_token %} |
|||
{% bootstrap_form rechargeform %} |
|||
{% bootstrap_button "Valider" button_type="submit" icon="piggy-bank" %} |
|||
</form> |
|||
{% endblock %} |
|||
@ -0,0 +1,40 @@ |
|||
# -*- mode: python; coding: utf-8 -*- |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2017 Gabriel Détraz |
|||
# Copyright © 2017 Goulven Kermarec |
|||
# Copyright © 2017 Augustin Lemesle |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""logs.acl |
|||
|
|||
Here are defined some functions to check acl on the application. |
|||
""" |
|||
|
|||
def can_view(user): |
|||
"""Check if an user can view the application. |
|||
|
|||
Args: |
|||
user: The user who wants to view the application. |
|||
|
|||
Returns: |
|||
A couple (allowed, msg) where allowed is a boolean which is True if |
|||
viewing is granted and msg is a message (can be None). |
|||
""" |
|||
can = user.has_module_perms('admin') |
|||
return can, None if can else "Vous ne pouvez pas voir cette application." |
|||
@ -0,0 +1,40 @@ |
|||
# -*- mode: python; coding: utf-8 -*- |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2017 Gabriel Détraz |
|||
# Copyright © 2017 Goulven Kermarec |
|||
# Copyright © 2017 Augustin Lemesle |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""machines.acl |
|||
|
|||
Here are defined some functions to check acl on the application. |
|||
""" |
|||
|
|||
def can_view(user): |
|||
"""Check if an user can view the application. |
|||
|
|||
Args: |
|||
user: The user who wants to view the application. |
|||
|
|||
Returns: |
|||
A couple (allowed, msg) where allowed is a boolean which is True if |
|||
viewing is granted and msg is a message (can be None). |
|||
""" |
|||
can = user.has_module_perms('machines') |
|||
return can, None if can else "Vous ne pouvez pas voir cette application." |
|||
@ -0,0 +1,79 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-12-31 18:47 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0069_auto_20171116_0822'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='domain', |
|||
options={'permissions': (('view_domain', 'Peut voir un objet domain'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='extension', |
|||
options={'permissions': (('view_extension', 'Peut voir un objet extension'), ('use_all_extension', 'Peut utiliser toutes les extension'))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='interface', |
|||
options={'permissions': (('view_interface', 'Peut voir un objet interface'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='iplist', |
|||
options={'permissions': (('view_iplist', 'Peut voir un objet iplist'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='iptype', |
|||
options={'permissions': (('view_iptype', 'Peut voir un objet iptype'), ('use_all_iptype', 'Peut utiliser tous les iptype'))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='machine', |
|||
options={'permissions': (('view_machine', 'Peut voir un objet machine quelquonque'), ('change_machine_user', "Peut changer le propriétaire d'une machine"))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='machinetype', |
|||
options={'permissions': (('view_machinetype', 'Peut voir un objet machinetype'), ('use_all_machinetype', "Peut utiliser n'importe quel type de machine"))}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='mx', |
|||
options={'permissions': (('view_mx', 'Peut voir un objet mx'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='nas', |
|||
options={'permissions': (('view_nas', 'Peut voir un objet Nas'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='ns', |
|||
options={'permissions': (('view_nx', 'Peut voir un objet nx'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='ouvertureportlist', |
|||
options={'permissions': (('view_ouvertureportlist', 'Peut voir un objet ouvertureport'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='service', |
|||
options={'permissions': (('view_service', 'Peut voir un objet service'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='soa', |
|||
options={'permissions': (('view_soa', 'Peut voir un objet soa'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='srv', |
|||
options={'permissions': (('view_soa', 'Peut voir un objet soa'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='txt', |
|||
options={'permissions': (('view_txt', 'Peut voir un objet txt'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='vlan', |
|||
options={'permissions': (('view_vlan', 'Peut voir un objet vlan'),)}, |
|||
), |
|||
] |
|||
@ -0,0 +1,19 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-12-31 20:00 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0070_auto_20171231_1947'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='ns', |
|||
options={'permissions': (('view_ns', 'Peut voir un objet ns'),)}, |
|||
), |
|||
] |
|||
@ -0,0 +1,19 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-08 17:22 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0071_auto_20171231_2100'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='interface', |
|||
options={'permissions': (('view_interface', 'Peut voir un objet interface'), ('change_interface_machine', "Peut changer le propriétaire d'une interface"))}, |
|||
), |
|||
] |
|||
@ -0,0 +1,29 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-28 21:03 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0072_auto_20180108_1822'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='Ipv6List', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('ipv6', models.GenericIPAddressField(protocol='IPv6', unique=True)), |
|||
('slaac_ip', models.BooleanField(default=False)), |
|||
('interface', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.Interface')), |
|||
], |
|||
), |
|||
migrations.AlterUniqueTogether( |
|||
name='ipv6list', |
|||
unique_together=set([('interface', 'slaac_ip')]), |
|||
), |
|||
] |
|||
@ -0,0 +1,19 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-29 02:52 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0073_auto_20180128_2203'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='ipv6list', |
|||
options={'permissions': (('view_ipv6list', 'Peut voir un objet ipv6'), ('change_ipv6list_slaac_ip', 'Peut changer la valeur slaac sur une ipv6'))}, |
|||
), |
|||
] |
|||
@ -0,0 +1,19 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-29 23:52 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0074_auto_20180129_0352'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterUniqueTogether( |
|||
name='ipv6list', |
|||
unique_together=set([]), |
|||
), |
|||
] |
|||
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-30 15:23 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('machines', '0075_auto_20180130_0052'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='ipv6list', |
|||
name='interface', |
|||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ipv6list', to='machines.Interface'), |
|||
), |
|||
] |
|||
File diff suppressed because it is too large
@ -0,0 +1,51 @@ |
|||
{% comment %} |
|||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
se veut agnostique au réseau considéré, de manière à être installable en |
|||
quelques clics. |
|||
|
|||
Copyright © 2017 Gabriel Détraz |
|||
Copyright © 2017 Goulven Kermarec |
|||
Copyright © 2017 Augustin Lemesle |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program 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 General Public License along |
|||
with this program; if not, write to the Free Software Foundation, Inc., |
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
{% endcomment %} |
|||
|
|||
{% load acl %} |
|||
|
|||
<table class="table table-striped"> |
|||
<thead> |
|||
<tr> |
|||
<th>Ipv6</th> |
|||
<th>Slaac</th> |
|||
<th></th> |
|||
</tr> |
|||
</thead> |
|||
{% for ipv6 in ipv6_list %} |
|||
<tr> |
|||
<td>{{ ipv6.ipv6 }}</td> |
|||
<td>{{ ipv6.slaac_ip }}</td> |
|||
<td class="text-right"> |
|||
{% can_edit ipv6 %} |
|||
{% include 'buttons/edit.html' with href='machines:edit-ipv6list' id=ipv6.id %} |
|||
{% acl_end %} |
|||
{% can_delete ipv6 %} |
|||
{% include 'buttons/suppr.html' with href='machines:del-ipv6list' id=ipv6.id %} |
|||
{% acl_end %} |
|||
{% include 'buttons/history.html' with href='machines:history' name='ipv6list' id=ipv6.id %} |
|||
</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</table> |
|||
|
|||
@ -0,0 +1,41 @@ |
|||
{% extends "machines/sidebar.html" %} |
|||
{% comment %} |
|||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
se veut agnostique au réseau considéré, de manière à être installable en |
|||
quelques clics. |
|||
|
|||
Copyright © 2017 Gabriel Détraz |
|||
Copyright © 2017 Goulven Kermarec |
|||
Copyright © 2017 Augustin Lemesle |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program 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 General Public License along |
|||
with this program; if not, write to the Free Software Foundation, Inc., |
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
{% endcomment %} |
|||
|
|||
{% load bootstrap3 %} |
|||
{% load acl %} |
|||
|
|||
{% block title %}Machines{% endblock %} |
|||
|
|||
{% block content %} |
|||
<h2>Liste des ipv6 de l'interface</h2> |
|||
{% can_create Ipv6List interface_id %} |
|||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-ipv6list' interface_id %}"><i class="fa fa-plus"></i> Ajouter une ipv6</a> |
|||
{% acl_end %} |
|||
{% include "machines/aff_ipv6.html" with ipv6_list=ipv6_list %} |
|||
<br /> |
|||
<br /> |
|||
<br /> |
|||
{% endblock %} |
|||
|
|||
File diff suppressed because it is too large
@ -0,0 +1,2 @@ |
|||
|
|||
from .acl import * |
|||
@ -0,0 +1,40 @@ |
|||
# -*- mode: python; coding: utf-8 -*- |
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il |
|||
# se veut agnostique au réseau considéré, de manière à être installable en |
|||
# quelques clics. |
|||
# |
|||
# Copyright © 2017 Gabriel Détraz |
|||
# Copyright © 2017 Goulven Kermarec |
|||
# Copyright © 2017 Augustin Lemesle |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program 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 General Public License along |
|||
# with this program; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
"""preferences.acl |
|||
|
|||
Here are defined some functions to check acl on the application. |
|||
""" |
|||
|
|||
def can_view(user): |
|||
"""Check if an user can view the application. |
|||
|
|||
Args: |
|||
user: The user who wants to view the application. |
|||
|
|||
Returns: |
|||
A couple (allowed, msg) where allowed is a boolean which is True if |
|||
viewing is granted and msg is a message (can be None). |
|||
""" |
|||
can = user.has_module_perms('preferences') |
|||
return can, None if can else "Vous ne pouvez pas voir cette application." |
|||
@ -0,0 +1,56 @@ |
|||
import string |
|||
import binascii |
|||
from random import choice |
|||
from Crypto.Cipher import AES |
|||
|
|||
from django.db import models |
|||
from django.conf import settings |
|||
|
|||
EOD = '`%EofD%`' # This should be something that will not occur in strings |
|||
|
|||
|
|||
def genstring(length=16, chars=string.printable): |
|||
return ''.join([choice(chars) for i in range(length)]) |
|||
|
|||
|
|||
def encrypt(key, s): |
|||
obj = AES.new(key) |
|||
datalength = len(s) + len(EOD) |
|||
if datalength < 16: |
|||
saltlength = 16 - datalength |
|||
else: |
|||
saltlength = 16 - datalength % 16 |
|||
ss = ''.join([s, EOD, genstring(saltlength)]) |
|||
return obj.encrypt(ss) |
|||
|
|||
|
|||
def decrypt(key, s): |
|||
obj = AES.new(key) |
|||
ss = obj.decrypt(s) |
|||
return ss.split(bytes(EOD, 'utf-8'))[0] |
|||
|
|||
|
|||
class AESEncryptedField(models.CharField): |
|||
def save_form_data(self, instance, data): |
|||
setattr(instance, self.name, |
|||
binascii.b2a_base64(encrypt(settings.AES_KEY, data))) |
|||
|
|||
def to_python(self, value): |
|||
if value is None: |
|||
return None |
|||
return decrypt(settings.AES_KEY, |
|||
binascii.a2b_base64(value)).decode('utf-8') |
|||
|
|||
def from_db_value(self, value, expression, connection, *args): |
|||
if value is None: |
|||
return value |
|||
return decrypt(settings.AES_KEY, |
|||
binascii.a2b_base64(value)).decode('utf-8') |
|||
|
|||
def get_prep_value(self, value): |
|||
if value is None: |
|||
return value |
|||
return binascii.b2a_base64(encrypt( |
|||
settings.AES_KEY, |
|||
value |
|||
)) |
|||
@ -0,0 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-12-31 20:42 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0024_optionaluser_all_can_create'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterModelOptions( |
|||
name='assooption', |
|||
options={'permissions': (('view_assooption', "Peut voir les options de l'asso"),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='generaloption', |
|||
options={'permissions': (('view_generaloption', 'Peut voir les options générales'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='mailmessageoption', |
|||
options={'permissions': (('view_mailmessageoption', 'Peut voir les options de mail'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='optionalmachine', |
|||
options={'permissions': (('view_optionalmachine', 'Peut voir les options de machine'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='optionaltopologie', |
|||
options={'permissions': (('view_optionaltopologie', 'Peut voir les options de topologie'),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='optionaluser', |
|||
options={'permissions': (('view_optionaluser', "Peut voir les options de l'user"),)}, |
|||
), |
|||
migrations.AlterModelOptions( |
|||
name='service', |
|||
options={'permissions': (('view_service', 'Peut voir les options de service'),)}, |
|||
), |
|||
] |
|||
@ -0,0 +1,16 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-06 19:19 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0025_auto_20171231_2142'), |
|||
('preferences', '0026_auto_20171216_0401'), |
|||
] |
|||
|
|||
operations = [ |
|||
] |
|||
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-08 14:12 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0027_merge_20180106_2019'), |
|||
('preferences', '0043_optionalmachine_create_machine'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='assooption', |
|||
name='description', |
|||
field=models.TextField(default=''), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-11 10:29 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0027_merge_20180106_2019'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='optionaluser', |
|||
name='max_recharge', |
|||
field=models.DecimalField(decimal_places=2, default=100, max_digits=5), |
|||
), |
|||
] |
|||
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-28 21:03 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0027_merge_20180106_2019'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RemoveField( |
|||
model_name='optionalmachine', |
|||
name='ipv6', |
|||
), |
|||
migrations.AddField( |
|||
model_name='optionalmachine', |
|||
name='ipv6_mode', |
|||
field=models.CharField(choices=[('SLAAC', 'Autoconfiguration par RA'), ('DHCPV6', 'Attribution des ip par dhcpv6'), ('DISABLED', 'Désactivé')], default='DISABLED', max_length=32), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-11 10:34 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0028_auto_20180111_1129'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='assooption', |
|||
name='payment', |
|||
field=models.CharField(choices=[('NONE', 'NONE'), ('COMNPAY', 'COMNPAY')], default='NONE', max_length=255), |
|||
), |
|||
] |
|||
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-11 22:46 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0029_auto_20180111_1134'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RemoveField( |
|||
model_name='optionaluser', |
|||
name='max_recharge', |
|||
), |
|||
migrations.AddField( |
|||
model_name='optionaluser', |
|||
name='max_solde', |
|||
field=models.DecimalField(decimal_places=2, default=50, max_digits=5), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-12 11:34 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0030_auto_20180111_2346'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='optionaluser', |
|||
name='self_adhesion', |
|||
field=models.BooleanField(default=False, help_text='Un nouvel utilisateur peut se créer son compte sur re2o'), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-13 16:43 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0031_optionaluser_self_adhesion'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='optionaluser', |
|||
name='min_online_payment', |
|||
field=models.DecimalField(decimal_places=2, default=10, max_digits=5), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 19:12 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0032_optionaluser_min_online_payment'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='generaloption', |
|||
name='GTU_sum_up', |
|||
field=models.TextField(blank=True, default='', help_text='Résumé des CGU'), |
|||
), |
|||
] |
|||
@ -0,0 +1,25 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 19:25 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0033_generaloption_gtu_sum_up'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='generaloption', |
|||
name='GTU', |
|||
field=models.FileField(default='', upload_to='GTU'), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='generaloption', |
|||
name='GTU_sum_up', |
|||
field=models.TextField(blank=True, default=''), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 20:32 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0034_auto_20180114_2025'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='generaloption', |
|||
name='GTU', |
|||
field=models.FileField(default='', upload_to='/var/www/static/'), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 20:41 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0035_auto_20180114_2132'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='generaloption', |
|||
name='GTU', |
|||
field=models.FileField(default='', upload_to=''), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 20:56 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0036_auto_20180114_2141'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='generaloption', |
|||
name='GTU', |
|||
field=models.FileField(default='', null=True, upload_to=''), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 21:09 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0037_auto_20180114_2156'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='generaloption', |
|||
name='GTU', |
|||
field=models.FileField(blank=True, default='', null=True, upload_to=''), |
|||
), |
|||
] |
|||
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-14 23:03 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import preferences.aes_field |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0038_auto_20180114_2209'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='assooption', |
|||
name='payment_id', |
|||
field=models.CharField(max_length=255, null=True), |
|||
), |
|||
] |
|||
@ -0,0 +1,26 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2018-01-29 16:45 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import preferences.aes_field |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0039_auto_20180115_0003'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='assooption', |
|||
name='payment_pass', |
|||
field=preferences.aes_field.AESEncryptedField(blank=True, max_length=255, null=True), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='assooption', |
|||
name='payment_id', |
|||
field=models.CharField(default='', max_length=255), |
|||
), |
|||
] |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue