コード例 #1
0
ファイル: tasks.py プロジェクト: 0x414A/toyz
def save_workspace(toyz_settings, tid, params):
    """
    Save a workspace for later use
    """
    core.check4keys(params, ['workspaces', 'overwrite'])
    workspaces = db_utils.get_param(toyz_settings.db, 'workspaces', user_id=tid['user_id'])
    work_id = params['workspaces'].keys()[0]
    if work_id in workspaces and params['overwrite'] is False:
        response = {
            'id': 'verify',
            'func': 'save_workspace'
        }
    else:
        user_id = tid['user_id']
        if 'user_id' in params and params['user_id']!=tid['user_id']:
            params['work_id'] = work_id
            permissions = core.get_workspace_permissions(toyz_settings, tid, params)
            if permissions['modify']:
                user_id = params['user_id']
            else:
                raise ToyzJobError(
                    "You do not have permission to save {0}".format(params['work_id']))
            
        db_utils.update_param(toyz_settings.db, 'workspaces', 
            workspaces=params['workspaces'], user_id=user_id)
        response = {
            'id': 'notification',
            'msg': 'Workspace saved successfully',
            'func': 'save_workspace'
        }
    
    return response
コード例 #2
0
ファイル: tasks.py プロジェクト: fred3m/toyz
def save_workspace(toyz_settings, tid, params):
    """
    Save a workspace for later use
    """
    core.check4keys(params, ['workspaces', 'overwrite'])
    workspaces = db_utils.get_param(toyz_settings.db,
                                    'workspaces',
                                    user_id=tid['user_id'])
    work_id = params['workspaces'].keys()[0]
    if work_id in workspaces and params['overwrite'] is False:
        response = {'id': 'verify', 'func': 'save_workspace'}
    else:
        user_id = tid['user_id']
        if 'user_id' in params and params['user_id'] != tid['user_id']:
            params['work_id'] = work_id
            permissions = core.get_workspace_permissions(
                toyz_settings, tid, params)
            if permissions['modify']:
                user_id = params['user_id']
            else:
                raise ToyzJobError(
                    "You do not have permission to save {0}".format(
                        params['work_id']))

        db_utils.update_param(toyz_settings.db,
                              'workspaces',
                              workspaces=params['workspaces'],
                              user_id=user_id)
        response = {
            'id': 'notification',
            'msg': 'Workspace saved successfully',
            'func': 'save_workspace'
        }

    return response
コード例 #3
0
ファイル: core.py プロジェクト: fred3m/toyz
    def first_time_setup(self, config_root_path):
        """
        Initial setup of the Toyz application and creation of files the first time it's run.
    
        Parameters
            - config_root_path (*string* ): Default root path of the new Toyz instance
        """
        from toyz.utils import file_access
        from toyz.utils import third_party

        # Set default settings
        default_settings['web']['third_party'] = third_party.get_defaults()
        for key, val in default_settings.items():
            setattr(self, key, ToyzClass(val))

        # Create config directory if it does not exist
        print("\nToyz: First Time Setup\n----------------------\n")
        self.config.root_path = normalize_path(os.getcwd())
        while not get_bool("Create new Toyz configuration in '{0}'? ".format(
                self.config.root_path)):
            self.config.root_path = normalize_path(raw_input("new path: "))
        self.config.path = os.path.join(self.config.root_path,
                                        self.config.config_path)
        create_paths([
            self.config.root_path,
            os.path.join(self.config.root_path, 'config')
        ])

        # Create database for toyz settings and permissions
        self.db.path = os.path.join(self.config.root_path, self.db.db_path)
        create_paths(os.path.dirname(self.db.path))
        db_utils.create_toyz_database(self.db)

        # Create default users and groups
        admin_pwd = 'admin'
        if self.security.user_login:
            admin_pwd = encrypt_pwd(self, admin_pwd)
        db_utils.update_param(self.db, 'pwd', user_id='admin', pwd=admin_pwd)
        db_utils.update_param(self.db, 'pwd', group_id='all', pwd='')
        db_utils.update_param(self.db, 'pwd', group_id='admin', pwd='')
        db_utils.update_param(self.db, 'pwd', group_id='modify_toyz', pwd='')
        db_utils.update_param(self.db,
                              'paths',
                              group_id='all',
                              paths={
                                  os.path.join(ROOT_DIR, 'web', 'static'):
                                  'fr',
                                  os.path.join(ROOT_DIR, 'web', 'templates'):
                                  'fr',
                                  os.path.join(ROOT_DIR, 'third_party'): 'fr',
                              })

        self.save_settings()
        print("\nFirst Time Setup completed")
