Example #1
0
def configure_node_red_https(state):
    """ Configure node red to use http or https.
    Args:
        state (str): 'true' or 'false'

    Returns:

    """
    settings = '/home/gwuser/.node-red/settings.js'
    https_settings = settings + ".https"
    http_settings = settings + ".http"
    shell_ops.run_command('systemctl stop node-red-experience.service')
    if state == 'true':
        if os.path.isfile(https_settings):
            try:
                os.rename(settings, http_settings)
                os.rename(https_settings, settings)
            except:
                pass
    else:
        if os.path.isfile(http_settings):
            try:
                os.rename(settings, https_settings)
                os.rename(http_settings, settings)
            except:
                pass
    shell_ops.run_command('systemctl start node-red-experience.service')
 def IsMecEnabled(self):
     try:
         result = shell_ops.run_command("sadmin status")
     except:
         pass
         result = ""        
     if "Enabled" in result:
         self.enabled = True 
     return self.enabled
 def IsMecEnabled(self):
     try:
         result = shell_ops.run_command("sadmin status")
     except:
         pass
         result = ""
     if "Enabled" in result:
         self.enabled = True
     return self.enabled
 def IsMecInstalled(self):
     try:
         result = shell_ops.run_command("sadmin version")
     except:
         pass
         result = ""        
     if "McAfee Solidifier" in result:
         self.installed = True
     return self.installed         
 def IsMecInstalled(self):
     try:
         result = shell_ops.run_command("sadmin version")
     except:
         pass
         result = ""
     if "McAfee Solidifier" in result:
         self.installed = True
     return self.installed
Example #6
0
def configure_nginx_https(state):
    log_helper = logging_helper.logging_helper.Logger()
    node_cloudcmd_conf_file = "/home/gwuser/.node-cloudcmd/node-cloudcmd_nginx_http.conf"
    node_red_conf_file = "/home/gwuser/.node-red/node-red_nginx_http.conf"
    if state == 'true':
        node_cloudcmd_conf_file = node_cloudcmd_conf_file.replace(
            "http", "https")
        node_red_conf_file = node_red_conf_file.replace("http", "https")
    try:
        shutil.copyfile(node_cloudcmd_conf_file,
                        '/etc/nginx/conf.d/node-cloudcmd.conf')
        shutil.copyfile(node_red_conf_file, '/etc/nginx/conf.d/node-red.conf')
        log_helper.logger.debug(
            'node-red and cloud commander nginx https configured')
        log_helper.logger.debug('Restarting ngnix')
        shell_ops.run_command('systemctl restart nginx.service')
    except Exception as e:
        log_helper.logger.error(str(e))
        log_helper.logger.error(
            "Failed to configure https settings for node-red and cloudcmd")
 def GetMecType(self):
     self.mec_type = ""
     try:
         result = shell_ops.run_command("sadmin license list")
         if "MEC Essential" in result:
             self.mec_type = "Essential"
         else:
             self.mec_type = "Pro"
     except:
             pass
     return self.mec_type
 def getWifiSSID(self):
     """ Return WiFi SSID.
     Returns:
         str: WiFi SSID
     """
     self.__ss_id = shell_ops.run_command(
         'uci show wireless.@wifi-iface[0].ssid')
     if 'not found' in self.__ss_id:
         return 'No Wireless'
     self.__ss_id = self.__ss_id.strip('\n').split('=')
     return self.__ss_id[1]
 def GetMecType(self):
     self.mec_type = ""
     try:
         result = shell_ops.run_command("sadmin license list")
         if "MEC Essential" in result:
             self.mec_type = "Essential"
         else:
             self.mec_type = "Pro"
     except:
         pass
     return self.mec_type
    def update(self):
        # make sure existing temp file is not used
        try:
            os.unlink(self.__script)
        except:
            # the file may not exist..
            pass

        # mark dev hub as no update
        # We need this in case that the package list file is not updated due to some network glitch.
        # Once the network is back on, the package list file will be updated.
        # So this is just for user friendliness until package list file is updated.
        try:
            temp_config_file = open(manage_config.package_data_file, 'r')
            temp_output = temp_config_file.read().decode('string_escape')
            temp_config_file.close()
            import json
            temp_output_json = json.loads(temp_output)
            for json_entry in temp_output_json:
                if json_entry['name'] == 'iot-developer-hub':
                    json_entry['upgrade_version'] = ''

            with open(manage_config.package_data_file, 'w') as my_file:
                my_file.write(json.dumps(temp_output_json))
        except:
            pass

        try:
            dh_upgrade = open(self.__script, 'w+')
            dh_upgrade.write(self.__process)
            dh_upgrade.close()
            shell_ops.run_command('chmod 700 /tmp/update-iot-dev-hub.sh')
            shell_ops.run_command('systemctl --no-block start iot-dev-hub-update')
            self.__response['status'] = "success"
        except Exception as e:
            self.__log_helper.logger.error(str(e))
            self.__response['status'] = "failure"
        return self.__response
