예제 #1
0
def setup():
    # create admin user
    if not User.query.count():
        app.logger.info('No users found. Creating new admin user.')
        admin = User(username='******',
                     password='******',
                     name='Administrative User',
                     has_access=True)
        admin.hash_password()
        db.session.add(admin)

        db.session.add(
            RadCheck(username='******',
                     attribute='Cleartext-Password',
                     op=':=',
                     value='freeradius@admin'))
        db.session.commit()

    # create default users groups
    if not Group.query.count():
        app.logger.info('No groups found. Creating default user group.')
        db.session.add(Group(name='user', description='Default user group'))

        # create default parameters for groups
        db.session.add(
            RadUserGroup(username='******', groupname='user', priority=1))
        db.session.commit()
예제 #2
0
def new_user():
    groups = Group.query.all()

    form = UserForm()
    form.group.choices = [(group.name, group.name) for group in groups]

    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data,
                    active=form.active.data,
                    name=form.name.data,
                    phone=form.phone.data,
                    address=form.address.data,
                    has_access=form.has_access.data)
        user.hash_password()
        db.session.add(user)
        app.logger.debug('Creating new user %s', user.username)

        db.session.add(
            RadUserGroup(username=form.username.data,
                         groupname=form.group.data,
                         priority=0))
        app.logger.debug(
            'Creating relation user-group for user %s and group %s',
            user.username, form.group.data)

        db.session.add(
            RadCheck(username=form.username.data,
                     attribute='Cleartext-Password',
                     op=':=',
                     value=form.password.data))
        app.logger.debug('Creating Cleartext-Password user check')

        if not form.active.data:
            db.session.add(
                RadCheck(username=form.username.data,
                         attribute='Auth-Type',
                         op=':=',
                         value='Reject'))
            app.logger.debug(
                'Creating Auth-Type Reject check for disabled user')

        db.session.commit()

        flash(_('New user added'), 'success')
        return redirect(url_for('list_users'))
    elif form.errors:
        app.logger.debug('Create User form errors: %s', form.errors)
        flash(_('Form has errors'), 'error')

    return render_template('radius/user_form.html',
                           form=form,
                           form_errors=form.errors,
                           action='add')