forked from prey/prey-bash-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
push
124 lines (104 loc) · 3.89 KB
/
push
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
#!/bin/bash
####################################################################
# Prey Core Push Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################
update_device_info_with(){
if [ -z "$device_key" ]; then return 1; fi
log ' -- Updating device info...'
send_request "$check_url/devices/$device_key.xml" "-X PUT -u $api_key:x -d "$1""
get_status_code
if [ $response_status == "200" ]; then
log " -- Device updated."
else
log " -- Couldn't update your device. Maybe the Control Panel is taking a bath."
fi
}
deactivate_modules_on_panel(){
if [ -z "$device_key" ]; then return 1; fi
log " -- Deactivating module(s) ${1} on Control Panel..."
local param_string=""
until [ -z "$1" ]; do
local param_string="${param_string}device[deactivate_modules][]=$1&"
shift
done
update_device_info_with "$param_string"
}
send_report(){
log ' -- Packing all gathered traces...'
local trace_list=`list_traces`
file_list=`list_files`
if [[ $trace_list || $file_list ]]; then
if [ -n "$test_mode" ]; then
log ' ** This is where the data gets sent. Not in test mode though!'
else
trace_file="$tmpdir/prey_traces.tmp"
echo -e "$trace_list" > "$trace_file"
log " -- Posting data via $post_method..."
eval 'send_via_'"${post_method}"''
local rs=$?
rm -f "$trace_file" 2> /dev/null
fi
remove_traces
remove_files
else
log " -- No data to send. It seems you didn't activate any report modules. Skipping..."
fi
return $rs
}
send_via_email(){
local complete_subject="$mail_subject @ `date +"%a, %e %Y %T %z"`"
local decrypted_pass=`decrypt "$smtp_password"`
echo -e "${EMAIL_NOTICE}${EMAIL_HEADER}`urldecode "$trace_list"`${EMAIL_FOOTER}" > "$trace_file.msg"
# only add user/pass if set
[ -n "$smtp_username" ] && local auth="username=$smtp_username password=$decrypted_pass"
response=`mailsender -f "$mail_from" -t "$mail_to" -u "$complete_subject" -s $smtp_server -a $file_list -o message-file="$trace_file.msg" tls=auto $auth`
if [ `find_in "$response" 'ERROR'` ]; then
log "$STRING_ERROR_EMAIL"
log "\n This is the complete error message: \n $response\n"
else
log ' -- Report successfully sent! Check your inbox now.'
fi
rm "$trace_file.msg"
}
send_via_http(){
if [ -z "$api_key" ]; then
log ' -- API key not set! Cannot post data to server.'
return 1
else
local args="-u $api_key:x"
fi
if [ `find_in "$post_url" 'https'` ]; then
echo " -- Using SSL v3 encryption! Nice."
args="$args -k -3"
fi
response=`getter $args -K "$trace_file" $file_list "$post_url" \
-w "\n -- %{size_upload} bytes uploaded in %{time_total} seconds, at %{speed_upload} bytes/sec."`
log " -- $response"
}
send_via_scp(){
if [[ -n "$scp_server" && -n "$scp_path" ]]; then
log " -- Uploading the stuff to $scp_path in $scp_server..."
local new_folder="prey_data_`echo $start_time | sed 'y/ :/_-/'`"
ssh $scp_user@$scp_server mkdir $scp_path/$new_folder
response=`scp $ssh_options "$trace_file" $file_list $scp_user@$scp_server:$scp_path/$new_folder`
else
log ' !! You need to set up a server in order to send the report via SCP!'
fi
}
# SFTP posting by http://github.com/birdtori
send_via_sftp(){
if [[ -n "$sftp_server" && -n "$sftp_path" ]]; then
local new_folder="prey_data_`echo $start_time | sed 'y/ :/_-/'`"
log " -- Uploading the stuff to $sftp_path/$new_folder in $sftp_server..."
local batch="$tmpdir/sftp.script"
echo "mkdir $sftp_path/$new_folder" > "$batch"
echo "put "$trace_file" $sftp_path/$new_folder/" >> "$batch"
for f in $file_list; do echo "put $f $sftp_path/$new_folder/" >> "$batch"; done
echo "bye" >> "$batch"
response=`sftp $ssh_options -b $batch $sftp_user@$sftp_server`
else
log ' !! You need to set up a server in order to send the report via SFTP!'
fi
}