更新了大量API

This commit is contained in:
2024-03-03 19:43:51 +00:00
parent 1ead9d9198
commit 2fdee6c011
39 changed files with 1511 additions and 217 deletions

0
Tools/Tools.bat Normal file
View File

0
Tools/Tools.sh Normal file
View File

View File

@@ -17,7 +17,10 @@ import requests
import urllib3 import urllib3
urllib3.disable_warnings() urllib3.disable_warnings()
#os.chdir("install/jcm_install")
gitrul = "https://github.com/XiaoXianNv-boot/jcm/raw/master" gitrul = "https://github.com/XiaoXianNv-boot/jcm/raw/master"
githul = "https://github.com/XiaoXianNv-boot/jcm/releases/download"
mirrorrul = "https://jiang144.i234.me/data/jcm" mirrorrul = "https://jiang144.i234.me/data/jcm"
install_diri = b"C:\jcm" install_diri = b"C:\jcm"
@@ -48,6 +51,7 @@ if os.path.exists("language/Tools") == False:
os.mkdir("language/Tools") os.mkdir("language/Tools")
if os.path.exists("language/Tools/install.py") == False: if os.path.exists("language/Tools/install.py") == False:
os.mkdir("language/Tools/install.py") os.mkdir("language/Tools/install.py")
def pr(new_client_socket,data): def pr(new_client_socket,data):
print(data.decode("utf-8"),end='') print(data.decode("utf-8"),end='')
@@ -96,7 +100,7 @@ def down(rul,dir,d): #
acc = 0 acc = 0
sys.stdout.write("\r{}".format(dir.split('/')[-1]) + d + " : Extracting...{}".format(" "*50)) # Ugly but works everywhere sys.stdout.write("\r{}".format(dir.split('/')[-1]) + d + " : Extracting...{}".format(" "*50)) # Ugly but works everywhere
sys.stdout.flush() sys.stdout.flush()
import time import time
time.sleep(0.5) time.sleep(0.5)
@@ -132,6 +136,11 @@ def dl(rul,dir,d):
if os.path.exists(dir) == False: if os.path.exists(dir) == False:
down(mirrorrul + rul,dir,d) down(mirrorrul + rul,dir,d)
#print(os.args)
if os.path.exists("tmp") == False:
os.mkdir("tmp")
if os.path.exists("lib") == False:
os.mkdir("lib")
if OS_ == 'Windows': if OS_ == 'Windows':
rul = '' rul = ''
if os.path.exists("jcm_install") == False: if os.path.exists("jcm_install") == False:
@@ -148,6 +157,10 @@ if OS_ == 'Windows':
dl(rul + "/lib/7z/7z.dll","lib/7z/7z.dll","\t\t\t") dl(rul + "/lib/7z/7z.dll","lib/7z/7z.dll","\t\t\t")
if os.path.exists("lib/7z/7z.exe") == False: if os.path.exists("lib/7z/7z.exe") == False:
dl(rul + "/lib/7z/7z.exe","lib/7z/7z.exe","\t\t\t") dl(rul + "/lib/7z/7z.exe","lib/7z/7z.exe","\t\t\t")
#if os.path.exists("lib/instsrv.exe") == False:
# down(rul + "/lib/instsrv.exe","lib/instsrv.exe","\t\t\t")
#if os.path.exists("lib/srvany.exe") == False:
# down(rul + "/lib/srvany.exe","lib/srvany.exe","\t\t\t")
if os.path.exists("lib/bash.zip") == False: if os.path.exists("lib/bash.zip") == False:
dl(rul + "/lib/bash.zip","lib/bash.zip","\t\t") dl(rul + "/lib/bash.zip","lib/bash.zip","\t\t")
if os.path.exists("lib/CopyX.exe") == False: if os.path.exists("lib/CopyX.exe") == False:
@@ -349,7 +362,7 @@ if install_ != b'exit':
''' '''
fs = open(install_dir.decode("utf-8") + "\\run.bat","wb") fs = open(install_dir.decode("utf-8") + "\\run.bat","wb")
fs.write(b"@cd " + install_dir + b"\n") fs.write(b"@cd " + install_dir + b"\n")
fs.write(b"@Tools\\.python\\python server\\init.py") fs.write(b"@Tools\\.python\\python server\\jcm.py")
fs.close() fs.close()
fs = open(install_dir.decode("utf-8") + "\\boot.py","wb") fs = open(install_dir.decode("utf-8") + "\\boot.py","wb")
fs.write(b"\r\n\ fs.write(b"\r\n\
@@ -489,11 +502,13 @@ if __name__ == '__main__':\r\n\
else: else:
os.system("systemctl disable jcm.service") os.system("systemctl disable jcm.service")
#os.system("systemctl status jcm.service") #os.system("systemctl status jcm.service")
elif os.path.exists("/etc/rc.d"): elif os.path.exists("/etc/rc.d"):
if install_boot == b'yes': if install_boot == b'yes':
os.system("cp run.sh /etc/rc.d/S99jcm") os.system("cp run.sh /etc/rc.d/S99jcm")
if OS_ == 'Windows': if OS_ == 'Windows':
os.system("run.bat") os.system("run.bat")
else: else:

View File

@@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash
export gitdir=https://github.com/XiaoXianNv-boot/jcm/raw/master export gitdir=https://github.com/XiaoXianNv-boot/jcm/raw/master
export gitdir=https://github.com/XiaoXianNv-boot/jcm/releases/download/
export mirrordir=http://jiang144.i234.me/data/jcm export mirrordir=http://jiang144.i234.me/data/jcm
#export dir=https://github.com/XiaoXianNv-boot/jcm/releases/download/Preview
export dir=http://jiang144.i234.me/data/jcm
if [ ! -e /usr/bin/curl ]; then if [ ! -e /usr/bin/curl ]; then
if [ -e /bin/apt ]; then if [ -e /bin/apt ]; then
@@ -48,7 +51,6 @@ if [ ! -e /bin/python3 ]; then
fi fi
fi fi
mkdir -p jcm_install mkdir -p jcm_install
cd jcm_install cd jcm_install

54
Tools/install.test.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
export dir=http://openwrt.lan/data/jcm/
# wget http://openwrt.lan/data/jcm/Tools/install.test.sh -c && sh install.test.sh
if [ ! -e /bin/curl ]; then
if [ -e /bin/apt ]; then
apt update
apt install -y curl
else
if [ -e /bin/yum ]; then
yum install -y curl
else
if [ -e /bin/opkg ]; then
opkg update
opkg install -y curl
fi
fi
fi
fi
if [ ! -e /bin/python3 ]; then
if [ -e /bin/apt ]; then
apt update
apt install -y python3
else
if [ -e /bin/yum ]; then
yum install -y python3
else
if [ -e /bin/opkg ]; then
opkg update
opkg install python3
fi
fi
fi
fi
mkdir -p jcm_install
cd jcm_install
mkdir -p Tools
cd Tools
curl -#fL -o install.py -C - $dir/Tools/install.py
cd ..
mkdir -p lib
cd lib
mkdir -p pkg
cd pkg
curl -#fL -o APP_V0.2.pkg -C - $dir/pkg/APP_V0.2.pkg
curl -#fL -o main_V0.2.pkg -C - $dir/pkg/main_V0.2.pkg
cd ..
cd ..
python3 -m venv venv
source ./venv/bin/activate
python3 Tools/install.py %1 %2 %3 %4 %5

70
server/APP/Package.py.old Normal file
View File

@@ -0,0 +1,70 @@
# coding=utf-8
#!/bin/python
#cding=utf-8
# encoding=utf8
import os
import sys
name = "APP"
Version = "V0.2"
def install(new_client_socket,post,Versino,Headers,info,prin):
pkg=""
try:
fs = open("server/server.ini", "rb")
pkg = fs.read().decode("utf-8").split('\n')
except Exception as e:
prin(new_client_socket,(e.args).encode("utf-8"))
inpkg = "install"
for i in pkg:
if i.split('\r')[0] == name:
inpkg = ""
prin(new_client_socket,("install " + name + " " + Version + "\n\r").encode("utf-8"))
os.system("cp -rf .out/" + name + "_" + Version + ".pkg/.out/* ./")
if inpkg == "install":
os.system("echo " + name + ">>server/server.ini")
# prin(new_client_socket,("END\n\r").encode("utf-8"))
os.system("rm -rf .out/" + name + "_" + Version + ".pkg")
def remove():
os.system("rm -rf server/" + name)
os.system("rm -rf web/" + name)
def out():
#os.system("cp -rf web/" + name + " .out/web/")
os.system("cp -rf web/Ace_Admin/" + name + " .out/web/Ace_Admin/")
os.system("rm -rf .out/web/APP/info.json")
os.system("cp -rf server/" + name + " .out/server/")
rm('.out/server/','__pycache__')
# os.system("find .out/ -name __pycache__")
def rm(dir,name):
path = os.listdir(dir)
for p in path:
if os.path.isdir(dir + p):
if p == name:
os.system("rm -rf " + dir + name)
else:
rm(dir + p + '/',name)
def info():
print("Package:" + name)
print("name:应用商店")
print("Version:" + Version)
print("Depends:main")
print("License:GPL-2.0")
print("Description:软件的应用商店")
print("issued:pkg")
if __name__ == "__main__":
if len(sys.argv) == 1:
sys.argv = sys.argv[0],"install"
if sys.argv[1] == "install":
install('','','','','')
elif sys.argv[1] == "remove":
remove()
elif sys.argv[1] == "out":
out()
else:
info()

View File

@@ -9,10 +9,11 @@ import imp
import hashlib import hashlib
import socket import socket
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
post = RUL_CS
for i in post: for i in post:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
@@ -33,8 +34,8 @@ def main(new_client_socket,post,Headers,info,user):
yuan = os.listdir(".config/APP/data/") yuan = os.listdir(".config/APP/data/")
yuan.sort(reverse=True) yuan.sort(reverse=True)
for y in yuan: for y in yuan:
fs = open(".config/APP/data/" + y,'r') fs = open(".config/APP/data/" + y,'rb')
yrul = fs.read().split('\n')[1:-1] yrul = fs.read().decode("utf-8").split('\n')[1:-1]
for i in yrul: for i in yrul:
i = i.split(',') i = i.split(',')
name = i[0].split('"')[3] name = i[0].split('"')[3]

View File

@@ -52,8 +52,8 @@ def install(new_client_socket,post,Versino,Headers,info):
yuan = os.listdir(".config/APP/data/") yuan = os.listdir(".config/APP/data/")
yuan.sort(reverse=True) yuan.sort(reverse=True)
for y in yuan: for y in yuan:
fs = open(".config/APP/data/" + y,'r') fs = open(".config/APP/data/" + y,'rb')
yrul = fs.read().split('\n')[1:-1] yrul = fs.read().decode("utf-8").split('\n')[1:-1]
for i in yrul: for i in yrul:
i = i.split(',') i = i.split(',')
name = i[0].split('"')[3] name = i[0].split('"')[3]
@@ -443,8 +443,8 @@ def update(new_client_socket,post,Versino,Headers,info):
if os.path.isdir(".config/APP/pkg/" + y): if os.path.isdir(".config/APP/pkg/" + y):
for i in range(len(os.listdir(".config/APP/pkg/" + y))): for i in range(len(os.listdir(".config/APP/pkg/" + y))):
if os.path.exists(".config/APP/pkg/" + y + '/' + str(i)): if os.path.exists(".config/APP/pkg/" + y + '/' + str(i)):
fs = open(".config/APP/pkg/" + y + '/' + str(i),'r') fs = open(".config/APP/pkg/" + y + '/' + str(i),'rb')
yrul = fs.read().split('\n') yrul = fs.read().decode("utf-8").split('\n')
for yyrul in yrul: for yyrul in yrul:
if yyrul != '': if yyrul != '':
prin(new_client_socket,(y + '[' + str(i)+ ']\t').encode("utf-8")) prin(new_client_socket,(y + '[' + str(i)+ ']\t').encode("utf-8"))
@@ -493,8 +493,8 @@ def update(new_client_socket,post,Versino,Headers,info):
fs.close() fs.close()
break break
else: else:
fs = open(".config/APP/pkg/" + y,'r') fs = open(".config/APP/pkg/" + y,'rb')
yrul = fs.read().split('\n') yrul = fs.read().decode("utf-8").split('\n')
for yyrul in yrul: for yyrul in yrul:
if yyrul != '': if yyrul != '':
prin(new_client_socket,(y + '\t').encode("utf-8")) prin(new_client_socket,(y + '\t').encode("utf-8"))

View File

@@ -4,8 +4,9 @@
import imp import imp
import traceback import traceback
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
Versino = "V1.0" Versino = "V1.0"
post = RUL_CS
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py") httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
httpserver.websockinit(new_client_socket,Headers,info) httpserver.websockinit(new_client_socket,Headers,info)
data = httpserver.websockrx(new_client_socket) data = httpserver.websockrx(new_client_socket)

View File

@@ -84,7 +84,7 @@ def remove():
def out(): def out():
os.system("cp -rf web/Ace_Admin/" + name + " .out/web/Ace_Admin/") os.system("cp -rf web/Ace_Admin/" + name + " .out/web/Ace_Admin/")
os.system("cp -rf server/" + name + " .out/server/") os.system("cp -rf server/" + name + " .out/server/")
os.system("#cp -rf lib/frp .out/server/frpc/lib") os.system("cp -rf lib/frp .out/server/frpc/lib")
rm('.out/server/','__pycache__') rm('.out/server/','__pycache__')
@@ -99,17 +99,25 @@ def rm(dir,name):
rm(dir + p + '/',name) rm(dir + p + '/',name)
def info(): def info():
data = {} data = {}
#文件夹名称
data["Package"] = name data["Package"] = name
#首选名称
data["names"] = "frpc" data["names"] = "frpc"
#多国语言翻译
data["namei"] = {} data["namei"] = {}
data["namei"]["zh-CN"] = "frpc".encode("utf-8") data["namei"]["zh-CN"] = "frpc".encode("utf-8")
#版本
data["Version"] = Version data["Version"] = Version
#依赖
data["Depends"] = "main" data["Depends"] = "main"
#License
data["License"] = "GPL-2.0" data["License"] = "GPL-2.0"
#首选解释
data["Description"] = "frp内网穿透客户端" data["Description"] = "frp内网穿透客户端"
#多国语言翻译
data["Descriptions"] = {} data["Descriptions"] = {}
data["Descriptions"]["zh-CN"] = "frp内网穿透客户端".encode("utf-8") data["Descriptions"]["zh-CN"] = "frp内网穿透客户端".encode("utf-8")
#库名称
data["issued"] = "pkg" data["issued"] = "pkg"
return data return data

View File

@@ -30,9 +30,10 @@ def setinfo(conf,section,option,value):
conf.set(section, option, value) conf.set(section, option, value)
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
type = "" type = ""
res = "" res = ""
post = RUL_CS
for i in post: for i in post:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'type': if tmp[0] == 'type':

View File

@@ -7,6 +7,29 @@ import sys
import time import time
import psutil import psutil
import imp import imp
import time
import locale
iftext = {}
iftext["Charging"] = "Charging"
iftext["Discharging"] = "Discharging"
iftext["Full"] = "Full"
#加载语言文件
try:
language = locale.getdefaultlocale()
language = language[0]
#language = "zh_CN"
if os.path.exists("language/server/info/info/" + language + ".py"):
run = imp.load_source('run',"language/server/info/info/" + language + ".py")
for textname in iftext.keys():
try:
textval = run.iftext[textname]
iftext[textname] = textval
except Exception as e:
print(e.args)
except Exception as e:
print(e.args)
def rom(info): def rom(info):
OS = info['OS'] OS = info['OS']
@@ -15,7 +38,7 @@ def rom(info):
rom=0 rom=0
romname = "" romname = ""
disks=1 disks=1
if OS == "Linux": '''if OS == "Linux":
romsh = os.popen("LANG=en_US df -h") romsh = os.popen("LANG=en_US df -h")
list = romsh.read().split("\n") list = romsh.read().split("\n")
ilen = len(list) ilen = len(list)
@@ -45,18 +68,21 @@ def rom(info):
romname = list[i].split(" ")[0] romname = list[i].split(" ")[0]
i=i+1 i=i+1
disks += 1 disks += 1
else: else:'''
list = psutil.disk_partitions() if True:
list = psutil.disk_partitions(False)
ilen = len(list) ilen = len(list)
while i < ilen: while i < ilen:
if list[i].mountpoint == "/boot": if list[i].mountpoint == "/boot":
i += 1 i += 1
elif list[i].device == "/dev/zram1":
i += 1
else: else:
try: try:
diskinfo = psutil.disk_usage(list[i].mountpoint) diskinfo = psutil.disk_usage(list[i].mountpoint)
if rom < diskinfo.percent: if rom < diskinfo.percent:
rom = diskinfo.percent rom = diskinfo.percent
romname = list[i].mountpoint romname = list[i].device
except Exception as e: except Exception as e:
if(len(e.args) == 2): if(len(e.args) == 2):
if e.args[1] != '设备未就绪。': if e.args[1] != '设备未就绪。':
@@ -97,6 +123,8 @@ def catdisk(OS):
ii += 1 ii += 1
fo = ii fo = ii
res = res + (('"diskfo":"' + str(fo) + '","disk":[\r\n').encode("utf-8")) res = res + (('"diskfo":"' + str(fo) + '","disk":[\r\n').encode("utf-8"))
fo = len(diskfo)
iii = 0
for i in range(fo): for i in range(fo):
device = diskfo[i].mountpoint device = diskfo[i].mountpoint
if diskfo[i].device[:len("/dev/loop")] != "/dev/loop": if diskfo[i].device[:len("/dev/loop")] != "/dev/loop":
@@ -134,10 +162,11 @@ def catdisk(OS):
diskinfo = " " + diskfo[i].fstype + ' ' + rams + ' / ' + ramall diskinfo = " " + diskfo[i].fstype + ' ' + rams + ' / ' + ramall
else: else:
name = diskfo[i].device name = diskfo[i].device
if i == (fo - 1): if iii == (ii - 1):
res = res + (('{"name":"' + name + '","minidiskinfo":"' + rams + ' / ' + ramall + '","diskinfo":"' + diskinfo + '","disk":"' + str(ram.percent)[:-2] + '"}\r\n').encode("utf-8")) res = res + (('{"name":"' + name + '","minidiskinfo":"' + rams + ' / ' + ramall + '","diskinfo":"' + diskinfo + '","disk":"' + str(ram.percent)[:-2] + '"}\r\n').encode("utf-8"))
else: else:
res = res + (('{"name":"' + name + '","minidiskinfo":"' + rams + ' / ' + ramall + '","diskinfo":"' + diskinfo + '","disk":"' + str(ram.percent)[:-2] + '"},\r\n').encode("utf-8")) res = res + (('{"name":"' + name + '","minidiskinfo":"' + rams + ' / ' + ramall + '","diskinfo":"' + diskinfo + '","disk":"' + str(ram.percent)[:-2] + '"},\r\n').encode("utf-8"))
iii = iii + 1
fo = os.popen('ls /sys/kernel/debug/mmc*/mmc*/ext_csd 2>/dev/null').read() fo = os.popen('ls /sys/kernel/debug/mmc*/mmc*/ext_csd 2>/dev/null').read()
#fo = os.popen('ls .tmp/mmc*/mmc*/ext_csd 2>/dev/null').read().split('\n') #fo = os.popen('ls .tmp/mmc*/mmc*/ext_csd 2>/dev/null').read().split('\n')
res = res + (('],\r\n').encode("utf-8")) res = res + (('],\r\n').encode("utf-8"))
@@ -194,7 +223,7 @@ def catcpu(OS):
res = b'' res = b''
fo = psutil.cpu_count() fo = psutil.cpu_count()
if OS == "Windows": if OS == "Windows":
shell = os.popen(bin + "wmic cpu get Name") shell = os.popen("wmic cpu get Name")
bash = shell.read().split('\n') bash = shell.read().split('\n')
cpuname = bash[2]#.split(')')[-1][1:] cpuname = bash[2]#.split(')')[-1][1:]
@@ -227,10 +256,36 @@ def catcpu(OS):
bash = shell.read().split('\n') bash = shell.read().split('\n')
if len(bash) == 2: if len(bash) == 2:
cputemp = bash[0][:-3] cputemp = bash[0][:-3]
elif OS == "Windows":
import clr
clr.AddReference(os.getcwd() + '/Tools/openhardwaremonitor/OpenHardwareMonitor/OpenHardwareMonitorLib.dll') # 填写绝对路径
import OpenHardwareMonitor as ohm
from OpenHardwareMonitor.Hardware import Computer, HardwareType, SensorType
computer = Computer()
computer.CPUEnabled = True
computer.MainboardEnabled = True
computer.FanControllerEnabled = True
hardwareType = ohm.Hardware.HardwareType
sensorType = ohm.Hardware.SensorType
computer.Open()
computer.Open()
for hardware in computer.Hardware:
hardware.Update()
for sensor in hardware.Sensors:
rr = str(sensor.Identifier)
print(rr)
print(sensor.get_Value())
if "/temperature" in str(sensor.Identifier):
cputemp = str(sensor.get_Value())
print(sensor.get_Value())
res = res + (('"cputemp":"' + cputemp + '","cpufo":"' + str(fo) + '","cpu":[\r\n').encode("utf-8")) res = res + (('"cputemp":"' + cputemp + '","cpufo":"' + str(fo) + '","cpu":[\r\n').encode("utf-8"))
#if len(cpuname) > 20: #if len(cpuname) > 20:
# cpunam = cpuname.split('CPU') # cpunam = cpuname.split('CPU')
# cpuname = cpunam[-1][1:] # cpuname = cpunam[-1][1:]
time.sleep(0.1)
freq = psutil.cpu_freq(percpu=True) freq = psutil.cpu_freq(percpu=True)
cpu = psutil.cpu_percent(percpu=True) cpu = psutil.cpu_percent(percpu=True)
if len(freq) != len(cpu): if len(freq) != len(cpu):
@@ -305,7 +360,7 @@ def catram():
res = res + (('{"name":"交换空间","raminfo":"' + rams + ' / ' + ramall + '","ram":"' + str(ram.percent) + '"}\r\n').encode("utf-8")) res = res + (('{"name":"交换空间","raminfo":"' + rams + ' / ' + ramall + '","ram":"' + str(ram.percent) + '"}\r\n').encode("utf-8"))
return res return res
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
OS = info['OS'] OS = info['OS']
bin = '' bin = ''
@@ -318,14 +373,27 @@ def main(new_client_socket,post,Headers,info,user):
res = res + (('"rommain": "'+rr+'",\r\n').encode("utf-8")) res = res + (('"rommain": "'+rr+'",\r\n').encode("utf-8"))
res = res + (('"romnamemain": "'+rrr+'",\r\n').encode("utf-8")) res = res + (('"romnamemain": "'+rrr+'",\r\n').encode("utf-8"))
bat = '0' bat = '0'
cat = "0"
try:
bat = str(psutil.sensors_battery().percent)
except Exception as e:
bat = '0'
if os.path.exists("/sys/class/power_supply"): if os.path.exists("/sys/class/power_supply"):
dirn = os.listdir("/sys/class/power_supply/") dirn = os.listdir("/sys/class/power_supply/")
for d in dirn: for d in dirn:
if os.path.exists("/sys/class/power_supply/" + d + "/type"): if os.path.exists("/sys/class/power_supply/" + d + "/type"):
if os.path.exists("/sys/class/power_supply/" + d + "/capacity"): if os.path.exists("/sys/class/power_supply/" + d + "/capacity"):
cat = os.popen("cat /sys/class/power_supply/" + d + "/type").read().split('\n')[0] if os.path.exists("/sys/class/power_supply/" + d + "/status"):
cat = os.popen("cat /sys/class/power_supply/" + d + "/status").read().split('\n')[0]
bat = os.popen("cat /sys/class/power_supply/" + d + "/capacity").read().split('\n')[0] bat = os.popen("cat /sys/class/power_supply/" + d + "/capacity").read().split('\n')[0]
res = res + (('"bat": "'+bat+'",\r\n').encode("utf-8")) res = res + (('"bat": "'+bat+'",\r\n').encode("utf-8"))
try:
cat = iftext[cat]
except Exception as e:
bat = bat
if cat == "0":
cat = bat
res = res + (('"cat": "'+cat+'",\r\n').encode("utf-8"))
# break # break
res = res + catcpu(OS) res = res + catcpu(OS)

View File

@@ -89,7 +89,7 @@ def dpkginstall(name):
pkg = '' pkg = ''
if os.path.exists("/bin/apt"): if os.path.exists("/bin/apt"):
if name == "update": if name == "update":
os.system("apt update") os.system("#apt update")
pkg = "apt install -y " pkg = "apt install -y "
elif os.path.exists("/bin/yum"): elif os.path.exists("/bin/yum"):
pkg = "yum install -y " pkg = "yum install -y "
@@ -103,7 +103,7 @@ def dpkginstall(name):
elif name == "update": elif name == "update":
print() print()
elif name == (python.split('/')[-1] + "-dev"): elif name == (python.split('/')[-1] + "-dev"):
if pkg == "yum": if pkg == "yum install -y ":
os.system(pkg + " " + python.split('/')[-1] + "-devel") os.system(pkg + " " + python.split('/')[-1] + "-devel")
else: else:
os.system(pkg + " " + name) os.system(pkg + " " + name)
@@ -121,6 +121,8 @@ def pip(name):
print('pip ' + name) print('pip ' + name)
while run == 1: while run == 1:
run = pipinstall(name," ") run = pipinstall(name," ")
if run == 1:
run = pipinstall(name," --break-system-packages ")
if run == 1: if run == 1:
run = pipinstall(name,"https://pypi.tuna.tsinghua.edu.cn/simple") run = pipinstall(name,"https://pypi.tuna.tsinghua.edu.cn/simple")
if run == 1: if run == 1:
@@ -133,16 +135,16 @@ def pip(name):
def pipinstall(name,link): def pipinstall(name,link):
sh = os.popen("" + python + " -m pip list | " + bash + "grep '" + name + "'") sh = os.popen("" + python + " -m pip list | " + bash + "grep '" + name + "'")
shell = sh.read().split(' ') shell = sh.read().split("\n")[0].split(' ')
if shell[0] != name: if shell[0] != name:
if link[0] == 'h': if link[0] == 'h':
link = ' -i ' + link link = ' -i ' + link
os.system(bin + "" + python + " -m pip install --break-system-packages " + name + link) os.system(bin + "" + python + " -m pip install " + name + link)
sh = os.popen("" + python + " -m pip list | " + bash + "grep '" + name + "'") sh = os.popen("" + python + " -m pip list | " + bash + "grep '" + name + "'")
shell = sh.read().split(' ') shell = sh.read().split("\n")[0].split(' ')
if shell[0] == name: if shell[0] == name:
pr = '' pr = ''
for p in shell[:-1]: for p in shell:
pr = pr + p pr = pr + p
if pr == name: if pr == name:
pr = pr + ' ' pr = pr + ' '
@@ -152,7 +154,7 @@ def pipinstall(name,link):
return 0 return 0
else: else:
pr = '' pr = ''
for p in shell[:-1]: for p in shell:
pr = pr + p pr = pr + p
if pr == name: if pr == name:
pr = pr + ' ' pr = pr + ' '
@@ -238,23 +240,23 @@ if os.path.exists(".config/main/user") == False:
os.mkdir(".config/main") os.mkdir(".config/main")
print(text["init"]) print(text["init"])
user = '' user = ''
if os.path.exists("/usr/bin/bashio"): if len(sys.argv) == 5:
user = os.popen("bashio api.sh config user").read().split("\n")[0] if sys.argv[1] == "hass":
print(text["user"] + user) print(sys.argv)
user = user.encode("utf-8") user = sys.argv[3].encode("utf-8")
else: else:
user = input(text["user"]).encode("utf-8") user = input(text["user"]).encode("utf-8")
password = '' password = ''
if os.path.exists("/usr/bin/bashio"): if len(sys.argv) == 5:
password = os.popen("bashio api.sh config password").read().split("\n")[0] if sys.argv[1] == "hass":
print(text["passwor"] + password) print(sys.argv)
password = password.encode("utf-8") password = sys.argv[4].encode("utf-8")
else: else:
password = input(text["passwor"]).encode("utf-8") password = input(text["passwor"]).encode("utf-8")
tools = imp.load_source('tools',"Tools/Tools.py") tools = imp.load_source('tools',"Tools/Tools.py")
tools.newuser(user,password,b"0") tools.newuser(user,password,b"0")
if OS_ == "Linux": #if OS_ == "Linux":
install = "L" install = "L"
if os.path.exists(".config/main/port"): if os.path.exists(".config/main/port"):
fs = open(".config/main/port", "rb") fs = open(".config/main/port", "rb")
@@ -272,6 +274,8 @@ OSS = OS.split(' ')
if OS_ == "Windows": if OS_ == "Windows":
pip("psutil") pip("psutil")
pip("pywin32") pip("pywin32")
pip("requests")
pip("pythonnet")
elif OS == "DSM": elif OS == "DSM":
if os.path.exists("server/psutil.py") == False: if os.path.exists("server/psutil.py") == False:
os.system('cp lib/psutil.py ./server/') os.system('cp lib/psutil.py ./server/')
@@ -284,11 +288,12 @@ elif OS_ == "Linux":
t = 1 t = 1
if t == 0: if t == 0:
dpkginstall("update") dpkginstall("update")
dpkginstall(python.split('/')[-1] + "-pip ") dpkginstall("python3" + "-pip ")
dpkginstall(python.split('/')[-1] + "-dev") dpkginstall("python3" + "-dev")
dpkginstall("gcc") dpkginstall("gcc")
dpkginstall("curl") dpkginstall("curl")
pip("psutil") pip("psutil")
pip("requests")
OS_ = os.popen('if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then echo "chroot"; else echo "Linux"; fi').read().split('\r')[0].split('\n')[0] OS_ = os.popen('if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then echo "chroot"; else echo "Linux"; fi').read().split('\r')[0].split('\n')[0]
@@ -316,8 +321,17 @@ print("OS: " + OS)
print("OS: " + OS_) print("OS: " + OS_)
print("port: " + str(port)) print("port: " + str(port))
print("theme: " + theme) print("theme: " + theme)
for iipp in ipaddr.split('\r'): try:
print(iipp) 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)
info = {} info = {}
info["Versino"] = Versino info["Versino"] = Versino
@@ -329,7 +343,6 @@ info["port"] = port
info["dev_name"] = dev_name info["dev_name"] = dev_name
info["theme"] = theme info["theme"] = theme
info["Headers"] = "Server: JCM/1.0\r\n" info["Headers"] = "Server: JCM/1.0\r\n"
info["ip"] = iipp
info['debug'] = False info['debug'] = False
info['tmp'] = '/tmp/jcm' info['tmp'] = '/tmp/jcm'
@@ -347,6 +360,9 @@ if info['debug']:
run = imp.load_source('run',"server/run.py") run = imp.load_source('run',"server/run.py")
if install == "L": if install == "L":
if OS_ == "Linux":
os.system("systemctl start jcm.service") os.system("systemctl start jcm.service")
else:
os.system("dist/boot/boot.exe start")
run.main(info) run.main(info)
print("end") print("end")

