Example #1
0
        public IActionResult NewSiteConfig([FromBody] NewSiteConfigDto data)
        {
            if (BCrypt.Net.BCrypt.EnhancedVerify(data.secret, _metaInfo.GetValue(MetaKeys.AdminPassword)))
            {
                _locker.AddSiteConfig(data.host, data.type, data.content);
                return(Ok());
            }

            return(StatusCode(403));
        }
Example #2
0
        public IActionResult Get()
        {
            var rpSecret = _metaInfo.GetValue(MetaKeys.ReverseProxySecretHeaderName);

            if (!string.IsNullOrWhiteSpace(rpSecret) &&
                string.IsNullOrWhiteSpace(HttpContext.Request.Headers[rpSecret]))
            {
                _logger.LogWarning($"Unauthorized: {HttpContext.Connection.RemoteIpAddress}");
                return(BadRequest());
            }

            var ip   = HttpContext.Request.Headers["X-Real-IP"].FirstOrDefault();
            var host = HttpContext.Request.Host.Host;

            if (_locker.GetIpAllowedForHost(ip, host))
            {
                _logger.LogInformation($"Allowed: {ip} ({host})");
                return(Ok());
            }

            _logger.LogInformation($"Blocked: {ip} ({host})");
            return(StatusCode(403));
        }