-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetaccess.sh
More file actions
36 lines (30 loc) · 1.02 KB
/
netaccess.sh
File metadata and controls
36 lines (30 loc) · 1.02 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
#!/bin/sh
# --- Config ---
USER="roll_no"
PASS="password"
# router's ip
IP="x.x.x.x"
ROOM="optional"
# 1 -> 1 hour, 2 -> 1 day
DURATION="2"
COOKIE_JAR="/root/netaccess_cookies.txt"
LOG="/tmp/netaccess.log"
# bug: could not find ip of netaccess
# fix: add "{ip} netaccess.iitm.ac.in" to /etc/hosts, use ping netaccess.iitm.ac.in to find ip
# use crontab -e and add
# 0 21 * * * /root/netaccess.sh >/dev/null 2>&1
# this runs every 9pm
# @reboot /root/netaccess.sh >/dev/null 2>&1
# however @reboot doesn't work as its not enabled feature, so add it to (include sleep 10 before)
# /etc/rc.local
# --- Login ---
echo "$(date): Logging in..." >> "$LOG"
curl -s -L -c "$COOKIE_JAR" \
-d "username=$USER&password=$PASS" \
"https://netaccess.iitm.ac.in/login" >> "$LOG" 2>&1
# --- Approve ---
echo "$(date): Approving session..." >> "$LOG"
curl -s -L -b "$COOKIE_JAR" \
-d "ip=$IP&username=$USER&building=Hostel&duration=$DURATION&room=$ROOM" \
"https://netaccess.iitm.ac.in/approve" >> "$LOG" 2>&1
echo "$(date): Done" >> "$LOG"