The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom Event Handler - get session details

Discussion in 'cPanel Developers' started by ruyrocha, Nov 21, 2012.

  1. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
    Hello,

    How can I get session details - like remote ip address - in custom event handler or function hooks system? When some user deletes a file trough file manager, there are nothing in logs other than "POST /json-api/", and I'm writing a logger to catch removed files:

    Code:
    sub event {
      print STDERR @_;
      my ( $apiv, $type, $module, $event, $cfgref, $dataref ) = @_;
    
      return 1 if ( $module ne 'fileman' );
    
      my $logger = Cpanel::Logger->new({ alternate_logfile => "/usr/local/cpanel/logs/unlink_log" });
    
      if ($module eq 'fileman') {
        if ($event eq 'fileop') {
          if ( $type eq 'post' ) {
            if ($dataref) {
              my $user = $Cpanel::user;
              my $op   = $cfgref->{'op'} ;
    
              my $msg ;
    
              if ($op eq 'unlink') {
                foreach (@$dataref) {
                  if ( $_->{'result'} ) {
                    $msg = "File Manager - $user - $_->{'src'}" ;
                    $logger->info($msg);
                  }
                }
              }
            }
          }
        }
        return 1;
      }
    
      return 1;
    }
    
    
    The specified log file shows this but I'm missing the remote ip address which removed this file :

    Code:
    ==> /usr/local/cpanel/logs/unlink_log <==
    [2012-11-21 17:02:26 -0200] info [cpanel] File Manager - bla - /home/bla/public_html/c
    
     
    #1 ruyrocha, Nov 21, 2012
    Last edited: Nov 21, 2012
  2. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    my $ip = $ENV{'REMOTE_ADDR'};
     
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    FYI, you can print a list of all the environmental variables available to /usr/local/cpanel/logs/error_log with this code:

    Code:
    use Data::Dumper ();
    print STDERR Data::Dumper::Dumper(%ENV);
    
     
Loading...

Share This Page