diff options
Diffstat (limited to 'server.py')
-rwxr-xr-x[-rw-r--r--] | server.py | 54 |
1 files changed, 12 insertions, 42 deletions
@@ -1,3 +1,4 @@ | |||
1 | #!/usr/bin/env python | ||
1 | # vim: set filencoding=utf8 | 2 | # vim: set filencoding=utf8 |
2 | """ | 3 | """ |
3 | Exchange Calendar Proxy Server | 4 | Exchange 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 | ||
10 | from getpass import getpass | 11 | from util import config_dict |
11 | from ConfigParser import ConfigParser | 12 | from exchange.wsgi import CalendarApp |
12 | from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler | 13 | from wsgiref.simple_server import make_server |
13 | 14 | ||
14 | from exchange.commands import FetchCalendar | ||
15 | from exchange.authenticators import CookieAuthenticator | ||
16 | 15 | ||
17 | 16 | def main(): | |
18 | class 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 | |||
37 | def 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 | ||