-
Notifications
You must be signed in to change notification settings - Fork 0
/
x6s-reboot.sh
87 lines (70 loc) · 1.89 KB
/
x6s-reboot.sh
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
#!/usr/bin/env bash
#
# A simple bash script for rebooting a Netgear Nighthawk X6S Extender
#
# https://github.com/rperrell/x6s-reboot
set -e
CURL_OPT="--connect-timeout 10"
trap 'catch $? $LINENO' ERR
catch() {
[ $1 -eq 28 ] && echo "Connection timeout"
exit $1
}
usage() { echo "Usage: x6s-reboot [options...] [host]"; }
while getopts ":hp:tu:" opt; do
case $opt in
h )
usage
echo " -h Print this help text"
echo " -p <password> Set the password"
echo " -t Test connection"
echo " -u <username> Set the username"
exit 0
;;
p )
PASSWORD=$(echo -n $OPTARG | base64 | tr -d '=')
;;
u )
EMAIL=$(echo -n $OPTARG | base64 | tr -d '=')
;;
t )
TEST=1
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
usage
exit 1
;;
: )
echo "Option -$OPTARG requires an argument" 1>&2
usage
exit 1
;;
* )
echo "Invalid option or argument" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
HOST=$1
if [ -z "$HOST" ]; then
read -p "host: " HOST
echo
fi
if [ -z "$EMAIL" ]; then
read -p "username: "
EMAIL=$(echo -n "$REPLY" | base64 | tr -d '=')
echo
fi
if [ -z "$PASSWORD" ]; then
read -sp "password: "
PASSWORD=$(echo -n "$REPLY" | base64 | tr -d '=')
echo
fi
curl $CURL_OPT -s -d 'submit_flag=login' -d "email=$EMAIL" -d "password=$PASSWORD" -d 'hid_remember_me=off' -X POST "http://$HOST/register.cgi?/status.htm" >/dev/null
TIMESTAMP=$(curl $CURL_OPT -s http://$HOST/backUpSettings.htm | grep timestamp= | grep langForm | cut -f 5 -d ' ' | tr -d '"' | cut -f 2 -d '=')
[ -z "$TIMESTAMP" ] && echo Connection failed && exit 1
[ "$TEST" ] && echo Connection successful && exit 0
curl $CURL_OPT -s -d 'submit_flag=reboot' "http://$HOST/admin.cgi?/status.htm%20timestamp=$TIMESTAMP" >/dev/null
echo Rebooting $HOST