Example #11
0
 def set_hdc_server_details():
     log_helper = logging_helper.logging_helper.Logger()
     try:
         f = open('/var/wra/files/default/default_settings', 'r+')
         data = json.load(f)
         data['device_config'][0]['model_number'] = "MI-IDP-IOT-GW-EVAL"
         data['ems_server_config'][0]['server_address'] = "wrpoc6.axeda.com"
         f.seek(0)
         f.write(json.dumps(data, indent=5, sort_keys=True))
         f.truncate()
         try:
             shell_ops.run_command(
                 'systemctl --no-block restart wr-iot-agent')
         except:
             log_helper.logger.debug(
                 "Unable to restart wr-iot-agent service. Package may not be installed."
             )
             pass
         HDCSettings.upgrade_status()
         log_helper.logger.debug('updated HDC server settings')
     except IOError:
         log_helper.logger.error(
             "HDC settings file doesn't exist. No need to set HDC server settings"
         )
def list_repos_original(do_filter=False, keep_tracking=True):
    """ List all repositories from the 'smart channel --list' command.
    Args:
        do_filter (bool): True to perform filtering.
        keep_tracking (bool): True to keep the repos in tracking file. False to remove the repos in tracking file.
    Returns:
        list: list of String of channel names
    """
    log_helper = logging_helper.logging_helper.Logger()
    response = []
    channel_list = shell_ops.run_command('smart channel --list').split("\n")
    for item in channel_list:
        if item != "" and 'rpmsys' not in item:
            response.append(item)
    if do_filter:
        response = RepoTracking.filter_repo_list(response, keep_tracking=keep_tracking)
    log_helper.logger.debug("List of repositories: '%s'" % str(response))
    return response
 def getCPUType(self):
     """ Return cpu arch.
     Returns:
         str: cpu arch
     """
     global arch
     global display_arch
     if arch == "Not Set":
         self.__log_helper.logger.debug('Setting Arch')
         command = '''rpm -q --queryformat %{ARCH} bash'''
         arch = shell_ops.run_command(command)
         if arch == 'corei7_64':
             arch = "baytrail"
         elif arch == 'quark':
             arch = "quark"
         else:
             arch = "haswell"
     cpu_name = shell_ops.run_cmd_chk(
         "cat /proc/cpuinfo | grep 'model name' | uniq")
     display_arch = cpu_name['cmd_output'].split(':')[1]
     return display_arch
