Beispiel #1
0
 def serve(self):
     logging.disable(logging.INFO)
     
     key = Key.get(self.args.key_id)
     member = key.getMember()
     
     if not os.environ.get("SSH_ORIGINAL_COMMAND"):
         print "Hi %s!" % member.username
         print "You've successfully authenticated, but %s does not provide shell access." % Config.get("phoenix", "app_name", "Phoenix")
         print "Use the following command to clone a repository:"
         print "    > git clone git@%s:%s/repository.git" % (gethostname(), member.username)
         return False
     else:
         (command, fullpath) = os.environ.get("SSH_ORIGINAL_COMMAND").replace("'", "").split()
         if not Validate.gitcommand(command):
             raise Exception(command)
             print "Hi %s!" % member.username
             print "You've successfully authenticated, but %s does not provide shell access." % Config.get("phoenix", "app_name", "Phoenix")
             print "Use the following command to clone a repository:"
             print "    > git clone git@%s:%s/repository.git" % (gethostname(), member.username)
             return False
     (username, repopath) = fullpath.split("/")
     try:
         owner = Member.selectBy(username=username)[0]
         repo = Repository.selectBy(member=owner, path=repopath)[0]
     except IndexError:
         logging.error("Repository `%s' not found but requested ..." % fullpath)
         raise ClientException("You are not allowed in this repository!")
     if repo.hasAccess(member, "master", "", "U" if command == "git-receive-pack" else "R"):
         __import__("os").execvp("git", ["git", "shell", "-c", "%s '%s'" % (command, repo.getFullpath())])
     else:
         logging.error("User `%s' tried to access repository `%s' ..." % (member.id, repo.id))
         raise ClientException("You are not allowed in this repository!")
Beispiel #2
0
 def runhook(self):   
     logging.disable(logging.INFO)     
     logging.info("Defining hook, repo and arguments ...")
     repo = Repository.get(self.args.repository_id)
     arguments = " " + self.args.arguments if self.args.arguments else ""
     
     logging.info("Looking up all hooks for repository `%s' and hook `%s' ..." % (repo.id, self.args.hook))
     for hook in repo.getHooksByName(self.args.hook):
         logging.info("Running command `%s' ..." % hook.command + arguments)
         Popen(split(str(hook.command + arguments)))
Beispiel #3
0
    def runhook(self):
        logging.disable(logging.INFO)
        logging.info("Defining hook, repo and arguments ...")
        repo = Repository.get(self.args.repository_id)
        arguments = " " + self.args.arguments if self.args.arguments else ""

        logging.info(
            "Looking up all hooks for repository `%s' and hook `%s' ..." %
            (repo.id, self.args.hook))
        for hook in repo.getHooksByName(self.args.hook):
            logging.info("Running command `%s' ..." % hook.command + arguments)
            Popen(split(str(hook.command + arguments)))
Beispiel #4
0
    def serve(self):
        logging.disable(logging.INFO)

        key = Key.get(self.args.key_id)
        member = key.getMember()

        if not os.environ.get("SSH_ORIGINAL_COMMAND"):
            print "Hi %s!" % member.username
            print "You've successfully authenticated, but %s does not provide shell access." % Config.get(
                "phoenix", "app_name", "Phoenix")
            print "Use the following command to clone a repository:"
            print "    > git clone git@%s:%s/repository.git" % (
                gethostname(), member.username)
            return False
        else:
            (command,
             fullpath) = os.environ.get("SSH_ORIGINAL_COMMAND").replace(
                 "'", "").split()
            if not Validate.gitcommand(command):
                raise Exception(command)
                print "Hi %s!" % member.username
                print "You've successfully authenticated, but %s does not provide shell access." % Config.get(
                    "phoenix", "app_name", "Phoenix")
                print "Use the following command to clone a repository:"
                print "    > git clone git@%s:%s/repository.git" % (
                    gethostname(), member.username)
                return False
        (username, repopath) = fullpath.split("/")
        try:
            owner = Member.selectBy(username=username)[0]
            repo = Repository.selectBy(member=owner, path=repopath)[0]
        except IndexError:
            logging.error("Repository `%s' not found but requested ..." %
                          fullpath)
            raise ClientException("You are not allowed in this repository!")
        if repo.hasAccess(member, "master", "",
                          "U" if command == "git-receive-pack" else "R"):
            __import__("os").execvp("git", [
                "git", "shell", "-c",
                "%s '%s'" % (command, repo.getFullpath())
            ])
        else:
            logging.error("User `%s' tried to access repository `%s' ..." %
                          (member.id, repo.id))
            raise ClientException("You are not allowed in this repository!")