-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtorctl.lib
More file actions
executable file
·173 lines (143 loc) · 4.49 KB
/
torctl.lib
File metadata and controls
executable file
·173 lines (143 loc) · 4.49 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
#
# ############################################################################
# Project: torctl (none)
# File...: torctl.lib
# Created: Tuesday, 2022/11/29 - 20:46:56
# Author.: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Saturday, 2025/08/02 - 09:23:56
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.0.4.451
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
_xLIB_TORCTL_=true
# define app directory
APP_DIR=$(dirname "$0")
# if executing out of $PATH system (./torctl), redifine APP_DIR
[ "$APP_DIR" == "." ] && cd "$PWD" && APP_DIR=$PWD
# function to load FW rules
firewall_load_rules(){
case "$(xsys.os)" in
Linux )
source "$APP_DIR/config/fw-up-linux.sh"
source "$APP_DIR/config/fw-down-linux.sh"
;;
Darwin)
source "$APP_DIR/config/fw-up-darwin.sh"
source "$APP_DIR/config/fw-down-darwin.sh"
;;
esac
}
# get current IP Address
current_ip(){
curl --silent ifconfig.me
}
# get geo information of current ip address
ip_geo_information(){
curl --silent http://ip-api.com/json/"$(current_ip)"
}
# function to start TOR SERVER
start_tor_server(){
# start tor server with docker
docker run --rm -d --net host \
-v "$APP_DIR"/torctl.rc:/etc/tor/torrc \
-v "$APP_DIR"/torctl.resolv.conf:/etc/resolv.conf \
--entrypoint "" \
--name torctl_server \
m88v2/tor-server:latest \
/bin/sh -c 'tor -f /etc/tor/torrc' &> /dev/null
}
# setup firewall rules to host use 'tor_server'
firewall_up(){
# load rules based on the current OS
firewall_load_rules
# test current OS and apply rules
case "$(xsys.os)" in
Linux ) fwLinuxUp ;;
Darwin) fwDarwinUp ;;
esac
}
# restore default rules or setup a clear firewall
firewall_down(){
# load rules based on the current OS
firewall_load_rules
# test current OS and apply rules
case "$(xsys.os)" in
Linux ) fwLinuxDown ;;
Darwin) fwDarwinDown ;;
esac
}
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
# script actions
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
actionStart(){
# require ROOT to run
requireROOT
local title="-> Starting Tor Server"
local msg=""
echo "$title"
if start_tor_server; then
echo "-> setting up iptables rules"
firewall_up
echo '-> Fetching current IP...'
sleep 2
tor_ip="$(current_ip)"
echo "-> CURRENT IP: $tor_ip"
# set variables for notification
title="torctl started"
msg="this is your current IP ($tor_ip)"
# call system function for notification
xsys.notify "$title" "$msg"
else
msg="(check your docker service)"
title="-> fail to start server..."
echo "$title $msg"
xsys.notify "torctl started" "$msg"
exit 2
fi
}
actionStop(){
# require ROOT to run
requireROOT
local title="-> Stopping Tor Server"
local msg=""
echo "$title"
echo "$title"
docker stop torctl_server &> /dev/null
echo "-> clear firewall rules"
firewall_down
tor_ip="$(current_ip)"
echo "-> CURRENT IP: $tor_ip"
title="torctl stoped"
msg="using again your provider IP ($tor_ip)"
# sys.notify "torctl stoped" "using again yout provider IP $tor_ip"
xsys.notify "$title" "$msg"
}
actionStatus(){
local title="torctl status"
local msg=''
# check if TorServer is running via docker
if docker ps | grep torctl &> /dev/null; then
msg="-> Tor Server is RUNNING..."
else
msg="-> Tor Server is NOT RUNNING"
fi
echo "$msg"
tor_ip="$(current_ip)"
msg+=" (IP: $tor_ip)"
echo "-> CURRENT IP: ${tor_ip}..."
echo "-> Details: (IP Geo Information)"
# sys.notify "torctl status" "$msg - IP: $(current_ip)"
xsys.notify "${title}" "$(echo ${msg/->/})"
ip_geo_information | jq
}
actionRestart(){
actionStop
actionStart
}