コード例 #1
0
    def POST(self):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL'),
            'InfoMsg': '',
        }

        post_data = cherrypy.request.json
        username = post_data.get('username')
        password = post_data.get('password')
        permission = post_data.get('permission')

        if UserManageHelper.user_exists(username):
            result['InfoMsg'] = f'user {username} already exists'
            return result

        if not username or not password or not permission:
            result['InfoMsg'] = 'Missing user name, password, or permission'
            return result

        if UserManageHelper.getNumberOfUsers(
        ) < SystemSettingsManage.get_max_web_clients():
            if UserManageHelper.addUser(username, password, permission):
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
                result['InfoMsg'] = 'User added'
            else:
                result['InfoMsg'] = 'failed to add user'
        else:
            result['InfoMsg'] = 'Max number of users reached'

        return result
コード例 #2
0
    def GET(self, *args, **kwargs):
        result = {'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL')}

        try:
            iface = self.get_modem_location_interface(Modem._bus)
            if iface:
                data = iface.GetLocation()
                result['positioning'] = dbus_to_python(data)
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
        except dbus.exceptions.DBusException as e:
            syslog("Get positioning data: DBUS failed %s" % e)
        except Exception as e:
            syslog("Get positioning data failed: %s" % e)

        return result
コード例 #3
0
 def DELETE(self):
     result = {
         'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL', 1),
         'InfoMsg': '',
     }
     username = cherrypy.session.pop('USERNAME', None)
     if username:
         LoginManageHelper.delete(username)
         result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
         result['InfoMsg'] = f"user {username} logged out"
         syslog(f"logout user {username}")
     else:
         result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_FAIL')
         result['InfoMsg'] = f"user {username} not found"
     cherrypy.lib.sessions.expire()
     return result
コード例 #4
0
    def PUT(self):

        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
            'InfoMsg': '',
        }

        zone = cherrypy.request.json.get('zone', "")
        method = cherrypy.request.json.get('method', "")
        dt = cherrypy.request.json.get('datetime', "")

        returncode, outs, errs = self.popenHelper(method, zone, dt)
        if returncode:
            result['message'] = errs.decode("utf-8")
            result['InfoMsg'] = errs.decode("utf-8")
            result['SDCERR'] = 1
            return result

        #Python datetime module returns system time only. Extra modules like dateutil etc. are
        #required to calculate the offset according to the timezone. So just get it from bash.
        returncode, outs, errs = self.popenHelper("check", "", "")
        result['time'] = outs.decode("utf-8")
        result['SDCERR'] = 0
        result['InfoMsg'] = self.getLocalZone()
        return result
コード例 #5
0
    def PUT(self):
        """
			Update password/permission
		"""
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL'),
            'REDIRECT': 0,
            'InfoMsg': '',
        }

        post_data = cherrypy.request.json
        username = post_data.get('username', None)
        new_password = post_data.get('new_password', None)

        if not UserManageHelper.user_exists(username):
            result['InfoMsg'] = f'user {username} not found'
            return result

        if new_password:
            current_password = post_data.get('current_password', None)
            if UserManageHelper.verify(username, current_password):
                if UserManageHelper.updatePassword(username, new_password):
                    result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
                    #Redirect is required when the default password is updated
                    default_username = cherrypy.request.app.config[
                        'weblcm'].get('default_username', "root")
                    default_password = cherrypy.request.app.config[
                        'weblcm'].get('default_password', "summit")
                    result['InfoMsg'] = 'password changed'
                    if current_password == default_password and username == default_username:
                        result['REDIRECT'] = 1
                else:
                    result['InfoMsg'] = 'unable to update password'
            else:
                result['InfoMsg'] = 'incorrect current password'
        else:
            permission = post_data.get('permission', None)
            if permission:
                if UserManageHelper.updatePermission(username, permission):
                    result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
                    result['InfoMsg'] = 'User logged in'
                else:
                    result['InfoMsg'] = 'could not update session'
            else:
                result['InfoMsg'] = 'invalid session'
        return result
コード例 #6
0
    def DELETE(self, username):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL'),
            'InfoMsg': 'unable to delete user',
        }
        default_username = cherrypy.request.app.config['weblcm'].get(
            'default_username', "root")

        if username == default_username:
            result['InfoMsg'] = f'unable to remove {default_username} user'
        elif not UserManageHelper.user_exists(username):
            result['InfoMsg'] = f'user {username} not found'
        elif UserManageHelper.delUser(username):
            result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
            result['InfoMsg'] = 'User deleted'

        return result
