File: pyzord

package info (click to toggle)
pyzor 1%3A0.4.0%2Bcvs20030201-8
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 356 kB
  • ctags: 394
  • sloc: python: 1,590; sh: 617; makefile: 16
file content (102 lines) | stat: -rwxr-xr-x 2,932 bytes parent folder | download | duplicates (3)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python2

import os
import os.path
import sys
import getopt
import pyzor
import pyzor.server
import ConfigParser

_author__   = pyzor.__author__
__version__  = pyzor.__version__
__revision__ = "$Id: pyzord,v 1.23 2002/10/09 00:33:44 ftobin Exp $"
progname = 'pyzord'

default_anonymous_allows = map(pyzor.Opname, ['check', 'report', 'ping',
                                              'info'])


def usage():
    sys.stderr.write("usage: %s [-d] [--homedir dir]\n" % progname)
    sys.exit(1)


def load_access_file(access_fn, server):
    server.acl = pyzor.server.ACL()
    if os.path.exists(access_fn):
        pyzor.server.AccessFile(open(access_fn)).feed_into(server.acl)
    else:
        output.warn("%s does not exist; using default ACL: allowing anonymous to do %s"
                    % (access_fn, default_anonymous_allows))
        for op in default_anonymous_allows:
            server.acl.add_entry(pyzor.server.ACLEntry((pyzor.anonymous_user,
                                                        op,
                                                        True)))

                                 
def load_passwd_file(access_fn, server):
    server.passwd = pyzor.server.Passwd()
    if os.path.exists(passwd_fn):
        for user, key in pyzor.server.PasswdFile(open(passwd_fn)):
            server.passwd[user] = key


########################################################################
# functions above, run below

debug = 0
(options, args) = getopt.getopt(sys.argv[1:], 'dh:', ['homedir='])
if len(args) != 0:
    usage()

specified_homedir = None

for (o, v) in options:
    if o == '-d':
        debug = 1
    elif o == '-h':
        usage()
    elif o == '--homedir':
        specified_homedir = v

homedir = pyzor.get_homedir(specified_homedir)

if not os.path.exists(homedir):
    os.mkdir(homedir)

defaults = {'port':          '24441',
            'listenaddress': '0.0.0.0',
            'digestdb':      'pyzord.db',
            'passwdfile':    'pyzord.passwd',
            'accessfile':    'pyzord.access',
            'CleanupAge':    "%d" % pyzor.server.DBHandle.max_age,
            }

config = pyzor.Config(homedir)
config.add_section('server')

for k, v in defaults.items():
    config.set('server', k, v)

config.read(os.path.join(homedir, 'config'))

port       = config.getint('server', 'port')
listen_adr = config.get('server', 'ListenAddress')

dbfile    = config.get_filename('server', 'DigestDB')
passwd_fn = config.get_filename('server', 'passwdfile')
access_fn = config.get_filename('server', 'accessfile')
pyzor.server.DBHandle.max_age = config.getint('server', 'CleanupAge')

output = pyzor.Output(debug=debug)

pyzor.server.DBHandle.initialize(dbfile, 'c')
server = pyzor.server.Server((listen_adr, port),
                             pyzor.server.Log(sys.stdout))


load_passwd_file(passwd_fn, server)
load_access_file(access_fn, server)

server.serve_forever()