|
|
|
@ -211,8 +211,19 @@ class CloudService: |
|
|
|
|
else: |
|
|
|
|
d = {} |
|
|
|
|
now = int(utils.get_current_datetime().timestamp()) |
|
|
|
|
if now - d.get(username, 0) < self.vhost_rate_limit_secs: |
|
|
|
|
raise RateLimitError(f'Please wait {self.vhost_rate_limit_secs} seconds') |
|
|
|
|
if username not in d: |
|
|
|
|
return |
|
|
|
|
time_passed = now - d[username] |
|
|
|
|
if time_passed < self.vhost_rate_limit_secs: |
|
|
|
|
time_remaining = self.vhost_rate_limit_secs - time_passed |
|
|
|
|
raise RateLimitError(f'Please wait {time_remaining} seconds') |
|
|
|
|
|
|
|
|
|
def _update_rate_limit_timestamp(self, username: str): |
|
|
|
|
if os.path.exists(self.vhost_rate_limit_file): |
|
|
|
|
d = json.load(open(self.vhost_rate_limit_file)) |
|
|
|
|
else: |
|
|
|
|
d = {} |
|
|
|
|
now = int(utils.get_current_datetime().timestamp()) |
|
|
|
|
d[username] = now |
|
|
|
|
json.dump(d, open(self.vhost_rate_limit_file, 'w')) |
|
|
|
|
|
|
|
|
@ -225,7 +236,11 @@ class CloudService: |
|
|
|
|
if not self._is_valid_ip_address(ip_address): |
|
|
|
|
raise InvalidIPError() |
|
|
|
|
self._check_rate_limit(username) |
|
|
|
|
# Wait for the vhost creation to succeed before updating the timestamp; |
|
|
|
|
# we don't want to force people to wait if they had a typo in their |
|
|
|
|
# domain or something. |
|
|
|
|
self.vhost_mgr.create_vhost(username, domain, ip_address) |
|
|
|
|
self._update_rate_limit_timestamp(username) |
|
|
|
|
|
|
|
|
|
def delete_vhost(self, username: str, domain: str): |
|
|
|
|
if not self._is_valid_domain(username, domain): |
|
|
|
|