@@ -0,0 +1,1655 @@
+#!/usr/bin/python3%0Aimport json%0Aimport logger%0Aimport os.path%0A%0A%0Adef save_to_file(data):%0A    f = open('users.json', 'w')%0A    json.dump(data, f)%0A    f.close()%0A%0A%0Adef register_user(username):%0A    global data%0A    data%5Busername%5D = %7B'admin': False, 'groups': %5B%5D%7D%0A%0A%0Adef is_user_admin(username):%0A    global data%0A    return username in data and data%5Busername%5D%5B'admin'%5D%0A%0A%0Adef set_user_admin(username, admin_flag):%0A    global data%0A    if username not in data:%0A        register_user(username)%0A    data%5Busername%5D%5B'admin'%5D = admin_flag%0A    save_to_file(data)%0A%0A%0Adef is_user_in_group(username, group):%0A    global data%0A    return username in data and group in data%5Busername%5D%5B'groups'%5D%0A%0A%0Adef add_user_to_group(username, group):%0A    global data%0A    if is_user_in_group(username, group):%0A        return%0A    data%5Busername%5D%5B'groups'%5D.append(group)%0A    save_to_file(data)%0A%0A%0Adef delete_user_from_group(username, group):%0A    global data%0A    if not is_user_in_group(username, group):%0A        return%0A    data%5Busername%5D%5B'groups'%5D.remove(group)%0A    save_to_file(data)%0A%0A%0Atry:%0A    data = json.load(open('users.json', 'r'))%0A    if type(data) != dict:%0A        raise ValueError%0A    else:%0A        for u in data%5B'users'%5D.values():%0A            if 'admin' not in u or type(u%5B'admin'%5D) != bool or 'groups' not in u or type(u%5B'groups'%5D) != list:%0A                raise ValueError%0Aexcept FileNotFoundError:%0A    logger.info('File with users not found and will be created')%0A    data = %7B'users': %7B%7D%7D%0Aexcept ValueError:%0A    logger.warning('Invalid users file, creating new')%0A    data = %7B'users': %7B%7D%7D%0Aexcept:%0A    logger.warning('Some error occured with users file, creating new')%0A    data = %7B'users': %7B%7D%7D%0A

Test version of users.py (TODO: add lock)