512758e6eb
Realign trailing EOS.
97 lines
2.9 KiB
Ruby
97 lines
2.9 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.1.0/sshguard-2.1.0.tar.gz"
|
|
sha256 "21252a4834ad8408df384ee4ddf468624aa9de9cead5afde1c77380a48cf028a"
|
|
version_scheme 1
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "eb13c51b65f9007163ade54a5f01699da82b4ba3c225af30a57ed05593bfe60e" => :high_sierra
|
|
sha256 "63b4d94b319432258792e9d00a0474c11c1bc37fe19deee1c7ee62f2980c982d" => :sierra
|
|
sha256 "4231ea2fbff92a76b72e8f3707e4600451e9315740cd5864c54641dc8bd75857" => :el_capitan
|
|
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-#{firewall}\""
|
|
if MacOS.version >= :sierra
|
|
s.gsub! %r{^#LOGREADER="/usr/bin/log}, "LOGREADER=\"/usr/bin/log"
|
|
s.gsub! %q{\"sshd\")'"}, %q{"sshd")'"}
|
|
else
|
|
s.gsub! /^#FILES.*$/, "FILES=#{log_path}"
|
|
end
|
|
end
|
|
etc.install "examples/sshguard.conf"
|
|
end
|
|
|
|
def firewall
|
|
(MacOS.version >= :lion) ? "pf" : "ipfw"
|
|
end
|
|
|
|
def log_path
|
|
(MacOS.version >= :lion) ? "/var/log/system.log" : "/var/log/secure.log"
|
|
end
|
|
|
|
def caveats
|
|
if MacOS.version >= :lion then <<~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
|
|
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|
|
|
begin
|
|
assert_equal "SSHGuard #{version}", r.read.strip
|
|
ensure
|
|
Process.wait pid
|
|
end
|
|
end
|
|
end
|
|
end
|