Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced unixid with uid-/gidnumber (glauth v2.0) #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions app/adminview.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ def no_root_allowed(form, field):
othergroups='Other Groups',
is_active='Active',
mail='Email Address',
unixid='UnixID')
uidnumber='UIDNumber')
# Configure columns in list view (order and which to show)
column_list = ('username', 'givenname', 'surname', 'mail', 'unixid', 'is_active', 'pgroup') #, 'othergroups')
column_list = ('username', 'givenname', 'surname', 'mail', 'uidnumber', 'is_active', 'pgroup') #, 'othergroups')
# Configure columns that are editable in list view
column_editable_list = ['username', 'mail', 'givenname', 'surname', 'is_active']
# Configure columns that a searchable
column_searchable_list = column_editable_list
# Configure columns to exclude in list view
column_exclude_list = ['password_hash']
# Details View List
column_details_list = ('username', 'givenname', 'surname', 'mail', 'unixid', 'is_active', 'pgroup')
column_details_list = ('username', 'givenname', 'surname', 'mail', 'uidnumber', 'is_active', 'pgroup')

# Configure colums to exclude in edit/create view
form_excluded_columns = column_exclude_list
Expand All @@ -125,7 +125,7 @@ def no_root_allowed(form, field):
)

# Configure which form fields to show
form_columns = ('send_pw_reset_link', 'send_invite_link', 'username', 'password', 'givenname', 'surname', 'mail', 'unixid', 'is_active', 'pgroup', 'othergroups')
form_columns = ('send_pw_reset_link', 'send_invite_link', 'username', 'password', 'givenname', 'surname', 'mail', 'uidnumber', 'is_active', 'pgroup', 'othergroups')

# Configure which columns are shown in detail view
column_details_exclude_list = ['password_hash']
Expand All @@ -147,11 +147,11 @@ def create_form(self, obj=None):
# Add Password field description
form.password.description = 'Leave empty if you want to autogenerate a password.'

default_unixid=5001
highest_user=User.query.order_by(User.unixid.desc()).limit(1).all()
default_uidnumber=5001
highest_user=User.query.order_by(User.uidnumber.desc()).limit(1).all()
if highest_user:
default_unixid=highest_user[0].unixid+1
form.unixid.data=default_unixid
default_uidnumber=highest_user[0].uidnumber+1
form.uidnumber.data=default_uidnumber
return form

def edit_form(self, obj):
Expand Down Expand Up @@ -236,19 +236,19 @@ def valid_chars(form, field):
name='Name',
description='Description',
primary='Primary Group',
unixid='UnixID',
gidnumber='GIDNumber',
included_in='Included in Group(s)',
includes='Includes Group(s)')
# Configure columns in list view (order and which to show)
column_list = ('name', 'unixid', 'primary', 'description')
column_list = ('name', 'gidnumber', 'primary', 'description')
# Configure columns that are editable in list view
column_editable_list = []
# Configure columns that a searchable
column_searchable_list = ['name', 'unixid', 'primary', 'description']
column_searchable_list = ['name', 'gidnumber', 'primary', 'description']
# Configure columns to exclude in list view
#column_exclude_list = ['password_hash']

column_details_list = ('name', 'unixid', 'primary', 'description', 'includes')
column_details_list = ('name', 'gidnumber', 'primary', 'description', 'includes')

# Sort by primary then name
column_default_sort = [('primary', True), ('name', False)]
Expand All @@ -264,7 +264,7 @@ def valid_chars(form, field):
)

# Configure which form fields to show
form_columns = ('name', 'unixid', 'primary', 'description', 'includes', 'included_in', 'p_users', 'o_users')
form_columns = ('name', 'gidnumber', 'primary', 'description', 'includes', 'included_in', 'p_users', 'o_users')

# Configure which columns are shown in detail view
column_details_exclude_list = ['password_hash']
Expand All @@ -283,11 +283,11 @@ def create_form(self, obj=None):
delattr(form, 'included_in')
delattr(form, 'p_users')
delattr(form, 'o_users')
default_unixid=5500
highest_group=Group.query.order_by(Group.unixid.desc()).limit(1).all()
default_gidnumber=5500
highest_group=Group.query.order_by(Group.gidnumber.desc()).limit(1).all()
if highest_group:
default_unixid=highest_group[0].unixid+1
form.unixid.data=default_unixid
default_gidnumber=highest_group[0].gidnumber+1
form.gidnumber.data=default_gidnumber
return form

