4 # :title: rbot auth management from IRC
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 class AuthModule < CoreBotModule
13 # The namespace migration causes each Irc::Auth::PermissionSet to be
14 # unrecoverable, and we have to rename their class name to
15 # Irc::Bot::Auth::PermissionSet
16 @registry.recovery = Proc.new { |val|
17 patched = val.sub("o:\035Irc::Auth::PermissionSet", "o:\042Irc::Bot::Auth::PermissionSet")
18 Marshal.restore(patched)
21 load_array(:default, true)
22 debug "initialized auth. Botusers: #{@bot.auth.save_array.pretty_inspect}"
29 def save_array(key=:default)
31 @registry[key] = @bot.auth.save_array
32 @bot.auth.reset_changed
33 debug "saved botusers (#{key}): #{@registry[key].pretty_inspect}"
37 def load_array(key=:default, forced=false)
38 debug "loading botusers (#{key}): #{@registry[key].pretty_inspect}"
39 @bot.auth.load_array(@registry[key], forced) if @registry.has_key?(key)
42 # The permission parameters accept arguments with the following syntax:
43 # cmd_path... [on #chan .... | in here | in private]
44 # This auxiliary method scans the array _ar_ to see if it matches
45 # the given syntax: it expects + or - signs in front of _cmd_path_
46 # elements when _setting_ = true
48 # It returns an array whose first element is the array of cmd_path,
49 # the second element is an array of locations and third an array of
50 # warnings occurred while parsing the strings
52 def parse_args(ar, setting)
57 next_must_be_chan = false
60 ar.each_with_index { |x, i|
61 if doing_cmds # parse cmd_path
62 # check if the list is done
63 if x == "on" or x == "in"
65 next_must_be_chan = true if x == "on"
68 if "+-".include?(x[0])
69 warns << ArgumentError.new(_("please do not use + or - in front of command %{command} when resetting") % {:command => x}) unless setting
71 warns << ArgumentError.new(_("+ or - expected in front of %{string}") % {:string => x}) if setting
74 else # parse locations
80 case next_must_be_chan
82 locs << x.gsub(/^here$/,'_').gsub(/^private$/,'?')
84 warns << ArgumentError.new(_("'%{string}' doesn't look like a channel name") % {:string => x}) unless @bot.server.supports[:chantypes].include?(x[0])
93 warns << _("trailing comma") if want_more
94 warns << _("you probably forgot a comma") unless last_idx == ar.length - 1
95 return cmds, locs, warns
98 def auth_edit_perm(m, params)
100 setting = m.message.split[1] == "set"
101 splits = params[:args]
103 has_for = splits[-2] == "for"
104 return usage(m) unless has_for
107 user = @bot.auth.get_botuser(splits[-1].sub(/^all$/,"everyone"))
109 return m.reply(_("couldn't find botuser %{name}") % {:name => splits[-1]})
111 return m.reply(_("you can't change permissions for %{username}") % {:username => user.username}) if user.owner?
112 splits.slice!(-2,2) if has_for
114 cmds, locs, warns = parse_args(splits, setting)
115 errs = warns.select { |w| w.kind_of?(Exception) }
118 m.reply _("couldn't satisfy your request: %{errors}") % {:errors => errs.join(',')}
129 ch = "?" if loc == "_"
131 ch = m.target.to_s if loc == "_"
135 val = setval[0].chr == '+'
137 user.set_permission(cmd, val, ch)
140 user.reset_permission(cmd, ch)
145 m.reply "something went wrong while trying to set the permissions"
148 @bot.auth.set_changed
149 debug "user #{user} permissions changed"
153 def auth_view_perm(m, params)
155 if params[:user].nil?
156 user = get_botusername_for(m.source)
157 return m.reply(_("you are owner, you can do anything")) if user.owner?
159 user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone"))
160 return m.reply(_("owner can do anything")) if user.owner?
163 return m.reply(_("couldn't find botuser %{name}") % {:name => params[:user]})
168 next if val.perm.empty?
171 str << _("on any channel: ")
173 str << _("in private: ")
175 str << _("on #{k}: ")
178 val.perm.each { |cmd, bool|
179 sub << (bool ? "+" : "-")
182 str.last << sub.join(', ')
185 m.reply _("no permissions set for %{user}") % {:user => user.username}
187 m.reply _("permissions for %{user}:: %{permissions}") %
188 { :user => user.username, :permissions => str.join('; ')}
192 def auth_search_perm(m, p)
193 pattern = Regexp.new(p[:pattern].to_s)
194 results = @bot.plugins.maps.select { |k, v| k.match(pattern) }
195 count = results.length
196 max = @bot.config['send.max_lines']
197 extra = (count > max ? _(". only %{max} will be shown") : "") % { :max => max }
198 m.reply _("%{count} commands found matching %{pattern}%{extra}") % {
199 :count => count, :pattern => pattern, :extra => extra
202 results[0,max].each { |cmd, hash|
203 m.reply _("%{cmd}: %{perms}") % {
205 :perms => hash[:auth].join(", ")
210 def find_auth(pseudo)
211 k = pseudo.plugin.intern
212 cmds = @bot.plugins.commands
215 cmds[k][:botmodule].handler.each do |tmpl|
216 options, failure = tmpl.recognize(pseudo)
218 auth = tmpl.options[:full_auth_path]
225 def auth_allow_deny(m, p)
227 botuser = @bot.auth.get_botuser(p[:user].sub(/^all$/,"everyone"))
229 return m.reply(_("couldn't find botuser %{name}") % {:name => p[:user]})
232 if p[:where].to_s.empty?
235 where = m.parse_channel_list(p[:where].to_s).first # should only be one anyway
238 # pseudo-message to find the template. The source is ignored, and the
239 # target is set according to where the template should be checked
240 # (public or private)
241 # This might still fail in the case of 'everywhere' for commands there are
242 # really only private
245 pseudo_target = @bot.myself
247 pseudo_target = m.channel
249 pseudo_target = m.server.channel(where)
252 pseudo = PrivMessage.new(bot, m.server, m.source, pseudo_target, p[:stuff].to_s)
254 auth_path = find_auth(pseudo)
259 if @bot.auth.permit?(botuser, auth_path, where)
260 return m.reply(_("%{user} can already do that") % {:user => botuser}) if allow
262 return m.reply(_("%{user} can't do that already") % {:user => botuser}) if !allow
264 cmd = PrivMessage.new(bot, m.server, m.source, m.target, "permissions set %{sign}%{path} %{where} for %{user}" % {
267 :sign => (allow ? '+' : '-'),
268 :where => p[:where].to_s
272 m.reply(_("sorry, %{cmd} doesn't look like a valid command. maybe you misspelled it, or you need to specify it should be in private?") % {
273 :cmd => p[:stuff].to_s
279 auth_allow_deny(m, p.merge(:allow => true))
283 auth_allow_deny(m, p.merge(:allow => false))
286 def get_botuser_for(user)
287 @bot.auth.irc_to_botuser(user)
290 def get_botusername_for(user)
291 get_botuser_for(user).username
295 m.reply _("welcome, %{user}") % {:user => get_botusername_for(m.source)}
298 def auth_auth(m, params)
299 params[:botuser] = 'owner'
303 def auth_login(m, params)
305 case @bot.auth.login(m.source, params[:botuser], params[:password])
308 @bot.auth.set_changed
310 m.reply _("sorry, can't do")
313 m.reply _("couldn't login: %{exception}") % {:exception => e}
318 def auth_autologin(m, params)
319 u = do_autologin(m.source)
321 m.reply _("I couldn't find anything to let you login automatically")
327 def do_autologin(user)
328 @bot.auth.autologin(user)
331 def auth_whoami(m, params)
332 m.reply _("you are %{who}") % {
333 :who => get_botusername_for(m.source).gsub(
334 /^everyone$/, _("no one that I know")).gsub(
335 /^owner$/, _("my boss"))
339 def auth_whois(m, params)
340 return auth_whoami(m, params) if !m.public?
341 u = m.channel.users[params[:user]]
343 return m.reply("I don't see anyone named '#{params[:user]}' here") unless u
345 m.reply _("#{params[:user]} is %{who}") % {
346 :who => get_botusername_for(u).gsub(
347 /^everyone$/, _("no one that I know")).gsub(
348 /^owner$/, _("my boss"))
352 def help(cmd, topic="")
355 return _("login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. When using the full form, you must contact the bot in private. <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")
357 return _("whoami: names the botuser you're linked to")
359 return _("who is <user>: names the botuser <user> is linked to")
363 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")
364 when "set", "reset", "[re]set", "(re)set"
365 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)")
367 return _("permissions view [for <user>]: display the permissions for user <user>")
369 return _("permissions search <pattern>: display the permissions associated with the commands matching <pattern>")
371 return _("permission topics: syntax, (re)set, view, search")
376 return _("user show <what> : shows info about the user; <what> can be any of autologin, login-by-mask, netmasks")
378 return _("user enable|disable <what> : turns on or off <what> (autologin, login-by-mask)")
380 return _("user set password <blah> : sets the user password to <blah>; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long")
382 return _("user add|rm netmask <mask> : adds/removes netmask <mask> from the list of netmasks known to the botuser you're linked to")
384 return _("user reset <what> : resets <what> to the default values. <what> can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)")
386 return _("user tell <who> the password for <botuser> : contacts <who> in private to tell him/her the password for <botuser>")
388 return _("user create <name> <password> : create botuser named <name> with password <password>. The password can be omitted, in which case a random one will be generated. The <name> should only contain alphanumeric characters and the underscore (_)")
390 return _("user list : lists all the botusers")
392 return _("user destroy <botuser> : destroys <botuser>. This function %{highlight}must%{highlight} be called in two steps. On the first call <botuser> is queued for destruction. On the second call, which must be in the form 'user confirm destroy <botuser>', the botuser will be destroyed. If you want to cancel the destruction, issue the command 'user cancel destroy <botuser>'") % {:highlight => Bold}
394 return _("user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy")
397 return _("auth <masterpassword>: log in as the bot owner; other commands: login, whoami, permission syntax, permissions [re]set, permissions view, user, meet, hello, allow, prevent")
399 return _("meet <nick> [as <user>]: creates a bot user for nick, calling it user (defaults to the nick itself)")
401 return _("hello: creates a bot user for the person issuing the command")
403 return _("allow <user> to do <sample command> [<where>]: gives botuser <user> the permissions to execute a command such as the provided sample command (in private or in channel, according to the optional <where>)")
405 return _("deny <user> from doing <sample command> [<where>]: removes from botuser <user> the permissions to execute a command such as the provided sample command (in private or in channel, according to the optional <where>)")
407 return _("auth commands: auth, login, whoami, who, permission[s], user, meet, hello, allow, deny")
412 _("sorry, I need more arguments to %{command}") % {:command => cmd}
415 def not_args(cmd, *stuff)
416 _("I can only %{command} these: %{arguments}") %
417 {:command => cmd, :arguments => stuff.join(', ')}
420 def set_prop(botuser, prop, val)
421 k = prop.to_s.gsub("-","_")
422 botuser.send( (k + "=").to_sym, val)
423 if prop == :password and botuser == @bot.auth.botowner
424 @bot.config.items[:'auth.password'].set_string(@bot.auth.botowner.password)
428 def reset_prop(botuser, prop)
429 k = prop.to_s.gsub("-","_")
430 botuser.send( ("reset_"+k).to_sym)
433 def ask_bool_prop(botuser, prop)
434 k = prop.to_s.gsub("-","_")
435 botuser.send( (k + "?").to_sym)
438 def auth_manage_user(m, params)
439 splits = params[:data]
442 return auth_whoami(m, params) if cmd.nil?
444 botuser = get_botuser_for(m.source)
445 # By default, we do stuff on the botuser the irc user is bound to
448 has_for = splits[-2] == "for"
450 butarget = @bot.auth.get_botuser(splits[-1]) rescue nil
451 return m.reply(_("no such bot user %{user}") % {:user => splits[-1]}) unless butarget
454 return m.reply(_("you can't mess with %{user}") % {:user => butarget.username}) if butarget.owner? && botuser != butarget
456 bools = [:autologin, :"login-by-mask"]
457 can_set = [:password]
458 can_addrm = [:netmasks]
459 can_reset = bools + can_set + can_addrm
460 can_show = can_reset + ["perms"]
466 return m.reply(_("you can't see the properties of %{user}") %
467 {:user => butarget.username}) if botuser != butarget &&
468 !botuser.permit?("auth::show::other")
474 if botuser != butarget
475 return m.reply(_("no way I'm telling you the master password!")) if butarget == @bot.auth.botowner
476 return m.reply(_("you can't ask for someone else's password"))
478 return m.reply(_("c'mon, you can't be asking me seriously to tell you the password in public!")) if m.public?
479 return m.reply(_("the password for %{user} is %{password}") %
480 { :user => butarget.username, :password => butarget.password })
482 props = splits[1..-1]
489 next if k == :password
492 if ask_bool_prop(butarget, k)
493 str << _("can %{action}") % {:action => k}
495 str << _("can not %{action}") % {:action => k}
498 if butarget.netmasks.empty?
499 str << _("knows no netmasks")
501 str << _("knows %{netmasks}") % {:netmasks => butarget.netmasks.join(", ")}
505 return m.reply("#{butarget.username} #{str.join('; ')}")
507 when :enable, :disable
508 return m.reply(_("you can't change the default user")) if butarget.default? && !botuser.permit?("auth::edit::other::default")
509 return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if butarget != botuser && !botuser.permit?("auth::edit::other")
511 return m.reply(need_args(cmd)) unless splits[1]
514 splits[1..-1].each { |a|
516 if bools.include?(arg)
517 set_prop(butarget, arg, cmd.to_sym == :enable)
524 m.reply(_("I ignored %{things} because %{reason}") % {
525 :things => skipped.join(', '),
526 :reason => not_args(cmd, *bools)}) unless skipped.empty?
528 m.reply _("I haven't changed anything")
530 @bot.auth.set_changed
531 return auth_manage_user(m, {:data => ["show"] + things + ["for", butarget.username] })
535 return m.reply(_("you can't change the default user")) if
536 butarget.default? && !botuser.permit?("auth::edit::default")
537 return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if
538 butarget != botuser && !botuser.permit?("auth::edit::other")
540 return m.reply(need_args(cmd)) unless splits[1]
541 arg = splits[1].to_sym
542 return m.reply(not_args(cmd, *can_set)) unless can_set.include?(arg)
544 return m.reply(need_args([cmd, splits[1]].join(" "))) unless argarg
545 if arg == :password && m.public?
546 return m.reply(_("is that a joke? setting the password in public?"))
548 set_prop(butarget, arg, argarg)
549 @bot.auth.set_changed
550 auth_manage_user(m, {:data => ["show", arg.to_s, "for", butarget.username] })
553 return m.reply(_("you can't change the default user")) if
554 butarget.default? && !botuser.permit?("auth::edit::default")
555 return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if
556 butarget != botuser && !botuser.permit?("auth::edit::other")
558 return m.reply(need_args(cmd)) unless splits[1]
561 splits[1..-1].each { |a|
563 if can_reset.include?(arg)
564 reset_prop(butarget, arg)
571 m.reply(_("I ignored %{things} because %{reason}") %
572 { :things => skipped.join(', '),
573 :reason => not_args(cmd, *can_reset)}) unless skipped.empty?
575 m.reply _("I haven't changed anything")
577 @bot.auth.set_changed
578 @bot.say(m.source, _("the password for %{user} is now %{password}") %
579 {:user => butarget.username, :password => butarget.password}) if
580 things.include?("password")
581 return auth_manage_user(m, {:data => (["show"] + things - ["password"]) + ["for", butarget.username]})
584 when :add, :rm, :remove, :del, :delete
585 return m.reply(_("you can't change the default user")) if
586 butarget.default? && !botuser.permit?("auth::edit::default")
587 return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if
588 butarget != botuser && !botuser.permit?("auth::edit::other")
591 if arg.nil? or arg !~ /netmasks?/ or splits[2].nil?
592 return m.reply(_("I can only add/remove netmasks. See +help user add+ for more instructions"))
595 method = cmd.to_sym == :add ? :add_netmask : :delete_netmask
599 splits[2..-1].each { |mask|
601 butarget.send(method, mask.to_irc_netmask(:server => @bot.server))
603 debug "failed with #{e.message}"
604 debug e.backtrace.join("\n")
608 m.reply "I failed to #{cmd} #{failed.join(', ')}" unless failed.empty?
609 @bot.auth.set_changed
610 return auth_manage_user(m, {:data => ["show", "netmasks", "for", butarget.username] })
613 m.reply _("sorry, I don't know how to %{request}") % {:request => m.message}
616 m.reply _("couldn't %{cmd}: %{exception}") % {:cmd => cmd, :exception => e}
620 def auth_meet(m, params)
623 # we are actually responding to a 'hello' command
624 unless m.botuser.transient?
625 m.reply @bot.lang.get('hello_X') % m.botuser
631 # m.channel is always an Irc::Channel because the command is either
632 # public-only 'meet' or private/public 'hello' which was handled by
633 # the !nick case, so this shouldn't fail
634 irc_user = m.channel.users[nick]
635 return m.reply("I don't see anyone named '#{nick}' here") unless irc_user
638 buname = params[:user] || nick
640 call_event(:botuser,:pre_perm, {:irc_user => irc_user, :bot_user => buname})
641 met = @bot.auth.make_permanent(irc_user, buname)
642 @bot.auth.set_changed
643 call_event(:botuser,:post_perm, {:irc_user => irc_user, :bot_user => buname})
644 m.reply @bot.lang.get('hello_X') % met
645 @bot.say nick, _("you are now registered as %{buname}. I created a random password for you : %{pass} and you can change it at any time by telling me 'user set password <password>' in private" % {
647 :pass => met.password
650 # or can this happen for other cases too?
651 # TODO autologin if forced
652 m.reply _("but I already know %{buname}" % {:buname => buname})
654 m.reply _("I had problems meeting %{nick}: %{e}" % { :nick => nick, :e => e })
658 def auth_tell_password(m, params)
661 botuser = @bot.auth.get_botuser(params[:botuser])
663 return m.reply(_("couldn't find botuser %{user}") % {:user => params[:botuser]})
665 return m.reply(_("I'm not telling the master password to anyone, pal")) if botuser == @bot.auth.botowner
666 msg = _("the password for botuser %{user} is %{password}") %
667 {:user => botuser.username, :password => botuser.password}
669 @bot.say m.source, _("I told %{user} that %{message}") % {:user => user, :message => msg}
672 def auth_create_user(m, params)
674 password = params[:password]
675 return m.reply(_("are you nuts, creating a botuser with a publicly known password?")) if m.public? and not password.nil?
677 bu = @bot.auth.create_botuser(name, password)
678 @bot.auth.set_changed
680 m.reply(_("failed to create %{user}: %{exception}") % {:user => name, :exception => e})
681 debug e.inspect + "\n" + e.backtrace.join("\n")
684 m.reply(_("created botuser %{user}") % {:user => bu.username})
687 def auth_list_users(m, params)
688 # TODO name regexp to filter results
689 list = @bot.auth.save_array.inject([]) { |list, x| ['everyone', 'owner'].include?(x[:username]) ? list : list << x[:username] }
690 if defined?(@destroy_q)
692 @destroy_q.include?(x) ? x + _(" (queued for destruction)") : x
695 return m.reply(_("I have no botusers other than the default ones")) if list.empty?
696 return m.reply(n_("botuser: %{list}", "botusers: %{list}", list.length) %
697 {:list => list.join(', ')})
700 def auth_destroy_user(m, params)
701 @destroy_q = [] unless defined?(@destroy_q)
702 buname = params[:name]
703 return m.reply(_("You can't destroy %{user}") % {:user => buname}) if
704 ["everyone", "owner"].include?(buname)
705 mod = params[:modifier].to_sym rescue nil
707 buser_array = @bot.auth.save_array
708 buser_hash = buser_array.inject({}) { |h, u|
713 return m.reply(_("no such botuser %{user}") % {:user=>buname}) unless
714 buser_hash.keys.include?(buname)
718 if @destroy_q.include?(buname)
719 @destroy_q.delete(buname)
720 m.reply(_("%{user} removed from the destruction queue") % {:user=>buname})
722 m.reply(_("%{user} was not queued for destruction") % {:user=>buname})
726 if @destroy_q.include?(buname)
727 return m.reply(_("%{user} already queued for destruction, use %{highlight}user confirm destroy %{user}%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})
730 return m.reply(_("%{user} queued for destruction, use %{highlight}user confirm destroy %{user}%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})
734 return m.reply(_("%{user} is not queued for destruction yet") %
735 {:user=>buname}) unless @destroy_q.include?(buname)
736 buser_array.delete_if { |u|
737 u[:username] == buname
739 @destroy_q.delete(buname)
740 @bot.auth.load_array(buser_array, true)
741 @bot.auth.set_changed
743 return m.reply(_("failed: %{exception}") % {:exception => e})
745 return m.reply(_("botuser %{user} destroyed") % {:user => buname})
749 def auth_copy_ren_user(m, params)
750 source = Auth::BotUser.sanitize_username(params[:source])
751 dest = Auth::BotUser.sanitize_username(params[:dest])
752 return m.reply(_("please don't touch the default users")) unless
753 (["everyone", "owner"] & [source, dest]).empty?
755 buser_array = @bot.auth.save_array
756 buser_hash = buser_array.inject({}) { |h, u|
761 return m.reply(_("no such botuser %{source}") % {:source=>source}) unless
762 buser_hash.keys.include?(source)
763 return m.reply(_("botuser %{dest} exists already") % {:dest=>dest}) if
764 buser_hash.keys.include?(dest)
766 copying = m.message.split[1] == "copy"
770 buser_hash[source].each { |k, val|
774 h = buser_hash[source]
777 buser_array << h if copying
779 @bot.auth.load_array(buser_array, true)
780 @bot.auth.set_changed
781 call_event(:botuser, copying ? :copy : :rename, :source => source, :dest => dest)
783 return m.reply(_("failed: %{exception}") % {:exception=>e})
786 m.reply(_("botuser %{source} copied to %{dest}") %
787 {:source=>source, :dest=>dest})
789 m.reply(_("botuser %{source} renamed to %{dest}") %
790 {:source=>source, :dest=>dest})
795 def auth_export(m, params)
797 exportfile = "#{@bot.botclass}/new-auth.users"
799 what = params[:things]
801 has_to = what[-2] == "to"
803 exportfile = "#{@bot.botclass}/#{what[-1]}"
809 m.reply _("selecting data to export ...")
811 buser_array = @bot.auth.save_array
812 buser_hash = buser_array.inject({}) { |h, u|
820 we_want = buser_hash.delete_if { |key, val|
821 not what.include?(key)
825 m.reply _("preparing data for export ...")
828 we_want.each { |k, val|
835 yaml_hash[k][kk] = []
837 yaml_hash[k][kk] << {
838 :fullform => nm.fullform,
839 :casemap => nm.casemap.to_s
848 m.reply _("failed to prepare data: %{exception}") % {:exception=>e}
849 debug e.backtrace.dup.unshift(e.inspect).join("\n")
853 m.reply _("exporting to %{file} ...") % {:file=>exportfile}
855 # m.reply yaml_hash.inspect
856 File.open(exportfile, "w") do |file|
857 file.puts YAML::dump(yaml_hash)
860 m.reply _("failed to export users: %{exception}") % {:exception=>e}
861 debug e.backtrace.dup.unshift(e.inspect).join("\n")
867 def auth_import(m, params)
869 importfile = "#{@bot.botclass}/new-auth.users"
871 what = params[:things]
873 has_from = what[-2] == "from"
875 importfile = "#{@bot.botclass}/#{what[-1]}"
881 m.reply _("reading %{file} ...") % {:file=>importfile}
883 yaml_hash = YAML::load_file(importfile)
885 m.reply _("failed to import from: %{exception}") % {:exception=>e}
886 debug e.backtrace.dup.unshift(e.inspect).join("\n")
890 # m.reply yaml_hash.inspect
892 m.reply _("selecting data to import ...")
897 we_want = yaml_hash.delete_if { |key, val|
898 not what.include?(key)
902 m.reply _("parsing data from import ...")
907 yaml_hash.each { |k, val|
908 buser_hash[k] = { :username => k }
912 buser_hash[k][kk] = []
914 buser_hash[k][kk] << nm[:fullform].to_irc_netmask(:casemap => nm[:casemap].to_irc_casemap).to_irc_netmask(:server => @bot.server)
917 buser_hash[k][kk] = v
922 m.reply _("failed to parse data: %{exception}") % {:exception=>e}
923 debug e.backtrace.dup.unshift(e.inspect).join("\n")
927 # m.reply buser_hash.inspect
929 org_buser_array = @bot.auth.save_array
930 org_buser_hash = org_buser_array.inject({}) { |h, u|
935 # TODO we may want to do a(n optional) key-by-key merge
937 org_buser_hash.merge!(buser_hash)
938 new_buser_array = org_buser_hash.values
939 @bot.auth.load_array(new_buser_array, true)
940 @bot.auth.set_changed
947 auth = AuthModule.new
949 auth.map "user export *things",
950 :action => 'auth_export',
951 :defaults => { :things => ['all'] },
952 :auth_path => ':manage:fedex:'
954 auth.map "user import *things",
955 :action => 'auth_import',
956 :auth_path => ':manage:fedex:'
958 auth.map "user create :name :password",
959 :action => 'auth_create_user',
960 :defaults => {:password => nil},
961 :auth_path => ':manage:'
963 auth.map "user [:modifier] destroy :name",
964 :action => 'auth_destroy_user',
965 :requirements => { :modifier => /^(cancel|confirm)?$/ },
966 :defaults => { :modifier => '' },
967 :auth_path => ':manage::destroy!'
969 auth.map "user copy :source [to] :dest",
970 :action => 'auth_copy_ren_user',
971 :auth_path => ':manage:'
973 auth.map "user rename :source [to] :dest",
974 :action => 'auth_copy_ren_user',
975 :auth_path => ':manage:'
977 auth.map "meet :nick [as :user]",
978 :action => 'auth_meet',
979 :auth_path => 'user::manage', :private => false
982 :action => 'auth_meet',
983 :auth_path => 'user::manage::meet'
985 auth.default_auth("user::manage", false)
986 auth.default_auth("user::manage::meet::hello", true)
988 auth.map "user tell :user the password for :botuser",
989 :action => 'auth_tell_password',
990 :auth_path => ':manage:'
992 auth.map "user list",
993 :action => 'auth_list_users',
996 auth.map "user *data",
997 :action => 'auth_manage_user'
999 auth.map "allow :user to do *stuff [*where]",
1000 :action => 'auth_allow',
1001 :requirements => {:where => /^(?:anywhere|everywhere|[io]n \S+)$/},
1002 :auth_path => ':edit::other:'
1004 auth.map "deny :user from doing *stuff [*where]",
1005 :action => 'auth_deny',
1006 :requirements => {:where => /^(?:anywhere|everywhere|[io]n \S+)$/},
1007 :auth_path => ':edit::other:'
1009 auth.default_auth("user", true)
1010 auth.default_auth("edit::other", false)
1013 :action => 'auth_whoami',
1016 auth.map "who is :user",
1017 :action => 'auth_whois',
1020 auth.map "auth :password",
1021 :action => 'auth_auth',
1023 :auth_path => '!login!'
1025 auth.map "login :botuser :password",
1026 :action => 'auth_login',
1028 :defaults => { :password => nil },
1029 :auth_path => '!login!'
1031 auth.map "login :botuser",
1032 :action => 'auth_login',
1033 :auth_path => '!login!'
1036 :action => 'auth_autologin',
1037 :auth_path => '!login!'
1039 auth.map "permissions set *args",
1040 :action => 'auth_edit_perm',
1041 :auth_path => ':edit::set:'
1043 auth.map "permissions reset *args",
1044 :action => 'auth_edit_perm',
1045 :auth_path => ':edit::set:'
1047 auth.map "permissions view [for :user]",
1048 :action => 'auth_view_perm',
1051 auth.map "permissions search *pattern",
1052 :action => 'auth_search_perm',
1055 auth.default_auth('*', false)