<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=RTLogins</id>
	<title>RTLogins - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=RTLogins"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=RTLogins&amp;action=history"/>
	<updated>2026-08-22T10:34:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=RTLogins&amp;diff=3005&amp;oldid=prev</id>
		<title>Admin: 2 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=RTLogins&amp;diff=3005&amp;oldid=prev"/>
		<updated>2016-04-06T20:27:17Z</updated>

		<summary type="html">&lt;p&gt;2 revisions imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Introduction&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This is a very basic and minimal php script I wrote to output the logins captured in syslog. It just dumps it to screen but you can redirect the output to a file also.&lt;br /&gt;
&lt;br /&gt;
 RT Login Stats for 2/9/2005&lt;br /&gt;
 eranam,1&lt;br /&gt;
 wildmanj,6&lt;br /&gt;
 garcial,3&lt;br /&gt;
 timm,5&lt;br /&gt;
 reillyj,4&lt;br /&gt;
 JenningsR,1&lt;br /&gt;
 veaziec,2&lt;br /&gt;
 vongleichr,1&lt;br /&gt;
 lewisd,1&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Requirements&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
I wrote this on PHP4 with PEAR::Date used. You&amp;#039;ll have to change the file location of the pear lib to where yours resides.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Caveat Emptor&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This script is provided with no warranties expressed or implied. Use your own risk. Milage may vary.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;TODO&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* Make a cron version&lt;br /&gt;
* Have script store to RRD&lt;br /&gt;
* Have summary e-mailed&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#!/usr/bin/php -q&lt;br /&gt;
 &amp;amp;lt;?php&lt;br /&gt;
 //&lt;br /&gt;
 // RTLogins.php&lt;br /&gt;
 //&lt;br /&gt;
 // parses syslog for RT Login information&lt;br /&gt;
 // returns username,#logins&lt;br /&gt;
 &lt;br /&gt;
 // You&amp;#039;re going to want to re-point this to where pear is on your machine&lt;br /&gt;
 include_once(&amp;quot;/var/www/tikiwiki/lib/pear/Date/Calc.php&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 $date_calc = new Date_Calc;&lt;br /&gt;
 &lt;br /&gt;
 // $logpath = &amp;quot;/var/log/&amp;quot;;&lt;br /&gt;
 $logfile = &amp;quot;&amp;quot;;&lt;br /&gt;
 $buffer = &amp;quot;&amp;quot;;&lt;br /&gt;
 $meDebug = False;&lt;br /&gt;
 $debug_routine_name = &amp;quot;main&amp;quot;;&lt;br /&gt;
 $login_regex = &amp;#039;Successful login&amp;#039;;&lt;br /&gt;
 $counter = 0;&lt;br /&gt;
 $res_summary = array();&lt;br /&gt;
 &lt;br /&gt;
 // What&amp;#039;s in argv[1]?&lt;br /&gt;
 if (strlen($argv[1] &amp;amp;lt; 2)){&lt;br /&gt;
     $logfile = $argv[1];&lt;br /&gt;
     } else {&lt;br /&gt;
         $logfile = &amp;quot;syslog&amp;quot;;&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
 // is this a debug session?&lt;br /&gt;
 if (debug_set($argv[1])){&lt;br /&gt;
     $meDebug = True;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 // open the file for reading&lt;br /&gt;
 if(! $handle=openFile($logfile)){&lt;br /&gt;
     if ($meDebug){echo $debug_routine_name . &amp;quot;: Premature Termination.\n&amp;quot;;}&lt;br /&gt;
     die;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 // Loop through logfile&lt;br /&gt;
 while (!feof($handle)) {&lt;br /&gt;
 &lt;br /&gt;
    $buffer = fgets($handle, 4096);&lt;br /&gt;
 &lt;br /&gt;
     // Match for Login Success&lt;br /&gt;
     $foundLogin = strpos($buffer,$login_regex);&lt;br /&gt;
     if ($meDebug){echo $buffer . &amp;quot; Match to &amp;quot; . $login_regex . &amp;quot; \n&amp;quot;;}&lt;br /&gt;
 &lt;br /&gt;
     $counter++;&lt;br /&gt;
 &lt;br /&gt;
     // Is current line a match?&lt;br /&gt;
     if($foundLogin &amp;amp;gt;= 1){&lt;br /&gt;
 &lt;br /&gt;
         if ($meDebug){echo $counter . &amp;quot; : Found a match \n&amp;quot;;}&lt;br /&gt;
         list($month,&lt;br /&gt;
              $nonce3,&lt;br /&gt;
              $day,&lt;br /&gt;
              $time,&lt;br /&gt;
              $server,&lt;br /&gt;
              $app,&lt;br /&gt;
              $result1,&lt;br /&gt;
              $result2,&lt;br /&gt;
              $nonce1,&lt;br /&gt;
              $user,&lt;br /&gt;
              $nonce2,&lt;br /&gt;
              $client,&lt;br /&gt;
              $func_str)=explode(&amp;quot; &amp;quot;,$buffer);&lt;br /&gt;
 &lt;br /&gt;
          if ($meDebug){&lt;br /&gt;
             echo &amp;quot;Month is &amp;quot; . $month . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Day is &amp;quot; . $day . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Time is &amp;quot; . $time . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Server is &amp;quot; . $server . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;App is &amp;quot; . $app . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;result1 is &amp;quot; . $result1 . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;result2 is &amp;quot; . $result2 . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Nonce1 is &amp;quot; . $nonce1 . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Client is &amp;quot; . $client . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             echo &amp;quot;Nonce2 is &amp;quot; . $func_str . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             }&lt;br /&gt;
 &lt;br /&gt;
          // If the users array key has not been set, go set it&lt;br /&gt;
          if (! isset($res_array[$user])){&lt;br /&gt;
             $res_array[$user] = array();&lt;br /&gt;
             $res_array[$user][&amp;#039;Times&amp;#039;]=array();&lt;br /&gt;
             }&lt;br /&gt;
 &lt;br /&gt;
          $month = $date_calc-&amp;amp;gt;getMonthFromFullName($month);&lt;br /&gt;
          //$time = str_replace(&amp;quot;:&amp;quot;,&amp;quot;&amp;quot;,$time);&lt;br /&gt;
          $res_array[$user][&amp;#039;Times&amp;#039;][] = substr(100+$day,1) . &amp;quot;/&amp;quot; . substr(100+$month,1) . &amp;quot;/2005 &amp;quot; . $time;&lt;br /&gt;
 &lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 // Dump result&lt;br /&gt;
 echo &amp;quot;RT Login Stats for &amp;quot; . $day . &amp;quot;/&amp;quot; . $month . &amp;quot;/2005\n&amp;quot;;&lt;br /&gt;
 dumpResult($res_array);&lt;br /&gt;
 echo &amp;quot;\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 function dumpResult($result){&lt;br /&gt;
 &lt;br /&gt;
     foreach($result as $name =&amp;amp;gt; $times){&lt;br /&gt;
 &lt;br /&gt;
         echo $name . &amp;quot;,&amp;quot; . count($result[$name][&amp;quot;Times&amp;quot;]);&lt;br /&gt;
         echo &amp;quot;\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
     return True;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 function openFile($fn){&lt;br /&gt;
 &lt;br /&gt;
     $logfile = $fn;&lt;br /&gt;
 &lt;br /&gt;
     // echo &amp;quot;Opening the File $logfile \n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
     if(! $handle = fopen($logfile, &amp;quot;r&amp;quot;)){&lt;br /&gt;
         echo &amp;quot;Couldn&amp;#039;t open logfile for reading!\n&amp;quot;;&lt;br /&gt;
         die;&lt;br /&gt;
         }&lt;br /&gt;
     return $handle;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 function debug_set($isDebug){&lt;br /&gt;
     $isDebug=strtolower($isDebug);&lt;br /&gt;
     // echo &amp;quot;In the debug setting\nValue is $isDebug\n\n&amp;quot;;&lt;br /&gt;
     if($isDebug==&amp;#039;y&amp;#039;){&lt;br /&gt;
         Return True;&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ?&amp;amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[MichaelErana]] &amp;lt;u&amp;gt;g33k (at) efamilynj.org&amp;lt;/u&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>