Tuckey UrlRewrite Filter redirecting all http requests except foo.html - tuckey-urlrewrite-filter

I'm trying to redirect all http requests to https except "health.html" which I need to serve over standard http on port 80; For some reason the rules below don't seem to be doing it - I'm sure it's a syntax thing...
Thoughts?
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
<rule match-type="regex">
<note>
Redirect all http requests to https except health.html for EB monitoring
</note>
<condition type="header" operator="equal" name="X-Forwarded-Proto">^HTTP$</condition>
<condition name="request-uri" operator="notequal">^/health.html(.*)$</condition>
<from>^.*$</from>
<to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}</to>
</rule>
<rule>
<note>
Allow TomCat to have SES links.
</note>
<condition type="request-uri" operator="notequal">\.(bmp|gif|jpe?g|png|css|js|txt|pdf|doc|xls|cfc|ico|php|asp)$</condition>
<condition type="request-uri" operator="notequal">^/railo-context(.*)$</condition>
<condition type="request-uri" operator="notequal">^/flex2gateway(.*)$</condition>
<condition type="request-uri" operator="notequal">^/jrunscripts(.*)$</condition>
<condition type="request-uri" operator="notequal">^/cfide(.*)$</condition>
<condition type="request-uri" operator="notequal">^/cfformgateway(.*)$</condition>
<condition type="request-uri" operator="notequal">^/files(.*)$</condition>
<condition type="request-uri" operator="notequal">^/images(.*)$</condition>
<condition type="request-uri" operator="notequal">^/javascripts(.*)$</condition>
<condition type="request-uri" operator="notequal">^/miscellaneous(.*)$</condition>
<condition type="request-uri" operator="notequal">^/stylesheets(.*)$</condition>
<condition type="request-uri" operator="notequal">^/favicon.ico(.*)$</condition>
<condition type="request-uri" operator="notequal">^/robots.txt(.*)$</condition>
<condition type="request-uri" operator="notequal">^/sitemap.xml(.*)$</condition>
<condition type="request-uri" operator="notequal">^/rewrite.cfm(.*)$</condition>
<condition type="request-uri" operator="notequal">^/health.html(.*)$</condition>
<condition type="request-uri" operator="notequal">^/public(.*)$</condition>
<from>^/(.*)$</from>
<to type="passthrough" last="true">/rewrite.cfm/$1</to>
</rule>
</urlrewrite>

I'm an idiot.
<condition name="request-uri" operator="notequal">
should be
<condition type="request-uri" operator="notequal">
Sigh.

Related

Setting up proxy headers in IIS for flask application

I have a flask application on windows running at http://localhost:3333. I want domain example.com to proxy to this application using IIS. I have setup IIS with below settings.
Added server variables HTTP_X_FORWARDED_HOST
Configured URL Rewrite module to redirect example.com to localhost:3333
There is a route in flask which I use to generate URL for forgot password like this url_for('/password_reset',_external=True).
When I access the page via example.com, all works fine where I have redirect() used. But wherever I have url_for(), the URL looks like http://localhost:3333/password_reset instead of http://example.com/password_reset. How do I make url_for() to use the external domain name properly.
Edit 1:
Current web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="http://localhost:3333" />
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3333/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:3333/(.*)" />
<action type="Rewrite" value="http{R:1}://example.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<httpProtocol>
<customHeaders>
<add name="Host" value="{HOST}" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
<identity impersonate="false" />
</system.web>
</configuration>
Edit 2:
Solution: I executed this to preserver headers and now the original host is preserved when using url_for().
"C:\Windows\System32\inetsrv\appcmd.exe" set config -section:system.webServer/proxy /preserveHostHeader:"True" /commit:apphost
you could use iis reverse proxy module for that you need to install arr:
https://www.iis.net/downloads/microsoft/application-request-routing
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
below is sample rule:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule2" enabled="false" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://127.0.0.1:5000/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml1" enabled="false">
<match filterByTags="A, Form, Img" pattern="^http(s)?://127.0.0.1:5000/(.*)" />
<action type="Rewrite" value="http{R:1}://example.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doDynamicCompression="false" />
</system.webServer>
</configuration>
Solution that worked, as per edit.
I executed this to preserver headers and now the original host is preserved when using url_for().
"C:\Windows\System32\inetsrv\appcmd.exe" set config -section:system.webServer/proxy /preserv

