summaryrefslogtreecommitdiff
path: root/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'server.py')
-rwxr-xr-x[-rw-r--r--]server.py54
1 files changed, 12 insertions, 42 deletions
diff --git a/server.py b/server.py
index 0510b2b..78911c3 100644..100755
--- a/server.py
+++ b/server.py
@@ -1,3 +1,4 @@
1#!/usr/bin/env python
1# vim: set filencoding=utf8 2# vim: set filencoding=utf8
2""" 3"""
3Exchange Calendar Proxy Server 4Exchange Calendar Proxy Server
@@ -7,52 +8,21 @@ Exchange Calendar Proxy Server
7@date: April 26, 2009 8@date: April 26, 2009
8""" 9"""
9 10
10from getpass import getpass 11from util import config_dict
11from ConfigParser import ConfigParser 12from exchange.wsgi import CalendarApp
12from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler 13from wsgiref.simple_server import make_server
13 14
14from exchange.commands import FetchCalendar
15from exchange.authenticators import CookieAuthenticator
16 15
17 16def main():
18class CalendarHandler(BaseHTTPRequestHandler): 17 config = config_dict('exchange.cfg')
19
20 def do_GET(self):
21 print('* Fetching Calendars')
22
23 fetcher = FetchCalendar(self.server.exchange_server)
24 authenticator = CookieAuthenticator(self.server.exchange_server)
25
26 authenticator.authenticate(self.server.user, self.server.password)
27 fetcher.authenticator = authenticator
28
29 calendar = fetcher.execute()
30 self.wfile.write(calendar.as_string())
31
32 # This seems to work on Linux but not Mac OS. ~mcrute
33 if hasattr(self.wfile, 'close'):
34 self.wfile.close()
35
36
37def main(config_file='exchange.cfg'):
38 config = ConfigParser()
39 config.read(config_file)
40 bind_address = config.get('local_server', 'address')
41 bind_port = int(config.get('local_server', 'port'))
42
43 print('Exchange iCal Proxy Running on port {0:d}'.format(bind_port))
44
45 server = HTTPServer((bind_address, bind_port), CalendarHandler)
46 server.exchange_server = config.get('exchange', 'server')
47 server.user = config.get('exchange', 'user')
48
49 if config.has_option('exchange', 'password'):
50 server.password = config.get('exchange', 'password')
51 else:
52 server.password = getpass('Exchange Password: ')
53 18
54 try: 19 try:
55 server.serve_forever() 20 app = CalendarApp(config['exchange']['server'],
21 config['exchange']['user'],
22 config['exchange']['password'])
23
24 make_server(config['local_server']['address'],
25 config['local_server']['port'], app).serve_forever()
56 except KeyboardInterrupt: 26 except KeyboardInterrupt:
57 print '\n All done, shutting down.' 27 print '\n All done, shutting down.'
58 28