コード例 #4
0
ファイル: core.py プロジェクト: 0x414A/toyz
 def first_time_setup(self, config_root_path):
     """
     Initial setup of the Toyz application and creation of files the first time it's run.
 
     Parameters
         - config_root_path (*string* ): Default root path of the new Toyz instance
     """
     from toyz.utils import file_access
     from toyz.utils import third_party
     
     # Set default settings
     default_settings['web']['third_party'] = third_party.get_defaults()
     for key, val in default_settings.items():
         setattr(self, key, ToyzClass(val))
 
     # Create config directory if it does not exist
     print("\nToyz: First Time Setup\n----------------------\n")
     self.config.root_path = normalize_path(os.getcwd())
     while not get_bool(
             "Create new Toyz configuration in '{0}'? ".format(self.config.root_path)):
         self.config.root_path = normalize_path(raw_input("new path: "))
     self.config.path = os.path.join(
         self.config.root_path,
         self.config.config_path
     )
     create_paths([self.config.root_path, os.path.join(self.config.root_path, 'config')])
     
     # Create database for toyz settings and permissions
     self.db.path = os.path.join(self.config.root_path, 
                                         self.db.db_path)
     create_paths(os.path.dirname(self.db.path))
     db_utils.create_toyz_database(self.db)
     
     # Create default users and groups
     admin_pwd = 'admin'
     if self.security.user_login:
         admin_pwd = encrypt_pwd(self, admin_pwd)
     db_utils.update_param(self.db, 'pwd', user_id='admin', pwd=admin_pwd)
     db_utils.update_param(self.db, 'pwd', group_id='all', pwd='')
     db_utils.update_param(self.db, 'pwd', group_id='admin', pwd='')
     db_utils.update_param(self.db, 'pwd', group_id='modify_toyz', pwd='')
     db_utils.update_param(self.db, 'paths', group_id='all', paths={
         os.path.join(ROOT_DIR, 'web','static'): 'fr',
         os.path.join(ROOT_DIR, 'web','templates'): 'fr',
         os.path.join(ROOT_DIR, 'third_party'): 'fr',
     })
     
     self.save_settings()
     print("\nFirst Time Setup completed")
コード例 #5
0
ファイル: tasks.py プロジェクト: fred3m/toyz
def change_pwd(toyz_settings, tid, params):
    """
    Change a users password.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - current_pwd (*string* ):  Users current password. Must match the password on 
          file or an exception is raised
        - new_pwd (*string* ): New password
        - confirm_pwd (*string* ): Confirmation of the the new password. If new_pwd and 
          confirm_pwd do not match, an exception is raised
    
    Response
        - id: 'notification'
        - func: 'change_pwd'
        - msg: 'Password changed successfully'
    """
    core.check4keys(params, ['current_pwd', 'new_pwd', 'confirm_pwd'])
    if core.check_pwd(toyz_settings, tid['user_id'], params['current_pwd']):
        if params['new_pwd'] == params['confirm_pwd']:
            pwd_hash = core.encrypt_pwd(toyz_settings, params['new_pwd'])
        else:
            raise ToyzJobError("New passwords did not match")
    else:
        raise ToyzJobError("Invalid user_id or password")

    db_utils.update_param(toyz_settings.db,
                          'pwd',
                          user_id=tid['user_id'],
                          pwd=pwd_hash)

    response = {
        'id': 'notification',
        'func': 'change_pwd',
        'msg': 'Password changed successfully',
    }
    return response
