Exemplo n.º 1
0
 def _initHooks(self, fullpath):
     hooks = path.join(Config.get("ABS_PATH"), Config.get("phoenix", "hook_dir"))
     for f in listdir(hooks):
         t = Template(open(path.join(hooks, f), "r").read())
         open(path.join(fullpath, "hooks", f), "w").write(t.substitute(repo=self.id))
         system("chmod +x " + path.join(fullpath, "hooks", f))
         remove(path.join(fullpath, "hooks", f + ".sample"))
Exemplo n.º 2
0
 def _initHooks(self, fullpath):
     hooks = path.join(Config.get("ABS_PATH"),
                       Config.get("phoenix", "hook_dir"))
     for f in listdir(hooks):
         t = Template(open(path.join(hooks, f), "r").read())
         open(path.join(fullpath, "hooks", f),
              "w").write(t.substitute(repo=self.id))
         system("chmod +x " + path.join(fullpath, "hooks", f))
         remove(path.join(fullpath, "hooks", f + ".sample"))
Exemplo n.º 3
0
    def addrepo(self):
        logging.info("Defining username, email and repository name ...")
        username = self.args.username
        email = self.args.email
        name = self.args.repository_name
        path = self.args.repository_path
        
        member = self._getMemberByUsernameOrEmail(username, email, True)
        dummy = self._getRepositoryByNameOrPath(member, name, path)

        logging.info("Changing to the git user ...")
        __import__("os").setgid(__import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_gid)
        __import__("os").setuid(__import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_uid)
        
        logging.info("Creating and saving the new repository ...")
        member.addRepository(name, path)
        
        print "Done."
Exemplo n.º 4
0
    def addrepo(self):
        logging.info("Defining username, email and repository name ...")
        username = self.args.username
        email = self.args.email
        name = self.args.repository_name
        path = self.args.repository_path

        member = self._getMemberByUsernameOrEmail(username, email, True)
        dummy = self._getRepositoryByNameOrPath(member, name, path)

        logging.info("Changing to the git user ...")
        __import__("os").setgid(
            __import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_gid)
        __import__("os").setuid(
            __import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_uid)

        logging.info("Creating and saving the new repository ...")
        member.addRepository(name, path)

        print "Done."
Exemplo n.º 5
0
 def __init__(self):
     from Phoenix.Conf import Config, logging
     
     parser = ArgumentParser()
     self.defineParser(parser)
     self.args = parser.parse_args()
     
     if self.args.action != "init" and Config.get("phoenix", "initialized", False) != "True":
         print "Please initalize `Phoenix' first."
         print "On Ubuntu simply type: "
         print "    > sudo phoenix-admin init"
         print "To find out about all options type:"
         print "    > sudo phoenix-admin init --help"
         exit()
     
     try:
         p = Popen(["git", "--help"], stdout=PIPE)
         if p.wait() != 0:
             raise ConsoleException("Git not installed.")
     except OSError, ConsoleException:
         print "Please install `git' first."
         print "On Ubuntu simply type:"
         print "    > sudo apt-get install git git-core"
         exit()
Exemplo n.º 6
0
 def _createDirectoryStructure(self, repo, tar, ssh):
     if not path.exists(repo):
         logging.info("Creating repository dir at `%s' ..." % repo)
         mkdir(repo)
     else:
         logging.warning("The folder `%s' already exists." % repo)
     Config.set("phoenix", "repository_dir", repo)
     
     if not path.exists(tar):
         logging.info("Creating tarball dir at `%s' ..." % tar)
         mkdir(tar)
     else:
         logging.warning("The folder `%s' already exists." % tar)
     Config.set("phoenix", "tarball_dir", tar)
     
     if not path.exists(ssh):
         logging.info("Creating ssh dir at `%s' ..." % ssh)
         mkdir(ssh, 0700)
     else:
         logging.warning("The folder `%s' already exists." % ssh)
     Config.set("phoenix", "ssh_dir", ssh)
