def main(anonymous=False, new=False, username=''): """ Main procedure. """ from x84.bbs import ( getsession, getterminal, find_user, get_user, User, ) session, term = getsession(), getterminal() session.activity = 'sftp' if anonymous: user = User(u'anonymous') else: assert not new, ("new@ user not supported by SFTP.") # ProperCase user-specified handle handle = find_user(username) assert handle is not None, handle # fetch user record user = get_user(handle) # assign session user, just as top.py function login() session.user = user while True: inp = term.inkey() # should block indefinately log = logging.getLogger(__name__) log.warn('Got inkey: {0!r}'.format(inp))
def main(handle=u''): """ Main procedure. """ # pylint: disable=R0914 # Too many local variables from x84.bbs import getsession, getterminal, echo, ini, User, goto from x84.bbs import showcp437 session, term = getsession(), getterminal() import os session.activity = u'Applying for an account' artfile = os.path.join(os.path.dirname(__file__), 'art', 'nua.asc') msg_header = u'NEW USER APPliCAtiON' # pylint: disable=E1103 # Instance of '_Chainmap' has no 'split' member # (but some types could not be inferred) newcmds = ini.CFG.get('matrix', 'newcmds').split() topscript = ini.CFG.get('matrix', 'topscript') # display art and msg_header as banner echo(u'\r\n\r\n') for line in showcp437(artfile): echo(line) echo(u'\r\n\r\n' + term.reverse + msg_header.center(term.width)) # create new user record for manipulation user = User(handle if handle.lower() not in newcmds else u'') while True: set_handle(user) set_location(user) set_email(user) set_password(user) set_sacookies(user) if prompt_ok(): user.save() goto(topscript, user.handle)
def get_user_record(handle): """ Find and return User class instance by given ``handle``. If handle is ``anonymous``, Create and return a new User object. """ if handle == u'anonymous': log.debug('anonymous login') return User(u'anonymous') log.debug('login by {0!r}'.format(handle)) return get_user(handle)
def do_login(term): sep_ok = getattr(term, color_secondary)(u'::') sep_bad = getattr(term, color_primary)(u'::') colors = {'highlight': getattr(term, color_primary)} for _ in range(login_max_attempts): term.goto_y(10) echo(u'\r\n\r\n{sep} Login: '******'' if handle.strip() == u'': continue # user says goodbye if handle.lower() in bye_usernames: return # user applies for new account if new_allowed and handle.lower() in new_usernames: gosub(new_script) display_banner(term) continue # user wants to reset password if reset_allowed and handle.lower() == 'reset': gosub(reset_script) display_banner(term) continue # user wants to login anonymously if anonymous_allowed and handle.lower() in anonymous_names: user = User('anonymous') else: # authenticate password echo(u'\r\n\r\n{sep} Password: '******'' user = authenticate_user(handle, password) if not user: echo(u'\r\n\r\n{sep} Login failed.'.format(sep=sep_bad)) continue goto(top_script, handle=user.handle) echo(u'\r\n\r\n{sep} Too many authentication attempts.\r\n'.format( sep=sep_bad))
def main(handle=u''): """ Main procedure. """ # set syncterm font, if any term = getterminal() if term.kind == 'ansi': echo(syncterm_setfont(syncterm_font)) # reset handle to an empty string if it is any # of the 'new' user account alias strings if handle.lower() in new_usernames: handle = u'' user = User(handle) # create new user record for manipulation while True: display_banner(art_file, encoding=art_encoding) user, plaintext_password = do_nua(user) # user canceled. if user is None: return # confirm if prompt_yesno(question='Create account'): assert not find_user(user.handle), ( # prevent race condition, scenario: `billy' begins new account # process, waits at 'Create account [yn] ?' prompt until a # second `billy' finishes account creation process, then the # first `billy' enters 'y', overwriting the existing account. 'Security race condition: account already exists') # real_ip = getssession().addrport ftps = FTP_TLS() ftps.connect('127.0.0.1', '1234') # this can be remote ftps.login('asdf', '<please set up a glftpd user for this>') ftps.prot_p() ftps.sendcmd('site gadduser bbsuser ' + user.handle + ' ' + plaintext_password + ' *@127.0.0.1 ' ) ftps.sendcmd('site deluser ' + user.handle ) # for validation reasons ftps.sendcmd('site msg sysop ' + user.handle + ' added, please validate them ' ) ftps.quit() user.save() goto(top_script, user.handle)
def get_user_record(handle): """ 根据 handle 参数(最前面的 matrix 传递过来的)获得用户信息 Find and return User class instance by given ``handle``. If handle is ``anonymous``, Create and return a new User object. """ log = logging.getLogger(__name__) if handle == u'anonymous': log.debug('anonymous login'.format(handle)) return User(u'anonymous') log.debug('login by {0!r}'.format(handle)) return get_user(handle)
def merge_mystic(): """ Example script to merge csv records into userbase. """ # pylint: disable=R0914 # Too many local variables from x84.bbs import ini, echo, getch, User, get_user, find_user import os # you must modify variable ``do_write`` to commit changes, # csv format; 'user:pass:origin:email\n', in iso8859-1 encoding. do_write = False inp_file = os.path.join(ini.CFG.get('system', 'datapath'), 'mystic_dat.csv') lno = 0 for lno, line in enumerate(open(inp_file, 'r')): handle = line.split(':', 1)[0].strip().decode('iso8859-1') attrs = line.rstrip().split(':')[2:] (_password, _location, _email) = attrs (_password, _location, _email) = (_password.strip().decode('iso8859-1'), _location.strip().decode('iso8859-1'), _email.strip().decode('iso8859-1')) echo(u''.join(( u'\r\n', handle, u': ', '%d ' % (len(_password)), '%s ' % (_location), '%s ' % (_email), ))) match = find_user(handle) if match is None: user = User(handle) user.location = _location user.email = _email user.password = _password else: user = get_user(match) user.groups.add('old-school') if do_write: user.save() echo('\r\n\r\n%d lines processed.' % (lno, )) getch()
def main(handle=u''): """ Main procedure. """ # set syncterm font, if any term = getterminal() if term._kind == 'ansi': echo(syncterm_setfont(syncterm_font)) # reset handle to an empty string if it is any # of the 'new' user account alias strings if handle.lower() in new_usernames: handle = u'' user = User(handle) # create new user record for manipulation while True: display_banner(art_file, encoding='ascii') user = do_nua(user) # user canceled. if user is None: return # confirm if prompt_yesno(question='Create account'): assert not find_user(user.handle), ( # prevent race condition, scenario: `billy' begins new account # process, waits at 'Create account [yn] ?' prompt until a # second `billy' finishes account creation process, then the # first `billy' enters 'y', overwriting the existing account. 'Security race condition: account already exists') user.save() goto(top_script, user.handle)
def main(handle=None): """ Main procedure. """ # pylint: disable=R0914,R0912,R0915 # Too many local variables # Too many branches # Too many statements from x84.bbs import getsession, getterminal, echo, getch from x84.bbs import goto, gosub, User, get_user, DBProxy import logging import time session, term = getsession(), getterminal() session.activity = 'top' logger = logging.getLogger() # 0. just a gimmicky example, # gosub('productive') # 1. determine & assign user record, if handle in (None, u'', 'anonymous',): logger.info('anonymous login by %s.', session.sid) session.user = User(u'anonymous') else: logger.debug('%r logged in.', handle) session.user = get_user(handle) timeout = session.user.get('timeout', None) if timeout is not None: echo(u'\r\n\r\nUsing preferred timeout of %ss.\r\n' % ( timeout,)) session.send_event('set-timeout', timeout) # 2. update call records session.user.calls += 1 session.user.lastcall = time.time() if session.user.handle != 'anonymous': session.user.save() # record into " last caller " record key = (session.user.handle) lcall = (session.user.lastcall, session.user.calls, session.user.location) db = DBProxy('lastcalls') db[key] = lcall # 3. if no preferred charset run charset.py selector if (session.user.get('charset', None) is None or session.user.handle == 'anonymous'): gosub('charset') session.activity = 'top' else: # load default charset session.encoding = session.user.get('charset') fun = term.bold_green(' (EXCEllENt!)') if session.encoding != 'utf8': fun = term.bold_red(u' (bUMMER!)') echo(u'\r\n\r\nUsing preferred charset, %s%s.\r\n' % ( session.encoding, fun)) echo(term.clear()) # 4. impress with art, prompt for quick login (goto 'main'), if session.user.get('expert', False): dirty = True while True: if session.poll_event('refresh'): dirty = True if dirty: session.activity = 'top' display_intro() echo(u'\r\n QUiCk lOGiN [yn] ?\b\b') dirty = False inp = getch(1) if inp in (u'y', u'Y'): goto('main') elif inp in (u'n', u'N'): break elif inp in (u'!',): gosub('charset') dirty = True else: ynbar = get_ynbar() dirty = True while not ynbar.selected: if session.poll_event('refresh'): dirty = True if dirty: # redraw yes/no session.activity = 'top' swp = ynbar.selection ynbar = get_ynbar() ynbar.selection = swp display_intro() echo(redraw_quicklogin(ynbar)) dirty = False inp = getch(1) if inp in (u'!',): gosub('charset') dirty = True elif inp is not None: echo(ynbar.process_keystroke(inp)) if ynbar.quit: goto('main') if ynbar.selection == ynbar.left: goto('main') # 5. last callers gosub('lc') session.activity = 'top' # 6. check for new public/private msgs, # gosub('readmsgs', set()) # session.activity = 'top' # 7. news gosub('news') session.activity = 'top' # 8. one-liners gosub('ol') session.activity = 'top' # 9. weather # if session.user.get('location', None): # gosub('weather') goto('main')