View File

@@ -7,7 +7,58 @@ import os
import sys import sys
name = "main" name = "main"
Version = "V0.2" Version = "V0.3"
rul = "https://jiang144.i234.me/data/jcm"
def progress_bar( nb_traits,name,d,prin,new_client_socket):
prin(new_client_socket,('\r' + name + d + ' : Downloading [').encode("utf-8"))
for i in range(0, nb_traits):
if i == nb_traits - 1:
prin(new_client_socket,'>'.encode("utf-8"))
else:
prin(new_client_socket,'='.encode("utf-8"))
for i in range(0, 49 - nb_traits):
prin(new_client_socket,' '.encode("utf-8"))
prin(new_client_socket,']'.encode("utf-8"))
def down(rul,dir,d,prin,new_client_socket):
import requests
prin(new_client_socket,(dir.split('/')[-1] + d + ' : Downloading...').encode("utf-8"))
bresp = requests.get(rul, stream=True, verify=False)
if (bresp.status_code != 200): # When the layer is located at a custom URL
if(bresp.status_code == 404):
prin(new_client_socket,('\rERROR: Cannot download layer {} [HTTP {}]'.format(dir.split('/')[-1], bresp.status_code, "")).encode("utf-8"))
prin(new_client_socket,(str(bresp.content)).encode("utf-8"))
return
bresp = requests.get(layer['urls'][0], headers=auth_head, stream=True, verify=False)
if (bresp.status_code != 200):
prin(new_client_socket,('\rERROR: Cannot download layer {} [HTTP {}]'.format(dir.split('/')[-1], bresp.status_code, bresp.headers['Content-Length'])).encode("utf-8"))
prin(new_client_socket,(str(bresp.content)).encode("utf-8"))
return
#exit(1)
# Stream download and follow the progress
bresp.raise_for_status()
unit = int(bresp.headers['Content-Length']) / 50
acc = 0
nb_traits = 0
progress_bar( nb_traits,dir.split('/')[-1],d,prin,new_client_socket)
with open(".out/" + name + "_V0.2.pkg/" + dir.split("/")[-1], "wb") as file:
for chunk in bresp.iter_content(chunk_size=8192):
if chunk:
file.write(chunk)
acc = acc + 8192
if acc > unit:
nb_traits = nb_traits + 1
progress_bar( nb_traits,dir.split('/')[-1],d,prin,new_client_socket)
acc = 0
prin(new_client_socket,("\r{}".format(dir.split('/')[-1]) + d + " : Extracting...{}".format(" "*50)).encode("utf-8")) # Ugly but works everywhere
os.rename(".out/" + name + "_V0.2.pkg/" + dir.split("/")[-1],dir)
prin(new_client_socket,("\r{}".format(dir.split('/')[-1]) + d + " : Pull complete [{}]".format(bresp.headers['Content-Length'])).encode("utf-8"))
def install(new_client_socket,post,Versino,Headers,info,prin): def install(new_client_socket,post,Versino,Headers,info,prin):
import imp import imp
@@ -21,6 +72,14 @@ def install(new_client_socket,post,Versino,Headers,info,prin):
for i in pkg: for i in pkg:
if i.split('\r')[0] == name: if i.split('\r')[0] == name:
inpkg = "" inpkg = ""
if os.path.exists("Tools/.python") == True:
if os.path.exists("lib/openhardwaremonitor-v0.9.6.zip") == False:
#sh = os.popen("Tools\\.python\\python.exe -m pip install requests").read()
#prin(new_client_socket,(sh.encode("utf-8")))
down(rul + "/lib/openhardwaremonitor-v0.9.6.zip","lib/openhardwaremonitor-v0.9.6.zip","\t",prin,new_client_socket)
prin(new_client_socket,("\n\r").encode("utf-8"))
if os.path.exists("Tools/openhardwaremonitor") == False:
os.system("Tools\\7z\\7z.exe x lib\\openhardwaremonitor-v0.9.6.zip -r -oTools\\openhardwaremonitor -aoa")
prin(new_client_socket,("install " + name + " V0.2\n\r").encode("utf-8")) prin(new_client_socket,("install " + name + " V0.2\n\r").encode("utf-8"))
os.system("cp -rf .out/" + name + "_V0.2.pkg/.out/* ./") os.system("cp -rf .out/" + name + "_V0.2.pkg/.out/* ./")
@@ -38,6 +97,12 @@ def install(new_client_socket,post,Versino,Headers,info,prin):
inpkg = "" inpkg = ""
if inpkg == "install": if inpkg == "install":
os.system("echo " + 'setup' + ">>server/server.ini") os.system("echo " + 'setup' + ">>server/server.ini")
inpkg = "install"
for i in pkg:
if i.split('\r')[0] == 'APP':
inpkg = ""
if inpkg == "install":
os.system("echo " + 'APP' + ">>server/server.ini")
prin(new_client_socket,("重启服务\n\r").encode("utf-8")) prin(new_client_socket,("重启服务\n\r").encode("utf-8"))
if new_client_socket != "": if new_client_socket != "":
#os.system("sh run.sh &") #os.system("sh run.sh &")
@@ -55,6 +120,7 @@ def out():
os.system("cp -rf server/" + name + " .out/server/") os.system("cp -rf server/" + name + " .out/server/")
os.system("cp -rf web/Ace_Admin/" + 'info' + " .out/web/Ace_Admin/") os.system("cp -rf web/Ace_Admin/" + 'info' + " .out/web/Ace_Admin/")
os.system("cp -rf server/" + 'info' + " .out/server/") os.system("cp -rf server/" + 'info' + " .out/server/")
os.system("cp -rf language/server/" + 'info' + " .out/language/server/")
os.system("cp -rf web/Ace_Admin/" + 'setup' + " .out/web/Ace_Admin/") os.system("cp -rf web/Ace_Admin/" + 'setup' + " .out/web/Ace_Admin/")
os.system("cp -rf server/" + 'setup' + " .out/server/") os.system("cp -rf server/" + 'setup' + " .out/server/")
#os.system("cp -rf web/" + "info" + " .out/web/") #os.system("cp -rf web/" + "info" + " .out/web/")
@@ -74,6 +140,10 @@ def out():
os.system("cp -rf Tools/install.bat .out/Tools/") os.system("cp -rf Tools/install.bat .out/Tools/")
os.system("cp -rf Tools/install.sh .out/Tools/") os.system("cp -rf Tools/install.sh .out/Tools/")
os.system("cp -rf Tools/install.py .out/Tools/") os.system("cp -rf Tools/install.py .out/Tools/")
os.system("cp -rf web/Ace_Admin/" + "APP" + " .out/web/Ace_Admin/")
os.system("rm -rf .out/web/APP/info.json")
os.system("cp -rf server/" + "APP" + " .out/server/")
rm('.out/server/','__pycache__') rm('.out/server/','__pycache__')

