Пример #1
0
def hg_serve(user, options, args):
    if not options.repository:
        raise subssh.InvalidArguments("Repository is missing")
    if not options.stdio:
        raise subssh.InvalidArguments("'--stdio' is missing")


    if not valid_repo.match(options.repository):
        subssh.errln("Illegal repository path '%s'" % options.repository)
        return 1

    repo_name = os.path.basename(options.repository.lstrip("/"))


    # Transform virtual root
    real_repository_path = os.path.join(config.REPOSITORIES, repo_name)

    repo = Mercurial(real_repository_path, subssh.config.ADMIN)

    if not repo.has_permissions(user.username, "r"):
        raise InvalidPermissions("%s has no read permissions to %s"
                                 %(user.username, options.repository))

    from mercurial.dispatch import dispatch
    return dispatch(['-R', repo.repo_path, 'serve', '--stdio'])
Пример #2
0
def remove_user(username):
    db = AuthorizedKeysDB()
    try:
        db.remove_user(username)
    except KeyError:
        subssh.errln("No such user '%s'" % username)
    else:
        db.commit()
    db.close()
Пример #3
0
def add_key(username, args, comment=""):

    if not username_pattern.search(username):
        subssh.writeln("User name \"%s\" contains restricted characters" % username)
        return 1

    try:
        key = get_key_from_input(" ".join(args))
    except (urllib2.HTTPError, IOError, OSError), e:
        if len(e.args) > 1:
            subssh.errln(e.args[1])
        else:
            subssh.errln(e.args[0])
        return 1
Пример #4
0
def show_doc(user, command):
    """
    Show man page of a command.
    
    usage: man <command>
    """
    try:
        doc_tmpl = active.cmds[command].__doc__
    except KeyError:
        subssh.errln("Unkown command '%s'" % command)
        return 1
    
    if doc_tmpl:
        subssh.writeln(tools.expand_subssh_vars(doc_tmpl, cmd=command))
    else:
        subssh.writeln("'%s' has no doc string" % command)
Пример #5
0
def handle_git(user, request_repo):
    """Used internally by Git"""

    if not valid_repo.match(request_repo):
        subssh.errln("Illegal repository path '%s'" % request_repo)
        return 1

    repo_name = os.path.basename(request_repo.lstrip("/"))

    # Transform virtual root
    real_repository_path = os.path.join(config.REPOSITORIES, repo_name)

    repo = Git(real_repository_path, subssh.config.ADMIN)

    # run requested command on the repository
    return repo.execute(user.username, user.cmd, git_bin=config.GIT_BIN)
Пример #6
0
    def init(self, user, repo_name):
        """
        Create new repository.

        usage: $cmd <repository name>
        """

        if not subssh.safe_chars_only_pat.match(repo_name):
            subssh.errln("Bad repository name. Allowed characters: %s (regexp)"
                        % subssh.safe_chars)
            return 1

        repo_path = self.real_path(repo_name)
        self.create_repository(repo_path, user.username)
        self.copy_common_hooks(user, repo_name)

        subssh.writeln("\n\n Created new repository '%s' \n" % repo_name)

        self.info(user, repo_name)
Пример #7
0
    def set_permissions(self, user, username, permissions, repo_name):
        """
        Set read/write permissions to repository.

        usage: $cmd <username> <+/-permissions> <repo name>

        Permissions can be 'r', 'w', or 'rw'.

        Eg. $cmd myfriend r myrepository
            $cmd myanotherfriend +w myrepository

        Only owners can change permissions. Owners can also add and remove
        other owners.

        """
        repo = self.get_repo_object(user.username, repo_name)
        repo.set_permissions(username, permissions)
        if not repo.has_permissions('*', 'r') and self.is_web_enabled(repo):
            self.web_disable(user, repo_name)
            subssh.errln("Note: Web view disabled")
        repo.save()
Пример #8
0
    try:
        key = get_key_from_input(" ".join(args))
    except (urllib2.HTTPError, IOError, OSError), e:
        if len(e.args) > 1:
            subssh.errln(e.args[1])
        else:
            subssh.errln(e.args[0])
        return 1

    exit_status = 0

    db = AuthorizedKeysDB()
    try:
        db.add_key_from_str(username, key, comment)
    except (PubKeyException, AuthorizedKeysException), e:
        subssh.errln(e.args[0])
        exit_status = 1
    else:
        db.commit()
    db.close()


    return exit_status

def list_keys(username):
    db = AuthorizedKeysDB(disable_lock=True)
    try:
        subuser = db.subusers[username]
    except KeyError:
        subssh.writeln("%s has no keys" % username)
    else: