s5启动文件配置
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
import pymysql
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
def add_days_to_table_fields(
|
||||||
|
conn_params: dict,
|
||||||
|
table_name: str,
|
||||||
|
days: int
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
为指定表的 end_time 和 end_time_unix 字段分别增加指定天数。
|
||||||
|
两个字段独立处理,end_time 为空时不改,end_time_unix 为空时也不改。
|
||||||
|
"""
|
||||||
|
# 连接数据库
|
||||||
|
conn = pymysql.connect(**conn_params)
|
||||||
|
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||||
|
|
||||||
|
# 查询整表需要的字段
|
||||||
|
cursor.execute(f"SELECT id, end_time, end_time_unix FROM {table_name}")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
count_end_time = 0
|
||||||
|
count_end_time_unix = 0
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
record_id = row["id"]
|
||||||
|
end_time_str = row.get("end_time")
|
||||||
|
end_time_unix_str = row.get("end_time_unix")
|
||||||
|
|
||||||
|
new_end_time = None
|
||||||
|
new_end_time_unix = None
|
||||||
|
|
||||||
|
# 1️⃣ 处理 end_time
|
||||||
|
if end_time_str:
|
||||||
|
try:
|
||||||
|
dt = datetime.strptime(end_time_str, "%Y-%m-%d %H:%M:%S")
|
||||||
|
new_dt = dt + timedelta(days=days)
|
||||||
|
new_end_time = new_dt.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
count_end_time += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[WARN] id={record_id} 的 end_time 无法解析: {end_time_str} ({e})")
|
||||||
|
|
||||||
|
# 2️⃣ 处理 end_time_unix
|
||||||
|
if end_time_unix_str and end_time_unix_str.isdigit():
|
||||||
|
try:
|
||||||
|
ts = int(end_time_unix_str)
|
||||||
|
new_ts = ts + days * 86400 # 1天=86400秒
|
||||||
|
new_end_time_unix = str(new_ts)
|
||||||
|
count_end_time_unix += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[WARN] id={record_id} 的 end_time_unix 无法解析: {end_time_unix_str} ({e})")
|
||||||
|
|
||||||
|
# 3️⃣ 如果有任意一个字段需要更新,则执行更新
|
||||||
|
if new_end_time or new_end_time_unix:
|
||||||
|
set_clauses = []
|
||||||
|
params = []
|
||||||
|
if new_end_time:
|
||||||
|
set_clauses.append("end_time=%s")
|
||||||
|
params.append(new_end_time)
|
||||||
|
if new_end_time_unix:
|
||||||
|
set_clauses.append("end_time_unix=%s")
|
||||||
|
params.append(new_end_time_unix)
|
||||||
|
params.append(record_id)
|
||||||
|
|
||||||
|
sql_update = f"UPDATE {table_name} SET {', '.join(set_clauses)} WHERE id=%s"
|
||||||
|
print(f'执行sql ===> {sql_update} 参数 ==> {params}')
|
||||||
|
cursor.execute(sql_update, params)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
print(f"✅ 更新完成:end_time {count_end_time} 条,end_time_unix {count_end_time_unix} 条。")
|
||||||
|
|
||||||
|
# 直接操作数据库,给全体用户增加有效天数
|
||||||
|
if __name__ == "__main__":
|
||||||
|
db_info = {
|
||||||
|
'host': '101.227.74.8',
|
||||||
|
'port': 3306,
|
||||||
|
'user': 'root',
|
||||||
|
'password': '9lYgSVPPDjh6sq2C',
|
||||||
|
"database": "ss2_migrated",
|
||||||
|
}
|
||||||
|
|
||||||
|
add_days_to_table_fields(db_info, "group_purchase_users", days=7)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
from proxy_line.write_file import writ_json_file
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
root_path= "/Users/leonbob/workspace/project/langtu/lt/jsq/server-setting/new"
|
||||||
|
# 目标起始 ip
|
||||||
|
target_ip = "172.16.0.11"
|
||||||
|
# 文件起始序号
|
||||||
|
sart_index_num = 161
|
||||||
|
# 起始监听端口号
|
||||||
|
start_listen_port = 5715
|
||||||
|
# 文件总数
|
||||||
|
file_total_count = 20
|
||||||
|
|
||||||
|
writ_json_file(root_path, sart_index_num, file_total_count, target_ip, start_listen_port)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# insert into ss2_migrated.ip_port_allocation ( ip_address, port, is_used, group_purchase_id, last_used_at, created_at, updated_at, max_connections, current_connections, type)
|
||||||
|
# values ( '103.6.221.91', 5663, 0, 0,now(), now(), now(), 1, 0, 'group_purchase')
|
||||||
|
if __name__ == '__main__':
|
||||||
|
line_count = 52
|
||||||
|
start_port = 5663
|
||||||
|
start_ip = '103.6.221.91'
|
||||||
|
print("insert into ss2_migrated.ip_port_allocation ( ip_address, port, is_used, group_purchase_id, last_used_at, created_at, updated_at, max_connections, current_connections, type) values ")
|
||||||
|
for i in range(0, line_count):
|
||||||
|
print(f" ( '{start_ip}', {start_port + i}, 0, 0,now(), now(), now(), 1, 0, 'group_purchase'),")
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from proxy_line.write_file import writ_json_file
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
root_path= "/Users/leonbob/workspace/project/langtu/lt/jsq/server-setting/new"
|
||||||
|
|
||||||
|
# 文件起始序号
|
||||||
|
sart_index_num = 101
|
||||||
|
# 起始监听端口号
|
||||||
|
start_listen_port = 5655
|
||||||
|
# 目标ip
|
||||||
|
target_ip = "10.0.0.2"
|
||||||
|
file_total_count = 60
|
||||||
|
|
||||||
|
writ_json_file(root_path, target_ip, sart_index_num, start_listen_port, file_total_count)
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
if __name__ == '__main__':
|
||||||
|
start_index = 161
|
||||||
|
end_index = 180
|
||||||
|
for i in range(start_index, end_index + 1):
|
||||||
|
print(f"nohup ./forward -c {i}.json > {i}.log 2>&1 &")
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
|
def generate_commands(start_port, start_subnet, start_ip, count):
|
||||||
|
ip = ipaddress.ip_address(start_ip)
|
||||||
|
commands = []
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
port = start_port + i
|
||||||
|
subnet_num = 65 + i # 从 10.65.0.0/16 开始
|
||||||
|
subnet = f"10.{subnet_num}.0.0/16"
|
||||||
|
gateway = f"10.{subnet_num}.0.1"
|
||||||
|
use_ip = str(ip + i)
|
||||||
|
|
||||||
|
cmd = (f"nohup ./s5_multi_1.0.1 -listen \"{port}={use_ip}\" "
|
||||||
|
f"-report=true "
|
||||||
|
f"> /root/socket5_1.0.1/{port}.log 2>&1 &")
|
||||||
|
commands.append(cmd)
|
||||||
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 参数配置
|
||||||
|
START_PORT = 25715
|
||||||
|
START_IP = "45.86.235.163"
|
||||||
|
COUNT = 20
|
||||||
|
|
||||||
|
cmds = generate_commands(START_PORT, 65, START_IP, COUNT)
|
||||||
|
for c in cmds:
|
||||||
|
print(c)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
|
def generate_commands(start_port, start_subnet, start_ip, count):
|
||||||
|
ip = ipaddress.ip_address(start_ip)
|
||||||
|
commands = []
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
port = start_port + i
|
||||||
|
subnet_num = 65 + i # 从 10.65.0.0/16 开始
|
||||||
|
subnet = f"10.{subnet_num}.0.0/16"
|
||||||
|
gateway = f"10.{subnet_num}.0.1"
|
||||||
|
use_ip = str(ip + i)
|
||||||
|
|
||||||
|
cmd = (f"nohup /root/server_tun/server --port {port} "
|
||||||
|
f"--subnet {subnet} "
|
||||||
|
f"--gateway {gateway} "
|
||||||
|
f"--use-ip {use_ip} "
|
||||||
|
f"> /root/server_tun/{port}.log 2>&1 &")
|
||||||
|
commands.append(cmd)
|
||||||
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 参数配置
|
||||||
|
START_PORT = 5715
|
||||||
|
START_IP = "45.86.235.163"
|
||||||
|
COUNT = 20
|
||||||
|
|
||||||
|
cmds = generate_commands(START_PORT, 65, START_IP, COUNT)
|
||||||
|
for c in cmds:
|
||||||
|
print(c)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
start_index = 5555
|
||||||
|
end_index = 5734
|
||||||
|
start_ip_subfix = 3
|
||||||
|
for index,item in enumerate(range(start_index, end_index + 1)):
|
||||||
|
print('START TRANSACTION;')
|
||||||
|
print(f"UPDATE port_keys SET out_ip = '45.86.235.{start_ip_subfix + index}' WHERE `port` = {item};")
|
||||||
|
print('COMMIT;')
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
def writ_json_file(root_folder_path,sart_index_num, file_total_count,target_ip,start_listen_port) :
|
||||||
|
for i,v in enumerate(range(sart_index_num, sart_index_num + file_total_count)):
|
||||||
|
# 定义一个json
|
||||||
|
port = str(start_listen_port + i)
|
||||||
|
target = target_ip + ":" + port
|
||||||
|
json_config = {
|
||||||
|
"server": target,
|
||||||
|
"port": ":"+ port,
|
||||||
|
}
|
||||||
|
print(json_config)
|
||||||
|
# 写对应文件
|
||||||
|
with open(f'{root_folder_path}/{v}.json', 'w', encoding='utf-8') as json_file:
|
||||||
|
json.dump(json_config, json_file, indent=4)
|
||||||
Reference in New Issue
Block a user