View File

@@ -9,6 +9,16 @@ import hashlib
import binascii import binascii
import socket import socket
# 加密
def enctry(k,s):
#k = 'djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd'
encry_str = ""
for i,j in zip(s,k):
# i为字符j为秘钥字符
temp = str(ord(i)+ord(j))+'_' # 加密字符 = 字符的Unicode码 + 秘钥的Unicode码
encry_str = encry_str + temp
return encry_str
def Client(ip,dk,dir,post): def Client(ip,dk,dir,post):
try: try:
if dk == "": if dk == "":
@@ -58,7 +68,9 @@ def Client(ip,dk,dir,post):
hhhh = hhh[1].split(b';') hhhh = hhh[1].split(b';')
fs = open(".config/main/cookie","ab") fs = open(".config/main/cookie","ab")
fs.write(ip.encode('utf-8')) fs.write(ip.encode('utf-8'))
fs.write(b':') fs.write(b'\t')
fs.write(str(dk).encode('utf-8'))
fs.write(b'\t')
fs.write(hhhh[0]) fs.write(hhhh[0])
fs.write(b'\n') fs.write(b'\n')
fs.close() fs.close()
@@ -74,13 +86,14 @@ def Client(ip,dk,dir,post):
return "404",e.args[-1].encode("utf-8") return "404",e.args[-1].encode("utf-8")
socket.setdefaulttimeout(0) socket.setdefaulttimeout(0)
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
res = '' res = ''
devname = '' devname = ''
devrul = '' devrul = ''
devuser = '' devuser = ''
devpassword = '' devpassword = ''
devport = '' devport = ''
post = post_data.decode("utf-8").split("&")
for i in post: for i in post:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'devname': if tmp[0] == 'devname':
@@ -97,23 +110,44 @@ def main(new_client_socket,post,Headers,info,user):
obj = hashlib.md5() obj = hashlib.md5()
md = devuser md = devuser
md += time.strftime("I %Y-%m-%d %H:%M ", time.localtime()) md += time.strftime(" %Y-%m-%d %H:%M ", time.localtime())
obj.update((md).encode('utf-8')) obj.update((md).encode('utf-8'))
a = obj.hexdigest() a = obj.hexdigest()
a = enctry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",enctry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),devuser))
if info['debug']: if info['debug']:
print(md) print(md)
print(a) print(a)
obj = hashlib.md5() obj = hashlib.md5()
md = binascii.hexlify(hashlib.pbkdf2_hmac("sha256",devpassword.encode("utf-8"),b"jcm",1000)).decode() md = binascii.hexlify(hashlib.pbkdf2_hmac("sha256",devpassword.encode("utf-8"),b"jcm",1000)).decode()
md += time.strftime("I %Y-%m-%d %H:%M ", time.localtime()) md += time.strftime(" %Y-%m-%d %H:%M ", time.localtime())
obj.update((md).encode('utf-8')) obj.update((md).encode('utf-8'))
b = obj.hexdigest() b = obj.hexdigest()
b = enctry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",enctry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),devpassword))
if info['debug']: if info['debug']:
print(md) print(md)
print(b) print(b)
cat,cdata = Client(devrul,int(devport),'/login/dev','a=' + a + '&b=' + b) c = enctry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",enctry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),devname))
cat,cdata = Client(devrul,int(devport),'/login/dev','a=' + a + '&b=' + b + '&c=' + c)
if cat == '200': if cat == '200':
cdata = cdata.decode('utf-8') cdata = cdata.decode('utf-8')
if cdata == '{"data":"login"}':
cdata = '{"name": "'
cdata += devname
cdata += '","host": "'
cdata += devrul
cdata += '","user": "'
cdata += devuser
cdata += '","password": "'
cdata += enctry(devname,devpassword)
cdata += '","port": "'
cdata += devport
cdata += '"},\n'
fs = open(".config/main/lits.json","ab")
fs.write(cdata.encode("utf-8"))
fs.close()
res += "{\"data\":\"添加成功\"}"
elif cat == '401':
res += "{\"data\":\"用户名或密码错误\"}"
elif cat == '404': elif cat == '404':
data = os.popen('ping ' + devrul + ' -c 1 | grep icmp_seq').read() data = os.popen('ping ' + devrul + ' -c 1 | grep icmp_seq').read()
if len(data.split('icmp_seq=1 ttl=64')) == 2: if len(data.split('icmp_seq=1 ttl=64')) == 2:
@@ -124,7 +158,7 @@ def main(new_client_socket,post,Headers,info,user):
cdata += '","user": "' cdata += '","user": "'
cdata += devuser cdata += devuser
cdata += '","password": "' cdata += '","password": "'
cdata += binascii.hexlify(hashlib.pbkdf2_hmac("sha256",devpassword.encode("utf-8"),b"jcm",1000)).decode() cdata += enctry(devname,devpassword)
cdata += '","port": "' cdata += '","port": "'
cdata += devport cdata += devport
cdata += '"},\n' cdata += '"},\n'
@@ -139,13 +173,32 @@ def main(new_client_socket,post,Headers,info,user):
res += "{\"data\":\"连接超时\"}" res += "{\"data\":\"连接超时\"}"
else: else:
res += "{\"data\":\"" + cdata + "\"}" res += "{\"data\":\"" + cdata + "\"}"
else: else:
if cdata == b'getaddrinfo failed': data = os.popen('ping ' + devrul + ' -c 1 | grep icmp_seq').read()
res += "{\"data\":\"找不到主机\"}" if len(data.split('icmp_seq=1 ttl=64')) == 2:
elif cdata == b'timed out': cdata = '{"name": "'
res += "{\"data\":\"连接超时\"}" cdata += devname
cdata += '","host": "'
cdata += devrul
cdata += '","user": "'
cdata += devuser
cdata += '","password": "'
cdata += enctry(devname,devpassword)
cdata += '","port": "'
cdata += devport
cdata += '"},\n'
fs = open(".config/main/lits.json","ab")
fs.write(cdata.encode("utf-8"))
fs.close()
res += "{\"data\":\"添加成功\"}"
else: else:
res += "{\"data\":\"" + cdata.decode("utf-8") + "\"}" if cdata == b'getaddrinfo failed':
res += "{\"data\":\"找不到主机\"}"
elif cdata == b'timed out':
res += "{\"data\":\"连接超时\"}"
else:
res += "{\"data\":\"" + cdata + "\"}"
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py") httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info) httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info)

View File

@@ -9,10 +9,11 @@ import imp
import hashlib import hashlib
import socket import socket
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '' res = ''
post = RUL_CS
for i in post: for i in post:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
@@ -51,71 +52,57 @@ def main(new_client_socket,post,Headers,info,user):
sh = imp.load_source("server/main/httpclient","server/main/httpclient.py") sh = imp.load_source("server/main/httpclient","server/main/httpclient.py")
#cat,cdata = sh.Client(ii[7],int(ii[19]),"/main/biao/dev") #cat,cdata = sh.Client(ii[7],int(ii[19]),"/main/biao/dev")
cat,cdata = sh.Client(ii[7],int(ii[19]),'/main/biao/dev','') cat,cdata = sh.Client(ii[7],int(ii[19]),'/main/biao/dev','')
if cdata == b'Connection refused': if cdata == b'timed out':
res += '{\n "name":"Connection refused",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"timed out",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cdata == b'Connection refused':
res += '{\n "name":"Connection refused",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
else: else:
if cat == "404": if cat == "404":
res += '{\n "name":"404",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"404",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == "502": elif cat == "502":
res += '{\n "name":"无响应",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"无响应",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == '401': elif cat == '401':
data = sh.logindev(ii[3])
obj = hashlib.md5() cat = data[0]
md = ii[11]
md += time.strftime("I %Y-%m-%d %H:%M ", time.localtime())
obj.update((md).encode('utf-8'))
a = obj.hexdigest()
if info['debug']:
print(md)
print(a)
obj = hashlib.md5()
md = ii[15]
md += time.strftime("I %Y-%m-%d %H:%M ", time.localtime())
obj.update((md).encode('utf-8'))
b = obj.hexdigest()
if info['debug']:
print(md)
print(b)
cat,cdata = sh.Client(ii[7],int(ii[19]),'/login/dev','a=' + a + '&b=' + b)
if cat == '200': if cat == '200':
cdata = cdata.decode("utf-8") #cdata = cdata.decode("utf-8")
if cdata == '{"data":"login"}\r\n\r\n': #if cdata == '{"data":"login"}\r\n\r\n':
cat,cdata = sh.Client(ii[7],int(ii[19]),"/main/biao/dev") cat,cdata = sh.Client(ii[7],int(ii[19]),'/main/biao/dev','')
if cat == "404": if cat == "404":
res += '{\n "name":"404",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"404",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == '502': elif cat == '502':
res += '{\n "name":"无响应",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"无响应",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == '401': elif cat == '401':
res += '{\n "name":"登录失败",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"登录失败",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cdata == '<!DOCTYPE html>': elif cdata == '<!DOCTYPE html>':
res += '{\n "name":"响应错误",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"响应错误",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
else: else:
cdata = cdata.decode("utf-8")[9:] cdata = cdata.decode("utf-8")[9:]
res += cdata res += cdata
res += '{}]} \r\n' res += '{}]} \r\n'
else: #else:
cdata = cdata.split('":"') #cdata = cdata.split('":"')
cdata = cdata[1].split('","') #cdata = cdata[1].split('","')
else: else:
if cat == "404": if cat == "404":
res += '{\n "name":"404",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"404",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == '502': elif cat == '502':
res += '{\n "name":"无响应",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"无响应",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cat == '401': elif cat == '401':
res += '{\n "name":"登录失败",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"登录失败",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
elif cdata == '<!DOCTYPE html>': elif cdata == '<!DOCTYPE html>':
res += '{\n "name":"响应错误",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"响应错误",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
else: else:
cdata = cdata.decode("utf-8")[9:] cdata = cdata.decode("utf-8")[9:]
res += cdata res += cdata
res += '{}]} \r\n' res += '{}]} \r\n'
elif cdata == '<!DOCTYPE html>': elif cdata == '<!DOCTYPE html>':
res += '{\n "name":"响应错误",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n' res += '{\n "name":"响应错误",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n'
else: else:
cdata = cdata.decode("utf-8")[9:] cdata = cdata.decode("utf-8")[9:]
res += cdata res += cdata
res += '{}]} \r\n' res += '{}]} \r\n'
#new_client_socket.send('{\n "name":"无响应",\n "link":"",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n').encode("utf-8")) #new_client_socket.send('{\n "name":"无响应",\n "link":"info?",\n "fa":"fa-tachometer"\n},' + '{}]} \r\n').encode("utf-8"))
res += ']} \r\n' res += ']} \r\n'
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py") httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info) httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info)

View File

@@ -0,0 +1,45 @@
# coding=utf-8
#!/bin/python
import os
import sys
import time
import imp
import hashlib
import socket
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = ''
path = ''
res = ''
post = RUL_CS
for i in post:
tmp = i.split('=')
if tmp[0] == 'link':
link = tmp[1]
if tmp[0] == 'path':
path = tmp[1]
fs = open(".config/main/lits.json", "rb")
hosts = fs.read().decode("utf-8").split('\n')
fs = open("./server/server.ini", "rb")
pat = fs.read().decode("utf-8")
path = pat.split('\n')
biao = ''
fo = 0
for p in path:
p = "server/" + p.split('\r')[0]
#print(p)
if os.path.isdir(p):
if os.path.isfile(p + "/biao.json"):
fs = open(p + "/biao.json", "rb")
fo += 1
bbt = fs.read().decode("utf-8")
bb = bbt.split('\"')
biao = biao + bbt + ","
#res += biao + '{}]} \r\n'
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info)

89
server/main/filesql.py Normal file
View File

@@ -0,0 +1,89 @@
# coding=utf-8
#!/bin/python
import imp
import os
def new(file,data):
if os.path.exists(file) == False:
fs = open(file,"wb")
fs.write(b"filesql V1.0\r\n")
for i in data:
fs.write(data[i].encode('utf-8'))
fs.write(b"\t")
fs.write(b"\r\n")
fs.close()
def catlen(file):
if os.path.exists(file):
fs = open(file,"rb")
fsdata = fs.read()
fsdata = fsdata.split(b'\r\n')
lens = len(fsdata[2:])
lens = lens - 1
fs.close()
return lens
else:
return 0
def catall(file):
if os.path.exists(file):
fs = open(file,"rb")
fsdata = fs.read()
fsdata = fsdata.split(b'\r\n')
fs.close()
return fsdata[2:-1]
else:
return b''
def cat(file,data,i):
if os.path.exists(file):
fs = open(file,"rb")
fsdata = fs.read()
fsdata = fsdata.split(b'\r\n')
for x in fsdata[2:-1]:
x = x.split(b'\t')
try:
if x[i] == data.encode('utf-8'):
return x
except Exception as e:
x = x
return False
else:
return False
def prin(file,data):
if os.path.exists(file):
fs = open(file,"ab")
for i in data:
fs.write(data[i].encode('utf-8'))
fs.write(b'\t')
fs.write(b'\r\n')
fs.close()
return True
else:
return False
def rmt(file,name,i):
if os.path.exists(file):
fs = open(file,"rb")
fsw = open(file + '.tmp',"wb")
fsdata = fs.read()
fsdata = fsdata.split(b'\r\n')
fsw.write(fsdata[0])
fsw.write(b'\r\n')
fsw.write(fsdata[1])
fsw.write(b'\r\n')
for xx in fsdata[2:-1]:
x = xx.split(b'\t')
try:
if x[i] != name.encode('utf-8'):
fsw.write(xx)
fsw.write(b'\r\n')
except Exception as e:
fsw.write(xx)
fsw.write(b'\r\n')
fs.close()
fsw.close()
os.remove(file)
os.rename(file + ".tmp",file)
return True
else:
return False

View File

