mynode/rootfs/standard/var/www/mynode/device_info.py

145 lines
4.5 KiB
Python
Raw Normal View History

2019-06-15 23:02:44 +00:00
from config import *
import os
import subprocess
2019-08-27 01:36:15 +00:00
# Globals
local_ip = "unknown"
2019-06-15 23:02:44 +00:00
# Functions
def get_current_version():
current_version = "0.0"
try:
with open("/usr/share/mynode/version", "r") as f:
current_version = f.read().strip()
except:
current_version = "error"
return current_version
def update_latest_version():
2019-06-30 16:50:05 +00:00
os.system("wget "+LATEST_VERSION_URL+" -O /usr/share/mynode/latest_version")
2019-06-15 23:02:44 +00:00
return True
def get_latest_version():
latest_version = "0.0"
try:
with open("/usr/share/mynode/latest_version", "r") as f:
latest_version = f.read().strip()
except:
latest_version = get_current_version()
return latest_version
2019-06-29 15:53:49 +00:00
def get_system_uptime():
uptime = subprocess.check_output('awk \'{print int($1/86400)" days "int($1%86400/3600)" hour(s) "int(($1%3600)/60)" minute(s) "int($1%60)" seconds(s)"}\' /proc/uptime', shell=True)
uptime = uptime.strip()
return uptime
2019-06-15 23:02:44 +00:00
def get_device_serial():
serial = subprocess.check_output("cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2", shell=True)
serial = serial.strip()
2019-10-08 03:11:54 +00:00
if serial == "":
# For VMs, use the UUID
serial = subprocess.check_output("sudo dmidecode | grep UUID | cut -d ' ' -f 2", shell=True)
serial = serial.strip()
2019-06-15 23:02:44 +00:00
return serial
2019-07-16 03:30:08 +00:00
def get_device_type():
return CONFIG["device_type"]
2019-07-25 02:51:12 +00:00
def is_uploader():
return os.path.isfile("/home/bitcoin/.mynode/uploader") or \
os.path.isfile("/mnt/hdd/mynode/settings/uploader")
def set_uploader():
os.system("touch /home/bitcoin/.mynode/uploader")
os.system("touch /mnt/hdd/mynode/settings/uploader")
def unset_uploader():
os.system("rm -rf /home/bitcoin/.mynode/uploader")
os.system("rm -rf /mnt/hdd/mynode/settings/uploader")
2019-07-25 02:51:12 +00:00
def is_quicksync_enabled():
2019-10-24 04:18:46 +00:00
return not os.path.isfile("/mnt/hdd/mynode/settings/quicksync_disabled")
def disable_quicksync():
os.system("touch /mnt/hdd/mynode/settings/quicksync_disabled")
def enable_quicksync():
os.system("rm -rf /mnt/hdd/mynode/settings/quicksync_disabled")
2019-06-15 23:02:44 +00:00
def set_skipped_product_key():
os.system("touch /home/bitcoin/.mynode/.product_key_skipped")
os.system("touch /mnt/hdd/mynode/settings/.product_key_skipped")
2019-06-15 23:02:44 +00:00
def unset_skipped_product_key():
os.system("rm -rf /home/bitcoin/.mynode/.product_key_skipped")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key_skipped")
2019-06-15 23:02:44 +00:00
def skipped_product_key():
return os.path.isfile("/home/bitcoin/.mynode/.product_key_skipped") or \
os.path.isfile("/mnt/hdd/mynode/settings/.product_key_skipped")
def is_community_edition():
return skipped_product_key()
2019-06-15 23:02:44 +00:00
def delete_product_key():
os.system("rm -rf /home/bitcoin/.mynode/.product_key")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key")
2019-06-15 23:02:44 +00:00
def has_product_key():
return os.path.isfile("/home/bitcoin/.mynode/.product_key")
def get_product_key():
product_key = "no_product_key"
if skipped_product_key():
return "community_edition"
if not has_product_key():
return "product_key_missing"
try:
with open("/home/bitcoin/.mynode/.product_key", "r") as f:
product_key = f.read().strip()
except:
product_key = "product_key_error"
return product_key
def is_valid_product_key():
return not os.path.isfile("/home/bitcoin/.mynode/.product_key_error")
def save_product_key(product_key):
pk = product_key.replace("-","")
os.system("echo '{}' > /home/bitcoin/.mynode/.product_key".format(pk))
os.system("echo '{}' > /mnt/hdd/mynode/settings/.product_key".format(pk))
2019-06-15 23:02:44 +00:00
def delete_product_key_error():
os.system("rm -rf /home/bitcoin/.mynode/.product_key_error")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key_error")
2019-08-27 01:36:15 +00:00
def get_local_ip():
global local_ip
if local_ip == "unknown" or local_ip == "error":
try:
result = subprocess.check_output('hostname -I', shell=True)
ips = result.split()
local_ip = ips[0]
except Exception as e:
local_ip = "error"
return local_ip
def get_device_changelog():
changelog = ""
try:
changelog = subprocess.check_output(["cat", "/usr/share/mynode/changelog"])
except:
changelog = "ERROR"
2019-10-20 03:20:03 +00:00
return changelog
def has_changed_password():
2019-10-26 16:32:06 +00:00
return os.path.isfile("/home/bitcoin/.mynode/.hashedpw")
def get_bitcoin_rpc_password():
try:
with open("/mnt/hdd/mynode/settings/.btcrpcpw", "r") as f:
return f.read()
except:
return "ERROR"
return "ERROR"