class FirmwareUpdaterConfig(ApiAppConfig):
    name = 'openwisp_firmware_upgrader'
    label = 'firmware_upgrader'
    verbose_name = _('Firmware Management')

    API_ENABLED = app_settings.FIRMWARE_UPGRADER_API
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            'firmware_upgrader': default_or_test('400/hour', None)
        },
    }

    def ready(self, *args, **kwargs):
        super().ready(*args, **kwargs)
        self.add_default_menu_items()

    def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [
            {
                'model': f'{self.label}.Build'
            },
        ]
        if not hasattr(settings, menu_setting):  # pragma: no cover
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items
Ejemplo n.º 2
0
class FirmwareUpdaterConfig(ApiAppConfig):
    name = 'openwisp_firmware_upgrader'
    label = 'firmware_upgrader'
    verbose_name = _('Firmware Management')

    API_ENABLED = app_settings.FIRMWARE_UPGRADER_API
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            'firmware_upgrader': default_or_test('400/hour', None)
        },
    }

    def ready(self, *args, **kwargs):
        super().ready(*args, **kwargs)
        self.add_default_menu_items()
        self.connect_device_signals()

    def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [
            {
                'model': f'{self.label}.Build'
            },
        ]
        if not hasattr(settings, menu_setting):  # pragma: no cover
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items

    def connect_device_signals(self):
        DeviceConnection = load_model('connection', 'DeviceConnection')
        DeviceFirmware = load_model('firmware_upgrader', 'DeviceFirmware')
        FirmwareImage = load_model('firmware_upgrader', 'FirmwareImage')
        post_save.connect(
            DeviceFirmware.auto_add_device_firmware_to_device,
            sender=DeviceConnection,
            dispatch_uid='connection.auto_add_device_firmware',
        )
        post_save.connect(
            DeviceFirmware.auto_create_device_firmwares,
            sender=FirmwareImage,
            dispatch_uid='firmware_image.auto_add_device_firmwares',
        )
Ejemplo n.º 3
0
class OpenWispIpamConfig(ApiAppConfig):
    name = 'openwisp_ipam'
    verbose_name = 'IPAM'

    API_ENABLED = True
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            'ipam': default_or_test('400/hour', None)
        },
    }

    def ready(self, *args, **kwargs):
        super().ready(*args, **kwargs)
        self.register_menu_groups()

    def register_menu_groups(self):
        register_menu_group(
            position=90,
            config={
                'label': _('Ipam'),
                'items': {
                    1: {
                        'label': _('IP Addresses'),
                        'model': get_model_name('openwisp_ipam', 'IpAddress'),
                        'name': 'changelist',
                        'icon': 'ow-ip-address',
                    },
                    2: {
                        'label': _('Subnets'),
                        'model': get_model_name('openwisp_ipam', 'Subnet'),
                        'name': 'changelist',
                        'icon': 'ow-subnet',
                    },
                },
                'icon': 'ow-ipam',
            },
        )
Ejemplo n.º 4
0
class OpenWispIpamConfig(ApiAppConfig):
    name = 'openwisp_ipam'
    verbose_name = 'IPAM'

    API_ENABLED = True
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            'ipam': default_or_test('400/hour', None)
        },
    }

    def ready(self, *args, **kwargs):
        super().ready(*args, **kwargs)
        patch_ipaddress_lib()
        items = [
            {
                'model': get_model_name('openwisp_ipam', 'Subnet')
            },
            {
                'model': get_model_name('openwisp_ipam', 'IpAddress')
            },
        ]
        register_menu_items(items,
                            name_menu='OPENWISP_DEFAULT_ADMIN_MENU_ITEMS')
Ejemplo n.º 5
0
from django.conf import settings
from openwisp_utils.utils import default_or_test