Exemplo n.º 7
0
    def _createDirectoryStructure(self, repo, tar, ssh):
        if not path.exists(repo):
            logging.info("Creating repository dir at `%s' ..." % repo)
            mkdir(repo)
        else:
            logging.warning("The folder `%s' already exists." % repo)
        Config.set("phoenix", "repository_dir", repo)

        if not path.exists(tar):
            logging.info("Creating tarball dir at `%s' ..." % tar)
            mkdir(tar)
        else:
            logging.warning("The folder `%s' already exists." % tar)
        Config.set("phoenix", "tarball_dir", tar)

        if not path.exists(ssh):
            logging.info("Creating ssh dir at `%s' ..." % ssh)
            mkdir(ssh, 0700)
        else:
            logging.warning("The folder `%s' already exists." % ssh)
        Config.set("phoenix", "ssh_dir", ssh)
Exemplo n.º 8
0
 def getFullpath(self, hash=None):
     if not hash and not self.hash: return False
     return path.join(Config.get("phoenix", "repository_dir"), hash
                      or self.hash)
Exemplo n.º 9
0
    def init(self):
        if Config.get("phoenix", "initialized") == "True":
            raise AdminException("Already initialized.")
        
        logging.info("Defining variables for init ...")
        user = self.args.git_user
        base = path.join(self.args.base_dir, user)
        repo = path.join(base, self.args.repository_dir)
        tar = path.join(base, self.args.tarball_dir)
        ssh = path.join(base, ".ssh")
        auth_keys = path.join(ssh, "authorized_keys")
        admin_repo = self.args.admin_repo
        email = self.args.admin_email
        name = self.args.admin_name
        username = self.args.admin_username
        sql = self.args.sql_connect or "sqlite://%s" % path.join(base, "phoenix.db")
                
        logging.info("Checking for permission to write the config file ...")
        if not File.writePermission(Config.get("CONF_FILE")):
            raise AdminException("You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE"))
        
        if not SysUser.exists(self.args.git_user):
            logging.info("Creating user `%s' ... " % user)
            SysUser.create(user, base)
            Config.set("phoenix", "user", user)
            Config.set("phoenix", "base", base)
        else:
            raise AdminException("The user `%s' already exists." % user)
        
        logging.info("Saving SQL connection string `%s' ..." % sql)
        Config.set("phoenix", "sql_connect", sql)
        Config.set("phoenix", "initialized", True)
        Config.set("phoenix", "authorized_keys", auth_keys)
        
        __import__("os").setgid(__import__("pwd").getpwnam(user).pw_gid)
        __import__("os").setuid(__import__("pwd").getpwnam(user).pw_uid)
                
        logging.info("Checking for permission to write the config file as `%s' ..." % user)
        if not File.writePermission(Config.get("CONF_FILE")):
            raise AdminException("You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE"))
        
        
        from sqlobject import connectionForURI, sqlhub
        connection = connectionForURI(Config.get("phoenix", "sql_connect"))
        sqlhub.processConnection = connection
        
        self._sqlChanges()
        self._createDirectoryStructure(repo, tar, ssh)

        logging.info("Creating `%s' ..." % auth_keys)
        File.touch(auth_keys)
        
        logging.info("Saving admin user information `%s' and `%s' in database ..." % (name, email))
        admin = Member(username=username, email=email, name=name)
        
        if admin_repo:
            logging.info("Initializing development repository at `%s/phoenix.git' ..." % repo)
            admin.addRepository("Phoenix Server Management", "phoenix.git")
        
        print "Done."
Exemplo n.º 10
0
 def _beforedestroy(cls, key, *a):
     File.replaceLine(Config.get("phoenix", "authorized_keys"), "--key-id %s" % key.id)
Exemplo n.º 11
0
 def getFullpath(self, hash=None):
     if not hash and not self.hash: return False
     return path.join(Config.get("phoenix", "repository_dir"), hash or self.hash)
