-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy path23-server-blacklist.php
More file actions
35 lines (27 loc) · 1.44 KB
/
23-server-blacklist.php
File metadata and controls
35 lines (27 loc) · 1.44 KB
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
<?php
// A more advanced example which runs a SOCKS proxy server that rejects connections
// to some domains (blacklist /filtering).
// The listen address can be given as first argument and defaults to 127.0.0.1:1080 otherwise.
//
// See also examples #12 and #14 for the client side.
// Client example #12 is expected to fail because port 80 is blocked in this server example.
// Client example #14 is expected to succceed because it is not blacklisted.
require __DIR__ . '/../vendor/autoload.php';
// create a connector that rejects the connection
$reject = new ConnectionManager\Extra\ConnectionManagerReject();
// create an actual connector that establishes real connections
$permit = new React\Socket\Connector();
// this connector selectively picks one of the the attached connectors depending on the target address
// reject youtube.com and unencrypted HTTP for google.com
// default connctor: permit everything
$connector = new ConnectionManager\Extra\Multiple\ConnectionManagerSelective(array(
'*.youtube.com' => $reject,
'www.google.com:80' => $reject,
'*' => $permit
));
// start a new SOCKS proxy server using our connection manager for outgoing connections
$socks = new Clue\React\Socks\Server(null, $connector);
// listen on 127.0.0.1:1080 or first argument
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:1080');
$socks->listen($socket);
echo 'SOCKS server listening on ' . $socket->getAddress() . PHP_EOL;