#!/bin/bash

# VERSION=1
# CHANGES=

/bin/mount -oremount,rw /

grep "plain.userfile" /etc/lighttpd.conf > /dev/null
if [ "${?}" == "1" ]; then
	exit 0
fi

pass_plain=$(expr match "$(cat /usr/conf/apiusers.conf)" "admin:\(.*\)")
pass_crypt=$(echo "<?php \$ret=crypt(\"${pass_plain}\", base64_encode(\"${pass_plain}\")); echo \$ret; ?>" | /usr/bin/php -q)

echo -n "admin:${pass_crypt}" > /usr/conf/apiusers.conf

exit 0
