<commit_before>#!/usr/bin/python

from config import hostname, port, username, password
import webdavlib
import urllib
import urllib2
import base64
import simplejson
import cookielib

def getAuthCookie(hostname, port, username, password) :
	cjar = cookielib.CookieJar();
	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cjar))
	urllib2.install_opener(opener)

	creds = urllib.urlencode([("userName",username), ("password", password)])
	req = urllib2.Request("http://%s/SOGo/connect" % hostname, creds)
	
	fd = urllib2.urlopen(req)
	#print fd.info()
	
	for cookie in cjar :
	    if cookie.name == "0xHIGHFLYxSOGo":
	      authinfo = cookie.value
	      break

	return "0xHIGHFLYxSOGo="+authinfo
if __name__ == "__main__" :
	getAuthCookie()<commit_msg>Add options handling to sogoLogin.py The script can now be used from the CLI to get the SOGo auth cookie.<commit_after>#!/usr/bin/python

from config import hostname, port, username, password
import sys, getopt
import webdavlib
import urllib
import urllib2
import base64
import simplejson
import cookielib

def getAuthCookie(hostname, port, username, password) :
	cjar = cookielib.CookieJar();
	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cjar))
	urllib2.install_opener(opener)

	creds = urllib.urlencode([("userName",username), ("password", password)])
	req = urllib2.Request("http://%s:%s/SOGo/connect" % (hostname, port), creds)
	
	fd = urllib2.urlopen(req)
	
	for cookie in cjar :
	    if cookie.name == "0xHIGHFLYxSOGo":
	      authinfo = cookie.value
	      break

	return "0xHIGHFLYxSOGo="+authinfo

def usage() :
	msg ="""Usage:
%s [-h] [-H | --host=hostname] [-p|--passwd=password] \
[-P|--port=port] [-u|--user=username]\n""" % sys.argv[0]

	sys.stderr.write(msg);

if __name__ == "__main__" :
	try:
	    opts, args = getopt.getopt (sys.argv[1:], "hH:p:P:u:", \
	                            ("host=", "passwd=", "port=", "user="));
	except getopt.GetoptError:
	    usage()
	    exit(1)
	for o, v in opts :
	    if o == "-h" :
	        usage()
	        exit(1)
	    elif o == "-H" or o == "--host" :
	        hostname = v
	    elif o == "-p" or o == "--passwd" :
	        password = v
	    elif o == "-P" or o == "--port" :
	        port = v
	    elif o == "-u" or o == "--user" :
	        username = v

	print getAuthCookie(hostname, port, username, password)
{'fraction_non_alphanumeric': 0.14938113529662825, 'fraction_numerical': 0.010243277848911651, 'mean_word_length': 3.397748592870544, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4126456', 'n_tokens_mistral': 880, 'n_tokens_neox': 850, 'n_words': 209}