phantom_proxy 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -44,5 +44,9 @@ if you have set the proxy or just to the address and port the proxy is running a
44
44
  Security(1.2.0)
45
45
  Now the phantom_proxy can be secured with a key. The system is implemented with an hmac algorithm.
46
46
  Simply supply "-hmac THE_KEY" when starting the proxy and the proxy is secured
47
+
48
+ Service script(1.2.1)
49
+ In lib/phantom_proxy/install you can find an init.d script which makes it pretty easy to use phantom_proxy as a service with variable configured instances.
50
+ A howto on the config of the services can be found in the init script.
47
51
 
48
52
  == TODO
@@ -0,0 +1,188 @@
1
+ #! /bin/bash
2
+ ### BEGIN INIT INFO
3
+ # Provides: phantom_proxy
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 3 4 5
7
+ # Default-Stop: 0 1 2 6
8
+ # Short-Description: This script starts the phantom proxy
9
+ # Description: With this script you can automaticly start phantom_proxy
10
+ # instances. The script should be placed in /etc/init.d/phproxy
11
+ ### END INIT INFO
12
+
13
+ ### README
14
+ #
15
+ # You can put a configfile at
16
+ # HOMEFOLDER/.phantom_proxy/config
17
+ # or
18
+ # put several files into a folder at HOMEFOLDER/.phantom_proxy/config
19
+ # all files are loaded and one instance is created per file(CAUTION!! you have to set a unique PP_PID_NAME for each instance)
20
+ #
21
+ # Options you can set are:
22
+ # PP_PID_NAME: The name of the process
23
+ # PP_PORT: The port to run the proxy on (3003)
24
+ # PP_HOST: The host to run the proxy on (127.0.0.1)
25
+ # PP_HMAC: The hmac key to secure the server
26
+ #
27
+ # Example config file could look like the following:
28
+ #
29
+ # PP_PID_NAME="phantom_proxy_instance"
30
+ # PP_PORT=3002
31
+ # PP_HMAC="abcdefghi"
32
+ #
33
+ # End Example
34
+ #
35
+ ### End README
36
+
37
+ PP_NAME=phantom_proxy
38
+
39
+ PP_PID_NAME="phantom_proxy"
40
+
41
+ PP_HMAC="none"
42
+
43
+ PP_LOG()
44
+ {
45
+ local log_dir="/tmp/$PP_NAME"
46
+
47
+ #create PP_LOG folder
48
+ if [ ! -d $log_dir ]
49
+ then
50
+ mkdir -p $log_dir
51
+ fi
52
+
53
+ echo $log_dir
54
+ }
55
+
56
+ PP_CONFIG()
57
+ {
58
+ echo "/home/dsudmann/.$PP_NAME/config"
59
+ }
60
+
61
+ PP_LOG_FILE()
62
+ {
63
+ echo "$(PP_LOG)/$PP_PID_NAME.log"
64
+ }
65
+
66
+ PP_PID()
67
+ {
68
+ echo "$(PP_LOG)/$PP_PID_NAME.pid"
69
+ }
70
+
71
+ PP_PORT=3003
72
+
73
+ PP_HOST=localhost
74
+
75
+ PP_OPTIONS()
76
+ {
77
+ if [ $PP_HMAC == "none" ]
78
+ then
79
+ echo "-p $PP_PORT -a $PP_HOST -P $(PP_PID) -l $(PP_LOG_FILE) -d"
80
+ else
81
+ echo "-p $PP_PORT -a $PP_HOST -P $(PP_PID) -l $(PP_LOG_FILE) -d -hmac $PP_HMAC"
82
+ fi
83
+ }
84
+
85
+ load_config_file()
86
+ {
87
+ PP_HMAC="none"
88
+ if [ -e $1 ]
89
+ then
90
+ echo "Loaded Configfile: $1"
91
+ source $1
92
+ fi
93
+ }
94
+
95
+ run_for_configs()
96
+ {
97
+ cfg_folder=$(PP_CONFIG)
98
+ echo "Check config $cfg_folder"
99
+ if [ -d $cfg_folder ]; then
100
+ echo "Config folder: $cfg_folder"
101
+ for i in $( ls $cfg_folder) ; do
102
+ load_config_file "$cfg_folder/$i"
103
+ #run the given method
104
+ $1
105
+ sleep 2
106
+ done
107
+ return
108
+ elif [ -e $cfg_folder ]; then
109
+ echo "Config file"
110
+ load_config_file $cfg_folder
111
+ #run the given method
112
+ $1
113
+ return
114
+ fi
115
+ echo "No config detect using standard"
116
+ $1
117
+ }
118
+
119
+ do_start()
120
+ {
121
+ if [ -e $(PP_PID) ]
122
+ then
123
+ echo "Service $PP_NAME already running abort"
124
+ return
125
+ fi
126
+ echo "Starting $PP_NAME service"
127
+ $PP_NAME $(PP_OPTIONS)
128
+ }
129
+
130
+ do_stop()
131
+ {
132
+ if [ -e $(PP_PID) ]
133
+ then
134
+ echo "Stopping $PP_NAME service"
135
+ pp_id=$(cat $(PP_PID))
136
+ echo "Stopping $PP_NAME service: $pp_id"
137
+ kill $pp_id
138
+ return
139
+ fi
140
+
141
+ echo "Error $PP_NAME service isn't running"
142
+ }
143
+
144
+ do_restart()
145
+ {
146
+ do_stop
147
+ sleep 5
148
+ do_start
149
+ }
150
+
151
+ do_status()
152
+ {
153
+ echo "Checking status"
154
+ if [ -e $(PP_PID) ]
155
+ then
156
+ pp_id=$(cat $(PP_PID))
157
+ if [ `ps -p $pp_id | grep -c $PP_NAME` -ne 1 ] ; then
158
+ echo "failed - no process"
159
+ return 2
160
+ else
161
+ echo "Found PID: $pp_id"
162
+ return 0
163
+ fi
164
+ return
165
+ fi
166
+ echo "$PP_NAME is not running"
167
+ }
168
+
169
+ case "$1" in
170
+ start)
171
+ run_for_configs do_start
172
+ ;;
173
+ stop)
174
+ run_for_configs do_stop
175
+ ;;
176
+ restart)
177
+ run_for_configs do_restart
178
+ ;;
179
+ status)
180
+ run_for_configs do_status
181
+ ;;
182
+ *)
183
+ echo "Usage: $PP_NAME {start|stop|status|restart}" >&2
184
+ exit 3
185
+ ;;
186
+ esac
187
+
188
+ :
@@ -58,6 +58,10 @@ module PhantomJSProxy
58
58
  end