@@ -10,6 +10,28 @@ import binascii
import socket import socket
# 加密
def enctry(k,s):
#k = 'djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd'
encry_str = ""
for i,j in zip(s,k):
# i为字符j为秘钥字符
temp = str(ord(i)+ord(j))+'_' # 加密字符 = 字符的Unicode码 + 秘钥的Unicode码
encry_str = encry_str + temp
return encry_str
def dectry(k,p):
#k = 'djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd'
dec_str = ""
for i,j in zip(p.split("_")[:-1],k):
# i 为加密字符j为秘钥字符
ttemp = ord(j)
temp = int(i)
temp = temp - ttemp
temp = chr(temp) # 解密字符 = (加密Unicode码字符 - 秘钥字符的Unicode码)的单字节字符
dec_str = dec_str+temp
return dec_str
def Client(ip,dk,dir,post): def Client(ip,dk,dir,post):
try: try:
if dk == "": if dk == "":
@@ -21,13 +43,84 @@ def Client(ip,dk,dir,post):
fsdata = fsdata + 'Host: ' + ip + ':' + str(dk) + '\r\n' fsdata = fsdata + 'Host: ' + ip + ':' + str(dk) + '\r\n'
fs = open(".config/main/cookie","rb") fs = open(".config/main/cookie","rb")
for c in fs.read().decode("utf-8").split('\n'): for c in fs.read().decode("utf-8").split('\n'):
if c.split(':')[0] == ip: if c.split('\t')[0] == ip:
fsdata = fsdata + 'Cookie: ' + c.split(':')[1] + '\r\n' fsdata = fsdata + 'Cookie: ' + c.split('\t')[2] + '\r\n'
client.connect((ip,dk)) client.connect((ip,dk))
client.send((fsdata + '\r\n' + post).encode("utf-8")) client.send((fsdata + '\r\n' + post).encode("utf-8"))
data = b'' data = b''
run = 0 run = 0
d = '' d = ''
while run == 0:
try:
d = client.recv(1024)
except Exception as e:
#print(e.args)
#if len(d) != 1024:
# run = 1
return "502",e.args[-1].encode("utf-8")
if data == b'':
data = b"404\r\n\r\n404"
else:
run = 1
if e.args[0] == 'timed out':
d = False
#break
if d:
data = data + d
if dir == '/assets/info':
if data[-1] == '}':
run = 1
else:
run = 1
#print(data)
client.close()
if data[:len(b'HTTP/1.1 200')] == b'HTTP/1.1 200':
catdatah = data.split(b'\r\n\r\n')[0].split(b'\r\n')
for hh in catdatah[1:]:
hhh = hh.split(b': ')
if hhh[0] == b'set-Cookie':
hhhh = hhh[1].split(b';')
fs = open(".config/main/cookie","ab")
fs.write(ip.encode('utf-8'))
fs.write(b'\t')
fs.write(str(dk).encode('utf-8'))
fs.write(b'\t')
fs.write(hhhh[0])
fs.write(b'\n')
fs.close()
#print(hhh)
datad = b''
for ddd in data.split(b'\r\n\r\n')[1:]:
datad = datad + b'\r\n\r\n' + ddd
return '200',datad[4:]
if data[:len(b'HTTP/1.1 ')] == b'HTTP/1.1 ':
return data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3].decode('utf-8'),data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3]
except Exception as e:
#print(e.args)
return "404",e.args[-1].encode("utf-8")
socket.setdefaulttimeout(0)
return "502","502".encode("utf-8")
def Clientchar(ip,dk,dir,post):
try:
if dk == "":
dk = 80
socket.setdefaulttimeout(5)
client = socket.socket() #定义协议类型,相当于生命socket类型,同时生成socket连接对象
#client.connect(('openwrt.lan',80))
fsdata = 'POST ' + dir + ' HTTP/1.1\r\n'
if post == b'':
fsdata = 'GET ' + dir + ' HTTP/1.1\r\n'
fsdata = fsdata + 'Host: ' + ip + ':' + str(dk) + '\r\n'
fs = open(".config/main/cookie","rb")
for c in fs.read().decode("utf-8").split('\n'):
if c.split('\t')[0] == ip:
fsdata = fsdata + 'Cookie: ' + c.split('\t')[2] + '\r\n'
client.connect((ip,dk))
client.send((fsdata + '\r\n').encode("utf-8") + post)
data = b''
run = 0
d = ''
while run == 0: while run == 0:
try: try:
d = client.recv(1024) d = client.recv(1024)
@@ -59,18 +152,49 @@ def Client(ip,dk,dir,post):
hhhh = hhh[1].split(b';') hhhh = hhh[1].split(b';')
fs = open(".config/main/cookie","ab") fs = open(".config/main/cookie","ab")
fs.write(ip.encode('utf-8')) fs.write(ip.encode('utf-8'))
fs.write(b':') fs.write(b'\t')
fs.write(str(dk).encode('utf-8'))
fs.write(b'\t')
fs.write(hhhh[0]) fs.write(hhhh[0])
fs.write(b'\n') fs.write(b'\n')
fs.close() fs.close()
print(hhh) print(hhh)
datad = b'' ma = data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3].decode('utf-8')
for ddd in data.split(b'\r\n\r\n')[1:]: dat = data[len(data.split(b'\r\n\r\n')[0]) + 4:]
datad = datad + b'\r\n\r\n' + ddd jvav = '6'
return '200',datad[4:] h = data.split(b'\r\n\r\n')[0].split(b'\r\n')
for i in h:
i = i.split(b':')
if i[0] == b'Content-Type':
jvav = i[1]
return ma,dat,jvav.decode('utf-8')
if data[:len(b'HTTP/1.1 ')] == b'HTTP/1.1 ': if data[:len(b'HTTP/1.1 ')] == b'HTTP/1.1 ':
return data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3].decode('utf-8'),data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3] ma = data[len(b'HTTP/1.1 '):len(b'HTTP/1.1 ') + 3].decode('utf-8')
dat = data[len(data.split(b'\r\n\r\n')[0]) + 4:]
jvav = '6'
h = data.split(b'\r\n\r\n')[0].split(b'\r\n')
for i in h:
i = i.split(b':')
if i[0] == b'Content-Type':
jvav = i[1]
return ma,dat,jvav.decode('utf-8')
except Exception as e: except Exception as e:
#print(e.args) #print(e.args)
return "404",e.args[-1].encode("utf-8") return "500",e.args[-1].encode("utf-8"),'text/html'
socket.setdefaulttimeout(0) socket.setdefaulttimeout(0)
return "502",b"502",'text/html'
def logindev(devname):
fs = open(".config/main/lits.json", "rb")
hosts = fs.read().decode("utf-8").split('\n')
for i in range(len(hosts)-1):
ii = hosts[i].split('"')
if ii[3] == devname:
dd = ''
a = ii[11]
b = ii[15]
b = dectry(ii[3],b)
a = enctry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",enctry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),a))
b = enctry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",enctry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),b))
cdata = Client(ii[7],int(ii[19]),'/login/dev','a=' + a + '&b=' + b)
return cdata

View File

@@ -53,7 +53,12 @@ def websockrx(new_client_socket):
return datas,Opcode return datas,Opcode
def websockfs(new_client_socket,data): def websockfs(new_client_socket,data):
data = b'' + data data = b'' + data
if len(data.decode("utf-8")) > 101: lens = 0
try:
lens = len(data.decode("utf-8"))
except Exception as e:
lens = len(data)
if lens > 101:
data = data.decode("utf-8") data = data.decode("utf-8")
cd = 0 cd = 0
while cd != len(data): while cd != len(data):
@@ -79,6 +84,42 @@ def websockfs(new_client_socket,data):
datab += bytes.fromhex(len_) datab += bytes.fromhex(len_)
new_client_socket.send(datab) new_client_socket.send(datab)
new_client_socket.send(data) new_client_socket.send(data)
def websockfsstr(new_client_socket,data):
data = b'' + data
datalen = len(data)
if datalen > 101:
data = data.decode("utf-8")
datalen = ''
for i in data:
datalen += i
if len(datalen.encode("utf-8")) > 90:
websockfsstr(new_client_socket,datalen.encode("utf-8"))
datalen = ''
websockfsstr(new_client_socket,datalen.encode("utf-8"))
#cd = 0
#while cd != len(data):
# if len(data) < (cd + 100):
# if cd == 0:
# websockfsstr(new_client_socket,data[cd:cd + 100].encode("utf-8"))
# else:
# websockfsstr(new_client_socket,b'' + data[cd:cd + 100].encode("utf-8"))
# cd = len(data)
# else:
# if cd == 0:
# websockfsstr(new_client_socket,data[cd:cd + 100].encode("utf-8"))
# else:
# websockfsstr(new_client_socket,b'' + data[cd:cd + 100].encode("utf-8"))
# cd = cd + 100
else:
datab = b'12'
if len(data) < 126:
datab = bytes.fromhex('81')
len_ = hex(len(data))[2:]
if len(len_) == 1:
len_ = '0' + len_
datab += bytes.fromhex(len_)
new_client_socket.send(datab)
new_client_socket.send(data)
def websockend(new_client_socket,data): def websockend(new_client_socket,data):
#websockfs(new_client_socket,b'2{"d":"disableLeaveAlert"}') #websockfs(new_client_socket,b'2{"d":"disableLeaveAlert"}')
data = b'0' + data data = b'0' + data
@@ -111,11 +152,44 @@ def websockend(new_client_socket,data):
datab += bytes.fromhex('E8') datab += bytes.fromhex('E8')
new_client_socket.send(datab) new_client_socket.send(datab)
time.sleep(0.05) time.sleep(0.05)
new_client_socket.close()
def websockendstr(new_client_socket,data):
#websockfs(new_client_socket,b'2{"d":"disableLeaveAlert"}')
data = b'' + data
if len(data.decode("utf-8")) > 101:
data = data.decode("utf-8")
cd = 0
while cd != len(data):
websockfsstr(new_client_socket,data[cd:cd + 100].encode("utf-8"))
if len(data) < (cd + 100):
cd = len(data)
else:
cd = cd + 100
else:
datab = b'12'
if len(data) < 126:
datab = bytes.fromhex('81')
#datab += bytes.fromhex('03')
#datab += bytes.fromhex('30')
#datab += bytes.fromhex('0D')
#datab += bytes.fromhex('0A')
len_ = hex(len(data))[2:]
if len(len_) == 1:
len_ = '0' + len_
datab += bytes.fromhex(len_)
new_client_socket.send(datab)
new_client_socket.send(data)
datab = bytes.fromhex('88')
datab += bytes.fromhex('02')
datab += bytes.fromhex('03')
datab += bytes.fromhex('E8')
new_client_socket.send(datab)
time.sleep(0.05)
def websocktime(new_client_socket): def websocktime(new_client_socket):
datab = bytes.fromhex('89') datab = bytes.fromhex('89')
datab += bytes.fromhex('00') datab += bytes.fromhex('00')
new_client_socket.send(datab) new_client_socket.send(datab)
time.sleep(0.2) time.sleep(0.01)
return websockrx(new_client_socket) return websockrx(new_client_socket)
def websockinit(new_client_socket,Headers,info): def websockinit(new_client_socket,Headers,info):
@@ -143,11 +217,12 @@ def websockinit(new_client_socket,Headers,info):
he = info["Headers"] he = info["Headers"]
he += "Upgrade: websocket\r\n" he += "Upgrade: websocket\r\n"
he += "Connection: Upgrade\r\n" he += "Connection: Upgrade\r\n"
he += "Connection: close\r\n"
he += "Sec-WebSocket-Accept: " + SecWebSocketAccept + "\r\n" he += "Sec-WebSocket-Accept: " + SecWebSocketAccept + "\r\n"
if SecWebSocketProtocol != '': if SecWebSocketProtocol != '':
he += "Sec-Websocket-Protocol: " + SecWebSocketProtocol + "\r\n" he += "Sec-Websocket-Protocol: " + SecWebSocketProtocol + "\r\n"
he = he + '\r\n' he = he + '\r\n'
he = "HTTP/1.1 101 Switching Protocols \r\n" + he he = "HTTP/1.0 101 Switching Protocols \r\n" + he
new_client_socket.send(he.encode("utf-8")) new_client_socket.send(he.encode("utf-8"))
if SecWebSocketProtocol != '': if SecWebSocketProtocol != '':
#time.sleep(0.5) #time.sleep(0.5)
@@ -219,11 +294,11 @@ def tcplink(sock, addr , logs, info,void):
l = len(l) l = len(l)
if recv_tcp[:4] == b'POST': if recv_tcp[:4] == b'POST':
if l > 1: if l > 1:
os.system("./error.sh '" + "POST" + "'") #os.system("./error.sh '" + "POST" + "'")
recv_data = recv_tcp.split(b'\r\n\r\n') recv_data = recv_tcp.split(b'\r\n\r\n')
Headers = recv_data[0].decode("utf-8") Headers = recv_data[0].decode("utf-8")
Headers = Headers.split('\r\n') Headers = Headers.split('\r\n')
os.system("./error.sh '" + catHeaders("Content-Type",Headers) + "'") #os.system("./error.sh '" + catHeaders("Content-Type",Headers) + "'")
if catHeaders("Content-Type",Headers)[:len("application/x-www-form-urlencoded")] == "application/x-www-form-urlencoded": if catHeaders("Content-Type",Headers)[:len("application/x-www-form-urlencoded")] == "application/x-www-form-urlencoded":
os.system("./error.sh '" + catHeaders("Transfer-Encoding",Headers) + "'") os.system("./error.sh '" + catHeaders("Transfer-Encoding",Headers) + "'")
if catHeaders("Transfer-Encoding",Headers)[:len("Transfer-Encoding")] == "chunked": if catHeaders("Transfer-Encoding",Headers)[:len("Transfer-Encoding")] == "chunked":
@@ -268,9 +343,9 @@ def tcplink(sock, addr , logs, info,void):
break break
#36\r\n #36\r\n
#name=admin password=admin type=username checkbox=false #name=admin password=admin type=username checkbox=false
#\r\n0\r\n\r\n #\r\n0\r\n\r\n
else: else:
recv_tcp += new_client_socket.recv(8192) recv_tcp += new_client_socket.recv(8192)
else: else:
@@ -298,9 +373,13 @@ def tcplink(sock, addr , logs, info,void):
RUL_CS = Headers[0].split(' ') RUL_CS = Headers[0].split(' ')
RUL_CS = RUL_CS[1].split('?') RUL_CS = RUL_CS[1].split('?')
if len(RUL_CS) == 1: if len(RUL_CS) == 1:
RUL_CS = '' RUL_CS = 'link=',''
else: else:
RUL_CS = http_to_char(RUL_CS[1]) RUL_CS = RUL_CS[1]
RUL_CS = RUL_CS.split("&")
for i in range(0,len(RUL_CS)):
RUL_CS[i] = http_to_char(RUL_CS[i])
#RUL_CS = http_to_char(RUL_CS[1])
pr = (time.strftime("I %Y-%m-%d %H:%M:%S ", time.localtime()).encode("utf-8")) pr = (time.strftime("I %Y-%m-%d %H:%M:%S ", time.localtime()).encode("utf-8"))
pr += ((str(client_addr) + ' ' + '' + Headers[0].split(' ')[1]).encode("utf-8")) pr += ((str(client_addr) + ' ' + '' + Headers[0].split(' ')[1]).encode("utf-8"))
logs("info",info,pr + b"\r\n") logs("info",info,pr + b"\r\n")

