-
Notifications
You must be signed in to change notification settings - Fork 2
/
onionservice-tui
executable file
·589 lines (523 loc) · 25.6 KB
/
onionservice-tui
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
#!/usr/bin/env sh
## This file is part of OnionService, an easy to use Tor hidden services manager.
##
## Copyright (C) 2021 OnionService developers (GPLv3)
## Github: https://github.com/nyxnor/onionservice
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it is useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
## DESCRIPTION
## This file lets you manage your authorized clients for hidden services
## It is a TUI for the onionservice-cli with everything integrated in this menu
##
## SYNTAX
## sh onionservice-tui
##
## Lines that begin with "## " try to explain what's going on. Lines
## that begin with just "#" are disabled commands.
[ -n "${ONIONSERVICE_PWD}" ] || { printf "\033[1;31mERROR: \${ONIONSERVICE_PWD} needs to be exported first!\033[0m\nRun: ./setup.sh\n"; exit 1; }
. "${ONIONSERVICE_PWD}"/.onionrc
## default values
i=0
###########################
######## FUNCTIONS ########
## clear is not a posix command
clear_posix(){
printf \\033[2J\\033[H\\033[m
}
trap 'clear_posix' EXIT
## $1 [checklist|menu]
## $2 complementary title
service_menu(){
DIALOG_TYPE="${1}"
COMPL_TITLE="${2}"
for SERVICE in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/); do
i=$((i+1))
ONION_HOSTNAME="$(sudo -u "${TOR_USER}" grep -s ".onion" "${DATA_DIR_SERVICES}"/"${SERVICE}"/hostname)"
ONION_HOSTNAME_WITHOUT_ONION=${ONION_HOSTNAME%.onion}
case "${DIALOG_TYPE}" in
checklist) SERVICE_LIST="$(printf "%s\n%s\n%s\n%s\n" "${SERVICE_LIST}" "${SERVICE}" "${ONION_HOSTNAME_WITHOUT_ONION}" 0)";;
menu) SERVICE_LIST="$(printf "%s\n%s\n%s\n" "${SERVICE_LIST}" "${SERVICE}" "${ONION_HOSTNAME_WITHOUT_ONION}")";;
esac
done
if [ -n "${SERVICE_LIST}" ]; then
TITLE="Onion Services - ${COMPL_TITLE}"
MENU="\nUse spacebar to select"
# shellcheck disable=SC2086
CHOICE_SERVICE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" --"${DIALOG_TYPE}" "${MENU}" \
"$((i+8))" 80 2 ${SERVICE_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_SERVICE}" ] && SERVICE_NAME_LIST="$(printf %s"${CHOICE_SERVICE}" | sed "s/ /,/g")"
fi
}
###########################
TITLE="Onion Services - Main Menu"
MENU="\nUse spacepar to select:"
BACKTITLE="Onion Services Manager"
if [ -z "$(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/)" ]; then
CHOICE_MAIN="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --no-cancel --menu "${MENU}" 16 80 2 \
"MAN" "Manual pages for the onionservice-cli" \
"GUIDES" "Markdown guides by Tor Project Organization and Riseup" \
"ENABLE" "Enable a onion service" \
"AUTH_CLIENT" "Manage your client keys of remote service" \
"VANGUARDS" "Add to protect against traffic analysis" \
"IMPORT" "Import backup from another machine" \
"QUIT" "Exit menu to the terminal" \
2>&1 >/dev/tty)"
else
CHOICE_MAIN="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --no-cancel --menu "${MENU}" 22 80 2 \
"MAN" "Manual pages for the onionservice-cli" \
"GUIDES" "Markdown guides by Tor Project Organization and Riseup" \
"ENABLE" "Enable a onion service" \
"DISABLE" "Disable chosen onion service" \
"RENEW" "Renew onion service address" \
"AUTH_SERVER" "Add or Remove client authorization from your service" \
"AUTH_CLIENT" "Manage your client keys of remote service" \
"CREDENTIALS" "See credentials (onion address, authorized clients)" \
"WEB_SERVER" "Serve a website folder on onion domain" \
"VANGUARDS" "Add to protect against traffic analysis" \
"LOCATION" "Guided steps to add onion-location to your plainnet website" \
"IMPORT" "Import backup from another machine" \
"EXPORT" "Export backup to another machine" \
"QUIT" "Exit menu to the terminal" \
2>&1 >/dev/tty)"
fi
case "${CHOICE_MAIN}" in
MAN) man onionservice-cli;;
GUIDES)
i=0
for MD in "${ONIONSERVICE_PWD}"/docs/*.md; do
i=$((i+1))
MD_LIST="$(printf "%s\n%s\n%s\n" "${MD_LIST}" "${MD##*/}" ".")"
done
TITLE="Markdown guides"
MENU="Select a guide:"
# shellcheck disable=SC2086
CHOICE_MD="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--menu "${MENU}" "$((i+7))" 50 10 ${MD_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_MD}" ] && { pandoc "${ONIONSERVICE_PWD}"/docs/"${CHOICE_MD}" | lynx -stdin ; }
;;
ENABLE)
TITLE="Onion Service - Activation"
MENU="Choose socket type:"
SOCKET_CHOICE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--menu "${MENU}" 9 70 8 \
"UNIX" "unix:path (more secure)" \
"TCP" "addr:port (leak onion address to the local network)" \
3>&1 1>&2 2>&3)"
SERVICE_MSG="\nName your service directory in one string and no space.\n(e.g.: torbox.ch)"
UNIX_PORT_MSG="\nYou are able to configure up to two virtual ports. Insert them separated by space. (e.g.: 80 443)"
TCP_PORT_MSG="\nYou are able to configure up to two virtual ports and targets, being only one virtual port required to create a service.
\nInsert them separated by space in the following order:\nVIRPORT TARGET VIRTPORT2 TARGET2\n(e.g.: 80 5000 443 5001) (e.g.: 80 192.168.5.10:5000 443 192.168.5.10:5001)"
case "${SOCKET_CHOICE}" in
UNIX)
SERVICE_NAME="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${SERVICE_MSG}" 10 60 3>&1 1>&2 2>&3)"
if [ -n "${SERVICE_NAME}" ]; then
SERVICE_PORTS="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${UNIX_PORT_MSG}" 10 60 3>&1 1>&2 2>&3)"
if [ -n "${SERVICE_PORTS}" ]; then
clear_posix
# shellcheck disable=SC2086
"${ONIONSERVICE_PWD}"/onionservice-cli on unix 3 "${SERVICE_NAME}" ${SERVICE_PORTS}
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
TCP)
SERVICE_NAME="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${SERVICE_MSG}" 10 60 3>&1 1>&2 2>&3)"
if [ -n "${SERVICE_NAME}" ]; then
SERVICE_PORTS="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${TCP_PORT_MSG}" 13 80 3>&1 1>&2 2>&3)"
if [ -n "${SERVICE_PORTS}" ]; then
# shellcheck disable=SC2086
"${ONIONSERVICE_PWD}"/onionservice-cli on tcp 3 "${SERVICE_NAME}" ${SERVICE_PORTS}
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
esac
;;
## improve this, not ctrl+c thing to cancel, it must be a menu option to return to the main menu
DISABLE)
service_menu checklist "Disable"
if [ -n "${SERVICE_NAME_LIST}" ]; then
TITLE="Onion Service - Deactivation"
MENU="\nWould you also like to DELETE (purge) the HiddenServiceDir?\n\nYES: All the directory data, including hidden service keys and clients will be deleted permanently (you won't be able to use the same onion address).\n\nNO (default): Service will be disabled, lines from the torrc deleted but the folder will be kept.\n\nCtrl+C to cancel deactivation (neither option)"
if CHOICE_PURGE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--defaultno --yesno "${MENU}" 15 80 2>&1 >/dev/tty)"; then CHOICE_PURGE="purge"; fi
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli off "${SERVICE_NAME_LIST}" "${CHOICE_PURGE}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
RENEW)
service_menu checklist "Renew"
if [ -n "${SERVICE_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli renew "${SERVICE_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2
read -r confirmation
fi
;;
AUTH_SERVER)
TITLE="Client Authorization - Server"
MENU="\nAs the onion service operator, manage client authorization to your services"
AUTH_TYPE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --cancel-label "Cancel" --menu "${MENU}" 14 60 2 \
"LIST" "List all clients for specific HiddenService" \
"EDIT" "Edit an existing authorization" \
"GEN" "Generate a new key pair (public and private key)" \
"PUB" "Register the client public key" \
"DEL" "Remove a client" \
2>&1 >/dev/tty)"
case "${AUTH_TYPE}" in
LIST)
service_menu checklist "Auth Server List"
if [ -n "${SERVICE_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth server list "${SERVICE_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
EDIT)
i=0
for SERVICE in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/); do
## only include services that have at least one client
CLIENT_EXIST="$(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/"${SERVICE}"/authorized_clients/ | sed "s/\.auth//g")"
if [ -n "${CLIENT_EXIST}" ]; then
i=$((i+1))
ONION_HOSTNAME="$(sudo -u "${TOR_USER}" grep -s ".onion" "${DATA_DIR_SERVICES}"/"${SERVICE}"/hostname)"
ONION_HOSTNAME_WITHOUT_ONION=${ONION_HOSTNAME%.onion}
SERVICE_LIST="$(printf "%s\n%s\n%s\n%s\n" "${SERVICE_LIST}" "${SERVICE}" "${ONION_HOSTNAME_WITHOUT_ONION}" 0)"
fi
done
if [ -z "${SERVICE_LIST}" ]; then
TITLE="Onion Service - INFO"
MENU="\nNone of your services have client authorization."
dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --msgbox "${MENU}" 10 50
else
TITLE="Client Authorization - Server - Deletion"
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_SERVICE="$(dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --menu "${MENU}" \
"$((i+8))" 80 2 ${SERVICE_LIST} 2>&1 >/dev/tty)"
fi
if [ -n "${CHOICE_SERVICE}" ]; then
i=0
for CLIENT in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/"${SERVICE}"/authorized_clients/ | sed "s/\.auth//g"); do
i=$((i+1))
CLIENT_LIST="$(printf "%s\n%s\n%s\n" "${CLIENT_LIST}" "${CLIENT}" ".")"
done
# shellcheck disable=SC2086
CHOICE_CLIENT="$(dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --menu "${MENU}" \
"$((i+8))" 50 2 ${CLIENT_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_CLIENT}" ] && sudo "${EDITOR:-vi}" "${DATA_DIR_SERVICES}"/"${SERVICE}"/authorized_clients/"${CHOICE_CLIENT}".auth
fi
;;
GEN)
service_menu checklist "Auth Server Gen"
if [ -n "${SERVICE_NAME_LIST}" ]; then
TITLE="Client Authorization - Server - Generate"
MENU="Client(s) name(s) delimited by space or/and comma (e.g.: alice, bob, carol)"
CLIENT_NAME_LIST="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 10 50 3>&1 1>&2 2>&3)"
CLIENT_NAME_LIST="$(printf %s"${CLIENT_NAME_LIST}" | tr -s ' ' ',' | tr -s ',' ',')"
if { [ -n "${SERVICE_NAME_LIST}" ] && [ -n "${CLIENT_NAME_LIST}" ]; }; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth server on "${SERVICE_NAME_LIST}" "${CLIENT_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
PUB)
service_menu menu "Auth Server Pub"
if [ -n "${SERVICE_NAME_LIST}" ]; then
TITLE="Client Authorization - Server - Pub"
MENU="Client name (e.g.: alice)"
CLIENT_NAME_LIST="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 10 50 3>&1 1>&2 2>&3)"
TITLE="Client Authorization - Server - Pub"
MENU="Client public key in base32:"
CLIENT_PUB_KEY="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 10 50 3>&1 1>&2 2>&3)"
if { [ -n "${SERVICE_NAME_LIST}" ] && [ -n "${CLIENT_NAME_LIST}" ] && [ -n "${CLIENT_PUB_KEY}" ]; }; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth server on "${SERVICE_NAME_LIST}" "${CLIENT_NAME_LIST}" "${CLIENT_PUB_KEY}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
DEL)
i=0
for SERVICE in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/); do
## only include services that have at least one client
CLIENT_EXIST="$(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/"${SERVICE}"/authorized_clients/ | sed "s/\.auth//g")"
if [ -n "${CLIENT_EXIST}" ]; then
i=$((i+1))
ONION_HOSTNAME="$(sudo -u "${TOR_USER}" grep -s ".onion" "${DATA_DIR_SERVICES}"/"${SERVICE}"/hostname)"
ONION_HOSTNAME_WITHOUT_ONION=${ONION_HOSTNAME%.onion}
SERVICE_LIST="$(printf "%s\n%s\n%s\n%s\n" "${SERVICE_LIST}" "${SERVICE}" "${ONION_HOSTNAME_WITHOUT_ONION}" 0)"
fi
done
if [ -z "${SERVICE_LIST}" ]; then
TITLE="Onion Service - INFO"
MENU="\nNone of your services have client authorization."
dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --msgbox "${MENU}" 10 50
else
TITLE="Client Authorization - Server - Deletion"
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_SERVICE="$(dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --checklist "${MENU}" \
"$((i+8))" 80 2 ${SERVICE_LIST} 2>&1 >/dev/tty)"
fi
if [ -n "${CHOICE_SERVICE}" ]; then
# shellcheck disable=SC2086
SERVICE_TOTAL=$(IFS=' '; set -f -- ${CHOICE_SERVICE}; printf %s"${#}")
for SERVICE in $(printf %s"${CHOICE_SERVICE}"); do
CLIENT="$(sudo -u "${TOR_USER}" ls "${DATA_DIR_SERVICES}"/"${SERVICE}"/authorized_clients/ | sed "s/\.auth//g")"
CLIENT_LIST="$(printf "%s\n%s\n" "${CLIENT_LIST}" "${CLIENT}")"
done
i=0
## intersection of clients on the chosen services
for CLIENT in $(printf %s"${CLIENT_LIST}" | tr " " "\n" | sort | uniq -c | grep "${SERVICE_TOTAL}" | sed "s/${SERVICE_TOTAL}//g" | tr -s "\n" " "); do
i=$((i+1))
CLIENT_BUILD_LIST="$(printf "%s\n%s\n%s\n%s\n" "${CLIENT_BUILD_LIST}" "${CLIENT}" "." 0)"
done
if [ -z "${CLIENT_BUILD_LIST}" ]; then
TITLE="Onion Service - INFO"
TEXT_NO_CLIENT="\nNo client exist inside the intersection of the chosen services."
dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --msgbox "${TEXT_NO_CLIENT}" 10 50
else
# shellcheck disable=SC2086
CHOICE_CLIENT="$(dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --checklist "${MENU}" \
"$((i+8))" 50 2 ${CLIENT_BUILD_LIST} 2>&1 >/dev/tty)"
fi
if [ -n "${CHOICE_CLIENT}" ]; then
SERVICE_NAME_LIST="$(printf %s"${CHOICE_SERVICE}" | sed "s/ /,/g")"
CLIENT_NAME_LIST="$(printf %s"${CHOICE_CLIENT}" | sed 's/ /,/g')"
fi
fi
if [ -n "${CLIENT_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth server off "${SERVICE_NAME_LIST}" "${CLIENT_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
esac
;;
AUTH_CLIENT)
TITLE="Client Authorization - Client"
MENU="As the onion service client: Would you like to 'add' or 'remove' your authorization?"
AUTH_TYPE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --cancel-label "Cancel" --menu "${MENU}" 13 80 4 \
"LIST" "List all the authorizations inside ClientOnionAuthDir" \
"EDIT" "Edit your client authorizations" \
"GEN" "Generate a new key pair (public and private key)" \
"PRIV" "Register your private key" \
"DEL" "Remove expired authorization" \
2>&1 >/dev/tty)"
case "${AUTH_TYPE}" in
LIST)
"${ONIONSERVICE_PWD}"/onionservice-cli auth client list
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
;;
EDIT)
i=0
for ONION_AUTH in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_AUTH}"/); do
ONION_AUTH_WITHOUT_SUFFIX=${ONION_AUTH%.auth_private}
i=$((i+1))
ONION_AUTH_LIST="$(printf "%s\n%s\n%s\n" "${ONION_AUTH_LIST}" "${ONION_AUTH_WITHOUT_SUFFIX}" ".")"
done
TITLE="Client Onion Auth Directory"
if [ "${#ONION_AUTH_LIST}" -eq 0 ]; then
TEXT_NO_CLIENT="\nThe folder ClientOnionAuthDir is empty.\n\nYou don't have any '.auth_private' file inside\n${DATA_DIR_AUTH}"
dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --msgbox "${TEXT_NO_CLIENT}" 10 50
else
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_ONION_AUTH="$(dialog --title "${TITLE}" --menu "${MENU}" \
"$((i+8))" 80 2 ${ONION_AUTH_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_ONION_AUTH}" ] && sudo "${EDITOR:-vi}" "${DATA_DIR_AUTH}"/"${CHOICE_ONION_AUTH}".auth_private
fi
;;
GEN)
MENU="\nInsert the onion address of the service you want to authenticate:"
ONION_HOSTNAME="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 9 80 3>&1 1>&2 2>&3)"
if [ -n "${ONION_HOSTNAME}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth client on "${ONION_HOSTNAME}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
PRIV)
MENU="\nInsert the onion address of the service you want to authenticate:"
ONION_HOSTNAME="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 9 80 3>&1 1>&2 2>&3)"
MENU="Insert the client's private key:"
CLIENT_PRIV_KEY="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--inputbox "${MENU}" 9 80 3>&1 1>&2 2>&3)"
if { [ -n "${ONION_HOSTNAME}" ] && [ -n "${CLIENT_PRIV_KEY}" ]; }; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth client on "${ONION_HOSTNAME}" "${CLIENT_PRIV_KEY}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
DEL)
i=0
for ONION_AUTH in $(sudo -u "${TOR_USER}" ls "${DATA_DIR_AUTH}"/); do
ONION_AUTH_WITHOUT_SUFFIX=${ONION_AUTH%.auth_private}
i=$((i+1))
ONION_AUTH_LIST="$(printf "%s\n%s\n%s\n%s\n" "${ONION_AUTH_LIST}" "${ONION_AUTH_WITHOUT_SUFFIX}" "." 0)"
done
TITLE="Onion Service - INFO"
if [ "${#ONION_AUTH_LIST}" -eq 0 ]; then
TEXT_NO_CLIENT="\nThe folder ClientOnionAuthDir is empty.\n\nYou don't have any '.auth_private' file inside\n${DATA_DIR_AUTH}"
dialog --backtitle "${BACKTITLE}" --title "${TITLE}" --msgbox "${TEXT_NO_CLIENT}" 10 50
else
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_ONION_AUTH="$(dialog --title "${TITLE}" --checklist "${MENU}" \
"$((i+8))" 80 2 ${ONION_AUTH_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_ONION_AUTH}" ] && ONION_AUTH_NAME_LIST="$(printf %s"${ONION_AUTH_NAME_LIST}" | sed "s/ /,/g")"
fi
if [ -n "${ONION_AUTH_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli auth client off "${ONION_AUTH_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
esac
;;
CREDENTIALS)
service_menu checklist "Credentials"
if [ -n "${SERVICE_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli list "${SERVICE_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
LOCATION)
service_menu menu "Location"
if [ -n "${SERVICE_NAME_LIST}" ]; then
TITLE="Onion-Location"
CHOICE_ACTION="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --cancel-label "Exit" --menu "${MENU}" 10 50 2 \
"NGINX" "Nginx web server header" \
"APACHE" "Apache web server header" \
"HTML" "hmtl <meta> http-equiv attribute" \
2>&1 >/dev/tty)"
if [ -n "${CHOICE_ACTION}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli location "${SERVICE_NAME_LIST}" "${CHOICE_ACTION}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
WEB_SERVER)
TITLE="Web server - Status"
MENU="\nWould you like to enable or disable serving a web site?"
STATUS="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" --menu "${MENU}" 12 50 2 \
"LIST" "List enabled websites" \
"ON" "Serve web site" \
"OFF" "Stop serving web site" \
2>&1 >/dev/tty)"
if [ "${STATUS}" = "LIST" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli "${WEBSERVER}" "${STATUS}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
elif [ "${STATUS}" = "ON" ]; then
service_menu menu "Web server "
if [ -n "${SERVICE_NAME_LIST}" ]; then
i=0
DIALOG_TYPE="${1}"
for FOLDER in $(sudo ls "${WEBSITE_DIR}"); do
i=$((i+1))
case "${DIALOG_TYPE}" in
checklist) FOLDER_LIST="$(printf "%s\n%s\n%s\n%s\n" "${FOLDER_LIST}" "${FOLDER}" "." 0)";;
menu) FOLDER_LIST="$(printf "%s\n%s\n%s\n" "${FOLDER_LIST}" "${FOLDER}" ".")";;
esac
done
TITLE="Folder"
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_FOLDER="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" --"${DIALOG_TYPE}" "${MENU}" \
"$((i+8))" 50 2 ${FOLDER_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_FOLDER}" ] && FOLDER_NAME_LIST="$(printf %s"${CHOICE_FOLDER}" | sed "s/ /,/g")"
if [ -n "${FOLDER_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli web "${STATUS}" "${SERVICE_NAME_LIST}" "${FOLDER_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
elif [ "${STATUS}" = "OFF" ]; then
i=0
for SERVICE in $(sudo ls /etc/"${WEBSERVER}"/sites-enabled/ | sed "s/-onion.conf//g"); do
i=$((i+1))
SERVICE_LIST="$(printf "%s\n%s\n" "${SERVICE_LIST}" "${SERVICE}" "." 0)"
done
TITLE="Web Server - Disable Site"
MENU="\nUse spacebar to select:"
# shellcheck disable=SC2086
CHOICE_SERVICE="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" --checklist "${MENU}" \
"$((i+8))" 50 2 ${SERVICE_LIST} 2>&1 >/dev/tty)"
[ -n "${CHOICE_SERVICE}" ] && SERVICE_NAME_LIST="$(printf %s"${CHOICE_SERVICE}" | sed "s/ /,/g")"
if [ -n "${SERVICE_NAME_LIST}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli web "${STATUS}" "${SERVICE_NAME_LIST}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
fi
;;
VANGUARDS)
TITLE="Vanguards"
if [ -z "$(sudo -u "${TOR_USER}" ls "${DATA_DIR}"/vanguards)" ]; then
CHOICE_ACTION="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --cancel-label "Exit" --menu "${MENU}" 8 50 2 \
"INSTALL" "Use Vanguards protections" 2>&1 >/dev/tty)"
else
CHOICE_ACTION="$(dialog --clear --backtitle "${BACKTITLE}" --title "${TITLE}" \
--ok-label "Select" --cancel-label "Exit" --menu "${MENU}" 10 50 2 \
"LOGS" "Follow vanguards logs" \
"UPGRADE" "Set new config and upgrade" \
"REMOVE" "Delete the Vanguards directory" \
2>&1 >/dev/tty)"
fi
if [ "${CHOICE_ACTION}" = "LOGS" ]; then
clear_posix
trap '"${ONIONSERVICE_PWD}"/onionservice-tui; exit 0' INT
sudo tail -f -n 25 /var/log/tor/vanguards.log
elif [ -n "${CHOICE_ACTION}" ]; then
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-cli vanguards "${CHOICE_ACTION}"
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
fi
;;
IMPORT)
"${ONIONSERVICE_PWD}"/onionservice-cli backup integrate
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2; read -r confirmation
;;
EXPORT)
"${ONIONSERVICE_PWD}"/onionservice-cli backup create
printf %s"${FOREGROUND_YELLOW}\nPress ENTER to return to the TUI: ${UNSET_FORMAT}" >&2
# shellcheck disable=SC2034
read -r confirmation
;;
QUIT) exit 0;;
esac
clear_posix
"${ONIONSERVICE_PWD}"/onionservice-tui