完善文档和配置流程
This commit is contained in:
33
README.md
33
README.md
@@ -1,8 +1,29 @@
|
|||||||
|
ros 批量配置脚本
|
||||||
|
|
||||||
|
## 项目说明
|
||||||
|
|
||||||
|
这是一个半自动的批量配置脚本,用于按需批量配置 ros 服务,目前适用于极狐与极光的配置
|
||||||
|
|
||||||
|
脚本通过 ssl 方式连接到 ros 服务,在使用前需要下载 ros 的证书到 certs 目录下
|
||||||
|
|
||||||
|
**项目结构**
|
||||||
|
```
|
||||||
|
ros
|
||||||
|
├── certs ros 服务的证书,在配置 csv 中 cert 列的根目录是这里
|
||||||
|
├── scripts ros 服务中的脚本,在配置脚本时会读取并写入 ros 配置
|
||||||
|
├── templates ros 服务的模板镜像
|
||||||
|
├── config.jh.bak.csv 极狐的配置参考表
|
||||||
|
├── config.jg.bak.csv 极光的配置参考表
|
||||||
|
├── config.csv 需要执行配置的表
|
||||||
|
├── steps.py 所有配置函数
|
||||||
|
└── main.py 主程序,执行 `steps.py` 中的配置函数
|
||||||
|
```
|
||||||
|
|
||||||
## 使用说明
|
## 使用说明
|
||||||
|
|
||||||
一、上传 ros 镜像,位置在 `templates` 目录下
|
1. 上传 ros 镜像,位置在 `templates` 目录下
|
||||||
|
|
||||||
二、为 ros 配置公网 IP 与网关,并重置 mac 地址
|
2. 为 ros 配置公网 IP 与网关,并重置 mac 地址
|
||||||
|
|
||||||
```
|
```
|
||||||
/ip/address/set 0 address=公网地址/掩码
|
/ip/address/set 0 address=公网地址/掩码
|
||||||
@@ -10,9 +31,13 @@
|
|||||||
/interface/ethernet/reset-mac-address wan
|
/interface/ethernet/reset-mac-address wan
|
||||||
```
|
```
|
||||||
|
|
||||||
三、将需要部署的 ros 配置条目从 `config.bak.csv` 中复制到 `config.csv`
|
3. 将需要部署的 ros 配置条目从 `config.jh.bak.csv` 或 `config.jg.bak.csv` 中复制到 `config.csv`(没有的话创建一个)
|
||||||
|
|
||||||
四、执行 `main.py`
|
> `config.jh.bak.csv` 与 `config.jg.bak.csv` 中是所有 ros 配置项的完整记录
|
||||||
|
|
||||||
|
4. 检查并按需调整 `main.py` 脚本开头定义的参数
|
||||||
|
|
||||||
|
5. 执行 `main.py`
|
||||||
|
|
||||||
## 部署流程
|
## 部署流程
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
index,name,code,gateway,public,mask,private,domain,cert
|
index,name,code,gateway,public,mask,private,domain,cert
|
||||||
0,混拨1,hh1,43.226.58.1,43.226.58.7,24,192.168.98.3,hh,jh/7.crt
|
1,混拨2,hh2,43.226.58.1,43.226.58.8,24,192.168.98.2,hh,jh/8.crt
|
||||||
0,混拨2,hh2,43.226.58.1,43.226.58.8,24,192.168.98.2,hh,server.crt
|
2,混拨3,hh3,43.226.58.1,43.226.58.7,24,192.168.98.3,hh,jh/7.crt
|
||||||
1,宣城,ahxc215,43.226.58.1,43.226.58.10,24,192.168.99.1,ahxc,jh/10.crt
|
1,宣城,ahxc215,43.226.58.1,43.226.58.10,24,192.168.99.1,ahxc,jh/10.crt
|
||||||
2,宿州,ahsz216,43.226.58.1,43.226.58.11,24,192.168.99.2,ahsz,jh/11.crt
|
2,宿州,ahsz216,43.226.58.1,43.226.58.11,24,192.168.99.2,ahsz,jh/11.crt
|
||||||
3,阜阳,ahfy225,43.226.58.1,43.226.58.12,24,192.168.99.3,ahfy,jh/12.crt
|
3,阜阳,ahfy225,43.226.58.1,43.226.58.12,24,192.168.99.3,ahfy,jh/12.crt
|
||||||
|
|||||||
|
18
main.py
18
main.py
@@ -21,24 +21,22 @@ pip install librouteros
|
|||||||
- public: 公网 IP
|
- public: 公网 IP
|
||||||
- mask: 公网子网掩码
|
- mask: 公网子网掩码
|
||||||
- private: 内网 IP
|
- private: 内网 IP
|
||||||
|
- domain: 节点域名
|
||||||
|
- cert: 证书文件路径
|
||||||
|
|
||||||
如果需要添加或修改配置项,从 config.*.bak.csv 文件复制配置项到 config.csv 文件中
|
如果需要添加或修改配置项,修改 config.*.bak.csv 文件,并复制配置项到 config.csv 文件中
|
||||||
|
|
||||||
如果需要修改配置内容,在下面 “配置执行步骤” 部分添加或修改函数调用
|
如果需要修改配置内容,在下面 “配置执行步骤” 部分添加或修改函数调用
|
||||||
"""
|
"""
|
||||||
|
|
||||||
threads = []
|
|
||||||
failed = []
|
|
||||||
|
|
||||||
# 配置执行步骤
|
# 配置执行步骤
|
||||||
steps = [
|
steps = [
|
||||||
configNet,
|
configJgOuts,
|
||||||
configJgAuth,
|
|
||||||
configJgMixOuts,
|
|
||||||
configJgScripts,
|
|
||||||
configJgLogs,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
threads = []
|
||||||
|
failed = []
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# 加载配置文件
|
# 加载配置文件
|
||||||
@@ -81,7 +79,7 @@ def start(config):
|
|||||||
try:
|
try:
|
||||||
ctx = ssl.create_default_context()
|
ctx = ssl.create_default_context()
|
||||||
ctx.check_hostname = False
|
ctx.check_hostname = False
|
||||||
ctx.load_verify_locations(f'certs/{config["cert"]}')
|
ctx.load_verify_locations(f"certs/{config['cert']}")
|
||||||
conn = connect(
|
conn = connect(
|
||||||
username="admin",
|
username="admin",
|
||||||
password="wyongk9815",
|
password="wyongk9815",
|
||||||
|
|||||||
39
steps.py
39
steps.py
@@ -120,6 +120,7 @@ def configJhMixOuts(conn: Api, config):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError("删除 PPP 失败: {}".format(e))
|
raise RuntimeError("删除 PPP 失败: {}".format(e))
|
||||||
|
|
||||||
|
index = (int(config["index"]) - 1) * 10
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
for j in range(10):
|
for j in range(10):
|
||||||
n = j * 30 + i
|
n = j * 30 + i
|
||||||
@@ -129,7 +130,7 @@ def configJhMixOuts(conn: Api, config):
|
|||||||
**{
|
**{
|
||||||
"name": f"l2tp-out{n + 1}",
|
"name": f"l2tp-out{n + 1}",
|
||||||
"connect-to": f"192.168.25{k}.25{k}",
|
"connect-to": f"192.168.25{k}.25{k}",
|
||||||
"user": f"jdzz{j+11}dt{i+221}",
|
"user": f"jdzz{j + 1 + index}dt{i + 221}",
|
||||||
"password": "123231",
|
"password": "123231",
|
||||||
"disabled": "no",
|
"disabled": "no",
|
||||||
}
|
}
|
||||||
@@ -355,7 +356,7 @@ def configJhDrop(conn: Api, config):
|
|||||||
layer7.add(
|
layer7.add(
|
||||||
**{
|
**{
|
||||||
"name": "illegal",
|
"name": "illegal",
|
||||||
"regexp": f'({"|".join([re.escape(domain) for domain in domains])})[/:]?.*',
|
"regexp": f"({'|'.join([re.escape(domain) for domain in domains])})[/:]?.*",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -425,7 +426,7 @@ def configJgAuth(conn: Api, config):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
l2tp = conn.path("interface", "l2tp-server", "server")
|
l2tp = conn.path("interface", "l2tp-server", "server")
|
||||||
l2tp.update(**{"enabled": "yes", "use-ipsec": "yes", "ipsec-secret": "byjd231"})
|
l2tp.update(**{"enabled": "yes", "use-ipsec": "yes", "ipsec-secret": "1234"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f"配置 l2tp 服务器失败: {e}")
|
raise RuntimeError(f"配置 l2tp 服务器失败: {e}")
|
||||||
|
|
||||||
@@ -451,7 +452,8 @@ def configJgOuts(conn: Api, config):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
count = 20
|
count = 10
|
||||||
|
window = 20
|
||||||
|
|
||||||
# 配置 ppp
|
# 配置 ppp
|
||||||
try:
|
try:
|
||||||
@@ -469,7 +471,7 @@ def configJgOuts(conn: Api, config):
|
|||||||
**{
|
**{
|
||||||
"name": f"l2tp-out{i}",
|
"name": f"l2tp-out{i}",
|
||||||
"connect-to": f"192.168.0.{int(config['gate']) + 1}",
|
"connect-to": f"192.168.0.{int(config['gate']) + 1}",
|
||||||
"user": f"bydj{config['gate']}api{(int(config['index'])-1) * count + i}",
|
"user": f"byjd{config['gate']}api{(int(config['index']) - 1) * window + i}",
|
||||||
"password": "byjd231",
|
"password": "byjd231",
|
||||||
"disabled": "no",
|
"disabled": "no",
|
||||||
}
|
}
|
||||||
@@ -529,7 +531,7 @@ def configJgMixOuts(conn: Api, config):
|
|||||||
**{
|
**{
|
||||||
"name": f"l2tp-out{i}",
|
"name": f"l2tp-out{i}",
|
||||||
"connect-to": f"192.168.0.{int(config['gate']) + 1}",
|
"connect-to": f"192.168.0.{int(config['gate']) + 1}",
|
||||||
"user": f"bydj{config['gate']}api{(int(config['index'])-1) * count + i}",
|
"user": f"byjd{config['gate']}api{(int(config['index']) - 1) * count + i}",
|
||||||
"password": "byjd231",
|
"password": "byjd231",
|
||||||
"disabled": "no",
|
"disabled": "no",
|
||||||
}
|
}
|
||||||
@@ -737,3 +739,28 @@ def configJgLogs(conn: Api, config):
|
|||||||
# ====================
|
# ====================
|
||||||
# 临时
|
# 临时
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
|
|
||||||
|
def temp(conn: Api, config):
|
||||||
|
ppps = conn.path("interface", "l2tp-client")
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for ppp in ppps:
|
||||||
|
count += 1
|
||||||
|
if ppp["name"].startswith("l2tp-out") and ppp["running"] != True:
|
||||||
|
break
|
||||||
|
|
||||||
|
if count < 20:
|
||||||
|
raise RuntimeError(f"有未运行的 PPP,count={count}")
|
||||||
|
|
||||||
|
# file = open(f"outs/{config['code']}.csv", "w", encoding="utf-8")
|
||||||
|
# file.write("ros,name,connect-to,user,running\n")
|
||||||
|
# for ppp in ppps:
|
||||||
|
# file.write("{},{},{},{},{}\n".format(
|
||||||
|
# config["name"],
|
||||||
|
# ppp["name"],
|
||||||
|
# ppp["connect-to"],
|
||||||
|
# ppp["user"],
|
||||||
|
# ppp["running"],
|
||||||
|
# ))
|
||||||
|
# file.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user