Ejemplo n.º 1
0
    def instantiate_user(username, password=""):
        # check the current authentication method
        # make sure that the config file exist
        if not os.path.exists(settings.SETTINGS_PATH):
            # create the file 
            ldap_helper = LdapHelper()
            # do something useless to remove the eclipse warning
            ldap_helper.get_url()
 
        # load the settings file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        
        # retrieve the settings
        auth_method = config.get('authentication', 'authmethod')
        if auth_method == 'ldap':
            return UserLdap(username)
        else:
            return UserApache(username, password)
Ejemplo n.º 2
0
    def instantiate_user(username, password=""):
        # check the current authentication method
        # make sure that the config file exist
        if not os.path.exists(settings.SETTINGS_PATH):
            # create the file 
            ldap_helper = LdapHelper()
            # do something useless to remove the eclipse warning
            ldap_helper.get_url()
 
        # load the settings file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        
        # retrieve the settings
        auth_method = config.get('authentication', 'authmethod')
        if auth_method == 'ldap':
            return UserLdap(username)
        else:
            return UserApache(username, password)
Ejemplo n.º 3
0
    def save(self):
        # add info to the file
        config_file_path = settings.INSTALL_DIR + '/apache/conf/gitstack/repositories/' + self.name + ".conf"
        # remove the old configuration file
        if os.path.isfile(config_file_path):
            os.remove(config_file_path)
        
        repo_config = open(config_file_path,"a")
        
        # check the current authentication method 
        # load the settings file
        config = ConfigParser.ConfigParser()
        # make sure that the config file exist
        if not os.path.exists(settings.SETTINGS_PATH):
            # create the file 
            ldap_helper = LdapHelper()
 
        config.read(settings.SETTINGS_PATH)
        everyone = UserFactory.instantiate_user("everyone")

        # retrieve the settings
        auth_method = config.get('authentication', 'authmethod')
        # file based authentification method
        if auth_method == 'file':
            # choose the correct template
            # check if it is a repository has anonymous read or write
            if everyone in self.user_read_list:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_anonymous_read_file.conf',"r")
            else:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_file.conf',"r")
        # ldap authentification method
        elif auth_method == 'ldap':
            if everyone in self.user_read_list:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_anonymous_read_ldap.conf',"r")
            else:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_ldap.conf',"r")

        # create a list of users & groups
        str_user_read_list = ''
        str_user_write_list = ''
        str_user_list = ''
        str_group_read_list = ''
        str_group_write_list = ''
        str_group_list = ''
        
        # convert objects to list of strings
        for u in self.user_read_list:
            str_user_read_list = str_user_read_list + u.username + ' '
        for u in self.user_write_list:
            str_user_write_list = str_user_write_list + u.username + ' '
        for u in self.user_list:
            str_user_list = str_user_list + u.username + ' '
        for g in self.group_read_list:
            str_group_read_list = str_group_read_list + g.name + ' '
        for g in self.group_write_list:
            str_group_write_list = str_group_write_list + g.name + ' '
        for g in self.group_list:
            str_group_list = str_group_list + g.name + ' '
            
        # get the user everyone
        everyone = UserFactory.instantiate_user("everyone")
            
        # for each line try to replace username or location
        for line in template_repo_config:
            # add the list of users
            # replace username   
            line = line.replace("ALL_USER_LIST",str_user_list)         
            line = line.replace("READ_USER_LIST",str_user_read_list)
            line = line.replace("WRITE_USER_LIST",str_user_write_list)
            
            line = line.replace("READ_USER_PERMISSIONS","Require user " + str_user_read_list)
            line = line.replace("READ_GROUP_PERMISSIONS","Require group " + str_group_read_list)

            line = line.replace("WRITE_USER_PERMISSIONS","Require user " + str_user_write_list)
            line = line.replace("WRITE_GROUP_PERMISSIONS","Require group " + str_group_write_list)
            
            # authentication ldap
            if auth_method == 'ldap':
                line = line.replace("READ_USER_LDAP_PERMISSIONS","Require ldap-user " + str_user_read_list)
                line = line.replace("WRITE_USER_LDAP_PERMISSIONS","Require ldap-user " + str_user_write_list)

                # get ldap parameters 
                ldap_helper = LdapHelper()
                line = line.replace("LDAP_URL",ldap_helper.get_url())
                line = line.replace("LDAP_BIND_DN",ldap_helper.bind_dn)
                line = line.replace("LDAP_BIND_PASSWORD",ldap_helper.bind_password)

            # replace repository name
            line = line.replace("REPO_NAME",self.name)
            #password file path
            line = line.replace("PASSFILE_PATH",settings.INSTALL_DIR + '/data/passwdfile')
            line = line.replace("GROUPFILE_PATH",settings.INSTALL_DIR + '/data/groupfile')
            
            # write the new config file
            repo_config.write(line)
    
        # close the files
        repo_config.close()
        template_repo_config.close()
        
        # save in the repo configuration file
        # if has not gitstack section
        if not self.has_gitstack_section():
            # create one
            self.create_gitstack_section()
            
        config = ConfigParser.ConfigParser()
        config.read(settings.REPOSITORIES_PATH + "/" + self.name + ".git" + "/config")
        
        
        # add a gitstack section
        config.set('gitstack', 'addedusers', str_user_list)
        config.set('gitstack', 'readusers', str_user_read_list)
        config.set('gitstack', 'writeusers', str_user_write_list)
        config.set('gitstack', 'addedgroups', str_group_list)
        config.set('gitstack', 'readgroups', str_group_read_list)
        config.set('gitstack', 'writegroups', str_group_write_list)
        
      
        f = open(settings.REPOSITORIES_PATH + "/" + self.name + ".git" + "/config", "w")
        config.write(f)
        f.close()
        
        # restart apache
        Apache.restart()
