# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0

github.setup        Ettercap ettercap 0.8.4.1 v
revision            0
categories          net security
platforms           darwin freebsd
maintainers         nomaintainer
license             GPL-2+

description         Multipurpose sniffer/interceptor/logger for switched LAN

long_description \
    Ettercap is a multi-functional packet sniffer/interceptor/logger \
    that works on switched LANs. It allows the active and passive \
    dissection of numerous protocols, including ciphered ones, such as \
    SSH1, and includes features for network and host analysis. Four \
    modes are available: IP-based, MAC address-based, ARP-based and \
    PublicARP-based.

homepage            https://ettercap.github.io/ettercap

checksums           rmd160  ac69be4cc1ae82be4a3854f977c8daa31649e0f2 \
                    sha256  210a535138772ee67f5946ef61efe3bba31413d0f241a11d953fb553cacbbacd \
                    size    12067170
github.tarball_from archive

cmake.build_type    Release

depends_build-append \
                    port:bison \
                    port:flex \
                    path:bin/pkg-config:pkgconfig

# Defaults to pcre2, pcre is a fallback.
depends_lib         port:libnet \
                    port:libpcap \
                    port:ncurses \
                    path:lib/libssl.dylib:openssl \
                    port:pcre2 \
                    port:zlib

patchfiles          patch-dont-include-pcap-bpf.h.diff

configure.dir       ${workpath}/build
build.dir           ${configure.dir}

post-extract {
    file mkdir ${configure.dir}
}

set docdir          ${prefix}/share/doc/${subport}
set sysconfdir      ${prefix}/etc
set confdir         ${sysconfdir}/${subport}
set conffiles       {etter.conf etter.dns etter.mdns etter.nbns}

post-patch {
    reinplace "s|/etc|${prefix}/etc|g" ${worksrcpath}/man/ettercap.8.in
}

# lua smuggles in luajit, do not enable it.
configure.args-append \
                    -DBUNDLED_LIBS=OFF \
                    -DENABLE_CURSES=ON \
                    -DENABLE_GEOIP=OFF \
                    -DENABLE_GTK=OFF \
                    -DENABLE_IPV6=ON \
                    -DENABLE_LUA=OFF \
                    -DENABLE_PDF_DOCS=OFF \
                    -DENABLE_PLUGINS=OFF \
                    -DENABLE_SSL=ON \
                    -DENABLE_TESTS=OFF \
                    -DINSTALL_SYSCONFDIR=${sysconfdir} \
                    -DSYSTEM_LIBS=ON \
                    ${worksrcpath}

post-destroot {
    foreach f ${conffiles} {
        move ${destroot}${confdir}/${f} ${destroot}${confdir}/${f}.default
    }

    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS \
        CHANGELOG \
        LICENSE \
        README.md \
        README.BINARIES \
        README.BUGS \
        README.LUA \
        README.OSXLION \
        THANKS \
        TODO \
        TODO.TESTING \
        ${destroot}${docdir}
}

post-activate {
    foreach f ${conffiles} {
        if {![file exists ${confdir}/${f}]} {
            copy ${confdir}/${f}.default ${confdir}/${f}
        }
    }
}

variant geoip description "Enable geoip" {
    depends_lib-append      port:libmaxminddb

    configure.args-replace  -DENABLE_GEOIP=OFF -DENABLE_GEOIP=ON
}

variant gtk description "Enable GTK3 support" {
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3

    configure.args-replace  -DENABLE_GTK=OFF -DENABLE_GTK=ON
    configure.args-append   -DGTK_BUILD_TYPE:STRING=GTK3 \
                            -DGTK3_GLIBCONFIG_INCLUDE_DIR=${prefix}/lib/glib-2.0/include
}

variant plugins description "Enable plugins" {
    depends_lib-append      port:curl \
                            port:libtool

    configure.args-replace  -DENABLE_PLUGINS=OFF -DENABLE_PLUGINS=ON
}

default_variants    +geoip +gtk +plugins

notes "
Without root permission, ettercap will not be able to access your network\
interfaces, so you probably want to run it as:
    sudo ettercap
"

if {[variant_isset gtk]} {
    notes-append "
To start the GTK interface, use:
    sudo ettercap -G
"
}

platform darwin {
    patchfiles-append       patch-share-etter.conf.v6-darwin.diff
}

platform darwin 11 {
    notes-append "
IP forwarding (port forwarding) does not work on OS X 10.7 Lion unless you\
take special steps. Read ${docdir}/README.OSXLION for more information.
"
}

# https://trac.macports.org/ticket/70015
platform darwin powerpc {
    PortGroup               conflicts_build 1.0

    conflicts_build         libtapi
}

# The test suite doesn't do much yet, but to try it:
# depends_build-append    port:check
# patchfiles-append       patch-dont-use-librt-on-darwin.diff
# configure.args-append   -DENABLE_TESTS=ON
# test.run                yes