View File

@@ -6,7 +6,8 @@ import os
import imp import imp
import hashlib import hashlib
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
post = RUL_CS
if len(post) == 3: if len(post) == 3:
link = '' link = ''
sw = '' sw = ''

View File

@@ -12,12 +12,24 @@ import psutil
import traceback import traceback
import threading import threading
def dectry(k,p):
#k = 'djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd'
dec_str = ""
for i,j in zip(p.split("_")[:-1],k):
# i 为加密字符j为秘钥字符
ttemp = ord(j)
temp = int(i)
temp = temp - ttemp
temp = chr(temp) # 解密字符 = (加密Unicode码字符 - 秘钥字符的Unicode码)的单字节字符
dec_str = dec_str+temp
return dec_str
def rom(info): def rom(info):
i=0 i=0
retlist1=[] retlist1=[]
rom=0 rom=0
disks=1 disks=1
if info['OS'] == "Linux": '''if info['OS'] == "Linux":
romsh = os.popen("LANG=en_US df -h") romsh = os.popen("LANG=en_US df -h")
list = romsh.read().split("\n") list = romsh.read().split("\n")
ilen = len(list) ilen = len(list)
@@ -46,12 +58,15 @@ def rom(info):
rom = diskinfo rom = diskinfo
i=i+1 i=i+1
disks += 1 disks += 1
else: else:'''
list = psutil.disk_partitions() if True:
list = psutil.disk_partitions(False)
ilen = len(list) ilen = len(list)
while i < ilen: while i < ilen:
if list[i].mountpoint == "/boot": if list[i].mountpoint == "/boot":
i += 1 i += 1
elif list[i].device == "/dev/zram1":
i += 1
else: else:
try: try:
diskinfo = psutil.disk_usage(list[i].mountpoint) diskinfo = psutil.disk_usage(list[i].mountpoint)
@@ -92,7 +107,7 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
user = tmp5[1] user = tmp5[1]
if RUL == "/favicon.ico": if RUL == "/favicon.ico":
if post_data == b'': if post_data == b'':
post = RUL_CS.split('&') post = RUL_CS
else: else:
post = post_data.decode("utf-8").split('&') post = post_data.decode("utf-8").split('&')
httpserver.httppostfile(new_client_socket,"200","./web" + RUL,True,Headers,info) httpserver.httppostfile(new_client_socket,"200","./web" + RUL,True,Headers,info)
@@ -101,6 +116,7 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
ma = "200" ma = "200"
if RUL == "/login": if RUL == "/login":
if Headers[0][:4] == "POST": if Headers[0][:4] == "POST":
import datetime
post = post_data.decode("utf-8").split('&') post = post_data.decode("utf-8").split('&')
name = "" name = ""
password = "" password = ""
@@ -130,9 +146,15 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
if fs_ == "": if fs_ == "":
fs_ = fs_ fs_ = fs_
else: else:
session_ = session_ + fs_ + ("\n")
fs__ = fs_.split(',') fs__ = fs_.split(',')
import datetime ifstr = (datetime.datetime.now()).strftime("%a, %d %b %Y %H:%M:%S GMT")
ifstr = (datetime.datetime.now()).strftime(" %d %b %Y ")
fistr = fs__[3][:0-len("23:40:54 GMT")]
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
ifstr = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime(" %d %b %Y ")
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
cookie_date = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%a, %d %b %Y %H:%M:%S GMT") cookie_date = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%a, %d %b %Y %H:%M:%S GMT")
#time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.localtime(time.strptime("1","%d"))) #time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.localtime(time.strptime("1","%d")))
@@ -146,15 +168,24 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
user_write = '' user_write = ''
for fs_ in fs_session: for fs_ in fs_session:
if fs_ == "sessinon": if fs_ == "sessinon":
fs_ = fs_ fs_rr = fs_rr
else: else:
if fs_ == "": if fs_ == "":
fs_ = fs_ fs_ = fs_
else: else:
fs__ = fs_.split(",") fs__ = fs_.split(',')
ifstr = (datetime.datetime.now()).strftime("%a, %d %b %Y %H:%M:%S GMT")
ifstr = (datetime.datetime.now()).strftime(" %d %b %Y ")
fistr = fs__[3][:0-len("23:40:54 GMT")]
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
ifstr = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime(" %d %b %Y ")
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
res = res + "set-Cookie: Cluster_management_Jiang=" + cok + "; SameSite=Lax; Expires=" + cookie_date res = res + "set-Cookie: Cluster_management_Jiang=" + cok + "; SameSite=Lax; Expires=" + cookie_date
fs_user = open(".config/sessino","a") fs_user = open(".config/sessino","wb")
fs_user.write(cok + "," + name + "," + cookie_date + "\n") fs_user.write(fs_rr.decode('utf-8'))
fs_user.write((cok + "," + name + "," + cookie_date + "\n").decode('utf-8'))
fs_user.close() fs_user.close()
else: else:
res = res + "set-Cookie: Cluster_management_Jiang=" + cok + "; SameSite=Lax;"# Expires=" + cookie_date + "\r\n" res = res + "set-Cookie: Cluster_management_Jiang=" + cok + "; SameSite=Lax;"# Expires=" + cookie_date + "\r\n"
@@ -163,7 +194,97 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
else: else:
res = "application/json" + res res = "application/json" + res
httpserver.httppostchar(new_client_socket,"200","{\"data\":\"用户名或密码错误\"}".encode("utf-8"),res,Headers,info) httpserver.httppostchar(new_client_socket,"200","{\"data\":\"用户名或密码错误\"}".encode("utf-8"),res,Headers,info)
return 0
elif RUL == "/login/dev":
if Headers[0][:4] == "POST":
post = post_data.decode("utf-8").split('&')
a = ''
b = ''
c = ''
for p in post:
pp = p.split("=")
if pp[0] == "a":
a = pp[1]
if pp[0] == "b":
b = pp[1]
if pp[0] == "c":
c = pp[1]
b = dectry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",b)
b = dectry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),b)
a = dectry("djq%5cu#-jeq15abg$z9_i#_w=$o88m!*alpbedlbat8cr74sd",a)
a = dectry(time.strftime(" %Y-%m-%d %H:%M ", time.localtime()),a)
tools = imp.load_source("Tools/Tools.py","Tools/Tools.py")
tools = tools.ifuser(a,b)
res = ""
if tools == "yes":
import datetime
cok = ''
for x in range(32):
cok = cok + random.choice("0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLLZXCVBNM")
fs_rr = session_
fs_session = fs_rr.split('\n')
for fs_ in fs_session:
if fs_ == "sessinon":
session_ = (fs_)
session_ = session_ + ("\n")
else:
if fs_ == "":
fs_ = fs_
else:
fs__ = fs_.split(',')
ifstr = (datetime.datetime.now()).strftime("%a, %d %b %Y %H:%M:%S GMT")
ifstr = (datetime.datetime.now()).strftime(" %d %b %Y ")
fistr = fs__[3][:0-len("23:40:54 GMT")]
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
ifstr = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime(" %d %b %Y ")
if fistr == ifstr:
session_ = session_ + fs_ + ("\n")
cookie_date = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%a, %d %b %Y %H:%M:%S GMT")
#time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.localtime(time.strptime("1","%d")))
session_ = session_ + cok + "," + a + "," + cookie_date + "\n"
res = res + "set-Cookie: Cluster_management_Jiang=" + cok + "; SameSite=Lax;"# Expires=" + cookie_date + "\r\n"
res = "application/json\r\n" + res
httpserver.httppostchar(new_client_socket,"200",b"{\"data\":\"login\"}",res,Headers,info)
return 0
elif RUL == "/assets/info":
res = ''
sent_now = psutil.net_io_counters().bytes_sent
recv_now = psutil.net_io_counters().bytes_recv
sent = (sent_now - sent_before)/1024/(time.time()-ttime) # 算出1秒后的差值
recv = (recv_now - recv_before)/1024/(time.time()-ttime)
ttime=time.time()
sent_before=sent_now
recv_before=recv_now
res += '"api": "1",'
if info['OS'] == "Linux":
res += '"safe": "--",'
else:
res += '"safe": "--",'
res += '"cpu": "'+str(psutil.cpu_percent(None))+'",'
res += '"ram": "'+str(psutil.virtual_memory().percent)+'",'
res += '"rom": "'+rom(info)+'",'
tx = ""
rx = ""
if sent < 1000:
tx = '{0}KB/s'.format("%.2f"%sent)
else:
sent = sent / 1024
tx = '{0}MB/s'.format("%.2f"%sent)
if recv < 1000:
rx = '{0}KB/s'.format("%.2f"%recv)
else:
recv = recv / 1024
rx = '{0}MB/s'.format("%.2f"%recv)
res += '"tx": "'+tx+'",'
res += '"rx": "'+rx+'"'
res += '}'
httpserver.httppostchar(new_client_socket,"200",res.encode('utf-8'),"application/json",Headers,info)
return 0
if RUL[:len("/assets")] != "/assets": if RUL[:len("/assets")] != "/assets":
RUL = "/login.html" RUL = "/login.html"
for h in Headers: for h in Headers:
@@ -176,10 +297,67 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
else: else:
my_file = "./web/" + info["theme"] + RUL my_file = "./web/" + info["theme"] + RUL
link = '' link = ''
for i in RUL_CS.split('&'): _link = ''
__link = ''
for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]
else:
if tmp[0] == '_link':
__link = tmp[1]
_link += "link=" + tmp[1] + '\n'
else:
_link += i + '\n'
if (link != '') and (link != '127.0.0.1'):
httpclient = imp.load_source("server/main/httpclient","server/main/httpclient.py")
#httpclient.Client(ii[7],int(ii[19]),'/login/dev','')
fs = open(".config/main/lits.json", "rb")
hosts = fs.read().decode("utf-8").split('\n')
for i in range(len(hosts)-1):
ii = hosts[i].split('"')
if ii[3] == link:
dd = ''
for ddd in RUL_CS:
tmp = ddd.split('=')
if tmp[0] == 'link':
link = tmp[1]
dd += '&_' + ddd
else:
dd += '&' + ddd
data = httpclient.Clientchar(ii[7],int(ii[19]),RUL + "?link=127.0.0.1" + dd,post_data)
if data[0] == "401":
httpclient.logindev(ii[3])
data = httpclient.Clientchar(ii[7],int(ii[19]),RUL + "?link=127.0.0.1" + dd,post_data)
if data[0] == "401":
strr = {}
strr["err"] = data[1].decode('utf-8')
php = imp.load_source("server/main/php.py","server/main/php.py")
data = php.php(new_client_socket,"post","/blink.php",user,Headers,info,strr)
httpserver.httppostchar(new_client_socket,"401",data.encode("utf-8"),"text/html;charset=UTF-8",Headers,info)
return 0
if data[0] == "500":
strr = {}
strr["err"] = data[1].decode('utf-8')
php = imp.load_source("server/main/php.py","server/main/php.py")
data = php.php(new_client_socket,"post","/500.php",user,Headers,info,strr)
httpserver.httppostchar(new_client_socket,"500",data.encode("utf-8"),"text/html;charset=UTF-8",Headers,info)
return 0
if data[0] == "502":
strr = {}
strr["err"] = data[1].decode('utf-8')
php = imp.load_source("server/main/php.py","server/main/php.py")
data = php.php(new_client_socket,"post","/500.php",user,Headers,info,strr)
httpserver.httppostchar(new_client_socket,"500",data.encode("utf-8"),"text/html;charset=UTF-8",Headers,info)
return 0
httpserver.httppostchar(new_client_socket,data[0],data[1],data[2],Headers,info)
return 0
#link = _link
if __link != '':
RUL_CS = _link.split('\n')[:-1]
if os.path.isdir(my_file): if os.path.isdir(my_file):
if os.path.isfile("./web/" + info["theme"] + RUL + "/index.php"): if os.path.isfile("./web/" + info["theme"] + RUL + "/index.php"):
RUL = RUL + "/index.php" RUL = RUL + "/index.php"
@@ -192,7 +370,7 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
if tmp2[-1] == 'php': if tmp2[-1] == 'php':
php = imp.load_source("server/main/php.py","server/main/php.py") php = imp.load_source("server/main/php.py","server/main/php.py")
if post_data == b'': if post_data == b'':
post = RUL_CS.split('&') post = RUL_CS
else: else:
post = post_data.decode("utf-8").split('&') post = post_data.decode("utf-8").split('&')
data = php.php(new_client_socket,post,RUL,user,Headers,info,strr) data = php.php(new_client_socket,post,RUL,user,Headers,info,strr)
@@ -203,8 +381,43 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
else: else:
if RUL == "/login": if RUL == "/login":
httpserver.httppostchar(new_client_socket,"200",b"{\"data\":\"login\"}","application/json",Headers,info) httpserver.httppostchar(new_client_socket,"200",b"{\"data\":\"login\"}","application/json",Headers,info)
elif RUL == "/login/dev":
httpserver.httppostchar(new_client_socket,"200",b"{\"data\":\"login\"}","application/json",Headers,info)
elif RUL == "/token": elif RUL == "/token":
httpserver.httppostchar(new_client_socket,"200",b"{\"token\":\"\"}","application/json",Headers,info) httpserver.httppostchar(new_client_socket,"200",b"{\"token\":\"\"}","application/json",Headers,info)
elif RUL == "/assets/info":
res = ''
sent_now = psutil.net_io_counters().bytes_sent
recv_now = psutil.net_io_counters().bytes_recv
sent = (sent_now - sent_before)/1024/(time.time()-ttime) # 算出1秒后的差值
recv = (recv_now - recv_before)/1024/(time.time()-ttime)
ttime=time.time()
sent_before=sent_now
recv_before=recv_now
res += '"api": "1",'
if info['OS'] == "Linux":
res += '"safe": "--",'
else:
res += '"safe": "--",'
res += '"cpu": "'+str(psutil.cpu_percent(None))+'",'
res += '"ram": "'+str(psutil.virtual_memory().percent)+'",'
res += '"rom": "'+rom(info)+'",'
tx = ""
rx = ""
if sent < 1000:
tx = '{0}KB/s'.format("%.2f"%sent)
else:
sent = sent / 1024
tx = '{0}MB/s'.format("%.2f"%sent)
if recv < 1000:
rx = '{0}KB/s'.format("%.2f"%recv)
else:
recv = recv / 1024
rx = '{0}MB/s'.format("%.2f"%recv)
res += '"tx": "'+tx+'",'
res += '"rx": "'+rx+'"'
res += '}'
httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info)
elif RUL == "/main/info": elif RUL == "/main/info":
res = '' res = ''
if os.path.isfile(".config/main/lits.json"): if os.path.isfile(".config/main/lits.json"):
@@ -248,11 +461,12 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
res += '"tx": "'+tx+'",' res += '"tx": "'+tx+'",'
res += '"rx": "'+rx+'"' res += '"rx": "'+rx+'"'
res += '}' res += '}'
#httpserver.httppostchar(new_client_socket,"200",res.encode('utf-8'),"application/json",Headers,info)
else: else:
url = "http://" + ii[7] + ":8889/assets/info" url = "http://" + ii[7] + ":8889/assets/info"
sh = imp.load_source("server/main/httpclient","server/main/httpclient.py") sh = imp.load_source("server/main/httpclient","server/main/httpclient.py")
#cat,cdata = sh.Client(ii[7],int(ii[19]),"/assets/info") #cat,cdata = sh.Client(ii[7],int(ii[19]),"/assets/info")
cat,cdata = sh.Client(ii[7],int(ii[19]),'/login/dev','') cat,cdata = sh.Client(ii[7],int(ii[19]),'/assets/info','')
if cat == "200": if cat == "200":
try: try:
#response = urllib.request.urlopen(url, timeout=1) #response = urllib.request.urlopen(url, timeout=1)
@@ -260,12 +474,12 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
#html = sh.Client("pi.lan",8889,"/assets/info") #html = sh.Client("pi.lan",8889,"/assets/info")
res += '"api": "1",' res += '"api": "1",'
data = cdata.decode("utf-8").split('"') data = cdata.decode("utf-8").split('"')
res += '"safe": "'+data[3]+'",' res += '"safe": "'+data[7]+'",'
res += '"cpu": "'+data[7]+'",' res += '"cpu": "'+data[11]+'",'
res += '"ram": "'+data[11]+'",' res += '"ram": "'+data[15]+'",'
res += '"rom": "'+data[15]+'",' res += '"rom": "'+data[19]+'",'
res += '"tx": "'+data[19]+'",' res += '"tx": "'+data[23]+'",'
res += '"rx": "'+data[23]+'"' res += '"rx": "'+data[27]+'"'
res += '}' res += '}'
except: except:
res += '"api": "0",' res += '"api": "0",'
@@ -320,27 +534,17 @@ def httpserver_void(new_client_socket,RUL,RUL_CS,post_data,Headers,logs,info):
else: else:
my_file = "./server" + RUL + "/api.py" my_file = "./server" + RUL + "/api.py"
if os.path.isfile(my_file): if os.path.isfile(my_file):
if post_data == b'': #if post_data == b'':
post = RUL_CS.split('&') # post = RUL_CS
else: #else:
rul_ = post_data.decode("utf-8").split('%') #post_data = post_data.split(b'&')
post_data = b'' #for i in range(0,len(post_data)):
for y in range(len(rul_)): # post_data[i] = httpserver.http_to_char(post_data[i].decode("utf-8"))
if y == 0: # for i in
post_data = rul_[y].encode("utf-8")
elif y == (len(rul_)+1): #post = post_data
y=y
else:
hex = rul_[y][:2]
charb = bytes.fromhex(hex)
post_data = post_data + charb
if len(rul_[y]) > 2:
post_data = post_data + rul_[y][2:].encode("utf-8")
#RUL_CS = RUL_CS.decode("utf-8")
post = post_data.decode("utf-8").split('&')
sh = imp.load_source(RUL + "/api.py",my_file) sh = imp.load_source(RUL + "/api.py",my_file)
sh.main(new_client_socket,post,Headers,info,user) sh.main(new_client_socket,RUL_CS,post_data,Headers,info,user)
else: else:
strr = {} strr = {}
strr["err"] = '404' strr["err"] = '404'
@@ -399,9 +603,9 @@ def logsprnts(live,info,data):
os.system("./error.sh '" + data.decode("utf-8") + "'") os.system("./error.sh '" + data.decode("utf-8") + "'")
except Exception as e: except Exception as e:
print() print()
print(live,end=' ') print("\033[31m " + live,end=' ')
print(data,end='') print(data,end='')
print('') print('\033[0m')
lock.release() lock.release()
def logsprnt(live,info,data): def logsprnt(live,info,data):
t = threading.Thread(target=logsprnts, args=(live,info,data)) t = threading.Thread(target=logsprnts, args=(live,info,data))
@@ -477,4 +681,5 @@ def main(info):
if res == -9: if res == -9:
tcp_server_socket.close() tcp_server_socket.close()
run = imp.load_source('run',"server/run.py") run = imp.load_source('run',"server/run.py")
run.main(info) run.main(info)
#os.system("run.sh || run.bat")

View File

@@ -103,10 +103,11 @@ function sysexit(){\r\n\
</p>' </p>'
res += poskuan("系统控制",data,"4") res += poskuan("系统控制",data,"4")
return res return res
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
post = RUL_CS
for i in post: for i in post:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
@@ -154,6 +155,13 @@ function jcmexit(){\r\n\
</p>' </p>'
res = poskuan("重启面板",data,"3") res = poskuan("重启面板",data,"3")
res = resys(res,info) res = resys(res,info)
if info['debug']:
res += poskuan("DEBUG",'<p>\r\n\
<button class="btn btn-sm btn-success" onclick="jcmreset();return false;">DEBUG</button>\r\n\
<script type="text/javascript">\r\n\
\
</script>\
</p>',"2")
strr = {} strr = {}
strr["data"] = res strr["data"] = res
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py") httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")

View File

@@ -9,11 +9,11 @@ import imp
import hashlib import hashlib
import socket import socket
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
for i in post: for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]

View File

@@ -9,11 +9,11 @@ import imp
import hashlib import hashlib
import socket import socket
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
for i in post: for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]

View File

@@ -8,20 +8,25 @@ import time
import imp import imp
import hashlib import hashlib
import socket import socket
import threading
def run(info): def run(info,no):
os.system("sleep 30 && poweroff") if os.path.exists("/sbin/poweroff"):
time.sleep(30)
os.system('/sbin/poweroff')
else:
os.system("shutdown -s -t 30")
def poweroff(info): def poweroff(info):
t = threading.Thread(target=run, args=(info)) t = threading.Thread(target=run, args=(info,""))
t.start() t.start()
return "30S poweroff" return "30S poweroff"
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
for i in post: for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]

View File

@@ -8,20 +8,25 @@ import time
import imp import imp
import hashlib import hashlib
import socket import socket
import threading
def run(info): def run(info,no):
os.system("sleep 30 && reboot") if os.path.exists("/sbin/reboot"):
time.sleep(30)
os.system('/sbin/reboot')
else:
os.system("shutdown -r -t 30")
def reboot(info): def reboot(info):
t = threading.Thread(target=run, args=(info)) t = threading.Thread(target=run, args=(info,""))
t.start() t.start()
return "30S reboot" return "30S reboot"
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
for i in post: for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]

View File

@@ -10,19 +10,19 @@ import hashlib
import socket import socket
import threading import threading
def run(info): def run(info,no):
os.system("timeout /t 30 && shutdown -h") os.system("timeout /t 30 && shutdown -h")
def poweroff(info): def poweroff(info):
t = threading.Thread(target=run, args=(info)) t = threading.Thread(target=run, args=(info,""))
t.start() t.start()
return "30S shutdown -h" return "30S shutdown -h"
def main(new_client_socket,post,Headers,info,user): def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = '' link = ''
path = '' path = ''
res = '{}' res = '{}'
for i in post: for i in RUL_CS:
tmp = i.split('=') tmp = i.split('=')
if tmp[0] == 'link': if tmp[0] == 'link':
link = tmp[1] link = tmp[1]

View File

@@ -0,0 +1,40 @@
# coding=utf-8
#!/bin/python
import os
import sys
import time
import imp
import hashlib
import socket
import threading
def run(info,no):
if os.path.exists("/sbin/halt"):
time.sleep(30)
os.system('/sbin/halt')
else:
os.system("sleep 30 && halt")
def poweroff(info):
t = threading.Thread(target=run, args=(info,""))
t.start()
return "30S halt"
def main(new_client_socket,RUL_CS,post_data,Headers,info,user):
link = ''
path = ''
res = '{}'
for i in RUL_CS:
tmp = i.split('=')
if tmp[0] == 'link':
link = tmp[1]
if tmp[0] == 'path':
path = tmp[1]
res = '{"data":"' + poweroff(info) + '"}'
httpserver = imp.load_source("server/main/httpserver.py","server/main/httpserver.py")
httpserver.httppostchar(new_client_socket,"200",res.encode("utf-8"),"application/json",Headers,info)

3
venv.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
python3 -m venv venv
source ./venv/bin/activate

View File

