废除s2f

This commit is contained in:
CSSC-WORK\murmur 2024-01-25 10:25:08 +08:00
parent 0c594af127
commit 3467a48070
5 changed files with 40 additions and 31 deletions

2
readme.txt Normal file
View File

@ -0,0 +1,2 @@
批量删除命令
ps aux | grep './restart.sh' | grep -v grep | awk '{print $2}' | xargs kill -9

View File

@ -3,13 +3,13 @@
while true; do
monitor=$(ps -ef | grep "./server.py" | grep -v grep | wc -l)
cur_dateTime=$(date +%Y-%m-%d_%H-%M-%s)
# cur_dateTime=$(date +%Y-%m-%d_%H-%M-%s)
if [ $monitor -eq 0 ]; then
echo $cur_dateTime" --- ./server.py program is not running, restart now"
# cd ~/tt/tt-tcp
#if= "./log-"$cur_dateTime".txt"
# f="./log-"${cur_dateTime}".txt"
mv "./rxlog.txt" "rxlog/rxlog-"${cur_dateTime}".txt"
# mv "./rxlog.txt" "rxlog/rxlog-"${cur_dateTime}".txt"
#cd /root/tt/tt-tcp
#mv rxlog.txt "./rxlog-"$cur_dateTime".txt"
# nohup python3 -u ./server.py >>$f 2>&1 &

View File

@ -13,13 +13,13 @@ kill_with_pid() {
kill_with_pid
echo "Now run new service."
#
cur_dateTime=$(date +%Y-%m-%d_%H-%M)
# cur_dateTime=$(date +%Y-%m-%d_%H-%M)
#cur_dateTime=$(date +%Y-%m-%d_%H-%m-%s)
echo ${cur_dateTime}
# echo ${cur_dateTime}
# cd ~/tt-tcp
#mv log.txt "./log-"${cur_dateTime}".txt"
# f="./log-"${cur_dateTime}".txt"
mv rxlog.txt "rxlog/rxlog-"${cur_dateTime}".txt"
# mv rxlog.txt "rxlog/rxlog-"${cur_dateTime}".txt"
nohup python3 -u ./server.py &
#nohup ./restart.sh &
nohup ./restart.sh >> reboot.log &

19
s2f.py
View File

@ -1,19 +0,0 @@
import datetime
import os
def gettm():
t= datetime.datetime.now()
d = str(t)
return d,d[:10]
def save2file(data,isR=1):
# pass
t,d = gettm()
p = '/'.join(['trlog',d])
if not os.path.exists(p):
os.makedirs(p)
l=f"{'[R]' if isR else '[T]'} - {t} --- {data}\n"
f=open('/'.join(['trlog',d,'trlog.txt']),'a')
f.write(l)
f.close

View File

@ -10,10 +10,36 @@ import requests
import socket
# import json
from threading import Timer
import s2f
from loguru import logger
import os
def gettm():
"""
返回时戳和日期
"""
t= datetime.datetime.now()
d = str(t)
return d,d[:10]
def save2file(data,isR=1):
"""
存储数据至文件
"""
t,d = gettm()
p = '/'.join(['trlog',d])
if not os.path.exists(p):
os.makedirs(p)
l=f"{'[R]' if isR else '[T]'} - {t} --- {data}\n"
f=open('/'.join(['trlog',d,'trlog.txt']),'a')
f.write(l)
f.close
SERVER = "http://www.pushplus.plus/send"
TOKEN = "ff328cba923a4225bc4acd0086a9014c"
# SERVER = "http://push.nmhd.eu.org:12722/push/murmur"
@ -273,7 +299,7 @@ def tt_hh(addr, data):
# 组帧再返回
msg = bytearray(data[:])
msg[:5] = b"$TTMX"
val = "%04x" % int(time.time())
val = "%04x" % int(time.time()) #取Unix时间戳以s为单位
tmp=[]
for i in range(0,len(val),2):
tmp.append(int(val[i:i+2],16))
@ -285,7 +311,7 @@ def tt_hh(addr, data):
msg[-1] = crc
add_timestamp()
addr.send(msg)
s2f.save2file(f"[SERVER --> {get_ccid(addr).decode() if get_ccid(addr) else 'None'}][{len(msg)}] {msg.hex(' ')}",0)
save2file(f"[SERVER --> {get_ccid(addr).decode() if get_ccid(addr) else 'None'}][{len(msg)}] {msg.hex(' ')}",0)
logger.debug("服务器回复心跳包。")
# 从缓存中匹配到数据才重发
@ -300,7 +326,7 @@ def tt_hh(addr, data):
add_timestamp()
# 按缓存先后顺序发送
addr.send(msgs[i])
s2f.save2file(f"[SERVER --> {get_ccid(addr).decode() if get_ccid(addr) else 'None'}][{len(msg)}] {msg.hex(' ')}")
save2file(f"[SERVER --> {get_ccid(addr).decode() if get_ccid(addr) else 'None'}][{len(msg)}] {msg.hex(' ')}")
time.sleep(1)
# 成功则清空已发送成功的缓存数据
cache[ccid].pop(0)
@ -378,7 +404,7 @@ def tt_trans(addr, data):
try:
add_timestamp()
taddr.send(msg)
s2f.save2file(f"[SERVER --> {get_ccid(taddr).decode() if get_ccid(taddr) else 'None'}][{len(msg)}] {msg.hex(' ')}",0)
save2file(f"[SERVER --> {get_ccid(taddr).decode() if get_ccid(taddr) else 'None'}][{len(msg)}] {msg.hex(' ')}",0)
logger.info(f"数据发送成功。 {sccid} --> {tccid}")
s2wx("","",f"匹配到在线终端, 数据发送成功。 \n{sccid.decode()} ---> {tccid.decode()}")
except Exception:
@ -512,7 +538,7 @@ class MyServer(socketserver.BaseRequestHandler):
add_timestamp()
self.recDataBuff.extend(data)
# logger.debug("[R] {}",data.hex(" "))
s2f.save2file(f"[{get_ccid(conn).decode() if get_ccid(conn) else 'None'} --> SERVER][{len(data)}] {data.hex(' ')}")
save2file(f"[{get_ccid(conn).decode() if get_ccid(conn) else 'None'} --> SERVER][{len(data)}] {data.hex(' ')}")
t = f"{str(self.client_address)}<->[{get_ccid(conn).decode() if get_ccid(conn) else 'None'}]接收到新数据,长度{len(data)}字节。"
logger.info(t)
logger.debug("[R] - {}",data.hex(" "))
@ -548,7 +574,7 @@ CCID:{pp[self.request].decode()}
if __name__ == "__main__":
_,t = s2f.gettm()
_,t = gettm()
if not os.path.exists('debug'):
os.mkdir('debug')
logger.add('/'.join(['debug',t,'/log_{time}.log']))