-
Notifications
You must be signed in to change notification settings - Fork 1
/
iptables.php
36 lines (28 loc) · 897 Bytes
/
iptables.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
<?php
define('SITE_DIR', dirname(__FILE__));
require_once SITE_DIR .'/db-api.php';
DbAPI::init(SITE_DIR.'/db/openvz-iptables.db');
if(!DbAPI::needSync()) {
exit(1);
}
$wanIP = 'xx.xx.xx.xx';
$wanIF = 'eth0';
$str = array();
$portsFwd = DbAPI::getPorts();
$identity = null;
foreach($portsFwd as $portFwd) {
if($identity != $portFwd['node_id']) {
$str []= "\n".'## VPS '.$portFwd['node_id'];
}
$str []= sprintf(
'/sbin/iptables -t nat -A PREROUTING -p %s -d %s --dport %s -i %s -j DNAT --to-destination %s:%s',
$portFwd['proto'], $wanIP, $portFwd['port_from'], $wanIF, $portFwd['ip_address'], $portFwd['port_to']
);
$identity = $portFwd['node_id'];
}
file_put_contents(SITE_DIR.'/all', implode("\n", $str));
shell_exec(SITE_DIR.'/main');
shell_exec('chmod 755 '.SITE_DIR.'/all');
shell_exec(SITE_DIR.'/all');
DbAPI::successSync();
exit('OK');