attr_accessor :response
end
+class PingServlet < WEBrick::HTTPServlet::AbstractServlet
+ def initialize(server, bot)
+ super server
+ @bot = bot
+ end
+
+ def do_GET(req, res)
+ res['Content-Type'] = 'text/plain'
+ res.body = "pong\r\n"
+ end
+end
+
class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, bot)
super server
botuser = @bot.auth.get_botuser(username)
raise 'Permission Denied' if not botuser or botuser.password != password
- ret = dispatch_command(command, botuser, ip)
+ begin
+ ret = dispatch_command(command, botuser, ip)
+ rescue
+ debug '[webservice] error: ' + $!.to_s
+ debug $@.join("\n")
+ end
res.status = 200
if req['Accept'] == 'application/json'
@port = @bot.config['webservice.port']
@host = @bot.config['webservice.host']
@server = nil
+ @bot.webservice = self
begin
start_service if @bot.config['webservice.autostart']
rescue => e
@server = WEBrick::HTTPServer.new(opts)
debug 'webservice started: ' + opts.inspect
@server.mount('/dispatch', DispatchServlet, @bot)
+ @server.mount('/ping', PingServlet, @bot)
Thread.new { @server.start }
end
m.reply s
end
+ def register_servlet(plugin, servlet)
+ @server.mount('/plugin/%s' % plugin.name, servlet, plugin, @bot)
+ end
+
end
webservice = WebServiceModule.new