forked from hotoo/gaegtalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmpp.py
104 lines (92 loc) · 4.5 KB
/
xmpp.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
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
103
104
############################################################################
# Copyright (C) 2010 by math2gold #
# Twitter:@math2gold #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
from google.appengine.api import xmpp
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import m2ggg_config
import m2ggg_core
import logging
import md5
import sys
class XMPPHandler(webapp.RequestHandler):
def post(self):
cmdOP=m2ggg_core.cmdop()
userview=m2ggg_core.UserView()
message =""
try:
message=xmpp.Message(self.request.POST)
except xmpp.InvalidMessageError, e:
logging.error("Invalid XMPP request: %s", e[0])
logging.error(self.request.body)
logging.error(self.request.POST)
return
except:
from_name=m2ggg_core.get_mail_name(self.request.get('from')).lower()
m2ggg_core.activeresouce_record(from_name,4);
logging.error(sys.exc_info()[0])
raise "under attack:" +from_name.encode("UTF-8");
return
#if message.body[0:5].lower() == 'hello':
#message.reply("Greetings!")
from_name=m2ggg_core.get_mail_name(self.request.get('from')).lower()
c1= ( from_name==m2ggg_config.root_gmail )
c2= userview.checklist(from_name)
if ( (not c2) and (not userview.is_blacklist) ) :
try:
logging.info(from_name.encode("UTF-8")+" : "+message.body );
m2ggg_core.registerOutside(from_name);
except:
pass
#logging.error(from_name.encode("UTF-8")+"|"+str)
m2ggg_core.activeresouce_record(from_name,1);
m2ggg_core.send_all_admin( from_name+'(is not member now , use //add '+from_name+' to make him to be one ) said outside: '+message.body,from_name );
if c1 or c2 :
if ( (from_name==m2ggg_config.root_gmail or userview.is_admin) and cmdOP.is_cmd(message.body.strip()) ) or ( cmdOP.is_all_cmd(message.body.strip(),from_name,userview.nickname,userview.idf) ) :
m2ggg_core.activeresouce_record(from_name,3);
m2ggg_core.activeresouce_record_usage(from_name,cmdOP.cmdname);
m2ggg_core.set_cached_xmpp_status(from_name,True);
message.reply(cmdOP.reply)
else:
#mdd=md5.new()
#mdd.update( from_name.encode("UTF-8") )
#qd=mdd.hexdigest()[0:10]
if (not userview.is_blacklist):
try:
m2ggg_core.set_cached_xmpp_status(from_name,True);
m2ggg_core.activeresouce_record(from_name,2);
except:
pass
if (not userview.usertype==1):
m2ggg_core.send_all(userview.nickname,userview.idf,message.body,from_name)
else:
ext=machine_passcode_decoder()
ext.decode(message.body)
m2ggg_core.send_all(userview.nickname+"/"+ext.nickname,userview.idf+"/"+ext.idf,ext.msg,from_name)
#if from_name==m2ggg_config.root_gmail:
# logging.error(message.body)
else:
pass
application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)],
debug=False)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
# vim:se sw=4: