 #   xxxxxxxxxxx [required] - API KEY
 #
 # Commands:
-#   hubot fw - fw commands
+#   hubot firewall - firewall commands
 #
 # Notes:
 #   requires hubot-auth be present

    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}: get url blacklist"
    robot.logger.info logmsg

    arr = []
    for obj in fwdata.blacklist
      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

    return

  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}: get cidr blacklist"
    robot.logger.info logmsg

    arr = []
    for obj in fwdata.blacklist
      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

    return

  robot.respond /fw(?: help| h|)$/, (msg) ->
    cmds = ['```']
    arr = [
      modulename + " blacklist [(cidr|url) [searchterm]] - show blacklist"
      modulename + " blacklist add (url|cidr) <weburl.tld/etc|x.x.x.x> - add to blacklist"
      modulename + " blacklist del (url|cidr) <weburl.tld/etc|x.x.x.x> - del from blacklist"
      modulename + " blacklist notify [username] - notify when changes happen"
      modulename + " blacklist subscribers - list notify subscribers"
    ]

    for str in arr


    return

  robot.respond /(?:firewall|fw) show (whitelist|wl|w|blacklist|bl|b)(?: (cidr|url)(?: ([^ ]+)|)|)$/i, (msg) ->
    return showList robot, msg

  robot.respond /(?:firewall|fw) add (whitelist|wl|w|blacklist|bl|b) (url|cidr) ([^ ]+)(?: ([^ ]+)|)$/i, (msg) ->
    return unless isAuthorized msg
    return unless is2fa msg

    return addListEntry robot, msg

  robot.respond /(?:firewall|fw) (?:delete|del|d) (whitelist|wl|w|blacklist|bl|b) (url|cidr) ([^ ]+)$/i, (msg) ->
    return unless isAuthorized msg
    return unless is2fa msg

    return deleteListEntry robot, msg

  robot.respond /(?:firewall|fw) (?:subscribe|sub)(?: ([^ ]+))$/i, (msg) ->
    return subscribe robot, msg

  robot.respond /(?:firewall|fw) show (?:subscribers|s)$/i, (msg) ->
    return showSubscribers robot, msg

  robot.respond /(?:firewall|fw) (?:unsubscribe|unsub)(?: ([^ ]+))$/i, (msg) ->
    return unsubscribe robot, msg

