This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

userfile management

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

userfile management

Post by honeybee »

hello,
I have a channel on quakenet and we offer some services for our users for that i need a script that can add people the script should have following features:
when a user msg the bot /msg botnick register pass
he/she will be added with hostmask *!*ident@*.ip.com
as we know there are following type of hosts
1) full alphabetic eg. *!honey@i.m.like.honey.com
2) full numeric eg. *!honey@63.39.45.1
3) numeric and alphabetic both eg. *!honey@64.40.39.2-aol.com etc
4) registered quakenet users eg: *!honey@honey.users.quakenet.org

so we need if an user is registered and triggers the command he/she should be added with full host like eg. *!*@blah.users.quakenet.org
and if they have a full alphabetic host their full host with ident should be added like *!*honey@i.m.like.honey.com
and if their host is numerical it sholuld be like ident and last mask should be wildcarded
*!*honey@64.32.42.*
and if they have both numeric and alphabets in their host then it should be like ident and only numeric part should be wildcarded.
eg: *!*honey@*.aol.com
--- end of the register part ---
now if their host get changed, we have to let them add their new host
for this they can msg the bot for adding new host.
/msg botnick addhost <nick/handle> <password>
------------- end of host adding ----
ofcourse their nick will be their handle but if they want to to change it
they can use this command
/msg botnick chnick <password>
again for this we need to have know if the new nick selected is not own by anyone , and if not they can change their nickname else an error will occur
----------------- end of the nick change ----
this is a rough touch of what i analysed for managing the userlist if you have a better idea that will be welcomed. i just dont want bot to think people with same ips to be the same thats it.
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

This proc should return the type of host you wish:

Code: Select all

proc setHost uhost {
 set host [lindex [split $uhost @] 1]
 set n [llength [split $host .]]
 if {[regexp -all {[A-z]{1,}(\.?)} $host] == $n && ![regexp {[0-9]} $host]} {
  set ehost *!*[string trimleft $uhost ~]
 } else if {[string match "*.users.quakenet.org" $host]} {
  set ehost *!*[string trimleft $uhost ~]
 } {
  set ehost [maskhost $uhost]
 }
 set ehost
}
As for the other requests, I bet you can implement something like that yourself.
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

thanks fz, anymore help will be appreciated and ofcourse I would like to hear from demond aswell
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

is only sir_fz active on forum?
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Don't wait for someone to come and write the whole script. If you just put a little effort in writing 10% of the script, anyone would be more than happy to help you. I'll give you some example on how you can do this.

Code: Select all

bind msg - register register:nick
bind msg - addhost addhost:nick

# register the user.
proc register:nick {n u h a} {
 if {$hand == "*" && $a != ""} {
  adduser $n [setHost $u]
  setuser $n PASS [lindex [split $a] 0]
  puthelp "notice $n :You've been added with handle $n."
 } {
  puthelp "notice $n :You're already added with handle $h or you didn't specify a password."
 }
}

# add a new host.
proc addhost:nick {n u h a} {
 set hh [lindex [split $a] 0]
 set p [lindex [split $a] 1]
 if {[validuser $hh] && [passwdok $hh $p]} {
  setuser $hh HOSTS [setHost $u]
  puthelp "notice $n :Added you new host to handle $hh."
 } {
  puthelp "notice $n :Invalid handle or wrong password."
 }
}
  
proc setHost uhost {
 set host [lindex [split $uhost @] 1]
 set n [llength [split $host .]]
 if {[regexp -all {[A-z]{1,}(\.?)} $host] == $n && ![regexp {[0-9]} $host]} {
  set ehost *!*[string trimleft $uhost ~]
 } else if {[string match "*.users.quakenet.org" $host]} {
  set ehost *!*[string trimleft $uhost ~]
 } {
  set ehost [maskhost $uhost]
 }
 set ehost
}
Now try and implement the rest. Reading tcl-commands.doc is very helpful.
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

thanks alot for your concern I will surely get started for something now. thanks again
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

well, here is the try by me lets see if its good enough and if there are mistakes please correct them thanks.

Code: Select all

############
## User management Tcl by Honey_bee @ Quakenet

bind msg - register register:nick 
bind msg - addhost addhost:nick 
bind msg - chhandle chhandle:nick
bind msg - chpass chpass:nick
bind msg - auth auth:nick
bind msg - deauth deauth:nick

