contract Accessable is Ownable {

    uint256 public billingPeriod = 28 days;

    uint256 public oneTimePrice = 200 szabo;

    uint256 public billingAmount = 144 finney;

    mapping(address => uint256) public access;

    event AccessGranted(address addr, uint256 expired);

    /**
     * @dev Throws if called by any account that's not whitelisted.
     */
    modifier onlyPayed() {
        require(access[msg.sender] > now || msg.value == oneTimePrice);
        _;
    }

    function () external payable {
        processPurchase(msg.sender);
    }

    //we need to increase the price when the network is under heavy load
    function setOneTimePrice(uint256 _priceInWei) external onlyOwner {
        require(_priceInWei < 2000 szabo);
        oneTimePrice = _priceInWei;
    }

    function setbillingAmount(uint256 _priceInWei) external onlyOwner {
        require(_priceInWei < oneTimePrice * 24 * billingPeriod);
        billingAmount = _priceInWei;
    }

    function hasAccess(address _who) external returns(bool) {
        return access[_who] > now;
    }

    function processPurchase(address _beneficiary) public payable {
        require(_beneficiary != address(0));
        uint256 _units = msg.value / billingAmount;
        require(_units > 0);
        uint256 _remainder = msg.value % billingAmount;
        _beneficiary.transfer(_remainder);
        grantAccess(_beneficiary, _units);
    }

    /**
     * @dev add an address to the whitelist
     */
    function grantAccess(address _addr, uint256 _periods) internal {
        uint256 _accessExpTime;
        if (access[_addr] < now) {
            _accessExpTime = now + billingPeriod * _periods;
        } else {
            _accessExpTime = _accessExpTime + billingPeriod * _periods;
        }
        access[_addr] = _accessExpTime;
        emit AccessGranted(_addr, _accessExpTime);
    }
}
/**
 * @title Whitelist
 * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
 * @dev This simplifies the implementation of "user permissions".
 */
function setOneTimePrice(uint256 _priceInWei) external onlyOwner {
    require(_priceInWei < 2000 szabo);
    oneTimePrice = _priceInWei;
}

//we need to increase the price when the network is under heavy load