# -*- 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.0
PortGroup           github 1.0

github.setup        Ettercap ettercap 0.8.2 v
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  0300c1b65f0074e62da516bb414f98903e9dc235 \
                    sha256  7bf56fd89e751ef95d33c5515142908b4d5e18e3238be187ba271358dad4ac27

depends_build-append \
                    port:pkgconfig

depends_lib         path:lib/libssl.dylib:openssl \
                    port:libpcap \
                    port:libnet11 \
                    port:ncurses \
                    port:pcre \
                    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
}

configure.args-append \
                    -DBUNDLED_LIBS=OFF \
                    -DENABLE_CURSES=ON \
                    -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}

# 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

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 \
        README.BINARIES \
        README.BUGS \
        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 gtk description {Enable GTK2 support} {
    depends_lib-append      port:gtk2

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

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

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

default_variants    +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.
"
}