示例#1
0
def get_ssh_command():
    orig_command = os.getenv('SSH_ORIGINAL_COMMAND')
    LOGR.debug('SSH_ORIGINAL_COMMAND: {0}'.format(orig_command))

    # if user tries to use this ssh to get shell access
    if not orig_command:
        # random error code:
        code = os.urandom(12)
        #TODO: raise error
        LOGR.error('NO COMMAND SPECIFIED BY USER {0}'.format(get_user_id()))
        die_gracefuly('Sorry, but there\'s no shell access available.\n')

    return orig_command
示例#2
0

LOGR = logging.getLogger('gitward')
LOGPATH = os.path.join(os.path.expanduser('~'), 'log_event.log')
formatter = logging.Formatter(
    '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
)
handler = RotatingFileHandler(LOGPATH)
handler.setFormatter(formatter)
LOGR.addHandler(handler)
LOGR.setLevel(logging.DEBUG)
LOGR.debug('------------------------------------------')


if __name__ == '__main__':
# if user send not a git command
    try:
        serve()
    except InvalidCommandError as e:
        LOGR.error('DISCARDING COMMAND: {0}'.format(e.command))
        LOGR.error('EXCEPTION MESSAGE: {0}'.format(e.formatted_message))
        die_gracefuly('Only git-upload-pack and git-receive-pack are allowed')
    except InvalidCommandArgumentError as e:
        LOGR.error('DISCARDING COMMAND: {0}'.format(e.command))
        LOGR.error('EXCEPTION MESSAGE: {0}'.format(e.formatted_message))
        die_gracefuly('Invalid command arguments')
    except RepoAccessDeniedError as e:
        LOGR.error("PATH DOESN'T EXIST: {0}".format(e.path))
        die_gracefuly("You dont have access to this repository")