#!/usr/bin/python
### Copyright 1999-2014. Parallels IP Holdings GmbH. All Rights Reserved.

import urllib, urllib2, sys, os

# version should be in format "%d.%d":
PLESK_VERSION = "12.0"

def main():
    try:
        comodo_url = "https://waf.comodo.com/api"
        data = [
            ("login", os.environ["MODSEC_VENDOR_LOGIN"]),
            ("password", os.environ["MODSEC_VENDOR_PASS"]),
            ("client_version", PLESK_VERSION),
            ("act", "download"),
        ]
        headers = {'User-Agent': 'Plesk/%s' % PLESK_VERSION}

        with open(sys.argv[1], 'w') as out:
            request = urllib2.Request(comodo_url, urllib.urlencode(data), headers)
            f = urllib2.urlopen(request)

            for line in f:
                out.write(line)
    except Exception as ex:
        sys.stderr.write("%s\n" % ex)
        sys.exit(1)

if __name__ == "__main__":
    main()

# vim: ts=4 sts=4 sw=4 et :