Ejemplo n.º 4
0
    def save(self):
        # add info to the file
        config_file_path = settings.INSTALL_DIR + '/apache/conf/gitstack/repositories/' + self.name + ".conf"
        # remove the old configuration file
        if os.path.isfile(config_file_path):
            os.remove(config_file_path)
        
        repo_config = open(config_file_path,"a")
        
        # check the current authentication method 
        # load the settings file
        config = ConfigParser.ConfigParser()
        # make sure that the config file exist
        if not os.path.exists(settings.SETTINGS_PATH):
            # create the file 
            ldap_helper = LdapHelper()
 
        config.read(settings.SETTINGS_PATH)
        everyone = UserFactory.instantiate_user("everyone")

        # retrieve the settings
        auth_method = config.get('authentication', 'authmethod')
        # file based authentification method
        if auth_method == 'file':
            # choose the correct template
            # check if it is a repository has anonymous read or write
            if everyone in self.user_read_list:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_anonymous_read_file.conf',"r")
            else:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_file.conf',"r")
        # ldap authentification method
        elif auth_method == 'ldap':
            if everyone in self.user_read_list:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_anonymous_read_ldap.conf',"r")
            else:
                template_repo_config = open(settings.INSTALL_DIR + '/app/gitstack/config_template/repository_template_ldap.conf',"r")

        # create a list of users & groups
        str_user_read_list = ''
        str_user_write_list = ''
        str_user_list = ''
        str_group_read_list = ''
        str_group_write_list = ''
        str_group_list = ''
        
        # convert objects to list of strings
        for u in self.user_read_list:
            str_user_read_list = str_user_read_list + u.username + ' '
        for u in self.user_write_list:
            str_user_write_list = str_user_write_list + u.username + ' '
        for u in self.user_list:
            str_user_list = str_user_list + u.username + ' '
        for g in self.group_read_list:
            str_group_read_list = str_group_read_list + g.name + ' '
        for g in self.group_write_list:
            str_group_write_list = str_group_write_list + g.name + ' '
        for g in self.group_list:
            str_group_list = str_group_list + g.name + ' '
            
        # get the user everyone
        everyone = UserFactory.instantiate_user("everyone")
            
        # for each line try to replace username or location
        for line in template_repo_config:
            # add the list of users
            # replace username   
            line = line.replace("ALL_USER_LIST",str_user_list)         
            line = line.replace("READ_USER_LIST",str_user_read_list)
            line = line.replace("WRITE_USER_LIST",str_user_write_list)
            
            line = line.replace("READ_USER_PERMISSIONS","Require user " + str_user_read_list)
            line = line.replace("READ_GROUP_PERMISSIONS","Require group " + str_group_read_list)

            line = line.replace("WRITE_USER_PERMISSIONS","Require user " + str_user_write_list)
            line = line.replace("WRITE_GROUP_PERMISSIONS","Require group " + str_group_write_list)
            
            # authentication ldap
            if auth_method == 'ldap':
                line = line.replace("READ_USER_LDAP_PERMISSIONS","Require ldap-user " + str_user_read_list)
                line = line.replace("WRITE_USER_LDAP_PERMISSIONS","Require ldap-user " + str_user_write_list)

                # get ldap parameters 
                ldap_helper = LdapHelper()
                line = line.replace("LDAP_URL",ldap_helper.get_url())
                line = line.replace("LDAP_BIND_DN",ldap_helper.bind_dn)
                line = line.replace("LDAP_BIND_PASSWORD",ldap_helper.bind_password)

            # replace repository name
            line = line.replace("REPO_NAME",self.name)
            #password file path
            line = line.replace("PASSFILE_PATH",settings.INSTALL_DIR + '/data/passwdfile')
            line = line.replace("GROUPFILE_PATH",settings.INSTALL_DIR + '/data/groupfile')
            
            # write the new config file
            repo_config.write(line)
    
        # close the files
        repo_config.close()
        template_repo_config.close()
                
        # save in the repo configuration file
        # if has not gitstack section
        if not self.has_gitstack_section():
            # create one
            self.create_gitstack_section()
            
        config = ConfigParser.ConfigParser()
        config.read(Repository.get_location() + "/" + self.name + ".git" + "/config")
        
        
        # add a gitstack section
        config.set('gitstack', 'addedusers', str_user_list)
        config.set('gitstack', 'readusers', str_user_read_list)
        config.set('gitstack', 'writeusers', str_user_write_list)
        config.set('gitstack', 'addedgroups', str_group_list)
        config.set('gitstack', 'readgroups', str_group_read_list)
        config.set('gitstack', 'writegroups', str_group_write_list)
        
      
        f = open(Repository.get_location() + "/" + self.name + ".git" + "/config", "w")
        config.write(f)
        f.close()
        
        # restart apache
        Apache.restart()