Redirecting Apache HTTP to HTTPS

Now that everyone can enjoy and use free SSL certificates from Let’s Encrypt, let’s all encrypt!

To forward HTTP requests to secure HTTPS, there are multiple options.

If you’re using some kind of panel to edit Apache configuration (like ISPConfig) that does not allow to edit the virtual host for HTTP separate from the virtual host for HTTPS, you can use this configuration in both configuration containers:

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

If you’re able to edit the virtual host for HTTP separately, Apache recommends using “Redirect”: http://httpd.apache.org/docs/current/rewrite/avoid.html#redirect

<VirtualHost *:80>
    ServerName www.example.com
    Redirect "/" "https://www.example.com/"
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost>

By the way: if you’re using ISPConfig, I can recommend installing the Let’s Encrypt plugin from https://github.com/alexalouit/ISPConfig-letsencrypt. The plugin will be included into the upcoming new version of ISPConfig >3.1.

AngularJS ng-options syntax

I keep forgetting the correct syntax for ng-options in angular dropdowns. The documentation can be found here: https://docs.angularjs.org/api/ng/directive/ngOptions

The syntax used in the documentation is a bit confusing:

select as label for value in array

A concrete example for the syntax would look like this:

item.Id as item.Name for item in itemSource

I hope this helps myself and maybe someone else as well…

Running ASP.NET vnext on Ubuntu Linux

After reading a lot about ASP.NET vNext I finally found an hour to give it a try. I only got as far as running the first sample webs, but it’s very nice to see it work.

There where some steps I had to take to get it up and running:

https://github.com/aspnet/home is a good starting point. Starting with the command to install the basic kvm script I already got kvm and was almost able to restore packages.

curl -sSL https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh &amp;&amp; source ~/.kre/kvm/kvm.sh

The next step was to install Mono from http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives:

sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
apt-get update
apt-get install mono-complete

Next I cloned the aspnet Home samples:

git clone --depth=1 https://github.com/aspnet/Home.git aspnet.Home
cd aspnet.Home/samples/HelloMvc/

Ready to go!

kpm restore

[…]
System.IO.IOException: The authentication or decryption has failed. —> Mono.Security.Protocol.Tls.TlsException
homer-doh

Some NuGet packages failed to restore because the certificate didn’t seem to be validated on my system. After some searching I found this helpful page:
http://www.ganshani.com/blog/2014/12/shell-script-to-setup-net-on-linux/

Executed this scripts (with some manual approvals in between!):

sudo certmgr -ssl -m https://go.microsoft.com
sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
sudo certmgr -ssl -m https://nuget.org
sudo certmgr -ssl -m https://www.myget.org/F/aspnetvnext/

Another

kpm restore

later, all packages restored perfectly.

Run the web:

k kestrel

– next error, null reference: https://github.com/aspnet/KestrelHttpServer/issues/29

Again the ganshani.com page helped with the script:

wget http://dist.libuv.org/dist/v1.0.0-rc1/libuv-v1.0.0-rc1.tar.gz 
tar -xvf libuv-v1.0.0-rc1.tar.gz
cd libuv-v1.0.0-rc1/
./gyp_uv.py -f make -Duv_library=shared_library
make -C out
sudo cp out/Debug/lib.target/libuv.so /usr/lib/libuv.so.1.0.0-rc1
sudo ln -s libuv.so.1.0.0-rc1 /usr/lib/libuv.so.1

So maybe things would have been faster using the setup script from Punit Ganshani in the first place, which can also be found on github: https://github.com/punitganshani/ganshani/blob/master/Samples/ASPNET5.0_SampleForLinux/SetupDotNetOnLinux.sh

In the end, this was what I saw: aspnet-linux

Next: Using http://www.omnisharp.net/ to edit the project in Sublime…

Sublime Text customization settings

Here’s a backup of my custom settings for my favorite text-editor Sublime.

Default (Windows).sublime-keymap

[
	// Add 7 to toggle_comment command for German keyboard handling
	{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } },
]

Preferences.sublime-settings

{
	"ignored_packages":
	[
		"Vintage",
	],
	"word_wrap": "false"
}

OpenWRT on TP-Link TL-WDR4900

My wifi connections at home have been really slow using a really old AVM Fritz!Box, so I decided to upgrade to a TL-WDR4900. (The only thing still missing is 802.11 ac but the cheapest router providing that would be the Asus RT-AC66U AC1750 for twice the price of the TL-WDR4900, so that wasn’t worth it for me.)

