Showing posts with label geekstuff. Show all posts
Showing posts with label geekstuff. Show all posts

Wednesday, May 7, 2014

Apache CORS Headers

It is possible to add multiple domains by using the following:
Header set Access-Control-Allow-Origin "http://domain1.com"
Header add Access-Control-Allow-Origin "http://domain2.net"
Header add Access-Control-Allow-Origin "http://domain3.org"
However, it doesn't work entirely as expected and it also exposes all your API clients to anyone interested. Not a big deal, but why expose more info than necessary?

So, to only have valid requests return one single domain (the accepted Origin) we can configure Apache to dynamically check and return only one permitted domain:
SetEnvIf Origin "(http|https)://(domain1.com|domain2.net|domain3.org)$" RequestOrigin=$0
Header always set Access-Control-Allow-Origin %{RequestOrigin}e env=RequestOrigin
This will return http://domain2.net if the request has an Origin of http://domain2.net. If the request has an origin that isn't matched by the regular expression in the SetEnvIf command, then it will not return any Access-Control-Allow-Origin header at all!

Some other headers I always include:
Header set Access-Control-Allow-Methods 'GET,PUT,POST,DELETE,OPTIONS'
Header set Access-Control-Allow-Credentials true

Monday, December 23, 2013

Regular Expressions

To match a floating point value in a substring I currently use the following regular expression:

(\d+(?:\.\d+)?(?:[eE][-+]?[0-9]+)?)

This matches:

  • 123
  • 123.4
  • 123.4E3
  • 123.4e-4
  • etc...


Does anyone have a better expression that matches example strings?
Please post in the comments below, thanks.

Tuesday, June 28, 2011

Project Firewall - Hardware

NetGear WNDR3700
Yey!

My ISP upgraded my internet connection, and lowered the price at the same time. My initial tought was ofcourse "Fantastic! Woot!!1". And it looked quite good, except I didn't manage to get full download speed on my new connection with my current router, the NetGear WNDR3700.
Don't get me wrong, its a pretty decent piece of hardware, but as most appliances meant for the mass market, it isn't really designed to handle a 60 Mbps fiber connection. My peak download speed was about 5.85 MB/s or about 50 Mbps.

So, out with the old, and in with the new. This time I wanted to be sure my router/firewall would handle the load I put on it, and preferably handle a couple of OpenVPN connections as well. After a shopping spree I ended up with the following hardware purchases:

ZOTAC FUSION350-A-E

All in all it set me back about 3000 NOK (including P&P), a bit expensive for a router, but with the load this should be able to handle I should hopefully not need to buy a new one for a few years!

ANTEC ISK 300-150
I must say I was very impressed by the Antec ISK 300-150 when it arrived. It is one heavy, solid piece of work weighing in at almost 5 kg!

It has room for two 2.5" HDD/SSD drives, as well as a slimline 5.25" CD/DVD ROM drive. Lots of open vents on the side and above the expansion slot and the 80mm fan has 3 adjustable speed settings though a small switch on the rear of the cabinet. Mine is running fine at the slowest setting, and is barely audible.

The mainboard comes with an Atheros based wireless mini-pc-express card for b/g/n networking in addition to the gigabit integrated NIC. Adding the Intel NIC completed my networking requirements with a total of three physical zones (wan, lan and wlan).

I will follow up this post with information about software and performance experiences later on. 

Thursday, May 5, 2011

OpenVPN 2 Cookbook



I just received a copy of the OpenVPN 2 Cookbook by Jan Just Keijser in my virtual mailbox. At first glance, the 350 pages appears to contain setup- and troubleshooting-guides for the most common usages of OpenVPN on both Linux and Windows platforms (and in some cases MacOS too).

It is available in regular printed form, and digitally in ePub and PDF formats, from Packt Publishing.

From the description of the book:
OpenVPN 2 Cookbook provides solutions to common OpenVPN problems. The book covers everything a system administrator needs to manage and run an OpenVPN network, from point to point networks to troubleshooting.
I will be back with a review once I have had a chance to read through it.

Tuesday, January 11, 2011

Ubuntu and OpenVPN FQDN Problems.

I have been having some weird problems with OpenVPN on my clean Ubuntu 10.10 (desktop) install whenever I connect to a remote LAN using OpenVPN. The remote LAN hosts a number of servers, all located under the domain company.local (example). Even if it connects and I can ping the remote machine that is called testserver, I can NOT ping the same server through its fully qualified domain name (FQDN) testserver.company.local. Ping would fail with the following error:

ping: unknown host testserver.company.local

Trying to lookup the FQDN with nslookup works just fine! Strange!

Now it appears that the reason is something called a MDNS (Multicast DNS) which kicks in and handles (by default) all .local domains. Looking at the file /etc/nsswitch.conf I found a line that looks like this:

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

Apparently the '.local' extension is not sent to the DNS server for resolution if the MDNS system cant resolve it. So I went ahead and changed the line to:

hosts: files mdns4_minimal dns mdns4

I went back to the shell and ran ping testserver.company.local again, and lo-and-behold it works!

Software used:
  • NetworkManager
  • NetworkManager-OpenVPN
  • OpenVPN
  • Ubuntu 10.10 Desktop

Thursday, January 29, 2009

Cool Open Source Site

I stumbled over a cool site for open-source software development today. It has the wierd url ohloh.net and appears to be a social networking site based on open-source development.

Anyway, somebody had already registered my pet project, Item Assistant, and I diligently grabbed it and started to fill in details like SVN repository URLs etc. It then started generating some useful and interesting statistics about the project.

Anyway, its cool and you can check it out right here!