Beispiel #1
0
def create_user(email, pw1, pw2, support_old):
    errors = {}
    _check_email(errors, email)
    _check_passwords(errors, pw1, pw2)
    if errors: return errors

    with Session() as sess:
        user = _get_user(email)
        if user is not None:
            errors['email'] = "Email already in use."
            return errors
        user = User(
            uuid=gen_uuid(),
            email=email,
            verified=False,
            name=email,
            message='',
            settings={},
            groups={},
            contacts={},
        )
        _set_passwords(user, pw1, support_old)
        sess.add(user)

    return errors
Beispiel #2
0
def main(email: str, *, oldmsn: bool = False, yahoo: bool = False) -> None:
    with Session() as sess:
        user = sess.query(User).filter(User.email == email).one_or_none()
        if user is None:
            print("Creating new user...")
            user = User(
                uuid=misc.gen_uuid(),
                email=email,
                verified=False,
                name=email,
                message='',
                groups={},
                settings={},
            )

            # TODO: Should be generated on-demand, not here
            #ticketxml = '<?xml version="1.0" encoding="utf-16"?>\r\n<Ticket xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r\n  <TS>{}</TS>\r\n  <CID>{}</CID>\r\n</Ticket>'.format(
            #	now.isoformat()[0:19] + 'Z', cid_format(user.uuid, decimal = True)
            #)
            #user.set_front_data('msn', 'circleticket', misc.sign_with_new_key_and_b64(ticketxml))
        else:
            print("User exists, changing password...")
        pw = getpass.getpass("Password: "******"Done.")
Beispiel #3
0
 def me_group_add(self, name: str) -> Group:
     if len(name) > MAX_GROUP_NAME_LENGTH:
         raise error.GroupNameTooLong()
     user = self.user
     detail = user.detail
     assert detail is not None
     if name == '(No Group)':
         raise error.GroupAlreadyExists()
     groups = detail.get_groups_by_name(name)
     if groups is not None:
         name += str(len(groups))
     group = Group(_gen_group_id(detail), gen_uuid(), name, False)
     detail.insert_group(group)
     self.backend._mark_modified(user)
     return group
Beispiel #4
0
async def handle_http_gateway(req: web.Request) -> web.Response:
	query = req.query
	session_id = query.get('SessionID')
	backend = req.app['backend']
	gateway_sessions = req.app['gateway_sessions'] # type: Dict[str, GatewaySession]
	now = time.time()
	
	if not session_id:
		from front.msn.msnp_ns import MSNPCtrlNS
		from front.msn.msnp_sb import MSNPCtrlSB
		
		# Create new GatewaySession
		server_type = query.get('Server')
		server_ip = query.get('IP')
		session_id = gen_uuid()
		
		logger = Logger('GW-{}'.format(server_type), session_id)
		
		if server_type == 'NS':
			controller = MSNPCtrlNS(logger, 'gw', backend) # type: MSNPCtrl
		else:
			controller = MSNPCtrlSB(logger, 'gw', backend)
		
		tmp = GatewaySession(logger, server_ip, controller, now)
		controller.close_callback = tmp._on_close
		gateway_sessions[session_id] = tmp
	gwsess = gateway_sessions.get(session_id)
	if gwsess is None:
		raise web.HTTPBadRequest()
	
	assert req.transport is not None
	gwsess.logger.log_connect()
	gwsess.controller.data_received(req.transport, await req.read())
	gwsess.logger.log_disconnect()
	body = gwsess.controller.flush()
	
	return web.HTTPOk(headers = {
		'Access-Control-Allow-Origin': '*',
		'Access-Control-Allow-Methods': 'POST',
		'Access-Control-Expose-Headers': 'X-MSN-Messenger',
		'X-MSN-Messenger': 'SessionID={}; GW-IP={}'.format(session_id, gwsess.hostname),
		'Content-Type': 'application/x-msn-messenger',
	}, body = body)