http://wiki.openwrt.org/toh/tp-link/tl-wdr4900

I’m only writing this blog post because I found it really hard to get the right information on how to install OpenWRT – the wiki entry only scared me away because it doesn’t mention the simple method. The simple method is: Download firmware, upgrade, configure, done. (I can only speak for the v1 variant though.)

In this directory you’ve got to select the right binary: http://downloads.openwrt.org/snapshots/trunk/mpc85xx/

And this is the right binary: openwrt-mpc85xx-generic-tl-wdr4900-v1-squashfs-factory.bin

After upgrading the firmware, the most simple way is to telnet to your machine:

telnet 192.168.0.1

Install luci http://wiki.openwrt.org/doc/howto/luci.essentials

Configure your router from http://192.168.0.1

Update (2014-11-24):
To allow multiple outgoing VPN PPTP connections, the package “kmod-gre” is needed (“Generic Routing Encapsulation support”).

opkg install kmod-gre

Continuous improvement

I started writing most of this article back in January and did not have time to finish it since – because I was stuck in doing exactly the things that I wanted to avoid. Now it’s time to finish the article so I’ll be able to compare my recent experience to my oh so nobel goals. This is what I wrote:

The week before Christmas was the last week in the office of a customer I have worked for for a little more than two years – which until now is the greater part of my working life. So at the moment I am thinking about the things that I have learned over that time to being able to apply that in my future work. I write this article as a reference to check against when I will look back at it in a few months to identify things that I have been doing different from the way I wanted to do them.

Only recently two interesting thoughts have been stuck with me: The first was an article that has been linked on Hacker news with the title “Everything is my fault” (http://news.ycombinator.com/item?id=4895335). To me, this meant to always remember not to blame anybody else for the things that are not done in the way I like them to be. Instead, in most of the cases it is myself to be blamed for not changing things or convince the right person about it. The other very helpful thought comes from Eric Schmidt in an interview at the Computer History Museum: https://www.youtube.com/watch?v=NfalakTPsnE&t=3m15s “It was some really smart person who really thought this was really good, and maybe I should understand why, before I just willingly attack them without any basis. My architecture by the way was better, but theirs was good too.” To me this basically means: Don’t be a smart ass and respect people around you – and I am still in the process of learning that.

With these premises in mind I’ll now just document my experience of what I believe are important things that I have learned over the past months.

Project management – tools and processes

The most annoying task I had to do repeatedly was time booking. I think this is a widespread problem and most people in bigger companies experience this, but I won’t accept that in the future and will do everything I can to reduce the overhead. In my case there have been some months in the transition between multiple time-booking systems when I had to book every little task into 4 (four!) systems – the work-items (Team Foundation Server), the old management tool (can’t even remember what that was), the new management tool (Microsoft Project) and the system of my employer to write the bill. To keep track of the hours I had already booked, I kept the hours in a fifth system, an Excel sheet as a “master”. This really is not only annoying, but also is a lot of wasted time and money. I understand that it is necessary to keep track of the hours, even down to “workitem/issues” level, but hopefully I’ll be able to keep that simple. We will keep track of the time in an instance of Redmine and import the entries into the proprietary billing system at my employer.

Another issue that is directly related with the tools being used has been, that the project planning has been done in MS Project, while the work-items to be worked on and booked to were created in TFS. Unfortunately Microsoft hasn’t been able to make those systems compatible (at least not that I or the customer know of). This, too, will be done in Redmine in my future projects (or any other good system, but not distributed over multiple databases…).

Setting up a build-server and doing continuous integration with unit-tests is another thing that I plan to do. I believe that the time invested in early stages of a project pays of big time. The same goes for doing reviews on a regular basis!

Project documentation

Documentation has been an important thing at the recent customer. Most of the documentation has been pretty good and I have learned the importance of having a place to look up specifications at a later time. The hardest part of writing good documentation however seems to be to decide what’s important and what’s not. A good part of technical documentation will always be work in progress and therefore it should be as short and formal as possible. Having technical documentation as close to the source code as possible also helps in keeping it up to date. In one project we used Sandcastle as a doc tool, but I don’t like it because it ads great overhead and took a very long time to compile (over 20 minutes). I will have to look for a better solution for my next project. Suggestions?

Having too much documentation might even be hurtful because it will lead to not reading any documentation at all in the future as well as to outdated information.

Requirements are the most important part of the documentation, but obviously it is very hard to phrase them properly.

The craft – technologies and architecture

As a developer, the most interesting part is the technologies and architecture being applied. My main tasks where to develop front ends using WPF and database services using Entity Framework. Additionally, the communication between frontend and backend has been a part of my job. For one project we used WCF, for others, proprietary protocols have been used. Another home-baked protocol has been used for the communication between the different programs and modules. Communication and thread handling is being done in an internal framework that is being used in almost every component.
While that makes sense for the most part, there was a very strong tendency of creating own protocols, patterns and frameworks instead of using existing solutions. The main reason for that was not to be dependent on external development. Sometimes this may be a valid argument, however my opinion is that it is always better to stand on the shoulders of giants – use open-source libraries, use existing commercial solutions, but don’t roll your own!

Testing

Quality assurance was a very important part of the development process at the customer. It was pretty good – the question is how to apply that to other conditions when it is not possible to have a whole department for it.

People and working atmosphere

I have learned about the importance of knowing each other, transparency on both ends, management listening to “the people” instead of making decisions without being grounded. Also: find the right person for the job. (Keep “creative” (but good) developers on a tight (but not too tight) leash, check & follow up.) It’s important to introduce a new colleague into the environment – both, the people and the technical stuff. Not only should a new employee have time to adjust to a new environment but the entire structure should be optimized to be easily understood. This goes on the micro-level with having a software project structure that can be up and running within minutes as well as on the macro-level with processes within the company that should be as simple as possible.

Well, that’s it for now – I’ll keep this article primarily as a reference for myself to compare to future experiences…

Synchronize a long-running task to the UI-Thread in WPF/.NET

This post explains how to process data from a task in WPF in a way I’d consider “best-practice”. The main code could or should be in the view-model.

Code-behind (keep it short or better yet use a delegate command)

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get some parameters if necessary
                [...]

                this.SomeViewModelData.StartSearch([parameters...]);
            }
            catch (Exception ex)
            {
                log.Warn("Error handling...", ex);
            }
        }

