Permalink
Browse files

Fixes for pending jobs. Commented some of the code so its more unders…

…tandable. New capitalize function for the self_setup routine. core/functions now runs before core/setup.
  • Loading branch information...
1 parent 5382029 commit e06ba53caa5db8d6968bddd791254aaa9a3fb7f4 @tomas tomas committed May 12, 2010
Showing with 65 additions and 40 deletions.
  1. +6 −2 config
  2. +1 −1 core/base
  3. +29 −18 core/functions
  4. +13 −6 core/jobs
  5. +4 −4 core/push
  6. +0 −4 core/setup
  7. +3 −3 platform/windows/check.bat
  8. +9 −2 prey.sh
View
8 config
@@ -23,7 +23,7 @@ check_url='http://control.preyproject.com'
missing_status_code='404'
# you can use send the report via email or to the web service
-# valid values: http, email or scp
+# valid values: http, email, scp or sftp
post_method='http'
####################################################################
@@ -58,7 +58,7 @@ mail_from='Prey <no-reply@gmail.com>'
mail_subject='[Prey] Status Report'
####################################################################
-# scp posting configuration -- EXPERIMENTAL!
+# scp/sftp posting configuration -- EXPERIMENTAL!
# we dont use user/pass but RSA keys
# for more info check http://tinyurl.com/sshtip
####################################################################
@@ -67,3 +67,7 @@ mail_subject='[Prey] Status Report'
scp_user='username'
scp_server='my.server.com'
scp_path='~'
+
+sftp_user='username'
+sftp_server='my.server.com'
+sftp_path='.'
View
@@ -5,8 +5,8 @@
# License: GPLv3
####################################################################
-. "$base_path/core/setup"
. "$base_path/core/functions"
+. "$base_path/core/setup"
. "$base_path/core/pull"
. "$base_path/core/updater"
. "$base_path/core/response"
View
@@ -131,10 +131,19 @@ find_in(){
echo "${1}" | grep "${2}" 1>/dev/null && echo 1 || return 0
}
+# returns 1 if int/float is first param is bigger than second
is_bigger_than() {
echo "$1 $2" | awk '{if ($1 > $2) print 1; else print 0}'
}
+lowercase(){
+ echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
+}
+
+capitalize(){
+ echo "$1" | sed -r 's/\b(.)/\U\1/g'
+}
+
urlencode(){
echo "$1" | tr $line_breaker "^" | sed -e 's/%/%25/g;s/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/=/%3D/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g' -e "s/\^$//;s/\^/%0A/g"
}
@@ -210,28 +219,30 @@ verify_installation(){
####################################################################
# self setup functions
####################################################################
+
self_setup(){
- if [[ -n "$api_key" && -z "$device_key" ]]; then
-
- local parms="device[title]=Mi Ubuntu&device[device_type]=Portable&device[os]=Linux&device[os_version]=Guadalinex"
- #echo -e "$parms"
- response=`getter -u $api_key:x -i $check_url/devices.xml -d "$parms"`
- #echo -e "$response"
- status_code=`echo "$response" | grep "Status" | sed 's/.*:[[:space:]]\([[:digit:]]*\).*/\1/'`
- if [ $status_code == "201" ]; then
- device_key=`echo "$response" | grep "<key>" | sed 's/.*<key>\(.*\)<\/key>.*/\1/'`
- sed -i -e "s/device_key='.*'/device_key='$device_key'/" $base_path/config
- echo " -- Device successfully added."
+ echo ' -- Sending request to Control Panel...'
+ local params="device[title]=`hostname`&device[device_type]=Portable&device[os]=`capitalize $os`"
+ local response=`getter -u $api_key:x -i $check_url/devices.xml -d "$params"`
- else
+ get_status_code
+ if [ $status == "201" ]; then
- echo -e " -- Couldn't add this device to your account. You probably don't have any slots left.\n"
- exit 1
+ echo ' -- Device succesfully added! Applying configuration...'
+ device_key=`echo "$response" | grep "<key>" | sed 's/.*<key>\(.*\)<\/key>.*/\1/'`
+ sed -i -e "s/device_key='.*'/device_key='$device_key'/" "$base_path/config" 2> /dev/null
+ if [ $? == 1 ]; then
+ echo " -- There was a problem saving the configuration. You probably don't have permissions to modify $base_path/config."
fi
-
- # exit 0
- fi
-}
+ echo ' -- All set.'
+ else
+
+ echo -e " -- Couldn't add this device to your account. Make sure you have any slots left.\n"
+ exit 1
+
+ fi
+
+}
View
@@ -35,17 +35,24 @@ add_job(){
run_pending_jobs(){
if [ "${#jobs[*]}" -gt 0 ]; then
+
echo -e "\n${bold} -- Running pending jobs...${bold_end}\n"
- for j in "${jobs[@]}"
- do
- module=`echo $j | sed 's/__.*//g'`
- function=`echo $j | sed 's/.*__//g'`
+ for j in "${jobs[@]}"; do
+
+ local module=`echo $j | sed 's/__.*//g'`
+ local function=`echo $j | sed 's/.*__//g'`
echo " -- Running job $function from $module module."
- function_exists $function
- if [ $? == 1 ]; then
+ # lets start by checking if we can actually execute the function
+ function_exists "$function"
+ if [ $? == 1 ]; then # the module isn't loaded yet
initialize_module "$module"
+ if [ $? == 1 ]; then # it means the module doesnt exist
+ continue
+ fi
fi
eval "$function"
+
done
+
fi
}
View
@@ -10,15 +10,15 @@ send_report(){
local trace_list=`list_traces`
file_list=`list_files`
if [[ $trace_list || $file_list ]]; then
- # if [ -n "$test_mode" ]; then
- # echo ' >> This is where the data gets sent. Though not in test mode!'
- # else
+ if [ -n "$test_mode" ]; then
+ echo ' >> This is where the data gets sent. Though not in test mode!'
+ else
trace_file="$tmpdir/prey_traces.tmp"
echo -e "$trace_list" > "$trace_file"
echo " -- Posting data via $post_method..."
eval 'send_via_'"${post_method}"''
rm -f "$trace_file"
- # fi
+ fi
remove_traces
remove_files
else
View
@@ -19,10 +19,6 @@ until [ -z "$1" ]; do
shift
done
-lowercase(){
- echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
-}
-
get_os(){
os=`lowercase \`uname\``
@@ -1,4 +1,4 @@
-@echo off
-cd ..\..\..\
+@echo off
+cd ..\..\
platform\windows\bin\bash.exe prey.sh --check
-pause
+pause
View
11 prey.sh
@@ -51,8 +51,16 @@ else
fi
-self_setup
+####################################################################
+# if we have an API key and no Device key, let's try to auto setup
+####################################################################
+
+if [[ -n "$api_key" && -z "$device_key" ]]; then
+ echo -e "\n${bold} >> Running self setup!${bold_end}\n"
+ self_setup
+
+fi
####################################################################
# verify if installation and keys are correct, if requested
@@ -69,7 +77,6 @@ if [ -n "$check_mode" ]; then
fi
-
####################################################################
# if there's a URL in the config, lets see if it actually exists
# if it doesn't, the program will shut down gracefully

0 comments on commit e06ba53

Please sign in to comment.