def getsupportlevel(of=0): global supportedsys if getosname(0)=="linux": import linux_os lvl = 0 if rpieGlobals.osinuse=="linux": if (linux_os.is_command_found('dpkg')) and (linux_os.is_command_found('apt')): lvl = 1 if linux_os.checkRPI(): lvl = 10 elif (linux_os.is_command_found('pacman')): lvl = 2 if of == 0: return supportedsys[lvl] else: return lvl
def installdeps(modulename): global modulelist for i in range(len(modulelist)): if modulelist[i]["name"]==modulename and modulelist[i]["installed"]!=1: modulelist[i]["installed"] = -1 try: if modulelist[i]["apt"]: installprog = " " for j in range(len(modulelist[i]["apt"])): if rpieGlobals.ossubtype==2: # arch exceptions if "python3-pip" in modulelist[i]["apt"][j]: modulelist[i]["apt"][j].replace("python3-pip","python-pip") installprog += modulelist[i]["apt"][j] + " " if rpieGlobals.ossubtype in [1,10]: installprog = OS.cmdline_rootcorrect("sudo apt-get update && sudo apt-get install -y "+ installprog.strip()) elif rpieGlobals.ossubtype==2: installprog = OS.cmdline_rootcorrect("yes | sudo pacman -S "+ installprog.strip()) misc.addLog(rpieGlobals.LOG_LEVEL_INFO,installprog) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull,"wb"), executable="/bin/bash") proc.wait() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e)) try: if modulelist[i]["pip"]: installprog = " " for j in range(len(modulelist[i]["pip"])): installprog += modulelist[i]["pip"][j] + " " installprog = "sudo -H pip3 install "+ installprog.strip() if OS.is_command_found("sudo")==False: # if sudo is installed use it because -H option is important installprog = OS.cmdline_rootcorrect("sudo -H pip3 install "+ installprog.strip()) misc.addLog(rpieGlobals.LOG_LEVEL_INFO,installprog) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull,"wb"), executable="/bin/bash") proc.wait() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e)) try: if modulelist[i]["installcmd"]: installprog = OS.cmdline_rootcorrect(modulelist[i]["installcmd"].strip()) misc.addLog(rpieGlobals.LOG_LEVEL_INFO,installprog) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull,"wb"), executable="/bin/bash") proc.wait() except Exception as e: if e!='installcmd': misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e)) break
def networkinit(self): ipi = getipinfos() ni = parseifconfig(ipi) realdevs = 0 if ni: if len(ni) > 0: #ni.sort(reverse=True,key=getsortkey) realdevs = 0 for i in range(len(ni)): if ni[i]["mac"] != "": if len(Settings.NetworkDevices) <= realdevs: tarr = NetworkDevice() Settings.NetworkDevices.append(tarr) Settings.NetworkDevices[realdevs].ip = ni[i]["ip"] Settings.NetworkDevices[realdevs].mask = ni[i]["mask"] Settings.NetworkDevices[realdevs].devicename = ni[i][ "name"] Settings.NetworkDevices[realdevs].connected = (int( ni[i]["active"]) != 0) Settings.NetworkDevices[ realdevs].lastconnectiontest = time.time() Settings.NetworkDevices[realdevs].mac = ni[i]["mac"] # Settings.NetworkDevices[realdevs].broadcast = ni[i]["broadcast"] realdevs += 1 if os.path.exists(self.dhcpcd_file_name): self.dhcpcd_inuse = True if self.dhcpcd_inuse: try: for i in range(len(Settings.NetworkDevices)): Settings.NetworkDevices[i].dhcp = True with open(self.dhcpcd_file_name) as f: detectedcard = -1 for line in f: line = line.strip() if len(line) > 0 and line[0] == "#": line = "" elif line.lower().startswith("interface"): detectedcard = -1 for i in range(len(Settings.NetworkDevices)): if Settings.NetworkDevices[ i].devicename in line: detectedcard = i elif ("static ip_address" in line) and (detectedcard >= 0): Settings.NetworkDevices[detectedcard].dhcp = False l1 = line.split("=") if len(l1) > 1: l = l1[1].split("/") if len(l) > 0: Settings.NetworkDevices[ detectedcard].ip = l[0] Settings.NetworkDevices[ detectedcard].mask = cidr_to_netmask( l[1]) elif ("static routers" in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[detectedcard].gw == "": l = line.split("=") if len(l) > 0: Settings.NetworkDevices[ detectedcard].gw = l[1] elif ("static domain_name_servers" in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[detectedcard].dns == "": l = line.split("=") if len(l) > 0: Settings.NetworkDevices[ detectedcard].dns = l[1] except: pass else: dhclient = isdhclient() if dhclient: for i in range(len(Settings.NetworkDevices)): Settings.NetworkDevices[i].dhcp = True try: with open(self.interfaces_file_name) as f: detectedcard = -1 for line in f: line = line.strip() if len(line) > 0 and line[0] == "#": line = "" elif "iface " in line.lower(): detectedcard = -1 for i in range(len(Settings.NetworkDevices)): if Settings.NetworkDevices[ i].devicename in line: detectedcard = i if ("dhcp" in line) and (detectedcard >= 0): Settings.NetworkDevices[ detectedcard].dhcp = True if ("static" in line) and (detectedcard >= 0): Settings.NetworkDevices[ detectedcard].dhcp = False elif ("address " in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[detectedcard].ip == "": l = line.split(" ") if len(l) > 0: Settings.NetworkDevices[ detectedcard].ip = l[1] elif ("netmask " in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[ detectedcard].mask == "": l = line.split(" ") if len(l) > 0: Settings.NetworkDevices[ detectedcard].mask = l[1] elif ("gateway " in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[detectedcard].gw == "": l = line.split(" ") if len(l) > 0: Settings.NetworkDevices[ detectedcard].gw = l[1] elif ("dns-nameservers " in line.lower()) and (detectedcard >= 0): if Settings.NetworkDevices[detectedcard].dns == "": l = line.split(" ") if len(l) > 0: for d in range(len(l)): Settings.NetworkDevices[ detectedcard].dns += l[d] + " " elif ("wpa-conf " in line.lower()): l = line.split(" ") if len(l) > 0: self.wpaconfig = l[1] except: pass try: with open(self.resolvconf_file_name) as f: dnsservers = "" for line in f: line = line.strip().lower() if line.startswith("nameserver"): dl = line.split(" ") if len(dl) > 1: fdns = dl[1].strip() for dc in range(len(Settings.NetworkDevices)): if fdns not in Settings.NetworkDevices[dc].dns: Settings.NetworkDevices[ dc].dns += " " + fdns except: pass if self.wpaconfig == "": tv = "/etc/wpa_supplicant/wpa_supplicant.conf" if os.path.exists(tv): self.wpaconfig = tv if self.wpaconfig != "": try: netid = -1 with open(self.wpaconfig) as f: for line in f: line = line.strip() if "network=" in line.lower(): netid += 1 if line.lower().strip().startswith("ssid="): tstrs = line.split("=") tstr = tstrs[1].replace('"', "").replace("'", "") if netid == 0: self.WifiSSID = tstr elif netid == 1: self.WifiSSID2 = tstr if "psk=" in line.lower(): tstrs = line.split("=") tstr = tstrs[1].replace('"', "").replace("'", "") if netid == 0: self.WifiKey = tstr elif netid == 1: self.WifiKey2 = tstr except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) for dc in range(len(Settings.NetworkDevices)): Settings.NetworkDevices[dc].dns = Settings.NetworkDevices[ dc].dns.strip() if Settings.NetworkDevices[ dc].gw == "" and Settings.NetworkDevices[dc].ip != "": Settings.NetworkDevices[dc].gw = getgw( Settings.NetworkDevices[dc].devicename) Settings.NetworkDevices[ dc].connectiontype = 0 # reset iswireless value in case of device name change! Settings.NetworkDevices[dc].iswireless() if (OS.is_command_found('hostapd') == False or OS.is_command_found('dnsmasq') == False): self.APMode = -1 self.setAPconf(True)
def installdeps2(modulename): global modulelist Settings.UpdateString = "!Installing " + modulename + " dependencies" for i in range(len(modulelist)): if modulelist[i][ "name"] == modulename and modulelist[i]["installed"] != 1: modulelist[i]["installed"] = -1 try: if modulelist[i]["apt"]: installprog = " " for j in range(len(modulelist[i]["apt"])): if rpieGlobals.ossubtype == 2: # arch exceptions if "python3-pip" in modulelist[i]["apt"][j]: modulelist[i]["apt"][j].replace( "python3-pip", "python-pip") installprog += modulelist[i]["apt"][j] + " " if rpieGlobals.ossubtype in [1, 3, 10]: installprog = OS.cmdline_rootcorrect( "sudo apt-get update && sudo apt-get install -y " + installprog.strip()) elif rpieGlobals.ossubtype == 2: installprog = OS.cmdline_rootcorrect( "yes | sudo pacman -S " + installprog.strip()) ustr = "apt: " + installprog Settings.UpdateString = "!" + ustr misc.addLog(rpieGlobals.LOG_LEVEL_INFO, ustr) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull, "wb"), executable="/bin/bash") proc.wait() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) try: if modulelist[i]["pip"]: installprog = " " for j in range(len(modulelist[i]["pip"])): installprog += modulelist[i]["pip"][j] + " " installprog = "sudo -H pip3 install " + installprog.strip() if OS.is_command_found( "sudo" ) == False: # if sudo is installed use it because -H option is important installprog = OS.cmdline_rootcorrect( "sudo -H pip3 install " + installprog.strip()) ustr = "pip3: " + installprog Settings.UpdateString = "!" + ustr misc.addLog(rpieGlobals.LOG_LEVEL_INFO, ustr) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull, "wb"), executable="/bin/bash") proc.wait() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) try: if modulelist[i]["installcmd"]: installprog = OS.cmdline_rootcorrect( modulelist[i]["installcmd"].strip()) ustr = "exec: " + installprog Settings.UpdateString = "!" + ustr misc.addLog(rpieGlobals.LOG_LEVEL_INFO, ustr) proc = subprocess.Popen(installprog, shell=True, stdin=None, stdout=open(os.devnull, "wb"), executable="/bin/bash") proc.wait() except Exception as e: if e != 'installcmd': misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) break Settings.UpdateString = "=" + modulename + " dependency install finished<br>" #<a class='button link wide' href='plugins'>Back to dependencies</a><br>" return True