Exemplo n.º 12
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!")
Exemplo n.º 13
0
 def __init__(self):        
     if not os.getuid() == __import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_uid:
         raise ClientException("Only `%s' can run this script" % Config.get("phoenix", "user"))
     super(Client, self).__init__()
Exemplo n.º 14
0
 def _writeKey(cls, id, key):
     File.replaceLine(Config.get("phoenix", "authorized_keys"),
                      "--key-id %s" % id, cls._prepareKey(id, key))
Exemplo n.º 15
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!")
Exemplo n.º 16
0
 def __init__(self):
     if not os.getuid() == __import__("pwd").getpwnam(
             Config.get("phoenix", "user")).pw_uid:
         raise ClientException("Only `%s' can run this script" %
                               Config.get("phoenix", "user"))
     super(Client, self).__init__()
Exemplo n.º 17
0
 def debug(self):
     print Config.get("ABS_PATH")
     print Config.get("phoenix", "hook_dir")
Exemplo n.º 18
0
    def init(self):
        if Config.get("phoenix", "initialized") == "True":
            raise AdminException("Already initialized.")

        logging.info("Defining variables for init ...")
        user = self.args.git_user
        base = path.join(self.args.base_dir, user)
        repo = path.join(base, self.args.repository_dir)
        tar = path.join(base, self.args.tarball_dir)
        ssh = path.join(base, ".ssh")
        auth_keys = path.join(ssh, "authorized_keys")
        admin_repo = self.args.admin_repo
        email = self.args.admin_email
        name = self.args.admin_name
        username = self.args.admin_username
        sql = self.args.sql_connect or "sqlite://%s" % path.join(
            base, "phoenix.db")

        logging.info("Checking for permission to write the config file ...")
        if not File.writePermission(Config.get("CONF_FILE")):
            raise AdminException(
                "You don't have permission to write the config file `%s' ..." %
                Config.get("CONF_FILE"))

        if not SysUser.exists(self.args.git_user):
            logging.info("Creating user `%s' ... " % user)
            SysUser.create(user, base)
            Config.set("phoenix", "user", user)
            Config.set("phoenix", "base", base)
        else:
            raise AdminException("The user `%s' already exists." % user)

        logging.info("Saving SQL connection string `%s' ..." % sql)
        Config.set("phoenix", "sql_connect", sql)
        Config.set("phoenix", "initialized", True)
        Config.set("phoenix", "authorized_keys", auth_keys)

        __import__("os").setgid(__import__("pwd").getpwnam(user).pw_gid)
        __import__("os").setuid(__import__("pwd").getpwnam(user).pw_uid)

        logging.info(
            "Checking for permission to write the config file as `%s' ..." %
            user)
        if not File.writePermission(Config.get("CONF_FILE")):
            raise AdminException(
                "You don't have permission to write the config file `%s' ..." %
                Config.get("CONF_FILE"))

        from sqlobject import connectionForURI, sqlhub
        connection = connectionForURI(Config.get("phoenix", "sql_connect"))
        sqlhub.processConnection = connection

        self._sqlChanges()
        self._createDirectoryStructure(repo, tar, ssh)

        logging.info("Creating `%s' ..." % auth_keys)
        File.touch(auth_keys)

        logging.info(
            "Saving admin user information `%s' and `%s' in database ..." %
            (name, email))
        admin = Member(username=username, email=email, name=name)

        if admin_repo:
            logging.info(
                "Initializing development repository at `%s/phoenix.git' ..." %
                repo)
            admin.addRepository("Phoenix Server Management", "phoenix.git")

        print "Done."
Exemplo n.º 19
0
 def debug(self):
     print Config.get("ABS_PATH")
     print Config.get("phoenix", "hook_dir")
Exemplo n.º 20
0
 def _get_pubkey(self):
     return File.extractKey(Config.get("phoenix", "authorized_keys"), self.id)