59
59
 
60
60
  def check_request_security req, env
61
+ if !env['HTTP_HMAC_KEY'] || !env['HTTP_HMAC_TIME']
62
+ return false
63
+ end
64
+
61
65
  client_key = env['HTTP_HMAC_KEY']
62
66
  client_time= Time.parse(env['HTTP_HMAC_TIME'])
63
67
  remote_time= Time.now
@@ -75,10 +79,10 @@ module PhantomJSProxy
75
79
 
76
80
  req = Rack::Request.new(env)
77
81
 
78
- haha = env.collect { |k, v| "#{k} : #{v}\n" }.join
79
- env['rack.errors'].write("The request: "+req.url()+"\nGET: "+haha+"\n")
82
+ request_parameters = env.collect { |k, v| "\t#{k} : #{v}\n" }.join
83
+ env['rack.errors'].write("The request: "+req.url()+"\nGET: "+request_parameters+"\n")
80
84
 
81
- if hmac_activated && !check_request_security(req, env)
85
+ if hmac_activated && hmac && !check_request_security(req, env)
82
86
  resp = Rack::Response.new([], 503, {
83
87
  'Content-Type' => 'text/html'
84
88
  }) { |r|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantom_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-02 00:00:00.000000000 Z
12
+ date: 2012-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin
@@ -58,6 +58,7 @@ files:
58
58
  - lib/phantom_proxy/scripts/proxy.js
59
59
  - lib/phantom_proxy/config.ru
60
60
  - lib/phantom_proxy/web/control_panel.html
61
+ - lib/phantom_proxy/install/phproxy
61
62
  - lib/phantom_proxy/vendor/bin/phantomjs
62
63
  - bin/phantom_proxy
63
64
  - README.rdoc