ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/moderator/sessions.pl  view on Meta::CPAN

# Debug information
print "<pre>pagedir     : $pagedir<br>pageset     : $pageset<br>debug       : $debug<br>CGISESSID   : $sessionID<br>action      : $action<br>session ID  : $CsessionID<br>URL ...     : $urlAccessParameters</pre>" if ( $debug eq 'T' );

if ( defined $sessionID and ! defined $errorUserAccessControl ) {
  my ($matchingSessionDetails, $matchingSessionsBlocked, $matchingSessionsActive, $matchingSessionsExpired, $matchingSessionsEmpty, $navigationBar);

  my $urlWithAccessParameters = $ENV{SCRIPT_NAME} . "?pagedir=$pagedir&amp;pageset=$pageset&amp;debug=$debug&amp;CGISESSID=$sessionID";

  if ($action eq 'deleteView') {
    $htmlTitle    = "Delete Session '$CsessionID'";
    $submitButton = "Delete";
    $nextAction   = "delete";
  } elsif ($action eq 'delete') {
    my $cgisessFilename = "cgisess_$CsessionID";

    if (-e "$CGISESSPATH/$cgisessFilename") {
      unlink ($CGISESSPATH.'/'.$cgisessFilename);	

      if (-e "$CGISESSPATH/$cgisessFilename") {
        $htmlTitle = "Session '$cgisessFilename' not deleted, not enough rights";
      } else {
        $htmlTitle = "Session '$cgisessFilename' deleted";
      }
    } else {
      $htmlTitle = "Session '$cgisessFilename' not deleted, doesn't exist";
    }
  } elsif ($action eq 'detailsView') {
    $htmlTitle    = "Details for session '$CsessionID'";
    $submitButton = "Display";
    $nextAction   = "listView";

	my $colspan = 2;
    my $cgisessFilename = "cgisess_$CsessionID";
    my ($sessionExists, %session) = get_session_param ($CsessionID, $CGISESSPATH, $cgisessFilename, $debug);

    $matchingSessionDetails = "\n      <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"$COLORSTABLE{TABLE}\">\n        <tr bgcolor=\"$COLORSTABLE{NOBLOCK}\"><th colspan=\"$colspan\">$htmlTitle</th></t...

    if ( $sessionExists ) {
      my $Temail = $session{email}; $Temail =~ s/\\//g;
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_ID</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{_SESSION_ID}. "</td></tr>\n" if (defined $session{_SESSION_ID});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_REMOTE_ADDR</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{_SESSION_REMOTE_ADDR}. "</td></tr>\n" if (defined $session{_SESSION_REMOTE_ADDR});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_CTIME</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .scalar(localtime($session{_SESSION_CTIME})). "</td></tr>\n" if (defined $session{_SESSION_CTIME});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_ATIME</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .scalar(localtime($session{_SESSION_ATIME})). "</td></tr>\n" if (defined $session{_SESSION_ATIME});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_ETIME</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{_SESSION_ETIME}. "</td></tr>\n" if (defined $session{_SESSION_ETIME});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">_SESSION_EXPIRE_LIST</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{_SESSION_EXPIRE_LIST}. "</td></tr>\n" if (defined $session{_SESSION_EXPIRE_LIST});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">~login-trials</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{'~login-trials'}. "</td></tr>\n" if (defined $session{'~login-trials'});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">~logged-in</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{'~logged-in'}. "</td></tr>\n" if (defined $session{'~logged-in'});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">remote user</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{remoteUser}. "</td></tr>\n" if (defined $session{remoteUser});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">remote address</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{remoteAddr}. "</td></tr>\n" if (defined $session{remoteAddr});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">remote netmask</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{remoteNetmask}. "</td></tr>\n" if (defined $session{remoteNetmask});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">given name</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .encode_html_entities('V', $session{givenName}). "</td></tr>\n" if (defined $session{givenName});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">surname</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .encode_html_entities('V', $session{familyName}). "</td></tr>\n" if (defined $session{familyName});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">email</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$Temail. "</td></tr>\n" if (defined $session{email});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">key language</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{keyLanguage}. "</td></tr>\n" if (defined $session{keyLanguage});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">password</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{password}. "</td></tr>\n" if (defined $session{password});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">user type</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{userType}. "</td></tr>\n" if (defined $session{userType});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">pagedir</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{pagedir}. "</td></tr>\n" if (defined $session{pagedir});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">activated</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{activated}. "</td></tr>\n" if (defined $session{activated});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon add</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconAdd}. "</td></tr>\n" if (defined $session{iconAdd});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon details</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconDetails}. "</td></tr>\n" if (defined $session{iconDetails});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon edit</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconEdit}. "</td></tr>\n" if (defined $session{iconEdit});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon delete</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconDelete}. "</td></tr>\n" if (defined $session{iconDelete});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon query</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconQuery}. "</td></tr>\n" if (defined $session{iconQuery});
      $matchingSessionDetails .= "        <tr><td bgcolor=\"$COLORSTABLE{ENDBLOCK}\">icon table</td><td bgcolor=\"$COLORSTABLE{STARTBLOCK}\">" .$session{iconTable}. "</td></tr>\n" if (defined $session{iconTable});
    } else {
      $matchingSessionDetails .= "        <tr><td colspan=\"$colspan\">No active sessions found</td></tr>\n";
    }

    $matchingSessionDetails .= "      </table>\n";
  } elsif ($action eq 'listView') {
    $htmlTitle    = "All sessions listed";

    my $actionPressend = ($iconDelete or $iconDetails) ? 1 : 0;
    my $actionHeader = ($actionPressend) ? "<th>Action</th>" : '';
    my $colspan = 7 + $actionPressend;

    my $table  = "\n      <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"$COLORSTABLE{TABLE}\">\n";
    my $header = "        <tr><th> Session ID </th><th> Remote User </th><th> Name </th><th> IP address </th><th> Activated </th><th> Login Trials </th><th> eTime </th>$actionHeader</tr>\n";

    $matchingSessionsBlocked = "$table        <tr bgcolor=\"$COLORSTABLE{NOBLOCK}\"><th colspan=\"$colspan\">Blocked Sessions</th></tr>\n$header";
    $matchingSessionsActive  = "$table        <tr bgcolor=\"$COLORSTABLE{NOBLOCK}\"><th colspan=\"$colspan\">Active Sessions</th></tr>\n$header";
    $matchingSessionsExpired = "$table        <tr bgcolor=\"$COLORSTABLE{NOBLOCK}\"><th colspan=\"$colspan\">Expired Sessions</th></tr>\n$header";
    $matchingSessionsEmpty   = "$table        <tr bgcolor=\"$COLORSTABLE{NOBLOCK}\"><th colspan=\"$colspan\">Empty Sessions</th></tr>\n$header";

    my ($numberRecordsIntoQueryBlocked, $numberRecordsIntoQueryActive, $numberRecordsIntoQueryExpired, $numberRecordsIntoQueryEmpty);
    $numberRecordsIntoQueryBlocked = $numberRecordsIntoQueryActive = $numberRecordsIntoQueryExpired = $numberRecordsIntoQueryEmpty = 0;

    my $currentTime = time();
    my $solaris = (-e '/usr/sbin/nslookup') ? 1 : 0; # solaris

    @cgisessPathFilenames = glob("$CGISESSPATH/cgisess_*");

    foreach my $cgisessPathFilename (@cgisessPathFilenames) {
      my (undef, $cgisessFilename) = split (/^$CGISESSPATH\//, $cgisessPathFilename);
      (undef, $CsessionID) = split (/^cgisess_/, $cgisessFilename);
      my ($sessionExists, %session) = get_session_param ($CsessionID, $CGISESSPATH, $cgisessFilename, $debug);

      if ( $sessionExists ) {
        my $sessionCtime = (defined $session{_SESSION_CTIME})       ? $session{_SESSION_CTIME}       : undef;
        my $sessionAtime = (defined $session{_SESSION_ATIME})       ? $session{_SESSION_ATIME}       : undef;
        my $sessionEtime = (defined $session{_SESSION_ETIME})       ? $session{_SESSION_ETIME}       : undef;
        my $remoteAddr   = (defined $session{_SESSION_REMOTE_ADDR}) ? $session{_SESSION_REMOTE_ADDR} : '';

        if ($solaris) { # solaris
          my $TremoteAddr = `/usr/sbin/nslookup $remoteAddr`;

		  if ($TremoteAddr) {
            $TremoteAddr =~ /^Name:\s+(.*)$/m;
            $remoteAddr = $1 if (defined $1);
          }
        } else { # linux
          my $TremoteAddr = `host -t ptr $remoteAddr`;

		  if ($TremoteAddr) {
            $TremoteAddr =~ /domain name pointer (.*)/;
            $remoteAddr = $1 if (defined $1);
          }
        }

        my $actionItem = ($actionPressend) ? "<td align=\"center\">&nbsp;" : '';
        my $urlWithAccessParametersAction = "$urlWithAccessParameters&amp;sessionID=$CsessionID&amp;action";



( run in 0.889 second using v1.01-cache-2.11-cpan-39bf76dae61 )