/
cable-id
executable file
·53 lines (43 loc) · 1.18 KB
/
cable-id
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
#!/bin/sh -e
# Setup environment with needed environment vars
. /etc/cable/profile
error() {
echo "cable-id: $@" 1>&2
exit 1
}
torhost=${CABLE_TOR}/hidden_service/hostname
i2phost=${CABLE_I2P}/eepsite/hostname
username=${CABLE_CERTS}/certs/username
undefined="undefined"
case "$1" in
user)
if [ ! -e ${username} ]; then
echo "${undefined}"
else
username=`cat ${username} | tr -cd a-z2-7`
[ ${#username} = 32 ] || error "bad username"
echo "${username}"
fi
;;
tor)
if [ ! -e ${torhost} ]; then
echo "${undefined}"
else
torhost=`cat ${torhost} | tr -cd '[:alnum:].-' | tr '[:upper:]' '[:lower:]'`
[ ${#torhost} != 0 ] || error "bad Tor hostname"
echo "${torhost}"
fi
;;
i2p)
if [ ! -e ${i2phost} ]; then
echo "${undefined}"
else
i2phost=`cat ${i2phost} | tr -cd '[:alnum:].-' | tr '[:upper:]' '[:lower:]'`
[ ${#i2phost} != 0 ] || error "bad I2P hostname"
echo "${i2phost}"
fi
;;
*)
error "param: user|tor|i2p"
;;
esac