def register(loop: asyncio.AbstractEventLoop, backend: Backend) -> None: from util.misc import ProtocolRunner backend.add_runner( ProtocolRunner('0.0.0.0', 6667, ListenerIRC, args=['IR', backend, IRCCtrl]))
def register(loop: asyncio.AbstractEventLoop, backend: Backend, *, devmode: bool = False) -> web.Application: from util.misc import AIOHTTPRunner if devmode: from devtls import DevTLS sysboard_host = '0.0.0.0' ssl_context = DevTLS('Escargot').create_ssl_context() else: sysboard_host = '127.0.0.1' ssl_context = None app = create_app(loop, backend) backend.add_runner( AIOHTTPRunner(sysboard_host, 52478, app, ssl_context=ssl_context, ssl_only=True)) app.router.add_get(SYSBOARD_PATH, handle_sysboard_gui) app.router.add_post(SYSBOARD_PATH, handle_sysboard_action) app.router.add_get(SYSBOARD_LOGIN_PATH, handle_sysboard_login) app.router.add_post(SYSBOARD_LOGIN_PATH, handle_sysboard_login_verify) return app
def register(backend: Backend) -> None: from util.misc import ProtocolRunner # TODO: Implement UDP ports # https://imfreedom.org/wiki/Yahoo#Network backend.add_runner(ProtocolRunner('0.0.0.0', 5000, ListenerVoiceChat)) backend.add_runner(ProtocolRunner('0.0.0.0', 5001, ListenerVoiceChat))
def register(loop: asyncio.AbstractEventLoop, backend: Backend) -> None: uuid = backend.util_get_uuid_from_email(BOT_EMAIL) assert uuid is not None bs = backend.login(uuid, CLIENT, BackendEventHandler(loop), option=LoginOption.BootOthers) assert bs is not None
def register(loop: asyncio.AbstractEventLoop, backend: Backend) -> None: for i in range(5): uuid = backend.util_get_uuid_from_email( 'bot{}@bot.log1p.xyz'.format(i)) assert uuid is not None bs = backend.login(uuid, CLIENT, BackendEventHandler(loop), option=LoginOption.BootOthers) assert bs is not None
def extend_ubx_payload(dialect: int, backend: Backend, user: User, ctc_sess: 'BackendSession') -> str: response = '' ctc_machineguid = ctc_sess.front_data.get('msn_machineguid') pop_id_ctc = ctc_sess.front_data.get('msn_pop_id') if dialect >= 13 and ctc_machineguid: response += '<MachineGuid>{}</MachineGuid>'.format(ctc_machineguid) if dialect >= 16: response += '{}<SignatureSound>{}</SignatureSound>{}'.format( ('<DDP>{}</DDP>'.format( encode_xml_he(ctc_sess.front_data.get('msn_msnobj_ddp'), dialect) or '') if dialect >= 18 else ''), encode_xml_he(ctc_sess.front_data.get('msn_sigsound'), dialect) or '', ('<Scene>{}</Scene><ColorScheme>{}</ColorScheme>'.format( encode_xml_he(ctc_sess.front_data.get('msn_msnobj_scene'), dialect) or '', ctc_sess.front_data.get('msn_colorscheme') or '') if dialect >= 18 else ''), ) if pop_id_ctc: response += EPDATA_PAYLOAD.format( mguid='{' + pop_id_ctc + '}', capabilities=encode_capabilities_capabilitiesex( ((ctc_sess.front_data.get('msn_capabilities') or 0) if ctc_sess.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC), ctc_sess.front_data.get('msn_capabilitiesex') or 0)) for ctc_sess_other in backend.util_get_sessions_by_user( ctc_sess.user): pop_id = ctc_sess_other.front_data.get('msn_pop_id') or '' if pop_id.lower() == pop_id_ctc.lower(): continue response += EPDATA_PAYLOAD.format( mguid='{' + pop_id + '}', capabilities=encode_capabilities_capabilitiesex( ((ctc_sess.front_data.get('msn_capabilities') or 0) if ctc_sess.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC), ctc_sess_other.front_data.get('msn_capabilitiesex') or 0)) if ctc_sess.user is user: for ctc_sess_other in backend.util_get_sessions_by_user( ctc_sess.user): if ctc_sess_other.front_data.get('msn_pop_id') is None: continue response += PRIVATEEPDATA_PAYLOAD.format( mguid='{' + (ctc_sess_other.front_data.get('msn_pop_id') or '') + '}', ped_data=_list_private_endpoint_data(ctc_sess_other)) return response
def register(loop: asyncio.AbstractEventLoop, backend: Backend, http_app: web.Application) -> None: from util.misc import ProtocolRunner from . import msnp_ns, msnp_sb, http, http_gateway, http_sound backend.add_runner( ProtocolRunner('0.0.0.0', 1863, ListenerMSNP, args=['NS', backend, msnp_ns.MSNPCtrlNS])) backend.add_runner( ProtocolRunner('0.0.0.0', 1864, ListenerMSNP, args=['SB', backend, msnp_sb.MSNPCtrlSB])) http.register(http_app) http_gateway.register(loop, http_app) http_sound.register(http_app)
class Hcenkrow: def __init__(self): self.name = 'hcenkrow is my name' self.backend = Backend() def getName(self): return self.name def list(self): str = "SELECT * FROM Writers" ## testing ## return self.backend.list(str)
def register(loop: asyncio.AbstractEventLoop, backend: Backend, *, devmode: bool = False) -> web.Application: from util.misc import AIOHTTPRunner if devmode: from devtls import DevTLS http_host = '0.0.0.0' http_port = 80 ssl_context = DevTLS('Escargot').create_ssl_context() else: http_host = '127.0.0.1' http_port = 8081 ssl_context = None app = create_app(loop, backend) backend.add_runner( AIOHTTPRunner(http_host, http_port, app, ssl_context=ssl_context)) return app
def main(*, devmode: bool = False) -> None: sys.excepthook = _excepthook import asyncio from core.backend import Backend from core import http import settings loop = asyncio.get_event_loop() backend = Backend(loop) http_app = http.register(loop, backend, devmode=devmode) if settings.ENABLE_FRONT_MSN: import front.msn front.msn.register(loop, backend, http_app) if settings.ENABLE_FRONT_YMSG: import front.ymsg front.ymsg.register(loop, backend, http_app) if settings.ENABLE_FRONT_IRC: import front.irc front.irc.register(loop, backend) if settings.ENABLE_FRONT_API: import front.api front.api.register(http_app) if settings.ENABLE_FRONT_BOT: import front.bot front.bot.register(loop, backend) import core.sysboard core.sysboard.register(loop, backend, devmode=devmode) if devmode: if settings.ENABLE_FRONT_DEVBOTS: import front.devbots front.devbots.register(loop, backend) import dev.webconsole dev.webconsole.register(loop, backend, http_app) backend.run_forever()
def main(*, devmode = False): import asyncio from core.backend import Backend import front.msn import front.ymsg import front.bot import settings if devmode: http_port = 80 else: http_port = 8081 loop = asyncio.get_event_loop() backend = Backend(loop) if settings.ENABLE_FRONT_MSN: front.msn.register(loop, backend, http_port = http_port, devmode = devmode) if settings.ENABLE_FRONT_YMSG: front.ymsg.register(loop, backend) if settings.ENABLE_FRONT_BOT: front.bot.register(loop, backend) backend.run_forever()
def __init__(self, loop: asyncio.AbstractEventLoop, backend: Backend) -> None: self.loop = loop self.locals = { '_': None, 'be': backend, 'dir': useful_dir, 'dirfull': dir, 'prof': profile, } self.objs = {} self.websocks = set() self.i = 0 backend._dev = self
def yahoo_id_to_uuid(backend: Backend, yahoo_id: Optional[str]) -> Optional[str]: if not yahoo_id: return None email = None # type: Optional[str] # Fun fact about foreign Yahoo! email addresses: they're just relays to the same account name but with # `@yahoo.com` instead of `@yahoo.*`. The server should check the address to add an entry for the `@yahoo.com` # account, then they can be identified. if '@' in yahoo_id: if not yahoo_id.endswith('@yahoo.com'): email = yahoo_id else: return None else: email = '{}@yahoo.com'.format(yahoo_id) return backend.util_get_uuid_from_email(email)
def __init__(self): self.name = 'hcenkrow is my name' self.backend = Backend()
def build_presence_notif( trid: Optional[str], ctc_head: User, user_me: User, dialect: int, backend: Backend, iln_sent: bool, *, self_presence: bool = False, bs_other: Optional['BackendSession'] = None, groupchat: Optional['GroupChat'] = None) -> Iterable[Tuple[Any, ...]]: detail = user_me.detail assert detail is not None if not iln_sent: return nfy_rst = '' if not groupchat: if not self_presence and ctc_head is not user_me: ctc = detail.contacts.get(ctc_head.uuid) assert ctc is not None status = ctc.status head = ctc.head else: head = user_me status = head.status else: head = ctc_head status = head.status is_offlineish = status.is_offlineish() if is_offlineish and trid is not None: return ctc_sess = None # type: Optional['BackendSession'] ctc_sess = first_in_iterable(backend.util_get_sessions_by_user(head)) #if dialect == 21: # cm = None # type: Optional[str] # pop_id_ctc = None # type: Optional[str] # # substatus = status.substatus # # if is_offlineish and head is not user_me: # # In case `ctc` is going `HDN`; make sure other people don't receive `HDN` as status # substatus = Substatus.Offline # # if not substatus is Substatus.Offline: # assert ctc_sess is not None # # cm = NFY_PUT_PRESENCE_USER_S_CM.format(cm = encode_xml_he(status.media or '', dialect)) # nfy_rst += NFY_PUT_PRESENCE_USER_S_PE.format( # msnobj = encode_xml_he(ctc_sess.front_data.get('msn_msnobj') or '', dialect), # name = status.name or head.email, message = status.message, # ddp = encode_xml_he(ctc_sess.front_data.get('msn_msnobj_ddp') or '', dialect), colorscheme = encode_xml_he(ctc_sess.front_data.get('msn_colorscheme') or '', dialect), scene = encode_xml_he(ctc_sess.front_data.get('msn_msnobj_scene') or '', dialect), sigsound = encode_xml_he(ctc_sess.front_data.get('msn_sigsound') or '', dialect), # ) # if ctc_sess.front_data.get('msn_pop_id') is not None: # pop_id_ctc = '{' + ctc_sess.front_data['msn_pop_id'] + '}' # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_IM.format( # epid_attrib = (NFY_PUT_PRESENCE_USER_SEP_EPID.format(mguid = pop_id_ctc or '') if pop_id_ctc is not None else ''), capabilities = encode_capabilities_capabilitiesex(((ctc_sess.front_data.get('msn_capabilities') or 0) if ctc_sess.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC), ctc_sess.front_data.get('msn_capabilitiesex') or 0), # ) # if ctc_sess.front_data.get('msn_PE'): # pe_data = '' # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_VER.format(ver = ctc_sess.front_data.get('msn_PE_VER') or '') # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_TYP.format(typ = ctc_sess.front_data.get('msn_PE_TYP') or '') # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_CAP.format(pe_capabilities = encode_capabilities_capabilitiesex(ctc_sess.front_data.get('msn_PE_capabilities') or 0, ctc_sess.front_data.get('msn_PE_capabilitiesex') or 0)) # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_PE.format( # epid_attrib = (NFY_PUT_PRESENCE_USER_SEP_EPID.format(mguid = pop_id_ctc or '') if pop_id_ctc is not None else ''), pe_data = pe_data, # ) # if pop_id_ctc is not None: # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_PD.format( # mguid = pop_id_ctc, ped_data = _list_private_endpoint_data(ctc_sess), # ) # # for ctc_sess_other in backend.util_get_sessions_by_user(ctc_sess.user): # if ctc_sess_other is ctc_sess: continue # if ctc_sess_other.front_data.get('msn_pop_id') is None: continue # # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_IM.format( # epid_attrib = NFY_PUT_PRESENCE_USER_SEP_EPID.format(mguid = '{' + ctc_sess_other.front_data['msn_pop_id'] + '}'), capabilities = encode_capabilities_capabilitiesex(((ctc_sess_other.front_data.get('msn_capabilities') or 0) if ctc_sess_other.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC), ctc_sess_other.front_data.get('msn_capabilitiesex') or 0), # ) # if ctc_sess_other.front_data.get('msn_PE'): # pe_data = '' # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_VER.format(ver = ctc_sess_other.front_data.get('msn_PE_VER') or '') # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_TYP.format(typ = ctc_sess_other.front_data.get('msn_PE_TYP') or '') # pe_data += NFY_PUT_PRESENCE_USER_SEP_PE_CAP.format(capabilities = encode_capabilities_capabilitiesex(ctc_sess_other.front_data.get('msn_PE_capabilities') or 0, ctc_sess_other.front_data.get('msn_PE_capabilitiesex') or 0)) # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_PE.format( # epid_attrib = NFY_PUT_PRESENCE_USER_SEP_EPID.format(mguid = '{' + ctc_sess_other.front_data['msn_pop_id'] + '}'), pe_data = pe_data, # ) # nfy_rst += NFY_PUT_PRESENCE_USER_SEP_PD.format( # mguid = '{' + ctc_sess_other.front_data['msn_pop_id'] + '}', ped_data = _list_private_endpoint_data(ctc_sess_other) # ) # # msn_status = MSNStatus.FromSubstatus(substatus) # # nfy_presence_body = NFY_PUT_PRESENCE_USER.format( # substatus = msn_status.name, cm = cm or '', rst = nfy_rst, # ) # # nfy_payload = encode_payload(NFY_PUT_PRESENCE, # to = user_me.email, from_email = head.email, cl = len(nfy_presence_body), payload = nfy_presence_body, # ) # # yield ('NFY', 'PUT', nfy_payload) # return if is_offlineish and not head is user_me: if dialect >= 18: reply = ('FLN', encode_email_networkid(head.email, None, groupchat=groupchat) ) # type: Tuple[Any, ...] else: reply = ('FLN', head.email) if 13 <= dialect <= 17: # Mypy incorrectly gives a type error here. Must be a bug. reply += (int(NetworkID.WINDOWS_LIVE), ) # type: ignore if 13 <= dialect <= 15: reply += ('0', ) elif dialect >= 16: reply += ('0:0', ) yield reply return assert ctc_sess is not None msn_status = MSNStatus.FromSubstatus(status.substatus) if trid and dialect < 18: frst = ('ILN', trid) # type: Tuple[Any, ...] else: frst = ('NLN', ) rst = [] if 8 <= dialect <= 15: rst.append(((ctc_sess.front_data.get('msn_capabilities') or 0) if ctc_sess.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC)) elif dialect >= 16: rst.append( ('0:0' if groupchat is not None and head.uuid == user_me.uuid else encode_capabilities_capabilitiesex( ((ctc_sess.front_data.get('msn_capabilities') or 0) if ctc_sess.front_data.get('msn') is True else MAX_CAPABILITIES_BASIC), ctc_sess.front_data.get('msn_capabilitiesex') or 0))) if dialect >= 9: rst.append( encode_msnobj( ctc_sess.front_data.get('msn_msnobj') or '<msnobj/>')) if dialect >= 18: yield (*frst, msn_status.name, encode_email_networkid(head.email, None, groupchat=groupchat), status.name, *rst) else: yield (*frst, msn_status.name, head.email, (int(NetworkID.WINDOWS_LIVE) if 14 <= dialect <= 17 else None), status.name, *rst) if dialect < 11: return if dialect >= 18 and (groupchat is not None and head.uuid == user_me.uuid): return ubx_payload = '<Data><PSM>{}</PSM><CurrentMedia>{}</CurrentMedia>{}</Data>'.format( (encode_xml_he(status.message, dialect) if dialect >= 13 else encode_xml_ne(status.message)) or '', (encode_xml_he(status.media, dialect) if dialect >= 13 else encode_xml_ne(status.media)) or '', extend_ubx_payload(dialect, backend, user_me, ctc_sess)).encode('utf-8') if dialect >= 18: yield ('UBX', encode_email_networkid(head.email, None, groupchat=groupchat), ubx_payload) else: yield ('UBX', head.email, (int(NetworkID.WINDOWS_LIVE) if 14 <= dialect <= 17 else None), ubx_payload)
def register(loop: asyncio.AbstractEventLoop, backend: Backend, http_app: web.Application) -> None: from util.misc import ProtocolRunner from . import pager, http, voicechat, videochat backend.add_runner( ProtocolRunner('0.0.0.0', 5050, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) # Funny that Yahoo! used the FTP transfer, Telnet, SMTP, and NNTP (Usenet) ports as the fallback ports. backend.add_runner( ProtocolRunner('0.0.0.0', 20, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) backend.add_runner( ProtocolRunner('0.0.0.0', 23, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) backend.add_runner( ProtocolRunner('0.0.0.0', 25, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) backend.add_runner( ProtocolRunner('0.0.0.0', 119, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) # Yahoo! also utilized port 80 for YMSG communication via TCP, but that interferes with the port 80 binded to the HTTP # services when the server is run in dev mode. #backend.add_runner(ProtocolRunner('0.0.0.0', 80, ListenerYMSG, args = ['YH', backend, pager.YMSGCtrlPager])) backend.add_runner( ProtocolRunner('0.0.0.0', 8001, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) backend.add_runner( ProtocolRunner('0.0.0.0', 8002, ListenerYMSG, args=['YH', backend, pager.YMSGCtrlPager])) http.register(http_app) #voicechat.register(backend) videochat.register(backend)
def register(backend: Backend) -> None: from util.misc import ProtocolRunner backend.add_runner(ProtocolRunner('0.0.0.0', 5100, ListenerVideoChat))
def json_client(): return Backend()