- (let* ((line (read-line in-port))
- (selector (string-trim-both line)))
- (let-values (((local-ip remote-ip) (tcp-addresses in-port)))
- (print "Accepted connection from " remote-ip
- " on " (seconds->string))
- (condition-case
- (begin
- (with-output-to-port out-port
- (lambda ()
- (serve-selector (if (= (string-length selector) 0)
- "/"
- selector)
- config)))
- (print "... served selector '" selector "'. Closing connection."))
- (o (exn)
- (print-error-message o out-port)
- (print-error-message o)
- (print "Error while attempting to serve selector " selector ".")))))
+ (let-values (((local-ip remote-ip) (tcp-addresses in-port)))
+ (print "Accepted connection from " remote-ip
+ " on " (seconds->string))
+ (condition-case
+ (if (or (null? (config-blacklist config))
+ (not (member remote-ip
+ (with-input-from-file
+ (config-blacklist config)
+ read))))
+ (let* ((line (read-line in-port))
+ (selector (string-trim-both line)))
+ (condition-case
+ (begin
+ (with-output-to-port out-port
+ (lambda ()
+ (serve-selector selector config)))
+ (print "... served selector '" selector "'. Closing connection."))
+ (o (exn)
+ (print-error-message o out-port)
+ (print-error-message o)
+ (print "Error while attempting to serve selector " selector "."))))
+ (begin
+ (print "Connection from blacklisted IP. Closing.")
+ (with-output-to-port out-port
+ (lambda ()
+ (print* "Refusing to serve to IP " remote-ip ".\r\n")
+ (unless (null? (config-blacklist-resp config))
+ (for-each (lambda (l) (print* l "\r\n"))
+ (with-input-from-file
+ (config-blacklist-resp config)
+ read-lines)))
+ (print* ".\r\n")))))
+ (o (exn)
+ (print-error-message o))))