set_admin_pass()
{
    info "Setting Ajenti admin password"
    sed -e "s%"sha512.*\"%"sha512\|$(mkpasswd -m sha-512 $panelpassword $(openssl rand -base64 16 | tr -d '+=' | head -c 16))\"%g" -i /etc/ajenti/config.json
    service ajenti restart
    if [ $? != 0 ]; then
        error "ERROR: Failed to set Ajenti admin password..."
        exit 5
    fi
    info "Password for Ajenti CP successfully set"
}

regen_ssl_cert()
{
    info "Regenerating SSL certificate"
    ajenti-ssl-gen $(hostname) -f
    [[ 'manual' == $ACTION ]] && broadcast "Password successfully updated"
    exit 0
}

app_setup()
{
    set_admin_pass
    if [ $? != 0 ]; then
        error "ERROR: Failed to set admin password in Ajenti"
        exit 3
    fi

    regen_ssl_cert
    if [ $? != 0 ]; then
        error "ERROR: Failed to regenerate SSL certificate..."
        exit 3
    fi
}