コード例 #6
0
ファイル: tasks.py プロジェクト: 0x414A/toyz
def reset_pwd(toyz_settings, tid, params):
    """
    Reset a users password
    """
    user = core.get_user_type(params)
    if 'user_id' in params:
        user_id = params['user_id']
    elif 'group_id' in params:
        user_id = group_id
    else:
        raise ToyzJobError("Must specify a user_id or group_id to reset password")
    pwd_hash = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd_hash, **user)
    
    response = {
        'id': 'notification',
        'func': 'reset_pwd',
        'msg': 'Password reset successfully',
    }
    return response
コード例 #7
0
ファイル: tasks.py プロジェクト: fred3m/toyz
def reset_pwd(toyz_settings, tid, params):
    """
    Reset a users password
    """
    user = core.get_user_type(params)
    if 'user_id' in params:
        user_id = params['user_id']
    elif 'group_id' in params:
        user_id = group_id
    else:
        raise ToyzJobError(
            "Must specify a user_id or group_id to reset password")
    pwd_hash = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd_hash, **user)

    response = {
        'id': 'notification',
        'func': 'reset_pwd',
        'msg': 'Password reset successfully',
    }
    return response
コード例 #8
0
ファイル: tasks.py プロジェクト: 0x414A/toyz
def change_pwd(toyz_settings, tid, params):
    """
    Change a users password.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - current_pwd (*string* ):  Users current password. Must match the password on 
          file or an exception is raised
        - new_pwd (*string* ): New password
        - confirm_pwd (*string* ): Confirmation of the the new password. If new_pwd and 
          confirm_pwd do not match, an exception is raised
    
    Response
        - id: 'notification'
        - func: 'change_pwd'
        - msg: 'Password changed successfully'
    """
    core.check4keys(params, ['current_pwd', 'new_pwd', 'confirm_pwd'])
    if core.check_pwd(toyz_settings, tid['user_id'], params['current_pwd']):
        if params['new_pwd'] == params['confirm_pwd']:
            pwd_hash = core.encrypt_pwd(toyz_settings, params['new_pwd'])
        else:
            raise ToyzJobError("New passwords did not match")
    else:
        raise ToyzJobError("Invalid user_id or password")
    
    db_utils.update_param(toyz_settings.db, 'pwd', user_id=tid['user_id'], pwd=pwd_hash)
    
    response = {
        'id': 'notification',
        'func': 'change_pwd',
        'msg': 'Password changed successfully',
    }
    return response
コード例 #9
0
ファイル: core.py プロジェクト: fred3m/toyz
def check_user_shortcuts(toyz_settings, user_id, shortcuts=None):
    """
    Check that a user has all of the default shortcuts.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings` ): Toyz Settings
        - user_id (*string* ): User id to check for shortcuts
        - shortcuts (*dict*, optional): Dictionary of shortcuts for a user. Shortcuts
          are always of the form ``shortcut_name:path`` .
    
    Returns
        - shortcuts: dictionary of shortcuts for the user
    """
    modified = False
    if shortcuts == None:
        shortcuts = db_utils.get_param(toyz_settings.db,
                                       'shortcuts',
                                       user_id=user_id)
    if 'user' not in shortcuts:
        shortcuts['user'] = os.path.join(toyz_settings.config.root_path,
                                         'users', user_id)
        db_utils.update_param(toyz_settings.db,
                              'shortcuts',
                              user_id=user_id,
                              shortcuts={'user': shortcuts['user']})
        create_paths([shortcuts['user']])
        modified = True
    if 'temp' not in shortcuts:
        shortcuts['temp'] = os.path.join(shortcuts['user'], 'temp')
        db_utils.update_param(toyz_settings.db,
                              'shortcuts',
                              user_id=user_id,
                              shortcuts={'temp': shortcuts['temp']})
        create_paths([shortcuts['temp']])
        modified = True
    if modified:
        db_utils.update_param(toyz_settings.db,
                              'shortcuts',
                              user_id=user_id,
                              shortcuts=shortcuts)
        paths = db_utils.get_param(toyz_settings.db, 'paths', user_id=user_id)
        # Ensure that the user has full access to his/her home directory
        if shortcuts['user'] not in paths or paths[
                shortcuts['user']] != 'frwx':
            db_utils.update_param(toyz_settings.db,
                                  'paths',
                                  user_id=user_id,
                                  paths={shortcuts['user']: '******'})
    return shortcuts
