class SkillIndexer(): def __init__(self, config): self.ldaptools = LDAPTools(config) self.config = config["skillindexer"] self.authconfig = config def getSkills(self, db, name, id, vCode): accountCharacters = "http://api.eveonline.com/account/Characters.xml.aspx" charSheet = "http://api.eveonline.com/char/CharacterSheet.xml.aspx" print "Processing %s" % name params = urllib.urlencode({"keyID": id, "vCode": vCode}) f = urllib.urlopen(accountCharacters+"?"+params) data = f.read() f.close() soup = BeautifulStoneSoup(data) r = soup.findAll("row", {"name":unicode(name)}) if len(r)==0: return (1, "Character not found") corp = r[0]["corporationname"] charid = r[0]["characterid"] params = urllib.urlencode({"keyID": id, "vCode": vCode, "characterID":charid}) f = urllib.urlopen(charSheet+"?"+params) data = f.read() f.close() soup = BeautifulStoneSoup(data) error = soup.findAll("error") if len(error): print "Error" skills = str(soup.findAll("rowset", {"name": "skills"})[0]).split("\n") skills = map(lambda x:x.replace("</row>", ""), skills) skills = filter(lambda x:x.startswith("<row "), skills) skills = map(lambda x: skillstripper.match(x).groups(), skills) print len(skills) for t, l in skills: t=int(t) l=int(l) r = db.execute('INSERT INTO skills (name, typeid, level) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE level=%s', (name, t, l, l) ) def main(self): #ldap everyone = self.ldaptools.getusers("alliance=" + self.authconfig["auth"]["alliance"]) #database server db = MySQLdb.connect(self.config["server"], self.config["user"], self.config["password"], self.config["database"]) c = db.cursor() c.execute('truncate skills;') for user in everyone: try: self.getSkills(c, user.characterName[0], user.keyID[0], user.vCode[0]) except Exception as e: print e db.commit()
def __init__(self, config): self.config = config["pingbot"] self.username = self.config["username"] self.passwd = self.config["passwd"] self.domain = self.config["domain"] self.ldaptools = LDAPTools(config)
class pingbot(): def __init__(self, config): self.config = config["pingbot"] self.username = self.config["username"] self.passwd = self.config["passwd"] self.domain = self.config["domain"] self.ldaptools = LDAPTools(config) def sendannounce(self, server, message): tojid = server+"/announce/online" jidparams={} jidparams['jid'] = self.username+"@"+server jidparams['password'] = self.passwd jid=xmpp.protocol.JID(jidparams['jid']) try: r = dns.resolver.query('_xmpp-client._tcp.%s' % server, dns.rdatatype.SRV) if len(r)==1: server = r[0].target.to_text().rstrip(".") except: pass cl=xmpp.Client(server, debug=[]) con=cl.connect() if not con: print 'could not connect!' sys.exit() print 'connected with',con auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) if not auth: print 'could not authenticate!' sys.exit() print 'authenticated using',auth id=cl.send(xmpp.protocol.Message(tojid,message)) print 'sent message with id',id def generatemessage(self, sender, to, message): utctime = strftime("%X +0000", gmtime()) result = message result = result+"\n\n" result = result+"== broadcast at %s (UTC/EVE) from %s to %s ==" % (utctime, sender, to) return result def broadcast(self, sender, to, message, servers): for server in servers: self.sendannounce(server, self.generatemessage(sender, to, message)) def sendmessage(self, tojids, message): jidparams={} jidparams['jid'] = self.username+"@"+self.domain jidparams['password'] = self.passwd jid=xmpp.protocol.JID(jidparams['jid']) cl=xmpp.Client(jid.getDomain(), debug=[]) con=cl.connect() if not con: print 'could not connect!' sys.exit() print 'connected with',con auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) if not auth: print 'could not authenticate!' sys.exit() print 'authenticated using',auth total = 0 for tojid in tojids: id=cl.send(xmpp.protocol.Message(tojid,message)) total = total+1 cl.disconnect() return total def groupbroadcast(self, sender, ldapfilter, message, to): message = self.generatemessage(sender, to, message) users = self.ldaptools.getusers(ldapfilter) tojids = filter(lambda x:x.accountStatus[0] != "Expired", users) tojids = map(lambda x:x.get_jid(), tojids) return self.sendmessage(tojids, message)
from flask import Flask, g from flask.ext.redis import FlaskRedis from flask.ext.login import LoginManager from flask.sessions import SecureCookieSessionInterface from ldappool import ConnectionManager from cosign import CoSign from ldaptools import LDAPTools app = Flask(__name__) app.config.from_object('config') flask_redis = FlaskRedis(app, 'REDIS') ldap = LDAPTools( ConnectionManager(app.config["LDAP_SERVER"]) ) cosign = CoSign(app) lm = LoginManager(app) lm.login_view = "login" class CustomSessionInterface(SecureCookieSessionInterface): """Prevent creating session from API requests.""" def save_session(self, *args, **kwargs): return app.session_interface = CustomSessionInterface() @lm.request_loader
import ts3tools, announce from ldaptools import LDAPTools from keytools import KeyTools import json import logging import time from logging import handlers from ldap import MOD_ADD, MOD_DELETE, MOD_REPLACE # Load configuration with open("config.json") as fh: config=json.loads(fh.read()) assert(config) # Set up all classes ldaptools = LDAPTools(config) if __name__ == "__main__": logger = logging.getLogger("buildgroups") logger.setLevel(logging.DEBUG) fh = logging.FileHandler("./logs/buildgroups_%d.log" % time.time()) formatter = logging.Formatter('%(asctime)s - %(message)s') fh.setFormatter(formatter) logger.addHandler(fh) allgroups = config["groups"]["opengroups"] + config["groups"]["closedgroups"] for group in allgroups: members = ldaptools.getusers("authGroup=%s" % group) if not members: continue
def __init__(self, config): self.ldaptools = LDAPTools(config) self.config = config["skillindexer"] self.authconfig = config
import ts3tools, announce from ldaptools import LDAPTools from keytools import KeyTools import json import logging import time from logging import handlers from ldap import MOD_ADD, MOD_DELETE, MOD_REPLACE # Load configuration with open("config.json") as fh: config=json.loads(fh.read()) assert(config) # Set up all classes ldaptools = LDAPTools(config) keytools = KeyTools(config) safecharacters = ["twistedbot", "pingbot", "root", "deszra", "dimethus", "webchat"] if __name__ == "__main__": logger = logging.getLogger("updateusers") logger.setLevel(logging.DEBUG) fh = logging.FileHandler("./logs/updateusers_%d.log" % time.time()) formatter = logging.Formatter('%(asctime)s - %(message)s') fh.setFormatter(formatter) logger.addHandler(fh) for character in ldaptools.getusers("objectclass=xxPilot"): try: characters = keytools.getcharacters(character.keyID, character.vCode)
class pingbot(): def __init__(self, config): self.config = config["pingbot"] self.username = self.config["username"] self.passwd = self.config["passwd"] self.domain = self.config["domain"] self.ldaptools = LDAPTools(config) def sendannounce(self, server, message): tojid = server+"/announce/online" jidparams={} jidparams['jid'] = self.username+"@"+server jidparams['password'] = self.passwd jid=xmpp.protocol.JID(jidparams['jid']) cl=xmpp.Client(jid.getDomain(), debug=[]) con=cl.connect() if not con: print 'could not connect!' sys.exit() print 'connected with',con auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) if not auth: print 'could not authenticate!' sys.exit() print 'authenticated using',auth id=cl.send(xmpp.protocol.Message(tojid,message)) print 'sent message with id',id def generatemessage(self, sender, to, message): result = message result = result+"\n\n" result = result+"== broadcast from %s to %s ==" % (sender, to) return result def broadcast(self, sender, to, message, servers): for server in servers: self.sendannounce(server, self.generatemessage(sender, to, message)) def sendmessage(self, tojids, message): jidparams={} jidparams['jid'] = self.username+"@"+self.domain jidparams['password'] = self.passwd jid=xmpp.protocol.JID(jidparams['jid']) cl=xmpp.Client(jid.getDomain(), debug=[]) con=cl.connect() if not con: print 'could not connect!' sys.exit() print 'connected with',con auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) if not auth: print 'could not authenticate!' sys.exit() print 'authenticated using',auth total = 0 for tojid in tojids: id=cl.send(xmpp.protocol.Message(tojid,message)) total = total+1 cl.disconnect() return total def groupbroadcast(self, sender, ldapfilter, message, to): message = self.generatemessage(sender, to, message) users = self.ldaptools.getusers(ldapfilter) tojids = filter(lambda x:x.accountStatus[0] != "Expired", users) tojids = map(lambda x:x.get_jid(), tojids) return self.sendmessage(tojids, message)
from flask import Flask from flask.ext.redis import FlaskRedis from flask.ext.login import LoginManager from ldaptools import LDAPTools import braintree app = Flask(__name__) app.config.from_object('config') flask_redis = FlaskRedis(app, 'REDIS') ldap = LDAPTools(app) lm = LoginManager(app) lm.login_view = "login" @lm.user_loader def get_user(uid): return ldap.getuser(uid) from . import views