]> jfr.im git - irc/UndernetIRC/gnuworld.git/commitdiff
Log last used user ip (alongside last used host).
authorMrBean <redacted>
Wed, 12 Nov 2008 20:45:42 +0000 (20:45 +0000)
committerMrBean <redacted>
Wed, 12 Nov 2008 20:45:42 +0000 (20:45 +0000)
NOTE: add doc/update.last_seen.sql contents into cservice database
      or complaints about missing column last_ip will be displayed!

doc/cservice.sql
doc/update.last_seen.sql [new file with mode: 0644]
mod.cservice/CHANINFOCommand.cc
mod.cservice/LOGINCommand.cc
mod.cservice/SCANHOSTCommand.cc
mod.cservice/sqlUser.cc
mod.cservice/sqlUser.h

index 47cabb89ca5f084374f16e3f34e688207148c245..18ceb8c0270bb127f6c4f6842af7195c20c8515b 100644 (file)
@@ -1,5 +1,5 @@
 ------------------------------------------------------------------------------------
--- "$Id: cservice.sql,v 1.86 2007/03/25 16:42:24 kewlio Exp $"
+-- "$Id: cservice.sql,v 1.87 2008/11/12 20:45:42 mrbean_ Exp $"
 -- Channel service DB SQL file for PostgreSQL.
 
 -- ChangeLog:
@@ -235,6 +235,7 @@ CREATE TABLE users_lastseen (
        user_id INT4 CONSTRAINT lastseen_users_id_ref REFERENCES users ( id ),
        last_seen INT4,
        last_hostmask VARCHAR( 256 ),
+       last_ip VARCHAR( 256 ),
        last_updated INT4 NOT NULL,
        PRIMARY KEY (user_id)
 );
diff --git a/doc/update.last_seen.sql b/doc/update.last_seen.sql
new file mode 100644 (file)
index 0000000..29c3239
--- /dev/null
@@ -0,0 +1,5 @@
+--
+-- Adds the last_ip column to the users_lastseen table
+
+ALTER TABLE users_lastseen ADD COLUMN  last_ip VARCHAR( 256 );
+
index dc04f63c0fc5ca4489c23fc9beaf0864ce9aa431..9527547ca13c3d49b364fdaaeef4d91fac7f8e5f 100755 (executable)
@@ -28,7 +28,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  *
- * $Id: CHANINFOCommand.cc,v 1.60 2008/01/01 19:03:41 kewlio Exp $
+ * $Id: CHANINFOCommand.cc,v 1.61 2008/11/12 20:45:42 mrbean_ Exp $
  */
 
 #include       <string>
@@ -43,7 +43,7 @@
 #include       "dbHandle.h"
 #include       "cservice_config.h"
 
-const char CHANINFOCommand_cc_rcsId[] = "$Id: CHANINFOCommand.cc,v 1.60 2008/01/01 19:03:41 kewlio Exp $" ;
+const char CHANINFOCommand_cc_rcsId[] = "$Id: CHANINFOCommand.cc,v 1.61 2008/11/12 20:45:42 mrbean_ Exp $" ;
 
 namespace gnuworld
 {
@@ -342,6 +342,12 @@ if( string::npos == st[ 1 ].find_first_of( '#' ) )
                } else {
                        bot->Notice(theClient, "Last Hostmask: %s",
                                theUser->getLastHostMask().c_str());
+                       //Show ip only to admins
+                       if(adminAccess > 0) 
+                               {
+                               bot->Notice(theClient, "Last IP: %s",
+                                       theUser->getLastIP().c_str());                  
+                               }
                }
 
 #ifdef USE_NOTES
index 806a39ecc7a502fcba0436889a3cad96689fd8a8..107a6b8b6146bdde62c140b322cdf3078b897e53 100755 (executable)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  *
- * $Id: LOGINCommand.cc,v 1.65 2008/01/01 13:49:19 kewlio Exp $
+ * $Id: LOGINCommand.cc,v 1.66 2008/11/12 20:45:42 mrbean_ Exp $
  */
 
 #include       <string>
@@ -33,8 +33,9 @@
 #include       "networkData.h"
 #include       "cservice_config.h"
 #include       "Network.h"
+#include       "ip.h"
 
-const char LOGINCommand_cc_rcsId[] = "$Id: LOGINCommand.cc,v 1.65 2008/01/01 13:49:19 kewlio Exp $" ;
+const char LOGINCommand_cc_rcsId[] = "$Id: LOGINCommand.cc,v 1.66 2008/11/12 20:45:42 mrbean_ Exp $" ;
 
 namespace gnuworld
 {
@@ -351,7 +352,8 @@ if( bot->SQLDb->Exec(queryString, true ) )
        }
 }
 /* update their details */
-theUser->setLastSeen(bot->currentTime(), theClient->getNickUserHost());
+theUser->setLastSeen(bot->currentTime(), theClient->getNickUserHost(),
+       theClient->getNickName() + "!" + theClient->getUserName() + "@" + xIP( theClient->getIP()).GetNumericIP());
 theUser->setFlag(sqlUser::F_LOGGEDIN);
 theUser->addAuthedClient(theClient);
 
