Skip to content

Commit

Permalink
Updated to v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
szczyglis-dev committed Apr 23, 2022
1 parent b992bf7 commit feecc86
Show file tree
Hide file tree
Showing 14 changed files with 2,503 additions and 2,371 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.idea/*

!/cookies/index.html
!/cache/index.html
!/cache/index.html
/vendor/
139 changes: 75 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
# [PHP] Ultra Small Proxy 2
### PHP: 7.0+
### PHP: 7.2.5+

Current version: **2.0** | 2022-02-23
Current version: **2.1** | 2022-04-23

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

## Key Features:
**Install with composer:**
```
composer require szczyglis/php-ultra-small-proxy
```

## Features:

- Proxy server written in PHP
- Easy usage and integration
- Standalone and external usage (it is only one PHP file)
- Simple and light-weight
- Sessions support
- Sending and receiving cookies
- Sending and receiving HTTP headers **(NEW in 2.0+)**
- Cache and assets storage **(NEW in 2.0+)**
- Domain and IP/host connection support **(NEW in 2.0+)**
- HTTP Basic Auth support **(NEW in 2.0+)**
- Sending and receiving HTTP headers
- Cache and assets storage
- Domain and IP/host connection support
- HTTP Basic Auth support
- GET and POST connections
- Forms submiting support
- POST variables redirecting
- Toolbar with address bar, configuration and debugger
- URLs rewriting/proxying at runtime (links, images, css, javascript, etc.)
- 2 different methods for URLs rewriting: Regex (with preg_replace) and DOM XML (with libxml / DOMDocument)
- PHP 7.0+ supported
- 2 different methods for URLs rewriting: Regex (with preg_replace) and XML (with libxml/DOM)
- PHP 7.2.5+ supported

## Requirements:

- PHP 7.0+
- CURL extension
- DOM XML extension
- PHP 7.2.5+ with CURL and XML extensions
- Composer


## Usage example:
```
```php
<?php

/* include classes */
include __DIR__.'/UltraSmallProxy.php';
require __DIR__ . '/vendor/autoload.php';

/* instantiate config */
$config = new UltraSmallProxyConfig();
use Szczyglis\UltraSmallProxy\UltraSmallProxy;
use Szczyglis\UltraSmallProxy\Config;

/* instantiate proxy with config */
$proxy = new UltraSmallProxy($config);
$config = new Config();

/* specify start page and load it! */
$output = $proxy->load('https://github.com');
$proxy = new UltraSmallProxy($config);

/* render output */
echo $output;
echo $proxy->load('https://github.com'); // <-- specify start page here

```
Make sure to have write permissions to `./cookies` and `./cache` directories.
Expand All @@ -60,109 +60,118 @@ Make sure to have write permissions to `./cookies` and `./cache` directories.
![proxy](https://user-images.githubusercontent.com/61396542/155353063-fde84995-6e43-46c4-8a1c-b8b4772e6dfc.png)


Open `loopback.php`if you want to test proxy features like sessions support, POST vars redirecting, form submiting and more, e.g.:
Open `loopback.php` if you want to test proxy features like sessions support, POST vars redirecting, form submiting and more, e.g.:
```
<?php
$output = $proxy->load('http://localhost/loopback.php');
```

## Repository contents:

- `UltraSmallProxy.php` - proxy class
- `src/` - proxy classes

- `index.php` - usage example

- `loopback.php` - loopback for test features like session support, form vars sending, and cookies redirecting


## Basic usage:

```
$config = new UltraSmallProxyConfig();
```php
use Szczyglis\UltraSmallProxy\UltraSmallProxy;
use Szczyglis\UltraSmallProxy\Config;

$config = new Config();
$proxy = new UltraSmallProxy($config);

echo $proxy->load('https://github.com');
```

## Configuration:

