2
2
####################################################################
3
# Prey Client - by Tomas Pollak (bootlog.org)
4
# URL: http://preyproject.com
3
# Prey Bash Client - (c) Fork Ltd.
4
# http://preyproject.com
6
6
####################################################################
8
8
PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
9
readonly base_path=`dirname "$0"`
9
readonly base_path=$(dirname "$0")
11
11
####################################################################
12
12
# base files inclusion
27
log "${cyan}$STRING_START ### $(uname -a)${color_end}\n"
27
log "\n${cyan} ## $STRING_START\n ## $(uname -a)\n ## $(date)${color_end}\n"
29
29
####################################################################
30
30
# lets check if we're actually connected
42
42
# ok, lets check again, after waiting a bit
45
46
if [ $connected == 0 ]; then
46
48
log "$STRING_NO_CONNECT_TO_WIFI"
47
49
if [ -f "$last_response" ]; then # offline actions were enabled
48
51
log ' -- Offline actions enabled!'
79
85
if [ -n "$check_mode" ]; then
81
log "\n${bold} >> Verifying Prey installation...${bold_end}\n"
87
log "\n${bold} == Verifying Prey installation...${bold_end}\n"
82
88
verify_installation
84
90
if [ "$post_method" == "http" ]; then
85
log "\n${bold} >> Verifying API and Device keys...${bold_end}\n"
91
log "\n${bold} == Verifying API and Device keys...${bold_end}\n"
87
93
elif [ "$post_method" == "email" ]; then
88
log "\n${bold} >> Verifying SMTP settings...${bold_end}\n"
94
log "\n${bold} == Verifying SMTP settings...${bold_end}\n"
89
95
verify_smtp_settings
96
102
####################################################################
103
# wait a few seconds to make sure our request doesn't get dropped
104
# due to clashes with the other zillion requests to the CP
105
####################################################################
107
# only do this if Prey is being run from cron in Mac and Linux
108
if [[ "$os" != "windows" && -n "$(running_from_cron)" && "$post_method" == "http" ]]; then
109
seconds_to_wait=$(get_random_number 59)
110
log " -- Pausing for ${seconds_to_wait} seconds..."
111
sleep $seconds_to_wait
114
####################################################################
97
115
# if there's a URL in the config, lets see if it actually exists
98
116
# if it doesn't, the program will shut down gracefully
99
117
####################################################################
104
122
if [[ $connected == 1 && -n "$check_url" ]]; then
105
124
log "$STRING_CHECK_URL"
126
log "\n${bold} == Verifying status...${bold_end}\n"
107
127
check_device_status
110
process_module_config
112
log "\n${bold} >> Verifying status...${bold_end}\n"
113
log " -- Got status code $response_status!"
115
if [ "$response_status" == "$missing_status_code" ]; then
117
log "$STRING_PROBLEM"
119
####################################################################
120
# initialize and fire off active modules
121
####################################################################
123
set +e # error mode off, just continue if a module fails
124
log " -- Running active report modules..."
125
run_active_modules # on http mode this will only be report modules
127
####################################################################
128
# lets send whatever we've gathered
129
####################################################################
131
log "\n${bold} >> Sending report!${bold_end}\n"
129
if [ -z "$response_status" ]; then
131
log_response_error "$check_url"
137
log "$STRING_NO_PROBLEM"
135
log " -- Got status code $response_status!"
136
[ "$response_status" == "$missing_status_code" ] && device_missing=1
138
process_module_config
140
if [ -n "$device_missing" ]; then
142
log "$STRING_PROBLEM"
144
####################################################################
145
# initialize and fire off active modules
146
####################################################################
148
set +e # error mode off, just continue if a module fails
149
log " -- Running active report modules..."
152
####################################################################
153
# lets send whatever we've gathered
154
####################################################################
156
log "\n${bold} == Sending report!${bold_end}\n"
163
log "$STRING_NO_PROBLEM"
141
171
####################################################################
142
172
# if we have any pending actions, run them
143
173
####################################################################
145
if [ -n "$offline_mode" ]; then
146
process_module_config
149
175
check_running_actions
151
177
if [ "${#actions[*]}" -gt 0 ]; then