How to redirect http to https in JBoss EAP 6.4?

Here how to set substitution to any address so that I can use it in AWS Application Load Balancer.
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" enable-lookups="false" secure="true" />
<virtual-server name="default-host" enable-welcome-root="true">
<rewrite pattern="^/(.*)$" substitution="https://localhost:443/$1" flags="RL">
<condition test="%{HTTPS}" pattern="off" />
</rewrite>
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
I want like
<rewrite pattern="^/(.*)$" substitution="https://%HOST_NAME%" flags="RL">
<condition test="%{HTTPS}" pattern="off" />
</rewrite>
Here are the steps to redirect from http to https in EAP 6,
Add redirect-port="443" to http connector as follows :
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" redirect-port="443"/>
Change the socket-binding of https to 443 as follows :
<socket-binding name="https" port="443"/>
Configure https connector in EAP 6,
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
<ssl name="ssl" key-alias="mykey" password="password" certificate-key-file="/path/to/keystore.jks"/>
</connector>
Edit the web.xml of application as follows:-
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
This is what worked for me (change in configruation/standalone-full.xml):
<filters>
<rewrite name="http-to-https" target="https://${jboss.qualified.host.name}:8443%U" redirect="true"/>
</filters>

How to do 307 redirect with tuckey UrlRewriteFilter

I have the following rule...
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<to type="temporary-redirect" last="true">https://something.com/$1</to>
</rule>
... And it works just fine (gives a 302 redirect) however i want to make it 307 redirect since that preserves parameters. I tried the following and have had no luck:...
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<set type="status">307</set>
<to type="temporary-redirect" last="true">https://something.com/$1</to>
</rule>
Any idea how to do this?
Figured it out!... You have to set the location header manually. Also null out the "to" node.
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<set type="status">307</set>
<set type="response-header" name="Location">https://something.com/$1</set>
<to last="true">null</to>
</rule>

WCF Web Service Error (Could not find default endpoint element that references contract)

I've spent hours trying to figure out this particular error and have had no luck.
I keep getting an error reading like I'm missing an endpoint and I'm new to WCF web Services so I'm not sure what direction to look. Anyway, The error reads.
Could not find default endpoint element that references contract 'ServiceReference1.ServiceContract' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I create the object like this and then add a method.
ServiceReference1.ServiceContractClient test = new ServiceReference1.ServiceContractClient();
var connecting = test.Connect();
I have endpoints in my web.config file of the WcfProject. Here's my web.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<sessionState cookieless="false" mode="InProc"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="RestBinding"></binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="WcfRestService1.Service">
<endpoint name="ServiceBinding" contract="WcfRestService1.IService" binding="webHttpBinding" bindingConfiguration="RestBinding" behaviorConfiguration="RestBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="basic" binding="wsHttpBinding" bindingConfiguration="" contract="WcfRestService1.IService" />
<host>
<baseAddresses>
<add baseAddress="http://servername/WcfRestService1/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint name="Default"
address="http://servername/WcfRestService1/Service.svc"
binding="webHttpBinding"
bindingConfiguration="RestBinding"
behaviorConfiguration="RestBehavior"
contract="WcfRestService1.IService" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>
I'm not sure what i need.
Thanks for any help.
You can not consume REST service using Service Proxy generated either by using Visual studio add service reference feature or using svcutil.exe. You need to use WebClient, HttpWebRequest or any other third party library capable of making http calls.