# register the user. 
proc register:nick {n u h a} { 
global botnick
 set pass [lindex [split $a] 0]
 if {$a == ""} {
 puthelp "NOTICE $n :Usage: /msg $botnick REGISTER <your password>"
 return 1
}
 if {$pass == ""} {
 puthelp "NOTICE $n :You need to specify password try /msg $botnick <you password>"
 return 1
}
 if {[validuser $h] == 1} {
 puthelp "NOTICE $n : $h is already registered, try to change your nickname /nick <new nick> and try again."
 putlog "$n tried to get registered with handle $h, which is already in use."
 return 1
}
 if {$hand == "*" && $a != ""} { 
  adduser $n [setHost $u] 
  setuser $n PASS [lindex [split $a] 0] 
  sendnote UM honey_bee "A new User is added with handle: $n and hostmask [setHost $u]"
  puthelp "notice $n :You've been added with handle $n." 
 } { 
  puthelp "notice $n :user with nickname < $h > already registered or you didn't specify a password." 
 } 
} 

# add a new host. 
proc addhost:nick {n u h a} { 
global botnick
 set hh [lindex [split $a] 0] 
 set p [lindex [split $a] 1] 
 if {$a == ""} {
 puthelp "NOTICE $n :Usage: /msg $botnick addhost <your password>"
 return 1
}
 if {$p == ""} {
 puthelp "NOTICE $n :You need to specify password try /msg $botnick addhost <you password>"
 return 1
}
 if {[validuser $h] != 1} {
 puthelp "NOTICE $n :You are not REGISTERED, try to register yourself /msg $botnick REGISTER <yourpass>"
 return 1
}
 if {[passwdok $hh ""] == 1} {
	puthelp "NOTICE $n :You don't have a password set, try to set a password /msg $botnick HELP PASS"
 return 1
}
 if {[passwdok $hh $p] != 1} {
	puthelp "NOTICE $n : You have supplied a wrong password try again."
 return 1
}
 if {[validuser $hh] && [passwdok $hh $p]} { 
  setuser $hh HOSTS [setHost $u] 
  sendnote UM honey_bee "New host is added $hh: [setHost $u]"
  puthelp "notice $n :Added you new host to handle $hh." 
 } { 
  puthelp "notice $n :Invalid handle or wrong password." 
 } 
} 
  
proc chhandle:nick {n u h a} { 
global botnick
set newhandle [lindex $a 0]
set p [lrange $a 1 end]
 if {$a == ""} {
 puthelp "NOTICE $n :Usage: /msg $botnick chhandle <newhandle> <your password>"
 return 1
}
 if {$p == ""} {
 puthelp "NOTICE $n :You need to specify password try /msg $botnick <you password>"
 return 1
}
 if {[validuser $newhandle] == 1} {
 puthelp "NOTICE $n :This handle is already owned by someone try another."
 return 1
}
 if {[validuser $h] != 1} {
 puthelp "NOTICE $n :You are not REGISTERED, try to register yourself /msg $botnick REGISTER <yourpass>"
 return 1
}
if {[passwdok $h ""] == 1} {
	puthelp "NOTICE $n :You don't have a password set, try to set a password /msg $botnick HELP PASS"
 return 1
}
if {[passwdok $h $p] != 1} {
	puthelp "NOTICE $n : You have supplied a wrong password try again."
 return 1
}
if {[validuser $h] && [passwdok $h $p]} { 
  chhandle $h $newhandle
  sendnote UM honey_bee "changed handle for $h to $newhandle"
  puthelp "notice $n :Your handle is successfully changed." 
 } { 
  puthelp "notice $n :unable to change your hostmask right now, contact an OP" 
 } 
} 