@@ -377,6 +377,7 @@
location.reload(); location.reload();
} else { } else {
var data = JSON.parse(cathttp); var data = JSON.parse(cathttp);
jcminit();
str = '<tr>' str = '<tr>'
str += ' <th class="detail-col" >' str += ' <th class="detail-col" >'
str += ' <label class="pos-rel">' str += ' <label class="pos-rel">'

View File

@@ -1,12 +0,0 @@
{"for":"10","server":[
{"Package":"VM","name":"VM","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/VM_V0.2.pkg","Description":"给 VMware Workstation 设计的控制台"},
{"Package":"code-server","name":"code-server","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/code-server_V0.2.pkg","Description":"code-server"},
{"Package":"main","name":"首页","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/main_V0.2.pkg","Description":"此软件包包含基本文件系统和系统脚本"},
{"Package":"docker","name":"Docker","Version":"V0.2","Depends":"file","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/docker_V0.2.pkg","Description":"Docker 控制台"},
{"Package":"hsk","name":"花生壳","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/hsk_V0.2.pkg","Description":"花生壳内外穿透客户端"},
{"Package":"APP","name":"应用商店","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/APP_V0.2.pkg","Description":"软件的应用商店"},
{"Package":"file","name":"文件管理","Version":"V0.2","Depends":"file","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/file_V0.2.pkg","Description":"文件管理"},
{"Package":"homeassistant","name":"Home Assistant","Version":"V0.2","Depends":"main,docker","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/homeassistant_V0.2.pkg","Description":"Home Assistant"},
{"Package":"GroupControl","name":"集群任务","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/GroupControl_V0.2.pkg","Description":"集群任务控制"},
{"Package":"frpc","name":"frpc","Version":"V0.2","Depends":"main","License":"GPL-2.0","rul":"http://openwrt.lan/data/Blog/www/jcm/pkg/frpc_V0.2.pkg","Description":"frp内网穿透客户端"}
]}

313
web/Ace_Admin/blank.php Normal file
View File

@@ -0,0 +1,313 @@
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>集群管理</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<!-- text fonts -->
<link rel="stylesheet" href="assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
<script src="assets/js/html5shiv.min.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="no-skin">
<div id="navbar" class="navbar navbar-default ace-save-state">
<div class="navbar-container ace-save-state" id="navbar-container">
<button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar">
<span class="sr-only">切换侧边栏</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-header pull-left">
<a href="./" class="navbar-brand">
<small>
<i class="fa fa-leaf"></i>
集群管理
</small>
</a>
</div>
<div class="navbar-buttons navbar-header pull-right" role="navigation">
<ul class="nav ace-nav">
<?php include 'main/wutz.html'; ?>
<li class="light-blue dropdown-modal">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
<img class="nav-user-photo" src="assets/images/avatars/user.jpg" alt="Jason's Photo" />
<span class="user-info">
<small>欢迎,</small>
<?php echo $user; ?>
</span>
<i class="ace-icon fa fa-caret-down"></i>
</a>
<?php include 'main/usercaidan.html'; ?>
</li>
</ul>
</div>
</div><!-- /.navbar-container -->
</div>
<div class="main-container ace-save-state" id="main-container">
<script type="text/javascript">
try { ace.settings.loadState('main-container') } catch (e) { }
</script>
<div id="sidebar" class="sidebar responsive ace-save-state">
<script type="text/javascript">
try { ace.settings.loadState('sidebar') } catch (e) { }
</script>
<div class="sidebar-shortcuts" id="sidebar-shortcuts">
<div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
<button class="btn btn-success">
<i class="ace-icon fa fa-signal"></i>
</button>
<button class="btn btn-info">
<i class="ace-icon fa fa-pencil"></i>
</button>
<button class="btn btn-warning">
<i class="ace-icon fa fa-users"></i>
</button>
<button class="btn btn-danger" onclink="location.href='./setup?link=127.0.0.1'" tybe="button">
<i class="ace-icon fa fa-cogs"></i>
</button>
</div>
<div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
<span class="btn btn-success"></span>
<span class="btn btn-info"></span>
<span class="btn btn-warning"></span>
<span onclick="javascript:window.open('./setup?link=127.0.0.1')" class="btn btn-danger"></span>
</div>
</div><!-- /.sidebar-shortcuts -->
<ul class="nav nav-list" id="biao">
<li class="">
<a href="">
<span class="menu-text">正在加载</span>
</a>
<b class="arrow"></b>
</li>
</ul><!-- /.nav-list -->
<div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
<i id="sidebar-toggle-icon" class="ace-icon fa fa-angle-double-left ace-save-state" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
</div>
</div>
<div class="main-content">
<div class="main-content-inner">
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
<ul class="breadcrumb">
<li class="active"><div id="biaotou">集群管理</li>
</ul><!-- /.breadcrumb -->
<div class="nav-search" id="nav-search">
<form class="form-search">
<span class="input-icon">
<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
<i class="ace-icon fa fa-search nav-search-icon"></i>
</span>
</form>
</div><!-- /.nav-search -->
</div>
<div class="page-content">
<?php include 'main/ace-settings-container.html'; ?>
<div id="row" class="row tab-content" style="border:0px solid #C5D0DC;padding: 0px 0px;">
</div><!-- /.row -->
</div><!-- /.page-content -->
</div>
</div><!-- /.main-content -->
<div class="footer">
<div class="footer-inner">
<div class="footer-content">
<span class="bigger-120">
<span class="blue bolder">Ace</span>
Application &copy; 2013-9014
</span>
&nbsp; &nbsp;
<span class="action-buttons">
<a href="#">
<i class="ace-icon fa fa-twitter-square light-blue bigger-150"></i>
</a>
<a href="#">
<i class="ace-icon fa fa-facebook-square text-primary bigger-150"></i>
</a>
<a href="#">
<i class="ace-icon fa fa-rss-square orange bigger-150"></i>
</a>
</span>
</div>
</div>
</div>
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
</div><!-- /.main-container -->
<!-- basic scripts -->
<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- <![endif]-->
<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]-->
<script type="text/javascript">
if ('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- page specific plugin scripts -->
<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>
<script src="assets/js/bootbox.js"></script>
<script src="main/index.js"></script>
<script src="index.js"></script>
<script type="text/javascript">
jQuery(function ($) {
/////////////////////////////////
//表复选框
$('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);
//选中/取消选择"根据表头选择所有行"复选框
$('#dynamic-table > thead > tr > th input[type=checkbox], #dynamic-table_wrapper input[type=checkbox]').eq(0).on('click', function () {
var th_checked = this.checked;//checkbox inside "TH" table header
$('#dynamic-table').find('tbody > tr').each(function () {
var row = this;
if (th_checked) myTable.row(row).select();
else myTable.row(row).deselect();
});
});
//选中/取消选中复选框时选择/取消选择行
$('#dynamic-table').on('click', 'td input[type=checkbox]', function () {
var row = $(this).closest('tr').get(0);
if (this.checked) myTable.row(row).deselect();
else myTable.row(row).select();
});
})
</script>
<script type="text/javascript">
window.onload = function () {
//jcminit();
}
function addpost() {
var devname = $('input[name=devname]').val();
var devrul = $('input[name=devrul]').val();
var devuser = $('input[name=devuser]').val();
var devpassword = $('input[name=devpassword').val();
var devport = $('input[name=devport').val();
if (!devrul) {
bootbox.confirm("地址不能为空", function (result) {
})
//layer.msg("用户名不能为空");
return false;
}if (!devuser) {
bootbox.confirm("用户名不能为空", function (result) {
})
//layer.msg("用户名不能为空");
return false;
}if (!devpassword) {
bootbox.confirm("密码不能为空", function (result) {
})
//layer.msg("用户名不能为空");
return false;
}if (!devname) {
devname = devrul;
//layer.msg("用户名不能为空");
}if (!devport) {
devport = 8888;
//layer.msg("用户名不能为空");
}
//var auto = false;
//if (checkbox.checked)
var data =
{ devname: devname, devrul: devrul, devuser: devuser ,devpassword: devpassword ,devport: devport };
$.ajax({
url: "main/add",
type: 'post',
async: true,
data: data,
dataType: "json",
success: function (data) {
if (data.data == "添加成功"){
location.reload();
}
bootbox.confirm(data.data, function (result) {
})
re_captcha();
},
error: function () {
bootbox.confirm("链接失败", function (result) {
})
re_captcha();
}
})
}
</script>
<!-- inline scripts related to this page -->
</body>
</html>

View File

@@ -631,18 +631,19 @@
var reg = ""; var reg = "";
var link = ""; var link = "";
for (i = 0; i < data.datafo; i++) { for (i = 0; i < data.datafo; i++) {
if (data.data[i].name == document.getElementById('name').value) if (data.data[i].name == document.getElementById('name').value){
document.getElementById('h3text').innerHTML = "edit"; document.getElementById('h3text').innerHTML = "edit";
document.getElementById('name').value = data.data[i].name; document.getElementById('name').value = data.data[i].name;
document.getElementById('type').value = data.data[i].type;; document.getElementById('type').value = data.data[i].type;;
document.getElementById('local_ip').value = data.data[i].local_ip;; document.getElementById('local_ip').value = data.data[i].local_ip;;
document.getElementById('local_port').value = data.data[i].local_port;; document.getElementById('local_port').value = data.data[i].local_port;;
document.getElementById('remote_port').value = data.data[i].remote_port;; document.getElementById('remote_port').value = data.data[i].remote_port;;
document.getElementById('name').disabled = false; document.getElementById('name').disabled = false;
document.getElementById('type').disabled = false; document.getElementById('type').disabled = false;
document.getElementById('local_ip').disabled = false; document.getElementById('local_ip').disabled = false;
document.getElementById('local_port').disabled = false; document.getElementById('local_port').disabled = false;
document.getElementById('remote_port').disabled = false; document.getElementById('remote_port').disabled = false;
}
} }
} }
} }

View File

@@ -46,7 +46,7 @@ function jcminit() {
str += '<ul class="submenu">'; str += '<ul class="submenu">';
for (j = 1; j < Object.keys(data.data[i].data).length; j++) { for (j = 1; j < Object.keys(data.data[i].data).length; j++) {
if (r[2] == data.data[i].name) { if (r[2] == data.data[i].name) {
if (window.location.pathname + '?' == data.data[i].data[j - 1].link) { if (window.location.pathname + '?' == ('/' + data.data[i].data[j - 1].link)) {
str += '<li class="active">'; str += '<li class="active">';
} else { } else {
str += '<li class="">'; str += '<li class="">';

View File

@@ -1,11 +1,14 @@
window.onload = function () { window.onload = function () {
infoupdata_(); infoupdata_();
} }
window.setInterval(infoupdata, 10000); window.setInterval(infoupdata, 5000);
function infoupdata_(){ function infoupdata_(){
const cpuHttp = new XMLHttpRequest(); const cpuHttp = new XMLHttpRequest();
cpuHttp.open("GET", 'info/info'); var rul = catrul('info/info?');
cpuHttp.open("GET", rul);
cpuHttp.send(); cpuHttp.send();
cpuHttp.onreadystatechange = function() { cpuHttp.onreadystatechange = function() {
if(cpuHttp.readyState == 4 && cpuHttp.status == 200){ if(cpuHttp.readyState == 4 && cpuHttp.status == 200){
@@ -249,7 +252,8 @@ function infoupdata_(){
function infoupdata(){ function infoupdata(){
const cpuHttp = new XMLHttpRequest(); const cpuHttp = new XMLHttpRequest();
cpuHttp.open("GET", 'info/info'); var rul = catrul('info/info?');
cpuHttp.open("GET", rul);
cpuHttp.send(); cpuHttp.send();
cpuHttp.onreadystatechange = function() { cpuHttp.onreadystatechange = function() {
if(cpuHttp.readyState == 4 && cpuHttp.status == 200){ if(cpuHttp.readyState == 4 && cpuHttp.status == 200){
@@ -330,7 +334,7 @@ function infoupdata(){
//var barColor = 'brown';//$('#' + servername).data('color');// || (!$box.hasClass('infobox-dark') ? $box.css('color') : 'rgba(255,255,255,0.95)'); //var barColor = 'brown';//$('#' + servername).data('color');// || (!$box.hasClass('infobox-dark') ? $box.css('color') : 'rgba(255,255,255,0.95)');
$('#' + servername).data('easyPieChart').update(data.bat).options.barColor = '#3983C2'; $('#' + servername).data('easyPieChart').update(data.bat).options.barColor = '#3983C2';
} }
document.getElementById(servername + 'text').innerHTML = "BAT"; document.getElementById(servername + 'text').innerHTML = data.cat;
document.getElementById(servername + 't').innerHTML = data.bat + ""; document.getElementById(servername + 't').innerHTML = data.bat + "";
} }

View File

@@ -0,0 +1,26 @@
<div class="footer">
<div class="footer-inner">
<div class="footer-content">
<span class="bigger-120">
<span class="blue bolder">JCM</span>
Application &copy; 2013-9014
</span>
&nbsp; &nbsp;
<span class="action-buttons">
<a href="#">
<i class="ace-icon fa fa-twitter-square light-blue bigger-150"></i>
</a>
<a href="#">
<i class="ace-icon fa fa-facebook-square text-primary bigger-150"></i>
</a>
<a href="#">
<i class="ace-icon fa fa-rss-square orange bigger-150"></i>
</a>
</span>
</div>
</div>
</div>

View File

@@ -575,18 +575,29 @@
onSocketClose(e) { onSocketClose(e) {
console.log(`[ttyd] websocket connection closed with code: ${e.code}`); console.log(`[ttyd] websocket connection closed with code: ${e.code}`);
const {refreshToken: t, connect: i, doReconnect: s, overlayAddon: r} = this; const {refreshToken: t, connect: i, doReconnect: s, overlayAddon: r} = this;
if ("1" == null) if (/*r.showOverlay("Connection Closed"),*/
r.showOverlay("Reconnecting..."), this.dispose(),
t().then(i); 1e3 !== e.code && s){
else {
const {terminal: e} = this const {terminal: e} = this
, s = e.onKey(e=>{ , s = e.onKey(e=>{
"Enter" === e.domEvent.key && (s.dispose(), "Enter" === e.domEvent.key && (s.dispose(),
r.showOverlay("Reconnecting..."), r.showOverlay("Reconnecting..."),
t().then(i)) t().then(i))
} }
); );
r.showOverlay("Press ⏎ to Reconnect") //r.showOverlay("Press ⏎ to Reconnect")
this.writeData("Press ⏎ to Reconnect");
}
else {
const {terminal: e} = this
, s = e.onKey(e=>{
"Enter" === e.domEvent.key && (s.dispose(),
r.showOverlay("Reconnecting..."),
t().then(i))
}
);
//r.showOverlay("Press ⏎ to Reconnect")
this.writeData("Press ⏎ to Reconnect");
} }
} }
onSocketData(e) { onSocketData(e) {