ORGANIZATION_USER_ADMIN = getattr(settings, 'OPENWISP_ORGANIZATION_USER_ADMIN', False)
ORGANIZATION_OWNER_ADMIN = getattr(settings, 'OPENWISP_ORGANIZATION_OWNER_ADMIN', True)
USERS_AUTH_API = getattr(settings, 'OPENWISP_USERS_AUTH_API', True)
USERS_AUTH_THROTTLE_RATE = getattr(
    settings,
    'OPENWISP_USERS_AUTH_THROTTLE_RATE',
    default_or_test(value='20/day', test=None),
)
Ejemplo n.º 6
0
class OpenwispRadiusConfig(ApiAppConfig):
    name = 'openwisp_radius'
    label = 'openwisp_radius'
    verbose_name = 'Freeradius'

    API_ENABLED = True
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            # None by default
            'authorize': None,
            'postauth': None,
            'accounting': None,
            'obtain_auth_token': None,
            'validate_auth_token': None,
            'create_phone_token': None,
            'validate_phone_token': None,
            # Relaxed throttling Policy
            'others': default_or_test('400/hour', None),
        },
    }
    AccountConfig.default_auto_field = 'django.db.models.AutoField'
    SocialAccountConfig.default_auto_field = 'django.db.models.AutoField'

    def ready(self, *args, **kwargs):
        from . import checks  # noqa

        super().ready(*args, **kwargs)
        self.connect_signals()
        self.regiser_menu_groups()

        if app_settings.SOCIAL_REGISTRATION_CONFIGURED:
            register_registration_method('social_login', _('Social login'))
        if app_settings.SAML_REGISTRATION_CONFIGURED:
            register_registration_method(
                'saml',
                app_settings.SAML_REGISTRATION_METHOD_LABEL,
                strong_identity=True,
            )

    def connect_signals(self):
        Organization = swapper.load_model('openwisp_users', 'Organization')
        OrganizationUser = swapper.load_model('openwisp_users', 'OrganizationUser')
        OrganizationRadiusSettings = load_model('OrganizationRadiusSettings')
        RadiusToken = load_model('RadiusToken')
        RadiusAccounting = load_model('RadiusAccounting')
        User = get_user_model()
        from openwisp_radius.api.freeradius_views import AccountingView

        radius_accounting_success.connect(
            send_email_on_new_accounting_handler,
            sender=AccountingView,
            dispatch_uid='send_email_on_new_accounting',
        )

        post_save.connect(
            create_default_groups_handler,
            sender=Organization,
            dispatch_uid='create_default_groups',
        )
        post_save.connect(
            update_user_related_records,
            sender=User,
            dispatch_uid='update_user_related_records',
        )
        post_save.connect(
            set_default_group_handler,
            sender=OrganizationUser,
            dispatch_uid='set_default_group',
        )
        pre_save.connect(
            organization_pre_save,
            sender=Organization,
            dispatch_uid='openwisp_radius_org_pre_save',
        )
        post_save.connect(
            organization_post_save,
            sender=Organization,
            dispatch_uid='openwisp_radius_org_post_save',
        )
        post_delete.connect(
            self.radiustoken_post_delete,
            sender=RadiusToken,
            dispatch_uid='openwisp_radius_radiustoken_post_delete',
        )
        post_save.connect(
            self.radiusorgsettings_post_save,
            sender=OrganizationRadiusSettings,
            dispatch_uid='openwisp_radius_organizationradiussettings_post_save',
        )
        post_delete.connect(
            self.radiusorgsettings_post_delete,
            sender=OrganizationRadiusSettings,
            dispatch_uid='openwisp_radius_organizationradiussettings_post_delete',
        )
        if app_settings.CONVERT_CALLED_STATION_ON_CREATE:
            post_save.connect(
                convert_radius_called_station_id,
                sender=RadiusAccounting,
                dispatch_uid='openwisp_radius_convert_called_station_id',
            )

    def radiustoken_post_delete(self, instance, **kwargs):
        instance.delete_cache()

    def radiusorgsettings_post_save(self, instance, **kwargs):
        instance.save_cache()

    def radiusorgsettings_post_delete(self, instance, **kwargs):
        instance.delete_cache()

    def regiser_menu_groups(self):
        items = {
            1: {
                'label': _('Accounting Sessions'),
                'model': get_model_name(self.label, 'RadiusAccounting'),
                'name': 'changelist',
                'icon': 'ow-radius-accounting',
            },
            2: {
                'label': _('Groups'),
                'model': get_model_name(self.label, 'RadiusGroup'),
                'name': 'changelist',
                'icon': 'ow-radius-group',
            },
            3: {
                'label': _('NAS'),
                'model': get_model_name(self.label, 'Nas'),
                'name': 'changelist',
                'icon': 'ow-radius-nas',
            },
            4: {
                'label': _('Checks'),
                'model': get_model_name(self.label, 'RadiusCheck'),
                'name': 'changelist',
                'icon': 'ow-radius-checks',
            },
            5: {
                'label': _('Replies'),
                'model': get_model_name(self.label, 'RadiusReply'),
                'name': 'changelist',
                'icon': 'ow-radius-replies',
            },
            6: {
                'label': _('Batch user Creation'),
                'model': get_model_name(self.label, 'RadiusBatch'),
                'name': 'changelist',
                'icon': 'ow-batch-creation',
            },
            7: {
                'label': _('Post Auth Log'),
                'model': get_model_name(self.label, 'RadiusPostAuth'),
                'name': 'changelist',
                'icon': 'ow-radius-post-log',
            },
        }
        if getattr(app_settings, 'DEBUG', False):
            items[8] = {
                'label': _('Radius Token'),
                'model': get_model_name(self.label, 'RadiusToken'),
                'name': 'changelist',
                'icon': 'ow-radius-token',
            }
        register_menu_group(
            position=70,
            config={'label': _('RADIUS'), 'items': items, 'icon': 'ow-radius'},
        )