Freeswitch call intercerpt configuration

I am trying to configure call intercept groups and I am having a hard time finding what is wrong with my config. When I dial the feature code to intercept *110(interceptgroup no) (in this case *110101) the dialplan doesn't match and fails. The hash is inserted successfully, I can see it in the cli via hash select/intercept_2/101. What am I missing here?
Here is my user config from directory/default.xml:
<user bluebox_id="3" id="1001">
<variables>
<variable name="internal_caller_id_number" value="1001"/>
<variable name="user_context" value="context_4"/>
<variable name="force_transfer_context" value="context_4"/>
<variable name="user_originated" value="true"/>
<variable name="toll_allow" value="domestic"/>
<variable name="accountcode" value="1001"/>
<variable name="callrecord_inbound" value="1"/>
<variable name="callrecord_outbound" value="1"/>
<variable name="interceptgroup" value="101"/>
</variables>
<params>
<param name="password" value="removed"/>
<param name="dial-string" value="{presence_id=${dialed_user}#${dialed_domain}}${sofia_contact(${dialed_user}#${dialed_domain})}"/>
</params>
</user>
<user bluebox_id="5" id="1238">
<variables>
<variable name="internal_caller_id_number" value="1238"/>
<variable name="user_context" value="context_4"/>
<variable name="force_transfer_context" value="context_4"/>
<variable name="user_originated" value="true"/>
<variable name="toll_allow" value="domestic"/>
<variable name="accountcode" value="1238"/>
<variable name="callrecord_inbound" value="1"/>
<variable name="callrecord_outbound" value="1"/>
<variable name="interceptgroup" value="101"/>
</variables>
<params>
<param name="password" value="removed"/>
<param name="dial-string" value="{presence_id=${dialed_user}#${dialed_domain}}${sofia_contact(${dialed_user}#${dialed_domain})}"/>
</params>
</user>
Here is my dialplan config from dialplan.xml:
<extension name="main_number_43" continue="true">
<condition field="destination_number" expression="^1238$">
<action application="hash" data="insert/intercept_2/101/${uuid}"/>
<action application="set" bluebox="settingTimeout" data="call_timeout=30"/>
<action application="set" bluebox="settingRing" data="ringback=${us-ring}"/>
<action application="set" bluebox="settingRingXfer" data="transfer_ringback=${us-ring}"/>
<action application="export" bluebox="sipCalleeIdName" data="sip_callee_id_name=linksys"/>
<action application="export" bluebox="sipCalleeIdNumber" data="sip_callee_id_number=1238"/>
<action application="bridge" data="user/1238#$${location_4}"/>
<action application="hangup"/>
</condition>
</extension>
<extension name="main_number_45" continue="true">
<condition field="${regex(m:/${destination_number}/^\*110([0-9]+)$/$1)}" expression="^${interceptgroup}$"/>
<condition field="destination_number" expression="^\*110([0-9]+)$">
<action application="answer"/>
<action application="set" data="intercept_unanswered_only=true"/>
<action application="intercept" data="${hash(select/intercept_2/$1)}"/>
<action application="sleep" data="2000"/>
<action application="hangup"/>
</condition>
</extension>
After some headache I discovered that you cannot prepend this particular feature code with a *, it causes freeswitch to parse the digits differently by separating the feature code itself (*110 in this case) from the digits you enter as an argument, which in this case is the intercept group number. Removing the * fixed it.
<extension name="main_number_45" continue="true">
<condition field="${regex(m:/${destination_number}/^\110([0-9]+)$/$1)}" expression="^${interceptgroup}$"/>
<condition field="destination_number" expression="^\110([0-9]+)$">
<action application="answer"/>
<action application="set" data="intercept_unanswered_only=true"/>
<action application="intercept" data="${hash(select/intercept_2/$1)}"/>
<action application="sleep" data="2000"/>
<action application="hangup"/>
</condition>
</extension>