egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

userfile management

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Thu Jan 05, 2006 3:58 am    Post subject: userfile management Reply with quote

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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Jan 05, 2006 9:33 am    Post subject: Reply with quote

This proc should return the type of host you wish:
Code:
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Thu Jan 05, 2006 11:17 am    Post subject: Reply with quote

thanks fz, anymore help will be appreciated and ofcourse I would like to hear from demond aswell
Back to top
View user's profile Send private message
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Fri Jan 06, 2006 4:46 pm    Post subject: Reply with quote

is only sir_fz active on forum?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Jan 06, 2006 7:56 pm    Post subject: Reply with quote

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:
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Sat Jan 07, 2006 10:10 am    Post subject: Reply with quote

thanks alot for your concern I will surely get started for something now. thanks again
Back to top
View user's profile Send private message
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Sun Jan 08, 2006 7:17 pm    Post subject: Reply with quote

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

Code:

############
## 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
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Jan 08, 2006 8:58 pm    Post subject: Reply with quote

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:
if {$a == ""} {

and then you have
Code:
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:
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:
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....
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Mon Jan 09, 2006 5:11 am    Post subject: Reply with quote

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:
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:
if {[matchattr $h C] == "0"} {


It's easier to just write

Code:
if {![matchattr $h C]} {
Back to top
View user's profile Send private message
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Tue Jan 10, 2006 3:09 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Tue Jan 10, 2006 7:05 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jan 10, 2006 5:43 pm    Post subject: Reply with quote

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:
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:
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>
Quote:
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:
set ehost *!*[string trimleft $uhost ~]

to
Code:
set ehost *!*@[lindex [split $uhost @] 1]

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Wed Jan 11, 2006 9:28 am    Post subject: Reply with quote

I replaced the 2nd code wit this

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

Code:
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:
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
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Jan 11, 2006 6:10 pm    Post subject: Reply with quote

Code:
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:
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:
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
honeybee
Halfop


Joined: 01 Jan 2006
Posts: 80

PostPosted: Fri Jan 27, 2006 11:31 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber