コード例 #1
0
    def on_unknown_command(self, command, *args, context=None):
        username = context.pop('username')
        password = command

        for creds in self._model.credentials:
            if creds.username == username and creds.password == password:
                user = self._model.get_user('id', creds.user_id)
                if user.lock_status == 'locked':
                    text = self._render('user_locked', context=context)
                    self._write(text)
                    raise exceptions.TerminalExitError()
                num = user.reenter_num
                user.set_reenter_num_temp(num)
                user.set_online()
                break

        else:
            try:
                user = self._model.get_user('name', username)
            except exceptions.SoftboxenError:
                text = self._render('password', context=context)
                self._write(text)
                raise exceptions.TerminalExitError()
            else:
                if user.reenter_num_temp < 0:
                    if (user.level == 'Admin') or (user.level == 'Super'):
                        user.set_reenter_num_temp(user.reenter_num)
                        text = self._render('password', context=context)
                        self._write(text)
                        raise exceptions.TerminalExitError()
                    else:
                        user.lock()
                        text = self._render('user_locked', context=context)
                        self._write(text)
                        raise exceptions.TerminalExitError()
                else:
                    num = user.reenter_num_temp - 1
                    user.set_reenter_num_temp(num)
                    text = self._render('password', context=context)
                    self._write(text)
                    raise exceptions.TerminalExitError()

        self._output.write(bytes(False))
        self._output.write(bytes(False))

        subprocessor = self._create_subprocessor(
            UserViewCommandProcessor, 'login', 'mainloop')

        context['timestamp1'] = self._model.last_login
        context['timestamp2'] = self._model.last_logout
        self._model.set_last_login(datetime.now().strftime("%m/%d/%Y %H:%M:%S"))
        self._model.set_last_logout('/')

        subprocessor.loop(context=context)
コード例 #2
0
    def on_unknown_command(self, command, *args, context=None):
        context['welcome_banner'] = self._model.welcome_banner
        username = context.pop('username')
        password = command

        for creds in self._model.credentials:
            if creds.username == username and creds.password == password:
                break

        else:
            text = self._render('password', context=context)
            self._write(text)
            raise exceptions.TerminalExitError()

        subprocessor = self._create_subprocessor(UserViewCommandProcessor,
                                                 'login', 'mainloop')

        context['timestamp'] = self._model.last_login
        context['meltStart'] = False
        context['session_id'] = ''

        self.on_exit(context)
        self._model.set_last_login(
            datetime.now().strftime("%m/%d/%Y %H:%M:%S"))

        subprocessor.loop(context=context)
コード例 #3
0
    def do_disable(self, command, *args, context=None):

        from .userViewCommandProcessor import UserViewCommandProcessor

        exc = exceptions.TerminalExitError()
        exc.return_to = UserViewCommandProcessor
        raise exc
コード例 #4
0
    def do_return(self, command, *args, context=None):

        from .enableCommandProcessor import EnableCommandProcessor

        exc = exceptions.TerminalExitError()
        exc.return_to = EnableCommandProcessor
        raise exc
コード例 #5
0
    def on_unknown_command(self, command, *args, context=None):
        username = context.pop('username')
        password = command

        for creds in self._model.credentials:
            if creds.username == username and creds.password == password:
                break

        else:
            text = self._render('password', context=context)
            self._write(text)
            raise exceptions.TerminalExitError()

        self.case_sensitive = False

        subprocessor = self._create_subprocessor(RootCommandProcessor, 'login',
                                                 'base')

        context['path'] = '/'

        self._write(
            self._render('login_message', 'login', 'base', context=context))

        subprocessor.loop(context=context, return_to=RootCommandProcessor)

        self.on_exit(context)
コード例 #6
0
 def do_restart(self, command, *args, context=None):
     card = self.get_component()
     if len(args) == 0 and context['path'].split('/')[-1] == 'main' and (
             card.product == 'isdn' or card.product == 'analog'):
         time.sleep(10)
         exc = exceptions.TerminalExitError()
         exc.return_to = 'sysreboot'
         raise exc
     else:
         raise exceptions.CommandSyntaxError(command=command)
コード例 #7
0
    def on_unknown_command(self, command, *args, context=None):
        context['welcome_banner'] = self._model.welcome_banner
        username = context.pop('username')
        password = command

        for creds in self._model.credentials:
            if creds.username == username and creds.password == password:
                user = self._model.get_user('id', creds.user_id)
                if user.level == 'Enable':
                    text = self._render('password', context=context)
                    self._write(text)
                    raise exceptions.TerminalExitError()
                user.set_online()
                break

        else:
            text = self._render('password', context=context)
            self._write(text)
            raise exceptions.TerminalExitError()

        subprocessor = self._create_subprocessor(UserViewCommandProcessor,
                                                 'login', 'mainloop')

        subprocessor.loop(context=context)
コード例 #8
0
 def do_quit(self, command, *args, context=None):
     self._write(
         "  Check whether system data has been changed. Please save data before logout.\n"
     )
     answer = 'y'
     if self._model.interactive_mode:
         answer = self.user_input("Are you sure to log out? (y/n)[n]:",
                                  False, 1)
     if answer == "y":
         self._model.set_last_logout(
             datetime.now().strftime("%m/%d/%Y %H:%M:%S"))
         user = self._model.get_user('status', 'online')
         user.set_offline()
         self._model.enable_smart()
         self._model.enable_interactive()
         exc = exceptions.TerminalExitError()
         exc.return_to = 'sysexit'
         raise exc
     return
コード例 #9
0
    def on_unknown_command(self, command, *args, context=None):
        username = context.pop('username')
        password = command

        for creds in self._model.credentials:
            if creds.username == username and creds.password == password:
                user = self._model.get_user('id', creds.user_id)
                if user.profile == 'root':
                    break
        else:
            text = self._render('password', context=context)
            self._write(text)
            raise exceptions.TerminalExitError()

        self._output.write(bytes(False))
        self._output.write(bytes(False))

        subprocessor = self._create_subprocessor(UserViewCommandProcessor,
                                                 'login', 'mainloop')

        subprocessor.loop(context=context)
コード例 #10
0
 def do_quit(self, command, *args, context=None):
     raise exceptions.TerminalExitError()
コード例 #11
0
 def do_exit(self, command, *args, context=None):
     exc = exceptions.TerminalExitError()
     exc.return_to = 'sysexit'
     raise exc
コード例 #12
0
    def do_switch(self, command, *args, context=None):
        if self._validate(args, 'vdsl', 'mode', 'to', str):
            user = self._model.get_user('status', 'online')
            if user.level != 'Super':
                raise exceptions.CommandSyntaxError(command=command)

            dsl_mode, = self._dissect(args, 'vdsl', 'mode', 'to', str)
            context['dsl_mode'] = dsl_mode
            if dsl_mode != 'tr129' and dsl_mode != 'tr165':
                self.line_buffer = []
                raise exceptions.CommandSyntaxError(command=command)

            if self._model.smart_mode:
                self.user_input('{ <cr>|adsl<K> }:', False)
                text = self._render('switch_dsl_mode_temp_1', context=context)
                self._write(text)

            if self._model.dsl_mode == dsl_mode:
                text = self._render('switch_dsl_mode_failure', context=context)
                self._write(text)
                self.line_buffer = []
                return

            answer_one = 'y'
            if self._model.interactive_mode:
                answer_one = self.user_input(
                    '  Warning: The operation will result in loss of all VDSL configuration. '
                    'Are you sure to proceed? (y/n)[n]:', False)
            if answer_one != 'y':
                self.line_buffer = []
                return

            answer_two = 'y'
            if self._model.interactive_mode:
                answer_two = self.user_input(
                    '  Warning: The operation will automatically save and reboot system. '
                    'Are you sure you want to proceed? (y/n)[n]:', False)
            if answer_two != 'y':
                self.line_buffer = []
                return

            text = self._render('switch_dsl_mode_temp_2', context=context)
            self._write(text)
            self._model.set_dsl_mode(dsl_mode)
            self.on_cycle(context=context)

            mgmt_card = self._model.get_card('product', 'mgnt')
            context['mgmt_card'] = mgmt_card.name[2:]
            x = 6
            while x <= 100:
                time.sleep(1)
                context['current_time'] = datetime.now().strftime(
                    '%Y-%m-%d %H:%M:%S')
                context['progress'] = x
                self._write(self._render('saving_progress', context=context))
                self.on_cycle(context=context)
                x += 6

            context['current_time'] = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S')
            self._write(self._render('saving_complete', context=context))
            self.on_cycle(context=context)
            time.sleep(10)
            self._model.set_last_logout(
                datetime.now().strftime("%m/%d/%Y %H:%M:%S"))
            user = self._model.get_user('status', 'online')
            user.set_offline()
            exc = exceptions.TerminalExitError()
            exc.return_to = 'sysreboot'
            raise exc

        else:
            raise exceptions.CommandSyntaxError(command=command)
コード例 #13
0
    def do_exit(self, command, *args, context=None):
        from .confCommandProcessor import ConfCommandProcessor

        exc = exceptions.TerminalExitError()
        exc.return_to = ConfCommandProcessor
        raise exc
コード例 #14
0
 def do_quit(self, command, *args, context=None):
     context.pop('srvprof')
     raise exceptions.TerminalExitError()
コード例 #15
0
 def do_exit(self, command, *args, context=None):
     user = self._model.get_user('status', 'online')
     user.set_offline()
     raise exceptions.TerminalExitError()