contract Whitelist is Ownable {
  event EnableWhitelist();
  event DisableWhitelist();
  event AddWhiteListed(address addr);
  event RemoveWhiteListed(address addr);

  bool private _whitelistEnable = false;

  mapping (address => bool) private _whitelist;

   /**
   * @dev add addresses to the whitelist
   * @param addrs addresses
   * @return true if at least one address was added to the whitelist,
   * false if all addresses were already in the whitelist
   */
  function addWhiteListAddr(address[] addrs)
    public
    onlyOwner
  {
    uint256 len = addrs.length;
    for (uint256 i = 0; i < len; i++) {
      _addAddressToWhitelist(addrs[i]);
    }
  }

  /**
   * @dev remove an address from the whitelist
   * @param addr address
   * @return true if the address was removed from the whitelist,
   * false if the address wasn't in the whitelist in the first place
   */
  function removeWhiteListAddr(address addr)
    public
    onlyOwner
  {
    require(addr != address(0), "address is zero");
    _whitelist[addr] = false;
    emit RemoveWhiteListed(addr);
  }

  function whitelistEnabled() public view returns(bool) {
    return _whitelistEnable;
  }

  function enableWhitelist() public onlyOwner {
    _whitelistEnable = true;
    emit EnableWhitelist();
  }

  function disableWhitelist() public onlyOwner {
    _whitelistEnable = true;
    emit DisableWhitelist();
  }

  modifier onlyAuthorised(address beneficiary) {
    require(_isWhiteListAddr(beneficiary),"Not authorised");
    _;
  }

  /**
   * @dev add an address to the whitelist
   * @param addr address
   * @return true if the address was added to the whitelist, false if the address was already in the whitelist
   */
  function _addAddressToWhitelist(address addr)
    internal
    onlyOwner
  {
    require(addr != address(0), "address is zero");
    _whitelist[addr] = true;
    emit AddWhiteListed(addr);
  }

  /**
   * @dev getter to determine if address is in whitelist
   */
  function _isWhiteListAddr(address addr)
    internal
    view
    returns (bool)
  {
    require(addr != address(0), "address is zero");

    if (whitelistEnabled()) {
      return _whitelist[addr];
    }
    // if white list disabled, this function always returns 'true'.
    return true;
  }
}
/**
 * @title Whitelist
 */
function addWhiteListAddr(address[] addrs)
  public
  onlyOwner
{
  uint256 len = addrs.length;
  for (uint256 i = 0; i < len; i++) {
    _addAddressToWhitelist(addrs[i]);
  }
}

/**
 * @dev add addresses to the whitelist
 * @param addrs addresses
 * @return true if at least one address was added to the whitelist,
 * false if all addresses were already in the whitelist
 */