mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Pylint compliance on logs
This commit is contained in:
parent
f2c91199d1
commit
2114a6ebba
7 changed files with 28 additions and 94 deletions
|
@ -35,20 +35,16 @@ https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_pyth
|
||||||
Inspiré du travail de Daniel Stan au Crans
|
Inspiré du travail de Daniel Stan au Crans
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
|
||||||
import netaddr
|
|
||||||
import radiusd # Module magique freeradius (radiusd.py is dummy)
|
|
||||||
import binascii
|
|
||||||
import hashlib
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
import radiusd # Module magique freeradius (radiusd.py is dummy)
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from machines.models import Interface, IpList, Nas, Domain
|
from machines.models import Interface, IpList, Nas, Domain
|
||||||
from topologie.models import Room, Port, Switch
|
from topologie.models import Port, Switch
|
||||||
from users.models import User
|
from users.models import User
|
||||||
from preferences.models import OptionalTopologie
|
from preferences.models import OptionalTopologie
|
||||||
|
|
||||||
|
@ -109,7 +105,8 @@ def radius_event(fun):
|
||||||
tuples en entrée en un dictionnaire."""
|
tuples en entrée en un dictionnaire."""
|
||||||
|
|
||||||
def new_f(auth_data):
|
def new_f(auth_data):
|
||||||
if type(auth_data) == dict:
|
""" The function transforming the tuples as dict """
|
||||||
|
if isinstance(auth_data, dict):
|
||||||
data = auth_data
|
data = auth_data
|
||||||
else:
|
else:
|
||||||
data = dict()
|
data = dict()
|
||||||
|
@ -188,6 +185,9 @@ def authorize(data):
|
||||||
|
|
||||||
@radius_event
|
@radius_event
|
||||||
def post_auth(data):
|
def post_auth(data):
|
||||||
|
""" Function called after the user is authenticated
|
||||||
|
"""
|
||||||
|
|
||||||
nas = data.get('NAS-IP-Address', data.get('NAS-Identifier', None))
|
nas = data.get('NAS-IP-Address', data.get('NAS-Identifier', None))
|
||||||
nas_instance = find_nas_from_request(nas)
|
nas_instance = find_nas_from_request(nas)
|
||||||
# Toutes les reuquètes non proxifiées
|
# Toutes les reuquètes non proxifiées
|
||||||
|
@ -220,7 +220,7 @@ def post_auth(data):
|
||||||
.filter(stack_member_id=id_stack_member)
|
.filter(stack_member_id=id_stack_member)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
'interface_set__domain__extension'
|
'interface_set__domain__extension'
|
||||||
)
|
)
|
||||||
.first())
|
.first())
|
||||||
# On récupère le numéro du port sur l'output de freeradius.
|
# On récupère le numéro du port sur l'output de freeradius.
|
||||||
# La ligne suivante fonctionne pour cisco, HP et Juniper
|
# La ligne suivante fonctionne pour cisco, HP et Juniper
|
||||||
|
@ -229,7 +229,7 @@ def post_auth(data):
|
||||||
sw_name, room, reason, vlan_id = out
|
sw_name, room, reason, vlan_id = out
|
||||||
|
|
||||||
log_message = '(fil) %s -> %s [%s%s]' % (
|
log_message = '(fil) %s -> %s [%s%s]' % (
|
||||||
sw_name + u":" + port + u"/" + unicode(room),
|
sw_name + u":" + port + u"/" + str(room),
|
||||||
mac,
|
mac,
|
||||||
vlan_id,
|
vlan_id,
|
||||||
(reason and u': ' + reason).encode('utf-8')
|
(reason and u': ' + reason).encode('utf-8')
|
||||||
|
@ -251,6 +251,7 @@ def post_auth(data):
|
||||||
return radiusd.RLM_MODULE_OK
|
return radiusd.RLM_MODULE_OK
|
||||||
|
|
||||||
|
|
||||||
|
# TODO : remove this function
|
||||||
@radius_event
|
@radius_event
|
||||||
def dummy_fun(_):
|
def dummy_fun(_):
|
||||||
"""Do nothing, successfully. (C'est pour avoir un truc à mettre)"""
|
"""Do nothing, successfully. (C'est pour avoir un truc à mettre)"""
|
||||||
|
@ -259,11 +260,12 @@ def dummy_fun(_):
|
||||||
|
|
||||||
def detach(_=None):
|
def detach(_=None):
|
||||||
"""Appelé lors du déchargement du module (enfin, normalement)"""
|
"""Appelé lors du déchargement du module (enfin, normalement)"""
|
||||||
print "*** goodbye from auth.py ***"
|
print("*** goodbye from auth.py ***")
|
||||||
return radiusd.RLM_MODULE_OK
|
return radiusd.RLM_MODULE_OK
|
||||||
|
|
||||||
|
|
||||||
def find_nas_from_request(nas_id):
|
def find_nas_from_request(nas_id):
|
||||||
|
""" Get the nas object from its ID """
|
||||||
nas = (Interface.objects
|
nas = (Interface.objects
|
||||||
.filter(
|
.filter(
|
||||||
Q(domain=Domain.objects.filter(name=nas_id)) |
|
Q(domain=Domain.objects.filter(name=nas_id)) |
|
||||||
|
@ -443,7 +445,7 @@ def decide_vlan_and_register_switch(nas_machine, nas_type, port_number,
|
||||||
return (sw_name,
|
return (sw_name,
|
||||||
room,
|
room,
|
||||||
u'Erreur dans le register mac %s' % (
|
u'Erreur dans le register mac %s' % (
|
||||||
reason + unicode(mac_address)
|
reason + str(mac_address)
|
||||||
),
|
),
|
||||||
VLAN_NOK)
|
VLAN_NOK)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -20,5 +20,8 @@
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""logs
|
||||||
|
The app in charge of the stats and logs of what's happening in re2o
|
||||||
|
"""
|
||||||
|
|
||||||
from .acl import *
|
from .acl import *
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
# -*- 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.
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
|
@ -1,28 +0,0 @@
|
||||||
# -*- 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.
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
|
@ -20,6 +20,9 @@
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""logs.templatetags.logs_extra
|
||||||
|
A templatetag to get the class name for a given object
|
||||||
|
"""
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
|
@ -28,4 +31,5 @@ register = template.Library()
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def classname(obj):
|
def classname(obj):
|
||||||
|
""" Returns the object class name """
|
||||||
return obj.__class__.__name__
|
return obj.__class__.__name__
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""logs.tests
|
||||||
|
The tests for the Logs module.
|
||||||
|
"""
|
||||||
|
|
||||||
from django.test import TestCase
|
# from django.test import TestCase
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
|
@ -46,8 +46,6 @@ from django.db.models import Count, Max
|
||||||
from reversion.models import Revision
|
from reversion.models import Revision
|
||||||
from reversion.models import Version, ContentType
|
from reversion.models import Version, ContentType
|
||||||
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
from users.models import (
|
from users.models import (
|
||||||
User,
|
User,
|
||||||
ServiceUser,
|
ServiceUser,
|
||||||
|
@ -109,15 +107,6 @@ from re2o.acl import (
|
||||||
from re2o.utils import all_active_assigned_interfaces_count
|
from re2o.utils import all_active_assigned_interfaces_count
|
||||||
from re2o.utils import all_active_interfaces_count, SortTable
|
from re2o.utils import all_active_interfaces_count, SortTable
|
||||||
|
|
||||||
STATS_DICT = {
|
|
||||||
0: ["Tout", 36],
|
|
||||||
1: ["1 mois", 1],
|
|
||||||
2: ["2 mois", 2],
|
|
||||||
3: ["6 mois", 6],
|
|
||||||
4: ["1 an", 12],
|
|
||||||
5: ["2 an", 24],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_view_app('logs')
|
@can_view_app('logs')
|
||||||
|
@ -418,12 +407,6 @@ def stats_users(request):
|
||||||
nombre de machines par user, d'etablissements par user,
|
nombre de machines par user, d'etablissements par user,
|
||||||
de moyens de paiements par user, de banque par user,
|
de moyens de paiements par user, de banque par user,
|
||||||
de bannissement par user, etc"""
|
de bannissement par user, etc"""
|
||||||
onglet = request.GET.get('onglet')
|
|
||||||
try:
|
|
||||||
_search_field = STATS_DICT[onglet]
|
|
||||||
except KeyError:
|
|
||||||
_search_field = STATS_DICT[0]
|
|
||||||
onglet = 0
|
|
||||||
stats = {
|
stats = {
|
||||||
'Utilisateur': {
|
'Utilisateur': {
|
||||||
'Machines': User.objects.annotate(
|
'Machines': User.objects.annotate(
|
||||||
|
@ -458,11 +441,7 @@ def stats_users(request):
|
||||||
).order_by('-num')[:10],
|
).order_by('-num')[:10],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return render(request, 'logs/stats_users.html', {
|
return render(request, 'logs/stats_users.html', {'stats_list': stats})
|
||||||
'stats_list': stats,
|
|
||||||
'stats_dict': STATS_DICT,
|
|
||||||
'active_field': onglet
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -485,7 +464,6 @@ def stats_actions(request):
|
||||||
@can_view_app('users')
|
@can_view_app('users')
|
||||||
def stats_droits(request):
|
def stats_droits(request):
|
||||||
"""Affiche la liste des droits et les users ayant chaque droit"""
|
"""Affiche la liste des droits et les users ayant chaque droit"""
|
||||||
depart = time()
|
|
||||||
stats_list = {}
|
stats_list = {}
|
||||||
|
|
||||||
for droit in ListRight.objects.all().select_related('group_ptr'):
|
for droit in ListRight.objects.all().select_related('group_ptr'):
|
||||||
|
|
Loading…
Reference in a new issue