-
Notifications
You must be signed in to change notification settings - Fork 3
/
xmppsvc.py
48 lines (40 loc) · 1.11 KB
/
xmppsvc.py
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
#!/usr/bin/env python
# XMPP service for BBS
"""xmppsvc -- XMPP server
Implements the XMPP server based on BBS user and messaging features
"""
import Config
import xmppserver
import rosters
import xmpp
import xmppauth
import UCache
import Utmp
import commondata
from Log import Log
from pwd import getpwnam
import os
import sys
import sasl
import bbsauth
if __name__ == '__main__':
try:
userinfo = getpwnam('bbs')
os.setuid(userinfo[2])
except:
Log.error("Failed to find user 'bbs'!")
sys.exit(1)
Config.Config.LoadConfig();
UCache.UCache.Init()
Utmp.Utmp.Init()
commondata.CommonData.Init()
hostname = Config.Config.GetString("BBS_XMPP_HOST", 'localhost')
server = xmpp.Server({
'plugins': [(xmppserver.XMPPServer, { 'rosters': rosters.Rosters() , 'host': hostname})],
'auth': xmppauth.XMPPAuth('xmpp', hostname, 'bbs'),
'mechanisms': (sasl.Plain, bbsauth.BBSAuth),
'certfile': Config.BBS_XMPP_CERT_FILE,
'keyfile': Config.BBS_XMPP_KEY_FILE,
})
SP = xmpp.TCPServer(server).bind('0.0.0.0', 5222)
xmpp.start([SP])