1
- # [ PHP] Ultra Small Proxy
2
- ### PHP 5.6+ / PHP 7
1
+ # [ PHP] Ultra Small Proxy 2
2
+ ### PHP: 7.0+
3
3
4
- Current version: 1.1
4
+ Current version: ** 2.0 ** | 2022-02-23
5
5
6
6
Ultra Small Proxy is a light-weight proxy written in PHP.
7
7
8
- ## Features:
8
+ ## Key Features:
9
9
10
10
- Proxy server written in PHP
11
11
- Easy usage and integration
12
- - Standalone and external usage (it is only one PHP class )
12
+ - Standalone and external usage (it is only one PHP file )
13
13
- Simple and light-weight
14
14
- Sessions support
15
15
- Sending and receiving cookies
16
+ - Sending and receiving HTTP headers ** (NEW in 2.0+)**
17
+ - Cache and assets storage ** (NEW in 2.0+)**
18
+ - Domain and IP/host connection support ** (NEW in 2.0+)**
19
+ - HTTP Basic Auth support ** (NEW in 2.0+)**
16
20
- GET and POST connections
17
21
- Forms submiting support
18
22
- POST variables redirecting
19
- - Toolbar with address bar and connection debugger
20
- - URLs rewriting at runtime (links, images, css, javascript, etc.)
23
+ - Toolbar with address bar, configuration and debugger
24
+ - URLs rewriting/proxying at runtime (links, images, css, javascript, etc.)
21
25
- 2 different methods for URLs rewriting: Regex (with preg_replace) and DOM XML (with libxml / DOMDocument)
22
- - PHP 5 and PHP 7 supported
26
+ - PHP 7.0+ supported
23
27
28
+ ## Requirements:
29
+
30
+ - PHP 7.0+
31
+ - CURL extension
32
+ - DOM XML extension
24
33
25
34
## Usage example:
26
35
```
27
36
<?php
28
37
29
- /* include class */
38
+ /* include classes */
30
39
include __DIR__.'/UltraSmallProxy.php';
31
40
32
- /* instantiate proxy */
33
- $proxy = new UltraSmallProxy();
41
+ /* instantiate config */
42
+ $config = new UltraSmallProxyConfig();
43
+
44
+ /* instantiate proxy with config */
45
+ $proxy = new UltraSmallProxy($config);
34
46
35
47
/* specify start page and load it! */
36
48
$output = $proxy->load('https://github.com');
@@ -40,10 +52,13 @@ echo $output;
40
52
41
53
```
42
54
Make sure to have write permissions to ` ./cookies ` directory.
55
+ Make sure to have write permissions to ` ./cache ` directory.
56
+
57
+ ### BE CAREFUL: directory with cookies should not be available to the public!
43
58
44
59
## Screenshot:
45
60
46
- ![ proxy_github ] ( https://user-images.githubusercontent.com/61396542/75244037-4c66bb00-57cb-11ea-82ee-c51c7736653b .png )
61
+ ![ proxy ] ( https://user-images.githubusercontent.com/61396542/155353063-fde84995-6e43-46c4-8a1c-b8b4772e6dfc .png )
47
62
48
63
49
64
Open ` loopback.php ` if you want to test proxy features like sessions support, POST vars redirecting, form submiting and more, e.g.:
@@ -59,62 +74,96 @@ $output = $proxy->load('http://localhost/loopback.php');
59
74
- ` loopback.php ` - loopback for test features like session support, form vars sending, and cookies redirecting
60
75
61
76
62
- ## Options :
77
+ ## Basic usage :
63
78
64
79
```
65
- $proxy = new UltraSmallProxy($init = true, $rewriteMode = 'regex', $attachToolbar = true);
66
- ```
67
- ` $init ` - autostarts listening for URLs in QUERY STRING, set to ` false ` if you want to disable this feature, default: ` true `
68
-
69
- ` $rewriteMode ` - method used to URLs rewriting, possible values: ` regex ` (rewriting by regular expressions), ` dom ` (rewriting by DOM XML), ` null ` (disable rewriting), default: ` regex `
80
+ $config = new UltraSmallProxyConfig();
81
+ $proxy = new UltraSmallProxy($config);
70
82
71
- ` $attachToolbar ` - appends toolbar DIV, CSS and JS to output when ` true ` , set to ` false ` if you want to disable this feature, default: ` true `
83
+ echo $proxy->load('https://github.com');
84
+ ```
72
85
86
+ ## Configuration:
73
87
74
88
```
75
89
$output = $proxy->load('https://github.com', $force = false);
76
90
```
77
91
` $force ` - if set to ` false ` then URLs given from QUERY STRING are always overwriting URLs passed here, set to ` true ` if you want to reverse this behaviour, default: ` false `
78
92
79
93
80
- ## Public methods :
94
+ ## Config values :
81
95
82
96
Before page load:
83
97
84
- ` $proxy->setUserAgent($agent) ` - sets custom User Agent, defaul : ` Mozilla/4.0 (compatible;) `
98
+ ` $config->set('init', bool); ` - auto-init ` true|false ` , default : ` true `
85
99
86
- ` $proxy->setRewriteMode($rewriteMode) ` - sets URLs rewrite mode : ` regex ` | ` dom ` | ` null `
100
+ ` $config->set('source', 'string'); ` - input source ` domain|ip ` , default : ` domain `
87
101
88
- ` $proxy->setMethod($method) ` - sets request method: ` GET ` | ` POST `
102
+ ` $config->set('raw', bool); ` - raw download ` true|false ` , default: ` false `
89
103
90
- ` $proxy->setCookiesDir($path) ` - sets directory for proxied cookies storage , default: ` cookies `
104
+ ` $config->set('toolbar', bool); ` - attach toolbar ` true|false ` , default: ` true `
91
105
106
+ ` $config->set('user_agent', 'string'); ` - user agent, default: ` Mozilla/4.0 (compatible;) `
92
107
108
+ ` $config->set('timeout', int); ` - curl timeout, default: ` 120 `
93
109
94
- After page load:
110
+ ` $config->set('max_redirects', int); ` - curl max redirects, default: ` 10 `
95
111
96
- ` $siteCookies = $proxy->getSiteCookies() ` - returns cookies[ ] received from proxied site
112
+ ` $config->set('cookies_dir', 'string'); ` - cookies directory, default: ` ./cookies `
97
113
98
- ` $localCookies = $proxy->getLocalCookies() ` - returns cookies [ ] stored localy and sended to proxied site
114
+ ` $config->set('cache_dir', 'string'); ` - cache directory, default: ` ./cache `
99
115
100
- ` $status = $proxy->getStatus() ` - returns connection status [ ]
116
+ ` $config->set('method', 'string'); ` - request method ` GET|POST `
101
117
102
- ` $sid = $proxy->getSid() ` - returns proxied PHPSESSID if exists
118
+ ` $config->set('rewrite', 'string'); ` - rewrite method ` REGEX,REGEX2,REGEX3,DOM ` , default: ` REGEX2 `
103
119
104
- ` $isError = $proxy->isError() ` - returns ` true ` if any error occured, ` false ` if not
120
+ ` $config->set('rewrite_url', bool); ` - enable URL rewriting ` true| false` , default: ` true `
105
121
106
- ` $isCurlError = $proxy->isCurlError() ` - returns ` true ` if curl error occured, ` false ` if not
122
+ ` $config->set('rewrite_img', bool); ` - enable IMG rewriting ` true| false` , default: ` true `
107
123
108
- ` $errorMessages = $proxy->getErrorMessages() ` - returns error messages [ ] if occured
124
+ ` $config->set('rewrite_js', bool); ` - enable JS rewriting ` true|false ` , default: ` true `
109
125
126
+ ` $config->set('rewrite_form', bool); ` - enable FORM ACTION rewriting ` true|false ` , default: ` true `
110
127
111
-
112
- Other:
128
+ ` $config->set('rewrite_css', bool); ` - enable CSS rewriting ` true|false ` , default: ` true `
129
+
130
+ ` $config->set('rewrite_video', bool); ` - enable VIDEO rewriting ` true|false ` , default: ` true `
131
+
132
+ ` $config->set('rewrite_ip', bool); ` - enable domain to IP+Host resolve ` true|false ` , default: ` true `
113
133
114
- ` $parsed = $proxy->parse($html) ` - parse/rewrite URLs in custom html content with selected ` $rewriteMode `
134
+ ` $config->set('assets', 'string'); ` - assets proxying mode ` REDIRECT|CURL ` , default: ` REDIRECT `
115
135
136
+ ` $config->set('is_cfg', bool); ` - show options ` true|false ` , default: ` false `
116
137
138
+ ` $config->set('is_dbg', bool); ` - show debug ` true|false ` , default: ` false `
117
139
140
+ ` $config->set('htaccess_user', 'string'); ` - HTTP AUTH user
141
+
142
+ ` $config->set('htaccess_pass', 'string'); ` - HTTP AUTH password
143
+
144
+
145
+ ## Public methods:
146
+
147
+ After page load:
148
+
149
+ ` $siteCookies = $proxy->cookie->getSiteCookies() ` - returns cookies[ ] received from proxied site
150
+
151
+ ` $localCookies = $proxy->cookie->getLocalCookies() ` - returns cookies[ ] stored localy and sended to proxied site
152
+
153
+ ` $status = $proxy->http->getStatus() ` - returns connection status[ ]
154
+
155
+ ` $headers = $proxy->http->getHeaders() ` - returns received headers[ ]
156
+
157
+ ` $sid = $proxy->getSid() ` - returns proxied PHPSESSID if exists
158
+
159
+ ` $errors = $proxy->getErrors() ` - returns error messages[ ] if occured
160
+
161
+
162
+ Other:
163
+
164
+ ` $parsed = $proxy->render($html) ` - parse/rewrite URLs in custom html content with selected ` $rewriteMode `
165
+
166
+ ---
118
167
119
168
### Ultra Small Proxy is free to use but if you liked then you can donate project via BTC:
120
169
@@ -126,9 +175,7 @@ or by PayPal:
126
175
127
176
Enjoy!
128
177
129
-
130
-
131
- MIT License | 2020 Marcin 'szczyglis' Szczygliński
178
+ MIT License | 2022 Marcin 'szczyglis' Szczygliński
132
179
133
180
https://github.com/szczyglis-dev/php-ultra-small-proxy
134
181
0 commit comments