-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraTLS.sh
More file actions
144 lines (117 loc) · 5.23 KB
/
Copy pathraTLS.sh
File metadata and controls
144 lines (117 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
echo "in porose config haye rathole shoma ra be rathole+tls tabdil khahad kard, edame midahid?"
echo "baraye edame adade 1 ra vared konid"
read -r choice
if [ "$choice" == "1" ]; then
if [ -d "/etc/rathole" ]; then
echo "Downloading tls.zip..."
curl -L -o /etc/rathole/tls.zip https://github.com/edthepurple/JanSakht/raw/refs/heads/main/tls.zip
echo "Extracting tls.zip..."
unzip -o /etc/rathole/tls.zip -d /etc/rathole
echo "Cleaning up..."
rm /etc/rathole/tls.zip
# Find all .toml config files
config_files=$(find /etc/rathole -maxdepth 1 -type f -name "*.toml")
if [ -z "$config_files" ]; then
echo "No .toml config files found in /etc/rathole."
exit 1
fi
echo "Found the following .toml files:"
echo "$config_files"
echo ""
# Process each config file
while IFS= read -r config_file; do
echo "Processing: $config_file"
first_line=$(head -n 1 "$config_file")
if [[ "$first_line" == "[client]" ]]; then
echo "Client config detected. Modifying transport..."
sed -i '/^\[client\.transport\.[^]]*\]/d' "$config_file"
sed -i '/^\[client\.transport\]/,/^\[.*\]/{
/^\[client\.transport\]/!{
/^\[.*\]/!d
}
}' "$config_file"
if ! grep -q "^\[client\.transport\]" "$config_file"; then
echo -e "\n[client.transport]" >> "$config_file"
fi
sed -i '/^\[client\.transport\]/,/^\[.*\]/{
/^\s*type\s*=/d
}' "$config_file"
sed -i '/^\[client\.transport\]/a type = "tls"' "$config_file"
# Insert [client.transport.tls] block directly after [client.transport]
awk '
BEGIN { inserted = 0 }
/^\[client\.transport\]/ {
print
while (getline) {
if ($0 ~ /^\[.*\]/) {
if (!inserted) {
print ""
print "[client.transport.tls]"
print "trusted_root = \"/etc/rathole/rootCA.crt\""
print "hostname = \"localhost\""
print ""
inserted = 1
}
print
} else {
print
}
}
exit
}
{ print }
' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
echo "TLS settings applied to client config: $config_file"
elif [[ "$first_line" == "[server]" ]]; then
echo "Server config detected. Modifying transport..."
sed -i '/^\[server\.transport\.[^]]*\]/d' "$config_file"
sed -i '/^\[server\.transport\]/,/^\[.*\]/{
/^\[server\.transport\]/!{
/^\[.*\]/!d
}
}' "$config_file"
if ! grep -q "^\[server\.transport\]" "$config_file"; then
echo -e "\n[server.transport]" >> "$config_file"
fi
sed -i '/^\[server\.transport\]/,/^\[.*\]/{
/^\s*type\s*=/d
}' "$config_file"
sed -i '/^\[server\.transport\]/a type = "tls"' "$config_file"
# Insert [server.transport.tls] block directly after [server.transport]
awk '
BEGIN { inserted = 0 }
/^\[server\.transport\]/ {
print
while (getline) {
if ($0 ~ /^\[.*\]/) {
if (!inserted) {
print ""
print "[server.transport.tls]"
print "pkcs12 = \"/etc/rathole/identity.pfx\""
print "pkcs12_password = \"1234\""
print ""
inserted = 1
}
print
} else {
print
}
}
exit
}
{ print }
' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
echo "TLS settings applied to server config: $config_file"
else
echo "Config $config_file is not a valid [client] or [server] file. No changes made."
fi
echo ""
done <<< "$config_files"
echo "Done processing all .toml files."
else
echo "rathole dar /etc/rathole nasb nist"
fi
else
echo "Operation cancelled."
fi