コード例 #10
0
ファイル: tasks.py プロジェクト: 0x414A/toyz
def add_new_user(toyz_settings, tid, params):
    """
    Add a new user to the toyz application.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id (*string* ): Id of user to add
    
    Response
        - id: 'notification'
        - func: 'add_new_user'
        - msg: 'User/Group added correctly'
    """
    user = core.get_user_type(params)
    user_id = six.next(six.itervalues(user))
    pwd = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd, **user)
    if 'user_id' in user:
        # set permissions and shortcuts for users home path
        core.check_user_shortcuts(toyz_settings, **user)
        # Add user to all users
        db_utils.update_param(toyz_settings.db, 'users', group_id='all', users=[user['user_id']])
        msg = 'User added correctly'
    else:
        msg = 'Group added correctly'
    
    response = {
        'id': 'notification',
        'func': 'add_new_user',
        'msg': msg
    }
    return response
コード例 #11
0
ファイル: tasks.py プロジェクト: fred3m/toyz
def add_new_user(toyz_settings, tid, params):
    """
    Add a new user to the toyz application.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id (*string* ): Id of user to add
    
    Response
        - id: 'notification'
        - func: 'add_new_user'
        - msg: 'User/Group added correctly'
    """
    user = core.get_user_type(params)
    user_id = six.next(six.itervalues(user))
    pwd = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd, **user)
    if 'user_id' in user:
        # set permissions and shortcuts for users home path
        core.check_user_shortcuts(toyz_settings, **user)
        # Add user to all users
        db_utils.update_param(toyz_settings.db,
                              'users',
                              group_id='all',
                              users=[user['user_id']])
        msg = 'User added correctly'
    else:
        msg = 'Group added correctly'

    response = {'id': 'notification', 'func': 'add_new_user', 'msg': msg}
    return response
コード例 #12
0
ファイル: core.py プロジェクト: 0x414A/toyz
def check_user_shortcuts(toyz_settings, user_id, shortcuts=None):
    """
    Check that a user has all of the default shortcuts.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings` ): Toyz Settings
        - user_id (*string* ): User id to check for shortcuts
        - shortcuts (*dict*, optional): Dictionary of shortcuts for a user. Shortcuts
          are always of the form ``shortcut_name:path`` .
    
    Returns
        - shortcuts: dictionary of shortcuts for the user
    """
    modified = False
    if shortcuts==None:
        shortcuts = db_utils.get_param(toyz_settings.db, 'shortcuts', user_id=user_id)
    if 'user' not in shortcuts:
        shortcuts['user'] = os.path.join(toyz_settings.config.root_path, 'users', user_id)
        db_utils.update_param(toyz_settings.db, 'shortcuts', user_id=user_id, 
            shortcuts={'user': shortcuts['user']})
        create_paths([shortcuts['user']])
        modified = True
    if 'temp' not in shortcuts:
        shortcuts['temp'] = os.path.join(shortcuts['user'], 'temp')
        db_utils.update_param(toyz_settings.db, 'shortcuts', user_id=user_id, 
            shortcuts={'temp': shortcuts['temp']})
        create_paths([shortcuts['temp']])
        modified = True
    if modified:
        db_utils.update_param(toyz_settings.db, 'shortcuts', user_id=user_id, 
            shortcuts=shortcuts)
        paths = db_utils.get_param(toyz_settings.db, 'paths', user_id=user_id)
        # Ensure that the user has full access to his/her home directory
        if shortcuts['user'] not in paths or paths[shortcuts['user']] !='frwx':
            db_utils.update_param(toyz_settings.db, 'paths', user_id=user_id, 
                paths={shortcuts['user']: '******'})
    return shortcuts