Permalink
Browse files

Fixed on demand pipe for Windows and Mac. Added help message

  • Loading branch information...
tomas committed Nov 23, 2010
1 parent 4113a86 commit 3c2bdcf8ccdc0130983e2a4ba8bea67ba7c4b07d
Showing with 58 additions and 21 deletions.
  1. +6 −1 core/functions
  2. +38 −18 core/setup
  3. +14 −2 platform/windows/functions
View
@@ -305,10 +305,15 @@ on_demand_command(){
openssl s_client -no_ssl2 -quiet -connect $on_demand_host:$on_demand_port 2> /dev/null
log " -- OpenSSL returned. Removing pipe/lockfile..."
rm -f "$on_demand_pipe"
+ kill_process "$on_demand_pipe"
+}
+
+on_demand_stdin(){
+ tail -f "$on_demand_pipe" 2> /dev/null
}
on_demand_loop(){
- tail --follow=name "$on_demand_pipe" 2> /dev/null | on_demand_command | while read message; do
+ on_demand_stdin | on_demand_command | while read message; do
if [[ "$message" =~ "run" ]]; then
log " -- Command issued: $message"
if [ "$message" == "run" ]; then
View
@@ -13,26 +13,46 @@ cleanup(){
delete_tmpdir
}
+show_usage(){
+ echo "Prey ${version} ( http://preyproject.com )"
+ echo -e "\nUsage: `basename $0` [options]"
+ echo -e "Options:"
+ echo -e " -t | --test\t\tTest mode. Runs Prey without sending any data."
+ echo -e " -c | --check\t\tCheck mode. Checks if configuration is correctly set up."
+ echo -e " -l | --log\t\tLog output to ${base_path}/prey.log (default in Windows)."
+ echo -e " -s | --silent\t\tDon't log any output."
+ echo -e " -o | --on-demand\tRuns Prey without checking if on-demand mode is active.\n"
+}
+
# step throught the params and check
until [ -z "$1" ]; do
- if [[ "$1" == "-t" || "$1" == "--test" ]]; then
- echo -e "\n -- TEST MODE ENABLED."
- trap - INT # set off trap
- test_mode=1
- . $base_path/test/include "$2" 2> /dev/null
- shift
- elif [[ "$1" == '-c' || "$1" == '--check' ]]; then
- echo -e "\n -- CHECK MODE ENABLED."
- check_mode=1
- elif [[ "$1" == "-l" || "$1" == "--log" ]]; then
- logfile="$base_path/prey.log"
- echo -n "" > "$logfile" # empty the logfile first
- log_output=">> \"$logfile\""
- elif [[ "$1" == "-s" || "$1" == "--silent" ]]; then
- log_output="&> /dev/null"
- elif [[ "$1" == "-o" || "$1" == "--on-demand" ]]; then
- on_demand_call=1
- fi
+ case "$1" in
+ -t | --test )
+ echo -e "\n -- TEST MODE ON."
+ trap - INT # set off trap
+ test_mode=1
+ . $base_path/test/include "$2" 2> /dev/null
+ shift
+ ;;
+ -c | --check )
+ echo -e "\n -- CHECK MODE ON."
+ check_mode=1
+ ;;
+ -o | --on-demand )
+ echo -e "\n -- ON-DEMAND MODE ON."
+ on_demand_call=1
+ ;;
+ -l | --log )
+ logfile="$base_path/prey.log"
+ echo -n "" > "$logfile" # empty the logfile first
+ log_output=">> \"$logfile\""
+ ;;
+ -s | --silent )
+ log_output="&> /dev/null"
+ ;;
+ -h | --help | * )
+ show_usage && exit
+ esac
shift
done
View
@@ -27,9 +27,9 @@ verify_installation(){
# check prey service on
log " -- Checking if Prey's cron service is running..."
if [ -n `is_process_running "cron"` ]; then
- echo " -- Cron service up and running. Good."
+ log " -- Cron service up and running. Good."
else
- echo " !! Cron service not found! Please make sure no antivirus is blocking cron.exe from running. Optionally reinstall. :)"
+ log " !! Cron service not found! Please make sure no antivirus is blocking cron.exe from running. Optionally reinstall. :)"
fi
# check net framework
@@ -103,6 +103,18 @@ reverse_tunnel_command(){
return $rs
}
+on_demand_stdin(
+ local sleep_interval=1
+ local last_msg=""
+ while sleep $sleep_interval; do
+ local new_msg=`tail -1 "$on_demand_pipe"`
+ if [ "$new_msg" != "$last_msg" ]; then
+ echo "$new_msg"
+ fi
+ last_msg="$new_msg"
+ done
+)
+
############################################
# module functions
############################################

0 comments on commit 3c2bdcf

Please sign in to comment.