\r
has_to = what[-2] == "to"\r
if has_to\r
- exportfile = what[-1]\r
+ exportfile = "#{@bot.botclass}/#{what[-1]}"\r
what.slice!(-2,2)\r
end\r
\r
\r
m.reply "exporting to #{exportfile} ..."\r
begin\r
+ # m.reply yaml_hash.inspect\r
File.open(exportfile, "w") do |file|\r
file.puts YAML::dump(yaml_hash)\r
end\r
m.reply "done"\r
end\r
\r
+ def auth_import(m, params)\r
+\r
+ importfile = "#{@bot.botclass}/new-auth.users"\r
+\r
+ what = params[:things]\r
+\r
+ has_from = what[-2] == "from"\r
+ if has_from\r
+ importfile = "#{@bot.botclass}/#{what[-1]}"\r
+ what.slice!(-2,2)\r
+ end\r
+\r
+ what.delete("all")\r
+\r
+ m.reply "reading #{importfile} ..."\r
+ begin\r
+ yaml_hash = YAML::load_file(importfile)\r
+ rescue => e\r
+ m.reply "failed to import from: #{e}"\r
+ debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
+ return\r
+ end\r
+\r
+ # m.reply yaml_hash.inspect\r
+\r
+ m.reply "selecting data to import ..."\r
+\r
+ if what.empty?\r
+ we_want = yaml_hash\r
+ else\r
+ we_want = yaml_hash.delete_if { |key, val|\r
+ not what.include?(key)\r
+ }\r
+ end\r
+\r
+ m.reply "parsing data from import ..."\r
+\r
+ buser_hash = {}\r
+\r
+ begin\r
+ yaml_hash.each { |k, val|\r
+ buser_hash[k] = { :username => k }\r
+ val.each { |kk, v|\r
+ case kk\r
+ when :netmasks\r
+ buser_hash[k][kk] = []\r
+ v.each { |nm|\r
+ buser_hash[k][kk] << nm[:fullform].to_irc_netmask(:casemap => nm[:casemap].to_irc_casemap).to_irc_netmask(:server => @bot.server)\r
+ }\r
+ else\r
+ buser_hash[k][kk] = v\r
+ end\r
+ }\r
+ }\r
+ rescue => e\r
+ m.reply "failed to parse data: #{e}"\r
+ debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
+ return\r
+ end\r
+\r
+ # m.reply buser_hash.inspect\r
+\r
+ org_buser_array = @bot.auth.save_array\r
+ org_buser_hash = org_buser_array.inject({}) { |h, u|\r
+ h[u[:username]] = u\r
+ h\r
+ }\r
+\r
+ # TODO we may want to do a(n optional) key-by-key merge\r
+ #\r
+ org_buser_hash.merge!(buser_hash)\r
+ new_buser_array = org_buser_hash.values\r
+ @bot.auth.load_array(new_buser_array, true)\r
+ @bot.auth.set_changed\r
+\r
+ m.reply "done"\r
+ end\r
+\r
end\r
\r
auth = AuthModule.new\r
:defaults => { :things => ['all'] },\r
:auth_path => ':manage:fedex:'\r
\r
-# auth.map "user import",\r
-# :action => 'auth_import',\r
-# :auth_path => ':manage:fedex:'\r
+auth.map "user import *things",\r
+ :action => 'auth_import',\r
+ :auth_path => ':manage:fedex:'\r
\r
auth.map "user create :name :password",\r
:action => 'auth_create_user',\r