Skip to content

Commit f6624a2

Browse files
committed
release: 2.0
1 parent b6328ba commit f6624a2

File tree

6 files changed

+2066
-633
lines changed

6 files changed

+2066
-633
lines changed

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
temp/
2-
cookies/
3-
.idea/
1+
/cookies/*
2+
/cache/*
3+
/.idea/*
4+
5+
!/cookies/index.html
6+
!/cache/index.html

README.md

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
1-
# [PHP] Ultra Small Proxy
2-
### PHP 5.6+ / PHP 7
1+
# [PHP] Ultra Small Proxy 2
2+
### PHP: 7.0+
33

4-
Current version: 1.1
4+
Current version: **2.0** | 2022-02-23
55

66
Ultra Small Proxy is a light-weight proxy written in PHP.
77

8-
## Features:
8+
## Key Features:
99

1010
- Proxy server written in PHP
1111
- 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)
1313
- Simple and light-weight
1414
- Sessions support
1515
- 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+)**
1620
- GET and POST connections
1721
- Forms submiting support
1822
- 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.)
2125
- 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
2327

28+
## Requirements:
29+
30+
- PHP 7.0+
31+
- CURL extension
32+
- DOM XML extension
2433

2534
## Usage example:
2635
```
2736
<?php
2837
29-
/* include class */
38+
/* include classes */
3039
include __DIR__.'/UltraSmallProxy.php';
3140
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);
3446
3547
/* specify start page and load it! */
3648
$output = $proxy->load('https://github.com');
@@ -40,10 +52,13 @@ echo $output;
4052
4153
```
4254
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!
4358

4459
## Screenshot:
4560

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)
4762

4863

4964
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');
5974
- `loopback.php` - loopback for test features like session support, form vars sending, and cookies redirecting
6075

6176

62-
## Options:
77+
## Basic usage:
6378

6479
```
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);
7082
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+
```
7285

86+
## Configuration:
7387

7488
```
7589
$output = $proxy->load('https://github.com', $force = false);
7690
```
7791
`$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`
7892

7993

80-
## Public methods:
94+
## Config values:
8195

8296
Before page load:
8397

84-
`$proxy->setUserAgent($agent)` - sets custom User Agent, defaul: `Mozilla/4.0 (compatible;)`
98+
`$config->set('init', bool);`- auto-init `true|false`, default: `true`
8599

86-
`$proxy->setRewriteMode($rewriteMode)` - sets URLs rewrite mode: `regex`|`dom`|`null`
100+
`$config->set('source', 'string');` - input source `domain|ip`, default: `domain`
87101

88-
`$proxy->setMethod($method)` - sets request method: `GET`|`POST`
102+
`$config->set('raw', bool);` - raw download `true|false`, default: `false`
89103

90-
`$proxy->setCookiesDir($path)` - sets directory for proxied cookies storage, default: `cookies`
104+
`$config->set('toolbar', bool);` - attach toolbar `true|false`, default: `true`
91105

106+
`$config->set('user_agent', 'string');` - user agent, default: `Mozilla/4.0 (compatible;)`
92107

108+
`$config->set('timeout', int);` - curl timeout, default: `120`
93109

94-
After page load:
110+
`$config->set('max_redirects', int);` - curl max redirects, default: `10`
95111

96-
`$siteCookies = $proxy->getSiteCookies()` - returns cookies[] received from proxied site
112+
`$config->set('cookies_dir', 'string');` - cookies directory, default: `./cookies`
97113

98-
`$localCookies = $proxy->getLocalCookies()` - returns cookies[] stored localy and sended to proxied site
114+
`$config->set('cache_dir', 'string');` - cache directory, default: `./cache`
99115

100-
`$status = $proxy->getStatus()` - returns connection status[]
116+
`$config->set('method', 'string');` - request method `GET|POST`
101117

102-
`$sid = $proxy->getSid()` - returns proxied PHPSESSID if exists
118+
`$config->set('rewrite', 'string');` - rewrite method `REGEX,REGEX2,REGEX3,DOM`, default: `REGEX2`
103119

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`
105121

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`
107123

108-
`$errorMessages = $proxy->getErrorMessages()` - returns error messages[] if occured
124+
`$config->set('rewrite_js', bool);` - enable JS rewriting `true|false`, default: `true`
109125

126+
`$config->set('rewrite_form', bool);` - enable FORM ACTION rewriting `true|false`, default: `true`
110127

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`
113133

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`
115135

136+
`$config->set('is_cfg', bool);` - show options `true|false`, default: `false`
116137

138+
`$config->set('is_dbg', bool);` - show debug `true|false`, default: `false`
117139

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+
---
118167

119168
### Ultra Small Proxy is free to use but if you liked then you can donate project via BTC:
120169

@@ -126,9 +175,7 @@ or by PayPal:
126175

127176
Enjoy!
128177

129-
130-
131-
MIT License | 2020 Marcin 'szczyglis' Szczygliński
178+
MIT License | 2022 Marcin 'szczyglis' Szczygliński
132179

133180
https://github.com/szczyglis-dev/php-ultra-small-proxy
134181

0 commit comments

Comments
 (0)