```
```php
$output = $proxy->load('https://github.com', $force = false);
```
`$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`
boolean `$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`


## Config values:

Before page load:
**Before page load:**

`$config->set('init', bool);`- auto-init `true|false`, default: `true`
**$config->set('init', true)** - `boolean`, auto-init `true|false`, default: `true`

`$config->set('source', 'string');` - input source `domain|ip`, default: `domain`
**$config->set('source', 'domain')** - `string`, input source `domain|ip`, default: `domain`

`$config->set('raw', bool);` - raw download `true|false`, default: `false`
**$config->set('raw', false)** - `boolean`, raw download `true|false`, default: `false`

`$config->set('toolbar', bool);` - attach toolbar `true|false`, default: `true`
**$config->set('toolbar', true)** - `boolean`, attach toolbar `true|false`, default: `true`

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

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

`$config->set('max_redirects', int);` - curl max redirects, default: `10`
**$config->set('max_redirects', 10)** - `int`, curl max redirects, default: `10`

`$config->set('cookies_dir', 'string');` - cookies directory, default: `./cookies`
**$config->set('cookies_dir', './cookies')** - `string`, cookies directory, default: `./cookies`

`$config->set('cache_dir', 'string');` - cache directory, default: `./cache`
**$config->set('cache_dir', './cache')** - `string`, cache directory, default: `./cache`

`$config->set('method', 'string');` - request method `GET|POST`
**$config->set('method', 'GET')** - `string`, request method `GET|POST`

`$config->set('rewrite', 'string');` - rewrite method `REGEX,REGEX2,REGEX3,DOM`, default: `REGEX2`
**$config->set('rewrite', 'REGEX2')** - `string`, rewrite method `REGEX,REGEX2,REGEX3,DOM`, default: `REGEX2`

`$config->set('rewrite_url', bool);` - enable URL rewriting `true|false`, default: `true`
**$config->set('rewrite_url', true)** - `boolean`, enable URL rewriting `true|false`, default: `true`

`$config->set('rewrite_img', bool);` - enable IMG rewriting `true|false`, default: `true`
**$config->set('rewrite_img', true)** - `boolean`, enable IMG rewriting `true|false`, default: `true`

`$config->set('rewrite_js', bool);` - enable JS rewriting `true|false`, default: `true`
**$config->set('rewrite_js', true)** - `boolean`, enable JS rewriting `true|false`, default: `true`

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

`$config->set('rewrite_css', bool);` - enable CSS rewriting `true|false`, default: `true`
**$config->set('rewrite_css', true)** - `boolean`, enable CSS rewriting `true|false`, default: `true`

`$config->set('rewrite_video', bool);` - enable VIDEO rewriting `true|false`, default: `true`
**$config->set('rewrite_video', true)** - `boolean`, enable VIDEO rewriting `true|false`, default: `true`

`$config->set('rewrite_ip', bool);` - enable domain to IP+Host resolve `true|false`, default: `true`
**$config->set('rewrite_ip', true)** - `boolean`, enable domain to IP+Host resolve `true|false`, default: `true`

`$config->set('assets', 'string');` - assets proxying mode `REDIRECT|CURL`, default: `REDIRECT`
**$config->set('assets', 'REDIRECT')** - `string`, assets proxying mode `REDIRECT|CURL`, default: `REDIRECT`

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

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

`$config->set('htaccess_user', 'string');` - HTTP AUTH user
**$config->set('htaccess_user', 'user')** - `string`, HTTP AUTH user

`$config->set('htaccess_pass', 'string');` - HTTP AUTH password
**$config->set('htaccess_pass', 'pass')** - `string`, HTTP AUTH password


## Public methods:

After page load:
**After page load:**

`$siteCookies = $proxy->cookie->getSiteCookies()` - returns cookies[] received from proxied site
**$siteCookies = $proxy->cookie->getSiteCookies()** - returns cookies[] received from proxied site

`$localCookies = $proxy->cookie->getLocalCookies()` - returns cookies[] stored localy and sended to proxied site
**$localCookies = $proxy->cookie->getLocalCookies()** - returns cookies[] stored localy and sended to proxied site

`$status = $proxy->http->getStatus()` - returns connection status[]
**$status = $proxy->http->getStatus()** - returns connection status[]

`$headers = $proxy->http->getHeaders()` - returns received headers[]
**$headers = $proxy->http->getHeaders()** - returns received headers[]

`$sid = $proxy->getSid()` - returns proxied PHPSESSID if exists
**$sid = $proxy->getSid()** - returns proxied PHPSESSID if exists

`$errors = $proxy->getErrors()` - returns error messages[] if occured
**$errors = $proxy->getErrors()** - returns error messages[] if occured


Other:
**Others:**

`$parsed = $proxy->render($html)` - parse/rewrite URLs in custom html content with selected `$rewriteMode`
$parsed = $proxy->render($html) - parse/rewrite URLs in custom html content with selected `$rewriteMode`

---

### Changelog

- `2.1` -- package was added to packagist (2022-04-23)

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

Expand All @@ -172,10 +181,12 @@ or by PayPal:
**[https://www.paypal.me/szczyglinski](https://www.paypal.me/szczyglinski)**


Enjoy!
**Enjoy!**

MIT License | 2022 Marcin 'szczyglis' Szczygliński

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

https://szczyglis.dev

Contact: szczyglis@protonmail.com
Loading

0 comments on commit feecc86

Please sign in to comment.