1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/bin/env python
# vi:si:et:sw=4:sts=4:ts=4
# -*- coding: UTF-8 -*-
# -*- Mode: Python -*-
#
# Copyright (C) 2015 mh <mh@immerda.ch>
# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
#
import sys, os, requests, getopt
def usage():
print sys.argv[0] + " -u username "+ \
"-p password " + \
"-s server path"
sys.exit(1)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "u:p:s:h")
except getopt.GetoptError:
usage()
return 3
user = url = password = None
for o, a in opts:
if o == "-u":
user = a
elif o == "-p":
password = a
elif o == "-s":
url = a + "/login.php"
elif o == '-h':
usage()
if user == None or password == None or url == None:
usage()
params = { 'horde_user': user,
'horde_pass': password,
'horde_select_view': 'auto',
'anchor_string': '',
'app': '',
'login_post': 1,
'new_lang': 'en_US',
'url': '',
}
r = requests.post(url, data=params, allow_redirects=False)
# on a successfully login we are redirected to the mailbox
if r.status_code == 302:
print "OK"
sys.exit(0)
else:
print "Error"
sys.exit(2)
if __name__ == "__main__":
sys.exit(main())
|