BotConfig.register BotConfigBooleanValue.new( 'auth.login_by_mask',\r
:default => 'false',\r
:desc => 'Set true if new botusers should allow logging in without a password when the user netmask is known')\r
- BotConfig.register BotConfigBooleanValue.new( 'auth.login_auto',\r
+ BotConfig.register BotConfigBooleanValue.new( 'auth.autologin',\r
:default => 'false',\r
:desc => 'Set true if new botusers should try to recognize IRC users without a need to manually login')\r
# BotConfig.register BotConfigIntegerValue.new( 'auth.default_level',\r
@netmasks = NetmaskList.new\r
@perm = {}\r
@login_by_mask = Auth.manager.bot.config['auth.login_by_mask'] unless defined?(@login_by_mask)\r
- @autologin = Auth.manager.bot.config['auth.login_auto'] unless defined?(@autologin)\r
+ @autologin = Auth.manager.bot.config['auth.autologin'] unless defined?(@autologin)\r
end\r
\r
# Inspection\r
# is right. If it is, the Netmask of the user is added to the\r
# list of acceptable Netmask unless it's already matched.\r
def login(user, password)\r
- if password == @password or (password.nil? and @login_by_mask and knows?(user))\r
+ if password == @password or (password.nil? and (@login_by_mask || @autologin) and knows?(user))\r
add_netmask(user) unless knows?(user)\r
debug "#{user} logged in as #{self.inspect}"\r
return true\r
#\r
# It is possible to autologin by Netmask, on request\r
#\r
- def login(user, botusername, pwd)\r
+ def login(user, botusername, pwd=nil)\r
ircuser = user.to_irc_user\r
n = BotUser.sanitize_username(botusername)\r
k = n.to_sym\r
# * everyone on all channels\r
#\r
def permit?(user, cmdtxt, channel=nil)\r
- botuser = irc_to_botuser(user)\r
+ if user.class <= BotUser\r
+ botuser = user\r
+ else\r
+ botuser = irc_to_botuser(user)\r
+ end\r
cmd = cmdtxt.to_irc_auth_command\r
\r
chan = channel\r
m.reply "Ok, #{user} now also has permissions #{params[:args].join(' ')}"\r
end\r
\r
+ def get_botuser_for(user)\r
+ @bot.auth.irc_to_botuser(user)\r
+ end\r
+\r
+ def get_botusername_for(user)\r
+ get_botuser_for(user).username\r
+ end\r
+\r
+ def welcome(user)\r
+ "welcome, #{get_botusername_for(user)}"\r
+ end\r
+\r
def auth_login(m, params)\r
begin\r
case @bot.auth.login(m.source, params[:botuser], params[:password])\r
when true\r
- m.reply "welcome, #{@bot.auth.irc_to_botuser(m.source).username}"\r
+ m.reply welcome(m.source)\r
@bot.auth.set_changed\r
else\r
m.reply "sorry, can't do"\r
end\r
end\r
\r
+ def auth_autologin(m, params)\r
+ u = do_autologin(m.source)\r
+ case u.username\r
+ when 'everyone'\r
+ m.reply "I couldn't find anything to let you login automatically"\r
+ else\r
+ m.reply welcome(m.source)\r
+ end\r
+ end\r
+\r
+ def do_autologin(user)\r
+ @bot.auth.autologin(user)\r
+ end\r
+\r
+ def auth_whoami(m, params)\r
+ rep = ""\r
+ # if m.public?\r
+ # rep << m.source.nick << ", "\r
+ # end\r
+ rep << "you are "\r
+ rep << get_botusername_for(m.source).gsub(/^everyone$/, "no one that I know").gsub(/^owner$/, "my boss")\r
+ m.reply rep\r
+ end\r
+\r
+ def help(plugin, topic="")\r
+ case topic\r
+ when /^login/\r
+ return "login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. <pass> can be omitted if <botuser> allows login-by-mask and your netmask is among the known ones. if <botuser> is omitted too autologin will be attempted"\r
+ when /^whoami/\r
+ return "whoami: names the botuser you're linked to"\r
+ when /^permission syntax/\r
+ return "A permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix"\r
+ when /^permission/\r
+ return "permissions (re)set <permission> [in <channel>] for <user>: sets or resets the permissions for botuser <user> in channel <channel> (use ? to change the permissions for private addressing)"\r
+ else\r
+ return "#{name}: login, whoami, permission syntax, permissions"\r
+ end\r
+ end\r
+\r
+ def need_args(cmd)\r
+ "sorry, I need more arguments to #{cmd}"\r
+ end\r
+\r
+ def not_args(cmd, *stuff)\r
+ "I can only #{cmd} these: #{stuff.join(', ')}"\r
+ end\r
+\r
+ def set_bool_prop(botuser, prop, val)\r
+ k = prop.to_s.gsub("-","_")\r
+ botuser.send( (k + "=").to_sym, val)\r
+ end\r
+\r
+ def reset_bool_prop(botuser, prop)\r
+ k = prop.to_s.gsub("-","_")\r
+ botuser.send( (k + "=").to_sym, @bot.config['auth.' + k])\r
+ end\r
+\r
+ def ask_bool_prop(botuser, prop)\r
+ k = prop.to_s.gsub("-","_")\r
+ botuser.send( (k + "?").to_sym)\r
+ end\r
+\r
+ def auth_manage_user(m, params)\r
+ splits = params[:data]\r
+\r
+ cmd = splits.first\r
+ return auth_whoami(m, params) if cmd.nil?\r
+\r
+ botuser = get_botuser_for(m.source)\r
+ # By default, we do stuff on the botuser the irc user is bound to\r
+ butarget = botuser\r
+\r
+ has_for = splits[-2] == "for"\r
+ butarget = @bot.auth.get_botuser(splits[-1]) if has_for\r
+ return m.reply "you can't mess with #{butarget.username}" if butarget == @bot.auth.botowner && botuser != butarget\r
+ splits.slice!(-2,2) if has_for\r
+\r
+ bools = [:autologin, :"login-by-mask"]\r
+ can_set = [:password] + bools\r
+ can_reset = can_set + [:netmasks]\r
+\r
+ case cmd.to_sym\r
+\r
+ when :show, :list\r
+ return "you can't see the properties of #{butarget.username}" if botuser != butarget and !botuser.permit?("auth::show::other")\r
+\r
+ case splits[1]\r
+ when nil, "all"\r
+ props = can_reset\r
+ when "password"\r
+ return m.reply "you can't ask for someone else's password" if botuser != butarget and !botuser.permit?("auth::show::other::password")\r
+ return m.reply "c'mon, you can't be asking me seriously to tell you the password in public!" if m.public?\r
+ return m.reply "the password for #{butarget.username} is #{butarget.password}"\r
+ else\r
+ props = splits[1..-1]\r
+ end\r
+\r
+ str = []\r
+\r
+ props.each { |arg|\r
+ k = arg.to_sym\r
+ next if k == :password\r
+ case k\r
+ when *bools\r
+ str << "can"\r
+ str.last << "not" unless ask_bool_prop(butarget, k)\r
+ str.last << " #{k}"\r
+ when :netmasks\r
+ str << "knows "\r
+ if butarget.netmasks.empty?\r
+ str.last << "no netmasks"\r
+ else\r
+ str.last << butarget.netmasks.join(", ")\r
+ end\r
+ end\r
+ }\r
+ return m.reply "#{butarget.username} #{str.join('; ')}"\r
+\r
+ when :enable, :disable\r
+ return m.reply "you can't change the default user" if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
+ return m.reply "you can't edit #{butarget.username}" if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+\r
+ return m.reply need_args(cmd) unless splits[1]\r
+ things = []\r
+ splits[1..-1].each { |a|\r
+ arg = a.to_sym\r
+ if bools.include?(arg)\r
+ set_bool_prop(butarget, arg, cmd.to_sym == :enable)\r
+ else\r
+ m.reply not_args(cmd, *bools)\r
+ end\r
+ things << a\r
+ }\r
+ return auth_manage_user(m, {:data => ["show"] + things })\r
+\r
+ when :set\r
+ return m.reply "you can't change the default user" if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
+ return m.reply "you can't edit #{butarget.username}" if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+\r
+ return need_args(cmd) unless splits[1]\r
+ things = []\r
+ # TODO\r
+ #return not_args(cmd, *can_set) unless bools.include?(arg)\r
+\r
+ when :reset\r
+ return m.reply "you can't change the default user" if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
+ return m.reply "you can't edit #{butarget.username}" if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+\r
+ return need_args(cmd) unless splits[1]\r
+ things = []\r
+ # TODO\r
+ else\r
+ m.reply "sorry, I don't know how to #{m.message}"\r
+ end\r
+ end\r
+\r
end\r
\r
auth = AuthModule.new\r
\r
-auth.map "permissions set *args for :user",\r
- :action => 'auth_set',\r
- :auth_path => ':edit::set:'\r
+auth.map "user *data",\r
+ :action => 'auth_manage_user'\r
\r
-auth.map "permissions reset *args for :user",\r
- :action => 'auth_reset',\r
- :auth_path => ':edit::reset:'\r
+auth.default_auth("user", true)\r
+\r
+auth.map "whoami",\r
+ :action => 'auth_whoami',\r
+ :auth_path => '!*!'\r
\r
auth.map "login :botuser :password",\r
:action => 'auth_login',\r
\r
auth.map "login :botuser",\r
:action => 'auth_login',\r
- :defaults => { :password => nil },\r
:auth_path => '!login!'\r
\r
+auth.map "login",\r
+ :action => 'auth_autologin',\r
+ :auth_path => '!login!'\r
+\r
+auth.map "permissions set *args for :user",\r
+ :action => 'auth_set',\r
+ :auth_path => ':edit::set:'\r
+\r
+auth.map "permissions reset *args for :user",\r
+ :action => 'auth_reset',\r
+ :auth_path => ':edit::reset:'\r
+\r
auth.default_auth('*', false)\r
\r