Exemplo n.º 1
0
def rest_repository(request):
    # Add new repository
    if request.method == 'POST':
        name = request.POST['name']
        try:
            # check the repo name
            matcher = re.compile("^\w{1,}$")
            if matcher.match(name) is None:
                raise Exception(
                    "Please enter an alphanumeric name without spaces")
            if (name == ""):
                raise Exception("Please enter a non empty name")
            # create the repo
            repository = Repository(name)
            repository.create()
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
        except Exception as e:
            return HttpResponseServerError(e)

        return HttpResponse("The repository has been successfully created")
    # List retrieve_all repositories
    if request.method == 'GET':
        try:
            # change to the repository directory
            repositories = Repository.retrieve_all()
            # remove the .git at the end

            json_reply = jsonpickle.encode(repositories, unpicklable=False)

            return HttpResponse(json_reply)
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
Exemplo n.º 2
0
def rest_repository(request):
    # Add new repository
    if request.method == 'POST':
        name=request.POST['name']
        try:
            # check the repo name
            matcher = re.compile("^[A-Za-z]\w{2,}$")
            if matcher.match(name) is None:
                raise Exception("Please enter an alphanumeric name without spaces")
            if(name == ""):
                raise Exception("Please enter a non empty name")
            # create the repo
            repository = Repository(name)
            repository.create()
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
        except Exception as e:
            return HttpResponseServerError(e)
        
        return HttpResponse("The repository has been successfully created")
    # List retrieve_all repositories
    if request.method == 'GET':
        try:
            # change to the repository directory
            repositories = Repository.retrieve_all()
            # remove the .git at the end
            
            json_reply = jsonpickle.encode(repositories, unpicklable = False)
            return HttpResponse(json_reply)
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
Exemplo n.º 3
0
    def upgrade(self):
        from gitstack.models import Repository

        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        previous_version = config.get('versionning', 'version')
        
        if previous_version == "1.5":
            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            
            # save the settings
            config.set('versionning', 'version', '2.0')
            
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
        
        if previous_version == "1.4":
            # write a config file with the version number 
            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            
            # save the settings
            config.set('versionning', 'version', '1.5')
            
            # add the protocol section
            config.add_section('protocols')   
            config.set('protocols', 'http', 'true')
            config.set('protocols', 'https', 'false')
            config.set('protocols', 'httpport', '80')
            config.set('protocols', 'httpsport', '443')
            
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
            
                
            # create a group file if it does not exist
            if not os.path.isfile(settings.GROUP_FILE_PATH):
                # create an empty group file
                group_file = open(settings.GROUP_FILE_PATH, 'w')
                group_file.write('')
                group_file.close()   
                
            # copy the self signed certificates
            self.copy_certificates()
            
            # write a config for each repo
            repo_list = Repository.retrieve_all()
            for repo in repo_list:
                repo.load()
                repo.save()
                
            # upgrade now to 2.0
            self.upgrade()
Exemplo n.º 4
0
def rest_settings_authentication(request):
    # Get the settings
    if request.method == 'GET':
        # load the settings file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        
        # retrieve the settings
        ldap_helper = LdapHelper()     
        
        # build json reply
        # if the ldap password has a value
        if ldap_helper.bind_password != '':
            # write "saved" instead of the password
            displayed_bind_password = "******"
        
        json_reply = '{"authMethod":"' + ldap_helper.auth_method + '","ldap":{"protocol": "' + ldap_helper.protocol +'","host": "' + ldap_helper.host +'","port": "' + ldap_helper.port +'","baseDn": "' + ldap_helper.base_dn +'","attribute": "' + ldap_helper.attribute +'","scope": "' + ldap_helper.scope +'","filter": "' + ldap_helper.filter +'","bindDn": "' + ldap_helper.bind_dn +'","bindPassword": "******"}}'
        # json_reply = '{"authMethod":"' + auth_method + '","ldap":{"host": "' + ldap_host +'","baseDn": "' + ldap_base_dn +'","bindDn": "' + ldap_bind_dn +'","bindPassword": "******"}}'
        # json_reply = '{"authMethod":"ldap","ldap":{"url": "ldap://10.0.1.24:389/","baseDn": "CN=Users,DC=contoso,DC=com","bindDn": "CN=john,CN=Users,DC=contoso,DC=com","bindPassword": "******"}}'
        return HttpResponse(json_reply)
    # Set the settings
    if request.method == 'PUT':
        auth_settings = json.loads(request.raw_post_data)
        
        # load the config file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        
        # save the settings
        # retrieve the settings
        ldap_helper = LdapHelper()  
        ldap_helper.auth_method = auth_settings['authMethod']
        ldap_helper.protocol = auth_settings['ldap']['protocol']
        ldap_helper.host = auth_settings['ldap']['host']
        ldap_helper.port = auth_settings['ldap']['port']
        ldap_helper.base_dn = auth_settings['ldap']['baseDn']
        ldap_helper.attribute = auth_settings['ldap']['attribute']
        ldap_helper.scope = auth_settings['ldap']['scope']
        ldap_helper.filter = auth_settings['ldap']['filter']
        ldap_helper.bind_dn = auth_settings['ldap']['bindDn']
        if auth_settings['ldap']['bindPassword'] != "saved":
            ldap_helper.bind_password = auth_settings['ldap']['bindPassword']
        
        ldap_helper.save()
        
        # Load and save all the repositories to update the ldap config
        repositories = Repository.retrieve_all()
        for repository in repositories:
            repository.load()
            repository.save()
        
        
        return HttpResponse("Settings successfully saved.")
Exemplo n.º 5
0
def rest_settings_authentication(request):
    # Get the settings
    if request.method == 'GET':
        # load the settings file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)

        # retrieve the settings
        ldap_helper = LdapHelper()

        # build json reply
        # if the ldap password has a value
        if ldap_helper.bind_password != '':
            # write "saved" instead of the password
            displayed_bind_password = "******"

        json_reply = '{"authMethod":"' + ldap_helper.auth_method + '","ldap":{"protocol": "' + ldap_helper.protocol + '","host": "' + ldap_helper.host + '","port": "' + ldap_helper.port + '","baseDn": "' + ldap_helper.base_dn + '","attribute": "' + ldap_helper.attribute + '","scope": "' + ldap_helper.scope + '","filter": "' + ldap_helper.filter + '","bindDn": "' + ldap_helper.bind_dn + '","bindPassword": "******"}}'
        # json_reply = '{"authMethod":"' + auth_method + '","ldap":{"host": "' + ldap_host +'","baseDn": "' + ldap_base_dn +'","bindDn": "' + ldap_bind_dn +'","bindPassword": "******"}}'
        # json_reply = '{"authMethod":"ldap","ldap":{"url": "ldap://10.0.1.24:389/","baseDn": "CN=Users,DC=contoso,DC=com","bindDn": "CN=john,CN=Users,DC=contoso,DC=com","bindPassword": "******"}}'
        return HttpResponse(json_reply)
    # Set the settings
    if request.method == 'PUT':
        auth_settings = json.loads(request.raw_post_data)

        # load the config file
        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)

        # save the settings
        # retrieve the settings
        ldap_helper = LdapHelper()
        ldap_helper.auth_method = auth_settings['authMethod']
        ldap_helper.protocol = auth_settings['ldap']['protocol']
        ldap_helper.host = auth_settings['ldap']['host']
        ldap_helper.port = auth_settings['ldap']['port']
        ldap_helper.base_dn = auth_settings['ldap']['baseDn']
        ldap_helper.attribute = auth_settings['ldap']['attribute']
        ldap_helper.scope = auth_settings['ldap']['scope']
        ldap_helper.filter = auth_settings['ldap']['filter']
        ldap_helper.bind_dn = auth_settings['ldap']['bindDn']
        if auth_settings['ldap']['bindPassword'] != "saved":
            ldap_helper.bind_password = auth_settings['ldap']['bindPassword']

        ldap_helper.save()

        # Load and save all the repositories to update the ldap config
        repositories = Repository.retrieve_all()
        for repository in repositories:
            repository.load()
            repository.save()

        return HttpResponse("Settings successfully saved.")
Exemplo n.º 6
0
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        os.remove(settings.INSTALL_DIR + '/data/passwdfile')
          
        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()
            
        # remove the settings.ini file from the filesystem
        os.remove(settings.SETTINGS_PATH)
Exemplo n.º 7
0
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        os.remove(settings.INSTALL_DIR + '/data/passwdfile')

        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()

        # remove the settings.ini file from the filesystem
        os.remove(settings.SETTINGS_PATH)
Exemplo n.º 8
0
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        users = UserApache.retrieve_all()
        for user in users:
            # delete the user
            if user.username != 'everyone':
                user.delete()
                time.sleep(0.1)
            
        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()
Exemplo n.º 9
0
    def upgrade(self):
        from gitstack.models import Repository

        config = ConfigParser.ConfigParser()
        config.read(settings.SETTINGS_PATH)
        previous_version = config.get('versionning', 'version')
        
        if previous_version == "2.2":
            # upgrade to 2.3
            open(settings.INSTALL_DIR + '/data/core', 'w').close()
            
            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            config.set('versionning', 'version', '2.3')
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
            
        if previous_version == "2.1":
            # upgrade to 2.2
            open(settings.INSTALL_DIR + '/data/core', 'w').close()
            
            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            config.set('versionning', 'version', '2.2')
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()

        if previous_version == "2.0":
            # upgrade to 2.1

            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            
            # create the section location and add a default location
            config.add_section('location')
            config.set('location', 'repositories', settings.INSTALL_DIR + '/repositories')
            config.set('versionning', 'version', '2.1')
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
            
        
        if previous_version == "1.5":
            # upgrade to 2.0

            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            
            # save the settings
            config.set('versionning', 'version', '2.0')
            
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
            # upgrade to 2.1
            self.upgrade()
        
        if previous_version == "1.4":
            # upgrade to 1.5
            
            # write a config file with the version number 
            # load the config file
            config = ConfigParser.ConfigParser()
            config.read(settings.SETTINGS_PATH)
            
            # save the settings
            config.set('versionning', 'version', '1.5')
            
            # add the protocol section
            config.add_section('protocols')   
            config.set('protocols', 'http', 'true')
            config.set('protocols', 'https', 'false')
            config.set('protocols', 'httpport', '80')
            config.set('protocols', 'httpsport', '443')
            
            f = open(settings.SETTINGS_PATH, "w")
            config.write(f)
            f.close()
            
                
            # create a group file if it does not exist
            if not os.path.isfile(settings.GROUP_FILE_PATH):
                # create an empty group file
                group_file = open(settings.GROUP_FILE_PATH, 'w')
                group_file.write('')
                group_file.close()   
                
            # copy the self signed certificates
            self.copy_certificates()
            
            # write a config for each repo
            repo_list = Repository.retrieve_all()
            for repo in repo_list:
                repo.load()
                repo.save()
                
            # upgrade now to 2.0
            self.upgrade()