forked from GAS85/nextcloud_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnextcloud-bot-hex.sh
More file actions
127 lines (94 loc) · 2.62 KB
/
nextcloud-bot-hex.sh
File metadata and controls
127 lines (94 loc) · 2.62 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
#!/bin/bash
# By Georgiy Sitnikov.
#
# AS-IS without any warranty
#
# To added to Nextcloud please execute:
# sudo -u www-data php /var/www/nextcloud/occ talk:command:add hex hex "/usr/local/bin/nextcloud-bot-hex.sh --hex {ARGUMENTS}" 1 3
# sudo -u www-data php /var/www/nextcloud/occ talk:command:add ascii ascii "/usr/local/bin/nextcloud-bot-hex.sh --ascii {ARGUMENTS}" 1 3
# OR
# sudo -u www-data php /var/www/nextcloud/occ talk:command:add hex hex "/usr/local/bin/nextcloud-bot-hex.sh {ARGUMENTS}" 1 3
# in This case only 1 command will do convertion hex2ascii and ascii2hex
#
# More infor under https://nextcloud-talk.readthedocs.io/en/latest/commands/
length=16
while test $# -gt 0; do
case "$1" in
--help)
# in case script was added as 1 command via
# sudo -u www-data php /var/www/nextcloud/occ talk:command:add hex hex "/usr/local/bin/nextcloud-bot-hex.sh {ARGUMENTS}" 1 3
echo "/hex - A Nextcloud Talk chat wrapper hex to ASCII and backwards"
echo " "
echo "Simple execution: /hex 0x21"
echo "Complex execution: /hex 0x22.0x5a"
echo "Symbol should start with 0x, Separated by '.' dots, or ' ' spaces."
echo " "
echo "Simple execution: /hex text"
exit 0
;;
*)
case "$2" in
--help)
if [ "$1" = "--hex" ]; then
echo "/hex - A Nextcloud Talk chat wrapper hex to ASCII"
echo " "
echo "for ASCII to hex see /ascii"
echo " "
echo "Simple execution: /hex 0x21"
echo "Complex execution: /hex 0x22.0x5a"
echo "First Symbol should start with 0x, Separated by '.' dots, or ' ' spaces"
exit 0
fi
if [ "$1" = "--ascii" ]; then
echo "/ascii - A Nextcloud Talk chat wrapper ASCII to hex"
echo " "
echo "for hex to ASCII see /hex"
echo " "
echo "Simple execution: /ascii Letter"
echo "Simple execution: /ascii Some Text"
exit 0
fi
;;
*)
break
;;
esac
esac
done
hex2ascii () {
echo "$userInput"
echo "$userInput" | xxd -r
echo
exit 0
}
ascii2hex () {
echo "$userInput" | xxd -g 1 -u
echo
exit 0
}
if [ "$1" = "--hex" ]; then
# Get first 2 Symbols of variable
first="$(echo $2 | head -c 2)"
if [ "$first" = "0x" ]; then
userInput="$2"
else
userInput="0x$2"
fi
hex2ascii
fi
if [ "$1" = "--ascii" ]; then
userInput="$2"
ascii2hex
fi
# in case script was added as 1 command via
# sudo -u www-data php /var/www/nextcloud/occ talk:command:add hex hex "/usr/local/bin/nextcloud-bot-hex.sh {ARGUMENTS}" 1 3
# Get first 2 Symbols of variable
first="$(echo $1 | head -c 2)"
if [ "$first" = "0x" ]; then
userInput=$(echo "$@" | tr '.' ' ')
hex2ascii
else
userInput="$@"
ascii2hex
fi
exit 0