Username:
Password:
  Home About Us Articles Rules Script Library FAQ Help
Not logged in (register
Whois Database [Alpha Release] for mIRC v6.x + SQLite.dll
By: arcane

Last Modified: Mar 01 1:14am (r2)

If you're not familiar with mIRC scripting and/or SQL this script is useless to you at this point.

What we have here is the start of a Whois Database script. It requires the SQLite DLL. You'll want to grab just the DLL from that zip file and throw it in your base mIRC directory. Please note neither I nor UtoNet can vouch for the security or validity of this 3rd party DLL.

So how does it work?

Once you've installed the script and let it run the initialization command, every whois you do will automatically be stored in a database in your mIRC base dir called whois.db. That file is stored in SQLite format and you can view it with a tool like SQLiteCC (google for it).

I've begun implementing very basic, hard to use, search functionality. Hopefully over the next week or two I'll have a GUI driving the searching so it's actually usable without knowing SQL. I haven't tested this lately and I'm thinking the searching might be totally broken right now.

For debugging purposes, if you set the global variable %whoisdb.debug to 1, it'll show all error messages; if you set it to 2 it'll show both all error messages and all successful operation messages.

If anyone is interested, I'd love some help testing what I have so far, especially from a non-oper standpoint (where things like the real hostname or IP may not be available), or on networks other than UtoNet.

If you find any problems, or have any suggestions, post them up here (and maybe PM me on IRC so I know to look).

Thanks!
;* FRONT END *;

; $whoisdb.get( $row, $column )
; returns data from row/column pair
alias whoisdb.get {
  var %ret = $SQLite(Fetch, whoisdb $1 $2)
  if ( $gettok( %ret, 1, 32 ) == S_OK ) {
    return $gettok( %ret, 2, 32 )
  }
  else {
    return -
  }
}

; WHERE $1 $2 $3 AND $4 $5 $6 etc.
; returns # of rows
alias whoisdb.search {
  var %i = 1
  var %query
  if ( $0 < 3 ) {
    %query = 1
  }
  else {
    while ( %i <= $0 ) { 
      if ( %i >= 3 ) {
        %query = %query AND
      }
      %query = %query $gettok( $1-, %i, 32 ) $gettok( $1-, $calc( %i + 1 ), 32 ) $&
        ' $+ $whoisdb.addslashes( $gettok( $1-, $calc( %i + 2 ), 32 ) ) $+ '
      inc %i 3
    }
  }
  return $whoisdb.select(%query)
}

; select * from whois where $1-
; returns row number
alias whoisdb.select {
  whoisdb.query SELECT * FROM whois WHERE $1-
  return $gettok( $SQLite( Rows, whoisdb ), 2, 32 )
}

; doesn't do anything yet
alias whoisdb.csearch {
  var %chan = $iif( #* iswm $1, $mid( $1, 2 ), $1 )
  if ( $2 ) {
    SQLite query SELECT whoisid FROM channels WHERE channel LIKE ' $+ %chan $+ ' AND status LIKE ' $+ $2 $+ '
  }
  else { 
    SQLite query SELECT whoisid FROM channels WHERE channel LIKE ' $+ %chan $+ '
  }
  ; Totally not finished yet
}

;* BACK END *;

alias whoisdb.hadd {
  hadd whoisdata $+ $cid $1-
}

alias whoisdb.hget {
  return $hget( whoisdata $+ $cid, $1 )
}

raw 311:*: { ; $nick $user $host * :$realname
  .enable #WhoisDBCheck
  hmake whoisdata $+ $cid 10
  whoisdb.handleWhois $3-
  whoisdb.hadd nick $2
  whoisdb.hadd ident $3
  whoisdb.hadd host $4
  whoisdb.hadd maskhost $4
  if ( $regex( $4, /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/ ) ) {
    whoisdb.hadd ip $4
  }
  whoisdb.hadd realname $iif( :* iswm $6, $mid( $6-, 2 ), $6- )
  ; defaults to 0, may get changed later in a raw 313
  whoisdb.hadd isoper 0 
  whoisdb.hadd channels 0
  whoisdb.hadd lines 0
  whoisdb.handleWhois $3-
}

alias whoisdb.addslashes {
  return $replace( $1-, ', '' )
}

alias whoisdb.stripslashes {
  return $replace( $1-, '', ' )
}

alias whoisdb.update {
  var %i = 2
  var %query
  while ( %i <= $0 ) { 
    if ( $whoisdb.hget( $gettok( $1-, %i, 32 ) ) != $null ) {
      if ( %i > 2 ) {
        %query = %query $+ ,
      }
      %query = %query $gettok( $1-, %i, 32 ) = ' $+ $whoisdb.addslashes( $whoisdb.hget( $gettok( $1-, %i, 32 ) ) ) $+ '
    }
    inc %i 1
  }
  if ( $whoisdb.hget( $2 ) ) {
    var %query = UPDATE whois SET %query WHERE whoisid = $1
    whoisdb.query %query
  }
}

raw 318:*: { ; $nick :End of /WHOIS list.
  if ( $hget( whoisdata $+ $cid ) ) {
    .disable #WhoisDBCheck
    whoisdb.query INSERT INTO whois (nick,ident,host,ctime,network) VALUES ( $&
      ' $+ $whoisdb.addslashes( $whoisdb.hget(nick) ) $+ ', $&
      ' $+ $whoisdb.addslashes( $whoisdb.hget(ident) ) $+ ', $&
      ' $+ $whoisdb.addslashes( $whoisdb.hget(host) ) $+ ', $&
      ' $+ $ctime $+ ', ' $+ $whoisdb.addslashes( $network ) $+ ' )
    whoisdb.query SELECT last_insert_rowid()
    var %id = $gettok( $SQLite(FetchRow, whoisdb 1 last_insert_rowid()), 2, 32 )
    whoisdb.query BEGIN TRANSACTION updatewhois
    whoisdb.update %id ip maskhost modes idle signon isoper
    whoisdb.update %id server realname

    var %i = 0
    while ( %i < $whoisdb.hget(channels) ) {
      var %query = INSERT INTO channels (whoisid,channel,status) VALUES ( ' $+ %id $+ ', $&
        ' $+ $whoisdb.addslashes( $whoisdb.hget(channel $+ %i) ) $+ ',  $&
        ' $+ $whoisdb.addslashes( $whoisdb.hget(channelstatus $+ %i) ) $+ ' )
      whoisdb.query %query
      inc %i
    }
    var %j = 0
    while ( %j < $whoisdb.hget(lines) ) {
      var %query = INSERT INTO data (whoisid,whoistext) VALUES ( ' $+ %id $+ ', $&
        ' $+ $whoisdb.addslashes( $whoisdb.hget(line $+ %j) ) $+ ' )
      whoisdb.query %query
      inc %j
    }

    whoisdb.query COMMIT TRANSACTION updatewhois
    hfree whoisdata $+ $cid
  }
}

alias whoisdb.handleWhois {
  if ( $numeric == 319 ) { ; channel list 
    var %i = 1
    var %numtok = $numtok( $1-, 32 )
    while ( %i <= %numtok ) {
      var %channel = $gettok( $1-, %i, 32 )
      if ( *? $+ $chr(35) $+ * iswm %channel ) {
        whoisdb.hadd channel $+ $whoisdb.hget(channels) $gettok( %channel, 2, 35 )
        whoisdb.hadd channelstatus $+ $whoisdb.hget(channels) $gettok( %channel, 1, 35 )
        whoisdb.hadd channels $calc( $whoisdb.hget(channels) + 1 )
      }
      else if ( $chr(35) $+ * iswm %channel ) {
        whoisdb.hadd channel $+ $whoisdb.hget(channels) $gettok( %channel, 1, 35 )
        whoisdb.hadd channels $calc( $whoisdb.hget(channels) + 1 )
      }
      inc %i
    }
  }
  else if ( $numeric == 312 ) { ; server info
    whoisdb.hadd server $1
  }
  else if ( $numeric == 317 ) { ; idle time, connect time
    whoisdb.hadd idle $1
    whoisdb.hadd signon $2
  }
  else if ( $numeric == 313 ) { ; oper
    whoisdb.hadd isoper 1
  }
  else if ( $regex( whoisdb.modes, $1-, /^is using modes \+(.*)$/ ) ) {
    whoisdb.hadd modes $regml( whoisdb.modes, 1 )
  }
  else if ( $regex( whoisdb.real, $1-, /^is connecting from \*@(.*)\s+(.*)$/ ) ) {
    whoisdb.hadd host $regml( whoisdb.real, 1 )
    whoisdb.hadd ip $regml( whoisdb.real, 2 )
  }
  whoisdb.hadd line $+ $whoisdb.hget(lines) $1-
  whoisdb.hadd lines $calc( $whoisdb.hget(lines) + 1 )
}

#WhoisDBCheck off
raw *:*: { ; all other whois messages
  whoisdb.handleWhois $3-
}
#WhoisDBCheck end

alias whoisdb.init {
  if ( !$isfile(whois.db) ) {
    SQLite open whoisdb whois.db
    whoisdb.query CREATE TABLE whois ( $&
      whoisid INTEGER PRIMARY KEY, $&
      ctime INTEGER, $&
      network VARCHAR(255), $&
      server VARCHAR(255), $&
      nick VARCHAR(255), $&
      ident VARCHAR(255), $&
      host VARCHAR(255), $&
      maskhost VARCHAR(255), $&
      ip VARCHAR(16), $&
      realname VARCHAR(255), $&
      modes VARCHAR(127), $&
      isoper INTEGER(1), $&
      signon INTEGER, $&
      idle INTEGER )
    whoisdb.query CREATE TABLE data ( $&
      whoisid INTEGER, $&
      whoistext TEXT )
    whoisdb.query CREATE TABLE channels ( $&
      whoisid INTEGER, $&
      channel VARCHAR(255), $&
      status VARCHAR(5) )
    whoisdb.query CREATE INDEX whoisctime ON whois (ctime)
    whoisdb.query CREATE INDEX whoisnick ON whois (nick)
    whoisdb.query CREATE INDEX whoisserver ON whois (server)
    whoisdb.query CREATE INDEX whoishost ON whois (host)
    whoisdb.query CREATE INDEX whoisip ON whois (ip)
    whoisdb.query CREATE INDEX datawhoisid ON data (whoisid)
    whoisdb.query CREATE INDEX channelswhoisid ON channels (whoisid)
    whoisdb.query CREATE INDEX channelschannel ON channels (channel)
  }
  else {
    SQLite open whoisdb whois.db
  }
}

alias whoisdb.query {
  return $SQLite( query, whoisdb $1- )
}

alias SQLite {
  var %ret = $dll( SQLite, $1, $iif( $2- != $null, $2- , _ ) )
  if ( S_OK* iswm %ret ) {
    if ( %whoisdb.debug > 1 ) {
      echo -s %ret
    }
  }
  else {
    if ( %whoisdb.debug ) {
      echo -s %ret
    }
  }
  return %ret
}

on *:start: {
  whoisdb.init
}

on *:exit: {
  SQLite close whoisdb
}

Comments
secretz
Mar 01 4:52pm
Sounds cool. Will give it a try once you get a GUI up.
 
All content Copyright © 2004 - 2008 UtoNet IRC Network
UtoNet is sponsored and hosted by Datinix Systems