-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyMDM.sh
executable file
·83 lines (72 loc) · 1.99 KB
/
MyMDM.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
#!/bin/bash
serverURL="localhost:8000"
BaseName=$(basename $HOME)
echo $BaseName
PublicIP=$(curl -s ipinfo.io/ip)
echo $PublicIP
function Startup () {
# Function that will run on startup
if ! [ -x "$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v brew)" ]; then
echo 'Error: brew is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
brew install jq
fi
echo "Starting Up"
Login=$(curl -sS "$serverURL/Login?Username=$BaseName&Ip=$PublicIP")
# {"Success":true,"Ip":"ip"}
#echo $Login
if jq -e '.Success' <<< "$Login" | grep -q "true"; then
echo "Login Successful"
else
echo "Login Failed"
echo $(jq '.Reason' <<< "$Login")
echo "Creating User"
AddUser=$(curl -sS "$serverURL/AddUser?Username=$BaseName&Ip=$PublicIP")
echo $AddUser
fi
# will set the status
# http://localhost:8000/SetStatus?Username=test&Status=unknown
Status=$(curl -sS "$serverURL/SetStatus?Username=$BaseName&Status=online")
if jq -e '.Success' <<< "$Status" | grep -q "true"; then
echo "Status Set"
else
# {"Success": false, "Reason": "Username Not Found"}
echo "Status Set Failed"
# prints the reason
echo $(jq '.Reason' <<< "$Status")
echo
fi
}
function Shutdown () {
echo "\nShutting Down"
curl -sS "$serverURL/SetStatus?Username=$BaseName&Status=offline"
clear
exit 0
}
Startup
trap Shutdown EXIT
echo "Started"
while true
do
nc -l 8080 | while read -r line
do
if [[ $line =~ ^GET ]]; then
command=${line#* }
command=${command%% *}
command=${command#/}
command=${command//%20/" "}
command=${command//%22/}
command=${command//%7C/|}
command=${command//%3F/?}
command=${command//%3E/>}
echo "Received command: $command"
fi
done
done