Module whereis working in V3

This commit is contained in:
Némunaire 2012-05-30 12:22:28 +02:00
parent 25b2634ea3
commit 8383668639
2 changed files with 38 additions and 64 deletions

View File

@ -10,9 +10,10 @@ from datetime import datetime
from datetime import date from datetime import date
from datetime import timedelta from datetime import timedelta
from urllib.parse import unquote from urllib.parse import unquote
from xml.dom.minidom import parse
from xml.dom.minidom import parseString from module_state import ModuleState
from xml.dom.minidom import getDOMImplementation
nemubotversion = 3.0
NS_SERVER = 'ns-server.epita.fr' NS_SERVER = 'ns-server.epita.fr'
NS_PORT = 4242 NS_PORT = 4242
@ -22,7 +23,8 @@ search = list()
class UpdatedStorage: class UpdatedStorage:
def __init__(self): def __init__(self):
sock = connect_to_ns(NS_SERVER, NS_PORT) sock = connect_to_ns(CONF.getNode("server")["url"],
CONF.getNode("server").getInt("port"))
self.users = dict() self.users = dict()
if sock != None: if sock != None:
for l in list_users(sock): for l in list_users(sock):
@ -50,56 +52,10 @@ class User(object):
@property @property
def sm(self): def sm(self):
if self.ip.startswith('10.200'): for sm in CONF.getNodes("sm"):
ip = self.ip.split('.') if self.ip.startswith(sm["ip"]):
if 20 < int(ip[2]) < 30: return sm["name"]
return 'SM02' return None
else:
return 'SM' + self.ip.split('.')[2]
elif self.ip.startswith('10.242'):
return 'bocal'
elif self.ip.startswith('10.247'):
return 'pasteur'
elif self.ip.startswith('10.248'):
return 'srlab'
elif self.ip.startswith('10.249'):
return 'midlab'
elif self.ip.startswith('10.250'):
return 'cisco'
elif self.ip.startswith('10.41.'):
return 'wifi'
elif self.ip.startswith('10.223.3.'):
return 'épimac'
elif self.ip.startswith('10.223.4.'):
return 'wcube'
elif self.ip.startswith('10.223.5.'):
return 'cycom'
elif self.ip.startswith('10.223.6.'):
return 'epitv'
elif self.ip.startswith('10.223.7.'):
return 'prologin'
elif self.ip.startswith('10.223'):
return 'assos'
elif self.ip.startswith('10.226.7.'):
return 'gistre'
elif self.ip.startswith('10.224.1.'):
return 'astek'
elif self.ip.startswith('10.224.2.'):
return 'acu'
elif self.ip.startswith('10.224.4.'):
return 'lse'
elif self.ip.startswith('10.224.8.'):
return 'eip'
elif self.ip.startswith('10.224.16.'):
return 'evolutek'
elif self.ip.startswith('10.224.18.'):
return 'mslab'
elif self.ip.startswith('10.2.'):
return 'adm'
elif self.ip.startswith('10.10.'):
return 'vpn'
else:
return None
@property @property
def poste(self): def poste(self):
@ -141,15 +97,6 @@ def list_users(sock):
return buf.split('\n')[:-2] return buf.split('\n')[:-2]
def load_module(datas_path):
"""Load this module"""
return
def save_module():
"""Save the module state"""
return
def help_tiny (): def help_tiny ():
"""Line inserted in the response to the command !help""" """Line inserted in the response to the command !help"""
return "Find a user on the PIE" return "Find a user on the PIE"
@ -207,7 +154,6 @@ def whoison(msg):
continue continue
else: else:
found = list() found = list()
print (len(datas.users))
for userC in datas.users: for userC in datas.users:
for user in datas.users[userC]: for user in datas.users[userC]:
if (msg.cmd[0] == "whoison" and (user.ip[:len(pc)] == pc or user.location.lower() == pc)) or (msg.cmd[0] == "whoisin" and user.sm == pc): if (msg.cmd[0] == "whoison" and (user.ip[:len(pc)] == pc or user.location.lower() == pc)) or (msg.cmd[0] == "whoisin" and user.sm == pc):

28
modules/whereis.xml Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" ?>
<nemubotmodule name="whereis">
<server url="ns-server.epita.fr" port="4242" />
<sm name="adm" ip="10.2." />
<sm name="vpn" ip="10.10." />
<sm name="wifi" ip="10.41" />
<sm name="sm02" ip="10.200.2" />
<sm name="sm14" ip="10.200.14." />
<sm name="sm15" ip="10.200.15." />
<sm name="épimac" ip="10.223.3." />
<sm name="wcube" ip="10.223.4." />
<sm name="cycom" ip="10.223.5" />
<sm name="eptv" ip="10.223.6" />
<sm name="prologin" ip="10.223.7" />
<sm name="assos" ip="10.223" />
<sm name="gistre" ip="10.226.7." />
<sm name="astek" ip="10.224.1." />
<sm name="acu" ip="10.224.2." />
<sm name="lse" ip="10.224.4." />
<sm name="eip" ip="10.224.8." />
<sm name="evolutek" ip="10.224.16." />
<sm name="mslab" ip="10.224.18." />
<sm name="bocal" ip="10.242" />
<sm name="pasteur" ip="10.247" />
<sm name="srlab" ip="10.248" />
<sm name="midlab" ip="10.249" />
<sm name="cisco" ip="10.250" />
</nemubotmodule>