Git Product home page Git Product logo

svn-utils-clientip-perl's Introduction

######################################################################
    SVN::Utils::ClientIP 0.02
######################################################################

NAME
    SVN::Utils::ClientIP - Get the client's IP address in a Subversion Hook

SYNOPSIS
        use SVN::Utils::ClientIP qw(ssh_client_ip);

        print "The client's IP address is ", ssh_client_ip();

DESCRIPTION
    SVN::Utils::ClientIP solves the age-old problem of obtaining the SSH
    client's IP address in a commit hook of a Subversion repository.

    Knowing the client's IP address can be quite useful in heavily used
    Subversion installations, as it allows for maintaining a log on who
    accessed a repository when and from where.

    However, the Subversion developers are not very accomodating when it
    comes to this, claiming "security purposes":

       http://svn.haxx.se/users/archive-2009-02/0804.shtml

    But, if you think about how a client connects to the repository using
    SSH, which then spawns the svn process, it becomes quite clear how you
    can get the IP address, even if the Subversion folks are hiding it from
    you: Starting from the currently running hook, walk up the process
    hierarchy, until you reach the parent that's the SSH instance serving
    the client (only tested with openssh). In its environment, you'll find a
    variable named SSH_CLIENT, which contains the IP address of the
    connecting client.

    This is exactly what this module does, and you can simply obtain the SSH
    client's IP address by running

        use SVN::Utils::ClientIP qw(ssh_client_ip);

        my $ip = ssh_client_ip();

    Under the hood, the module uses the CPAN modules Proc::ProcessTable for
    obtaining the ppid() to walk up the process hierarchy and
    Proc::Info::Environment for reading out the SSH_CLIENT environment
    variable. By the time of this writing, the latter only worked for Linux,
    but in the meantime other OSes might be supported.

    It's not terribly expensive, but it adds up and if you're using the
    function many times, you might want to memoize() it.

OBJECT NOTATION
    The ssh_client_ip() convenience function illustrated above will suffice
    for most hooks, if you want more control or diagnosing functions, use
    the full object notation:

        use SVN::Utils::ClientIP;

        my $finder = SVN::Utils::ClientIP->new();

        if( my $ip = $finder->ssh_client_ip_find() ) {
            print "Found IP address: $ip\n";
        } else {
            print "IP address not found: ", $finder->error(), "\n";
        }

    The SSH_CLIENT variable of the ssh process contains not only the
    client's IP address, but also the pid of the process and the port the
    client docked on to (typically 22). It looks something like this:

        "123.123.123.123 57890 22"

    The convenience function ssh_client_ip returns only the first part. If
    you call the object method in scalar context, it also returns only the
    IP address and skips the two following fields. If you want all fields,
    use ssh_client_ip_find() in list context:

        my($ip, $pid, $port) = $finder->ssh_client_ip_find();

    and $pid and $port will be populated with the values found after
    separating blanks in SSH_CLIENT.

LEGALESE
    Copyright 2010 by Mike Schilli, all rights reserved. This program is
    free software, you can redistribute it and/or modify it under the same
    terms as Perl itself.

AUTHOR
    2010, Mike Schilli <[email protected]>

svn-utils-clientip-perl's People

Contributors

mschilli avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.