 
 modulename = 'fw'
 blacklistfile = modulename + ".json"
+
+isAuthorized = (robot, msg) ->
+  u = msg.envelope.user
+  return true if robot.auth.hasRole(u,'fw') and robot.auth.isSudo(u)
+  msg.reply "Not authorized.  Missing fw role or not sudo."
+  return false
+
+isSudo = (msg) ->
+  u = msg.envelope.user
+  return true if robot.auth.isSudo(u)
+  msg.reply "Sudo required."
+  return false
 
 module.exports = (robot) ->
 

    robot.logger.info logmsg

  robot.respond /fw (?:blacklist|b) add (url|cidr) ([^ ]+)(?: ([^ ]+)|)$/i, (msg) ->
    unless isAuthorized robot, msg, ['fw','sudo']
      errmsg = "Only users with fw and sudo roles allowed this command."
      return msg.reply errmsg

    bl =
      created: moment().format()

      robot.logger.info logmsg

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

    bl_type = msg.match[1]
    bl_search = msg.match[2]
