       logmsg = "#{modulename}: #{msg.envelope.user.name} requested: " +
         "blacklist #{bl.type} #{bl.val} expires #{bl.expires}"
       robot.logger.info logmsg
+
       data.push bl
       fs.writeFileSync blacklistfile, JSON.stringify(data), 'utf-8'
+
+      logmsg = "#{modulename}: robot responded to #{msg.envelope.user.name}: " +
+        "added entry to blacklist"
+      robot.logger.info logmsg


    robot.send {room: msg.message?.user?.name}, cmds.join "\n"

  robot.respond /fw (?:blacklist|b)$/i, (msg) ->
    logmsg = "#{modulename}: #{msg.envelope.user.name} requested: blacklist"
    robot.logger.info logmsg
    data = fs.readFileSync blacklistfile, 'utf-8'

    robot.send {room: msg.message?.user?.name}, data.join "\n"

  robot.respond /fw (?:blacklist|b) (url|cidr) ([^ ]+)(?: ([^ ]+)|)$/i, (msg) ->
    bl =

modulename = 'fw'
blacklistfile = modulename + ".json"

module.exports = (robot) ->

  data = []
  try
    fwdata = fs.readFileSync blacklistfile, 'utf-8'
    if fwdata
      data = JSON.parse(fwdata)
      console.log "#{modulename} blacklist loaded: " + data.length + " entries"
  catch error
    console.log('Unable to read file', error) unless error.code is 'ENOENT'

  robot.router.get "/#{robot.name}/#{modulename}/blacklist/url", (req, res) ->
    clientip = req.connection.remoteAddress || req.socket.remoteAddress ||
      req.connection.socket.remoteAddress
    logmsg = "#{modulename}: web request from #{clientip}: url blacklist"
    robot.logger.info logmsg

    arr = []
    for obj in data
      if obj.type == 'url' and moment(obj.expires).isAfter()
        arr.push obj.val
    content = '# nothing here yet! #'
    content = arr.join "\n" if arr.length
    res.setHeader 'content-type', 'text/plain'
    res.end content

    logmsg = "#{modulename}: robot responded to web request: sent url blacklist"
    robot.logger.info logmsg

  robot.router.get "/#{robot.name}/#{modulename}/blacklist/cidr", (req, res) ->
    clientip = req.connection.remoteAddress || req.socket.remoteAddress ||
      req.connection.socket.remoteAddress
    logmsg = "#{modulename}: web request from #{clientip}: cidr blacklist"
    robot.logger.info logmsg

    arr = []
    for obj in data
      if obj.type == 'cidr' and moment(obj.expires).isAfter()
        arr.push obj.val
    content = '# nothing here yet! #'
    content = arr.join "\n" if arr.length
    res.setHeader 'content-type', 'text/plain'
    res.end content

    logmsg = "#{modulename}: robot responded to web request: " +
      "sent cidr blacklist"
    robot.logger.info logmsg

  robot.respond /fw(?: help|)$/, (msg) ->
    cmds = []
    arr = [
      modulename + " blacklist - show blacklist"
