# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
_php=php5
pkgname=phpldapadmin
pkgver=1.2.3
pkgrel=4
pkgdesc="Web front-end for managing OpenLDAP"
url="http://phpldapadmin.sourceforge.net"
arch="noarch"
license="GPL-2.0"
depends="${_php} ${_php}-ldap ${_php}-gettext ${_php}-xml"
depends_dev=
makedepends="$depends_dev"
install=
subpackages=
source="http://downloads.sourceforge.net/project/$pkgname/$pkgname-php5/$pkgver/$pkgname-$pkgver.tgz
	$pkgname.additional-template
	phpldapadmin-1.2.3-force-ssha512.patch
	phpldapadmin-1.2.3_changed-password_hash-to-pla_password_hash.patch
	phpldapadmin-1.2.3_fixed-call-to-renamed-function-pla_password_hash.patch
	phpldapadmin-1.2.3_changed-preg_replace-to-preg_replace-callback.patch
	phpldapadmin-1.2.3_use-preg_replace_callback.patch
	CVE-2017-11107.patch
	"

# secfixes:
#   1.2.3-r4:
#   - CVE-2017-11107

_builddir="$srcdir"/$pkgname-$pkgver

prepare() {
	cd "$_builddir"
        for i in $source; do
                case $i in
                *.patch)
                        msg "Applying $i..."
                        if ! patch -s -p1 -N -i "$srcdir"/$i; then
                                echo $i >>failed
                                _patch_failed=1
                        fi
                        ;;
                esac
        done

}

build() {
	cd "$_builddir"
}

package() {
	cd "$_builddir"
	mkdir -p "$pkgdir"/usr/share/webapps/phpldapadmin
	mkdir -p "$pkgdir"/etc
	mv * "$pkgdir"/usr/share/webapps/phpldapadmin
	mv "$pkgdir"/usr/share/webapps/phpldapadmin/config "$pkgdir"/etc/phpldapadmin
	ln -s /etc/phpldapadmin "$pkgdir"/usr/share/webapps/phpldapadmin/config || return 1
	install -Dm644 ../$pkgname.additional-template \
	  "$pkgdir"/usr/share/webapps/phpldapadmin/templates/creation/groupOfNames.xml || return 1
}

sha512sums="58a57ca577586685ebd0d7fde7e299b8945d1693018c7803e19239b79f4b9d72a4d207d53c9f284268e32398108038efafcdb434e634619bfe87db3524d267b6  phpldapadmin-1.2.3.tgz
913cc89bfba3a24064865f091a3bcc6ec88db0824d750e8b3b1f6497b5ac1a1e158ced895f1f85f93607402e9353798b3dd4ccdbb1454713f96937c884456eb7  phpldapadmin.additional-template
aecbf3699af4ae39426c6c81edd45a738cdd91f9cfc1e8062ade4b6fa11e7530a8d8b4c2730cd648749b87381dbcca1bbe8681b8e45ec7af50b6b74137f89331  phpldapadmin-1.2.3-force-ssha512.patch
71a0bc987e526401c72b77b36843868099040654c3435e9c2f5b266a49a27b75b007fd949e9981bcd4b9a678f0edd74e988e66647984c882c57fe8dc99a26849  phpldapadmin-1.2.3_changed-password_hash-to-pla_password_hash.patch
d238e27ed89e400f467ab8282a67920cd1e72e5f52709d086f6b31708960dc65acafc0fe683887ceff0b78b3aa9631e91e2c57f722d9f7e0f057e0f872ae73a2  phpldapadmin-1.2.3_fixed-call-to-renamed-function-pla_password_hash.patch
0524112c7a3c591eaf4b3e64de26282a786a2c0fa73f1047084f14c4f9093cf31e1b9a36b7b1736d6c6ae89f9940916d42cbbab7081249abf1a963de588aac63  phpldapadmin-1.2.3_changed-preg_replace-to-preg_replace-callback.patch
57e1d8d861f84f0934a2275d7ba37621c2c19c71bf2c04db918ccbc6df36eaca60986db2ba6b543356ad55eab8d7850267db1d30677d77c96238821c29b99ac9  phpldapadmin-1.2.3_use-preg_replace_callback.patch
647e8924a302666ebae3090bcf61f82e3a82d19c232beabaf3faae43d0c434b12fb83a3d862fe6ce6a27b2b750c67974ac22e583d4897734f39e26733bdd2580  CVE-2017-11107.patch"
