Files
jcm_test/server/jcm.py

176 lines
5.3 KiB
Python
Raw Normal View History

2023-08-22 04:30:01 +08:00
# coding=utf-8
#!/bin/python
import os
import sys
2024-04-19 16:15:23 +08:00
import imp
#import importlib
2023-08-22 04:30:01 +08:00
import locale
2023-11-26 20:20:29 +00:00
import platform
2023-08-22 04:30:01 +08:00
2024-04-19 16:15:23 +08:00
if platform.system() != "Windows":
try:
osuser = os.popen("id -un").read().split('\n')[0].split('\r')[0]
if osuser != "root":
print("No root user,exit!")
exit()
except Exception as e:
print(e.args)
2023-08-22 04:30:01 +08:00
iftext = {}
iftext["osname"] = "OS Name:"
iftext["devname"] = "Host Name:"
2023-11-26 20:20:29 +00:00
iftext["netdir"] = "Network Card(s):"
iftext["netname"] = "Connection Name:"
iftext["ip"] = "IP addrees(es)"
2023-08-22 04:30:01 +08:00
text = {}
text["init"] = "init"
text["user"] = "User:"
text["passwor"] = "Password:"
2023-11-26 20:20:29 +00:00
#加载语言文件
2023-08-22 04:30:01 +08:00
try:
language = locale.getdefaultlocale()
language = language[0]
#language = "zh_CN"
2023-11-26 20:20:29 +00:00
if os.path.exists("language/server/init.py/" + language + ".py"):
2024-04-19 16:15:23 +08:00
#run = importlib.machinery.SourceFileLoader('run',"language/server/init.py/" + language + ".py").load_module()
run = imp.load_source('run',"language/server/init.py/" + language + ".py")
2023-11-26 20:20:29 +00:00
for textname in iftext.keys():
try:
textval = run.text[textname]
iftext[textname] = textval
except Exception as e:
print(e.args)
except Exception as e:
print(e.args)
try:
language = locale.getdefaultlocale()
language = language[0]
#language = "zh_CN"
if os.path.exists("language/server/init.py/" + language + ".py"):
2024-04-19 16:15:23 +08:00
#run = importlib.machinery.SourceFileLoader('run',"language/server/init.py/" + language + ".py").load_module()
2023-11-26 20:20:29 +00:00
run = imp.load_source('run',"language/server/init.py/" + language + ".py")
for textname in text.keys():
try:
textval = run.text[textname]
text[textname] = textval
except Exception as e:
print(e.args)
2023-08-22 04:30:01 +08:00
except Exception as e:
print(e.args)
2024-04-05 18:53:46 +00:00
info = {}
info["Versino"] = ""
info["python"] = "python"
info["dir"] = "dir"
info["OS"] = "OS_"
info["OS_name"] = "OS"
info["port"] = "port"
info["dev_name"] = "dev_name"
info["theme"] = "Ace_Admin"
info["Headers"] = "Server: JCM/1.0\r\n"
info['debug'] = False
info['tmp'] = '/tmp/jcm'
2023-08-22 04:30:01 +08:00
2024-04-05 18:53:46 +00:00
#获取版本
def catVersino():
sh = "server/main/Package.py"
2024-04-19 16:15:23 +08:00
#sh = importlib.machinery.SourceFileLoader(sh, sh).load_module()
sh = imp.load_source(sh, sh)
2024-04-05 18:53:46 +00:00
info["Versino"] = sh.Version
info["Headers"] = "Server: JCM/" + sh.Version + "\r\n"
#获取端口
def catport():
info["port"] = 8888
if os.path.exists(".config/main/port"):
fs = open(".config/main/port", "rb")
ini = fs.read().decode("utf-8")
info["port"] = int(ini)
#获取Python地址
info["python"] = sys.executable
#获取目录
info["dir"] = os.getcwd()
#获取OS类型
info["OS"] = platform.system()
#获取OS名称
def catosname():
if info["OS"] == "Windows":
sh = os.popen("systeminfo")
shell = sh.read().split('\n')
for sh in range(len(shell)):
#print('[' + str(sh) + '] ' + shell[sh])
sh = shell[sh].split(' ')
if sh[0] == iftext["osname"]:
info["OS_name"] = sh[-1]
if sh[0] == iftext["devname"]:
info["dev_name"] = sh[-1]
2023-08-22 04:30:01 +08:00
else:
2024-04-05 18:53:46 +00:00
if os.path.exists('/etc/os-release'):
sh = os.popen("cat /etc/os-release | grep PRETTY_NAME")
shell = sh.read().split('"')
info["OS_name"] = shell[1]
else:
sh = os.popen("uname -n")
shell = sh.read()
info["OS_name"] = shell[:-1]
2023-11-26 20:20:29 +00:00
sh = os.popen('cat /etc/hostname')
2024-04-05 18:53:46 +00:00
info["dev_name"] = sh.read().split('\r')[0].split('\n')[0]
2023-11-26 20:20:29 +00:00
2024-04-05 18:53:46 +00:00
catVersino()
catport()
catosname()
2023-08-22 04:30:01 +08:00
2024-04-05 18:53:46 +00:00
if os.path.exists(".config/main/debug"):
info['debug'] = True
2023-08-22 04:30:01 +08:00
2024-04-05 18:53:46 +00:00
sh = os.popen(info["python"] + " -V")
2023-08-22 04:30:01 +08:00
shell = sh.read().split('\n')
if os.path.exists("info.sh"):
os.system("./info.sh '" + shell[0] + "'")
2024-04-05 18:53:46 +00:00
os.system("./info.sh '" + "JCM " + info["Versino"] + "'")
os.system("./info.sh '" + "name: " + info["dev_name"] + "'")
os.system("./info.sh '" + "python: " + info["python"] + "'")
os.system("./info.sh '" + "dir: " + info["dir"] + "'")
os.system("./info.sh '" + "OS: " + info["OS"] + "'")
os.system("./info.sh '" + "OS: " + info["OS_name"] + "'")
os.system("./info.sh '" + "port: " + str(info["port"]) + "'")
os.system("./info.sh '" + "theme: " + info["theme"] + "'")
else:
print(shell[0])
print("JCM " + info["Versino"])
print("name: " + info["dev_name"])
print("python: " + info["python"])
print("dir: " + info["dir"])
print("OS: " + info["OS"])
print("OS: " + info["OS_name"])
print("port: " + str(info["port"]))
print("theme: " + info["theme"])
2024-03-03 19:43:51 +00:00
try:
import psutil
print("Net: ")
net = psutil.net_if_addrs()
for i in net:
addrees = net[i]
addrees = addrees[0]
addrees = addrees.address
print('\t' + i + '\t' + addrees)
except Exception as e:
print(e.args)
2023-08-22 04:30:01 +08:00
if info['debug']:
if os.path.exists("info.sh"):
os.system("./info.sh '" + "DEBUG" + "'")
os.system("error.sh '" + "DEBUG" + "'")
2023-08-22 04:30:01 +08:00
print('Debug')
2024-04-19 16:15:23 +08:00
run = imp.load_source('run',"server/run.py")
#run = importlib.machinery.SourceFileLoader('run', "server/run.py").load_module()
2024-04-05 18:53:46 +00:00
#if install == "L":
# if OS_ == "Linux":
# os.system("systemctl start jcm.service")
# else:
# os.system("dist/boot/boot.exe start")
2023-08-22 04:30:01 +08:00
run.main(info)
print("end")