def msg_login_plaintext(self, data): if (not type(self.conf) is dict): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 if (not self.conf.has_key('auth')): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 if (not self.conf['auth'].has_key('user')): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 try: user = data[2:2+ord(data[0])] password = data[2+ord(data[0]):2+ord(data[0])+ord(data[1])] except: linfo('user authentification failed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 linfo('user authentification not implemented') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0
def msg_login_plaintext(self, data): if (not type(self.conf) is dict): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 if (not self.conf.has_key('auth')): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 if (not self.conf['auth'].has_key('user')): linfo('no user authentification allowed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 try: user = data[2:2 + ord(data[0])] password = data[2 + ord(data[0]):2 + ord(data[0]) + ord(data[1])] except: linfo('user authentification failed') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0 linfo('user authentification not implemented') self.nack(NetClientThread.M_LOGIN_PLAINTEXT) return 0
def sbserver(): global run_daemon run_daemon = True conf = {} if (not start_config_default(conf)): return 1 if (not start_config_params(conf)): return 1 if (not start_config_get(conf)): return 1 start_log(conf) linfo('starting %s process' % conf['general']['name']) if (not start_config_check(conf)): return 1 signal(SIGHUP, sig_handler) signal(SIGTERM, sig_handler) if (conf['general']['daemon'] == 'yes'): ldebug('%s process starting in daemon mode' % conf['general']['name']) ret = start_daemon() if (ret != 0): lcritic('failed to start %s daemon' % conf['general']['name']) os.exit(ret) ldebug('started %s process with pid: %d' % (conf['general']['name'], os.getpid())) eventhandler = EventHandler() plugins = start_modules(conf) plugins['EventHandler'] = {} plugins['EventHandler']['type'] = (0, ) plugins['EventHandler']['object'] = eventhandler for plugin in plugins: if (0 in plugins[plugin]['type']): ldebug('start system plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() elif (1 in plugins[plugin]['type']): ldebug('start listener plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() elif (2 in plugins[plugin]['type']): ldebug('start handler plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() while (run_daemon): sleep(0.5) for plugin in plugins: if (2 in plugins[plugin]['type']): ldebug('stop handler plugin %s' % plugin) plugins[plugin]['object'].stop() if (1 in plugins[plugin]['type']): ldebug('stop listener plugin %s' % plugin) plugins[plugin]['object'].stop() if (0 in plugins[plugin]['type']): ldebug('stop system plugin %s' % plugin) plugins[plugin]['object'].stop() sleep(1) linfo('exiting %s process' % conf['general']['name']) return 1
def run(self): self.netsocket.settimeout(60) exten_groups = {} queue_groups = {} self.exten_groups = exten_groups self.queue_groups = queue_groups address, port = self.clientaddress ldebug('opening connection to %s:%d' % (address, port)) while self.runthread: data = [] try: data = self.netsocket.recv(6) except: timeout = True self.runthread = False if (len(data) == 6): try: msg_ident, = unpack("H", data[0:2]) msg_type, = unpack("H", data[2:4]) msg_len, = unpack("H", data[4:6]) if (msg_ident == NetClientThread.PREAMBLE): if (msg_len > 0): data = self.netsocket.recv(msg_len) else: data = '' else: linfo('malformed packet - length:%d' % len(data)) except: linfo('packet error - length:%d' % len(data)) continue ldebug('received packet type:%d length:%d' % (msg_type, len(data))) if (msg_len != len(data)): self.nack(msg_type) continue if (msg_type == NetClientThread.M_CLOSE): self.runthread = False break elif (msg_type == NetClientThread.M_PING): self.ack(msg_type) elif (msg_type == NetClientThread.M_LOGIN_PLAINTEXT): if (msg_len > 1): self.msg_login_plaintext(data) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_EXTGROUPSET): if (msg_len > 1): self.msg_extgroupset(exten_groups, data) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_EXTGROUPSTAT): if (msg_len == 2): self.msg_extgroupstat(exten_groups, ord(data[0]), data[1]) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_EXTGROUPSUBSCRIBE): if (msg_len == 2): self.msg_extgroupsubscribe(exten_groups, ord(data[0]), data[1]) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_QUEUEGROUPSET): if (msg_len > 1): self.msg_queuegroupset(queue_groups, data) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_QUEUEGROUPCALLS): if (msg_len == 2): self.msg_queuegroupcalls(queue_groups, ord(data[0]), data[1]) else: self.nack(msg_type) elif (msg_type == NetClientThread.M_CHANNELSGET): self.msg_channels_get(None) elif (msg_type == NetClientThread.M_CALLFORWARDGET): self.msg_callforward_get(None) else: self.nack(msg_type) if not data: break ldebug('closing client connection to %s:%d' % (address, port)) self.netsocket.close() for subscription in self.event_subscriptions: if (self.client_key in self.event_subscriptions[subscription]): self.event_subscriptions[subscription].remove(self.client_key) del self.clients[self.client_key]
def ret_ack(self, data): if (len(data) != 2): linfo('malformed ACK packet') return False packet_type, = unpack("H", data[0:2]) ldebug('packet %d acknowledged by client' % packet_type)
if (ipcalc.innet(addr_int, network, bitmask)): accept_ip = True break if (not accept_ip): ldebug('ip rejected') continue for network in self.net_reject.keys(): bitmask = self.net_reject[network] if (ipcalc.innet(addr_int, network, bitmask)): accept_ip = False break if (not accept_ip): linfo('ip rejected') continue auth_ip = False for network in self.net_allow.keys(): bitmask = self.net_allow[network] if (ipcalc.innet(addr_int, network, bitmask)): auth_ip = True ldebug('trusted ip %s' % address[0]) break self.clients[address] = {} ct = NetClientThread(clientsocket, address, auth_ip, self.clients, address) ct.plugins(self.pluginlist)
if (ipcalc.innet(addr_int, network, bitmask)): accept_ip = True break if (not accept_ip): ldebug('ip rejected') continue for network in self.net_reject.keys(): bitmask = self.net_reject[network] if (ipcalc.innet(addr_int, network, bitmask)): accept_ip = False break if (not accept_ip): linfo('ip rejected') continue auth_ip = False for network in self.net_allow.keys(): bitmask = self.net_allow[network] if (ipcalc.innet(addr_int, network, bitmask)): auth_ip = True ldebug('trusted ip %s' % address[0]) break self.clients[address] = {} ct = NetClientThread(clientsocket, address, auth_ip, self.clients, address) ct.plugins(self.pluginlist) ct.events(self.event_subscriptions)
def sbserver(): global run_daemon run_daemon = True conf = {} if (not start_config_default(conf)): return 1 if (not start_config_params(conf)): return 1 if (not start_config_get(conf)): return 1 start_log(conf) linfo('starting %s process' % conf['general']['name']) if (not start_config_check(conf)): return 1 signal(SIGHUP, sig_handler) signal(SIGTERM, sig_handler) if (conf['general']['daemon'] == 'yes'): ldebug('%s process starting in daemon mode' % conf['general']['name']) ret = start_daemon() if (ret != 0): lcritic('failed to start %s daemon' % conf['general']['name']) os.exit(ret) ldebug('started %s process with pid: %d' % (conf['general']['name'], os.getpid())) eventhandler = EventHandler() plugins = start_modules(conf) plugins['EventHandler'] = {} plugins['EventHandler']['type'] = (0,) plugins['EventHandler']['object'] = eventhandler for plugin in plugins: if (0 in plugins[plugin]['type']): ldebug('start system plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() elif (1 in plugins[plugin]['type']): ldebug('start listener plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() elif (2 in plugins[plugin]['type']): ldebug('start handler plugin %s' % plugin) plugins[plugin]['object'].config(conf) plugins[plugin]['object'].plugins(plugins) plugins[plugin]['object'].start() while (run_daemon): sleep(0.5) for plugin in plugins: if (2 in plugins[plugin]['type']): ldebug('stop handler plugin %s' % plugin) plugins[plugin]['object'].stop() if (1 in plugins[plugin]['type']): ldebug('stop listener plugin %s' % plugin) plugins[plugin]['object'].stop() if (0 in plugins[plugin]['type']): ldebug('stop system plugin %s' % plugin) plugins[plugin]['object'].stop() sleep(1) linfo('exiting %s process' % conf['general']['name']) return 1