Exemplo n.º 1
0
    def GET(self, *args, **kwargs):

        result = {'SDCERR': 1, 'InfoMsg': "Device is busy"}

        if not cherrypy.session.get('swupdate', None):
            return result

        try:
            mode = int(kwargs.get('mode', 0))
        except Exception as e:
            result['InfoMsg'] = 'Mode must be 0 (block/block mode) or 1 '
            return result
        try:
            proc = Popen([SWUpdate.SWUPDATE_SCRIPT, "get-update",
                          str(mode)],
                         stdout=PIPE,
                         stderr=PIPE)
            outs, errs = proc.communicate(
                timeout=SystemSettingsManage.get_user_callback_timeout())
            if proc.returncode:
                ret_string = errs.decode("utf-8")
                result['InfoMsg'] = ret_string.replace("\n", "")
                result['SDCERR'] = proc.returncode
            else:
                result['InfoMsg'] = "Updated"
                result['SDCERR'] = 0

        except TimeoutExpired:
            proc.kill()
            outs, errs = proc.communicate()
            result['InfoMsg'] = "Update checking timeout"
        except Exception as e:
            result['InfoMsg'] = "{}".format(e)

        return result
Exemplo n.º 2
0
    def popenHelper(self, method="", zone="", dt=""):

        proc = Popen([DateTimeSetting.DATE_TIME_SCRIPT, method, zone, dt],
                     stdout=PIPE,
                     stderr=PIPE)
        try:
            outs, errs = proc.communicate(
                timeout=SystemSettingsManage.get_user_callback_timeout())
        except TimeoutExpired:
            proc.kill()
            outs, errs = proc.communicate()

        return (proc.returncode, outs, errs)
Exemplo n.º 3
0
	def get_reg_domain_info(cls):
		if not os.path.exists(NetworkStatusHelper._IW_PATH):
			return "WW"

		try:
			proc = Popen(["iw", "reg", "get"], stdout=PIPE, stderr=PIPE)
			outs, errs = proc.communicate(timeout=SystemSettingsManage.get_user_callback_timeout())
			if not proc.returncode:
				s = re.split('phy#', outs.decode("utf-8"))
				#Return regulatory domain of phy#0
				m = re.search('country [A-Z][A-Z]', s[1] if len(s) > 1 else s[0])
				if m:
					return m.group(0)[8:10]
		except TimeoutExpired:
			proc.kill()
			outs, errs = proc.communicate()
			syslog(LOG_ERR, "Call 'iw reg get' timeout")
		except Exception as e:
			syslog(LOG_ERR, "Call 'iw reg get' failed")

		return "WW"
Exemplo n.º 4
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
Exemplo n.º 5
0
	def get_frequency_info(cls, interface, frequency):
		if not os.path.exists(NetworkStatusHelper._IW_PATH):
			return frequency
		try:
			proc = Popen(["iw", "dev"], stdout=PIPE, stderr=PIPE)
			outs, errs = proc.communicate(timeout=SystemSettingsManage.get_user_callback_timeout())
			if not proc.returncode:
				ifces = re.split('Interface', outs.decode("utf-8"))
				for ifce in ifces:
					lines = ifce.splitlines()
					if (lines[0].strip() != interface) or (len(lines) < 7):
						continue
					m = re.search('[2|5][0-9]{3}', lines[6])
					if m:
						return m.group(0)
		except TimeoutExpired:
			proc.kill()
			outs, errs = proc.communicate()
			syslog(LOG_ERR, "Call 'iw dev' timeout")
		except Exception as e:
			syslog(LOG_ERR, "Call 'iw dev' failed")

		return frequency
Exemplo n.º 6
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
Exemplo n.º 7
0
        def do_swupdate(
            args,
            callback=None,
            timeout=SystemSettingsManage.get_user_callback_timeout()):

            try:
                proc = Popen(args, stdout=PIPE, stderr=PIPE)
                outs, errs = proc.communicate(timeout=timeout)
                if proc.returncode:
                    ret_string = errs.decode("utf-8")
                    result['InfoMsg'] = ret_string.replace("\n", "")

                    result['SDCERR'] = proc.returncode
                else:
                    if not callback or callback(dryrun) > 0:
                        result['InfoMsg'] = ''
                        result['SDCERR'] = 0
            except TimeoutExpired:
                proc.kill()
                outs, errs = proc.communicate()
                result['InfoMsg'] = "Update checking timeout"
            except Exception as e:
                result['InfoMsg'] = "{}".format(e)
            return