forked from Open-Web-Analytics/Open-Web-Analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
owa_requestContainer.php
304 lines (228 loc) · 7.3 KB
/
owa_requestContainer.php
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
//
// Open Web Analytics - An Open Source Web Analytics Framework
//
// Copyright 2006 Peter Adams. All rights reserved.
//
// Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $Id$
//
/**
* OWA Request Params
*
* @author Peter Adams <[email protected]>
* @copyright Copyright © 2006 Peter Adams <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
* @category owa
* @package owa
* @version $Revision$
* @since owa 1.0.0
*/
class owa_requestContainer {
var $cli_args;
var $is_https;
var $owa_params = array();
var $cookies = array();
var $owa_cookies = array();
var $session = array();
var $request = array();
var $server;
var $guid;
var $state;
var $request_type = '';
var $timestamp;
var $current_url;
/**
* Constructor
*
*/
function __construct() {
$this->timestamp = time();
$this->guid = owa_lib::generateRandomUid();
// php's server variables
$this->server = $_SERVER;
// files
if (!empty($_FILES)) {
$this->files = $_FILES;
}
// setup cookies
$this->cookies = array();
// look for access to the raw HTTP cookie string. This is needed becuause OWA can set settings cookies
// with the same name under different subdomains. Multiple cookies with the same name are not
// available under $_COOKIE. Therefor OWA's cookie conainter must be an array of arrays.
if ( isset( $_SERVER['HTTP_COOKIE'] ) && strpos( $_SERVER['HTTP_COOKIE'], ';') ) {
$raw_cookie_array = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($raw_cookie_array as $raw_cookie ) {
$nvp = explode( '=', trim( $raw_cookie ) );
$this->cookies[ $nvp[0] ][] = urldecode($nvp[1]);
}
} else {
// just use the normal cookie global
if ( $_COOKIE && is_array($_COOKIE) ) {
foreach ($_COOKIE as $n => $v) {
// hack against other frameworks sanitizing cookie data and blowing away our '>' delimiter
// this should be removed once all cookies are using json format.
if (strpos($v, '>')) {
$v = str_replace(">", ">", $v);
}
$cookies[ $n ][] = $v;
}
}
}
// populate owa_cookie container with just the cookies that have the owa namespace.
$this->owa_cookies = owa_lib::stripParams( $this->cookies, owa_coreAPI::getSetting('base', 'ns') );
// session
if (!empty($_SESSION)) {
$this->session = $_SESSION;
}
/* STATE CONTAINER */
// state
$this->state = owa_coreAPI::supportClassFactory('base', 'state');
// merges session
if (!empty($this->session)) {
$this->state->addStores(owa_lib::stripParams($this->session, owa_coreAPI::getSetting('base', 'ns')));
}
// merges cookies
foreach ( $this->owa_cookies as $k => $owa_cookie ) {
$this->state->setInitialState( $k, $owa_cookie );
}
// create request params from GET or POST or CLI args
$params = array();
// use GET vars as the base for the request
if ( isset( $_GET ) && ! empty( $_GET ) ) {
// get params from _GET
$params = $_GET;
$this->request_type = 'get';
}
// merge in POST vars. GET and POST can occure on the same request.
if ( isset( $_POST ) && ! empty( $_POST ) ) {
// get params from _GET
$params = array_merge( $params, $_POST);
$this->request_type = 'post';
}
// look for command line arguments in the 'argv' index.
if ( ! $this->request_type && isset( $_SERVER['argv'] ) ) {
$this->cli_args = $_SERVER['argv'];
// parse arguments into key value pairs
for ( $i=1; $i < count( $this->cli_args ); $i++ ) {
$it = explode( "=", $this->cli_args[$i] );
if ( isset( $it[1] ) ) {
$params[ $it[0] ] = $it[1];
} else {
$params[ $it[0] ] = '';
}
}
$this->request_type = 'cli';
}
if ( $this->request_type === 'get' || $this->request_type === 'post' ) {
$this->current_url = owa_lib::get_current_url();
}
// Clean Input arrays
$this->request = owa_lib::inputFilter($params);
// get namespace
$ns = owa_coreAPI::getSetting('base', 'ns');
// strip action and do params of nasty include exploits.
if (array_key_exists( $ns.'action', $this->request)) {
$this->request[$ns.'action'] = owa_lib::fileInclusionFilter($this->request[$ns.'action']);
}
if (array_key_exists($ns.'do', $this->request)) {
$this->request[$ns.'do'] = owa_lib::fileInclusionFilter($this->request[$ns.'do']);
}
// strip owa namespace
$this->owa_params = owa_lib::stripParams($this->request, $ns);
// translate certain request variables that are reserved in javascript
$this->owa_params = owa_lib::rekeyArray($this->owa_params, array_flip(owa_coreAPI::getSetting('base', 'reserved_words')));
// set https flag
if( isset($_SERVER['HTTPS'] ) ) {
$this->is_https = true;
}
}
function getParam($name) {
if (array_key_exists($name, $this->owa_params)) {
return $this->owa_params[$name];
} else {
return false;
}
}
function setParam($name, $value) {
$this->owa_params[$name] = $value;
return true;
}
function getCookie($name) {
if (array_key_exists($name, $this->cookies)) {
return $this->cookies[$name];
} else {
return false;
}
}
function getRequestParam($name) {
if (array_key_exists($name, $this->request)) {
return $this->request[$name];
} else {
return false;
}
}
function getAllRequestParams() {
return $this->request;
}
function getAllOwaParams() {
return $this->owa_params;
}
function mergeParams($params) {
$this->owa_params = array_merge($this->owa_params, $params);
return;
}
function getServerParam($name) {
if (array_key_exists($name, $this->server)) {
return $this->server[$name];
} else {
return false;
}
}
function decodeRequestParams() {
$params = array();
// Apply caller specific params
foreach ($this->owa_params as $k => $v) {
if (is_array($v)) {
array_walk_recursive($v, array($this, 'arrayUrlDecode'));
$params[$k] = $v;
} else {
$params[$k] = urldecode($v);
}
}
// clean params after decode
$params = owa_lib::inputFilter($params);
// replace owa params
$this->owa_params = $params;
//debug
owa_coreAPI::debug('decoded OWA params: '. print_r($this->owa_params, true));
return;
}
function arrayUrlDecode(&$val, $index) {
urldecode($val);
}
function getOwaCookie($name) {
if (array_key_exists($name, $this->owa_cookies)) {
return $this->owa_cookies[$name];
} else {
return false;
}
}
public function getTimestamp() {
return $this->timestamp;
}
public function getCurrentUrl() {
return $this->current_url;
}
public function getRequestType() {
return $this->request_type;
}
}
?>