def edit_form(self, obj):
Expand Down
8 changes: 4 additions & 4 deletions app/glauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def create_glauth_config():
new_config += " sn = \"{}\"\n".format(user.surname)
if user.mail:
new_config += " mail = \"{}\"\n".format(user.mail)
new_config += " unixid = {}\n".format(user.unixid)
new_config += " uidnumber = {}\n".format(user.uidnumber)
new_config += " primarygroup = {}\n".format(user.primarygroup)
new_config += " passsha256 = \"{}\"\n".format(user.password_hash)
if len(user.othergroups) > 0:
new_config += " otherGroups = [ {} ]\n".format(",".join(str(group.unixid) for group in user.othergroups))
new_config += " otherGroups = [ {} ]\n".format(",".join(str(group.gidnumber) for group in user.othergroups))
if not user.is_active:
new_config += " disabled = true\n"
new_config += "\n"
Expand All @@ -56,10 +56,10 @@ def create_glauth_config():
for group in groups:
new_config += "[[groups]]\n"
new_config += " name = \"{}\"\n".format(group.name)
new_config += " unixid = {}\n".format(group.unixid)
new_config += " gidnumber = {}\n".format(group.gidnumber)
# Need to count the query results as len() is not working here.
if group.included_in.count() > 0:
new_config += " includegroups = [ {} ]\n".format(",".join(str(group.unixid) for group in group.included_in))
new_config += " includegroups = [ {} ]\n".format(",".join(str(group.gidnumber) for group in group.included_in))
# Add Group description as comment
if group.description != None:
new_config += " # {}\n".format(group.description)
Expand Down
32 changes: 16 additions & 16 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

othergroups_users = db.Table(
'othergroups_users',
db.Column('user_id', db.Integer(), db.ForeignKey('user.unixid')),
db.Column('group_id', db.Integer(), db.ForeignKey('group.unixid'))
db.Column('user_id', db.Integer(), db.ForeignKey('user.uidnumber')),
db.Column('group_id', db.Integer(), db.ForeignKey('group.gidnumber'))
)

included_groups = db.Table(
'included_groups',
db.Column('include_id', db.Integer(), db.ForeignKey('group.unixid')),
db.Column('included_in_id', db.Integer(), db.ForeignKey('group.unixid'))
db.Column('include_id', db.Integer(), db.ForeignKey('group.gidnumber')),
db.Column('included_in_id', db.Integer(), db.ForeignKey('group.gidnumber'))
)


Expand All @@ -38,13 +38,13 @@ def __repr__(self):
class Group(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), index=True, unique=True, nullable=False)
unixid = db.Column(db.Integer, unique=True, nullable=False)
gidnumber = db.Column(db.Integer, unique=True, nullable=False)
primary = db.Column(db.Boolean, default=False, nullable=False)
description = db.Column(db.String(255))
p_users = db.relationship('User', backref='pgroup', lazy='dynamic')
included_in = db.relationship('Group', secondary=included_groups,
primaryjoin=(included_groups.c.include_id == unixid),
secondaryjoin=(included_groups.c.included_in_id == unixid),
primaryjoin=(included_groups.c.include_id == gidnumber),
secondaryjoin=(included_groups.c.included_in_id == gidnumber),
backref=db.backref('includes', lazy='dynamic'), lazy='dynamic')
def __repr__(self):
return '{}'.format(self.name)
Expand All @@ -57,11 +57,11 @@ class User(UserMixin, db.Model):
mail = db.Column(db.String(50), index=True, unique=True)
givenname = db.Column(db.String(40)) #, index=True)
surname = db.Column(db.String(40)) #, index=True)
unixid = db.Column(db.Integer, unique=True, nullable=False)
uidnumber = db.Column(db.Integer, unique=True, nullable=False)
is_active = db.Column(db.Boolean, default=True, nullable=False)
password_hash = db.Column(db.String(64), nullable=False)
# add activation date?
primarygroup = db.Column(db.Integer, db.ForeignKey('group.unixid'), nullable=False)
primarygroup = db.Column(db.Integer, db.ForeignKey('group.gidnumber'), nullable=False)
othergroups = db.relationship('Group', secondary=othergroups_users,
backref=db.backref('o_users', lazy='dynamic'))

Expand Down Expand Up @@ -97,7 +97,7 @@ def get_new_account_token(self, expires_in=86400):
def in_groups(self,*allowed_groups):
"""Check if the user is in a group
"""
primarygroup=Group.query.filter_by(unixid=self.primarygroup).first()
primarygroup=Group.query.filter_by(gidnumber=self.primarygroup).first()
if primarygroup.name in allowed_groups:
return True
for group in self.othergroups:
Expand Down Expand Up @@ -134,21 +134,21 @@ def create_basic_db():

db.session.add(settings)