proc chpass:nick {n u h a} { 
global botnick
 set hh [lindex [split $a] 0] 
 set p [lindex [split $a] 1]
 if {$a == ""} {
 puthelp "NOTICE $n :Usage: /msg $botnick chpass <new password>"
 return 1
}
 if {$p == ""} {
 puthelp "NOTICE $n :You need to specify password try /msg $botnick chpass <newpass>"
 return 1
}
 if {[validuser $hh] != 1} {
 puthelp "NOTICE $n :You are not REGISTERED, try to register yourself /msg $botnick REGISTER <yourpass>"
 return 1
}
 if {[passwdok $hh ""] == 1} {
	puthelp "NOTICE $n :You don't have a password set, try to set a password /msg $botnick HELP PASS"
 return 1
}
 if {[validuser $hh] { 
  setuser $hh PASS $p 
  puthelp "notice $n :Your password is successfully changed." 
 } { 
  puthelp "notice $n :unable to change your password right now, contact an OP" 
 } 
} 

proc auth:nick {n u h a} {
 global botnick
 set p [lindex $a 0]
  if {$p == ""} {
  puthelp "NOTICE $n :Usage: /msg $botnick auth <password>"
  return 0
 }
  if {[matchattr $h C] == 1} {
  puthelp "NOTICE $n : You are already Authenticated."
  return 0
 }
  if {[validuser $h] != 1} {
 puthelp "NOTICE $n : Your are not REGISTERED yet, try /msg $botnick REGISTER <your password>"
 return 1
}
  set ch [passwdok $h ""]
  if {$ch == 1} {
  puthelp "NOTICE $n :No password set. Type /msg $botnick PASS <password>"
  return 0
 }
  if {[passwdok $h $p] == 0} {
  puthelp "NOTICE $n :Incorrect password, login failed!"
 }
  if {[passwdok $h $p] == 1} {
  foreach userhost [getuser $h HOSTS] {
  if {[string tolower [setHost $u]] == [string tolower $userhost]} {
  putlog "host [setHost $u] is already present in $h HOSTS: $userhost"
  return 1
 } else {
  # this will make sure if the current host is added if not lets add it
  setuser $hh HOSTS [setHost $u]
  chattr $hh +C
  puthelp "NOTICE $nick :login successful."
  }
 }

proc deauth:nick {n u h a} {
 global X botnick
 if {$a == ""} {
  puthelp "NOTICE $n : Usage: /msg $botnick deauth <password>"
  return 0
 }
 if {[matchattr $h C] == 0} {
  puthelp "NOTICE $n : You never authenticated."
  return 0
 }
 if {[passwdok $hand $a] == 1} {
  chattr $h -C
  puthelp "NOTICE $n : DeAuthentication successful"
 }
 if {[passwdok $h $a] == 0} {
  puthelp "NOTICE $n : DeAuthentication failed"
 }
}

proc setHost uhost { 
 set host [lindex [split $uhost @] 1] 
 set n [llength [split $host .]] 
 if {[regexp -all {[A-z]{1,}(\.?)} $host] == $n && ![regexp {[0-9]} $host]} { 
  set ehost *!*[string trimleft $uhost ~] 
 } else if {[string match "*.users.quakenet.org" $host]} { 
  set ehost *!*[string trimleft $uhost ~] 
 } { 
  set ehost [maskhost $uhost] 
 } 
 set ehost 
}
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Try it and see if it works. If there're any errors then paste the error log.

A tip I can provide is to code logically; for example:
In the register proc you have

Code: Select all

if {$a == ""} {
and then you have

Code: Select all

if {$pass == ""} {
but pass is the first word in $a, so logically those two if-statements are the same (this applies on the rest of the script too). So you can improve your code by avoiding these repetitions.

Also, improve the format of your code. Instead of:

Code: Select all

proc register:nick {n u h a} {
global botnick
 set pass [lindex [split $a] 0]
 if {$a == ""} {
 puthelp "NOTICE $n :Usage: /msg $botnick REGISTER <your password>"
 return 1
}
 # rest goes here...
}
try

Code: Select all

proc register:nick {n u h a} {
global botnick
 set pass [lindex [split $a] 0]
 if {$a == ""} {
  puthelp "NOTICE $n :Usage: /msg $botnick REGISTER <your password>"
  return 1
 }
 # rest goes here....
}
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Trying to match to an unsplitted "$a" will cause an error if there is a brace in the password afaik, I'd use something like

Code: Select all

if {[llength [split $a]] < 1} {
 puthelp "NOTICE $n :Usage: /msg $botnick REGISTER <your password>"
} elseif {[validuser $n] || [validuser $h]} {
 puthelp "NOTICE $n :User already exists."
} else {
 adduser $n [setHost $u]; setuser $n PASS [lindex [split $a] 0] 
 # other stuff
}
PS: Instead of using things like

Code: Select all

if {[matchattr $h C] == "0"} {
It's easier to just write

Code: Select all

if {![matchattr $h C]} {
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

Is it possible to restrict users not to trigger a command more than 3 times if the password supplied is incorrect?
and if they tirgger it more than 3 times they will be ignored for lets say X mints.
I'm trying to figure that out but found it to be kinda too difficult. thanks for all the help
Last edited by honeybee on Tue Jan 10, 2006 5:16 pm, edited 1 time in total.
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

Sir_Fz: the host for QuakeNet registered users is still *!ident@username.users.quakenet.org like
, I wanted it to be
*!*@honeybee.users.quakenet.org
can you please change it?
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

honeybee wrote:Is it possible to restrict users not to trigger a command more than 3 times if the password supplied is incorrect?
and if they tirgger it more than 3 times they will be ignored for lets say X mints.
I'm trying to figure that out but found it to be kinda too difficult. thanks for all the help
Something like:

Code: Select all

proc wrongPass {v o s} {
 upvar $v uv
 if {![info exists uv]} {
  set uv [list [unixtime] 0]; return 0
 }
 foreach {ct co} $uv {break}
 if {[unixtime]-$ct > $s} {
  set uv [list [unixtime] 0]; return 0
 }
 if {$co >= $o} {
  return 1
 }
 return 0
}
and in each proc add:

Code: Select all

if {![wrongPass wrongPass([string tolower $nick]) 3 180]} {
 if {![passwdok $hand $pass]} {
  foreach {foo bar} $wrongPass([string tolower $nick]) {break}
  set wrongPass([string tolower $nick]) [list [unixtime] [incr bar]]
 } {
  unset wrongPass([stringtolower $nick])
  # do stuff...
 }
}
SYNTAX: isFlood <global-variable> <limit> <seconds>
Sir_Fz: the host for QuakeNet registered users is still *!ident@username.users.quakenet.org like
Quote:
*!*sexy@honeybee.users.quakenet.org
, I wanted it to be
Quote:
*!*@honeybee.users.quakenet.org

can you please change it?
You didn't say tha in your initial post, you said
honeybee wrote:4) registered quakenet users eg: *!honey@honey.users.quakenet.org
But to fix it, just change the 2nd

Code: Select all

set ehost *!*[string trimleft $uhost ~]
to

Code: Select all

set ehost *!*@[lindex [split $uhost @] 1]
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

I replaced the 2nd code wit this

Code: Select all

set ehost *!*@[lindex [split $uhost @] 1]
but it still banning *!*ident@xyz.users.quakenet.org
and ..
I was using ...

Code: Select all

if {[passwdok $h $oldpass] != 1} {
 puthelp "NOTICE $n : password inncorrect try again."
 return 1
}
I removed it with your code, i have loaded the proc wrongPass but it doesnt seems to work:

Code: Select all

if {![wrongPass wrongPass([string tolower $n]) 3 180]} { 
 if {![passwdok $h $oldpass]} {
  puthelp "NOTICE $n : password incorrect try again."
  foreach {foo bar} $wrongPass([string tolower $n]) {break} 
  set wrongPass([string tolower $n]) [list [unixtime] [incr bar]] 
 } { 
  unset wrongPass([stringtolower $]) 
  puthelp "NOTICE $n : Password incorrect, ignoring for 3 mints. try laters"
 } 
  return 1
}
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

proc setHost uhost {
 set host [lindex [split $uhost @] 1]
 set n [llength [split $host .]]
 if {[string match "*.users.quakenet.org" $host]} {
  set ehost *!*@[lindex [split $uhost @] 1]
 } elseif {[regexp -all {[A-z]{1,}(\.?)} $host] == $n && ![regexp {[0-9]} $host]} {
  set ehost *!*[string trimleft $uhost ~]
 } {
  set ehost [maskhost $uhost]
 }
 set ehost
}
and try

Code: Select all

proc rightPass {v o s n h op} {
 upvar $v uv
 if {![info exists uv]} {
  set uv [list [unixtime] 0]
 }
 foreach {ct co} $uv {break}
 if {[unixtime]-$ct > $s} {
  set uv [list [unixtime] 0]
  foreach {ct co} $uv {break}
 }
 if {$co >= $o} {return 0}
 if {![passwdok $h $op]} {
   puthelp "NOTICE $n :password incorrect try again."
   set uv [list [unixtime] [incr co]]
   return 0
 }
 unset uv
 return 1
}
And then use

Code: Select all

if {[rightPass wrongPass([string tolower $n]) 3 180 $n $h $oldpass]} {
 # He got the right pass
}
rightPass will return 0 if he got the wrongPass or if he flooded.
h
honeybee
Halfop
Posts: 80
Joined: Sun Jan 01, 2006 12:42 pm

Post by honeybee »

I'm sorry i had no internet, anyways Sir_fz thaks for all of your help I'm really very grateful to you, though the max correct password check didnt worked but I'm did some public testing, I will contact if i have to learn more thanks again
Post Reply