And the code in the view-model:

  • StartSearch() is a method in the view-model class and sets the properties of the view-model that are bound to the UI
  • this.IsWaiting is some bool property to indicate the waiting status in the UI
  • this.ResultData is not bound but contains data to be processed
  • ProcessResultData() processes the result and sets the output (for example it might fill an ObservableCollection)
        public void StartSearch([parameters...])
        {
            try
            {
                var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();

                this.IsWaiting = true;

                Task.Factory.StartNew(() =>
                {
                    this.ResultData = DatabaseService.GetComplexData([parameters...]);
                }).ContinueWith((t) =>
                {
                    // Invoke in UI Thread via scheduler
                    this.ProcessResultData();

                    // Cancel waiting indicator
                    this.IsWaiting = false;
                }, uiScheduler // <-- This is the important part: Continue
                               // the task in the UI thread
                {
                    if (t.Exception != null)
                    {
                        log.Warn("Task exception handling...", t.Exception);
                    }

                    this.IsWaiting = false;
                }, TaskContinuationOptions.OnlyOnFaulted);
            }
            catch (Exception ex)
            {
                log.Warn("Do exception handling... ", ex);
                this.IsWaiting = false;
            }
        }

Replace Linebreak in Excel

Just a quick note because this helped me a lot 🙂

To replace a linebreak in an excel cell:

In Excel, choose Edit>Replace
Click in the Find What box
Hold the Alt key, and (on the number keypad), type 0010
This represents a line break in Excel.
You won’t see anything in the ‘Find What’ box

In the Replace with box, type the characters that you want to use
instead of a line break

Click the Replace All button

Props go to this thread.

Hope it helps someone else…

Apache ODE modification framework

A little late I am now publishing the source code of the demonstration prototype of my diploma thesis. The thesis has been about runtime modification of BPEL processes.

The modification is based on the svn trunk of Apache ODE located in https://svn.apache.org/repos/asf/ode/trunk and the revision was 805932 updated at 19. August 09. It shouldn’t be hard to apply the changes to the latest revision though.

The source code is available in a 7-zip File containing the SVN checkout and the additional files required to run the modification service: apache-ode-modification-framework.7z

EDIT:
The modification framework provides some simple modification operations like inserting or skipping BPEL activities and modifying the value of process variables. The inserted BPEL activities can be provided to the webservice in the form of BPEL code as if this fraction of the process has been part of the process in the first place. The provided code is compiled using the default ODE compiler. With the current state of the implementation it is not possible to modify the specification of existent partner links or to create new partner links to use in the activities that are inserted. Therefore to use such a modification framework in a reasonable way, the given prototype would have to be extended to enable such modifications.