og1 = Group(name='glauth_admin', unixid=5551, description='Glauth UI admin group')
og2 = Group(name='vpn', unixid=5552)
og1 = Group(name='glauth_admin', gidnumber=5551, description='Glauth UI admin group')
og2 = Group(name='vpn', gidnumber=5552)

db.session.add(og1)
db.session.add(og2)

pg1 = Group(name='people', unixid=5501, primary=True, description='primary user group', includes=[ og2 ])
pg2 = Group(name='svcaccts', unixid=5502, primary=True, description='service accounts')
pg1 = Group(name='people', gidnumber=5501, primary=True, description='primary user group', includes=[ og2 ])
pg2 = Group(name='svcaccts', gidnumber=5502, primary=True, description='service accounts')

db.session.add(pg1)
db.session.add(pg2)

u1 = User(username='j_doe', givenname='Jane', surname='Doe', unixid=5001, password_hash='6478579e37aff45f013e14eeb30b3cc56c72ccdc310123bcdf53e0333e3f416a', mail='[email protected]', pgroup=pg1, othergroups=[og1])
u1 = User(username='j_doe', givenname='Jane', surname='Doe', uidnumber=5001, password_hash='6478579e37aff45f013e14eeb30b3cc56c72ccdc310123bcdf53e0333e3f416a', mail='[email protected]', pgroup=pg1, othergroups=[og1])
# PW: dogood
u2 = User(username='search', unixid=5002, password_hash='125844054e30fabcd4182ae69c9d7b38b58d63c067be10ab5ab883d658383316', pgroup=pg2)
u2 = User(username='search', uidnumber=5002, password_hash='125844054e30fabcd4182ae69c9d7b38b58d63c067be10ab5ab883d658383316', pgroup=pg2)
# PW: searchpw
db.session.add(u1)
db.session.add(u2)
Expand Down
2 changes: 1 addition & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@app.route('/index')
@login_required
def index():
pgroup_name = Group.query.filter_by(unixid=current_user.primarygroup).first().name
pgroup_name = Group.query.filter_by(gidnumber=current_user.primarygroup).first().name
#return render_template('index.html', title='Home', user=user)
return render_template("index.html", title='Profile', primarygroup=pgroup_name)

Expand Down
4 changes: 2 additions & 2 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ <h2>Hello, {{ current_user.username }}!</h2>
<td class="text-primary">{{ current_user.mail }}</td>
</tr>
<tr>
<th scope="row">UnixID</th>
<td class="text-danger">{{ current_user.unixid }}</td>
<th scope="row">UIDNumber</th>
<td class="text-danger">{{ current_user.uidnumber }}</td>
</tr>
<tr>
<th scope="row">Groups</th>
Expand Down
18 changes: 9 additions & 9 deletions migrations/versions/ea1b74e55123_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def upgrade():
op.create_table('group',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=20), nullable=False),
sa.Column('unixid', sa.Integer(), nullable=False),
sa.Column('gidnumber', sa.Integer(), nullable=False),
sa.Column('primary', sa.Boolean(), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('unixid')
sa.UniqueConstraint('gidnumber')
)
op.create_index(op.f('ix_group_name'), 'group', ['name'], unique=True)
op.create_table('settings',
Expand All @@ -43,30 +43,30 @@ def upgrade():
op.create_table('included_groups',
sa.Column('include_id', sa.Integer(), nullable=True),
sa.Column('included_in_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['include_id'], ['group.unixid'], ),
sa.ForeignKeyConstraint(['included_in_id'], ['group.unixid'], )
sa.ForeignKeyConstraint(['include_id'], ['group.gidnumber'], ),
sa.ForeignKeyConstraint(['included_in_id'], ['group.gidnumber'], )
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=20), nullable=False),
sa.Column('mail', sa.String(length=50), nullable=True),
sa.Column('givenname', sa.String(length=40), nullable=True),
sa.Column('surname', sa.String(length=40), nullable=True),
sa.Column('unixid', sa.Integer(), nullable=False),
sa.Column('uidnumber', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('password_hash', sa.String(length=64), nullable=False),
sa.Column('primarygroup', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['primarygroup'], ['group.unixid'], ),
sa.ForeignKeyConstraint(['primarygroup'], ['group.gidnumber'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('unixid')
sa.UniqueConstraint('uidnumber')
)
op.create_index(op.f('ix_user_mail'), 'user', ['mail'], unique=True)
op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True)
op.create_table('othergroups_users',
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['group.unixid'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.unixid'], )
sa.ForeignKeyConstraint(['group_id'], ['group.gidnumber'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.gidnumber'], )
)
# ### end Alembic commands ###

Expand Down