def set_proxy_config_in_worker_process(http_url, http_port, https_url, https_port, ftp_url,
                                       ftp_port, socks_url, socks_port, no_proxy):
    """ Writes the new proxy configuration to the /etc/environment file without overriding other environment configurations.
        This also has to be done in the worker process...

    Args:
        http_url (str):
        http_port (str):
        https_url (str):
        https_port (str):
        ftp_url (str):
        ftp_port (str):
        socks_url (str):
        socks_port (str):
        no_proxy (str): comma separated

    Returns:
        str: Json response with key 'status' and value 'success' if no error was encountered.
    """
    log_helper = logging_helper.logging_helper.Logger()
    network_checker = network_ops.NetworkCheck()

    proxy_mass = ''
    http_proxy = ''
    https_proxy = ''
    if http_url != '' and http_port != '':
        http_proxy = http_url + ':' + http_port
        proxy_mass += 'http_proxy=' + http_proxy + '\n'
        os.environ["http_proxy"] = http_proxy
    else:
        os.environ["http_proxy"] = ''

    if https_url != '' and https_port != '':
        https_proxy = https_url + ':' + https_port
        proxy_mass += 'https_proxy=' + https_proxy + '\n'
        os.environ["https_proxy"] = https_proxy
    else:
        os.environ["https_proxy"] = ''

    if ftp_url != '' and ftp_port != '':
        ftp_proxy = ftp_url + ':' + ftp_port
        proxy_mass += 'ftp_proxy=' + ftp_proxy + '\n'
        os.environ["ftp_proxy"] = ftp_proxy
    else:
        os.environ["ftp_proxy"] = ''

    if socks_url != '' and socks_port != '':
        socks_proxy = socks_url + ':' + socks_port
        proxy_mass += 'socks_proxy=' + socks_proxy + '\n'
        os.environ["socks_proxy"] = socks_proxy
    else:
        os.environ["socks_proxy"] = ''

    if no_proxy != '':
        no_proxy = no_proxy
        proxy_mass += 'no_proxy=' + no_proxy + '\n'
        os.environ["no_proxy"] = no_proxy
    else:
        os.environ["no_proxy"] = ''

    # Add Java proxy support
    java_proxy = "_JAVA_OPTIONS='-Dhttp.proxyHost=%s -Dhttp.proxyPort=%s -Dhttps.proxyHost=%s -Dhttps.proxyPort=%s'" % (http_url, http_port, https_url, https_port)
    proxy_mass += java_proxy

    # Update proxy environment file
    update = open('/var/www/www-repo-gui/proxy_env', 'w+')
    update.write(proxy_mass)
    update.close()
    log_helper.logger.debug("New environment file: '%s'" % proxy_mass)

    # Confirm if NPM is installed and update proxy
    npm_check = os.path.isfile('/usr/bin/npm')
    if npm_check:
        if http_proxy != '':
            if '://' not in http_proxy:
                http_proxy = 'http://' + http_proxy
            shell_ops.run_command('npm config set proxy ' + http_proxy)
        else:
            shell_ops.run_command('npm config rm proxy')
        if https_proxy != '':
            if '://' not in https_proxy:
                https_proxy = 'https://' + https_proxy
            shell_ops.run_command('npm config set https-proxy ' + https_proxy)
        else:
            shell_ops.run_command('npm config rm https-proxy')

    # Set proxy for HDC
    if '://' in http_url:
        split_url = http_url.split('://')
        http_url = split_url[1]
    if http_url != '':
        manage_config.HDCSettings.set_proxy_settings_for_HDC("http", http_url, http_port)
    else:
        manage_config.HDCSettings.set_proxy_settings_for_HDC("none", "proxy.windriver.com", "3128")

    # Check network connections
    response = {'status': 'success', 'https_conn': 'False'}
    net_conn, net_resp = network_checker.test_network_connection(check_http=manage_config.network_check_http,
                                                                 no_rest_period=True)
    if net_conn['https_conn'] == "False" or net_conn['http_conn'] == 'False':
        log_helper.logger.debug("Proxy setting invalid: '%s'" % proxy_mass)
        manage_config.network_status['https_conn'] = net_conn['https_conn']
        manage_config.network_status['http_conn'] = net_conn['http_conn']
        return json.dumps(response)
    else:
        manage_config.network_status['https_conn'] = net_conn['https_conn']
        manage_config.network_status['http_conn'] = net_conn['http_conn']
        response['https_conn'] = 'True'

    # Add Flex repos if we are in flex.
    # And we do not need to check network again since we checked it already.
    pro_status = manage_pro_upgrade.ProStatus()
    if pro_status.enabled_state()['result'] == 'False':
        log_helper.logger.debug('Has network and in flex... so add flex repos.')
        # add flex repos
        os_updater = manage_os_update.OS_UPDATER(sysinfo_ops.rcpl_version, sysinfo_ops.arch)
        add_result = os_updater.add_os_repos()
        if add_result['status'] == 'fail':
            log_helper.logger.error('Failed to add flex repos.. ' + add_result['error'])

    # We do this at the end so that we don't run too many processes.
    # Restart Node-Red and WR-IOT-Agent for Proxy settings to take effect
    try:
        shell_ops.run_command('systemctl --no-block restart node-red-experience')
    except:
        log_helper.logger.debug("Unable to restart node-red service. Package may not be installed.")
        pass

    try:
        shell_ops.run_command('systemctl --no-block restart wr-iot-agent')
    except:
        log_helper.logger.debug("Unable to restart wr-iot-agent service. Package may not be installed.")
        pass

    return json.dumps(response)
 def getDevHubVersion(self):
     devhub_version = shell_ops.run_command(
         'rpm -q --queryformat %{version}-%{release} iot-developer-hub')
     return devhub_version