Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Fixes for pending jobs. Commented some of the code so its more unders…
Browse files Browse the repository at this point in the history
…tandable. New capitalize function for the self_setup routine. core/functions now runs before core/setup.
  • Loading branch information
tomas committed May 12, 2010
1 parent 5382029 commit e06ba53
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 40 deletions.
8 changes: 6 additions & 2 deletions config
Expand Up @@ -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'

####################################################################
Expand Down Expand Up @@ -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
####################################################################
Expand All @@ -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='.'
2 changes: 1 addition & 1 deletion core/base
Expand Up @@ -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"
Expand Down
47 changes: 29 additions & 18 deletions core/functions
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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

}
19 changes: 13 additions & 6 deletions core/jobs
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions core/push
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions core/setup
Expand Up @@ -19,10 +19,6 @@ until [ -z "$1" ]; do
shift
done

lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}

get_os(){
os=`lowercase \`uname\``

Expand Down
6 changes: 3 additions & 3 deletions platform/windows/check.bat
@@ -1,4 +1,4 @@
@echo off
cd ..\..\..\
@echo off
cd ..\..\
platform\windows\bin\bash.exe prey.sh --check
pause
pause
11 changes: 9 additions & 2 deletions prey.sh
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e06ba53

Please sign in to comment.