コード例 #7
0
    def PUT(self):
        p = Popen(['systemctl', 'reboot'])
        p.wait()
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
            'InfoMsg': 'Reboot initiated',
        }
        syslog("reboot initiated")

        return result
コード例 #8
0
    def PUT(self):
        result = {'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL')}

        post_data = cherrypy.request.json
        token = post_data.get('token', 0)
        if not token:
            return result

        try:
            iface = self.get_modem_location_interface(Modem._bus)
            if iface:
                iface.InjectAssistanceData(bytearray(token.encode('utf-8')))
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
        except dbus.exceptions.DBusException as e:
            syslog("Set token: DBUS failed %s" % e)
        except Exception as e:
            syslog("Set token failed: %s" % e)

        return result
コード例 #9
0
    def PUT(self):
        result = {'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL')}

        try:
            post_data = cherrypy.request.json
            source = post_data.get('positioning', 0)
            if (PositioningSwitch._source !=
                    source) and (not source or not PositioningSwitch._source):
                iface = self.get_modem_location_interface(Modem._bus)
                if iface:
                    iface.Setup(dbus.UInt32(source), False)
                    PositioningSwitch._source = source
                    result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
        except dbus.exceptions.DBusException as e:
            syslog("Enable/disable positioning: DBUS failed %s" % e)
        except Exception as e:
            syslog("Enable/disable positioning failed: %s" % e)

        result['positioning'] = PositioningSwitch._source
        return result
コード例 #10
0
    def PUT(self):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL'),
            'InfoMsg': 'Reboot required',
        }

        setOptions = ['unset', 'fips', 'fips_wifi']

        post_data = cherrypy.request.json
        fips = post_data.get('fips', None)
        if fips not in setOptions:
            result[
                'InfoMsg'] = f'Invalid option: {fips}; valid options: {setOptions}'
            return result

        try:
            proc = Popen([Fips.FIPS_SCRIPT, fips], stdout=PIPE, stderr=PIPE)
        except Exception as e:
            syslog("FIPS SET exception: %s" % e)
            result['InfoMsg'] = 'Not a FIPS image'
            return result

        try:
            outs, errs = proc.communicate(
                timeout=SystemSettingsManage.get_user_callback_timeout())
        except TimeoutExpired:
            proc.kill()
            outs, errs = proc.communicate()
            syslog("FIPS SET timeout: %s" % e)
            result['InfoMsg'] = 'FIPS SET timeout'
        except Exception as e:
            syslog("FIPS set exception: %s" % e)
            result['InfoMsg'] = 'FIPS SET exception: {}'.format(e)

        if not proc.returncode:
            result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
        else:
            syslog("FIPS set error: %s" % e)
            result['InfoMsg'] = 'FIPS SET error'
        return result
コード例 #11
0
 def GET(self, *args, **kwargs):
     result = {
         'SDCERR':
         WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
         'InfoMsg':
         'only non-default users listed under \'Users\'',
         'Default_user':
         cherrypy.request.app.config['weblcm'].get('default_username',
                                                   "root")
     }
     result['Users'] = UserManageHelper.getUserList()
     result['Count'] = len(result.get('Users'))
     return result
コード例 #12
0
    def PUT(self):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL'),
        }
        p = Popen([FactoryReset.FACTORY_RESET_SCRIPT, 'reset'])
        result['SDCERR'] = p.wait()
        syslog("Factory Reset requested")
        if result.get('SDCERR') == 0:
            result['InfoMsg'] = 'Reboot required'
        else:
            result['InfoMsg'] = 'Error running factory reset'
            syslog("FactoryReset's p.wait() returned %s" %
                   result.get('SDCERR'))

        return result
コード例 #13
0
    def GET(self, *args, **kwargs):

        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
            'InfoMsg': '',
        }

        result['zones'] = self.zones
        result['zone'] = self.getLocalZone()

        returncode, outs, errs = self.popenHelper("check", "", "")
        if returncode:
            result['method'] = "manual"
        else:
            result['method'] = "auto"
        result['time'] = outs.decode("utf-8")

        return result
