Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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:
    51
    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:
    66
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    my $ip = $ENV{'REMOTE_ADDR'};
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    68
    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);
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice