<config>


//////////////
//
//  Proxy Blocker v1.2b by Pri (28th of June 2011)
//  This script requires Metis v2.80 & RoboMX v2.08
//  Please use Metis v2.81 for the smoothest experience: http://bit.ly/ldk6C3
//  Website: http://www.renmx.com
//  Forum: http://www.mxpulse.com/board
//
///////  COMMANDS
//
//  !Download - Forcibly check for recent Proxy Servers to Ban that were used in other rooms
//  !Proxy [IP Address] - Check if an IP Address is a known Proxy Server or not
//
///////  SERVER SUPPORT
//
//  WCS, RCS, ZCS, RSWCS, and FXServer are all supported out of the box
//  ZCS support is limited, WCS, RSWCS or FXServe are recommended.
//
//////////////

<OnEnter type="script">
// Clear some variables for a clean run
<out type="pop" extdata="Proxy_UI_Result"/>
<out type="pop" extdata="Private_IP_Detected"/>
// Break if the IP is private (127.0.0.1, 192.168.x.x, 10.0.x.x and so on)
<out type="push" extdata="Joined_IP">:%IP%</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="127.0.0.1">1</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="0.0.0.0">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":169.254.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.16.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.17.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.18.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.19.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.20.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.21.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.22.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.23.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.24.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.25.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.26.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.27.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.28.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.29.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.30.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.31.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":192.168.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":10.">1</out>
<out type="break" condition="==" lvalue="%USERVAR[Private_IP_Detected]%" rvalue="1"></out>
// Check that the user has the correct version of Metis to run this script by quering server and checking for a file, if this file doesn't display right tell the user to update
// The reason this variable is called Pulse is because it shares this variable among all my scripts to make sure the right Metis is being used, saves queries
<out type="push" extdata="Pulse_Metis_Check" condition="==" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.check.ini" lvalue="l" rvalue="1"/></out>
// If the server is down (And this is running Metis 2.8b1 modified by Pri) then detect that the server went down and break here
<out type="break" condition="?" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue="Error: The operation timed out"></out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You appear to be running an outdated version of Metis.</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You can download the latest one here#c63#: #c62#http://bit.ly/ldk6C3</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#To install this file replace your old Metis.r2x file located in your script plugins folder</out>
<out type="break" condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849"></out>
// Check if the user is using Metis v2.81, if not suggest version v2.81 - Only make this recommendation once
<out type="push" extdata="ReminderCount" condition="!=" lvalue="%VERSION%" rvalue="2.81"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.Metis.Version.Reminder.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="ReminderCount" condition="!=" lvalue="%VERSION%" rvalue="2.81"><operator type="+" lvalue="$ReminderCount$" rvalue="1"/></out>
<out condition="!=" lvalue="%VERSION%" rvalue="2.81" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.Metis.Version.Reminder.ini" mode="t">$ReminderCount$</out>
<out type="goto" extdata="3" condition=">" lvalue="$ReminderCount$" rvalue="1"></out> 
<out condition="!=" lvalue="%VERSION%" rvalue="2.81">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#This script will function much better with Metis version 2.81#c63#: #c62#http://bit.ly/ldk6C3</out>
<out condition="!=" lvalue="%VERSION%" rvalue="2.81">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#Reminder #c62#1#c9# of 1</out>
// Check that the scripts folder and settings file has been setup. If it hasn't do it.
<out type="push" extdata="Prox_Setup_Check"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.proxy.setup.check.ini" lvalue="l" rvalue="1"/></out>
<out condition="!=" lvalue="$Prox_Setup_Check$" rvalue="2" type="exec" extdata="1">cmd.exe /c MD C:\Pri.Script.Dependencies\Proxy.Blocker\Cache</out>
<out condition="!=" lvalue="$Prox_Setup_Check$" rvalue="2" type="sleep" extdata="3000"></out>
<out condition="!=" lvalue="$Prox_Setup_Check$" rvalue="2" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.proxy.setup.check.ini" mode="t">2\nv1.2b</out>
// Create a Whitelist File if one doesn't exsist and tell the admins how to use it
<out type="push" extdata="Whitelist_Result"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.Whitelist.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$Whitelist_Result$" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#A Whitelist file has been created here#c63#: #c62#C:\Pri.Script.Dependencies\Proxy.Blocker\.Whitelist.ini</out>
<out condition="==" lvalue="$Whitelist_Result$" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You may fill this file with Proxy IP's or Usernames of the people you trust to use Proxy Servers</out>
<out condition="==" lvalue="$Whitelist_Result$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.Whitelist.ini" mode="t">You can place Proxy Server IP's OR Usernames in this file, one entry per line, unlimited size, Please do not delete this line explaining how to use the file!\n</out>
// Create an 'Exile to x Room' file if one doesn't exsist and tell the admins how to use it
<out type="push" extdata="Exileroom_Result"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.exile.room.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$Exileroom_Result$" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#An Exile File has been created here#c63#: #c62#C:\Pri.Script.Dependencies\Proxy.Blocker\.exile.room.ini</out>
<out condition="==" lvalue="$Exileroom_Result$" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You can put your main room name here for the Proxy Blocker to exile users to it #c63#(#c62#Once Verified#c63#)</out>
<out condition="==" lvalue="$Exileroom_Result$" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#If you do not need this feature simply leave the file as-is and users will not be exiled anywhere</out>
<out condition="==" lvalue="$Exileroom_Result$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.exile.room.ini" mode="t">Enter the name of your room on the line directly below this one, Make sure it's the correct address. DO NOT DELETE THIS LINE OR BAD THINGS WILL HAPPEN!\n</out>
// Download some special characters required for this to function (Metis by itself doesn't allow these characters inside the code so they have to be loaded as varibles)
<out type="push" extdata="Special_1" condition="==" lvalue="%USERVAR[Special_1]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Special_3" condition="==" lvalue="%USERVAR[Special_3]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="3"/></out>
// If the IP supplied to the bot is blank then load in the Access Level reminder counter (should be blank at first, then goes up to 3+)
<out type="push" extdata="ReminderCount" condition="==" lvalue="%IP%" rvalue=""><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.Bot.Access.Level.Reminder.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="ReminderCount" condition="==" lvalue="%IP%" rvalue=""><operator type="+" lvalue="$ReminderCount$" rvalue="1"/></out>
<out condition="==" lvalue="%IP%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.Bot.Access.Level.Reminder.ini" mode="t">$ReminderCount$</out>
// Break if the IP is blank then tell the Admins that they need to give their Bot high enough access to see IP Addresses
<out type="goto" extdata="3" condition=">" lvalue="$ReminderCount$" rvalue="3"></out> 
<out condition="==" lvalue="%IP%" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#Your bot doesn't have a high enough access level to see the IP's of people who enter your room, Try logging it in as Admin or Host to correct this, or make your bot its own password with the necessary access level</out>
<out condition="==" lvalue="%IP%" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#Reminder #c62#%USERVAR[ReminderCount]%#c9# of 3</out>
<out type="break" condition="==" lvalue="%IP%" rvalue=""></out>
// Sometimes the creation of the Folder for the Setup Check is too slow causing the install check file to not save, so let's just re-attempt that if this is a first time install
<out condition="!=" lvalue="$Prox_Setup_Check$" rvalue="2" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.proxy.setup.check.ini" mode="t">2\nv1.2b</out>
// Reference the Whitelist file incase this user has been given permission to use a Proxy Server in this room
// The whitelist checks for both a designated Proxy Server IP Address and the users Username from this file
<out type="push" extdata="Proxy_Permission">0</out>
<out type="push" extdata="Whitelist_Line">0</out>
<out type="push" extdata="Whitelist_Line"><operator type="+" lvalue="$Whitelist_Line$" rvalue="1"/></out>
<out type="push" extdata="Whitelist_Result"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.Whitelist.ini" lvalue="l" rvalue="$Whitelist_Line$"/></out>
<out type="push" extdata="Proxy_Permission" condition="==" lvalue="%NAME%" rvalue="%USERVAR[Whitelist_Result]%">1</out>
<out type="push" extdata="Proxy_Permission" condition="==" lvalue="%IP%" rvalue="%USERVAR[Whitelist_Result]%">1</out>
<out type="goto" extdata="2" condition="==" lvalue="%USERVAR[Proxy_Permission]%" rvalue="1"></out>
<out type="goto" extdata="-5" condition="!=" lvalue="%USERVAR[Whitelist_Result]%" rvalue=""></out>
// Check the Cache for this IP, if the IP is found don't query the IP with the API and just push it to the API Result variable
<out type="push" extdata="Live_Check_Cache_Date"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%IP%.Live.Cache.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Live_Check_Cache_Content" condition="==" lvalue="%USERVAR[Live_Check_Cache_Date]%" rvalue="%DAY%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%IP%.Live.Cache.ini" lvalue="l" rvalue="2"/></out>
// Check the Cache output for a proxy or not and push those variables so that duplicate queries are not made within the past day for this IP
<out type="push" extdata="Proxy_Server_API_Result" condition="==" lvalue="%USERVAR[Live_Check_Cache_Content]%" rvalue="1">Proxy Detected in the Cache</out>
<out type="push" extdata="Proxy_Server_API_Result" condition="==" lvalue="%USERVAR[Live_Check_Cache_Content]%" rvalue="0">0</out>
<out type="goto" extdata="12" condition="==" lvalue="%USERVAR[Live_Check_Cache_Date]%" rvalue="%DAY%"></out>
// Query the Proxy API to see if this IP Address is a proxy or not
<out type="push" extdata="Proxy_Server_API_Result"><operator type="readweb" nvalue="http://winmxunlimited.net/utilities/api/proxy/check.php?ip=%IP%%USERVAR[Special_1]%winmx=1" lvalue="l" rvalue="1"/></out>
// If the winmxunlimited API is down use the MXPulse version of the API instead, if MXPulse API is also down break
<out type="push" extdata="Use_MXPulse_API">1</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="0" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Proxy_Server_API_Result" condition="==" lvalue="1" rvalue="%USERVAR[Use_MXPulse_API]%"><operator type="readweb" nvalue="http://private.proxy.mxpulse.com/Proxy.API.php?ip=%IP%%USERVAR[Special_1]%winmx=1" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Use_MXPulse_API">1</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="0" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="break" condition="==" lvalue="%USERVAR[Use_MXPulse_API]%" rvalue="1"></out>
// Format the API output to make it a little nicer
<out type="push" extdata="Proxy_UI_Result">%USERVAR[Proxy_Server_API_Result]%</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">Random Public Proxy</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">Tor Proxy</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
// If the user had permission to use a proxy do not kick them but tell the admins they are using a proxy if they are
<out type="goto" extdata="2" condition="==" lvalue="%USERVAR[Proxy_Permission]%" rvalue="0"></out>
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">/opmsg #c10#%NAME% #c9#is using a Proxy but has permission and won't be kicked. #c63#(#c62#%USERVAR[Proxy_UI_Result]%#c63#)</out>
// If a match was found, Kick/Ban and alert admins to this users Proxy use unless they had permission in which case skip this part
<out type="goto" extdata="4" condition="==" lvalue="%USERVAR[Proxy_Permission]%" rvalue="1"></out>
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">/banip %IP% 1440</out>
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">/kick %RAWNAME%</out>
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">/opmsg #c10#%NAME% #c9#is using a Proxy and has had their IP banned for 24 Hours. #c63#(#c62#%USERVAR[Proxy_UI_Result]%#c63#)</out>
// If the user has setup the exile in the exile.room.ini file then exile this user to that room if they are not a Proxy Server, Just exile if the user is Whitelisted however
<out type="push" extdata="Exileroom_Result"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.exile.room.ini" lvalue="l" rvalue="2"/></out>
<out type="goto" extdata="4" condition="==" lvalue="%USERVAR[Exileroom_Result]%" rvalue=""></out>
<out type="goto" extdata="2" condition="==" lvalue="%USERVAR[Proxy_Permission]%" rvalue="1"></out>
<out type="goto" extdata="2" condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0"></out>
<out>/exile %RAWNAME% %USERVAR[Exileroom_Result]%</out>
// Replace some symbols from the name that just don't work in a httpget request to the web server, and other characters we just don't want saved
<out type="push" extdata="Cleaned_Name">%RAWNAME%</out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_1]%lowast;" rvalue="[star]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_1]%" rvalue="[and]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="\" rvalue="[bslash]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="/" rvalue="[fslash]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_3]%" rvalue="[dollar]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="#" rvalue="[hash]"/></out>
// Replace some symbols from the Roomname that don't work in httpget requests - Send the roomname to the Analytics API only if a Proxy was kicked from this room
<out type="push" extdata="Cleaned_Room">%ROOMNAME%</out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="%USERVAR[Special_1]%lowast;" rvalue="[star]"/></out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="%USERVAR[Special_1]%" rvalue="[and]"/></out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="\" rvalue="[bslash]"/></out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="/" rvalue="[fslash]"/></out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="%USERVAR[Special_3]%" rvalue="[dollar]"/></out>
<out type="push" extdata="Cleaned_Room"><operator type="strrep" nvalue="%USERVAR[Cleaned_Room]%" lvalue="#" rvalue="[hash]"/></out>
// If this user was detected as using a proxy, send the IP, Username and Room Name to MXPulse (Analytical data for Pri)
<out type="push" extdata="Analytics_Response" condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0"><operator type="readweb" nvalue="http://analytics.mxpulse.com/v1/?ip=%IP%&amp;name=%USERVAR[Cleaned_Name]%&amp;room=%USERVAR[Cleaned_Room]%&amp;via=%USERVAR[Proxy_UI_Result]%" lvalue="l" rvalue="1"/></out>
// Create a cache for this IP so that we don't query it again atleast within 24 hours
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%IP%.Live.Cache.ini" mode="t">%DAY%\n1\n%USERVAR[Proxy_UI_Result]%\nBanned from inside your room\n%DAY%</out>
<out condition="==" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%IP%.Live.Cache.ini" mode="t">%DAY%\n0\nNot detected as a Proxy\nUsername: %RAWNAME%</out>
// Check for recent bans on the API and cache those
<out type="self" condition="!=" lvalue="%USERVAR[Proxy_Previous_Download_Minute]%" rvalue="%MINUTE%">!botpreempban</out>
// Break here if this is a proxy, only check for updates when the user has not been detected as a proxy
<out type="break" condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0"></out>
// Check for an updated version of this script
<out type="push" extdata="Version_Info">v1.2b</out>
<out type="pop" extdata="Version_Release_Message"/>
<out type="push" extdata="Version_Check_Date"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\.Version.Check.Date.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Info" condition="!=" lvalue="%USERVAR[Version_Check_Date]%" rvalue="%DATE%"><operator type="readweb" nvalue="http://private.proxy.mxpulse.com/Version.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Release_Message" condition="!=" lvalue="%USERVAR[Version_Info]%" rvalue="v1.2b"><operator type="readweb" nvalue="http://private.proxy.mxpulse.com/Version.ini" lvalue="l" rvalue="2"/></out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#%USERVAR[Version_Release_Message]%</out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\.Version.Check.Date.txt" mode="t">%DATE%\n%USERVAR[Version_Info]%</out>
</OnEnter>


<command type="script">
<in>!proxy %PARAM%</in>
// Check that the command was used at the beginning of a sentence
<out type="push" extdata="req">%TRIGGER%</out>
<out type="push" extdata="req"><operator type="strleft" lvalue="$req$" rvalue="7"/></out>
<out type="break" condition="!_?" lvalue="$req$" rvalue="!proxy "></out>
// Break if the IP is private (127.0.0.1, 192.168.x.x, 10.0.x.x and so on)
<out type="push" extdata="Joined_IP">:%IP%</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="127.0.0.1">1</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="0.0.0.0">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":169.254.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.16.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.17.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.18.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.19.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.20.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.21.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.22.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.23.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.24.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.25.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.26.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.27.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.28.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.29.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.30.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.31.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":192.168.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":10.">1</out>
<out type="break" condition="==" lvalue="%USERVAR[Private_IP_Detected]%" rvalue="1"></out>
// Break if input doesn't contain a dot (just a really basic check to see if this is actually an IP Address, it isn't full proof but lots more code would be needed to properly verify input with Metis)
<out condition="!?" lvalue="%PARAM%" rvalue=".">#c62#Your parameter #c63#"#c4#%PARAM%#c63#" #c62#is not a valid IP Address. Valid Example#c63#: #c4#!proxy 137.56.163.46</out>
<out type="break" condition="!?" lvalue="%PARAM%" rvalue="."></out>
// Push the PARAM to a variable so that it works inside the readweb operator
<out type="push" extdata="Proxy_Query_IP">%PARAM%</out>
// Check that the user has the correct version of Metis to run this script by quering server and checking for a file, if this file doesn't display right tell the user to update
// The reason this variable is called Pulse is because it shares this variable among all my scripts to make sure the right Metis is being used, saves queries
<out type="push" extdata="Pulse_Metis_Check" condition="==" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.check.ini" lvalue="l" rvalue="1"/></out>
// If the server is down (And this is running Metis 2.8b1 modified by Pri) then detect that the server went down and break here
<out type="break" condition="?" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue="Error: The operation timed out"></out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You appear to be running an outdated version of Metis.</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#You can download the latest one here#c63#: #c62#http://bit.ly/ldk6C3</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#To install this file replace your old Metis.r2x file located in your script plugins folder</out>
<out type="break" condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849"></out>
// Query the Proxy API to see if this IP Address is a proxy or not
<out type="push" extdata="Proxy_Server_API_Result"><operator type="readweb" nvalue="http://winmxunlimited.net/utilities/api/proxy/check.php?ip=%USERVAR[Proxy_Query_IP]%" lvalue="l" rvalue="1"/></out>
// If the winmxunlimited API is down use the MXPulse version of the API instead, if MXPulse API is also down break
<out type="push" extdata="Use_MXPulse_API">1</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="0" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Proxy_Server_API_Result" condition="==" lvalue="1" rvalue="%USERVAR[Use_MXPulse_API]%"><operator type="readweb" nvalue="http://private.proxy.mxpulse.com/Proxy.API.php?ip=%USERVAR[Proxy_Query_IP]%" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Use_MXPulse_API">1</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="push" extdata="Use_MXPulse_API" condition="==" lvalue="0" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
<out type="break" condition="==" lvalue="%USERVAR[Use_MXPulse_API]%" rvalue="1"></out>
// Format the API output to make it a little nicer
<out type="push" extdata="Proxy_UI_Result">%USERVAR[Proxy_Server_API_Result]%</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="Live" rvalue="%USERVAR[Proxy_Server_API_Result]%">Random Public Proxy</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="Tor" rvalue="%USERVAR[Proxy_Server_API_Result]%">Tor Proxy</out>
<out type="push" extdata="Proxy_UI_Result" condition="==" lvalue="" rvalue="%USERVAR[Proxy_Server_API_Result]%">0</out>
// Tell the user if the IP they have queries is a proxy server or not
<out condition="==" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">#c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c62#%PARAM%#c63#: #c4#This IP is believed not to be a Proxy Server.</out>
<out condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="0">#c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c62#%PARAM%#c63#: #c8#Known Proxy Server #c63#(#c62#%USERVAR[Proxy_UI_Result]%#c63#)</out>
</command>