Ejemplo n.º 7
0
class OpenwispRadiusConfig(ApiAppConfig):
    name = 'openwisp_radius'
    label = 'openwisp_radius'
    verbose_name = 'Freeradius'

    API_ENABLED = True
    REST_FRAMEWORK_SETTINGS = {
        'DEFAULT_THROTTLE_RATES': {
            # None by default
            'authorize': None,
            'postauth': None,
            'accounting': None,
            'obtain_auth_token': None,
            'validate_auth_token': None,
            'create_phone_token': None,
            'validate_phone_token': None,
            # Relaxed throttling Policy
            'others': default_or_test('400/hour', None),
        },
    }

    def ready(self, *args, **kwargs):
        super().ready(*args, **kwargs)
        self.connect_signals()
        self.add_default_menu_items()

    def connect_signals(self):
        Organization = swapper.load_model('openwisp_users', 'Organization')
        OrganizationUser = swapper.load_model('openwisp_users',
                                              'OrganizationUser')
        OrganizationRadiusSettings = load_model('OrganizationRadiusSettings')
        RadiusToken = load_model('RadiusToken')
        User = get_user_model()

        post_save.connect(
            create_default_groups_handler,
            sender=Organization,
            dispatch_uid='create_default_groups',
        )
        post_save.connect(
            update_user_related_records,
            sender=User,
            dispatch_uid='update_user_related_records',
        )
        post_save.connect(
            set_default_group_handler,
            sender=OrganizationUser,
            dispatch_uid='set_default_group',
        )
        pre_save.connect(
            organization_pre_save,
            sender=Organization,
            dispatch_uid='openwisp_radius_org_pre_save',
        )
        post_save.connect(
            organization_post_save,
            sender=Organization,
            dispatch_uid='openwisp_radius_org_post_save',
        )
        post_delete.connect(
            self.radiustoken_post_delete,
            sender=RadiusToken,
            dispatch_uid='openwisp_radius_radiustoken_post_delete',
        )
        post_save.connect(
            self.radiusorgsettings_post_save,
            sender=OrganizationRadiusSettings,
            dispatch_uid='openwisp_radius_organizationradiussettings_post_save',
        )
        post_delete.connect(
            self.radiusorgsettings_post_delete,
            sender=OrganizationRadiusSettings,
            dispatch_uid=
            'openwisp_radius_organizationradiussettings_post_delete',
        )

    def radiustoken_post_delete(self, instance, **kwargs):
        instance.delete_cache()

    def radiusorgsettings_post_save(self, instance, **kwargs):
        instance.save_cache()

    def radiusorgsettings_post_delete(self, instance, **kwargs):
        instance.delete_cache()

    def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [{
            'model': f'{self.label}.RadiusAccounting',
            'label': _('Radius sessions')
        }]
        if not hasattr(settings, menu_setting):
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items