MainWP Community

Block proxy traffic

Hello, I’m here for the first time.
I use MainWP and think it is a great solution for managing WP-based websites. I have such a problem that I wanted to block proxy traffic by adding functions.php to the theme directory of the following rule:

function shapeSpace_block_proxy_visits() {
if (@fsockopen($_SERVER[‘REMOTE_ADDR’], 80, $errstr, $errno, 1)) {
die(‘Proxy access not allowed’);
}
}
add_action(‘after_setup_theme’, ‘shapeSpace_block_proxy_visits’);

however, the connection to the child site has been broken and cannot reconnect it. After deleting the rule, communication between the WP page and MainWP is possible. Can you help add the MainWP exception to the rule, or have another idea on how to block it?

Have you tried to make exception for your dashboard IP address?

Hi, thanks for the reply.
I don’t have PHP programming knowledge to modify the script. What exception I should write and where?.

I am also not a coder, so I will have to consult our dev team. As soon as I get some info from them, I will update the post.

Hi MAQ, can you try with something like this:

function shapeSpace_block_proxy_visits() {	
	if (@fsockopen($_SERVER["REMOTE_ADDR"], 80, $errstr, $errno, 1) && isset( $_SERVER['HTTP_REFERER'] ) && false === strpos( $_SERVER['HTTP_REFERER'], 'dashboard.site.url' )) { 
        // Note: dashboard.site.url is url of your MainWP Dashboard site.	
		die("Proxy access not allowed");
	}	
}
add_action( "after_setup_theme", "shapeSpace_block_proxy_visits" );

Hi Bogdan
I test Your script on https://hide.me/pl/proxy but not working. The site is still displayed at https://hide.me/pl/proxy, and ‘Proxy access not allowed’ should appear.

If you need custom help for your setup I recommend working with a MainWP Coding Expert