<OnRename type="script">
// This part of the script will check if there is any new IP's to be banned anytime someone in your room changes their username.
// I've used this method because I do not want to use an OnTimer event as Metis only allows 1 to be used per Bot and I wouldn't want to 'steal' your only OnTimer and possibly break other scripts you are using.
// Check for recent bans on the API and cache those
<out type="self" condition="!=" lvalue="%USERVAR[Proxy_Previous_Download_Minute]%" rvalue="%MINUTE%">!botpreempban</out>
</OnRename>


<command type="script">
<in>!botpreempban</in>
<in>!download</in>
// Check if a pre-emptive ban check has already been done in the past minute, if it has break
<out type="push" extdata="Proxy_Previous_Download_Minute">%MINUTE%</out>
// Generate a random number to be used in the query to the API to make sure the results are not from the readweb cache
<out type="push" extdata="Random_Number">%RANDOMNUM[1337]%</out>
// Pick the appropriate command to be used for different servers. Use /banip as the default however.
<out type="push" extdata="Server_Appropriate_CMD">/banip</out>
<out type="push" extdata="Server_Appropriate_CMD" condition="_?" lvalue="%SERVER%" rvalue="RCS">/hidecmd /banip</out>
<out type="push" extdata="Server_Appropriate_CMD" condition="_?" lvalue="%SERVER%" rvalue="WCS">/hidecmd /banip</out>
// Read in recent ban (start line 20 then go down) - Due to the way this is coded it actually starts with line 21 but its then reduced to line 20 before it begins reading the actual webpage
<out type="push" extdata="Proxy_Server_API_Result_Line">21</out>
// Set the Ban Message to off for a clean run
<out type="push" extdata="IP_Ban_Message">0</out>
// Set the banned IP Count to 0 for a clean run
<out type="push" extdata="Amount_of_Proxies_Banned">0</out>
// Reduce the line we are reading by 1, the reason we read the highest line first is so that Metis can cache all the lines and then reference that, basically for performance
<out type="push" extdata="Proxy_Server_API_Result_Line"><operator type="-" lvalue="%USERVAR[Proxy_Server_API_Result_Line]%" rvalue="1"/></out>
// Read in the webpage on the Line we have selected
<out type="push" extdata="Proxy_Server_API_Result"><operator type="readweb" nvalue="http://winmxunlimited.net/utilities/api/proxy/tools/recentdetections.php?rand=%USERVAR[Random_Number]%" lvalue="l" rvalue="%USERVAR[Proxy_Server_API_Result_Line]%"/></out>
// If the divider [:@:] isn't found in the server output then consider the server bugged out or missing data and skip this line
<out type="goto" extdata="12" condition="!?" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="[:@:]"></out>
// Replace the data seperator with something more Metis friendly
<out type="push" extdata="Proxy_Server_API_Result"><operator type="strrep" nvalue="%USERVAR[Proxy_Server_API_Result]%" lvalue="[:@:]" rvalue="^"/></out>
// Find the new seperator and push the variables on both sides (Left = IP, Right = Proxy Type)
<out type="push" extdata="Found_Divider"><operator type="strrfind" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="^"/></out>
<out type="push" extdata="Cache_Line01"><operator type="strleft" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="$Found_Divider$"/></out>
<out type="push" extdata="Found_Divider"><operator type="+" lvalue="%USERVAR[Found_Divider]%" rvalue="1"/></out>
<out type="push" extdata="Cache_Line02"><operator type="strright" lvalue="%USERVAR[Proxy_Server_API_Result]%" rvalue="$Found_Divider$"/></out>
// Check that this Proxy wasn't already banned in the past 24 hours, if it was then just skip forward to the next IP
<out type="push" extdata="Cache_Line03"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%USERVAR[Cache_Line01]%.Live.Cache.ini" lvalue="l" rvalue="5"/></out>
<out type="goto" extdata="5" condition="==" lvalue="%USERVAR[Cache_Line03]%" rvalue="%DAY%"></out>
// Save this Proxy to the local cache so that the system doesn't try and ban it again for 24 hours
<out condition="!=" lvalue="%USERVAR[Cache_Line01]%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Proxy.Blocker\Cache\%USERVAR[Cache_Line01]%.Live.Cache.ini" mode="t">%DAY%\n1\n%USERVAR[Cache_Line02]%\nPre-emptive Ban from the API\n%DAY%</out>
// Ban the IP in the rooms server
<out condition="!=" lvalue="%USERVAR[Cache_Line01]%" rvalue="">%USERVAR[Server_Appropriate_CMD]% %USERVAR[Cache_Line01]% 1440</out>
<out type="push" extdata="IP_Ban_Message" condition="!=" lvalue="%USERVAR[Cache_Line01]%" rvalue="">1</out>
// +1 the amount of IP's banned if some IP's were banned
<out type="push" extdata="Amount_of_Proxies_Banned" condition="!=" lvalue="%USERVAR[Cache_Line01]%" rvalue=""><operator type="+" lvalue="%USERVAR[Amount_of_Proxies_Banned]%" rvalue="1"/></out>
// Process this code a few more times or until we reach line 1 in which case finish
<out type="goto" extdata="-14" condition="!=" lvalue="%USERVAR[Proxy_Server_API_Result_Line]%" rvalue="1"></out>
// Proxy Servers were banned message creation
<out type="push" extdata="Proxy_Opmsg_Output" condition=">" lvalue="%USERVAR[Amount_of_Proxies_Banned]%" rvalue="1">%USERVAR[Amount_of_Proxies_Banned]% Proxy Servers have been banned in your room for 24 Hours #c63#(#c62#Pre-Emptive Bans#c63#)</out>
<out type="push" extdata="Proxy_Opmsg_Output" condition="==" lvalue="%USERVAR[Amount_of_Proxies_Banned]%" rvalue="1">%USERVAR[Amount_of_Proxies_Banned]% Proxy Server has been banned in your room for 24 Hours #c63#(#c62#Pre-Emptive Bans#c63#)</out>
// Output to the admins that some IP's were banned if they were banned
<out condition="==" lvalue="%USERVAR[IP_Ban_Message]%" rvalue="1">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#%USERVAR[Proxy_Opmsg_Output]%</out>
<out type="break" condition="==" lvalue="%TRIGGER%" rvalue="!botpreempban"></out>
<out condition="==" lvalue="%USERVAR[IP_Ban_Message]%" rvalue="0">/opmsg #c4#Proxy Blocker #c63#(#c62#v1.2b#c63#): #c9#No Proxy Servers were found to ban at this time #c63#(#c62#Pre-Emptive Bans#c63#)</out>
</command>



</config>