index ad878fadb71cfc7f748c2e2cf03236880e9c8f0e..3520437f56eb6bdad409abd623ce8bf5163cf46a 100755 (executable)
@@ -22,7 +22,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  *
- * $Id: SCANHOSTCommand.cc,v 1.6 2007/08/28 16:10:11 dan_karrels Exp $
+ * $Id: SCANHOSTCommand.cc,v 1.7 2008/11/12 20:45:42 mrbean_ Exp $
  */
 
 
@@ -89,9 +89,10 @@ if (level < level::scanhost)
 string host = string_lower(st[1]);
 
 stringstream scanhostQuery;
-scanhostQuery << "SELECT users.user_name, users_lastseen.last_hostmask FROM users, users_lastseen WHERE "
+scanhostQuery << "SELECT users.user_name, users_lastseen.last_hostmask, users_lastseen.last_ip FROM users, users_lastseen WHERE "
                 << "users.id = users_lastseen.user_id AND "
-               << "lower(users_lastseen.last_hostmask) LIKE '" << escapeSQLChars(searchSQL(host)) << "' LIMIT 50"
+               << "(lower(users_lastseen.last_hostmask) LIKE '" << escapeSQLChars(searchSQL(host)) << "'"
+               << " OR lower(users_lastseen.last_ip) LIKE '" << escapeSQLChars(searchSQL(host)) << "') LIMIT 50"
                 << ends;
 
 #ifdef LOG_SQL
@@ -133,7 +134,7 @@ int matchCount = 0;
 for (unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
 {
        string username = bot->SQLDb->GetValue(i, 0);
-       string lasthost = bot->SQLDb->GetValue(i, 1);
+       string lasthost = bot->SQLDb->GetValue(i, 1) + " - Last IP: " + bot->SQLDb->GetValue(i, 2);
        scanResults.insert( std::make_pair(username, lasthost));
 }
 
index e6c243bb1d0af0190c4a3443337ad4a08dd1016f..1038287d7b60cdd578c0ac5b646338e8a8aea7dc 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  *
- * $Id: sqlUser.cc,v 1.46 2007/08/28 16:10:12 dan_karrels Exp $
+ * $Id: sqlUser.cc,v 1.47 2008/11/12 20:45:42 mrbean_ Exp $
  */
 
 #include       <sstream>
@@ -267,6 +267,9 @@ queryString << queryHeader
                << "last_hostmask = '"
                << escapeSQLChars(last_hostmask)
                << "', "
+               << "last_ip = '"
+               << escapeSQLChars(last_ip)
+               << "', "
                << "last_updated = now()::abstime::int4 "
                << queryCondition
                << id
@@ -399,7 +402,40 @@ return ("");
 
 }
 
+const string sqlUser::getLastIP()
+{
+stringstream queryString;
+queryString    << "SELECT last_ip"
+               << " FROM users_lastseen WHERE user_id = "
+               << id
+               << ends;
 
+#ifdef LOG_SQL
+       elog    << "sqlUser::getLastIP> "
+               << queryString.str().c_str()
+               << endl;
+#endif
+
+if( SQLDb->Exec(queryString, true ) )
+//if( PGRES_TUPLES_OK == status )
+       {
+       /*
+        *  If the user doesn't exist, we won't get any rows back.
+        */
+
+       if(SQLDb->Tuples() < 1)
+               {
+               return ("");
+               }
+
+       last_ip = SQLDb->GetValue(0, 0);
+
+       return (last_ip);
+       }
+
+return ("");
+
+}
 void sqlUser::writeEvent(unsigned short eventType, sqlUser* theUser, const string& theMessage)
 {
 string userExtra = theUser ? theUser->getUserName() : "Not Logged In";
index 076d8b9287ff6956dd29a207c0b072391c8c96d9..a9d42796383889e57b49efc548b738b1e7d4278f 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  *
- * $Id: sqlUser.h,v 1.41 2007/08/28 16:10:12 dan_karrels Exp $
+ * $Id: sqlUser.h,v 1.42 2008/11/12 20:45:42 mrbean_ Exp $
  */
 
 #ifndef __SQLUSER_H
-#define __SQLUSER_H "$Id: sqlUser.h,v 1.41 2007/08/28 16:10:12 dan_karrels Exp $"
+#define __SQLUSER_H "$Id: sqlUser.h,v 1.42 2008/11/12 20:45:42 mrbean_ Exp $"
 
 #include       <string>
 #include       <vector>
@@ -154,9 +154,11 @@ public:
                { password = _password; }
 
        inline void setLastSeen( const time_t& _last_seen,
-                       const std::string& _last_hostmask )
+                       const std::string& _last_hostmask,
+                       const std::string& _last_ip)
                { last_seen = _last_seen;
                  last_hostmask = _last_hostmask ;
+                 last_ip = _last_ip;
                  commitLastSeen(); }
 
        inline void setLastSeen( const time_t& _last_seen )
@@ -208,6 +210,7 @@ public:
        bool commitLastSeenWithoutMask();
        time_t  getLastSeen();
        const std::string getLastHostMask();
+       const std::string getLastIP();
        bool Insert() ;
 
        bool loadData( int );
@@ -237,6 +240,7 @@ protected:
        time_t          instantiated_ts;
        std::string     email ;
        std::string     last_hostmask ;
+       std::string last_ip;
        unsigned int    maxlogins;
        time_t          last_note;
        unsigned int    notes_sent;