summaryrefslogtreecommitdiff
path: root/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'server.py')
-rw-r--r--server.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/server.py b/server.py
new file mode 100644
index 0000000..f4f671c
--- /dev/null
+++ b/server.py
@@ -0,0 +1,69 @@
1# -*- coding: utf-8 -*-
2"""
3Exchange Calendar Proxy Server
4
5@author: Mike Crute (mcrute@gmail.com)
6@organization: SoftGroup Interactive, Inc.
7@date: April 26, 2009
8@version: $Rev$
9
10$Id$
11"""
12from getpass import getpass
13from ConfigParser import ConfigParser
14from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
15
16from exchange.commands import FetchCalendar
17from exchange.authenticators import CookieAuthenticator
18
19
20class CalendarHandler(BaseHTTPRequestHandler):
21 def do_GET(self):
22 print('> GET CALENDARS')
23
24 fetcher = FetchCalendar(self.server.exchange_server)
25 authenticator = CookieAuthenticator(self.server.exchange_server)
26
27 authenticator.authenticate(self.server.user, self.server.password)
28 fetcher.authenticator = authenticator
29
30 calendar = fetcher.execute()
31 self.wfile.write(calendar.as_string()).close()
32
33
34def get_un_pass(config):
35 username = config.get('exchange', 'user')
36
37 if config.has_option('exchange', 'password'):
38 password = config.get('exchange', 'password')
39 else:
40 password = getpass('Exchange Password: ')
41
42 return username, password
43
44
45def get_host_port(config):
46 bind_address = config.get('local_server', 'address')
47 bind_port = int(config.get('local_server', 'port'))
48
49 return bind_address, bind_port
50
51
52def main(config_file='exchange.cfg'):
53 config = ConfigParser().read(config_file)
54 server_cfg = get_host_port(config)
55
56 print('Exchange iCal Proxy Running on port {0:d}'.format(server_cfg[1]))
57
58 server = HTTPServer(server_cfg, CalendarHandler)
59 server.exchange_server = config.get('exchange', 'server')
60 server.user, server.password = get_un_pass(config)
61
62 try:
63 server.serve_forever()
64 except KeyboardInterrupt:
65 print '\n All done, shutting down.'
66
67
68if __name__ == '__main__':
69 main()