Beispiel #5
0
    def create_groupchat(self, user: User, name: str, owner_friendly: str,
                         membership_access: int) -> str:
        with Session() as sess:
            chat_id = misc.gen_uuid()[-12:]

            dbgroupchat = DBGroupChat(
                chat_id=chat_id,
                name=name,
                owner_id=user.id,
                owner_uuid=user.uuid,
                owner_friendly=owner_friendly,
                membership_access=membership_access,
                request_membership_option=0,
            )

            dbgroupchat.add_membership(user.uuid, int(GroupChatRole.Admin),
                                       int(GroupChatState.Accepted))

            sess.add(dbgroupchat)

        return chat_id
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser(
        description="Create user/change password.")
    parser.add_argument('email', help="email of new/existing user")
    parser.add_argument('password')
    parser.add_argument('--old',
                        dest='old_msn_support',
                        action='store_const',
                        const=True,
                        default=False,
                        help="old MSN support")
    args = parser.parse_args()

    email = args.email
    pw = args.password

    with Session() as sess:
        user = sess.query(User).filter(User.email == email).one_or_none()
        if user is None:
            print("Creating new user...")
            user = User(
                uuid=gen_uuid(),
                email=email,
                verified=False,
                name=email,
                message='',
                settings={},
                groups={},
                contacts={},
            )
        else:
            print("User exists, changing password...")
        _set_passwords(user, pw, args.old_msn_support)
        sess.add(user)

    print("Done.")
Beispiel #7
0
    def save_oim(self,
                 bs: 'BackendSession',
                 recipient_uuid: str,
                 run_id: str,
                 origin_ip: str,
                 message: str,
                 utf8: bool,
                 *,
                 from_friendly: Optional[str] = None,
                 from_friendly_charset: str = 'utf-8',
                 from_friendly_encoding: str = 'B',
                 from_user_id: Optional[str] = None,
                 headers: Dict[str, str] = {},
                 oim_proxy: Optional[str] = None) -> None:
        assert bs is not None
        user = bs.user

        path = _get_oim_path(recipient_uuid)
        path.mkdir(parents=True, exist_ok=True)
        oim_uuid = misc.gen_uuid().upper()
        oim_path = path / oim_uuid

        if oim_path.is_file():
            return

        oim_json = {}  # type: Dict[str, Any]
        oim_json['uuid'] = oim_uuid
        oim_json['run_id'] = run_id
        oim_json['from'] = user.email
        oim_json['from_friendly'] = {
            'friendly_name': from_friendly,
            'encoding':
            (None if from_friendly is None else from_friendly_encoding),
            'charset':
            (None if from_friendly is None else from_friendly_charset),
        }
        oim_json['from_user_id'] = from_user_id
        oim_json['is_read'] = False
        oim_json['sent'] = misc.date_format(datetime.utcnow())
        oim_json['origin_ip'] = origin_ip
        oim_json['proxy'] = oim_proxy
        oim_json['headers'] = headers
        oim_json['message'] = {
            'text': message,
            'utf8': utf8,
        }

        oim_path.write_text(json.dumps(oim_json))

        oim = OIM(oim_json['uuid'],
                  oim_json['run_id'],
                  oim_json['from'],
                  oim_json['from_friendly']['friendly_name'],
                  user.email,
                  iso_parser.parse(oim_json['sent']),
                  oim_json['message']['text'],
                  oim_json['message']['utf8'],
                  headers=oim_json['headers'],
                  from_friendly_encoding=oim_json['from_friendly']['encoding'],
                  from_friendly_charset=oim_json['from_friendly']['charset'],
                  from_user_id=oim_json['from_user_id'],
                  origin_ip=oim_json['origin_ip'],
                  oim_proxy=oim_json['proxy'])

        bs.me_contact_notify_oim(recipient_uuid, oim)
Beispiel #8
0
	def __init__(self, stats):
		self.id = gen_uuid()
		# Dict[Session, User]
		self._users_by_sess = {}
		self._stats = stats
Beispiel #9
0
 def _add_user(self, email):
     u = User(gen_uuid(), email, True, UserStatus(email))
     self._user_by_uuid[u.uuid] = u
     self._user_by_email[u.email] = u
     self._detail_by_uuid[u.uuid] = UserDetail({})