コード例 #14
0
    def GET(self, *args, **kwargs):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
            'InfoMsg': '',
            'status': "unset"
        }
        try:
            proc = Popen([Fips.FIPS_SCRIPT, 'status'],
                         stdout=PIPE,
                         stderr=PIPE)
        except Exception as e:
            syslog("FIPS get exception: %s" % e)
            result['InfoMsg'] = 'Not a FIPS image'
            return result

        try:
            outs, errs = proc.communicate(
                timeout=SystemSettingsManage.get_user_callback_timeout())
        except TimeoutExpired:
            proc.kill()
            outs, errs = proc.communicate()
            syslog("FIPS get timeout: %s" % e)
            result['InfoMsg'] = 'FIPS GET timeout'
        except Exception as e:
            syslog("FIPS get exception: %s" % e)
            result['InfoMsg'] = 'FIPS GET exception: {}'.format(e)

        if not proc.returncode:
            try:
                result['status'] = outs.decode("utf-8").strip()
            except Exception as e:
                syslog('FIPS GET exception: %s' % e)
        else:
            syslog("FIPS GET error: %d" % proc.returncode)
            result['InfoMsg'] = 'FIPS GET error'

        return result
コード例 #15
0
    def POST(self):
        result = {
            'SDCERR': WEBLCM_ERRORS.get('SDCERR_FAIL', 1),
            'REDIRECT': 0,
            'PERMISSION': "",
            'InfoMsg': '',
        }

        post_data = cherrypy.request.json
        username = post_data.get('username', "")
        password = post_data.get('password', "")
        syslog(f"Attempt to login user {username}")

        #Return if username is blocked
        if not cherrypy.session.get('USERNAME', None):
            if LoginManageHelper.is_user_blocked(username):
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_USER_BLOCKED')
                result['InfoMsg'] = 'User blocked'
                return result

        default_username = cherrypy.request.app.config['weblcm'].get(
            'default_username', "root")
        default_password = cherrypy.request.app.config['weblcm'].get(
            'default_password', "summit")

        #If default password is not changed, redirect to passwd update page.
        if ((username == default_username) and (password == default_password)):

            cnt = UserManageHelper.getNumberOfUsers()
            if not cnt:
                UserManageHelper.addUser(
                    username, password,
                    " ".join(USER_PERMISSION_TYPES['UserPermissionTypes']))

            if not cnt or UserManageHelper.verify(default_username,
                                                  default_password):

                LoginManageHelper.login_reset(username)
                if LoginManageHelper.is_user_logged_in(username):
                    result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_USER_LOGGED')
                    result['InfoMsg'] = 'User already logged in'
                    return result

                cherrypy.session['USERNAME'] = username
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
                result['REDIRECT'] = 1
                result['InfoMsg'] = 'Password change required'
                syslog(f"User {username} logged in")
                return result

        #Session is created, but default password was not changed.
        if cherrypy.session.get('USERNAME', None) == default_username:
            if UserManageHelper.verify(default_username, default_password):
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
                result['REDIRECT'] = 1
                result['InfoMsg'] = 'Password change required'
                syslog(f"User {username} logged in")
                return result

        #If session already exists, return success; otherwise verify login username and password.
        if not cherrypy.session.get('USERNAME', None):

            if not UserManageHelper.verify(username, password):
                LoginManageHelper.login_failed(username)
                result['InfoMsg'] = 'unable to verify user/password'
                return result

            LoginManageHelper.login_reset(username)

            if LoginManageHelper.is_user_logged_in(username):
                result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_USER_LOGGED')
                result['InfoMsg'] = 'User already logged in'
                return result

            cherrypy.session['USERNAME'] = username

        result['PERMISSION'] = UserManageHelper.getPermission(
            cherrypy.session.get('USERNAME', None))
        #Don't display "system_user" page for single user mode
        if SystemSettingsManage.get_max_web_clients() == 1:
            result['PERMISSION'] = result['PERMISSION'].replace(
                "system_user", "")

        result['SDCERR'] = WEBLCM_ERRORS.get('SDCERR_SUCCESS')
        result['InfoMsg'] = 'User logged in'
        syslog(f"user {username} logged in")
        return result
コード例 #16
0
 def GET(self, *args, **kwargs):
     result = {
         'SDCERR': WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
         'positioning': PositioningSwitch._source
     }
     return result