# -*- 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           perl5 1.0

name                sqlninja
version             0.2.6-r1
revision            0
conflicts           sqlninja-devel
categories          security net
supported_archs     noarch
platforms           any
maintainers         nomaintainer
license             GPL-3+

description         Microsoft SQL Server SQL Injection vulnerability tester

long_description    Sqlninja is a tool targeted to exploit SQL Injection \
                    vulnerabilities on a web application that uses \
                    Microsoft SQL Server as its back-end.

# homepage doesn't support https
homepage            http://sqlninja.sourceforge.net/
master_sites        sourceforge
extract.suffix      .tgz

checksums           rmd160  1313f381e302da64cb6f9a9b1ec86bd842412129 \
                    sha256  7f8e9103d3fe58eb6e6f1476474589f7e5ca501703a82ae5299bd7a708342bc5 \
                    size    454841

livecheck.regex     {(\d+\.\d+\.\d+-r.*)</a></h3>}

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

depends_lib         port:p${perl5.major}-netpacket \
                    port:p${perl5.major}-net-pcap \
                    port:p${perl5.major}-net-dns \
                    port:p${perl5.major}-net-rawip \
                    port:p${perl5.major}-io-socket-ssl

subport ${name}-devel {
    version         0.2.999-alpha1
    revision        0
    conflicts       sqlninja
    checksums       rmd160  68a5ccbf3e301ca12b970c485b0ee2a309336caa \
                    sha256  cd1e51434fdbe8900fbfb117b753e390415a1821b0b917812f1f6040ab55f9d6 \
                    size    613341

    depends_lib-append \
                    port:p${perl5.major}-dbd-sqlite \
                    port:p${perl5.major}-dbi

    patchfiles      patch-sqlninja-lib-path.diff \
                    patch-lib-utils.pl.diff

    post-patch {
        reinplace "s|@@SQLNINJA_LIB_PATH@@|${prefix}/lib/${subport}|" \
            ${worksrcpath}/sqlninja
    }

    livecheck.regex {(\d+\.\d+\.\d+-.*)</a></h3>}
}

use_configure       no
build {}

destroot {
    xinstall -m 755 ${worksrcpath}/sqlninja ${destroot}${prefix}/bin/sqlninja
    xinstall -d ${destroot}${prefix}/share/doc/${subport}
    xinstall -m 644 ${worksrcpath}/README ${destroot}${prefix}/share/doc/${subport}/
    xinstall -m 644 ${worksrcpath}/sqlninja-howto.html ${destroot}${prefix}/share/doc/${subport}/
    xinstall -d ${destroot}${prefix}/share/examples/${subport}
    copy ${worksrcpath}/scripts ${destroot}${prefix}/share/examples/${subport}/
    copy ${worksrcpath}/sources ${destroot}${prefix}/share/examples/${subport}/
    reinplace "s|/usr/bin/env perl|${prefix}/bin/perl${perl5.major}|" ${destroot}${prefix}/bin/sqlninja

    if {${subport} eq ${name}} {
        if {[file exists ${worksrcpath}/sqlninja.conf.example]} {
            xinstall -m 644 ${worksrcpath}/sqlninja.conf.example ${destroot}${prefix}/share/examples/${subport}/
        }
    } else {
        if {[file exists ${worksrcpath}/sqlninja.conf]} {
            xinstall -m 644 ${worksrcpath}/sqlninja.conf ${destroot}${prefix}/share/examples/${subport}/sqlninja.conf.example
        }
        xinstall -d ${destroot}${prefix}/lib/${subport}
        copy ${worksrcpath}/lib ${destroot}${prefix}/lib/${subport}
    }
}

livecheck.type      regex
livecheck.url       ${homepage}/download.html