88 lines
3.0 KiB
Ruby
88 lines
3.0 KiB
Ruby
class Sshguard < Formula
|
|
desc "Protect from brute force attacks against SSH"
|
|
homepage "https://www.sshguard.net/"
|
|
url "https://downloads.sourceforge.net/project/sshguard/sshguard/2.4.1/sshguard-2.4.1.tar.gz"
|
|
sha256 "875d02e6e67dced614790ed5e36aef1160edea940f353a79306cbb1852af3c67"
|
|
version_scheme 1
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "24aa4cab661aa1ecdf1c2f20e80de6cd7bc90ec928a7d251dbd0d45b0983e0b1"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "9a11ca09ad3478fbd84a62c21e94c4f9997fedd210fd3ac271a8abb9fc006267"
|
|
sha256 cellar: :any_skip_relocation, catalina: "77cd7948bbc56730642e7698416d00b8313cb1273919d762f55d6054c1631e25"
|
|
sha256 cellar: :any_skip_relocation, mojave: "6b817c8751e409999328cdf22aba24701af0ab9c02d1d9c652285dacaa4968bd"
|
|
sha256 cellar: :any_skip_relocation, high_sierra: "0f006d36404600cb1053df6073142d394cbe166525ab37cb62a4a8c56b7f369f"
|
|
end
|
|
|
|
head do
|
|
url "https://bitbucket.org/sshguard/sshguard.git"
|
|
|
|
depends_on "autoconf" => :build
|
|
depends_on "automake" => :build
|
|
depends_on "docutils" => :build
|
|
end
|
|
|
|
def install
|
|
system "autoreconf", "-fiv" if build.head?
|
|
system "./configure", "--disable-dependency-tracking",
|
|
"--disable-silent-rules",
|
|
"--prefix=#{prefix}",
|
|
"--sysconfdir=#{etc}"
|
|
system "make", "install"
|
|
inreplace man8/"sshguard.8", "%PREFIX%/etc/", "#{etc}/"
|
|
cp "examples/sshguard.conf.sample", "examples/sshguard.conf"
|
|
inreplace "examples/sshguard.conf" do |s|
|
|
s.gsub!(/^#BACKEND=.*$/, "BACKEND=\"#{opt_libexec}/sshg-fw-pf\"")
|
|
if MacOS.version >= :sierra
|
|
s.gsub! %r{^#LOGREADER="/usr/bin/log}, "LOGREADER=\"/usr/bin/log"
|
|
else
|
|
s.gsub!(/^#FILES.*$/, "FILES=/var/log/system.log")
|
|
end
|
|
end
|
|
etc.install "examples/sshguard.conf"
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
Add the following lines to /etc/pf.conf to block entries in the sshguard
|
|
table (replace $ext_if with your WAN interface):
|
|
|
|
table <sshguard> persist
|
|
block in quick on $ext_if proto tcp from <sshguard> to any port 22 label "ssh bruteforce"
|
|
|
|
Then run sudo pfctl -f /etc/pf.conf to reload the rules.
|
|
EOS
|
|
end
|
|
|
|
plist_options startup: true
|
|
|
|
def plist
|
|
<<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_sbin}/sshguard</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
require "pty"
|
|
PTY.spawn(sbin/"sshguard", "-v") do |r, _w, pid|
|
|
assert_equal "SSHGuard #{version}", r.read.strip
|
|
ensure
|
|
Process.wait pid
|
|
end
|
|
end
|
|
end
|