import requests
import json


def get_login_cookie(url, user, passwd):
    """
    Logs into AdGuard URL using username/password and returns a valid session cookie.
    :param url: Base URL of AdGuard
    :param user: Username of AdGuard
    :param passwd: Password of AdGuard
    :return: Session token
    """

    creds = {
        'name': user,
        'password': passwd
    }

    response = requests.post('{}/control/login'.format(url), data=json.dumps(creds))
    return response.cookies['agh_session']